]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common/bl: c_str() considers _carriage now.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Mon, 19 Jul 2021 14:06:20 +0000 (14:06 +0000)
committerIlya Dryomov <idryomov@gmail.com>
Mon, 13 Sep 2021 19:16:14 +0000 (21:16 +0200)
It could be that `_carriage` points on empty bptr which is
also stored in the `_buffers` container -- this happens
when we'are trying to preserve the appendable space to not
waste memory and avoid new allocation.
Before the change this approach was imposing unncessary
rebuilding on `c_str()`. Now we take into consideration
the special case when a bufferlist has the extra, empty
bptr at its end.

Fixes: https://tracker.ceph.com/issues/51725
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/common/buffer.cc

index 8ade26dc911789a86e7540e5489ec65e2abe93f1..2b534402f6dca7c8f624603fea02d2398cce94aa 100644 (file)
@@ -1527,10 +1527,13 @@ static ceph::spinlock debug_lock;
       return nullptr;                         // no non-empty buffers
     }
 
-    auto iter = std::cbegin(_buffers);
-    ++iter;
-
-    if (iter != std::cend(_buffers)) {
+    const auto second = std::next(std::cbegin(_buffers));
+    // splice() tries to not waste our appendable space; to carry
+    // it an empty bptr is added at the end. we account for that.
+    const auto end = _carriage->length() == 0 && \
+      _carriage == &_buffers.back() ? buffers_t::const_iterator(_carriage)
+                                    : std::cend(_buffers);
+    if (second != end) {
       rebuild();
     }
     return _buffers.front().c_str();