]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
seastore: support validating device signature for ceph-lvm 64333/head
authorMohit Agrawal <moagrawa@redhat.com>
Thu, 3 Jul 2025 12:28:29 +0000 (17:58 +0530)
committerMohit Agrawal <moagrawa@redhat.com>
Thu, 10 Jul 2025 08:11:18 +0000 (13:41 +0530)
Write the SEASTORE_SUPERBLOCK_SIGN at offset 0 before
encoding the superblock. If the signature is added inside
the block_sm_superblock_t structure (via DENC), it won't be
written at offset 0 because DENC encoding add some metadata.
Therefore prepend the signature to the bufferlist before
encoding the superblock sothat signature always appears at the
start of the written data

Fixes: https://tracker.ceph.com/issues/71954
Signed-off-by: Mohit Agrawal <moagrawa@redhat.com>
src/crimson/os/seastore/seastore_types.h
src/crimson/os/seastore/segment_manager/block.cc

index 5a80c6ef720f5f0449051b059324ce11406cd4f2..c5cb9472f3491214efa1d58ccf746522c24710aa 100644 (file)
@@ -118,6 +118,11 @@ constexpr device_id_t DEVICE_ID_SEGMENTED_MIN = 0;
 constexpr device_id_t DEVICE_ID_RANDOM_BLOCK_MIN = 
   1 << (std::numeric_limits<device_id_t>::digits - 1);
 
+// TODO this Signature is only applicable for segment devices(SSD/HDD) not
+// for other two devices like ZBD/RANDOM_BLOCK_SSD
+constexpr const char SEASTORE_SUPERBLOCK_SIGN[] = "seastore block device\n";
+constexpr std::size_t SEASTORE_SUPERBLOCK_SIGN_LEN = sizeof(SEASTORE_SUPERBLOCK_SIGN) - 1;
+
 struct device_id_printer_t {
   device_id_t id;
 };
index 98a3d1bb9282de5ff9cce0ebea563a541e134313..185c139b358ddfd822cb19505919651d02138bb6 100644 (file)
@@ -293,7 +293,10 @@ write_superblock(
     bufferptr(ceph::buffer::create_page_aligned(sb.block_size)),
     [=, &device](auto &bp)
   {
+    //  Encode SEASTORE_SUPERBLOCK_SIGN at offset 0 before
+    //  encoding anything else
     bufferlist bl;
+    bl.append(SEASTORE_SUPERBLOCK_SIGN);
     encode(sb, bl);
     auto iter = bl.begin();
     assert(bl.length() < sb.block_size);
@@ -323,14 +326,23 @@ read_superblock(seastar::file &device, seastar::stat_data sd)
       bl.push_back(bp);
       block_sm_superblock_t ret;
       auto bliter = bl.cbegin();
+      // Validate the magic prefix
+      std::string sb_magic;
+      bliter.copy(SEASTORE_SUPERBLOCK_SIGN_LEN, sb_magic);
+      if (sb_magic != SEASTORE_SUPERBLOCK_SIGN) {
+        ERROR("invalid superblock signature: got '{}' expected '{}'",
+             sb_magic, SEASTORE_SUPERBLOCK_SIGN);
+        ceph_abort_msg("invalid superblock signature");
+      }
+
       try {
         decode(ret, bliter);
       } catch (...) {
         ERROR("got decode error!");
         ceph_assert(0 == "invalid superblock");
       }
-      assert(ceph::encoded_sizeof<block_sm_superblock_t>(ret) <
-             sd.block_size);
+      assert(ceph::encoded_sizeof<block_sm_superblock_t>(ret) +
+            SEASTORE_SUPERBLOCK_SIGN_LEN <= sd.block_size);
       return BlockSegmentManager::access_ertr::future<block_sm_superblock_t>(
         BlockSegmentManager::access_ertr::ready_future_marker{},
         ret);