]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: supply image id of new images to bootstrap state machine
authorJason Dillaman <dillaman@redhat.com>
Fri, 21 Apr 2017 00:54:44 +0000 (20:54 -0400)
committerJason Dillaman <dillaman@redhat.com>
Fri, 21 Apr 2017 02:38:18 +0000 (22:38 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc
src/test/rbd_mirror/image_replayer/test_mock_CreateImageRequest.cc
src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc
src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc
src/tools/rbd_mirror/image_replayer/CreateImageRequest.h

index cc1bfc55dc37cd4059f397f49b15b18de711b0d9..197166b8c8ee350df31adcb223a0ad76e2560a98 100644 (file)
@@ -132,8 +132,10 @@ struct CreateImageRequest<librbd::MockTestImageCtx> {
                                     const std::string &remote_mirror_uuid,
                                     const std::string &local_image_name,
                                     librbd::MockTestImageCtx *remote_image_ctx,
+                                   std::string *local_image_id,
                                     Context *on_finish) {
     assert(s_instance != nullptr);
+    *local_image_id = "local image id";
     s_instance->on_finish = on_finish;
     return s_instance;
   }
index 1cfff1879da472f12057ac0436a603cce2998287..9abbbcbfdf0ab133a6c9adfef6b014f4a551f4fc 100644 (file)
@@ -314,11 +314,12 @@ public:
                                          const std::string &remote_mirror_uuid,
                                          const std::string &local_image_name,
                                          librbd::MockTestImageCtx &mock_remote_image_ctx,
+                                        std::string *local_image_id,
                                          Context *on_finish) {
     return new MockCreateImageRequest(m_local_io_ctx, m_threads->work_queue,
                                       global_image_id, remote_mirror_uuid,
                                       local_image_name, &mock_remote_image_ctx,
-                                      on_finish);
+                                      local_image_id, on_finish);
   }
 
   librbd::ImageCtx *m_remote_image_ctx;
@@ -332,11 +333,14 @@ TEST_F(TestMockImageReplayerCreateImageRequest, Create) {
   expect_create_image(mock_create_request, m_local_io_ctx, 0);
 
   C_SaferCond ctx;
+  std::string local_image_id;
   MockCreateImageRequest *request = create_request("global uuid", "remote uuid",
                                                    "image name",
-                                                   mock_remote_image_ctx, &ctx);
+                                                   mock_remote_image_ctx,
+                                                  &local_image_id, &ctx);
   request->send();
   ASSERT_EQ(0, ctx.wait());
+  ASSERT_FALSE(local_image_id.empty());
 }
 
 TEST_F(TestMockImageReplayerCreateImageRequest, CreateError) {
@@ -347,9 +351,11 @@ TEST_F(TestMockImageReplayerCreateImageRequest, CreateError) {
   expect_create_image(mock_create_request, m_local_io_ctx, -EINVAL);
 
   C_SaferCond ctx;
+  std::string local_image_id;
   MockCreateImageRequest *request = create_request("global uuid", "remote uuid",
                                                    "image name",
-                                                   mock_remote_image_ctx, &ctx);
+                                                   mock_remote_image_ctx,
+                                                   &local_image_id, &ctx);
   request->send();
   ASSERT_EQ(-EINVAL, ctx.wait());
 }
@@ -390,12 +396,14 @@ TEST_F(TestMockImageReplayerCreateImageRequest, Clone) {
   expect_close_image(mock_close_image_request, mock_remote_parent_image_ctx, 0);
 
   C_SaferCond ctx;
+  std::string local_image_id;
   MockCreateImageRequest *request = create_request("global uuid", "remote uuid",
                                                    "image name",
                                                    mock_remote_clone_image_ctx,
-                                                   &ctx);
+                                                   &local_image_id, &ctx);
   request->send();
   ASSERT_EQ(0, ctx.wait());
+  ASSERT_FALSE(local_image_id.empty());
 }
 
 TEST_F(TestMockImageReplayerCreateImageRequest, CloneGetGlobalImageIdError) {
@@ -415,10 +423,11 @@ TEST_F(TestMockImageReplayerCreateImageRequest, CloneGetGlobalImageIdError) {
   expect_get_parent_global_image_id(m_remote_io_ctx, "global uuid", -ENOENT);
 
   C_SaferCond ctx;
+  std::string local_image_id;
   MockCreateImageRequest *request = create_request("global uuid", "remote uuid",
                                                    "image name",
                                                    mock_remote_clone_image_ctx,
-                                                   &ctx);
+                                                   &local_image_id, &ctx);
   request->send();
   ASSERT_EQ(-ENOENT, ctx.wait());
 }
