From f40cc664047ba25cb3b78d496b115c55843c1ee0 Mon Sep 17 00:00:00 2001 From: Jos Collin Date: Thu, 22 Feb 2024 20:21:00 +0530 Subject: [PATCH] cephfs-journal-tool: Add warning messages during 'journal reset' and prevent execution on active fs Fixes: https://tracker.ceph.com/issues/62925 Signed-off-by: Jos Collin (cherry picked from commit 57f7d8b70f6989dee09a2adf5ff99b2917589488) --- src/tools/cephfs/JournalTool.cc | 36 ++++++++++++++++++++++++++++---- src/tools/cephfs/first-damage.py | 2 +- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/tools/cephfs/JournalTool.cc b/src/tools/cephfs/JournalTool.cc index fed266123551f..021ad7fdea407 100644 --- a/src/tools/cephfs/JournalTool.cc +++ b/src/tools/cephfs/JournalTool.cc @@ -47,7 +47,7 @@ void JournalTool::usage() << " inspect\n" << " import [--force]\n" << " export \n" - << " reset [--force]\n" + << " reset [--force] <--yes-i-really-really-mean-it>\n" << " cephfs-journal-tool [options] header \n" << " : [trimmed_pos|expire_pos|write_pos|pool_id]\n" << " cephfs-journal-tool [options] event [special options]\n" @@ -139,6 +139,12 @@ int JournalTool::main(std::vector &argv) } auto& fs = fsmap->get_filesystem(role_selector.get_ns()); + stringstream (rank_str.substr(rank_str.find(':') + 1)) >> rank; + if (fs.get_mds_map().is_active(rank)) { + derr << "Cannot run cephfs-journal-tool on an active file system!" << dendl; + return -CEPHFS_EPERM; + } + int64_t const pool_id = fs.get_mds_map().get_metadata_pool(); dout(4) << "JournalTool: resolving pool " << pool_id << dendl; std::string pool_name; @@ -196,7 +202,7 @@ int JournalTool::validate_type(const std::string &type) if (type == "mdlog" || type == "purge_queue") { return 0; } - return -1; + return -CEPHFS_EPERM; } std::string JournalTool::gen_dump_file_path(const std::string &prefix) { @@ -250,14 +256,36 @@ int JournalTool::main_journal(std::vector &argv) } } else if (command == "reset") { bool force = false; - if (argv.size() == 2) { + if (argv.size() == 1) { + std::cerr << "warning: this operation resets the journal!!!\n" + << "Do not run this operation if you do not understand CephFS' internal storage mechanisms or have received specific instructions from those who do.\n" + << "If you want to continue, please add --yes-i-really-really-mean-it!!!" + << std::endl; + return -EINVAL; + } else if (argv.size() == 2) { + if (std::string(argv[1]) == "--force") { + std::cerr << "warning: this operation resets the journal!!!\n" + << "Do not run this operation if you do not understand CephFS' internal storage mechanisms or have received specific instructions from those who do.\n" + << "If you want to continue, please add --yes-i-really-really-mean-it!!!" + << std::endl; + return -EINVAL; + } else if (std::string(argv[1]) != "--yes-i-really-really-mean-it") { + std::cerr << "Unknown argument " << argv[1] << std::endl; + return -EINVAL; + } + } else if (argv.size() == 3) { if (std::string(argv[1]) == "--force") { force = true; } else { std::cerr << "Unknown argument " << argv[1] << std::endl; return -EINVAL; } - } else if (argv.size() > 2) { + + if (std::string(argv[2]) != "--yes-i-really-really-mean-it") { + std::cerr << "Unknown argument " << argv[2] << std::endl; + return -EINVAL; + } + } else if (argv.size() > 3) { std::cerr << "Too many arguments!" << std::endl; return -EINVAL; } diff --git a/src/tools/cephfs/first-damage.py b/src/tools/cephfs/first-damage.py index 0479dc8cb2a6c..28fb783e7ea00 100644 --- a/src/tools/cephfs/first-damage.py +++ b/src/tools/cephfs/first-damage.py @@ -25,7 +25,7 @@ # # 4b) If all good so far, reset the journal: # -# cephfs-journal-tool --rank=:0 journal reset +# cephfs-journal-tool --rank=:0 journal reset --yes-i-really-really-mean-it # # 5) Run this tool to see list of damaged dentries: # -- 2.39.5