From 3748b8874ecfced0ae72bf924103187354cc5ab8 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Tue, 29 Mar 2016 00:02:10 -0400 Subject: [PATCH] librbd: helper methods for mirroring notifications Signed-off-by: Jason Dillaman --- src/librbd/MirroringWatcher.cc | 48 ++++++++++++++++++++++++++++++++++ src/librbd/MirroringWatcher.h | 9 +++++++ 2 files changed, 57 insertions(+) diff --git a/src/librbd/MirroringWatcher.cc b/src/librbd/MirroringWatcher.cc index 3d8237e6d53..b0a975a7956 100644 --- a/src/librbd/MirroringWatcher.cc +++ b/src/librbd/MirroringWatcher.cc @@ -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 @@ -10,6 +11,14 @@ namespace librbd { +using namespace mirroring_watcher; + +namespace { + +static const uint64_t NOTIFY_TIMEOUT_MS = 5000; + +} // anonymous namespace + template MirroringWatcher::MirroringWatcher(librados::IoCtx &io_ctx, ContextWQT *work_queue) @@ -21,6 +30,45 @@ std::string MirroringWatcher::get_oid() const { return RBD_MIRRORING; } +template +int MirroringWatcher::notify_mode_updated(librados::IoCtx &io_ctx, + cls::rbd::MirrorMode mirror_mode) { + CephContext *cct = reinterpret_cast(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 +int MirroringWatcher::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(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; diff --git a/src/librbd/MirroringWatcher.h b/src/librbd/MirroringWatcher.h index f9799532748..9c755805152 100644 --- a/src/librbd/MirroringWatcher.h +++ b/src/librbd/MirroringWatcher.h @@ -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; -- 2.39.5