]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
seastore/cbjournal: remove header_checksum field and add calculating header checkksum
authormyoungwon oh <ohmyoungwon@gmail.com>
Fri, 13 May 2022 07:30:51 +0000 (16:30 +0900)
committermyoungwon oh <ohmyoungwon@gmail.com>
Thu, 19 May 2022 00:51:55 +0000 (09:51 +0900)
Signed-off-by: Myoungwon Oh <myoungwon.oh@samsung.com>
src/crimson/os/seastore/journal/circular_bounded_journal.cc
src/crimson/os/seastore/journal/circular_bounded_journal.h

index fb6c3c6f4cc9f22863bfbc096f0ca2e9a1f62e6c..c671da32498d3fde2be3bf8620a57f0a72bde797 100644 (file)
@@ -22,7 +22,6 @@ std::ostream &operator<<(std::ostream &out,
             << ", journal_tail=" << header.journal_tail
             << ", applied_to="<< header.applied_to
             << ", written_to=" << header.written_to
-            << ", header_checksum=" << header.header_checksum
              << ")";
 }
 
@@ -89,6 +88,16 @@ ceph::bufferlist CircularBoundedJournal::encode_header()
 {
   bufferlist bl;
   encode(header, bl);
+  auto header_crc_filler = bl.append_hole(sizeof(checksum_t));
+  auto bliter = bl.cbegin();
+  auto header_crc = bliter.crc32c(
+    ceph::encoded_sizeof_bounded<cbj_header_t>(),
+    -1);
+  ceph_le32 header_crc_le;
+  header_crc_le = header_crc;
+  header_crc_filler.copy_in(
+    sizeof(checksum_t),
+    reinterpret_cast<const char *>(&header_crc_le));
   return bl;
 }
 
@@ -326,6 +335,14 @@ CircularBoundedJournal::read_header(rbm_abs_addr start)
       ERROR("read_header: unable to read header block");
       return crimson::ct_error::enoent::make();
     }
+    auto bliter = bl.cbegin();
+    auto test_crc = bliter.crc32c(
+      ceph::encoded_sizeof_bounded<cbj_header_t>(),
+      -1);
+    ceph_le32 recorded_crc_le;
+    decode(recorded_crc_le, bliter);
+    uint32_t recorded_crc = recorded_crc_le;
+    ceph_assert(test_crc == recorded_crc);
     return read_header_ret(
       read_header_ertr::ready_future_marker{},
       std::make_pair(cbj_header, bl)
@@ -561,6 +578,7 @@ CircularBoundedJournal::write_header()
     DEBUG("unable to encode header block from underlying deivce");
     return crimson::ct_error::input_output_error::make();
   }
+  ceph_assert(bl.length() + sizeof(checksum_t) < get_block_size());
   DEBUG(
     "sync header of CircularBoundedJournal, length {}",
     bl.length());
index 1910571cfc3b4fb74d9c3f4bc4981d3f4282ef16..be67bf1d144e8e9381e491983eb5768184da9689 100644 (file)
@@ -215,8 +215,6 @@ public:
     // address to represent where last appllied record is written
     rbm_abs_addr applied_to = 0;
 
-    checksum_t header_checksum = 0;       // checksum of entire cbj_header_t
-
     device_id_t device_id;
 
     DENC(cbj_header_t, v, p) {
@@ -231,7 +229,6 @@ public:
       denc(v.written_to, p);
       denc(v.applied_to, p);
 
-      denc(v.header_checksum, p);
       denc(v.device_id, p);
 
       DENC_FINISH(p);