Merge pull request #31161 from trociny/wip-42488

rbd-mirror: mirrored clone should be same format 

Reviewed-by: Jason Dillaman <dillaman@redhat.com>
This commit is contained in:
Jason Dillaman 2019-10-30 12:07:30 -04:00 committed by GitHub
commit f4d99f796a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 88 additions and 23 deletions

View File

@ -242,6 +242,20 @@ compare_images ${POOL} ${clone_image}
clone_image ${CLUSTER1} ${PARENT_POOL} ${parent_image} ${parent_snap} ${POOL} ${clone_image}1
clone_image ${CLUSTER2} ${PARENT_POOL} ${parent_image} ${parent_snap} ${POOL} \
${clone_image}_v1 --rbd-default-clone-format 1
test $(get_clone_format ${CLUSTER2} ${POOL} ${clone_image}_v1) = 1
wait_for_image_replay_started ${CLUSTER1} ${POOL} ${clone_image}_v1
test $(get_clone_format ${CLUSTER1} ${POOL} ${clone_image}_v1) = 1
parent_snap=snap_v2
create_snapshot ${CLUSTER2} ${PARENT_POOL} ${parent_image} ${parent_snap}
clone_image ${CLUSTER2} ${PARENT_POOL} ${parent_image} ${parent_snap} ${POOL} \
${clone_image}_v2 --rbd-default-clone-format 2
test $(get_clone_format ${CLUSTER2} ${POOL} ${clone_image}_v2) = 2
wait_for_image_replay_started ${CLUSTER1} ${POOL} ${clone_image}_v2
test $(get_clone_format ${CLUSTER1} ${POOL} ${clone_image}_v2) = 2
testlog "TEST: data pool"
dp_image=test_data_pool
create_image ${CLUSTER2} ${POOL} ${dp_image} 128 --data-pool ${PARENT_POOL}

View File

@ -871,8 +871,12 @@ clone_image()
local clone_pool=$5
local clone_image=$6
rbd --cluster ${cluster} clone ${parent_pool}/${parent_image}@${parent_snap} \
${clone_pool}/${clone_image} --image-feature layering,exclusive-lock,journaling
shift 6
rbd --cluster ${cluster} clone \
${parent_pool}/${parent_image}@${parent_snap} \
${clone_pool}/${clone_image} \
--image-feature layering,exclusive-lock,journaling $@
}
disconnect_image()
@ -1167,6 +1171,28 @@ get_image_data_pool()
awk '$1 == "data_pool:" {print $2}'
}
get_clone_format()
{
local cluster=$1
local pool=$2
local image=$3
rbd --cluster ${cluster} info ${pool}/${image} |
awk 'BEGIN {
format = 1
}
$1 == "parent:" {
parent = $2
}
/op_features: .*clone-child/ {
format = 2
}
END {
if (!parent) exit 1
print format
}'
}
#
# Main
#

View File

@ -268,6 +268,7 @@ enum {
RBD_IMAGE_OPTION_FEATURES_CLEAR = 9,
RBD_IMAGE_OPTION_DATA_POOL = 10,
RBD_IMAGE_OPTION_FLATTEN = 11,
RBD_IMAGE_OPTION_CLONE_FORMAT = 12,
};
typedef enum {

View File

@ -95,23 +95,25 @@ void CloneRequest<I>::validate_options() {
m_use_p_features = false;
}
std::string default_clone_format = m_config.get_val<std::string>(
"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<std::string>(
"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;
}
}
}

View File

@ -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<string, bufferlist> m_pairs;

View File

@ -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 : "")

View File

@ -489,6 +489,15 @@ void CreateImageRequest<I>::populate_image_options(
if (data_pool != "") {
image_options->set(RBD_IMAGE_OPTION_DATA_POOL, data_pool);
}
if (m_remote_parent_spec.pool_id != -1) {
uint64_t clone_format = 1;
if (m_remote_image_ctx->test_op_features(
RBD_OPERATION_FEATURE_CLONE_CHILD)) {
clone_format = 2;
}
image_options->set(RBD_IMAGE_OPTION_CLONE_FORMAT, clone_format);
}
}
} // namespace image_replayer