From: Igor Fedotov Date: Thu, 6 Mar 2025 20:44:11 +0000 (+0300) Subject: tools/ceph-bluestore-tool: introduce bluefs-super-dump command. X-Git-Tag: v20.3.0~237^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e9d3ea827568afb6063db2ed4fe222b455e5ddec;p=ceph.git tools/ceph-bluestore-tool: introduce bluefs-super-dump command. This is a rework of Adam's commit: https://github.com/ceph/ceph/pull/62069/commits/c8e57c4e06691bef7718277267e7590ae695bd02 Signed-off-by: Igor Fedotov --- diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc index 7279549405b1..f301badfbe0c 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -1861,6 +1861,26 @@ int BlueFS::_replay(bool noop, bool to_stdout) return 0; } +int BlueFS::super_dump() +{ + // only dump superblock's content + _init_logger(); + int r = _open_super(); + if (r < 0) { + derr << __func__ << " failed to open super: " << cpp_strerror(r) << dendl; + return r; + } + ceph::JSONFormatter f(true); + f.open_object_section("superblock"); + super.dump(&f); + f.close_section(); + f.flush(std::cout); + + _shutdown_logger(); + super = bluefs_super_t(); + return r; +} + int BlueFS::log_dump() { // only dump log file's content diff --git a/src/os/bluestore/BlueFS.h b/src/os/bluestore/BlueFS.h index f0c565003b8a..e0676d7967f3 100644 --- a/src/os/bluestore/BlueFS.h +++ b/src/os/bluestore/BlueFS.h @@ -687,6 +687,7 @@ public: int prepare_new_device(int id, const bluefs_layout_t& layout); int log_dump(); + int super_dump(); void collect_metadata(std::map *pm, unsigned skip_bdev_id); void get_devices(std::set *ls); diff --git a/src/os/bluestore/bluestore_tool.cc b/src/os/bluestore/bluestore_tool.cc index 31c7e33c31d2..0983af7bca4e 100644 --- a/src/os/bluestore/bluestore_tool.cc +++ b/src/os/bluestore/bluestore_tool.cc @@ -214,6 +214,25 @@ void log_dump( delete fs; } +void super_dump( + CephContext *cct, + const string& path, + const vector& devs) +{ + validate_path(cct, path, true); + BlueFS *fs = new BlueFS(cct); + + add_devices(fs, cct, devs); + int r = fs->super_dump(); + if (r < 0) { + cerr << "super_dump failed" << ": " + << cpp_strerror(r) << std::endl; + exit(EXIT_FAILURE); + } + + delete fs; +} + void inferring_bluefs_devices(vector& devs, std::string& path) { cout << "inferring bluefs devices from bluestore path" << std::endl; @@ -340,6 +359,7 @@ int main(int argc, char **argv) "set-label-key, " "rm-label-key, " "prime-osd-dir, " + "bluefs-super-dump, " "bluefs-log-dump, " "free-dump, " "free-score, " @@ -513,6 +533,7 @@ int main(int argc, char **argv) } if (action == "bluefs-export" || action == "bluefs-import" || + action == "bluefs-super-dump" || action == "bluefs-log-dump") { if (path.empty()) { cerr << "must specify bluestore path" << std::endl; @@ -1001,6 +1022,8 @@ int main(int argc, char **argv) delete fs; } else if (action == "bluefs-log-dump") { log_dump(cct.get(), path, devs); + } else if (action == "bluefs-super-dump") { + super_dump(cct.get(), path, devs); } else if (action == "bluefs-bdev-new-db" || action == "bluefs-bdev-new-wal") { map cur_devs_map; bool need_db = action == "bluefs-bdev-new-db";