]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: clone state machine should accept snapshot namespace
authorJason Dillaman <dillaman@redhat.com>
Wed, 29 Jan 2020 22:27:22 +0000 (17:27 -0500)
committerJason Dillaman <dillaman@redhat.com>
Thu, 30 Jan 2020 15:26:36 +0000 (10:26 -0500)
It currently assumes that you can only create snapshots from user
snapshot namespaces.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/api/Image.cc
src/librbd/api/Migration.cc
src/librbd/image/CloneRequest.cc
src/librbd/image/CloneRequest.h
src/librbd/internal.cc
src/test/librbd/image/test_mock_CloneRequest.cc
src/test/rbd_mirror/image_replayer/test_mock_CreateImageRequest.cc
src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc

index 2df690e25ada1e5a4a2baf974f96b7c75c5cc709..c0bacaf675ec0bfd044e76f4c21cac241bd0e090 100644 (file)
@@ -614,7 +614,7 @@ int Image<I>::deep_copy(I *src, librados::IoCtx& dest_md_ctx,
     C_SaferCond ctx;
     std::string dest_id = util::generate_image_id(dest_md_ctx);
     auto *req = image::CloneRequest<I>::create(
-      config, parent_io_ctx, parent_spec.image_id, "", parent_spec.snap_id,
+      config, parent_io_ctx, parent_spec.image_id, "", {}, parent_spec.snap_id,
       dest_md_ctx, destname, dest_id, opts, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL,
       "", "", src->op_work_queue, &ctx);
     req->send();
index cbdfd5b4666ce9195f2c54294102e2eff7557d79..73294503217710c9e4052ef80ccf9a86a8243f30 100644 (file)
@@ -1244,7 +1244,7 @@ int Migration<I>::create_dst_image() {
     }
 
     auto *req = image::CloneRequest<I>::create(
-      config, parent_io_ctx, parent_spec.image_id, "", parent_spec.snap_id,
+      config, parent_io_ctx, parent_spec.image_id, "", {}, parent_spec.snap_id,
       m_dst_io_ctx, m_dst_image_name, m_dst_image_id, m_image_options,
       cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "", op_work_queue, &on_create);
     req->send();
index 02793da61f106941865771d00bb459688989d450..cdf1fd7a911efceea9fc25a8c3b53cf9230f7fe5 100644 (file)
@@ -30,21 +30,24 @@ using util::create_context_callback;
 using util::create_async_context_callback;
 
 template <typename I>
-CloneRequest<I>::CloneRequest(ConfigProxy& config,
-                              IoCtx& parent_io_ctx,
-                              const std::string& parent_image_id,
-                              const std::string& parent_snap_name,
-                              uint64_t parent_snap_id,
-                              IoCtx &c_ioctx,
-                             const std::string &c_name,
-                             const std::string &c_id,
-                             ImageOptions c_options,
-                              cls::rbd::MirrorImageMode mirror_image_mode,
-                             const std::string &non_primary_global_image_id,
-                             const std::string &primary_mirror_uuid,
-                             ContextWQ *op_work_queue, Context *on_finish)
+CloneRequest<I>::CloneRequest(
+    ConfigProxy& config,
+    IoCtx& parent_io_ctx,
+    const std::string& parent_image_id,
+    const std::string& parent_snap_name,
+    const cls::rbd::SnapshotNamespace& parent_snap_namespace,
+    uint64_t parent_snap_id,
+    IoCtx &c_ioctx,
+    const std::string &c_name,
+    const std::string &c_id,
+    ImageOptions c_options,
+    cls::rbd::MirrorImageMode mirror_image_mode,
+    const std::string &non_primary_global_image_id,
+    const std::string &primary_mirror_uuid,
+    ContextWQ *op_work_queue, Context *on_finish)
   : m_config(config), m_parent_io_ctx(parent_io_ctx),
     m_parent_image_id(parent_image_id), m_parent_snap_name(parent_snap_name),
+    m_parent_snap_namespace(parent_snap_namespace),
     m_parent_snap_id(parent_snap_id), m_ioctx(c_ioctx), m_name(c_name),
     m_id(c_id), m_opts(c_options), m_mirror_image_mode(mirror_image_mode),
     m_non_primary_global_image_id(non_primary_global_image_id),
@@ -138,8 +141,10 @@ void CloneRequest<I>::open_parent() {
                                    m_parent_io_ctx, true);
   } else {
     m_parent_image_ctx = I::create("", m_parent_image_id,
-                                   m_parent_snap_name.c_str(), m_parent_io_ctx,
+                                   m_parent_snap_name.c_str(),
+                                   m_parent_io_ctx,
                                    true);
+    m_parent_image_ctx->snap_namespace = m_parent_snap_namespace;
   }
 
   Context *ctx = create_context_callback<
