From: Adam Kupczyk Date: Thu, 5 Aug 2021 09:00:54 +0000 (+0200) Subject: tools/ceph-bluestore-tool: Enable configuration options from monitor/ceph.conf X-Git-Tag: v17.1.0~1155^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=46603dab364a8d7e1f3fb35e36c98c619c26977f;p=ceph.git tools/ceph-bluestore-tool: Enable configuration options from monitor/ceph.conf Added option -i that allows to operate as specific osd. It reads configuration options from monitor or ceph.conf. In addition providing configuration option not accepted by OSD or ceph-bluestore-tool is now an error. Signed-off-by: Adam Kupczyk --- diff --git a/doc/man/8/ceph-bluestore-tool.rst b/doc/man/8/ceph-bluestore-tool.rst index 94d712c7b7b..8c92275dafc 100644 --- a/doc/man/8/ceph-bluestore-tool.rst +++ b/doc/man/8/ceph-bluestore-tool.rst @@ -11,6 +11,7 @@ Synopsis | **ceph-bluestore-tool** *command* [ --dev *device* ... ] + [ -i *osd_id* ] [ --path *osd path* ] [ --out-dir *dir* ] [ --log-file | -l *filename* ] @@ -121,6 +122,11 @@ Options Add *device* to the list of devices to consider +.. option:: -i *osd_id* + + Operate as OSD *osd_id*. Connect to monitor for OSD specific options. + If monitor is unavailable, add --no-mon-config to read from ceph.conf instead. + .. option:: --devs-source *device* Add *device* to the list of devices to consider as sources for migrate operation @@ -131,7 +137,7 @@ Options .. option:: --path *osd path* - Specify an osd path. In most cases, the device list is inferred from the symlinks present in *osd path*. This is usually simpler than explicitly specifying the device(s) with --dev. + Specify an osd path. In most cases, the device list is inferred from the symlinks present in *osd path*. This is usually simpler than explicitly specifying the device(s) with --dev. Not necessary if -i *osd_id* is provided. .. option:: --out-dir *dir* @@ -161,6 +167,12 @@ Options /// Default: 10000000/10000/1000000/1000 +Additional ceph.conf options +============================ + +Any configuration option that is accepted by OSD can be also passed to **ceph-bluestore-tool**. +Useful to provide necessary configuration options when access to monitor/ceph.conf is impossible and -i option cannot be used. + Device labels ============= diff --git a/src/os/bluestore/bluestore_tool.cc b/src/os/bluestore/bluestore_tool.cc index 80418388287..0f4704ac5cb 100644 --- a/src/os/bluestore/bluestore_tool.cc +++ b/src/os/bluestore/bluestore_tool.cc @@ -274,6 +274,7 @@ static void bluefs_import( int main(int argc, char **argv) { string out_dir; + string osd_instance; vector devs; vector devs_source; string dev_target; @@ -292,6 +293,7 @@ int main(int argc, char **argv) po::options_description po_options("Options"); po_options.add_options() ("help,h", "produce help message") + (",i", po::value(&osd_instance), "OSD instance. Requires access to monitor/ceph.conf") ("path", po::value(&path), "bluestore path") ("out-dir", po::value(&out_dir), "output directory") ("input-file", po::value(&input_file), "import file") @@ -335,14 +337,12 @@ int main(int argc, char **argv) ; po::options_description po_all("All options"); po_all.add(po_options).add(po_positional); - po::positional_options_description pd; - pd.add("command", 1); vector ceph_option_strings; po::variables_map vm; try { po::parsed_options parsed = - po::command_line_parser(argc, argv).options(po_all).allow_unregistered().positional(pd).run(); + po::command_line_parser(argc, argv).options(po_all).allow_unregistered().run(); po::store( parsed, vm); po::notify(vm); ceph_option_strings = po::collect_unrecognized(parsed.options, @@ -359,11 +359,71 @@ int main(int argc, char **argv) usage(po_all); exit(EXIT_SUCCESS); } + + vector args; + if (log_file.size()) { + args.push_back("--log-file"); + args.push_back(log_file.c_str()); + static char ll[10]; + snprintf(ll, sizeof(ll), "%d", log_level); + args.push_back("--debug-bluestore"); + args.push_back(ll); + args.push_back("--debug-bluefs"); + args.push_back(ll); + args.push_back("--debug-rocksdb"); + args.push_back(ll); + } else { + // do not write to default-named log "osd.x.log" if --log-file is not provided + if (!osd_instance.empty()) { + args.push_back("--no-log-to-file"); + } + } + + if (!osd_instance.empty()) { + args.push_back("-i"); + args.push_back(osd_instance.c_str()); + } + args.push_back("--no-log-to-stderr"); + args.push_back("--err-to-stderr"); + + for (auto& i : ceph_option_strings) { + args.push_back(i.c_str()); + } + auto cct = global_init(NULL, args, osd_instance.empty() ? CEPH_ENTITY_TYPE_CLIENT : CEPH_ENTITY_TYPE_OSD, + CODE_ENVIRONMENT_UTILITY, + osd_instance.empty() ? CINIT_FLAG_NO_DEFAULT_CONFIG_FILE : 0); + + common_init_finish(cct.get()); + if (action.empty()) { + // if action ("command") is not yet defined try to use first param as action + if (args.size() > 0) { + if (args.size() == 1) { + // treat first unparsed value as action + action = args[0]; + } else { + std::cerr << "Unknown options: " << args << std::endl; + exit(EXIT_FAILURE); + } + } + } else { + if (args.size() != 0) { + std::cerr << "Unknown options: " << args << std::endl; + exit(EXIT_FAILURE); + } + } + if (action.empty()) { cerr << "must specify an action; --help for help" << std::endl; exit(EXIT_FAILURE); } + if (!osd_instance.empty()) { + // when "-i" is provided "osd data" can be used as path + if (path.size() == 0) { + path = cct->_conf.get_val("osd_data"); + } + } + if (action == "fsck" || action == "repair" || action == "quick-fix") { if (path.empty()) { cerr << "must specify bluestore path" << std::endl; @@ -483,30 +543,6 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } } - vector args; - if (log_file.size()) { - args.push_back("--log-file"); - args.push_back(log_file.c_str()); - static char ll[10]; - snprintf(ll, sizeof(ll), "%d", log_level); - args.push_back("--debug-bluestore"); - args.push_back(ll); - args.push_back("--debug-bluefs"); - args.push_back(ll); - args.push_back("--debug-rocksdb"); - args.push_back(ll); - } - args.push_back("--no-log-to-stderr"); - args.push_back("--err-to-stderr"); - - for (auto& i : ceph_option_strings) { - args.push_back(i.c_str()); - } - auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, - CODE_ENVIRONMENT_UTILITY, - CINIT_FLAG_NO_DEFAULT_CONFIG_FILE); - - common_init_finish(cct.get()); if (action == "fsck" || action == "repair" ||