]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rbd-mirror: add set_remote_images method to ImageReplayer
authorMykola Golub <mgolub@mirantis.com>
Fri, 10 Mar 2017 16:03:52 +0000 (17:03 +0100)
committerMykola Golub <mgolub@mirantis.com>
Fri, 7 Apr 2017 12:15:07 +0000 (14:15 +0200)
Signed-off-by: Mykola Golub <mgolub@mirantis.com>
src/tools/rbd_mirror/ImageReplayer.cc
src/tools/rbd_mirror/ImageReplayer.h
src/tools/rbd_mirror/types.h

index 0a58a6b72c6b9bdd27cce3941e5b89abfdda43cf..c89e9305b07442063e0f858742e2a08ed5fb47a2 100644 (file)
@@ -326,7 +326,7 @@ void ImageReplayer<I>::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<I>::remove_remote_image(const std::string &mirror_uuid,
   m_remote_images.erase({mirror_uuid, image_id});
 }
 
+template <typename I>
+void ImageReplayer<I>::set_remote_images(const PeerImages &remote_images) {
+  Mutex::Locker locker(m_lock);
+  m_remote_images = remote_images;
+}
+
 template <typename I>
 bool ImageReplayer<I>::remote_images_empty() const {
   Mutex::Locker locker(m_lock);
index 07ed7f8ada4cb37b0a8d2b1fb03b7f3bebf19e5f..81d16e1be101e0f44a25f538dc8a9e96d39f7798 100644 (file)
@@ -69,6 +69,20 @@ public:
     STATE_STOPPED,
   };
 
+  static ImageReplayer *create(
+    Threads<librbd::ImageCtx> *threads,
+    std::shared_ptr<ImageDeleter> image_deleter,
+    ImageSyncThrottlerRef<ImageCtxT> 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<librbd::ImageCtx> *threads,
                 std::shared_ptr<ImageDeleter> image_deleter,
                 ImageSyncThrottlerRef<ImageCtxT> 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<RemoteImage> RemoteImages;
-
   typedef typename librbd::journal::TypeTraits<ImageCtxT>::Journaler Journaler;
   typedef boost::optional<State> OptionalState;
 
@@ -274,8 +259,8 @@ private:
   std::shared_ptr<ImageDeleter> m_image_deleter;
   ImageSyncThrottlerRef<ImageCtxT> 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;
index 617effd21cf0df0052864a7f8ea965b80219e9be..e0be7d5ba7cd56605358c78c74c84fe6af80f717 100644 (file)
@@ -51,6 +51,57 @@ std::ostream &operator<<(std::ostream &, const ImageId &image_id);
 
 typedef std::set<ImageId> 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<Peer> 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<PeerImage> PeerImages;
+
 struct peer_t {
   peer_t() = default;
   peer_t(const std::string &uuid, const std::string &cluster_name,