index 1bad9945da9cf816ed927f2f4ca0b8eb22b2667e..c7bfc823c0db11782b966642ce9cb391eb4b3bd3 100644 (file)
@@ -19,26 +19,29 @@ namespace image {
 template <typename ImageCtxT = ImageCtx>
 class CloneRequest {
 public:
-  static CloneRequest *create(ConfigProxy& config, IoCtx& parent_io_ctx,
-                              const std::string& parent_image_id,
-                              const std::string& parent_snap_name,
-                              uint64_t parent_snap_id,
-                              IoCtx &c_ioctx, const std::string &c_name,
-                              const std::string &c_id, ImageOptions c_options,
-                              cls::rbd::MirrorImageMode mirror_image_mode,
-                             const std::string &non_primary_global_image_id,
-                             const std::string &primary_mirror_uuid,
-                             ContextWQ *op_work_queue, Context *on_finish) {
+  static CloneRequest *create(
+      ConfigProxy& config, IoCtx& parent_io_ctx,
+      const std::string& parent_image_id,
+      const std::string& parent_snap_name,
+      const cls::rbd::SnapshotNamespace& parent_snap_namespace,
+      uint64_t parent_snap_id,
+      IoCtx &c_ioctx, const std::string &c_name,
+      const std::string &c_id, ImageOptions c_options,
+      cls::rbd::MirrorImageMode mirror_image_mode,
+      const std::string &non_primary_global_image_id,
+      const std::string &primary_mirror_uuid,
+      ContextWQ *op_work_queue, Context *on_finish) {
     return new CloneRequest(config, parent_io_ctx, parent_image_id,
-                            parent_snap_name, parent_snap_id, c_ioctx, c_name,
-                            c_id, c_options, mirror_image_mode,
-                            non_primary_global_image_id, primary_mirror_uuid,
-                            op_work_queue, on_finish);
+                            parent_snap_name, parent_snap_namespace,
+                            parent_snap_id, c_ioctx, c_name, c_id, c_options,
+                            mirror_image_mode, non_primary_global_image_id,
+                            primary_mirror_uuid, op_work_queue, on_finish);
   }
 
   CloneRequest(ConfigProxy& config, IoCtx& parent_io_ctx,
                const std::string& parent_image_id,
                const std::string& parent_snap_name,
+               const cls::rbd::SnapshotNamespace& parent_snap_namespace,
                uint64_t parent_snap_id,
                IoCtx &c_ioctx, const std::string &c_name,
                const std::string &c_id, ImageOptions c_options,
@@ -101,6 +104,7 @@ private:
   IoCtx &m_parent_io_ctx;
   std::string m_parent_image_id;
   std::string m_parent_snap_name;
+  cls::rbd::SnapshotNamespace m_parent_snap_namespace;
   uint64_t m_parent_snap_id;
   ImageCtxT *m_parent_image_ctx;
 
index 97f3205e6ef21634e62f40d167446ff7a1a82164..662bfa18fa65a95525bded10eb0d46559404fd9a 100644 (file)
@@ -781,7 +781,8 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) {
 
     C_SaferCond cond;
     auto *req = image::CloneRequest<>::create(
-      config, p_ioctx, parent_id, p_snap_name, CEPH_NOSNAP, c_ioctx, c_name,
+      config, p_ioctx, parent_id, p_snap_name,
+      {cls::rbd::UserSnapshotNamespace{}}, CEPH_NOSNAP, c_ioctx, c_name,
       clone_id, c_opts, cls::rbd::MIRROR_IMAGE_MODE_JOURNAL,
       non_primary_global_image_id, primary_mirror_uuid, op_work_queue, &cond);
     req->send();
index c9af674bad0f619684982af4478cfb85783f378e..46c4ce96e8672c6a39e47d96ed1261926f9eeb81 100644 (file)
@@ -399,7 +399,7 @@ TEST_F(TestMockImageCloneRequest, SuccessV1) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123,
                                   m_ioctx, "clone name", "clone id", clone_opts,
                                   cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "",
                                   image_ctx->op_work_queue, &ctx);
@@ -449,7 +449,7 @@ TEST_F(TestMockImageCloneRequest, SuccessV2) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123,
                                   m_ioctx, "clone name", "clone id", clone_opts,
                                   cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "",
                                   image_ctx->op_work_queue, &ctx);
@@ -499,7 +499,7 @@ TEST_F(TestMockImageCloneRequest, SuccessAuto) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123,
                                   m_ioctx, "clone name", "clone id", clone_opts,
                                   cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "",
                                   image_ctx->op_work_queue, &ctx);
@@ -518,7 +518,7 @@ TEST_F(TestMockImageCloneRequest, OpenParentError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123,
                                   m_ioctx, "clone name", "clone id", clone_opts,
                                   cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "",
                                   image_ctx->op_work_queue, &ctx);
