From: Igor Fedotov Date: Sat, 15 Feb 2025 17:13:22 +0000 (+0300) Subject: tools/bluestore-tool: add "show-label-at" command X-Git-Tag: testing/wip-khiremat-testing-20250424.121018-squid-debug~19^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6b3a7b46c0c9f9f12fd0ceb2a7bb0b22a5343b2a;p=ceph-ci.git tools/bluestore-tool: add "show-label-at" command Signed-off-by: Igor Fedotov (cherry picked from commit 19788291c991d11313fb2bebce48dcb7354b882e) --- diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index db935ade9fc..f1d650d390f 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -6915,6 +6915,26 @@ int BlueStore::_check_main_bdev_label() return 0; } +int BlueStore::read_bdev_label_at_pos( + CephContext* cct, + const std::string &bdev_path, + uint64_t disk_position, + bluestore_bdev_label_t *label) +{ + unique_ptr bdev(BlockDevice::create( + cct, bdev_path, nullptr, nullptr, nullptr, nullptr)); + if (!bdev) { + return -EIO; + } + bdev->set_no_exclusive_lock(); + int r = bdev->open(bdev_path); + if (r < 0) + return r; + r = _read_bdev_label(cct, bdev.get(), bdev_path, label, disk_position); + bdev->close(); + return r; +} + int BlueStore::read_bdev_label( CephContext* cct, const std::string &path, diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 58ba1e9b4b5..368c842d4cd 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -231,6 +231,8 @@ enum { #define META_POOL_ID ((uint64_t)-1ull) using bptr_c_it_t = buffer::ptr::const_iterator; +extern const std::vector bdev_label_positions; + class BlueStore : public ObjectStore, public md_config_obs_t { // ----------------------------------------------------- @@ -3433,17 +3435,17 @@ public: _wctx_finish(&txc, c, o, &wctx, nullptr); } - static int debug_read_bdev_label( - CephContext* cct, BlockDevice* bdev, const std::string &path, - bluestore_bdev_label_t *label, uint64_t disk_position) { - return _read_bdev_label(cct, bdev, path, label, disk_position); - } static int debug_write_bdev_label( CephContext* cct, BlockDevice* bdev, const std::string &path, const bluestore_bdev_label_t& label, uint64_t disk_position) { return _write_bdev_label(cct, bdev, path, label, std::vector({disk_position})); } + static int read_bdev_label_at_pos( + CephContext* cct, + const std::string &bdev_path, + uint64_t disk_position, + bluestore_bdev_label_t *label); static int read_bdev_label( CephContext* cct, const std::string &path, diff --git a/src/os/bluestore/bluestore_tool.cc b/src/os/bluestore/bluestore_tool.cc index 0d18eaf2c9e..b8cd83a5801 100644 --- a/src/os/bluestore/bluestore_tool.cc +++ b/src/os/bluestore/bluestore_tool.cc @@ -290,6 +290,7 @@ int main(int argc, char **argv) string resharding_ctrl; int log_level = 30; bool fsck_deep = false; + uint64_t disk_offset; po::options_description po_options("Options"); po_options.add_options() ("help,h", "produce help message") @@ -314,6 +315,7 @@ int main(int argc, char **argv) ("resharding-ctrl", po::value(&resharding_ctrl), "gives control over resharding procedure details") ("op", po::value(&action_aux), "--command alias, ignored if the latter is present") + ("offset", po::value(&disk_offset), "disk location") ; po::options_description po_positional("Positional options"); po_positional.add_options() @@ -332,6 +334,7 @@ int main(int argc, char **argv) "bluefs-bdev-new-wal, " "bluefs-bdev-migrate, " "show-label, " + "show-label-at, " "set-label-key, " "rm-label-key, " "prime-osd-dir, " @@ -499,6 +502,12 @@ int main(int argc, char **argv) if (devs.empty()) inferring_bluefs_devices(devs, path); } + if (action == "show-label-at") { + if (devs.empty()) { + cerr << "must specify bluestore raw device" << std::endl; + exit(EXIT_FAILURE); + } + } if (action == "bluefs-export" || action == "bluefs-import" || action == "bluefs-log-dump") { @@ -746,6 +755,35 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } } + else if (action == "show-label-at") { + JSONFormatter jf(true); + bluestore_bdev_label_t label; + bool valid_offset = false; + for (auto o : bdev_label_positions) { + if (disk_offset == o) { + valid_offset = true; + break; + } + } + if (!valid_offset) { + cerr << "Suspicious offset: " << disk_offset + << ", expected locations: " << bdev_label_positions + << std::endl; + } + int r = BlueStore::read_bdev_label_at_pos(cct.get(), devs[0], disk_offset, &label); + if (r < 0) { + cerr << "unable to read label for " << devs[0] << ": " + << cpp_strerror(r) << std::endl; + exit(EXIT_FAILURE); + } + jf.open_object_section(devs[0].c_str()); + label.dump(&jf); + jf.open_array_section("locations"); + jf.dump_format("", "0x%llx", disk_offset); + jf.close_section(); + jf.close_section(); + jf.flush(cout); + } else if (action == "set-label-key") { bluestore_bdev_label_t label; std::vector valid_positions; diff --git a/src/test/objectstore/store_test.cc b/src/test/objectstore/store_test.cc index 21278e717f0..35aa29e63c7 100644 --- a/src/test/objectstore/store_test.cc +++ b/src/test/objectstore/store_test.cc @@ -221,13 +221,7 @@ class MultiLabelTest : public StoreTestDeferredSetup { } bool read_bdev_label(bluestore_bdev_label_t* label, uint64_t position) { string bdev_path = get_data_dir() + "/block"; - unique_ptr bdev(BlockDevice::create( - g_ceph_context, bdev_path, nullptr, nullptr, nullptr, nullptr)); - int r = bdev->open(bdev_path); - if (r < 0) - return r; - r = BlueStore::debug_read_bdev_label(g_ceph_context, bdev.get(), bdev_path, label, position); - bdev->close(); + int r = BlueStore::read_bdev_label_at_pos(g_ceph_context, bdev_path, position, label); return r; } bool write_bdev_label(const bluestore_bdev_label_t& label, uint64_t position) {