]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-bluestore-tool: Fix set-label-key and rm-label-key
authorAdam Kupczyk <akupczyk@ibm.com>
Wed, 24 Apr 2024 17:13:22 +0000 (17:13 +0000)
committerAdam Kupczyk <akupczyk@ibm.com>
Mon, 22 Jul 2024 12:36:29 +0000 (12:36 +0000)
Functions were not adapted to multiple superblocks.
Now for superblock labels that handle multiple copies, all are updated.

Signed-off-by: Adam Kupczyk <akupczyk@ibm.com>
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h
src/os/bluestore/bluestore_tool.cc
src/test/objectstore/store_test.cc

index 918e6563fc84ab7e8a60d9f421addc447488dcb9..ec648692c9ecfdb3509898caf9779d7b75ee0f1a 100644 (file)
@@ -6018,7 +6018,7 @@ int BlueStore::write_meta(const std::string& key, const std::string& value)
   }
   string p = path + "/block";
   if (bdev_label_valid_locations.empty()) {
-    _read_main_bdev_label(cct, bdev, p, fsid, &bdev_label, &bdev_label_valid_locations,
+    _read_multi_bdev_label(cct, bdev, p, fsid, &bdev_label, &bdev_label_valid_locations,
       &bdev_label_multi, &bdev_label_epoch);
   }
   if (!bdev_label_valid_locations.empty()) {
@@ -6041,7 +6041,7 @@ int BlueStore::read_meta(const std::string& key, std::string *value)
   }
   string p = path + "/block";
   if (bdev_label_valid_locations.empty()) {
-    _read_main_bdev_label(cct, bdev, p, fsid, &bdev_label, &bdev_label_valid_locations,
+    _read_multi_bdev_label(cct, bdev, p, fsid, &bdev_label, &bdev_label_valid_locations,
       &bdev_label_multi, &bdev_label_epoch);
   }
   if (!bdev_label_valid_locations.empty()) {
@@ -6487,7 +6487,7 @@ int BlueStore::get_block_device_fsid(CephContext* cct, const string& path,
   unique_ptr<BlockDevice> bdev(BlockDevice::create(cct, bdev_path, nullptr, nullptr, nullptr, nullptr));
   int r = bdev->open(bdev_path);
   if (r == 0) {
-    r = _read_main_bdev_label(cct, bdev.get(), bdev_path, uuid_d(), &label);
+    r = _read_multi_bdev_label(cct, bdev.get(), bdev_path, uuid_d(), &label);
   }
   if (r == 0) {
     *fsid = label.osd_uuid;
@@ -6637,7 +6637,7 @@ int BlueStore::_read_bdev_label(
   1    When some, but not all labels are read
   -ENOENT Otherwise
 */
-int BlueStore::_read_main_bdev_label(
+int BlueStore::_read_multi_bdev_label(
   CephContext* cct,
   BlockDevice* bdev,
   const string& path,
@@ -6697,7 +6697,7 @@ int BlueStore::_read_main_bdev_label(
         }
       } else {
         derr << __func__ << " label at 0x" << std::hex << position << std::dec
-             << " is multi=yes but no epoch=" << dendl;
+             << " is multi=yes but no epoch" << dendl;
       }
     } else if (r == 0) {
       derr << __func__ << " label at 0x" << std::hex << position << std::dec
@@ -6843,7 +6843,7 @@ int BlueStore::_set_main_bdev_label()
 int BlueStore::_check_main_bdev_label()
 {
   string block_path = path + "/block";
-  int r = _read_main_bdev_label(cct, bdev, block_path, fsid, &bdev_label,
+  int r = _read_multi_bdev_label(cct, bdev, block_path, fsid, &bdev_label,
     &bdev_label_valid_locations, &bdev_label_multi, &bdev_label_epoch);
   if (r < 0)
     return r;
@@ -6863,16 +6863,21 @@ int BlueStore::_check_main_bdev_label()
 }
 
 int BlueStore::read_bdev_label(
-  CephContext* cct, const std::string &path,
-  bluestore_bdev_label_t *label, uint64_t disk_position)
+  CephContext* cct,
+  const std::string &path,
+  bluestore_bdev_label_t* out_label,
+  std::vector<uint64_t>* out_valid_positions,
+  bool* out_is_multi,
+  int64_t* out_epoch)
 {
   unique_ptr<BlockDevice> bdev(BlockDevice::create(
     cct, path, nullptr, nullptr, nullptr, nullptr));
   int r = bdev->open(path);
   if (r < 0)
     return r;
-  r = BlueStore::_read_bdev_label(
-    cct, bdev.get(), path, label, disk_position);
+  uuid_d fsid;
+  r = BlueStore::_read_multi_bdev_label(
+    cct, bdev.get(), path, fsid, out_label, out_valid_positions, out_is_multi, out_epoch);
   bdev->close();
   return r;
 }
index a6f1c2a2ffd460de3c340c2f7ca53e633fb5889a..8ad87e41178ce28f07e654ba9a7f7e9bc16c93d1 100644 (file)
@@ -2767,14 +2767,14 @@ private:
                                const std::string& desc, bool create);
   int _set_main_bdev_label();
   int _check_main_bdev_label();
-  static int _read_main_bdev_label(
+  static int _read_multi_bdev_label(
     CephContext* cct,
     BlockDevice* bdev,
     const std::string& path,
     uuid_d fsid,
     bluestore_bdev_label_t *out_label,
     std::vector<uint64_t>* out_valid_positions = nullptr,
-    bool* out_is_cloned = nullptr,
+    bool* out_is_multi = nullptr,
     int64_t* out_epoch = nullptr);
   int _set_bdev_label_size(const std::string& path, uint64_t size);
   void _main_bdev_label_try_reserve();
@@ -3454,8 +3454,12 @@ public:
         std::vector<uint64_t>({disk_position}));
     }
   static int read_bdev_label(
-    CephContext* cct, const std::string &path,
-    bluestore_bdev_label_t *label, uint64_t disk_position = 0);
+    CephContext* cct,
+    const std::string &path,
+    bluestore_bdev_label_t *out_label,
+    std::vector<uint64_t>* out_valid_positions = nullptr,
+    bool* out_is_cloned = nullptr,
+    int64_t* out_epoch = nullptr);
   static int write_bdev_label(
     CephContext* cct, const std::string &path,
     const bluestore_bdev_label_t& label, uint64_t disk_position = 0);
index eaf651d8e18618ab999c0b26afd984a67357520f..b53a8cdcb40a823c981003b301a78d7277571d22 100644 (file)
@@ -746,7 +746,11 @@ int main(int argc, char **argv)
   }
   else if (action == "set-label-key") {
     bluestore_bdev_label_t label;
-    int r = BlueStore::read_bdev_label(cct.get(), devs.front(), &label);
+    std::vector<uint64_t> valid_positions;
+    bool is_multi = false;
+    int64_t epoch = -1;
+    int r = BlueStore::read_bdev_label(cct.get(), devs.front(), &label,
+      &valid_positions, &is_multi, &epoch);
     if (r < 0) {
       cerr << "unable to read label for " << devs.front() << ": "
           << cpp_strerror(r) << std::endl;
@@ -768,16 +772,32 @@ int main(int argc, char **argv)
     } else {
       label.meta[key] = value;
     }
-    r = BlueStore::write_bdev_label(cct.get(), devs.front(), label);
-    if (r < 0) {
-      cerr << "unable to write label for " << devs.front() << ": "
-          << cpp_strerror(r) << std::endl;
-      exit(EXIT_FAILURE);
+    if (is_multi) {
+      epoch++;
+      label.meta["epoch"] = std::to_string(epoch);
+    }
+    bool wrote_at_least_one = false;
+    for (uint64_t position : valid_positions) {
+      r = BlueStore::write_bdev_label(cct.get(), devs.front(), label, position);
+      if (r < 0) {
+        cerr << "unable to write label for " << devs.front()
+             << " at 0x" << std::hex << position << std::dec
+             << ": " << cpp_strerror(r) << std::endl;
+      } else {
+        wrote_at_least_one = true;
+      }
+    }
+    if (!wrote_at_least_one) {
+        exit(EXIT_FAILURE);
     }
   }
   else if (action == "rm-label-key") {
     bluestore_bdev_label_t label;
-    int r = BlueStore::read_bdev_label(cct.get(), devs.front(), &label);
+    std::vector<uint64_t> valid_positions;
+    bool is_multi = false;
+    int64_t epoch = -1;
+    int r = BlueStore::read_bdev_label(cct.get(), devs.front(), &label,
+      &valid_positions, &is_multi, &epoch);
     if (r < 0) {
       cerr << "unable to read label for " << devs.front() << ": "
           << cpp_strerror(r) << std::endl;
@@ -788,11 +808,23 @@ int main(int argc, char **argv)
       exit(EXIT_FAILURE);
     }
     label.meta.erase(key);
-    r = BlueStore::write_bdev_label(cct.get(), devs.front(), label);
-    if (r < 0) {
-      cerr << "unable to write label for " << devs.front() << ": "
-          << cpp_strerror(r) << std::endl;
-      exit(EXIT_FAILURE);
+    if (is_multi) {
+      epoch++;
+      label.meta["epoch"] = std::to_string(epoch);
+    }
+    bool wrote_at_least_one = false;
+    for (uint64_t position : valid_positions) {
+      r = BlueStore::write_bdev_label(cct.get(), devs.front(), label, position);
+      if (r < 0) {
+        cerr << "unable to write label for " << devs.front()
+             << " at 0x" << std::hex << position << std::dec
+             << ": " << cpp_strerror(r) << std::endl;
+      } else {
+        wrote_at_least_one = true;
+      }
+    }
+    if (!wrote_at_least_one) {
+        exit(EXIT_FAILURE);
     }
   }
   else if (action == "bluefs-bdev-sizes") {
index 87ec5b99d60a36e26df12d54ef2faae30e07889c..60c8cca100b68b8149bc3ce88b1366af06ba21df 100644 (file)
@@ -239,12 +239,24 @@ class MultiLabelTest : public StoreTestDeferredSetup {
   }
   bool read_bdev_label(bluestore_bdev_label_t* label, uint64_t position) {
     string bdev_path = get_data_dir() + "/block";
-    int r = BlueStore::read_bdev_label(g_ceph_context, bdev_path, label, position);
+    unique_ptr<BlockDevice> 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();
     return r;
   }
   bool write_bdev_label(const bluestore_bdev_label_t& label, uint64_t position) {
     string bdev_path = get_data_dir() + "/block";
-    int r = BlueStore::write_bdev_label(g_ceph_context, bdev_path, label, position);
+    unique_ptr<BlockDevice> 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_write_bdev_label(g_ceph_context, bdev.get(), bdev_path, label, position);
+    bdev->close();
     return r;
   }
   protected: