]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: async image set flags method
authorMykola Golub <mgolub@mirantis.com>
Wed, 31 Aug 2016 19:42:20 +0000 (22:42 +0300)
committerMykola Golub <mgolub@mirantis.com>
Wed, 28 Sep 2016 12:17:18 +0000 (15:17 +0300)
Signed-off-by: Mykola Golub <mgolub@mirantis.com>
src/librbd/image/SetFlagsRequest.cc [new file with mode: 0644]
src/librbd/image/SetFlagsRequest.h [new file with mode: 0644]

diff --git a/src/librbd/image/SetFlagsRequest.cc b/src/librbd/image/SetFlagsRequest.cc
new file mode 100644 (file)
index 0000000..979bebf
--- /dev/null
@@ -0,0 +1,78 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "librbd/image/SetFlagsRequest.h"
+#include "common/dout.h"
+#include "common/errno.h"
+#include "cls/rbd/cls_rbd_client.h"
+#include "librbd/ImageCtx.h"
+#include "librbd/Utils.h"
+#include "include/assert.h"
+
+#define dout_subsys ceph_subsys_rbd
+#undef dout_prefix
+#define dout_prefix *_dout << "librbd::image::SetFlagsRequest: "
+
+namespace librbd {
+namespace image {
+
+using util::create_context_callback;
+using util::create_rados_ack_callback;
+
+template <typename I>
+SetFlagsRequest<I>::SetFlagsRequest(I *image_ctx, uint64_t flags,
+                                   uint64_t mask, Context *on_finish)
+  : m_image_ctx(image_ctx), m_flags(flags), m_mask(mask),
+    m_on_finish(on_finish) {
+}
+
+template <typename I>
+void SetFlagsRequest<I>::send() {
+  send_set_flags();
+}
+
+template <typename I>
+void SetFlagsRequest<I>::send_set_flags() {
+  CephContext *cct = m_image_ctx->cct;
+  ldout(cct, 20) << __func__ << dendl;
+
+  RWLock::WLocker snap_locker(m_image_ctx->snap_lock);
+  std::vector<uint64_t> snap_ids;
+  snap_ids.push_back(CEPH_NOSNAP);
+  for (auto it : m_image_ctx->snap_info) {
+    snap_ids.push_back(it.first);
+  }
+
+  Context *ctx = create_context_callback<
+    SetFlagsRequest<I>, &SetFlagsRequest<I>::handle_set_flags>(this);
+  C_Gather *gather_ctx = new C_Gather(cct, ctx);
+
+  for (auto snap_id : snap_ids) {
+    librados::ObjectWriteOperation op;
+    cls_client::set_flags(&op, snap_id, m_flags, m_mask);
+
+    librados::AioCompletion *comp =
+      create_rados_ack_callback(gather_ctx->new_sub());
+    int r = m_image_ctx->md_ctx.aio_operate(m_image_ctx->header_oid, comp, &op);
+    assert(r == 0);
+    comp->release();
+  }
+  gather_ctx->activate();
+}
+
+template <typename I>
+Context *SetFlagsRequest<I>::handle_set_flags(int *result) {
+  CephContext *cct = m_image_ctx->cct;
+  ldout(cct, 20) << __func__ << ": r=" << *result << dendl;
+
+  if (*result < 0) {
+    lderr(cct) << "set_flags failed: " << cpp_strerror(*result)
+              << dendl;
+  }
+  return m_on_finish;
+}
+
+} // namespace image
+} // namespace librbd
+
+template class librbd::image::SetFlagsRequest<librbd::ImageCtx>;
diff --git a/src/librbd/image/SetFlagsRequest.h b/src/librbd/image/SetFlagsRequest.h
new file mode 100644 (file)
index 0000000..36905e6
--- /dev/null
@@ -0,0 +1,62 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#ifndef CEPH_LIBRBD_IMAGE_SET_FLAGS_REQUEST_H
+#define CEPH_LIBRBD_IMAGE_SET_FLAGS_REQUEST_H
+
+#include "include/buffer.h"
+#include "common/Mutex.h"
+#include <map>
+#include <string>
+
+class Context;
+
+namespace librbd {
+
+class ImageCtx;
+
+namespace image {
+
+template <typename ImageCtxT = ImageCtx>
+class SetFlagsRequest {
+public:
+  static SetFlagsRequest *create(ImageCtxT *image_ctx, uint64_t flags,
+                                uint64_t mask, Context *on_finish) {
+    return new SetFlagsRequest(image_ctx, flags, mask, on_finish);
+  }
+
+  void send();
+
+private:
+  /**
+   * @verbatim
+   *
+   * <start>
+   *    |   .  .  .
+   *    v   v     .
+   * SET_FLAGS    . (for every snapshot)
+   *    |   .     .
+   *    v   .  .  .
+   * <finis>
+   *
+   * @endverbatim
+   */
+
+  SetFlagsRequest(ImageCtxT *image_ctx, uint64_t flags, uint64_t mask,
+                 Context *on_finish);
+
+  ImageCtxT *m_image_ctx;
+  uint64_t m_flags;
+  uint64_t m_mask;
+  Context *m_on_finish;
+
+  void send_set_flags();
+  Context *handle_set_flags(int *result);
+};
+
+} // namespace image
+} // namespace librbd
+
+extern template class librbd::image::SetFlagsRequest<librbd::ImageCtx>;
+
+#endif // CEPH_LIBRBD_IMAGE_SET_FLAGS_REQUEST_H