From 7f6ec55b3c2650aef855b396a4e1cd33fd03092b Mon Sep 17 00:00:00 2001 From: Adam Kupczyk Date: Thu, 8 Feb 2024 14:38:09 +0000 Subject: [PATCH] os/bluestore: Update test for resilience of bdev label against bad UUID Signed-off-by: Adam Kupczyk (cherry picked from commit b89fb919160165ea1295254f8b6edf43d9cd3632) --- src/os/bluestore/BlueStore.h | 12 +++++ src/test/objectstore/store_test.cc | 78 ++++++++++++++++++++++++++++-- 2 files changed, 85 insertions(+), 5 deletions(-) diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 4546f7091ec..6894a75b737 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -3412,6 +3412,18 @@ public: _wctx_finish(&txc, c, o, &wctx, nullptr); } + static int debug_read_bdev_label( + CephContext* cct, const std::string &path, + bluestore_bdev_label_t *label, uint64_t disk_position) { + return _read_bdev_label(cct, path, label, disk_position); + } + static int debug_write_bdev_label( + CephContext* cct, const std::string &path, + const bluestore_bdev_label_t& label, uint64_t disk_position) { + return _write_bdev_label(cct, path, label, + std::vector({disk_position})); + } + inline void log_latency(const char* name, int idx, const ceph::timespan& lat, diff --git a/src/test/objectstore/store_test.cc b/src/test/objectstore/store_test.cc index 0c233876d76..4e61bade6a4 100644 --- a/src/test/objectstore/store_test.cc +++ b/src/test/objectstore/store_test.cc @@ -188,10 +188,10 @@ class MultiLabelTest : public StoreTestDeferredSetup { return data_dir; } bool mounted = false; - void mount() { - ASSERT_FALSE(mounted); - store->mount(); - mounted = true; + int mount() { + int r = store->mount(); + if (r == 0) mounted = true; + return r; } void umount() { ASSERT_TRUE(mounted); @@ -10411,7 +10411,6 @@ TEST_P(MultiLabelTest, DetectCorruptedFirst) { bool corrupt = corrupt_disk_at(0); ASSERT_EQ(corrupt, true); ASSERT_EQ(store->fsck(false), 1); - //store->mount(); } TEST_P(MultiLabelTest, FixCorruptedFirst) { @@ -10496,6 +10495,75 @@ TEST_P(MultiLabelTest, CantFixCorruptedAll) { ASSERT_NE(store->repair(false), 0); } +TEST_P(MultiLabelTest, SkipInvalidUUID) { + static constexpr uint64_t _1G = uint64_t(1024)*1024*1024; + SetVal(g_conf(), "bluestore_block_size", + stringify(101L * _1G).c_str()); + SetVal(g_conf(), "bluestore_bdev_label_multi", "true"); + g_conf().apply_changes(nullptr); + DeferredSetup(); + if (!bdev_supports_label()) { + GTEST_SKIP(); + } + umount(); + int r; + bluestore_bdev_label_t label; + r = BlueStore::debug_read_bdev_label(g_ceph_context, + get_data_dir()+"/block", &label, 0); + ASSERT_EQ(r, 0); + label.meta["epoch"] = "1"; + uuid_d new_id; + new_id.generate_random(); + label.osd_uuid = new_id; + r = BlueStore::debug_write_bdev_label(g_ceph_context, + get_data_dir()+"/block", label, 0); + ASSERT_EQ(r, 0); + + ASSERT_EQ(store->fsck(false), 1); + ASSERT_EQ(store->repair(false), 0); + mount(); +} + +TEST_P(MultiLabelTest, FailAllInvalidUUID) { + static constexpr uint64_t _1G = uint64_t(1024)*1024*1024; + SetVal(g_conf(), "bluestore_block_size", + stringify(101 * _1G).c_str()); + SetVal(g_conf(), "bluestore_bdev_label_multi", "true"); + SetVal(g_conf(), "bluestore_bdev_label_require_all", "false"); + g_conf().apply_changes(nullptr); + DeferredSetup(); + if (!bdev_supports_label()) { + GTEST_SKIP(); + } + umount(); + int r; + bluestore_bdev_label_t label; + r = BlueStore::debug_read_bdev_label(g_ceph_context, + get_data_dir()+"/block", &label, 0); + ASSERT_EQ(r, 0); + label.meta["epoch"] = "1"; + uuid_d new_id; + new_id.generate_random(); + label.osd_uuid = new_id; + r = BlueStore::debug_write_bdev_label(g_ceph_context, + get_data_dir()+"/block", label, 0); + ASSERT_EQ(r, 0); + r = BlueStore::debug_write_bdev_label(g_ceph_context, + get_data_dir()+"/block", label, _1G); + ASSERT_EQ(r, 0); + r = BlueStore::debug_write_bdev_label(g_ceph_context, + get_data_dir()+"/block", label, 10 * _1G); + ASSERT_EQ(r, 0); + r = BlueStore::debug_write_bdev_label(g_ceph_context, + get_data_dir()+"/block", label, 100 * _1G); + ASSERT_EQ(r, 0); + + ASSERT_EQ(store->fsck(false), -2); // this is complete failure + ASSERT_EQ(store->repair(false), -2); + r = mount(); + ASSERT_NE(r, 0); +} + TEST_P(MultiLabelTest, SelectNewestLabel) { static constexpr uint64_t _1G = uint64_t(1024)*1024*1024; SetVal(g_conf(), "bluestore_block_size", -- 2.39.5