librbd: permit cross-namespace when using clone v2

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
This commit is contained in:
Jason Dillaman 2018-08-20 16:33:20 -04:00
parent 8209789dc3
commit c5697d3c69
2 changed files with 12 additions and 7 deletions

View File

@ -112,6 +112,13 @@ void CloneRequest<I>::validate_options() {
}
}
if (m_clone_format == 1 &&
m_parent_io_ctx.get_namespace() != m_ioctx.get_namespace()) {
ldout(m_cct, 1) << "clone v2 required for cross-namespace clones" << dendl;
complete(-EXDEV);
return;
}
open_parent();
}

View File

@ -63,12 +63,6 @@ int execute(const po::variables_map &vm,
}
opts.set(RBD_IMAGE_OPTION_FORMAT, static_cast<uint64_t>(2));
// TODO clones across namespaces not yet supported
if (namespace_name != dst_namespace_name) {
std::cerr << "rbd: clones across namespaces is not supported." << std::endl;
return -EINVAL;
}
librados::Rados rados;
librados::IoCtx io_ctx;
r = utils::init(pool_name, namespace_name, &rados, &io_ctx);
@ -85,7 +79,11 @@ int execute(const po::variables_map &vm,
librbd::RBD rbd;
r = do_clone(rbd, io_ctx, image_name.c_str(), snap_name.c_str(), dst_io_ctx,
dst_image_name.c_str(), opts);
if (r < 0) {
if (r == -EXDEV) {
std::cerr << "rbd: clone v2 required for cross-namespace clones."
<< std::endl;
return r;
} else if (r < 0) {
std::cerr << "rbd: clone error: " << cpp_strerror(r) << std::endl;
return r;
}