1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "librbd/object_map/RemoveRequest.h"
5 #include "common/dout.h"
6 #include "common/errno.h"
7 #include "cls/rbd/cls_rbd_client.h"
8 #include "librbd/ImageCtx.h"
9 #include "librbd/ObjectMap.h"
10 #include "librbd/Utils.h"
11 #include "include/assert.h"
13 #define dout_subsys ceph_subsys_rbd
15 #define dout_prefix *_dout << "librbd::object_map::RemoveRequest: "
18 namespace object_map {
20 using util::create_rados_callback;
23 RemoveRequest<I>::RemoveRequest(I *image_ctx, Context *on_finish)
24 : m_image_ctx(image_ctx), m_on_finish(on_finish),
25 m_lock("object_map::RemoveRequest::m_lock") {
29 void RemoveRequest<I>::send() {
30 send_remove_object_map();
34 void RemoveRequest<I>::send_remove_object_map() {
35 CephContext *cct = m_image_ctx->cct;
36 ldout(cct, 20) << __func__ << dendl;
38 RWLock::WLocker snap_locker(m_image_ctx->snap_lock);
39 std::vector<uint64_t> snap_ids;
40 snap_ids.push_back(CEPH_NOSNAP);
41 for (auto it : m_image_ctx->snap_info) {
42 snap_ids.push_back(it.first);
45 Mutex::Locker locker(m_lock);
46 assert(m_ref_counter == 0);
48 for (auto snap_id : snap_ids) {
50 std::string oid(ObjectMap<>::object_map_name(m_image_ctx->id, snap_id));
51 using klass = RemoveRequest<I>;
52 librados::AioCompletion *comp =
53 create_rados_callback<klass, &klass::handle_remove_object_map>(this);
55 int r = m_image_ctx->md_ctx.aio_remove(oid, comp);
62 Context *RemoveRequest<I>::handle_remove_object_map(int *result) {
63 CephContext *cct = m_image_ctx->cct;
64 ldout(cct, 20) << __func__ << ": r=" << *result << dendl;
67 Mutex::Locker locker(m_lock);
68 assert(m_ref_counter > 0);
71 if (*result < 0 && *result != -ENOENT) {
72 lderr(cct) << "failed to remove object map: " << cpp_strerror(*result)
74 m_error_result = *result;
76 if (m_ref_counter > 0) {
80 if (m_error_result < 0) {
81 *result = m_error_result;
86 } // namespace object_map
89 template class librbd::object_map::RemoveRequest<librbd::ImageCtx>;