From dd2249ac8f3b672616a92cdc1ce593f02c5537d6 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Fri, 4 Dec 2026 18:10:24 +0300 Subject: [PATCH] osd: Return the stored bitmap for secondary reads sent without attr_len Since 51ecbadb a secondary OSD passes no bitmap to the blockstore when attr_len is 0. That is right for writes, but the SEC_READ reply always carries clean_entry_bitmap_size bytes of bitmap, so a read with attr_len = 0 now returns an unfilled buffer instead of the object's bitmap. Primaries before 51ecbadb (3.0.13 and older) send every read with attr_len = 0. During a rolling upgrade they take that buffer as the part's bitmap: chained reads of layered images then assert in send_chained_read_results, and EC read-modify-write builds new bitmaps from it. Keep the attr_len check for writes only, so reads always fill the bitmap. --- src/osd/osd_secondary.cpp | 3 ++- src/test/osd_test.cpp | 48 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/osd/osd_secondary.cpp b/src/osd/osd_secondary.cpp index ac415633..b8839d78 100644 --- a/src/osd/osd_secondary.cpp +++ b/src/osd/osd_secondary.cpp @@ -200,7 +200,8 @@ void osd_t::exec_secondary_real(osd_op_t *cur_op) cur_op->bs_op->offset = cur_op->req.sec_rw.offset; cur_op->bs_op->len = cur_op->req.sec_rw.len; cur_op->bs_op->buf = (uint8_t*)cur_op->buf; - if (cur_op->req.sec_rw.attr_len) + // A read always replies with the bitmap, and primaries before 51ecbadb send reads with attr_len = 0 + if (cur_op->req.sec_rw.attr_len || cur_op->req.hdr.opcode == OSD_OP_SEC_READ) cur_op->bs_op->bitmap = (uint8_t*)cur_op->bitmap; else cur_op->bs_op->bitmap = NULL; diff --git a/src/test/osd_test.cpp b/src/test/osd_test.cpp index 5ec262a1..b76044ed 100644 --- a/src/test/osd_test.cpp +++ b/src/test/osd_test.cpp @@ -5768,6 +5768,53 @@ void test_primary_list_inverted_range() printf("test_primary_list_inverted_range passed\n"); } +// A primary without 51ecbadb (3.0.13 and older) sends SEC_READ with attr_len = 0 +// and uses the bitmap of the reply, so the reply must carry the stored bitmap +static void test_sec_read_without_attr_len_returns_bitmap() +{ + printf("test_sec_read_without_attr_len_returns_bitmap\n"); + osd_test_fixture_t f; + f.configure_replicated_pool(/*pool_id*/ 1, /*pg_size*/ 2, /*pg_minsize*/ 1, /*pg_count*/ 1, + { { 1, 2 } }); + f.start(json11::Json::object { + { "osd_num", 2 }, + { "etcd_address", "127.0.0.1:2379" }, + { "immediate_commit", "all" }, + { "block_size", 131072 }, + { "bitmap_granularity", 4096 }, + }); + // clean_entry_bitmap_size = 131072/4096/8 = 4 + const uint32_t stored_bmp = 0xa5c3; + object_id oid = { .inode = INODE_WITH_POOL(1, 1), .stripe = 0 }; + uint64_t cl_id = f.connect_client(); + f.client(cl_id)->in_osd_num = 1; + for (uint32_t attr_len: { 0u, (uint32_t)sizeof(stored_bmp) }) + { + auto *op = new osd_op_t(); + op->op_type = OSD_OP_IN; + op->client_id = cl_id; + op->req.hdr.magic = SECONDARY_OSD_OP_MAGIC; + op->req.hdr.id = 1+attr_len; + op->req.hdr.opcode = OSD_OP_SEC_READ; + op->req.sec_rw.oid = oid; + op->req.sec_rw.version = UINT64_MAX; + op->req.sec_rw.len = 4096; + op->req.sec_rw.attr_len = attr_len; + op->req.sec_rw.flags = OSD_OP_IGNORE_PG_LOCK; + f.exec(op); + auto *rd = f.bs->take(BS_OP_READ); + if (rd->bitmap) + memcpy(rd->bitmap, &stored_bmp, sizeof(stored_bmp)); + rd->version = 1; + rd->retval = rd->len; + rd->callback(rd); + auto *reply = f.client(cl_id)->sent_ops.at(op->req.hdr.id); + assert(reply->reply.sec_rw.attr_len == sizeof(stored_bmp)); + assert(!memcmp(reply->bitmap, &stored_bmp, sizeof(stored_bmp))); + } + printf("test_sec_read_without_attr_len_returns_bitmap passed\n"); +} + int main(int narg, char *args[]) { test_load_global_config(); @@ -5855,5 +5902,6 @@ int main(int narg, char *args[]) test_peering_yields_after_repeer(); test_peering_yields_between_pgs(); test_peering_sends_replies_before_calc(); + test_sec_read_without_attr_len_returns_bitmap(); return 0; } -- 2.47.3