From 8dca9f024a1a5960922fa61b97eba3aafdb85c7d Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Fri, 10 Mar 2017 17:03:52 +0100 Subject: [PATCH] rbd-mirror: add set_remote_images method to ImageReplayer Signed-off-by: Mykola Golub --- src/tools/rbd_mirror/ImageReplayer.cc | 8 ++++- src/tools/rbd_mirror/ImageReplayer.h | 51 ++++++++++----------------- src/tools/rbd_mirror/types.h | 51 +++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 34 deletions(-) diff --git a/src/tools/rbd_mirror/ImageReplayer.cc b/src/tools/rbd_mirror/ImageReplayer.cc index 0a58a6b72c6..c89e9305b07 100644 --- a/src/tools/rbd_mirror/ImageReplayer.cc +++ b/src/tools/rbd_mirror/ImageReplayer.cc @@ -326,7 +326,7 @@ void ImageReplayer::add_remote_image(const std::string &mirror_uuid, librados::IoCtx &io_ctx) { Mutex::Locker locker(m_lock); - RemoteImage remote_image(mirror_uuid, image_id, io_ctx); + PeerImage remote_image(mirror_uuid, io_ctx, image_id); auto it = m_remote_images.find(remote_image); if (it == m_remote_images.end()) { m_remote_images.insert(remote_image); @@ -340,6 +340,12 @@ void ImageReplayer::remove_remote_image(const std::string &mirror_uuid, m_remote_images.erase({mirror_uuid, image_id}); } +template +void ImageReplayer::set_remote_images(const PeerImages &remote_images) { + Mutex::Locker locker(m_lock); + m_remote_images = remote_images; +} + template bool ImageReplayer::remote_images_empty() const { Mutex::Locker locker(m_lock); diff --git a/src/tools/rbd_mirror/ImageReplayer.h b/src/tools/rbd_mirror/ImageReplayer.h index 07ed7f8ada4..81d16e1be10 100644 --- a/src/tools/rbd_mirror/ImageReplayer.h +++ b/src/tools/rbd_mirror/ImageReplayer.h @@ -69,6 +69,20 @@ public: STATE_STOPPED, }; + static ImageReplayer *create( + Threads *threads, + std::shared_ptr image_deleter, + ImageSyncThrottlerRef image_sync_throttler, + RadosRef local, const std::string &local_mirror_uuid, int64_t local_pool_id, + const std::string &global_image_id) { + return new ImageReplayer(threads, image_deleter, image_sync_throttler, + local, local_mirror_uuid, local_pool_id, + global_image_id); + } + void destroy() { + delete this; + } + ImageReplayer(Threads *threads, std::shared_ptr image_deleter, ImageSyncThrottlerRef image_sync_throttler, @@ -96,6 +110,8 @@ public: librados::IoCtx &remote_io_ctx); void remove_remote_image(const std::string &remote_mirror_uuid, const std::string &remote_image_id); + void set_remote_images(const PeerImages &remote_images); + bool remote_images_empty() const; inline int64_t get_local_pool_id() const { @@ -204,37 +220,6 @@ protected: bool on_replay_interrupted(); private: - struct RemoteImage { - std::string mirror_uuid; - std::string image_id; - librados::IoCtx io_ctx; - - RemoteImage() { - } - RemoteImage(const std::string &mirror_uuid, - const std::string &image_id) - : mirror_uuid(mirror_uuid), image_id(image_id) { - } - RemoteImage(const std::string &mirror_uuid, - const std::string &image_id, - librados::IoCtx &io_ctx) - : mirror_uuid(mirror_uuid), image_id(image_id), io_ctx(io_ctx) { - } - - inline bool operator<(const RemoteImage &rhs) const { - if (mirror_uuid != rhs.mirror_uuid) { - return mirror_uuid < rhs.mirror_uuid; - } else { - return image_id < rhs.image_id; - } - } - inline bool operator==(const RemoteImage &rhs) const { - return (mirror_uuid == rhs.mirror_uuid && image_id == rhs.image_id); - } - }; - - typedef std::set RemoteImages; - typedef typename librbd::journal::TypeTraits::Journaler Journaler; typedef boost::optional OptionalState; @@ -274,8 +259,8 @@ private: std::shared_ptr m_image_deleter; ImageSyncThrottlerRef m_image_sync_throttler; - RemoteImages m_remote_images; - RemoteImage m_remote_image; + PeerImages m_remote_images; + PeerImage m_remote_image; RadosRef m_local; std::string m_local_mirror_uuid; diff --git a/src/tools/rbd_mirror/types.h b/src/tools/rbd_mirror/types.h index 617effd21cf..e0be7d5ba7c 100644 --- a/src/tools/rbd_mirror/types.h +++ b/src/tools/rbd_mirror/types.h @@ -51,6 +51,57 @@ std::ostream &operator<<(std::ostream &, const ImageId &image_id); typedef std::set ImageIds; +struct Peer { + std::string mirror_uuid; + librados::IoCtx io_ctx; + + Peer() { + } + + Peer(const std::string &mirror_uuid) : mirror_uuid(mirror_uuid) { + } + + Peer(const std::string &mirror_uuid, librados::IoCtx &io_ctx) + : mirror_uuid(mirror_uuid), io_ctx(io_ctx) { + } + + inline bool operator<(const Peer &rhs) const { + return mirror_uuid < rhs.mirror_uuid; + } + inline bool operator==(const Peer &rhs) const { + return mirror_uuid == rhs.mirror_uuid; + } +}; + +typedef std::set Peers; + +struct PeerImage : public Peer { + std::string image_id; + + PeerImage() { + } + PeerImage(const std::string &mirror_uuid, const std::string &image_id) + : Peer(mirror_uuid), image_id(image_id) { + } + PeerImage(const std::string &mirror_uuid, librados::IoCtx &io_ctx, + const std::string &image_id) + : Peer(mirror_uuid, io_ctx), image_id(image_id) { + } + + inline bool operator<(const PeerImage &rhs) const { + if (mirror_uuid != rhs.mirror_uuid) { + return mirror_uuid < rhs.mirror_uuid; + } else { + return image_id < rhs.image_id; + } + } + inline bool operator==(const PeerImage &rhs) const { + return (mirror_uuid == rhs.mirror_uuid && image_id == rhs.image_id); + } +}; + +typedef std::set PeerImages; + struct peer_t { peer_t() = default; peer_t(const std::string &uuid, const std::string &cluster_name, -- 2.39.5