Skip to content

Commit e92273a

Browse files
committed
crimson/os/seastore: disable crc calculation if end to end data protection is enabled
Signed-off-by: Myoungwon Oh <[email protected]>
1 parent 169a81e commit e92273a

File tree

11 files changed

+76
-14
lines changed

11 files changed

+76
-14
lines changed

src/crimson/os/seastore/cache.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,13 @@ void Cache::complete_commit(
15621562
is_inline = true;
15631563
i->set_paddr(final_block_start.add_relative(i->get_paddr()));
15641564
}
1565-
assert(i->get_last_committed_crc() == i->calc_crc32c());
1565+
#ifndef NDEBUG
1566+
if (i->get_paddr().is_root() || epm.get_checksum_needed(i->get_paddr())) {
1567+
assert(i->get_last_committed_crc() == i->calc_crc32c());
1568+
} else {
1569+
assert(i->get_last_committed_crc() == CRC_NULL);
1570+
}
1571+
#endif
15661572
i->pending_for_transaction = TRANS_ID_NULL;
15671573
i->on_initial_write();
15681574

src/crimson/os/seastore/cache.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,7 @@ class Cache {
16511651
extent->get_length(),
16521652
extent->get_bptr()
16531653
).safe_then(
1654-
[extent=std::move(extent)]() mutable {
1654+
[extent=std::move(extent), this]() mutable {
16551655
LOG_PREFIX(Cache::read_extent);
16561656
if (likely(extent->state == CachedExtent::extent_state_t::CLEAN_PENDING)) {
16571657
extent->state = CachedExtent::extent_state_t::CLEAN;
@@ -1662,7 +1662,11 @@ class Cache {
16621662
if (extent->is_valid()) {
16631663
// crc will be checked against LBA leaf entry for logical extents,
16641664
// or check against in-extent crc for physical extents.
1665-
extent->last_committed_crc = extent->calc_crc32c();
1665+
if (epm.get_checksum_needed(extent->get_paddr())) {
1666+
extent->last_committed_crc = extent->calc_crc32c();
1667+
} else {
1668+
extent->last_committed_crc = CRC_NULL;
1669+
}
16661670
extent->on_clean_read();
16671671
}
16681672
extent->complete_io();

src/crimson/os/seastore/extent_placement_manager.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,15 @@ class ExtentPlacementManager {
551551
return background_process.run_until_halt();
552552
}
553553

554+
bool get_checksum_needed(paddr_t addr) {
555+
// checksum offloading only for blocks physically stored in the device
556+
if (addr.is_fake()) {
557+
return true;
558+
}
559+
assert(addr.is_absolute());
560+
return !devices_by_id[addr.get_device_id()]->is_end_to_end_data_protection();
561+
}
562+
554563
private:
555564
rewrite_gen_t adjust_generation(
556565
data_category_t category,

src/crimson/os/seastore/journal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class Journal {
107107
virtual ~Journal() {}
108108

109109
virtual backend_type_t get_type() = 0;
110+
111+
virtual bool is_checksum_needed() = 0;
110112
};
111113
using JournalRef = std::unique_ptr<Journal>;
112114

src/crimson/os/seastore/journal/circular_bounded_journal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ class CircularBoundedJournal : public Journal, RecordScanner {
186186
return get_journal_end();
187187
}
188188

189+
bool is_checksum_needed() final {
190+
return cjs.is_checksum_needed();
191+
}
192+
189193
// Test interfaces
190194

191195
CircularJournalSpace& get_cjs() {

src/crimson/os/seastore/journal/circular_journal_space.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ class CircularJournalSpace : public JournalAllocator {
242242
return header;
243243
}
244244

245+
bool is_checksum_needed() {
246+
return !device->is_end_to_end_data_protection();
247+
}
248+
245249
private:
246250
std::string print_name;
247251
cbj_header_t header;

src/crimson/os/seastore/journal/segmented_journal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ class SegmentedJournal : public Journal {
6363
return seastar::now();
6464
}
6565

66+
bool is_checksum_needed() final {
67+
// segmented journal always requires checksum
68+
return true;
69+
}
70+
6671
private:
6772
submit_record_ret do_submit_record(
6873
record_t &&record,

src/crimson/os/seastore/lba_manager.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ LBAManager::update_mappings(
1313
{
1414
return trans_intr::do_for_each(extents,
1515
[this, &t](auto &extent) {
16-
assert(extent->get_last_committed_crc());
1716
return update_mapping(
1817
t,
1918
extent->get_laddr(),

src/crimson/os/seastore/seastore_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ inline depth_le_t init_depth_le(uint32_t i) {
3939
}
4040

4141
using checksum_t = uint32_t;
42+
constexpr checksum_t CRC_NULL = 0;
4243

4344
// Immutable metadata for seastore to set at mkfs time
4445
struct seastore_meta_t {

src/crimson/os/seastore/transaction_manager.cc

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ TransactionManager::update_lba_mappings(
331331
std::list<LogicalCachedExtentRef>(),
332332
std::list<CachedExtentRef>(),
333333
[this, &t, &pre_allocated_extents](auto &lextents, auto &pextents) {
334-
auto chksum_func = [&lextents, &pextents](auto &extent) {
334+
auto chksum_func = [&lextents, &pextents, this](auto &extent) {
335335
if (!extent->is_valid() ||
336336
!extent->is_fully_loaded() ||
337337
// EXIST_MUTATION_PENDING extents' crc will be calculated when
@@ -343,10 +343,20 @@ TransactionManager::update_lba_mappings(
343343
// for rewritten extents, last_committed_crc should have been set
344344
// because the crc of the original extent may be reused.
345345
// also see rewrite_logical_extent()
346-
if (!extent->get_last_committed_crc()) {
347-
extent->set_last_committed_crc(extent->calc_crc32c());
348-
}
349-
assert(extent->calc_crc32c() == extent->get_last_committed_crc());
346+
if (!extent->get_last_committed_crc()) {
347+
if (get_checksum_needed(extent->get_paddr())) {
348+
extent->set_last_committed_crc(extent->calc_crc32c());
349+
} else {
350+
extent->set_last_committed_crc(CRC_NULL);
351+
}
352+
}
353+
#ifndef NDEBUG
354+
if (get_checksum_needed(extent->get_paddr())) {
355+
assert(extent->get_last_committed_crc() == extent->calc_crc32c());
356+
} else {
357+
assert(extent->get_last_committed_crc() == CRC_NULL);
358+
}
359+
#endif
350360
lextents.emplace_back(extent->template cast<LogicalCachedExtent>());
351361
} else {
352362
pextents.emplace_back(extent);
@@ -367,15 +377,20 @@ TransactionManager::update_lba_mappings(
367377

368378
return lba_manager->update_mappings(
369379
t, lextents
370-
).si_then([&pextents] {
380+
).si_then([&pextents, this] {
371381
for (auto &extent : pextents) {
372382
assert(!extent->is_logical() && extent->is_valid());
373383
// for non-logical extents, we update its last_committed_crc
374384
// and in-extent checksum fields
375385
// For pre-allocated fresh physical extents, update in-extent crc.
376-
auto crc = extent->calc_crc32c();
377-
extent->set_last_committed_crc(crc);
378-
extent->update_in_extent_chksum_field(crc);
386+
checksum_t crc;
387+
if (get_checksum_needed(extent->get_paddr())) {
388+
crc = extent->calc_crc32c();
389+
} else {
390+
crc = CRC_NULL;
391+
}
392+
extent->set_last_committed_crc(crc);
393+
extent->update_in_extent_chksum_field(crc);
379394
}
380395
});
381396
});
@@ -516,7 +531,13 @@ TransactionManager::rewrite_logical_extent(
516531

517532
DEBUGT("rewriting logical extent -- {} to {}", t, *lextent, *nlextent);
518533

519-
assert(lextent->get_last_committed_crc() == lextent->calc_crc32c());
534+
#ifndef NDEBUG
535+
if (get_checksum_needed(lextent->get_paddr())) {
536+
assert(lextent->get_last_committed_crc() == lextent->calc_crc32c());
537+
} else {
538+
assert(lextent->get_last_committed_crc() == CRC_NULL);
539+
}
540+
#endif
520541
nlextent->set_last_committed_crc(lextent->get_last_committed_crc());
521542
/* This update_mapping is, strictly speaking, unnecessary for delayed_alloc
522543
* extents since we're going to do it again once we either do the ool write

0 commit comments

Comments
 (0)