From 08adf84fabd888f686b2cbc3b3e01fd2515a5256 Mon Sep 17 00:00:00 2001 From: myoungwon oh Date: Fri, 13 May 2022 16:30:51 +0900 Subject: [PATCH] seastore/cbjournal: remove header_checksum field and add calculating header checkksum Signed-off-by: Myoungwon Oh --- .../journal/circular_bounded_journal.cc | 20 ++++++++++++++++++- .../journal/circular_bounded_journal.h | 3 --- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/crimson/os/seastore/journal/circular_bounded_journal.cc b/src/crimson/os/seastore/journal/circular_bounded_journal.cc index fb6c3c6f4cc9f..c671da32498d3 100644 --- a/src/crimson/os/seastore/journal/circular_bounded_journal.cc +++ b/src/crimson/os/seastore/journal/circular_bounded_journal.cc @@ -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(), + -1); + ceph_le32 header_crc_le; + header_crc_le = header_crc; + header_crc_filler.copy_in( + sizeof(checksum_t), + reinterpret_cast(&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(), + -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()); diff --git a/src/crimson/os/seastore/journal/circular_bounded_journal.h b/src/crimson/os/seastore/journal/circular_bounded_journal.h index 1910571cfc3b4..be67bf1d144e8 100644 --- a/src/crimson/os/seastore/journal/circular_bounded_journal.h +++ b/src/crimson/os/seastore/journal/circular_bounded_journal.h @@ -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); -- 2.39.5