]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
librbd: helper methods for mirroring notifications
authorJason Dillaman <dillaman@redhat.com>
Tue, 29 Mar 2016 04:02:10 +0000 (00:02 -0400)
committerJason Dillaman <dillaman@redhat.com>
Wed, 30 Mar 2016 21:00:31 +0000 (17:00 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/MirroringWatcher.cc
src/librbd/MirroringWatcher.h

index 3d8237e6d53b4e6ff1a7b6e1af835fc80e0d1093..b0a975a79566d908e4118c1ae4e6c722664d7baf 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "librbd/MirroringWatcher.h"
 #include "include/rbd_types.h"
+#include "common/errno.h"
 
 #define dout_subsys ceph_subsys_rbd
 #undef dout_prefix
 
 namespace librbd {
 
+using namespace mirroring_watcher;
+
+namespace {
+
+static const uint64_t NOTIFY_TIMEOUT_MS = 5000;
+
+} // anonymous namespace
+
 template <typename I>
 MirroringWatcher<I>::MirroringWatcher(librados::IoCtx &io_ctx,
                                       ContextWQT *work_queue)
@@ -21,6 +30,45 @@ std::string MirroringWatcher<I>::get_oid() const {
   return RBD_MIRRORING;
 }
 
+template <typename I>
+int MirroringWatcher<I>::notify_mode_updated(librados::IoCtx &io_ctx,
+                                             cls::rbd::MirrorMode mirror_mode) {
+  CephContext *cct = reinterpret_cast<CephContext*>(io_ctx.cct());
+  ldout(cct, 20) << dendl;
+
+  bufferlist bl;
+  ::encode(NotifyMessage{ModeUpdatedPayload{mirror_mode}}, bl);
+
+  int r = io_ctx.notify2(RBD_MIRRORING, bl, NOTIFY_TIMEOUT_MS, nullptr);
+  if (r < 0) {
+    lderr(cct) << ": error encountered sending mode updated notification: "
+               << cpp_strerror(r) << dendl;
+    return r;
+  }
+  return 0;
+}
+
+template <typename I>
+int MirroringWatcher<I>::notify_image_updated(
+    librados::IoCtx &io_ctx, cls::rbd::MirrorImageState mirror_image_state,
+    const std::string &image_id, const std::string &global_image_id) {
+  CephContext *cct = reinterpret_cast<CephContext*>(io_ctx.cct());
+  ldout(cct, 20) << dendl;
+
+  bufferlist bl;
+  ::encode(NotifyMessage{ImageUpdatedPayload{mirror_image_state, image_id,
+                                             global_image_id}},
+           bl);
+
+  int r = io_ctx.notify2(RBD_MIRRORING, bl, NOTIFY_TIMEOUT_MS, nullptr);
+  if (r < 0) {
+    lderr(cct) << ": error encountered sending image updated notification: "
+               << cpp_strerror(r) << dendl;
+    return r;
+  }
+  return 0;
+}
+
 } // namespace librbd
 
 template class librbd::MirroringWatcher<librbd::ImageCtx>;
index f97995327485385a6dd073a0e9fc15b38143c100..9c755805152118ffce8ed4f18de2fc8a683e9251 100644 (file)
@@ -5,6 +5,8 @@
 #define CEPH_LIBRBD_MIRRORING_WATCHER_H
 
 #include "include/int_types.h"
+#include "include/rados/librados.hpp"
+#include "cls/rbd/cls_rbd_types.h"
 #include "librbd/ImageCtx.h"
 #include "librbd/ObjectWatcher.h"
 #include "librbd/mirroring_watcher/Types.h"
@@ -18,6 +20,13 @@ public:
 
   MirroringWatcher(librados::IoCtx &io_ctx, ContextWQT *work_queue);
 
+  static int notify_mode_updated(librados::IoCtx &io_ctx,
+                                 cls::rbd::MirrorMode mirror_mode);
+  static int notify_image_updated(librados::IoCtx &io_ctx,
+                                  cls::rbd::MirrorImageState mirror_image_state,
+                                  const std::string &image_id,
+                                  const std::string &global_image_id);
+
 protected:
   virtual std::string get_oid() const;