]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: retrieve local image mirror mode during prepare
authorJason Dillaman <dillaman@redhat.com>
Tue, 7 Jan 2020 01:48:34 +0000 (20:48 -0500)
committerJason Dillaman <dillaman@redhat.com>
Thu, 9 Jan 2020 15:48:52 +0000 (10:48 -0500)
The local image status was already being retrieved so tweak the state
machine to retrieve the mode as well.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/test/rbd_mirror/image_replayer/test_mock_PrepareLocalImageRequest.cc
src/tools/rbd_mirror/image_replayer/PrepareLocalImageRequest.cc
src/tools/rbd_mirror/image_replayer/PrepareLocalImageRequest.h

index b758a973c27c2b33462ea02d01fb06a093c02318..64843155123efa0c24d9df6b62667630cbab3a45 100644 (file)
@@ -101,9 +101,11 @@ public:
   }
 
   void expect_mirror_image_get(librados::IoCtx &io_ctx,
+                               cls::rbd::MirrorImageMode mode,
                                cls::rbd::MirrorImageState state,
                                const std::string &global_id, int r) {
     cls::rbd::MirrorImage mirror_image;
+    mirror_image.mode = mode;
     mirror_image.state = state;
     mirror_image.global_image_id = global_id;
 
@@ -137,6 +139,7 @@ TEST_F(TestMockImageReplayerPrepareLocalImageRequest, Success) {
                              0);
   expect_dir_get_name(m_local_io_ctx, "local image name", 0);
   expect_mirror_image_get(m_local_io_ctx,
+                          cls::rbd::MIRROR_IMAGE_MODE_JOURNAL,
                           cls::rbd::MIRROR_IMAGE_STATE_ENABLED,
                           "global image id", 0);
 
@@ -212,7 +215,9 @@ TEST_F(TestMockImageReplayerPrepareLocalImageRequest, MirrorImageError) {
   expect_get_mirror_image_id(mock_get_mirror_image_id_request, "local image id",
                              0);
   expect_dir_get_name(m_local_io_ctx, "local image name", 0);
-  expect_mirror_image_get(m_local_io_ctx, cls::rbd::MIRROR_IMAGE_STATE_DISABLED,
+  expect_mirror_image_get(m_local_io_ctx,
+                          cls::rbd::MIRROR_IMAGE_MODE_JOURNAL,
+                          cls::rbd::MIRROR_IMAGE_STATE_DISABLED,
                           "", -EINVAL);
 
   std::string local_image_id;
@@ -238,6 +243,7 @@ TEST_F(TestMockImageReplayerPrepareLocalImageRequest, TagOwnerError) {
                              0);
   expect_dir_get_name(m_local_io_ctx, "local image name", 0);
   expect_mirror_image_get(m_local_io_ctx,
+                          cls::rbd::MIRROR_IMAGE_MODE_JOURNAL,
                           cls::rbd::MIRROR_IMAGE_STATE_ENABLED,
                           "global image id", 0);
 
index 37e6bf4b74491b46746677b802335af56a0c5a96..52bbeb2cc87722752e6d2f1a4e378145ebbfcb90 100644 (file)
@@ -91,27 +91,27 @@ void PrepareLocalImageRequest<I>::handle_get_local_image_name(int r) {
     return;
   }
 
-  get_mirror_state();
+  get_mirror_image();
 }
 
 template <typename I>
-void PrepareLocalImageRequest<I>::get_mirror_state() {
+void PrepareLocalImageRequest<I>::get_mirror_image() {
   dout(10) << dendl;
 
   librados::ObjectReadOperation op;
   librbd::cls_client::mirror_image_get_start(&op, *m_local_image_id);
 
   m_out_bl.clear();
-  librados::AioCompletion *aio_comp = create_rados_callback<
+  auto aio_comp = create_rados_callback<
     PrepareLocalImageRequest<I>,
-    &PrepareLocalImageRequest<I>::handle_get_mirror_state>(this);
+    &PrepareLocalImageRequest<I>::handle_get_mirror_image>(this);
   int r = m_io_ctx.aio_operate(RBD_MIRRORING, aio_comp, &op, &m_out_bl);
   ceph_assert(r == 0);
   aio_comp->release();
 }
 
 template <typename I>
-void PrepareLocalImageRequest<I>::handle_get_mirror_state(int r) {
+void PrepareLocalImageRequest<I>::handle_get_mirror_image(int r) {
   dout(10) << ": r=" << r << dendl;
 
   cls::rbd::MirrorImage mirror_image;
@@ -131,7 +131,18 @@ void PrepareLocalImageRequest<I>::handle_get_mirror_state(int r) {
   // delete a partially formed image
   // (e.g. MIRROR_IMAGE_STATE_CREATING/DELETING)
 
-  get_tag_owner();
+  switch (mirror_image.mode) {
+  case cls::rbd::MIRROR_IMAGE_MODE_JOURNAL:
+    get_tag_owner();
+    break;
+  case cls::rbd::MIRROR_IMAGE_MODE_SNAPSHOT:
+    // TODO
+  default:
+    derr << "unsupported mirror image mode " << mirror_image.mode << " "
+         << "for image " << m_global_image_id << dendl;
+    finish(-EOPNOTSUPP);
+    break;
+  }
 }
 
 template <typename I>
index 3417dd960a10e37b9876eedf8300c2f6b054c505..f279f1867dde89caa7d8bd7a2c9a6cd52fecc3c4 100644 (file)
@@ -59,10 +59,13 @@ private:
    * GET_LOCAL_IMAGE_NAME
    *    |
    *    v
-   * GET_MIRROR_STATE
+   * GET_MIRROR_IMAGE
    *    |
-   *    v
-   * <finish>
+   *    | (journal)
+   *    \-----------> GET_TAG_OWNER
+   *                      |
+   *                      v
+   *                  <finish>
 
    * @endverbatim
    */
@@ -83,8 +86,8 @@ private:
   void get_local_image_name();
   void handle_get_local_image_name(int r);
 
-  void get_mirror_state();
-  void handle_get_mirror_state(int r);
+  void get_mirror_image();
+  void handle_get_mirror_image(int r);
 
   void get_tag_owner();
   void handle_get_tag_owner(int r);