]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rbd-mirror: store remote image ctx in state builder
authorJason Dillaman <dillaman@redhat.com>
Mon, 27 Jan 2020 19:03:07 +0000 (14:03 -0500)
committerJason Dillaman <dillaman@redhat.com>
Thu, 30 Jan 2020 15:26:36 +0000 (10:26 -0500)
The snapshot-based mirroring logic will need access to the remote
image during replay.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc
src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc
src/tools/rbd_mirror/image_replayer/BootstrapRequest.h
src/tools/rbd_mirror/image_replayer/StateBuilder.cc
src/tools/rbd_mirror/image_replayer/StateBuilder.h
src/tools/rbd_mirror/image_replayer/journal/StateBuilder.cc
src/tools/rbd_mirror/image_replayer/journal/StateBuilder.h
src/tools/rbd_mirror/image_replayer/snapshot/StateBuilder.cc
src/tools/rbd_mirror/image_replayer/snapshot/StateBuilder.h

index 24822f6e493004d096e309c3b823ba276ff92ec7..a765c46067212dd1e5c8d9a45ece4f8a5084cad8 100644 (file)
@@ -240,6 +240,7 @@ struct StateBuilder<librbd::MockTestImageCtx> {
   MockBaseRequest mock_base_request;
 
   librbd::MockTestImageCtx* local_image_ctx = nullptr;
+  librbd::MockTestImageCtx* remote_image_ctx = nullptr;
   std::string local_image_id;
   std::string remote_mirror_uuid;
   std::string remote_image_id;
@@ -261,10 +262,9 @@ struct StateBuilder<librbd::MockTestImageCtx> {
   MOCK_CONST_METHOD0(is_local_primary, bool());
   MOCK_CONST_METHOD0(is_linked, bool());
 
-  MOCK_METHOD6(create_local_image_request,
+  MOCK_METHOD5(create_local_image_request,
                BaseRequest*(Threads<librbd::MockTestImageCtx>*,
                             librados::IoCtx&,
-                            librbd::MockTestImageCtx*,
                             const std::string&,
                             ProgressContext*,
                             Context*));
@@ -428,8 +428,8 @@ public:
   void expect_create_local_image(MockStateBuilder& mock_state_builder,
                                  const std::string& local_image_id, int r) {
     EXPECT_CALL(mock_state_builder,
-                create_local_image_request(_, _, _, _, _, _))
-      .WillOnce(WithArg<5>(
+                create_local_image_request(_, _, _, _, _))
+      .WillOnce(WithArg<4>(
         Invoke([this, &mock_state_builder, local_image_id, r](Context* ctx) {
           if (r >= 0) {
             mock_state_builder.local_image_id = local_image_id;
index bfa252275c789b99df7c42dbd69d796020655a75..739a5599f1b3d52af141ea386c4723226ef5a045 100644 (file)
@@ -78,11 +78,6 @@ BootstrapRequest<I>::BootstrapRequest(
   dout(10) << dendl;
 }
 
-template <typename I>
-BootstrapRequest<I>::~BootstrapRequest() {
-  ceph_assert(m_remote_image_ctx == nullptr);
-}
-
 template <typename I>
 bool BootstrapRequest<I>::is_syncing() const {
   std::lock_guard locker{m_lock};
@@ -215,12 +210,13 @@ void BootstrapRequest<I>::open_remote_image() {
 
   update_progress("OPEN_REMOTE_IMAGE");
 
-  Context *ctx = create_context_callback<
-    BootstrapRequest<I>, &BootstrapRequest<I>::handle_open_remote_image>(
-      this);
+  auto ctx = create_context_callback<
+    BootstrapRequest<I>,
+    &BootstrapRequest<I>::handle_open_remote_image>(this);
+  ceph_assert(*m_state_builder != nullptr);
   OpenImageRequest<I> *request = OpenImageRequest<I>::create(
-    m_remote_io_ctx, &m_remote_image_ctx, remote_image_id, false,
-    ctx);
+    m_remote_io_ctx, &(*m_state_builder)->remote_image_ctx, remote_image_id,
+    false, ctx);
   request->send();
 }
 
@@ -228,14 +224,14 @@ template <typename I>
 void BootstrapRequest<I>::handle_open_remote_image(int r) {
   dout(15) << "r=" << r << dendl;
 
+  ceph_assert(*m_state_builder != nullptr);
   if (r < 0) {
     derr << "failed to open remote image: " << cpp_strerror(r) << dendl;
-    ceph_assert(m_remote_image_ctx == nullptr);
+    ceph_assert((*m_state_builder)->remote_image_ctx == nullptr);
     finish(r);
     return;
   }
 
-  ceph_assert(*m_state_builder != nullptr);
   if ((*m_state_builder)->local_image_id.empty()) {
     create_local_image();
     return;
@@ -343,8 +339,7 @@ void BootstrapRequest<I>::create_local_image() {
     BootstrapRequest<I>,
     &BootstrapRequest<I>::handle_create_local_image>(this);
   auto request = (*m_state_builder)->create_local_image_request(
-    m_threads, m_local_io_ctx, m_remote_image_ctx, m_global_image_id,
-    m_progress_ctx, ctx);
+    m_threads, m_local_io_ctx, m_global_image_id, m_progress_ctx, ctx);
   request->send();
 }
 
@@ -387,7 +382,7 @@ void BootstrapRequest<I>::image_sync() {
   Context *ctx = create_context_callback<
     BootstrapRequest<I>, &BootstrapRequest<I>::handle_image_sync>(this);
   m_image_sync = ImageSync<I>::create(
-    m_threads, state_builder->local_image_ctx, m_remote_image_ctx,
+    m_threads, state_builder->local_image_ctx, state_builder->remote_image_ctx,
     m_local_mirror_uuid, sync_point_handler, m_instance_watcher,
     m_progress_ctx, ctx);
   m_image_sync->get();
@@ -427,11 +422,12 @@ void BootstrapRequest<I>::close_remote_image() {
 
   update_progress("CLOSE_REMOTE_IMAGE");
 
-  Context *ctx = create_context_callback<
-    BootstrapRequest<I>, &BootstrapRequest<I>::handle_close_remote_image>(
-      this);
-  CloseImageRequest<I> *request = CloseImageRequest<I>::create(
-    &m_remote_image_ctx, ctx);
+  auto ctx = create_context_callback<
+    BootstrapRequest<I>,
+    &BootstrapRequest<I>::handle_close_remote_image>(this);
+  ceph_assert(*m_state_builder != nullptr);
+  auto request = CloseImageRequest<I>::create(
+    &(*m_state_builder)->remote_image_ctx, ctx);
   request->send();
 }
 
index 7d94d847c0d4999ca64122d8af5673bdffd8be3c..cc15a91334b8a758162f6c6a33faa4b42e44e75b 100644 (file)
@@ -73,7 +73,6 @@ public:
       StateBuilder<ImageCtxT>** state_builder,
       bool* do_resync,
       Context* on_finish);
-  ~BootstrapRequest() override;
 
   bool is_syncing() const;
 
@@ -139,7 +138,6 @@ private:
   mutable ceph::mutex m_lock;
   bool m_canceled = false;
 
-  ImageCtxT *m_remote_image_ctx = nullptr;
   int m_ret_val = 0;
 
   std::string m_local_image_name;
index 4c543b7880aee650ef42acf4eaf2f6620648be5e..1e8420bbbc8c411bf3785853d398de6e91575024 100644 (file)
@@ -31,6 +31,7 @@ StateBuilder<I>::StateBuilder(const std::string& global_image_id)
 template <typename I>
 StateBuilder<I>::~StateBuilder() {
   ceph_assert(local_image_ctx == nullptr);
+  ceph_assert(remote_image_ctx == nullptr);
   ceph_assert(m_sync_point_handler == nullptr);
 }
 
index 192ffca44e8898f3b6c510bd6a26e1eea3bd698c..c6bf3ea8fd0418ae92489e1378fae950d3656986 100644 (file)
@@ -52,7 +52,6 @@ public:
   virtual BaseRequest* create_local_image_request(
       Threads<ImageCtxT>* threads,
       librados::IoCtx& local_io_ctx,
-      ImageCtxT* remote_image_ctx,
       const std::string& global_image_id,
       ProgressContext* progress_ctx,
       Context* on_finish) = 0;
@@ -81,6 +80,7 @@ public:
   std::string remote_image_id;
   librbd::mirror::PromotionState remote_promotion_state =
     librbd::mirror::PROMOTION_STATE_NON_PRIMARY;
+  ImageCtxT* remote_image_ctx = nullptr;
 
 protected:
   image_sync::SyncPointHandler* m_sync_point_handler = nullptr;
index 7372475d87078df05b464ea3fb54c927e1ec42a8..01d51e7d56985cd3ddbd65bd50e8b9d9eb5122f3 100644 (file)
@@ -71,12 +71,11 @@ template <typename I>
 BaseRequest* StateBuilder<I>::create_local_image_request(
     Threads<I>* threads,
     librados::IoCtx& local_io_ctx,
-    I* remote_image_ctx,
     const std::string& global_image_id,
     ProgressContext* progress_ctx,
     Context* on_finish) {
   return CreateLocalImageRequest<I>::create(
-    threads, local_io_ctx, remote_image_ctx, this->global_image_id,
+    threads, local_io_ctx, this->remote_image_ctx, this->global_image_id,
     progress_ctx, this, on_finish);
 }
 
index 868260699f2014fb58057204ad4356fc50f146c2..ee0743d3b909b0dff660604528413af5b80d6710 100644 (file)
@@ -45,7 +45,6 @@ public:
   BaseRequest* create_local_image_request(
       Threads<ImageCtxT>* threads,
       librados::IoCtx& local_io_ctx,
-      ImageCtxT* remote_image_ctx,
       const std::string& global_image_id,
       ProgressContext* progress_ctx,
       Context* on_finish) override;
index 018574dec72b2ff86260add6e76c9d0b8880d433..471a8a7a638c09c1f8ab1588a6567802bfe3e76d 100644 (file)
@@ -59,7 +59,6 @@ template <typename I>
 BaseRequest* StateBuilder<I>::create_local_image_request(
     Threads<I>* threads,
     librados::IoCtx& local_io_ctx,
-    I* remote_image_ctx,
     const std::string& global_image_id,
     ProgressContext* progress_ctx,
     Context* on_finish) {
index 105e3a0134893490fe5c05ee13885fa81d9ce71c..49e2f66d853462d0c86b0a5c0c133af19d3c8d32 100644 (file)
@@ -39,7 +39,6 @@ public:
   BaseRequest* create_local_image_request(
       Threads<ImageCtxT>* threads,
       librados::IoCtx& local_io_ctx,
-      ImageCtxT* remote_image_ctx,
       const std::string& global_image_id,
       ProgressContext* progress_ctx,
       Context* on_finish) override;