]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
os/bluestore: Update test for resilience of bdev label against bad UUID
authorAdam Kupczyk <akupczyk@ibm.com>
Thu, 8 Feb 2024 14:38:09 +0000 (14:38 +0000)
committerPere Diaz Bou <pere-altea@hotmail.com>
Fri, 23 Aug 2024 09:49:24 +0000 (11:49 +0200)
Signed-off-by: Adam Kupczyk <akupczyk@ibm.com>
(cherry picked from commit b89fb919160165ea1295254f8b6edf43d9cd3632)

src/os/bluestore/BlueStore.h
src/test/objectstore/store_test.cc

index 4546f7091ecab5efd865e0cbe8c23669d2c8d5c3..6894a75b73735007ce3042413caf80860adfcf92 100644 (file)
@@ -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<uint64_t>({disk_position}));
+    }
+
   inline void log_latency(const char* name,
     int idx,
     const ceph::timespan& lat,
index 0c233876d766bfe43d7403aebc52aa698d22a00c..4e61bade6a4a7df092d86212134dca52848ead1b 100644 (file)
@@ -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",