]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: add class for mirror status watcher
authorMykola Golub <mgolub@mirantis.com>
Tue, 3 Jan 2017 10:10:01 +0000 (12:10 +0200)
committerMykola Golub <mgolub@mirantis.com>
Wed, 1 Feb 2017 09:55:03 +0000 (10:55 +0100)
Signed-off-by: Mykola Golub <mgolub@mirantis.com>
src/tools/rbd_mirror/CMakeLists.txt
src/tools/rbd_mirror/MirrorStatusWatcher.cc [new file with mode: 0644]
src/tools/rbd_mirror/MirrorStatusWatcher.h [new file with mode: 0644]

index fff32f7168dd5301c13b7da7d7e4f88f65bd1043..53382525929eeebd0aa4482226b03c09045bd925 100644 (file)
@@ -5,6 +5,7 @@ set(rbd_mirror_internal
   ImageSync.cc
   ImageSyncThrottler.cc
   Mirror.cc
+  MirrorStatusWatcher.cc
   PoolWatcher.cc
   Replayer.cc
   Threads.cc
diff --git a/src/tools/rbd_mirror/MirrorStatusWatcher.cc b/src/tools/rbd_mirror/MirrorStatusWatcher.cc
new file mode 100644 (file)
index 0000000..b969ed6
--- /dev/null
@@ -0,0 +1,63 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "MirrorStatusWatcher.h"
+#include "common/debug.h"
+#include "common/errno.h"
+#include "cls/rbd/cls_rbd_client.h"
+#include "librbd/Utils.h"
+
+#define dout_context g_ceph_context
+#define dout_subsys ceph_subsys_rbd_mirror
+#undef dout_prefix
+#define dout_prefix *_dout << "rbd::mirror::MirrorStatusWatcher: " \
+                           << this << " " << __func__ << ": "
+
+namespace rbd {
+namespace mirror {
+
+using librbd::util::create_rados_ack_callback;
+
+MirrorStatusWatcher::MirrorStatusWatcher(librados::IoCtx &io_ctx,
+                                         ContextWQ *work_queue)
+  : Watcher(io_ctx, work_queue, RBD_MIRRORING) {
+}
+
+void MirrorStatusWatcher::init(Context *on_finish) {
+  dout(20) << dendl;
+
+  on_finish = new FunctionContext(
+    [this, on_finish] (int r) {
+      if (r < 0) {
+        derr << "error removing down statuses: " << cpp_strerror(r) << dendl;
+        on_finish->complete(r);
+        return;
+      }
+      register_watch(on_finish);
+    });
+
+  librados::ObjectWriteOperation op;
+  librbd::cls_client::mirror_image_status_remove_down(&op);
+  librados::AioCompletion *aio_comp = create_rados_ack_callback(on_finish);
+
+  int r = m_ioctx.aio_operate(RBD_MIRRORING, aio_comp, &op);
+  assert(r == 0);
+  aio_comp->release();
+}
+
+void MirrorStatusWatcher::shut_down(Context *on_finish) {
+  dout(20) << dendl;
+
+  unregister_watch(on_finish);
+}
+
+void MirrorStatusWatcher::handle_notify(uint64_t notify_id, uint64_t handle,
+                                        uint64_t notifier_id, bufferlist &bl) {
+  dout(20) << dendl;
+
+  bufferlist out;
+  acknowledge_notify(notify_id, handle, out);
+}
+
+} // namespace mirror
+} // namespace rbd
diff --git a/src/tools/rbd_mirror/MirrorStatusWatcher.h b/src/tools/rbd_mirror/MirrorStatusWatcher.h
new file mode 100644 (file)
index 0000000..0349e97
--- /dev/null
@@ -0,0 +1,27 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#ifndef CEPH_RBD_MIRROR_MIRROR_STATUS_WATCHER_H
+#define CEPH_RBD_MIRROR_MIRROR_STATUS_WATCHER_H
+
+#include "librbd/Watcher.h"
+
+namespace rbd {
+namespace mirror {
+
+class MirrorStatusWatcher : protected librbd::Watcher {
+public:
+  MirrorStatusWatcher(librados::IoCtx &io_ctx, ContextWQ *work_queue);
+
+  void init(Context *on_finish);
+  void shut_down(Context *on_finish);
+
+protected:
+  virtual void handle_notify(uint64_t notify_id, uint64_t handle,
+                            uint64_t notifier_id, bufferlist &bl);
+};
+
+} // namespace mirror
+} // namespace rbd
+
+#endif // CEPH_RBD_MIRROR_MIRROR_STATUS_WATCHER_H