Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / object_map / UnlockRequest.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/UnlockRequest.h"
5 #include "cls/lock/cls_lock_client.h"
6 #include "common/dout.h"
7 #include "common/errno.h"
8 #include "librbd/ImageCtx.h"
9 #include "librbd/ObjectMap.h"
10 #include "librbd/Utils.h"
11
12 #define dout_subsys ceph_subsys_rbd
13 #undef dout_prefix
14 #define dout_prefix *_dout << "librbd::object_map::UnlockRequest: "
15
16 namespace librbd {
17 namespace object_map {
18
19 using util::create_rados_callback;
20
21 template <typename I>
22 UnlockRequest<I>::UnlockRequest(I &image_ctx, Context *on_finish)
23   : m_image_ctx(image_ctx), m_on_finish(on_finish) {
24 }
25
26 template <typename I>
27 void UnlockRequest<I>::send() {
28   send_unlock();
29 }
30
31 template <typename I>
32 void UnlockRequest<I>::send_unlock() {
33   CephContext *cct = m_image_ctx.cct;
34   std::string oid(ObjectMap<>::object_map_name(m_image_ctx.id, CEPH_NOSNAP));
35   ldout(cct, 10) << this << " " << __func__ << ": oid=" << oid << dendl;
36
37   librados::ObjectWriteOperation op;
38   rados::cls::lock::unlock(&op, RBD_LOCK_NAME, "");
39
40   using klass = UnlockRequest<I>;
41   librados::AioCompletion *rados_completion =
42     create_rados_callback<klass, &klass::handle_unlock>(this);
43   int r = m_image_ctx.md_ctx.aio_operate(oid, rados_completion, &op);
44   assert(r == 0);
45   rados_completion->release();
46 }
47
48 template <typename I>
49 Context *UnlockRequest<I>::handle_unlock(int *ret_val) {
50   CephContext *cct = m_image_ctx.cct;
51   ldout(cct, 10) << this << " " << __func__ << ": r=" << *ret_val << dendl;
52
53   if (*ret_val < 0 && *ret_val != -ENOENT) {
54     lderr(m_image_ctx.cct) << "failed to release object map lock: "
55                            << cpp_strerror(*ret_val) << dendl;
56
57   }
58
59   *ret_val = 0;
60   return m_on_finish;
61 }
62
63 } // namespace object_map
64 } // namespace librbd
65
66 template class librbd::object_map::UnlockRequest<librbd::ImageCtx>;