@@ -441,10 +450,11 @@ TEST_F(TestMockImageReplayerCreateImageRequest, CloneGetLocalParentImageIdError)
   expect_mirror_image_get_image_id(m_local_io_ctx, "local parent id", -ENOENT);
 
   C_SaferCond ctx;
+  std::string local_image_id;
   MockCreateImageRequest *request = create_request("global uuid", "remote uuid",
                                                    "image name",
                                                    mock_remote_clone_image_ctx,
-                                                   &ctx);
+                                                   &local_image_id, &ctx);
   request->send();
   ASSERT_EQ(-ENOENT, ctx.wait());
 }
@@ -472,10 +482,11 @@ TEST_F(TestMockImageReplayerCreateImageRequest, CloneOpenRemoteParentError) {
                     m_remote_image_ctx->id, mock_remote_parent_image_ctx, -ENOENT);
 
   C_SaferCond ctx;
+  std::string local_image_id;
   MockCreateImageRequest *request = create_request("global uuid", "remote uuid",
                                                    "image name",
                                                    mock_remote_clone_image_ctx,
-                                                   &ctx);
+                                                   &local_image_id, &ctx);
   request->send();
   ASSERT_EQ(-ENOENT, ctx.wait());
 }
@@ -513,10 +524,11 @@ TEST_F(TestMockImageReplayerCreateImageRequest, CloneOpenLocalParentError) {
   expect_close_image(mock_close_image_request, mock_remote_parent_image_ctx, 0);
 
   C_SaferCond ctx;
+  std::string local_image_id;
   MockCreateImageRequest *request = create_request("global uuid", "remote uuid",
                                                    "image name",
                                                    mock_remote_clone_image_ctx,
-                                                   &ctx);
+                                                   &local_image_id, &ctx);
   request->send();
   ASSERT_EQ(-ENOENT, ctx.wait());
 }
@@ -556,10 +568,11 @@ TEST_F(TestMockImageReplayerCreateImageRequest, CloneSnapSetError) {
   expect_close_image(mock_close_image_request, mock_remote_parent_image_ctx, 0);
 
   C_SaferCond ctx;
+  std::string local_image_id;
   MockCreateImageRequest *request = create_request("global uuid", "remote uuid",
                                                    "image name",
                                                    mock_remote_clone_image_ctx,
-                                                   &ctx);
+                                                   &local_image_id, &ctx);
   request->send();
   ASSERT_EQ(-ENOENT, ctx.wait());
 }
@@ -600,10 +613,11 @@ TEST_F(TestMockImageReplayerCreateImageRequest, CloneError) {
   expect_close_image(mock_close_image_request, mock_remote_parent_image_ctx, 0);
 
   C_SaferCond ctx;
+  std::string local_image_id;
   MockCreateImageRequest *request = create_request("global uuid", "remote uuid",
                                                    "image name",
                                                    mock_remote_clone_image_ctx,
-                                                   &ctx);
+                                                   &local_image_id, &ctx);
   request->send();
   ASSERT_EQ(-EINVAL, ctx.wait());
 }
@@ -644,12 +658,14 @@ TEST_F(TestMockImageReplayerCreateImageRequest, CloneLocalParentCloseError) {
   expect_close_image(mock_close_image_request, mock_remote_parent_image_ctx, 0);
 
   C_SaferCond ctx;
+  std::string local_image_id;
   MockCreateImageRequest *request = create_request("global uuid", "remote uuid",
                                                    "image name",
                                                    mock_remote_clone_image_ctx,
-                                                   &ctx);
+                                                   &local_image_id, &ctx);
   request->send();
   ASSERT_EQ(0, ctx.wait());
+  ASSERT_FALSE(local_image_id.empty());
 }
 
 TEST_F(TestMockImageReplayerCreateImageRequest, CloneRemoteParentCloseError) {
@@ -688,12 +704,14 @@ TEST_F(TestMockImageReplayerCreateImageRequest, CloneRemoteParentCloseError) {
   expect_close_image(mock_close_image_request, mock_remote_parent_image_ctx, -EINVAL);
 
   C_SaferCond ctx;
+  std::string local_image_id;
   MockCreateImageRequest *request = create_request("global uuid", "remote uuid",
                                                    "image name",
                                                    mock_remote_clone_image_ctx,
-                                                   &ctx);
+                                                   &local_image_id, &ctx);
   request->send();
   ASSERT_EQ(0, ctx.wait());
+  ASSERT_FALSE(local_image_id.empty());
 }
 
 } // namespace image_replayer
index bba3114f936a040b21e5d3d2fe5f59fb83088831..3191daa672a95c0b91604d0ffa378796978c2af5 100644 (file)
@@ -440,7 +440,7 @@ void BootstrapRequest<I>::create_local_image() {
       this);
   CreateImageRequest<I> *request = CreateImageRequest<I>::create(
     m_local_io_ctx, m_work_queue, m_global_image_id, m_remote_mirror_uuid,
-    m_local_image_name, m_remote_image_ctx, ctx);
+    m_local_image_name, m_remote_image_ctx, &m_local_image_id, ctx);
   request->send();
 }
 
