From b6b7ef8af414527cfa391ee129db98661fdaed26 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 10 Jan 2019 11:01:19 -0600 Subject: [PATCH] ceph-monstore-tool: add --monmap argument to rebuild command Signed-off-by: Sage Weil --- src/tools/ceph_monstore_tool.cc | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/tools/ceph_monstore_tool.cc b/src/tools/ceph_monstore_tool.cc index 043fdd93cd032..ae3e151b2b427 100644 --- a/src/tools/ceph_monstore_tool.cc +++ b/src/tools/ceph_monstore_tool.cc @@ -496,13 +496,27 @@ static int update_auth(MonitorDBStore& st, const string& keyring_path) return 0; } -static int update_mkfs(MonitorDBStore& st) +static int update_mkfs(MonitorDBStore& st, const string& monmap_path) { MonMap monmap; - int r = monmap.build_initial(g_ceph_context, true, cerr); - if (r) { - cerr << "no initial monitors" << std::endl; - return -EINVAL; + if (!monmap_path.empty()) { + cout << __func__ << " pulling initial monmap from " << monmap_path << std::endl; + bufferlist bl; + string err; + int r = bl.read_file(monmap_path.c_str(), &err); + if (r < 0) { + cerr << "failed to read monmap from " << monmap_path << ": " + << cpp_strerror(r) << std::endl; + return r; + } + monmap.decode(bl); + } else { + cout << __func__ << " generating seed initial monmap" << std::endl; + int r = monmap.build_initial(g_ceph_context, true, cerr); + if (r) { + cerr << "no initial monitors" << std::endl; + return -EINVAL; + } } monmap.print(cout); bufferlist bl; @@ -626,9 +640,12 @@ int rebuild_monstore(const char* progname, { po::options_description op_desc("Allowed 'rebuild' options"); string keyring_path; + string monmap_path; op_desc.add_options() ("keyring", po::value(&keyring_path), - "path to the client.admin key"); + "path to the client.admin key") + ("monmap", po::value(&monmap_path), + "path to the initial monmap"); po::variables_map op_vm; int r = parse_cmd_args(&op_desc, nullptr, nullptr, subcmds, &op_vm); if (r) { @@ -649,7 +666,7 @@ int rebuild_monstore(const char* progname, if ((r = update_paxos(st))) { return r; } - if ((r = update_mkfs(st))) { + if ((r = update_mkfs(st, monmap_path))) { return r; } if ((r = update_monitor(st))) { -- 2.39.5