Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / operation / MetadataRemoveRequest.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/operation/MetadataRemoveRequest.h"
5 #include "common/dout.h"
6 #include "common/errno.h"
7 #include "librbd/ImageCtx.h"
8
9 #define dout_subsys ceph_subsys_rbd
10 #undef dout_prefix
11 #define dout_prefix *_dout << "librbd::MetadataRemoveRequest: "
12
13 namespace librbd {
14 namespace operation {
15
16 template <typename I>
17 MetadataRemoveRequest<I>::MetadataRemoveRequest(I &image_ctx,
18                                                 Context *on_finish,
19                                                 const std::string &key)
20   : Request<I>(image_ctx, on_finish), m_key(key) {
21 }
22
23 template <typename I>
24 void MetadataRemoveRequest<I>::send_op() {
25   send_metadata_remove();
26 }
27
28 template <typename I>
29 bool MetadataRemoveRequest<I>::should_complete(int r) {
30   I &image_ctx = this->m_image_ctx;
31   CephContext *cct = image_ctx.cct;
32   ldout(cct, 20) << this << " " << __func__ << "r=" << r << dendl;
33
34   if (r < 0) {
35     lderr(cct) << "encountered error: " << cpp_strerror(r) << dendl;
36   }
37   return true;
38 }
39
40 template <typename I>
41 void MetadataRemoveRequest<I>::send_metadata_remove() {
42   I &image_ctx = this->m_image_ctx;
43   assert(image_ctx.owner_lock.is_locked());
44
45   CephContext *cct = image_ctx.cct;
46   ldout(cct, 20) << this << " " << __func__ << dendl;
47
48   librados::ObjectWriteOperation op;
49   cls_client::metadata_remove(&op, m_key);
50
51   librados::AioCompletion *comp = this->create_callback_completion();
52   int r = image_ctx.md_ctx.aio_operate(image_ctx.header_oid, comp, &op);
53   assert(r == 0);
54   comp->release();
55 }
56
57 } // namespace operation
58 } // namespace librbd
59
60 template class librbd::operation::MetadataRemoveRequest<librbd::ImageCtx>;