From: Venky Shankar Date: Mon, 23 Jul 2018 06:35:05 +0000 (-0400) Subject: cephfs-journal-tool: make "--rank" argument mandatory X-Git-Tag: v12.2.11~96^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b1c20437abee4750749b7b5193b3ff87ab2f11a2;p=ceph.git cephfs-journal-tool: make "--rank" argument mandatory ... and do not silenty act on the default filesystem. Force users to specify the filesystem name and rank. Signed-off-by: Venky Shankar (cherry picked from commit 5e4702e303bd70b4ff1de973375bef952c0d8b6a) Conflicts: src/tools/cephfs/JournalTool.cc src/tools/cephfs/JournalTool.h --- diff --git a/src/tools/cephfs/JournalTool.cc b/src/tools/cephfs/JournalTool.cc index a5f927431c47..a9756f73e2a9 100644 --- a/src/tools/cephfs/JournalTool.cc +++ b/src/tools/cephfs/JournalTool.cc @@ -62,9 +62,7 @@ void JournalTool::usage() << " : [summary|list|binary|json] [--path ]\n" << "\n" << "General options:\n" - << " --rank=filesystem:mds-rank Journal rank (required if multiple\n" - << " file systems, default is rank 0 on\n" - << " the only filesystem otherwise.\n" + << " --rank=filesystem:mds-rank|all Journal rank (mandatory)\n" << "\n" << "Special options\n" << " --alternate-pool Alternative metadata pool to target\n" @@ -92,13 +90,12 @@ int JournalTool::main(std::vector &argv) std::vector::iterator arg = argv.begin(); std::string rank_str; - if(!ceph_argparse_witharg(argv, arg, &rank_str, "--rank", (char*)NULL)) { - // Default: act on rank 0. Will give the user an error if they - // try invoking this way when they have more than one filesystem. - rank_str = "0"; + if (!ceph_argparse_witharg(argv, arg, &rank_str, "--rank", (char*)NULL)) { + derr << "missing mandatory \"--rank\" argument" << dendl; + return -EINVAL; } - r = role_selector.parse(*fsmap, rank_str); + r = role_selector.parse(*fsmap, rank_str, false); if (r != 0) { derr << "Couldn't determine MDS rank." << dendl; return r; @@ -145,7 +142,18 @@ int JournalTool::main(std::vector &argv) // Execution // ========= - for (auto role : role_selector.get_roles()) { + auto roles = role_selector.get_roles(); + if (roles.size() > 1) { + const std::string &command = argv[0]; + bool allowed = can_execute_for_all_ranks(mode, command); + if (!allowed) { + derr << "operation not allowed for all ranks" << dendl; + return -EINVAL; + } + + all_ranks = true; + } + for (auto role : roles) { rank = role.rank; std::vector rank_argv(argv); dout(4) << "Executing for rank " << rank << dendl; @@ -178,6 +186,15 @@ std::string JournalTool::gen_dump_file_path(const std::string &prefix) { return prefix + "." + std::to_string(rank); } +bool JournalTool::can_execute_for_all_ranks(const std::string &mode, + const std::string &command) { + if (mode == "journal" && command == "import") { + return false; + } + + return true; +} + /** * Handle arguments for 'journal' mode * diff --git a/src/tools/cephfs/JournalTool.h b/src/tools/cephfs/JournalTool.h index 2f904e2397ca..4dccd92f12b5 100644 --- a/src/tools/cephfs/JournalTool.h +++ b/src/tools/cephfs/JournalTool.h @@ -84,6 +84,11 @@ class JournalTool : public MDSUtility // generate output file path for dump/export std::string gen_dump_file_path(const std::string &prefix); + // check if an operation (mode, command) is safe to be + // executed on all ranks. + bool can_execute_for_all_ranks(const std::string &mode, + const std::string &command); + public: void usage(); JournalTool() : diff --git a/src/tools/cephfs/RoleSelector.cc b/src/tools/cephfs/RoleSelector.cc index 3c7932a5eb9e..e2d53b86ea79 100644 --- a/src/tools/cephfs/RoleSelector.cc +++ b/src/tools/cephfs/RoleSelector.cc @@ -29,13 +29,14 @@ int MDSRoleSelector::parse_rank( } } -int MDSRoleSelector::parse(const FSMap &fsmap, std::string const &str) +int MDSRoleSelector::parse(const FSMap &fsmap, std::string const &str, + bool allow_unqualified_rank) { auto colon_pos = str.find(":"); if (colon_pos == std::string::npos) { // An unqualified rank. Only valid if there is only one // namespace. - if (fsmap.filesystem_count() == 1) { + if (fsmap.filesystem_count() == 1 && allow_unqualified_rank) { fscid = fsmap.get_filesystem()->fscid; return parse_rank(fsmap, str); } else { diff --git a/src/tools/cephfs/RoleSelector.h b/src/tools/cephfs/RoleSelector.h index 933c51d0f78f..9090b7200fb6 100644 --- a/src/tools/cephfs/RoleSelector.h +++ b/src/tools/cephfs/RoleSelector.h @@ -15,7 +15,8 @@ class MDSRoleSelector { public: const std::vector &get_roles() const {return roles;} - int parse(const FSMap &fsmap, std::string const &str); + int parse(const FSMap &fsmap, std::string const &str, + bool allow_unqualified_rank=true); MDSRoleSelector() : fscid(FS_CLUSTER_ID_NONE) {}