From: Adam Kupczyk Date: Fri, 4 Jul 2025 16:28:16 +0000 (+0000) Subject: os/bluestore: Rework on decoding X-Git-Tag: v21.0.1~8^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=cf6d025d81a408e3653fe2cdd248b42d3c781f7e;p=ceph.git os/bluestore: Rework on decoding Refactored ExtentDecoder. Introduced decode_create_blob method to it. Converted bluestore_blob_t::decode and Blob::decode methods into templates. Created clear example path how to specialize these and other decoders. Signed-off-by: Adam Kupczyk --- diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index b5619a49ffc..d74b11bbdaa 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -2945,36 +2945,6 @@ void BlueStore::Blob::maybe_prune_tail() { } } -void BlueStore::Blob::decode( - bufferptr::const_iterator& p, - uint64_t struct_v, - uint64_t* sbid, - bool include_ref_map, - Collection *coll) -{ - denc(blob, p, struct_v); - if (blob.is_shared()) { - denc(*sbid, p); - } - if (include_ref_map) { - if (struct_v > 1) { - used_in_blob.decode(p); - } else { - used_in_blob.clear(); - bluestore_extent_ref_map_t legacy_ref_map; - legacy_ref_map.decode(p); - if (coll) { - for (auto r : legacy_ref_map.ref_map) { - get_ref( - coll, - r.first, - r.second.refs * r.second.length); - } - } - } - } -} - // Extent void BlueStore::Extent::dump(Formatter* f) const @@ -4150,9 +4120,8 @@ void BlueStore::ExtentMap::ExtentDecoder::decode_extent( consume_blobid(le, false, blobid - 1); } else { // dummy onodes might not have collections, we need a check for it. - BlobRef b = c ? c->new_blob() : new Blob(nullptr); uint64_t sbid = 0; - b->decode(p, struct_v, &sbid, false, c); + BlobRef b = decode_create_blob(p, struct_v, &sbid, false, c); consume_blob(le, extent_pos, sbid, b); } } @@ -4198,15 +4167,29 @@ void BlueStore::ExtentMap::ExtentDecoder::decode_spanning_blobs( unsigned n; denc_varint(n, p); while (n--) { - BlobRef b = c ? c->new_blob() : new Blob(nullptr); - denc_varint(b->id, p); + decltype(Blob::id) id; + denc_varint(id, p); + uint64_t sbid = 0; - b->decode(p, struct_v, &sbid, true, c); + BlobRef b = decode_create_blob(p, struct_v, &sbid, true, c); + b->id = id; consume_spanning_blob(sbid, b); } } /////////////////// BlueStore::ExtentMap::DecoderExtentFull /////////// + +BlueStore::BlobRef BlueStore::ExtentMap::ExtentDecoderFull::decode_create_blob( + bptr_c_it_t& p, + __u8 struct_v, + uint64_t* sbid, + bool include_ref_map, + Collection* c) { + BlobRef b = c ? c->new_blob() : new Blob(nullptr); + b->decode(p, struct_v, sbid, include_ref_map, c); + return b; +} + void BlueStore::ExtentMap::ExtentDecoderFull::consume_blobid( BlueStore::Extent* le, bool spanning, uint64_t blobid) { ceph_assert(le); @@ -20667,6 +20650,16 @@ void BlueStore::set_allocation_in_simple_bmap(SimpleBitmap* sbmap, uint64_t offs sbmap->set(offset >> min_alloc_size_order, length >> min_alloc_size_order); } +BlueStore::BlobRef BlueStore::ExtentDecoderPartial::decode_create_blob( + bptr_c_it_t& p, + __u8 struct_v, + uint64_t* sbid, + bool include_ref_map, + Collection* c) { + BlobRef b = c ? c->new_blob() : new Blob(nullptr); + b->decode(p, struct_v, sbid, include_ref_map, c); + return b; +} void BlueStore::ExtentDecoderPartial::_consume_new_blob(bool spanning, uint64_t extent_no, uint64_t sbid, diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index c2793ae0382..a22a0f1d556 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -825,13 +825,37 @@ public: used_in_blob.encode(p); } } + template void decode( ceph::buffer::ptr::const_iterator& p, uint64_t struct_v, uint64_t* sbid, bool include_ref_map, - Collection *coll); + Collection *coll) { + if constexpr (decode_csum) + blob.decode(p, struct_v); + else + blob.decode(p, struct_v); + if (blob.is_shared()) { + denc(*sbid, p); + } + if (include_ref_map) { + if (struct_v > 1) { + used_in_blob.decode(p); + } else { + used_in_blob.clear(); + bluestore_extent_ref_map_t legacy_ref_map; + legacy_ref_map.decode(p); + if (coll) { + for (const auto& r : legacy_ref_map.ref_map) { + get_ref(coll, r.first, r.second.refs * r.second.length); + } + } + } + } + } }; + typedef boost::intrusive_ptr BlobRef; typedef mempool::bluestore_cache_meta::map blob_map_t; @@ -1024,6 +1048,15 @@ public: uint64_t prev_len = 0; uint64_t extent_pos = 0; protected: + // Decodes Blob from bitstream. + // The returned Blob is then used in \ref consume_blob or \ref consume_spanning_blob + virtual BlobRef decode_create_blob( + bptr_c_it_t& p, + __u8 struct_v, + uint64_t* sbid, // shared blobid, is Blob turns out to be shared blob + bool include_ref_map, // only spanning blobs have references stored + Collection* c) = 0; + virtual void consume_blobid(Extent* le, bool spanning, uint64_t blobid) = 0; @@ -1051,6 +1084,13 @@ public: ExtentMap& extent_map; std::vector blobs; protected: + BlobRef decode_create_blob( + bptr_c_it_t& p, + __u8 struct_v, + uint64_t* sbid, + bool include_ref_map, + Collection* c) override; + void consume_blobid(Extent* le, bool spanning, uint64_t blobid) override; void consume_blob(Extent* le, uint64_t extent_no, @@ -4104,7 +4144,12 @@ private: volatile_statfs* per_pool_statfs = nullptr; blob_map_t blobs; blob_map_t spanning_blobs; - + virtual BlobRef decode_create_blob( + bptr_c_it_t& p, + __u8 struct_v, + uint64_t* sbid, + bool include_ref_map, + Collection* c) override; void _consume_new_blob(bool spanning, uint64_t extent_no, uint64_t sbid, diff --git a/src/os/bluestore/bluestore_types.h b/src/os/bluestore/bluestore_types.h index d7259bac500..5e19113ed9f 100644 --- a/src/os/bluestore/bluestore_types.h +++ b/src/os/bluestore/bluestore_types.h @@ -561,8 +561,10 @@ public: denc(unused, p); } } - - void decode(ceph::buffer::ptr::const_iterator& p, uint64_t struct_v) { + struct empty_context_t {}; + template + void decode(ceph::buffer::ptr::const_iterator& p, uint64_t struct_v, + context_t context = empty_context_t()) { ceph_assert(struct_v == 1 || struct_v == 2); denc(extents, p); denc_varint(flags, p); @@ -577,8 +579,12 @@ public: denc(csum_chunk_order, p); int len; denc_varint(len, p); - csum_data = p.get_ptr(len); - csum_data.reassign_to_mempool(mempool::mempool_bluestore_cache_other); + if (decode_csum) { + csum_data = p.get_ptr(len); + csum_data.reassign_to_mempool(mempool::mempool_bluestore_cache_other); + } else { + p += len; + } } if (has_unused()) { denc(unused, p);