From: Radoslaw Zarzynski Date: Thu, 8 Aug 2024 15:39:03 +0000 (+0000) Subject: compressor: switch out of get_current_ptr() for the sake of const-stricter bufferlist X-Git-Tag: v20.0.0~482^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=24f34caf9e71ffc8718557c364a64c5fdc8c4fb1;p=ceph.git compressor: switch out of get_current_ptr() for the sake of const-stricter bufferlist Although simplifying the things, the main rationale is going towards `bufferlist` with tight restrictions on modyfying stored data, and thus enabling e.g. deduplication of padding zeros. This in turn can be very interesting for some further optimizations of EC support which have in common increasing the chunk size. Currently `bufferlist` allows to mess its content and cause crosstalks through at least three mechanisms: * the `bufferlist::c_str()` returning non-`const` pointer to `char`, * the iterator's `get_current_ptr()` returning a writable bptr, * the iterator's `copy_in()`. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/compressor/lz4/LZ4Compressor.cc b/src/compressor/lz4/LZ4Compressor.cc index a209a5ac149f..1504a2fe65d1 100644 --- a/src/compressor/lz4/LZ4Compressor.cc +++ b/src/compressor/lz4/LZ4Compressor.cc @@ -121,16 +121,12 @@ int LZ4Compressor::decompress(ceph::buffer::list::const_iterator &p, LZ4_streamDecode_t lz4_stream_decode; LZ4_setStreamDecode(&lz4_stream_decode, nullptr, 0); - ceph::buffer::ptr cur_ptr = p.get_current_ptr(); - ceph::buffer::ptr *ptr = &cur_ptr; - std::optional data_holder; - if (compressed_len != cur_ptr.length()) { - data_holder.emplace(compressed_len); - p.copy_deep(compressed_len, *data_holder); - ptr = &*data_holder; - } - - char *c_in = ptr->c_str(); + ceph::buffer::list indata; + // this does a shallow copy + p.copy(compressed_len, indata); + // if the input isn't fragmented, c_str() costs almost nothing. + // otherwise rectifying copy will be taken + const char* c_in = indata.c_str(); char *c_out = dstptr.c_str(); for (unsigned i = 0; i < count; ++i) { int r = LZ4_decompress_safe_continue(