From a39a309631482b0caa071d586f192cd19a7ae470 Mon Sep 17 00:00:00 2001 From: Alex Ainscow Date: Sun, 29 Jun 2025 22:54:51 +0100 Subject: [PATCH] osd: Truncate coding shards to minimal size Scrub detected a bug where if an object was truncated to a size where the first shard is smaller than the chunk size (only possible for >4k chunk sizes), then the coding shards were being aligned to the chunk size, rather than to 4k. This fixes changes how the write plan is calculated to write the correct size. Signed-off-by: Alex Ainscow --- src/osd/ECTransaction.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/osd/ECTransaction.cc b/src/osd/ECTransaction.cc index 47f09873231..18544db6dc2 100644 --- a/src/osd/ECTransaction.cc +++ b/src/osd/ECTransaction.cc @@ -255,17 +255,22 @@ ECTransaction::WritePlanObj::WritePlanObj( */ if (op.truncate && op.truncate->first < orig_size) { ECUtil::shard_extent_set_t truncate_read(sinfo.get_k_plus_m()); - extent_set truncate_write; uint64_t prev_stripe = sinfo.ro_offset_to_prev_stripe_ro_offset(op.truncate->first); uint64_t next_align = ECUtil::align_next(op.truncate->first); - sinfo.ro_range_to_shard_extent_set_with_superset( + sinfo.ro_range_to_shard_extent_set( prev_stripe, next_align - prev_stripe, - truncate_read, truncate_write); + truncate_read); - /* We must always update the entire parity chunk, even if we only read - * a small amount of one shard. + /* Unless we are doing a full stripe write, we must always read the data + * for the partial stripe and update the parity. For the purposes of + * parity, the truncated shards are all zero. */ - truncate_write.align(sinfo.get_chunk_size()); + extent_set truncate_write; + + if (next_align != 0) { + truncate_write = truncate_read.at(shard_id_t(0)); + truncate_write.align(EC_ALIGN_SIZE); + } if (!truncate_read.empty()) { if (to_read) { -- 2.39.5