index 2ddf80b5dcad6ba9bcad7d53b4225eb4b94ca340..2c7a0f367e3d8597425c9f62f90672a72f21a02e 100644 (file)
@@ -34,12 +34,13 @@ CreateImageRequest<I>::CreateImageRequest(librados::IoCtx &local_io_ctx,
                                           const std::string &remote_mirror_uuid,
                                           const std::string &local_image_name,
                                           I *remote_image_ctx,
+                                         std::string *local_image_id,
                                           Context *on_finish)
   : m_local_io_ctx(local_io_ctx), m_work_queue(work_queue),
     m_global_image_id(global_image_id),
     m_remote_mirror_uuid(remote_mirror_uuid),
     m_local_image_name(local_image_name), m_remote_image_ctx(remote_image_ctx),
-    m_on_finish(on_finish) {
+    m_local_image_id(local_image_id), m_on_finish(on_finish) {
 }
 
 template <typename I>
@@ -74,12 +75,12 @@ void CreateImageRequest<I>::create_image() {
   image_options.set(RBD_IMAGE_OPTION_STRIPE_COUNT,
                     m_remote_image_ctx->stripe_count);
 
-  std::string id = librbd::util::generate_image_id(m_local_io_ctx);
+  *m_local_image_id = librbd::util::generate_image_id(m_local_io_ctx);;
 
   librbd::image::CreateRequest<I> *req = librbd::image::CreateRequest<I>::create(
-    m_local_io_ctx, m_local_image_name, id, m_remote_image_ctx->size,
-    image_options, m_global_image_id, m_remote_mirror_uuid, false,
-    m_remote_image_ctx->op_work_queue, ctx);
+    m_local_io_ctx, m_local_image_name, *m_local_image_id,
+    m_remote_image_ctx->size, image_options, m_global_image_id,
+    m_remote_mirror_uuid, false, m_remote_image_ctx->op_work_queue, ctx);
   req->send();
 }
 
@@ -289,14 +290,14 @@ void CreateImageRequest<I>::clone_image() {
   opts.set(RBD_IMAGE_OPTION_STRIPE_UNIT, m_remote_image_ctx->stripe_unit);
   opts.set(RBD_IMAGE_OPTION_STRIPE_COUNT, m_remote_image_ctx->stripe_count);
 
-  std::string id = librbd::util::generate_image_id(m_local_io_ctx);
+  *m_local_image_id = librbd::util::generate_image_id(m_local_io_ctx);;
 
   using klass = CreateImageRequest<I>;
   Context *ctx = create_context_callback<klass, &klass::handle_clone_image>(this);
 
   librbd::image::CloneRequest<I> *req = librbd::image::CloneRequest<I>::create(
-    m_local_parent_image_ctx, m_local_io_ctx, m_local_image_name, id, opts,
-    m_global_image_id, m_remote_mirror_uuid,
+    m_local_parent_image_ctx, m_local_io_ctx, m_local_image_name,
+    *m_local_image_id, opts, m_global_image_id, m_remote_mirror_uuid,
     m_remote_image_ctx->op_work_queue, ctx);
   req->send();
 }
index e920498f15fba34bf565802e6f69afa2a75b0b50..683a6d9a2cf96d6dfd0c2690b4071df1b817e17d 100644 (file)
@@ -27,10 +27,11 @@ public:
                                     const std::string &remote_mirror_uuid,
                                     const std::string &local_image_name,
                                     ImageCtxT *remote_image_ctx,
+                                   std::string *local_image_id,
                                     Context *on_finish) {
     return new CreateImageRequest(local_io_ctx, work_queue, global_image_id,
                                   remote_mirror_uuid, local_image_name,
-                                  remote_image_ctx, on_finish);
+                                  remote_image_ctx, local_image_id, on_finish);
   }
 
   CreateImageRequest(librados::IoCtx &local_io_ctx, ContextWQ *work_queue,
@@ -38,6 +39,7 @@ public:
                      const std::string &remote_mirror_uuid,
                      const std::string &local_image_name,
                      ImageCtxT *remote_image_ctx,
+                    std::string *local_image_id,
                      Context *on_finish);
 
   void send();
@@ -85,6 +87,7 @@ private:
   std::string m_remote_mirror_uuid;
   std::string m_local_image_name;
   ImageCtxT *m_remote_image_ctx;
+  std::string *m_local_image_id;
   Context *m_on_finish;
 
   librados::IoCtx m_remote_parent_io_ctx;