@@ -545,7 +545,7 @@ TEST_F(TestMockImageCloneRequest, CreateError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123,
                                   m_ioctx, "clone name", "clone id", clone_opts,
                                   cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "",
                                   image_ctx->op_work_queue, &ctx);
@@ -577,7 +577,7 @@ TEST_F(TestMockImageCloneRequest, OpenError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123,
                                   m_ioctx, "clone name", "clone id", clone_opts,
                                   cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "",
                                   image_ctx->op_work_queue, &ctx);
@@ -614,7 +614,7 @@ TEST_F(TestMockImageCloneRequest, AttachParentError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123,
                                   m_ioctx, "clone name", "clone id", clone_opts,
                                   cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "",
                                   image_ctx->op_work_queue, &ctx);
@@ -654,7 +654,7 @@ TEST_F(TestMockImageCloneRequest, AttachChildError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123,
                                   m_ioctx, "clone name", "clone id", clone_opts,
                                   cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "",
                                   image_ctx->op_work_queue, &ctx);
@@ -696,7 +696,7 @@ TEST_F(TestMockImageCloneRequest, MetadataListError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123,
                                   m_ioctx, "clone name", "clone id", clone_opts,
                                   cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "",
                                   image_ctx->op_work_queue, &ctx);
@@ -739,7 +739,7 @@ TEST_F(TestMockImageCloneRequest, MetadataSetError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123,
                                   m_ioctx, "clone name", "clone id", clone_opts,
                                   cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "",
                                   image_ctx->op_work_queue, &ctx);
@@ -784,7 +784,7 @@ TEST_F(TestMockImageCloneRequest, GetMirrorModeError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123,
                                   m_ioctx, "clone name", "clone id", clone_opts,
                                   cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "",
                                   image_ctx->op_work_queue, &ctx);
@@ -832,7 +832,7 @@ TEST_F(TestMockImageCloneRequest, MirrorEnableError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123,
                                   m_ioctx, "clone name", "clone id", clone_opts,
                                   cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "",
                                   image_ctx->op_work_queue, &ctx);
@@ -875,7 +875,7 @@ TEST_F(TestMockImageCloneRequest, CloseError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123,
                                   m_ioctx, "clone name", "clone id", clone_opts,
                                   cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "",
                                   image_ctx->op_work_queue, &ctx);
@@ -907,7 +907,7 @@ TEST_F(TestMockImageCloneRequest, RemoveError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123,
                                   m_ioctx, "clone name", "clone id", clone_opts,
                                   cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "",
                                   image_ctx->op_work_queue, &ctx);
@@ -939,7 +939,7 @@ TEST_F(TestMockImageCloneRequest, CloseParentError) {
 
   C_SaferCond ctx;
   ImageOptions clone_opts;
-  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", 123,
+  auto req = new MockCloneRequest(m_cct->_conf, m_ioctx, "parent id", "", {}, 123,
                                   m_ioctx, "clone name", "clone id", clone_opts,
                                   cls::rbd::MIRROR_IMAGE_MODE_JOURNAL, "", "",
                                   image_ctx->op_work_queue, &ctx);
index 63419fe4fa0e669cb0a459d6c3ae32cf355864ce..ab952269d3d222a9b8d0f38885a82f6f76361328 100644 (file)
@@ -78,6 +78,7 @@ struct CloneRequest<librbd::MockTestImageCtx> {
   static CloneRequest *create(ConfigProxy& config, IoCtx &p_ioctx,
                               const std::string &p_id,
                               const std::string &p_snap_name,
+                              const cls::rbd::SnapshotNamespace& snap_ns,
                               uint64_t p_snap_id,
                              IoCtx &c_ioctx, const std::string &c_name,
                              const std::string &c_id, ImageOptions c_options,
index f1f9cc42bb4ad0072ada4111ba8f39ecd1ddc60f..c023902c20944f864ac6c0443d4f5a767f9d8763 100644 (file)
@@ -288,9 +288,9 @@ void CreateImageRequest<I>::clone_image() {
 
   librbd::image::CloneRequest<I> *req = librbd::image::CloneRequest<I>::create(
     config, m_local_parent_io_ctx, m_local_parent_spec.image_id, snap_name,
-    CEPH_NOSNAP, m_local_io_ctx, m_local_image_name, m_local_image_id, opts,
-    m_mirror_image_mode, m_global_image_id, m_remote_mirror_uuid,
-    m_remote_image_ctx->op_work_queue, ctx);
+    snap_namespace, CEPH_NOSNAP, m_local_io_ctx, m_local_image_name,
+    m_local_image_id, opts, m_mirror_image_mode, m_global_image_id,
+    m_remote_mirror_uuid, m_remote_image_ctx->op_work_queue, ctx);
   req->send();
 }