]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: Improve data pool selection when creating images
authorAdam Wolfe Gordon <awg@digitalocean.com>
Tue, 26 Sep 2017 20:30:06 +0000 (20:30 +0000)
committerAdam Wolfe Gordon <awg@digitalocean.com>
Fri, 29 Sep 2017 15:14:03 +0000 (15:14 +0000)
Previously we used the source image's data pool name
unconditionally. There were two problems with that:

1. If a pool with the same name didn't exist locally, creation of the
   local image would fail.
2. If the local pool had a default data pool configured it would be
   ignored.

Change local image creation so it uses the default pool if configured,
and uses the remote pool name only if a pool with that name exists
locally. If neither of those is true, leave the data pool unset.

Signed-off-by: Adam Wolfe Gordon <awg@digitalocean.com>
src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc

index acef392b1a4eafbb49d7aa3408cdd14f6644ec47..a329d22a6e4d0a0c6fcaad1929db8277eb853f89 100644 (file)
@@ -74,8 +74,29 @@ void CreateImageRequest<I>::create_image() {
                     m_remote_image_ctx->stripe_unit);
   image_options.set(RBD_IMAGE_OPTION_STRIPE_COUNT,
                     m_remote_image_ctx->stripe_count);
-  image_options.set(RBD_IMAGE_OPTION_DATA_POOL,
-                   m_remote_image_ctx->data_ctx.get_pool_name());
+
+  // 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);
+  }
 
   librbd::image::CreateRequest<I> *req = librbd::image::CreateRequest<I>::create(
     m_local_io_ctx, m_local_image_name, m_local_image_id,