]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: use 'open snap by id' in deep copy image copy request
authorMykola Golub <mgolub@suse.com>
Fri, 25 May 2018 13:36:13 +0000 (16:36 +0300)
committerJason Dillaman <dillaman@redhat.com>
Tue, 14 Aug 2018 22:29:45 +0000 (18:29 -0400)
Signed-off-by: Mykola Golub <mgolub@suse.com>
src/librbd/deep_copy/ImageCopyRequest.cc
src/librbd/deep_copy/ImageCopyRequest.h
src/test/librbd/deep_copy/test_mock_ImageCopyRequest.cc

index e537ce13ce4da604132b54801e1d50f6112e2740..651937fcd36ff09dd9b042c0cdb827f6e04ac918 100644 (file)
@@ -8,7 +8,6 @@
 #include "librbd/deep_copy/Utils.h"
 #include "librbd/image/CloseRequest.h"
 #include "librbd/image/OpenRequest.h"
-#include "librbd/image/SetSnapRequest.h"
 #include "osdc/Striper.h"
 
 #define dout_subsys ceph_subsys_rbd
@@ -62,6 +61,7 @@ void ImageCopyRequest<I>::cancel() {
 
 template <typename I>
 void ImageCopyRequest<I>::send_open_parent() {
+  ParentSpec parent_spec;
   {
     RWLock::RLocker snap_locker(m_src_image_ctx->snap_lock);
     RWLock::RLocker parent_locker(m_src_image_ctx->parent_lock);
@@ -72,24 +72,24 @@ void ImageCopyRequest<I>::send_open_parent() {
         ldout(m_cct, 20) << "could not find parent info for snap id " << snap_id
                          << dendl;
     } else {
-      m_parent_spec = parent_info->spec;
+      parent_spec = parent_info->spec;
     }
   }
 
-  if (m_parent_spec.pool_id == -1) {
+  if (parent_spec.pool_id == -1) {
     send_object_copies();
     return;
   }
 
-  ldout(m_cct, 20) << "pool_id=" << m_parent_spec.pool_id << ", image_id="
-                   << m_parent_spec.image_id << ", snap_id="
-                   << m_parent_spec.snap_id << dendl;
+  ldout(m_cct, 20) << "pool_id=" << parent_spec.pool_id << ", image_id="
+                   << parent_spec.image_id << ", snap_id="
+                   << parent_spec.snap_id << dendl;
 
   librados::Rados rados(m_src_image_ctx->md_ctx);
   librados::IoCtx parent_io_ctx;
-  int r = rados.ioctx_create2(m_parent_spec.pool_id, parent_io_ctx);
+  int r = rados.ioctx_create2(parent_spec.pool_id, parent_io_ctx);
   if (r < 0) {
-    lderr(m_cct) << "failed to access parent pool (id=" << m_parent_spec.pool_id
+    lderr(m_cct) << "failed to access parent pool (id=" << parent_spec.pool_id
                  << "): " << cpp_strerror(r) << dendl;
     finish(r);
     return;
@@ -98,9 +98,8 @@ void ImageCopyRequest<I>::send_open_parent() {
   // TODO support clone v2 parent namespaces
   parent_io_ctx.set_namespace(m_src_image_ctx->md_ctx.get_namespace());
 
-  m_src_parent_image_ctx = I::create("", m_parent_spec.image_id, nullptr,
-                                     parent_io_ctx, true);
-
+  m_src_parent_image_ctx = I::create("", parent_spec.image_id,
+                                     parent_spec.snap_id, parent_io_ctx, true);
   auto ctx = create_context_callback<
     ImageCopyRequest<I>, &ImageCopyRequest<I>::handle_open_parent>(this);
 
@@ -120,31 +119,6 @@ void ImageCopyRequest<I>::handle_open_parent(int r) {
     return;
   }
 
-  send_set_parent_snap();
-}
-
-template <typename I>
-void ImageCopyRequest<I>::send_set_parent_snap() {
-  ldout(m_cct, 20) << dendl;
-
-  auto ctx = create_context_callback<
-    ImageCopyRequest<I>, &ImageCopyRequest<I>::handle_set_parent_snap>(this);
-  auto req = image::SetSnapRequest<I>::create(*m_src_parent_image_ctx,
-                                              m_parent_spec.snap_id, ctx);
-  req->send();
-}
-
-template <typename I>
-void ImageCopyRequest<I>::handle_set_parent_snap(int r) {
-  ldout(m_cct, 20) << "r=" << r << dendl;
-
-  if (r < 0) {
-    lderr(m_cct) << "failed to set parent snap: " << cpp_strerror(r) << dendl;
-    m_ret_val = r;
-    send_close_parent();
-    return;
-  }
-
   send_object_copies();
 }
 
index c8fc08169f34946a7239b141f1b14bec07c30157..c7d020785673acc8bf0a804e0e6a312b4dca33d3 100644 (file)
@@ -59,9 +59,6 @@ private:
    *    v
    * OPEN_PARENT (skip if not needed)
    *    |
-   *    v
-   * SET_PARENT_SNAP (skip if not needed)
-   *    |
    *    |      . . . . .
    *    |      .       .  (parallel execution of
    *    v      v       .   multiple objects at once)
@@ -98,15 +95,11 @@ private:
   bool m_updating_progress = false;
   SnapMap m_snap_map;
   int m_ret_val = 0;
-  ParentSpec m_parent_spec;
   ImageCtxT *m_src_parent_image_ctx = nullptr;
 
   void send_open_parent();
   void handle_open_parent(int r);
 
-  void send_set_parent_snap();
-  void handle_set_parent_snap(int r);
-
   void send_object_copies();
   void send_next_object_copy();
   void handle_object_copy(uint64_t object_no, int r);
index 602a12f04756bca0f8f652fe8769ad8af48b73a8..04d93f4e025b045da9853a8392339fcb9dd375e1 100644 (file)
@@ -10,7 +10,6 @@
 #include "librbd/deep_copy/ObjectCopyRequest.h"
 #include "librbd/image/CloseRequest.h"
 #include "librbd/image/OpenRequest.h"
-#include "librbd/image/SetSnapRequest.h"
 #include "librbd/internal.h"
 #include "test/librados_test_stub/MockTestMemIoCtxImpl.h"
 #include "test/librbd/mock/MockImageCtx.h"
@@ -25,7 +24,7 @@ struct MockTestImageCtx : public librbd::MockImageCtx {
   static MockTestImageCtx* s_instance;
   static MockTestImageCtx* create(const std::string &image_name,
                                   const std::string &image_id,
-                                  const char *snap, librados::IoCtx& p,
+                                  librados::snap_t snap_id, librados::IoCtx& p,
                                   bool read_only) {
     assert(s_instance != nullptr);
     return s_instance;
@@ -119,26 +118,6 @@ struct OpenRequest<MockTestImageCtx> {
 
 OpenRequest<MockTestImageCtx>* OpenRequest<MockTestImageCtx>::s_instance = nullptr;
 
-template <>
-struct SetSnapRequest<MockTestImageCtx> {
-  Context* on_finish = nullptr;
-  static SetSnapRequest* s_instance;
-  static SetSnapRequest* create(MockTestImageCtx &image_ctx, uint64_t snap_id,
-                                Context *on_finish) {
-    assert(s_instance != nullptr);
-    s_instance->on_finish = on_finish;
-    return s_instance;
-  }
-
-  MOCK_METHOD0(send, void());
-
-  SetSnapRequest() {
-    s_instance = this;
-  }
-};
-
-SetSnapRequest<MockTestImageCtx>* SetSnapRequest<MockTestImageCtx>::s_instance = nullptr;
-
 } // namespace image
 
 } // namespace librbd