#include "tools/rbd/ArgumentTypes.h"
#include "tools/rbd/IndentStream.h"
#include "tools/rbd/OptionPrinter.h"
+#include "common/ceph_argparse.h"
#include "common/config.h"
#include "global/global_context.h"
+#include "global/global_init.h"
#include "include/stringify.h"
#include <algorithm>
#include <iostream>
static const std::string HELP_SPEC("help");
static const std::string BASH_COMPLETION_SPEC("bash-completion");
+boost::intrusive_ptr<CephContext> global_init(
+ int argc, const char **argv, std::vector<std::string> *command_args,
+ std::vector<std::string> *global_init_args) {
+ std::vector<const char*> cmd_args;
+ argv_to_vec(argc, argv, cmd_args);
+ std::vector<const char*> args(cmd_args);
+ env_to_vec(args);
+ auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
+ CODE_ENVIRONMENT_UTILITY, 0);
+
+ *command_args = {args.begin(), args.end()};
+
+ // Scan command line arguments for ceph global init args (those are
+ // filtered out from args vector by global_init).
+
+ auto cursor = args.begin();
+ for (auto &arg : cmd_args) {
+ auto iter = cursor;
+ for (; iter != args.end(); iter++) {
+ if (*iter == arg) {
+ break;
+ }
+ }
+ if (iter == args.end()) {
+ // filtered out by global_init
+ global_init_args->push_back(arg);
+ } else {
+ cursor = ++iter;
+ }
+ }
+
+ return cct;
+}
+
std::string format_command_spec(const Shell::CommandSpec &spec) {
return joinify<std::string>(spec.begin(), spec.end(), " ");
}
return switch_arguments;
}
-int Shell::execute(const Arguments& cmdline_arguments) {
+int Shell::execute(int argc, const char **argv) {
+ std::vector<std::string> arguments;
+ std::vector<std::string> ceph_global_init_args;
+ auto cct = global_init(argc, argv, &arguments, &ceph_global_init_args);
- std::vector<std::string> arguments(cmdline_arguments.begin(),
- cmdline_arguments.end());
std::vector<std::string> command_spec;
get_command_spec(arguments, &command_spec);
bool is_alias = true;
positional_options.add(at::POSITIONAL_ARGUMENTS.c_str(), max_count);
}
- po::options_description global_opts;
- get_global_options(&global_opts);
-
po::options_description group_opts;
group_opts.add(command_opts)
- .add(argument_opts)
- .add(global_opts);
+ .add(argument_opts);
po::store(po::command_line_parser(arguments)
.style(po::command_line_style::default_style &
return EXIT_FAILURE;
}
- int r = (*action->execute)(vm);
+ int r = (*action->execute)(vm, ceph_global_init_args);
if (r != 0) {
return std::abs(r);
}
class Shell {
public:
- typedef std::vector<const char *> Arguments;
typedef std::vector<std::string> CommandSpec;
struct Action {
typedef void (*GetArguments)(boost::program_options::options_description *,
boost::program_options::options_description *);
- typedef int (*Execute)(const boost::program_options::variables_map &);
+ typedef int (*Execute)(const boost::program_options::variables_map &,
+ const std::vector<std::string> &);
CommandSpec command_spec;
CommandSpec alias_command_spec;
}
};
- int execute(const Arguments &argument);
+ int execute(int argc, const char **argv);
private:
static std::vector<Action *>& get_actions();
return 0;
}
-int execute_for_write(const po::variables_map &vm) {
+int execute_for_write(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
std::cerr << "rbd: bench-write is deprecated, use rbd bench --io-type write ..." << std::endl;
return bench_execute(vm, IO_TYPE_WRITE);
}
-int execute_for_bench(const po::variables_map &vm) {
+int execute_for_bench(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
io_type_t bench_io_type;
if (vm.count("io-type")) {
bench_io_type = vm["io-type"].as<io_type_t>();
at::add_format_options(options);
}
-int execute(const po::variables_map &vm) {
+int execute(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
at::add_create_image_options(options, false);
}
-int execute(const po::variables_map &vm) {
+int execute(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
at::add_no_progress_option(options);
}
-int execute(const po::variables_map &vm) {
+int execute(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
at::add_size_option(options);
}
-int execute(const po::variables_map &vm) {
+int execute(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
at::add_format_options(options);
}
-int execute(const po::variables_map &vm) {
+int execute(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
"snapshot starting point");
}
-int execute(const po::variables_map &vm) {
+int execute(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
at::add_no_progress_option(options);
}
-int execute_diff(const po::variables_map &vm) {
+int execute_diff(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
at::add_export_format_option(options);
}
-int execute(const po::variables_map &vm) {
+int execute(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
return 0;
}
-int execute_disable(const po::variables_map &vm) {
+int execute_disable(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
return execute(vm, false);
}
-int execute_enable(const po::variables_map &vm) {
+int execute_enable(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
return execute(vm, true);
}
at::add_no_progress_option(options);
}
-int execute(const po::variables_map &vm) {
+int execute(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
namespace po = boost::program_options;
static int call_ggate_cmd(const po::variables_map &vm,
- const std::vector<const char*> &args)
-{
+ const std::vector<std::string> &args,
+ const std::vector<std::string> &ceph_global_args) {
SubProcess process("rbd-ggate", SubProcess::KEEP, SubProcess::KEEP,
SubProcess::KEEP);
- if (vm.count("conf")) {
- process.add_cmd_arg("--conf");
- process.add_cmd_arg(vm["conf"].as<std::string>().c_str());
- }
- if (vm.count("cluster")) {
- process.add_cmd_arg("--cluster");
- process.add_cmd_arg(vm["cluster"].as<std::string>().c_str());
- }
- if (vm.count("id")) {
- process.add_cmd_arg("--id");
- process.add_cmd_arg(vm["id"].as<std::string>().c_str());
- }
- if (vm.count("name")) {
- process.add_cmd_arg("--name");
- process.add_cmd_arg(vm["name"].as<std::string>().c_str());
- }
- if (vm.count("mon_host")) {
- process.add_cmd_arg("--mon_host");
- process.add_cmd_arg(vm["mon_host"].as<std::string>().c_str());
- }
- if (vm.count("keyfile")) {
- process.add_cmd_arg("--keyfile");
- process.add_cmd_arg(vm["keyfile"].as<std::string>().c_str());
- }
- if (vm.count("keyring")) {
- process.add_cmd_arg("--keyring");
- process.add_cmd_arg(vm["keyring"].as<std::string>().c_str());
+ for (auto &arg : ceph_global_args) {
+ process.add_cmd_arg(arg.c_str());
}
- for (std::vector<const char*>::const_iterator p = args.begin();
- p != args.end(); ++p)
- process.add_cmd_arg(*p);
+ for (auto &arg : args) {
+ process.add_cmd_arg(arg.c_str());
+ }
if (process.spawn()) {
std::cerr << "rbd: failed to run rbd-ggate: " << process.err() << std::endl;
at::add_format_options(options);
}
-int execute_list(const po::variables_map &vm)
-{
- std::vector<const char*> args;
+int execute_list(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
+ std::vector<std::string> args;
args.push_back("list");
if (vm.count("format")) {
args.push_back("--format");
- args.push_back(vm["format"].as<at::Format>().value.c_str());
+ args.push_back(vm["format"].as<at::Format>().value);
}
if (vm["pretty-format"].as<bool>()) {
args.push_back("--pretty-format");
}
- return call_ggate_cmd(vm, args);
+ return call_ggate_cmd(vm, args, ceph_global_init_args);
}
void get_map_arguments(po::options_description *positional,
("device", po::value<std::string>(), "specify ggate device");
}
-int execute_map(const po::variables_map &vm)
-{
- std::vector<const char*> args;
+int execute_map(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
+ std::vector<std::string> args;
args.push_back("map");
std::string img;
if (r < 0) {
return r;
}
- args.push_back(img.c_str());
+ args.push_back(img);
if (vm["read-only"].as<bool>())
args.push_back("--read-only");
if (vm.count("device")) {
args.push_back("--device");
- args.push_back(vm["device"].as<std::string>().c_str());
+ args.push_back(vm["device"].as<std::string>());
}
- return call_ggate_cmd(vm, args);
+ return call_ggate_cmd(vm, args, ceph_global_init_args);
}
void get_unmap_arguments(po::options_description *positional,
at::add_snap_option(options, at::ARGUMENT_MODIFIER_NONE);
}
-int execute_unmap(const po::variables_map &vm)
-{
+int execute_unmap(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
std::string device_name = utils::get_positional_argument(vm, 0);
if (!boost::starts_with(device_name, "/dev/")) {
device_name.clear();
return -EINVAL;
}
- std::vector<const char*> args;
+ std::vector<std::string> args;
args.push_back("unmap");
- args.push_back(device_name.empty() ? image_name.c_str() :
- device_name.c_str());
+ args.push_back(device_name.empty() ? image_name : device_name);
- return call_ggate_cmd(vm, args);
+ return call_ggate_cmd(vm, args, ceph_global_init_args);
}
Shell::SwitchArguments switched_arguments({"read-only", "exclusive"});
namespace at = argument_types;
namespace po = boost::program_options;
-int execute_create(const po::variables_map &vm) {
+int execute_create(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string group_name;
return 0;
}
-int execute_list(const po::variables_map &vm) {
+int execute_list(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name = utils::get_pool_name(vm, &arg_index);
return 0;
}
-int execute_remove(const po::variables_map &vm) {
+int execute_remove(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string group_name;
return 0;
}
-int execute_add(const po::variables_map &vm) {
+int execute_add(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
// Parse group data.
std::string group_name;
return 0;
}
-int execute_remove_image(const po::variables_map &vm) {
+int execute_remove_image(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string group_name;
return 0;
}
-int execute_list_images(const po::variables_map &vm) {
+int execute_list_images(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string group_name;
std::string pool_name;
return 0;
}
-int execute_group_snap_create(const po::variables_map &vm) {
+int execute_group_snap_create(const po::variables_map &vm,
+ const std::vector<std::string> &global_args) {
size_t arg_index = 0;
std::string group_name;
return 0;
}
-int execute_group_snap_remove(const po::variables_map &vm) {
+ int execute_group_snap_remove(const po::variables_map &vm,
+ const std::vector<std::string> &global_args) {
size_t arg_index = 0;
std::string group_name;
return r;
}
-int execute_group_snap_rename(const po::variables_map &vm) {
+int execute_group_snap_rename(const po::variables_map &vm,
+ const std::vector<std::string> &global_args) {
size_t arg_index = 0;
std::string group_name;
return 0;
}
-int execute_group_snap_list(const po::variables_map &vm) {
+int execute_group_snap_list(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_args) {
size_t arg_index = 0;
std::string group_name;
std::string pool_name;
at::add_format_options(options);
}
-int execute_list(const po::variables_map &vm) {
+int execute_list(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
add_key_option(positional);
}
-int execute_get(const po::variables_map &vm) {
+int execute_get(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
("value", "image meta value");
}
-int execute_set(const po::variables_map &vm) {
+int execute_set(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
add_key_option(positional);
}
-int execute_remove(const po::variables_map &vm) {
+int execute_remove(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
at::add_no_progress_option(options);
}
-int execute_diff(const po::variables_map &vm) {
+int execute_diff(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
std::string path;
size_t arg_index = 0;
int r = utils::get_path(vm, &arg_index, &path);
at::add_image_option(options, at::ARGUMENT_MODIFIER_NONE, " (deprecated)");
}
-int execute(const po::variables_map &vm) {
+int execute(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
std::string path;
size_t arg_index = 0;
int r = utils::get_path(vm, &arg_index, &path);
at::add_format_options(options);
}
-int execute(const po::variables_map &vm) {
+int execute(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
at::add_format_options(options);
}
-int execute_info(const po::variables_map &vm) {
+int execute_info(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string journal_name;
at::add_format_options(options);
}
-int execute_status(const po::variables_map &vm) {
+int execute_status(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string journal_name;
at::add_journal_spec_options(positional, options, at::ARGUMENT_MODIFIER_NONE);
}
-int execute_reset(const po::variables_map &vm) {
+int execute_reset(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string journal_name;
"client ID (or leave unspecified to disconnect all)");
}
-int execute_client_disconnect(const po::variables_map &vm) {
+int execute_client_disconnect(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string journal_name;
at::add_verbose_option(options);
}
-int execute_inspect(const po::variables_map &vm) {
+int execute_inspect(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string journal_name;
at::add_no_error_option(options);
}
-int execute_export(const po::variables_map &vm) {
+int execute_export(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string journal_name;
at::add_no_error_option(options);
}
-int execute_import(const po::variables_map &vm) {
+int execute_import(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
std::string path;
size_t arg_index = 0;
int r = utils::get_path(vm, &arg_index, &path);
at::add_format_options(options);
}
-int execute_show(const po::variables_map &vm) {
+int execute_show(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
at::Format::Formatter formatter;
int r = utils::get_formatter(vm, &formatter);
if (r < 0) {
("exclusive", po::bool_switch(), "disable automatic exclusive lock transitions");
}
-int execute_map(const po::variables_map &vm) {
+int execute_map(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
("options,o", po::value<std::string>(), "unmap options");
}
-int execute_unmap(const po::variables_map &vm) {
+int execute_unmap(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
std::string device_name = utils::get_positional_argument(vm, 0);
if (!boost::starts_with(device_name, "/dev/")) {
device_name.clear();
at::add_format_options(options);
}
-int execute(const po::variables_map &vm) {
+int execute(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name = utils::get_pool_name(vm, &arg_index);
at::add_format_options(options);
}
-int execute_list(const po::variables_map &vm) {
+int execute_list(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
("shared", po::value<std::string>(), "shared lock tag");
}
-int execute_add(const po::variables_map &vm) {
+int execute_add(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
("locker", "locker client");
}
-int execute_remove(const po::variables_map &vm) {
+int execute_remove(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
at::add_no_progress_option(options);
}
-int execute(const po::variables_map &vm) {
+int execute(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
std::string first_diff = utils::get_positional_argument(vm, 0);
if (first_diff.empty()) {
std::cerr << "rbd: first diff was not specified" << std::endl;
return 0;
}
-int execute_disable(const po::variables_map &vm) {
+int execute_disable(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
return execute_enable_disable(vm, false, vm["force"].as<bool>());
}
-int execute_enable(const po::variables_map &vm) {
+int execute_enable(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
return execute_enable_disable(vm, true, false);
}
at::add_image_spec_options(positional, options, at::ARGUMENT_MODIFIER_NONE);
}
-int execute_promote(const po::variables_map &vm) {
+int execute_promote(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
return 0;
}
-int execute_demote(const po::variables_map &vm) {
+int execute_demote(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
return 0;
}
-int execute_resync(const po::variables_map &vm) {
+int execute_resync(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
at::add_format_options(options);
}
-int execute_status(const po::variables_map &vm) {
+int execute_status(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
at::Format::Formatter formatter;
int r = utils::get_formatter(vm, &formatter);
if (r < 0) {
("remote-cluster", po::value<std::string>(), "remote cluster name");
}
-int execute_peer_add(const po::variables_map &vm) {
+int execute_peer_add(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name = utils::get_pool_name(vm, &arg_index);
add_uuid_option(positional);
}
-int execute_peer_remove(const po::variables_map &vm) {
+int execute_peer_remove(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name = utils::get_pool_name(vm, &arg_index);
("value", "new client or cluster name");
}
-int execute_peer_set(const po::variables_map &vm) {
+int execute_peer_set(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name = utils::get_pool_name(vm, &arg_index);
return 0;
}
-int execute_disable(const po::variables_map &vm) {
+int execute_disable(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name = utils::get_pool_name(vm, &arg_index);
"disabled");
}
-int execute_enable(const po::variables_map &vm) {
+int execute_enable(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name = utils::get_pool_name(vm, &arg_index);
at::add_format_options(options);
}
-int execute_info(const po::variables_map &vm) {
+int execute_info(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name = utils::get_pool_name(vm, &arg_index);
at::add_verbose_option(options);
}
-int execute_status(const po::variables_map &vm) {
+int execute_status(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name = utils::get_pool_name(vm, &arg_index);
at::add_pool_options(positional, options);
}
-int execute_promote(const po::variables_map &vm) {
+int execute_promote(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name = utils::get_pool_name(vm, &arg_index);
at::add_pool_options(positional, options);
}
-int execute_demote(const po::variables_map &vm) {
+int execute_demote(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name = utils::get_pool_name(vm, &arg_index);
namespace po = boost::program_options;
static int call_nbd_cmd(const po::variables_map &vm,
- const std::vector<const char*> &args)
-{
+ const std::vector<std::string> &args,
+ const std::vector<std::string> &ceph_global_init_args) {
char exe_path[PATH_MAX];
ssize_t exe_path_bytes = readlink("/proc/self/exe", exe_path,
sizeof(exe_path) - 1);
SubProcess process(exe_path, SubProcess::KEEP, SubProcess::KEEP, SubProcess::KEEP);
- if (vm.count("conf")) {
- process.add_cmd_arg("--conf");
- process.add_cmd_arg(vm["conf"].as<std::string>().c_str());
- }
- if (vm.count("cluster")) {
- process.add_cmd_arg("--cluster");
- process.add_cmd_arg(vm["cluster"].as<std::string>().c_str());
- }
- if (vm.count("id")) {
- process.add_cmd_arg("--id");
- process.add_cmd_arg(vm["id"].as<std::string>().c_str());
- }
- if (vm.count("name")) {
- process.add_cmd_arg("--name");
- process.add_cmd_arg(vm["name"].as<std::string>().c_str());
- }
- if (vm.count("mon_host")) {
- process.add_cmd_arg("--mon_host");
- process.add_cmd_arg(vm["mon_host"].as<std::string>().c_str());
- }
- if (vm.count("keyfile")) {
- process.add_cmd_arg("--keyfile");
- process.add_cmd_arg(vm["keyfile"].as<std::string>().c_str());
- }
- if (vm.count("keyring")) {
- process.add_cmd_arg("--keyring");
- process.add_cmd_arg(vm["keyring"].as<std::string>().c_str());
+ for (auto &arg : ceph_global_init_args) {
+ process.add_cmd_arg(arg.c_str());
}
- for (std::vector<const char*>::const_iterator p = args.begin();
- p != args.end(); ++p)
- process.add_cmd_arg(*p);
+ for (auto &arg : args) {
+ process.add_cmd_arg(arg.c_str());
+ }
if (process.spawn()) {
std::cerr << "rbd: failed to run rbd-nbd: " << process.err() << std::endl;
at::add_format_options(options);
}
-int execute_show(const po::variables_map &vm)
-{
- std::vector<const char*> args;
+int execute_show(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
+ std::vector<std::string> args;
args.push_back("list-mapped");
args.push_back("--pretty-format");
}
- return call_nbd_cmd(vm, args);
+ return call_nbd_cmd(vm, args, ceph_global_init_args);
}
void get_map_arguments(po::options_description *positional,
("timeout", po::value<std::string>(), "set nbd request timeout (seconds)");
}
-int execute_map(const po::variables_map &vm)
-{
- std::vector<const char*> args;
+int execute_map(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
+ std::vector<std::string> args;
args.push_back("map");
std::string img;
if (r < 0) {
return r;
}
- args.push_back(img.c_str());
+ args.push_back(img);
if (vm["read-only"].as<bool>())
args.push_back("--read-only");
if (vm.count("device")) {
args.push_back("--device");
- args.push_back(vm["device"].as<std::string>().c_str());
+ args.push_back(vm["device"].as<std::string>());
}
if (vm.count("nbds_max")) {
args.push_back("--nbds_max");
- args.push_back(vm["nbds_max"].as<std::string>().c_str());
+ args.push_back(vm["nbds_max"].as<std::string>());
}
if (vm.count("max_part")) {
args.push_back("--max_part");
- args.push_back(vm["max_part"].as<std::string>().c_str());
+ args.push_back(vm["max_part"].as<std::string>());
}
if (vm.count("timeout")) {
args.push_back("--timeout");
- args.push_back(vm["timeout"].as<std::string>().c_str());
+ args.push_back(vm["timeout"].as<std::string>());
}
- return call_nbd_cmd(vm, args);
+ return call_nbd_cmd(vm, args, ceph_global_init_args);
}
void get_unmap_arguments(po::options_description *positional,
at::add_snap_option(options, at::ARGUMENT_MODIFIER_NONE);
}
-int execute_unmap(const po::variables_map &vm)
-{
+int execute_unmap(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
std::string device_name = utils::get_positional_argument(vm, 0);
if (!boost::starts_with(device_name, "/dev/")) {
device_name.clear();
return -EINVAL;
}
- std::vector<const char*> args;
+ std::vector<std::string> args;
args.push_back("unmap");
- args.push_back(device_name.empty() ? image_name.c_str() :
- device_name.c_str());
+ args.push_back(device_name.empty() ? image_name : device_name);
- return call_nbd_cmd(vm, args);
+ return call_nbd_cmd(vm, args, ceph_global_init_args);
}
Shell::SwitchArguments switched_arguments({"read-only"});
at::add_no_progress_option(options);
}
-int execute_rebuild(const po::variables_map &vm) {
+int execute_rebuild(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
at::add_no_progress_option(options);
}
-int execute_check(const po::variables_map &vm) {
+int execute_check(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
"force initialize pool for RBD use if registered by another application");
}
-int execute_init(const po::variables_map &vm) {
+int execute_init(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name = utils::get_pool_name(vm, &arg_index);
at::add_no_progress_option(options);
}
-int execute(const po::variables_map &vm) {
+int execute(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
at::add_image_spec_options(positional, options, at::ARGUMENT_MODIFIER_DEST);
}
-int execute(const po::variables_map &vm) {
+int execute(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
at::add_no_progress_option(options);
}
-int execute(const po::variables_map &vm) {
+int execute(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
(name.c_str(), po::bool_switch(), "list snapshots from all namespaces");
}
-int execute_list(const po::variables_map &vm) {
+int execute_list(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
at::add_snap_spec_options(positional, options, at::ARGUMENT_MODIFIER_NONE);
}
-int execute_create(const po::variables_map &vm) {
+int execute_create(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
("force", po::bool_switch(), "flatten children and unprotect snapshot if needed.");
}
-int execute_remove(const po::variables_map &vm) {
+int execute_remove(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
at::add_no_progress_option(options);
}
-int execute_purge(const po::variables_map &vm) {
+int execute_purge(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
at::add_no_progress_option(options);
}
-int execute_rollback(const po::variables_map &vm) {
+int execute_rollback(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
at::add_snap_spec_options(positional, options, at::ARGUMENT_MODIFIER_NONE);
}
-int execute_protect(const po::variables_map &vm) {
+int execute_protect(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
at::add_image_id_option(options);
}
-int execute_unprotect(const po::variables_map &vm) {
+int execute_unprotect(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
at::add_limit_option(opt);
}
-int execute_set_limit(const po::variables_map &vm) {
+int execute_set_limit(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
at::add_image_spec_options(pos, opt, at::ARGUMENT_MODIFIER_NONE);
}
-int execute_clear_limit(const po::variables_map &vm) {
+int execute_clear_limit(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
at::add_snap_spec_options(positional, options, at::ARGUMENT_MODIFIER_DEST);
}
-int execute_rename(const po::variables_map &vm) {
+int execute_rename(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
at::add_format_options(options);
}
-int execute(const po::variables_map &vm) {
+int execute(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
"time delay in seconds until effectively remove the image");
}
-int execute_move(const po::variables_map &vm) {
+int execute_move(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
("force", po::bool_switch(), "force remove of non-expired delayed images");
}
-int execute_remove(const po::variables_map &vm) {
+int execute_remove(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_id;
at::add_format_options(options);
}
-int execute_list(const po::variables_map &vm) {
+int execute_list(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name = utils::get_pool_name(vm, &arg_index);
at::add_image_option(options, at::ARGUMENT_MODIFIER_NONE, "");
}
-int execute_restore(const po::variables_map &vm) {
+int execute_restore(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_id;
at::add_image_spec_options(positional, options, at::ARGUMENT_MODIFIER_NONE);
}
-int execute(const po::variables_map &vm) {
+int execute(const po::variables_map &vm,
+ const std::vector<std::string> &ceph_global_init_args) {
size_t arg_index = 0;
std::string pool_name;
std::string image_name;
// vim: ts=8 sw=2 smarttab
#include "tools/rbd/Shell.h"
-#include "include/int_types.h"
-#include "common/ceph_argparse.h"
-#include "global/global_init.h"
-#include <vector>
int main(int argc, const char **argv)
{
- std::vector<const char*> args;
- argv_to_vec(argc, argv, args);
- env_to_vec(args);
-
- auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
- CODE_ENVIRONMENT_UTILITY, 0);
-
rbd::Shell shell;
- return shell.execute(args);
+ return shell.execute(argc, argv);
}