]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: re-use image create option logic for clones
authorJason Dillaman <dillaman@redhat.com>
Thu, 17 May 2018 17:18:15 +0000 (13:18 -0400)
committerJason Dillaman <dillaman@redhat.com>
Fri, 18 May 2018 13:45:32 +0000 (09:45 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc
src/tools/rbd_mirror/image_replayer/CreateImageRequest.h

index 9d1dd72a9b2dfcda0966038541794693cb68db68..61c8a3ee43373605324a9f7d0a12203c614b693d 100644 (file)
@@ -69,35 +69,7 @@ void CreateImageRequest<I>::create_image() {
   RWLock::RLocker snap_locker(m_remote_image_ctx->snap_lock);
 
   librbd::ImageOptions image_options;
-  image_options.set(RBD_IMAGE_OPTION_FEATURES, m_remote_image_ctx->features);
-  image_options.set(RBD_IMAGE_OPTION_ORDER, m_remote_image_ctx->order);
-  image_options.set(RBD_IMAGE_OPTION_STRIPE_UNIT,
-                    m_remote_image_ctx->stripe_unit);
-  image_options.set(RBD_IMAGE_OPTION_STRIPE_COUNT,
-                    m_remote_image_ctx->stripe_count);
-
-  // Determine the data pool for the local image as follows:
-  // 1. If the local pool has a default data pool, use it.
-  // 2. If the remote image has a data pool different from its metadata pool and
-  //    a pool with the same name exists locally, use it.
-  // 3. Don't set the data pool explicitly.
-  std::string data_pool;
-  librados::Rados local_rados(m_local_io_ctx);
-  auto default_data_pool = g_ceph_context->_conf->get_val<std::string>("rbd_default_data_pool");
-  auto remote_md_pool = m_remote_image_ctx->md_ctx.get_pool_name();
-  auto remote_data_pool = m_remote_image_ctx->data_ctx.get_pool_name();
-
-  if (default_data_pool != "") {
-    data_pool = default_data_pool;
-  } else if (remote_data_pool != remote_md_pool) {
-    if (local_rados.pool_lookup(remote_data_pool.c_str()) >= 0) {
-      data_pool = remote_data_pool;
-    }
-  }
-
-  if (data_pool != "") {
-    image_options.set(RBD_IMAGE_OPTION_DATA_POOL, data_pool);
-  }
+  populate_image_options(&image_options);
 
   librbd::image::CreateRequest<I> *req = librbd::image::CreateRequest<I>::create(
     m_local_io_ctx, m_local_image_name, m_local_image_id,
@@ -325,10 +297,7 @@ void CreateImageRequest<I>::clone_image() {
   dout(20) << dendl;
 
   librbd::ImageOptions opts;
-  opts.set(RBD_IMAGE_OPTION_FEATURES, m_remote_image_ctx->features);
-  opts.set(RBD_IMAGE_OPTION_ORDER, m_remote_image_ctx->order);
-  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);
+  populate_image_options(&opts);
 
   using klass = CreateImageRequest<I>;
   Context *ctx = create_context_callback<klass, &klass::handle_clone_image>(this);
@@ -463,6 +432,40 @@ int CreateImageRequest<I>::validate_parent() {
   return 0;
 }
 
+template <typename I>
+void CreateImageRequest<I>::populate_image_options(
+    librbd::ImageOptions* image_options) {
+  image_options->set(RBD_IMAGE_OPTION_FEATURES, m_remote_image_ctx->features);
+  image_options->set(RBD_IMAGE_OPTION_ORDER, m_remote_image_ctx->order);
+  image_options->set(RBD_IMAGE_OPTION_STRIPE_UNIT,
+                     m_remote_image_ctx->stripe_unit);
+  image_options->set(RBD_IMAGE_OPTION_STRIPE_COUNT,
+                     m_remote_image_ctx->stripe_count);
+
+  // Determine the data pool for the local image as follows:
+  // 1. If the local pool has a default data pool, use it.
+  // 2. If the remote image has a data pool different from its metadata pool and
+  //    a pool with the same name exists locally, use it.
+  // 3. Don't set the data pool explicitly.
+  std::string data_pool;
+  librados::Rados local_rados(m_local_io_ctx);
+  auto default_data_pool = g_ceph_context->_conf->get_val<std::string>("rbd_default_data_pool");
+  auto remote_md_pool = m_remote_image_ctx->md_ctx.get_pool_name();
+  auto remote_data_pool = m_remote_image_ctx->data_ctx.get_pool_name();
+
+  if (default_data_pool != "") {
+    data_pool = default_data_pool;
+  } else if (remote_data_pool != remote_md_pool) {
+    if (local_rados.pool_lookup(remote_data_pool.c_str()) >= 0) {
+      data_pool = remote_data_pool;
+    }
+  }
+
+  if (data_pool != "") {
+    image_options->set(RBD_IMAGE_OPTION_DATA_POOL, data_pool);
+  }
+}
+
 } // namespace image_replayer
 } // namespace mirror
 } // namespace rbd
index 595e1992dc2466a84320077763a40cdd63e93c8a..0e6b8e10560f6efa5a8b3d0e658e2645a5f4dd13 100644 (file)
@@ -13,6 +13,7 @@
 class Context;
 class ContextWQ;
 namespace librbd { class ImageCtx; }
+namespace librbd { class ImageOptions; }
 
 namespace rbd {
 namespace mirror {
@@ -135,6 +136,8 @@ private:
 
   int validate_parent();
 
+  void populate_image_options(librbd::ImageOptions* image_options);
+
 };
 
 } // namespace image_replayer