Skip to content

Commit

Permalink
rbd: handle --{group,image}-namespace in "rbd group image {add,rm}"
Browse files Browse the repository at this point in the history
Currently only passing the namespace as part of the group or image spec
works.  If --group-namespace or --image-namespace options are used, the
namespace isn't picked up.

Fixes: https://tracker.ceph.com/issues/69324
Signed-off-by: Ilya Dryomov <[email protected]>
  • Loading branch information
idryomov committed Dec 20, 2024
1 parent 862ed6e commit f35e3a6
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 43 deletions.
5 changes: 5 additions & 0 deletions qa/workunits/rbd/cli_generic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,11 @@ test_namespace() {

rbd group create rbd/test1/group1
rbd group image add rbd/test1/group1 rbd/test1/image1
rbd group image add --group-pool rbd --group-namespace test1 --group group1 \
--image-pool rbd --image-namespace test1 --image image2
rbd group image rm --group-pool rbd --group-namespace test1 --group group1 \
--image-pool rbd --image-namespace test1 --image image1
rbd group image rm rbd/test1/group1 rbd/test1/image2
rbd group rm rbd/test1/group1

rbd trash move rbd/test1/image1
Expand Down
10 changes: 6 additions & 4 deletions src/tools/rbd/Utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,14 @@ int get_pool_image_snapshot_names(const po::variables_map &vm,
SpecValidation spec_validation) {
std::string pool_key = (mod == at::ARGUMENT_MODIFIER_DEST ?
at::DEST_POOL_NAME : at::POOL_NAME);
std::string namespace_key = (mod == at::ARGUMENT_MODIFIER_DEST ?
at::DEST_NAMESPACE_NAME : at::NAMESPACE_NAME);
std::string image_key = (mod == at::ARGUMENT_MODIFIER_DEST ?
at::DEST_IMAGE_NAME : at::IMAGE_NAME);

return get_pool_generic_snapshot_names(vm, mod, spec_arg_index, pool_key,
pool_name, namespace_name, image_key,
"image", image_name, snap_name,
pool_name, namespace_key, namespace_name,
image_key, "image", image_name, snap_name,
image_name_required, snapshot_presence,
spec_validation);
}
Expand All @@ -351,6 +354,7 @@ int get_pool_generic_snapshot_names(const po::variables_map &vm,
size_t *spec_arg_index,
const std::string& pool_key,
std::string *pool_name,
const std::string& namespace_key,
std::string *namespace_name,
const std::string& generic_key,
const std::string& generic_key_desc,
Expand All @@ -359,8 +363,6 @@ int get_pool_generic_snapshot_names(const po::variables_map &vm,
bool generic_name_required,
SnapshotPresence snapshot_presence,
SpecValidation spec_validation) {
std::string namespace_key = (mod == at::ARGUMENT_MODIFIER_DEST ?
at::DEST_NAMESPACE_NAME : at::NAMESPACE_NAME);
std::string snap_key = (mod == at::ARGUMENT_MODIFIER_DEST ?
at::DEST_SNAPSHOT_NAME : at::SNAPSHOT_NAME);

Expand Down
9 changes: 5 additions & 4 deletions src/tools/rbd/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,11 @@ int get_pool_generic_snapshot_names(
const boost::program_options::variables_map &vm,
argument_types::ArgumentModifier mod, size_t *spec_arg_index,
const std::string& pool_key, std::string *pool_name,
std::string *namespace_name, const std::string& generic_key,
const std::string& generic_key_desc, std::string *generic_name,
std::string *snap_name, bool generic_name_required,
SnapshotPresence snapshot_presence, SpecValidation spec_validation);
const std::string& namespace_key, std::string *namespace_name,
const std::string& generic_key, const std::string& generic_key_desc,
std::string *generic_name, std::string *snap_name,
bool generic_name_required, SnapshotPresence snapshot_presence,
SpecValidation spec_validation);

int get_pool_image_id(const boost::program_options::variables_map &vm,
size_t *spec_arg_index,
Expand Down
80 changes: 45 additions & 35 deletions src/tools/rbd/action/Group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ static const std::string DEST_GROUP_NAME("dest-group");
static const std::string GROUP_POOL_NAME("group-" + at::POOL_NAME);
static const std::string IMAGE_POOL_NAME("image-" + at::POOL_NAME);

static const std::string GROUP_NAMESPACE_NAME("group-" + at::NAMESPACE_NAME);
static const std::string IMAGE_NAMESPACE_NAME("image-" + at::NAMESPACE_NAME);

void add_group_option(po::options_description *opt,
at::ArgumentModifier modifier) {
std::string name = GROUP_NAME;
Expand Down Expand Up @@ -107,8 +110,8 @@ int execute_create(const po::variables_map &vm,

int r = utils::get_pool_generic_snapshot_names(
vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, at::POOL_NAME, &pool_name,
&namespace_name, GROUP_NAME, "group", &group_name, nullptr, true,
utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_FULL);
at::NAMESPACE_NAME, &namespace_name, GROUP_NAME, "group", &group_name,
nullptr, true, utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_FULL);
if (r < 0) {
return r;
}
Expand Down Expand Up @@ -187,8 +190,8 @@ int execute_remove(const po::variables_map &vm,

int r = utils::get_pool_generic_snapshot_names(
vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, at::POOL_NAME, &pool_name,
&namespace_name, GROUP_NAME, "group", &group_name, nullptr, true,
utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_FULL);
at::NAMESPACE_NAME, &namespace_name, GROUP_NAME, "group", &group_name,
nullptr, true, utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_FULL);
if (r < 0) {
return r;
}
Expand Down Expand Up @@ -221,8 +224,8 @@ int execute_rename(const po::variables_map &vm,

int r = utils::get_pool_generic_snapshot_names(
vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, at::POOL_NAME, &pool_name,
&namespace_name, GROUP_NAME, "group", &group_name, nullptr, true,
utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_FULL);
at::NAMESPACE_NAME, &namespace_name, GROUP_NAME, "group", &group_name,
nullptr, true, utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_FULL);
if (r < 0) {
return r;
}
Expand All @@ -233,9 +236,9 @@ int execute_rename(const po::variables_map &vm,

r = utils::get_pool_generic_snapshot_names(
vm, at::ARGUMENT_MODIFIER_DEST, &arg_index, at::DEST_POOL_NAME,
&dest_pool_name, &dest_namespace_name, DEST_GROUP_NAME, "group",
&dest_group_name, nullptr, true, utils::SNAPSHOT_PRESENCE_NONE,
utils::SPEC_VALIDATION_FULL);
&dest_pool_name, at::DEST_NAMESPACE_NAME, &dest_namespace_name,
DEST_GROUP_NAME, "group", &dest_group_name, nullptr, true,
utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_FULL);
if (r < 0) {
return r;
}
Expand Down Expand Up @@ -283,8 +286,8 @@ int execute_info(const po::variables_map &vm,

int r = utils::get_pool_generic_snapshot_names(
vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, at::POOL_NAME, &pool_name,
&namespace_name, GROUP_NAME, "group", &group_name, nullptr, true,
utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_FULL);
at::NAMESPACE_NAME, &namespace_name, GROUP_NAME, "group", &group_name,
nullptr, true, utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_FULL);
if (r < 0) {
return r;
}
Expand Down Expand Up @@ -335,8 +338,9 @@ int execute_add(const po::variables_map &vm,

int r = utils::get_pool_generic_snapshot_names(
vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, GROUP_POOL_NAME,
&group_pool_name, &group_namespace_name, GROUP_NAME, "group", &group_name,
nullptr, true, utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_FULL);
&group_pool_name, GROUP_NAMESPACE_NAME, &group_namespace_name,
GROUP_NAME, "group", &group_name, nullptr, true,
utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_FULL);
if (r < 0) {
return r;
}
Expand All @@ -347,9 +351,9 @@ int execute_add(const po::variables_map &vm,

r = utils::get_pool_generic_snapshot_names(
vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, IMAGE_POOL_NAME,
&image_pool_name, &image_namespace_name, at::IMAGE_NAME, "image",
&image_name, nullptr, true, utils::SNAPSHOT_PRESENCE_NONE,
utils::SPEC_VALIDATION_FULL);
&image_pool_name, IMAGE_NAMESPACE_NAME, &image_namespace_name,
at::IMAGE_NAME, "image", &image_name, nullptr, true,
utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_FULL);
if (r < 0) {
return r;
}
Expand Down Expand Up @@ -393,8 +397,9 @@ int execute_remove_image(const po::variables_map &vm,

int r = utils::get_pool_generic_snapshot_names(
vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, GROUP_POOL_NAME,
&group_pool_name, &group_namespace_name, GROUP_NAME, "group", &group_name,
nullptr, true, utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_FULL);
&group_pool_name, GROUP_NAMESPACE_NAME, &group_namespace_name,
GROUP_NAME, "group", &group_name, nullptr, true,
utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_FULL);
if (r < 0) {
return r;
}
Expand All @@ -410,9 +415,9 @@ int execute_remove_image(const po::variables_map &vm,

r = utils::get_pool_generic_snapshot_names(
vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, IMAGE_POOL_NAME,
&image_pool_name, &image_namespace_name, at::IMAGE_NAME, "image",
&image_name, nullptr, image_id.empty(), utils::SNAPSHOT_PRESENCE_NONE,
utils::SPEC_VALIDATION_FULL);
&image_pool_name, IMAGE_NAMESPACE_NAME, &image_namespace_name,
at::IMAGE_NAME, "image", &image_name, nullptr, image_id.empty(),
utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_FULL);
if (r < 0) {
return r;
}
Expand Down Expand Up @@ -464,8 +469,8 @@ int execute_list_images(const po::variables_map &vm,

int r = utils::get_pool_generic_snapshot_names(
vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, at::POOL_NAME, &pool_name,
&namespace_name, GROUP_NAME, "group", &group_name, nullptr, true,
utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_FULL);
at::NAMESPACE_NAME, &namespace_name, GROUP_NAME, "group", &group_name,
nullptr, true, utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_FULL);
if (r < 0) {
return r;
}
Expand Down Expand Up @@ -563,8 +568,9 @@ int execute_group_snap_create(const po::variables_map &vm,

int r = utils::get_pool_generic_snapshot_names(
vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, at::POOL_NAME, &pool_name,
&namespace_name, GROUP_NAME, "group", &group_name, &snap_name, true,
utils::SNAPSHOT_PRESENCE_REQUIRED, utils::SPEC_VALIDATION_FULL);
at::NAMESPACE_NAME, &namespace_name, GROUP_NAME, "group", &group_name,
&snap_name, true, utils::SNAPSHOT_PRESENCE_REQUIRED,
utils::SPEC_VALIDATION_FULL);
if (r < 0) {
return r;
}
Expand Down Expand Up @@ -604,8 +610,9 @@ int execute_group_snap_remove(const po::variables_map &vm,

int r = utils::get_pool_generic_snapshot_names(
vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, at::POOL_NAME, &pool_name,
&namespace_name, GROUP_NAME, "group", &group_name, &snap_name, true,
utils::SNAPSHOT_PRESENCE_REQUIRED, utils::SPEC_VALIDATION_FULL);
at::NAMESPACE_NAME, &namespace_name, GROUP_NAME, "group", &group_name,
&snap_name, true, utils::SNAPSHOT_PRESENCE_REQUIRED,
utils::SPEC_VALIDATION_FULL);
if (r < 0) {
return r;
}
Expand Down Expand Up @@ -640,8 +647,9 @@ int execute_group_snap_rename(const po::variables_map &vm,

int r = utils::get_pool_generic_snapshot_names(
vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, at::POOL_NAME, &pool_name,
&namespace_name, GROUP_NAME, "group", &group_name, &source_snap_name, true,
utils::SNAPSHOT_PRESENCE_REQUIRED, utils::SPEC_VALIDATION_FULL);
at::NAMESPACE_NAME, &namespace_name, GROUP_NAME, "group", &group_name,
&source_snap_name, true, utils::SNAPSHOT_PRESENCE_REQUIRED,
utils::SPEC_VALIDATION_FULL);
if (r < 0) {
return r;
}
Expand Down Expand Up @@ -696,8 +704,8 @@ int execute_group_snap_list(const po::variables_map &vm,

int r = utils::get_pool_generic_snapshot_names(
vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, at::POOL_NAME, &pool_name,
&namespace_name, GROUP_NAME, "group", &group_name, nullptr, true,
utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_FULL);
at::NAMESPACE_NAME, &namespace_name, GROUP_NAME, "group", &group_name,
nullptr, true, utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_FULL);
if (r < 0) {
return r;
}
Expand Down Expand Up @@ -764,8 +772,9 @@ int execute_group_snap_info(const po::variables_map &vm,

int r = utils::get_pool_generic_snapshot_names(
vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, at::POOL_NAME, &pool_name,
&namespace_name, GROUP_NAME, "group", &group_name, &group_snap_name, true,
utils::SNAPSHOT_PRESENCE_REQUIRED, utils::SPEC_VALIDATION_FULL);
at::NAMESPACE_NAME, &namespace_name, GROUP_NAME, "group", &group_name,
&group_snap_name, true, utils::SNAPSHOT_PRESENCE_REQUIRED,
utils::SPEC_VALIDATION_FULL);
if (r < 0) {
return r;
}
Expand Down Expand Up @@ -872,8 +881,9 @@ int execute_group_snap_rollback(const po::variables_map &vm,

int r = utils::get_pool_generic_snapshot_names(
vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, at::POOL_NAME, &pool_name,
&namespace_name, GROUP_NAME, "group", &group_name, &snap_name, true,
utils::SNAPSHOT_PRESENCE_REQUIRED, utils::SPEC_VALIDATION_FULL);
at::NAMESPACE_NAME, &namespace_name, GROUP_NAME, "group", &group_name,
&snap_name, true, utils::SNAPSHOT_PRESENCE_REQUIRED,
utils::SPEC_VALIDATION_FULL);
if (r < 0) {
return r;
}
Expand Down

0 comments on commit f35e3a6

Please sign in to comment.