]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
buffer: add a 'deep' append mode
authorSage Weil <sage@redhat.com>
Thu, 22 Sep 2016 19:51:39 +0000 (15:51 -0400)
committerSage Weil <sage@redhat.com>
Sun, 16 Oct 2016 14:32:51 +0000 (10:32 -0400)
Do the copy up-front.  This is useful if we know our target buffer must
be a contiguous buffer (e.g., because it will be passed to a kv store).

Signed-off-by: Sage Weil <sage@redhat.com>
src/include/buffer.h

index a7af128c772f68010b7d868eb98160fd91b6f16b..b0326bc79caa5010b639bbf6ceafaa32c87f9f64 100644 (file)
@@ -462,11 +462,14 @@ namespace buffer CEPH_BUFFER_API {
       bufferlist *pbl;
       char *pos;
       ptr bp;
+      bool deep;
 
       /// running count of bytes appended that are not reflected by @pos
       size_t out_of_band_offset = 0;
 
-      contiguous_appender(bufferlist *l, size_t len) : pbl(l) {
+      contiguous_appender(bufferlist *l, size_t len, bool d)
+       : pbl(l),
+         deep(d) {
        size_t unused = pbl->append_buffer.unused_tail_length();
        if (len > unused) {
          // note: if len < the normal append_buffer size it *might*
@@ -537,14 +540,31 @@ namespace buffer CEPH_BUFFER_API {
       }
 
       void append(const bufferptr& p) {
-       flush_and_continue();
-       pbl->append(p);
-       out_of_band_offset += p.length();
+       if (!p.length()) {
+         return;
+       }
+       if (deep) {
+         append(p.c_str(), p.length());
+       } else {
+         flush_and_continue();
+         pbl->append(p);
+         out_of_band_offset += p.length();
+       }
       }
       void append(const bufferlist& l) {
-       flush_and_continue();
-       pbl->append(l);
-       out_of_band_offset += l.length();
+       if (!l.length()) {
+         return;
+       }
+       if (deep) {
+         for (const auto &p : l._buffers) {
+           append(p.c_str(), p.length());
+         }
+       } else {
+         flush_and_continue();
+         pbl->append(l);
+         out_of_band_offset += l.length();
+       }
+      }
 
       size_t get_logical_offset() {
        if (bp.have_raw()) {
@@ -555,8 +575,8 @@ namespace buffer CEPH_BUFFER_API {
       }
     };
 
-    contiguous_appender get_contiguous_appender(size_t len) {
-      return contiguous_appender(this, len);
+    contiguous_appender get_contiguous_appender(size_t len, bool deep=false) {
+      return contiguous_appender(this, len, deep);
     }
 
     class page_aligned_appender {