From 5e4702e303bd70b4ff1de973375bef952c0d8b6a Mon Sep 17 00:00:00 2001 From: Venky Shankar Date: Mon, 23 Jul 2018 02:35:05 -0400 Subject: [PATCH] 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 --- src/tools/cephfs/JournalTool.cc | 33 ++++++++++++++++++++++++-------- src/tools/cephfs/JournalTool.h | 5 +++++ src/tools/cephfs/RoleSelector.cc | 5 +++-- src/tools/cephfs/RoleSelector.h | 3 ++- 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/tools/cephfs/JournalTool.cc b/src/tools/cephfs/JournalTool.cc index 8be2cd85034ff..37f3b5e165a5c 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" << " --journal= Journal type (purge_queue means\n" << " this journal is used to queue for purge operation,\n" << " default is mdlog, and only mdlog support event mode)\n" @@ -96,9 +94,8 @@ int JournalTool::main(std::vector &argv) 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"; + derr << "missing mandatory \"--rank\" argument" << dendl; + return -EINVAL; } if (!ceph_argparse_witharg(argv, arg, &type, "--journal", (char*)NULL)) { @@ -112,7 +109,7 @@ int JournalTool::main(std::vector &argv) return r; } - 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; @@ -161,7 +158,18 @@ int JournalTool::main(std::vector &argv) // ========= // journal and header are general journal mode // event mode is only specific for mdlog - 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; @@ -200,6 +208,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 081e140e8f21e..8d610a8665f1e 100644 --- a/src/tools/cephfs/JournalTool.h +++ b/src/tools/cephfs/JournalTool.h @@ -87,6 +87,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: static void usage(); JournalTool() : diff --git a/src/tools/cephfs/RoleSelector.cc b/src/tools/cephfs/RoleSelector.cc index 3c7932a5eb9e6..e2d53b86ea790 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 933c51d0f78fd..9090b7200fb6d 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) {} -- 2.39.5