]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
compressor: switch out of get_current_ptr() for the sake of const-stricter bufferlist 59116/head
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Thu, 8 Aug 2024 15:39:03 +0000 (15:39 +0000)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Fri, 9 Aug 2024 19:21:22 +0000 (19:21 +0000)
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 <rzarzyns@redhat.com>
src/compressor/lz4/LZ4Compressor.cc

index a209a5ac149f3f9e4143254207af3e33e0772242..1504a2fe65d1bc2e136b5383ac814a47a163ad03 100644 (file)
@@ -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<ceph::buffer::ptr> 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(