]> git.proxmox.com Git - ceph.git/blame - ceph/src/librbd/object_map/RemoveRequest.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / librbd / object_map / RemoveRequest.cc
CommitLineData
7c673cae
FG
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"
11fdf7f2 11#include "include/ceph_assert.h"
7c673cae
FG
12
13#define dout_subsys ceph_subsys_rbd
14#undef dout_prefix
15#define dout_prefix *_dout << "librbd::object_map::RemoveRequest: "
16
17namespace librbd {
18namespace object_map {
19
20using util::create_rados_callback;
21
22template <typename I>
23RemoveRequest<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") {
26}
27
28template <typename I>
29void RemoveRequest<I>::send() {
30 send_remove_object_map();
31}
32
33template <typename I>
34void RemoveRequest<I>::send_remove_object_map() {
35 CephContext *cct = m_image_ctx->cct;
36 ldout(cct, 20) << __func__ << dendl;
37
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);
43 }
44
45 Mutex::Locker locker(m_lock);
11fdf7f2 46 ceph_assert(m_ref_counter == 0);
7c673cae
FG
47
48 for (auto snap_id : snap_ids) {
49 m_ref_counter++;
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);
54
55 int r = m_image_ctx->md_ctx.aio_remove(oid, comp);
11fdf7f2 56 ceph_assert(r == 0);
7c673cae
FG
57 comp->release();
58 }
59}
60
61template <typename I>
62Context *RemoveRequest<I>::handle_remove_object_map(int *result) {
63 CephContext *cct = m_image_ctx->cct;
64 ldout(cct, 20) << __func__ << ": r=" << *result << dendl;
65
66 {
67 Mutex::Locker locker(m_lock);
11fdf7f2 68 ceph_assert(m_ref_counter > 0);
7c673cae
FG
69 m_ref_counter--;
70
71 if (*result < 0 && *result != -ENOENT) {
72 lderr(cct) << "failed to remove object map: " << cpp_strerror(*result)
73 << dendl;
74 m_error_result = *result;
75 }
76 if (m_ref_counter > 0) {
77 return nullptr;
78 }
79 }
80 if (m_error_result < 0) {
81 *result = m_error_result;
82 }
83 return m_on_finish;
84}
85
86} // namespace object_map
87} // namespace librbd
88
89template class librbd::object_map::RemoveRequest<librbd::ImageCtx>;