From 2e239c05518e67b3db80500dbdd3fc5dde30e443 Mon Sep 17 00:00:00 2001 From: Adam Wolfe Gordon Date: Tue, 26 Sep 2017 20:30:06 +0000 Subject: [PATCH] rbd-mirror: Improve data pool selection when creating images 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 --- .../image_replayer/CreateImageRequest.cc | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc b/src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc index acef392b1a4ea..a329d22a6e4d0 100644 --- a/src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc +++ b/src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc @@ -74,8 +74,29 @@ void CreateImageRequest::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("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 *req = librbd::image::CreateRequest::create( m_local_io_ctx, m_local_image_name, m_local_image_id, -- 2.39.5