Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / operation / SnapshotLimitRequest.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/SnapshotLimitRequest.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::SnapshotLimitRequest: "
12
13 namespace librbd {
14 namespace operation {
15
16 template <typename I>
17 SnapshotLimitRequest<I>::SnapshotLimitRequest(I &image_ctx,
18                                               Context *on_finish,
19                                               uint64_t limit)
20   : Request<I>(image_ctx, on_finish), m_snap_limit(limit) {
21 }
22
23 template <typename I>
24 void SnapshotLimitRequest<I>::send_op() {
25   send_limit_snaps();
26 }
27
28 template <typename I>
29 bool SnapshotLimitRequest<I>::should_complete(int r) {
30   I &image_ctx = this->m_image_ctx;
31   CephContext *cct = image_ctx.cct;
32   ldout(cct, 5) << 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 SnapshotLimitRequest<I>::send_limit_snaps() {
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, 5) << this << " " << __func__ << dendl;
47
48   {
49     RWLock::RLocker md_locker(image_ctx.md_lock);
50     RWLock::RLocker snap_locker(image_ctx.snap_lock);
51
52     librados::ObjectWriteOperation op;
53     cls_client::snapshot_set_limit(&op, m_snap_limit);
54
55     librados::AioCompletion *rados_completion =
56       this->create_callback_completion();
57     int r = image_ctx.md_ctx.aio_operate(image_ctx.header_oid, rados_completion,
58                                          &op);
59     assert(r == 0);
60     rados_completion->release();
61   }
62 }
63
64 } // namespace operation
65 } // namespace librbd
66
67 template class librbd::operation::SnapshotLimitRequest<librbd::ImageCtx>;