From: Mykola Golub Date: Fri, 25 Oct 2019 12:59:10 +0000 (+0300) Subject: librbd: allow to override format in clone request X-Git-Tag: v15.1.0~1106^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=06bda36b42db59bcf64bb2072377cfac4e440df2;p=ceph.git librbd: allow to override format in clone request Signed-off-by: Mykola Golub --- diff --git a/src/librbd/image/CloneRequest.cc b/src/librbd/image/CloneRequest.cc index d5f2acd5fb13..3a4e7c0bde60 100644 --- a/src/librbd/image/CloneRequest.cc +++ b/src/librbd/image/CloneRequest.cc @@ -95,23 +95,25 @@ void CloneRequest::validate_options() { m_use_p_features = false; } - std::string default_clone_format = m_config.get_val( - "rbd_default_clone_format"); - if (default_clone_format == "1") { - m_clone_format = 1; - } else if (default_clone_format == "auto") { - librados::Rados rados(m_ioctx); - int8_t min_compat_client; - int8_t require_min_compat_client; - int r = rados.get_min_compatible_client(&min_compat_client, - &require_min_compat_client); - if (r < 0) { - complete(r); - return; - } - if (std::max(min_compat_client, require_min_compat_client) < - CEPH_RELEASE_MIMIC) { + if (m_opts.get(RBD_IMAGE_OPTION_CLONE_FORMAT, &m_clone_format) < 0) { + std::string default_clone_format = m_config.get_val( + "rbd_default_clone_format"); + if (default_clone_format == "1") { m_clone_format = 1; + } else if (default_clone_format == "auto") { + librados::Rados rados(m_ioctx); + int8_t min_compat_client; + int8_t require_min_compat_client; + int r = rados.get_min_compatible_client(&min_compat_client, + &require_min_compat_client); + if (r < 0) { + complete(r); + return; + } + if (std::max(min_compat_client, require_min_compat_client) < + CEPH_RELEASE_MIMIC) { + m_clone_format = 1; + } } } diff --git a/src/librbd/image/CloneRequest.h b/src/librbd/image/CloneRequest.h index 1e7d4c9c13ad..640de9fe0dab 100644 --- a/src/librbd/image/CloneRequest.h +++ b/src/librbd/image/CloneRequest.h @@ -115,7 +115,7 @@ private: Context *m_on_finish; CephContext *m_cct; - uint32_t m_clone_format = 2; + uint64_t m_clone_format = 2; bool m_use_p_features; uint64_t m_features; map m_pairs; diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index e2fa5632e36e..00505b264c21 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -306,6 +306,7 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) { {RBD_IMAGE_OPTION_FEATURES_CLEAR, UINT64}, {RBD_IMAGE_OPTION_DATA_POOL, STR}, {RBD_IMAGE_OPTION_FLATTEN, UINT64}, + {RBD_IMAGE_OPTION_CLONE_FORMAT, UINT64}, }; std::string image_option_name(int optname) { @@ -334,6 +335,8 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) { return "data_pool"; case RBD_IMAGE_OPTION_FLATTEN: return "flatten"; + case RBD_IMAGE_OPTION_CLONE_FORMAT: + return "clone_format"; default: return "unknown (" + stringify(optname) + ")"; } @@ -750,11 +753,16 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) { } CephContext *cct = (CephContext *)io_ctx.cct(); - uint64_t flatten; - if (opts.get(RBD_IMAGE_OPTION_FLATTEN, &flatten) == 0) { + uint64_t option; + if (opts.get(RBD_IMAGE_OPTION_FLATTEN, &option) == 0) { lderr(cct) << "create does not support 'flatten' image option" << dendl; return -EINVAL; } + if (opts.get(RBD_IMAGE_OPTION_CLONE_FORMAT, &option) == 0) { + lderr(cct) << "create does not support 'clone_format' image option" + << dendl; + return -EINVAL; + } ldout(cct, 10) << __func__ << " name=" << image_name << ", " << "id= " << id << ", " @@ -1316,11 +1324,16 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) { ImageOptions& opts, ProgressContext &prog_ctx, size_t sparse_size) { CephContext *cct = (CephContext *)dest_md_ctx.cct(); - uint64_t flatten; - if (opts.get(RBD_IMAGE_OPTION_FLATTEN, &flatten) == 0) { + uint64_t option; + if (opts.get(RBD_IMAGE_OPTION_FLATTEN, &option) == 0) { lderr(cct) << "copy does not support 'flatten' image option" << dendl; return -EINVAL; } + if (opts.get(RBD_IMAGE_OPTION_CLONE_FORMAT, &option) == 0) { + lderr(cct) << "copy does not support 'clone_format' image option" + << dendl; + return -EINVAL; + } ldout(cct, 20) << "copy " << src->name << (src->snap_name.length() ? "@" + src->snap_name : "")