]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/object_map/RemoveRequest.cc
import 15.2.0 Octopus source
[ceph.git] / ceph / src / librbd / object_map / RemoveRequest.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
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/ceph_assert.h"
12
13 #define dout_subsys ceph_subsys_rbd
14 #undef dout_prefix
15 #define dout_prefix *_dout << "librbd::object_map::RemoveRequest: "
16
17 namespace librbd {
18 namespace object_map {
19
20 using util::create_rados_callback;
21
22 template <typename I>
23 RemoveRequest<I>::RemoveRequest(I *image_ctx, Context *on_finish)
24 : m_image_ctx(image_ctx), m_on_finish(on_finish) {
25 }
26
27 template <typename I>
28 void RemoveRequest<I>::send() {
29 send_remove_object_map();
30 }
31
32 template <typename I>
33 void RemoveRequest<I>::send_remove_object_map() {
34 CephContext *cct = m_image_ctx->cct;
35 ldout(cct, 20) << __func__ << dendl;
36
37 std::unique_lock image_locker{m_image_ctx->image_lock};
38 std::vector<uint64_t> snap_ids;
39 snap_ids.push_back(CEPH_NOSNAP);
40 for (auto it : m_image_ctx->snap_info) {
41 snap_ids.push_back(it.first);
42 }
43
44 std::lock_guard locker{m_lock};
45 ceph_assert(m_ref_counter == 0);
46
47 for (auto snap_id : snap_ids) {
48 m_ref_counter++;
49 std::string oid(ObjectMap<>::object_map_name(m_image_ctx->id, snap_id));
50 using klass = RemoveRequest<I>;
51 librados::AioCompletion *comp =
52 create_rados_callback<klass, &klass::handle_remove_object_map>(this);
53
54 int r = m_image_ctx->md_ctx.aio_remove(oid, comp);
55 ceph_assert(r == 0);
56 comp->release();
57 }
58 }
59
60 template <typename I>
61 Context *RemoveRequest<I>::handle_remove_object_map(int *result) {
62 CephContext *cct = m_image_ctx->cct;
63 ldout(cct, 20) << __func__ << ": r=" << *result << dendl;
64
65 {
66 std::lock_guard locker{m_lock};
67 ceph_assert(m_ref_counter > 0);
68 m_ref_counter--;
69
70 if (*result < 0 && *result != -ENOENT) {
71 lderr(cct) << "failed to remove object map: " << cpp_strerror(*result)
72 << dendl;
73 m_error_result = *result;
74 }
75 if (m_ref_counter > 0) {
76 return nullptr;
77 }
78 }
79 if (m_error_result < 0) {
80 *result = m_error_result;
81 }
82 return m_on_finish;
83 }
84
85 } // namespace object_map
86 } // namespace librbd
87
88 template class librbd::object_map::RemoveRequest<librbd::ImageCtx>;