]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
bufferlist: Refactor func get_contiguous.
authorJianpeng Ma <jianpeng.ma@intel.com>
Mon, 26 Jan 2015 02:01:22 +0000 (10:01 +0800)
committerJianpeng Ma <jianpeng.ma@intel.com>
Mon, 26 Jan 2015 02:01:22 +0000 (10:01 +0800)
Now it can rebuild the related prt not all prt

Signed-off-by: Jianpeng Ma <jianpeng.ma@intel.com>
src/common/buffer.cc

index 88656e836bd29fc8d51f94e6a30024e8bbf0e3d4..b62856f4540cfaa7a441d98a46008867d7564aed 100644 (file)
@@ -1483,9 +1483,24 @@ void buffer::list::rebuild_page_aligned()
     }
 
     if (off + len > curbuf->length()) {
-      // FIXME we'll just rebuild the whole list for now.
-      rebuild();
-      return c_str() + orig_off;
+      bufferlist tmp;
+      unsigned l = off + len;
+
+      do {
+       if (l >= curbuf->length())
+         l -= curbuf->length();
+       else
+         l = 0;
+       tmp.append(*curbuf);
+       curbuf = _buffers.erase(curbuf);
+
+      } while (curbuf != _buffers.end() && l > 0);
+
+      assert(l == 0);
+
+      tmp.rebuild();
+      _buffers.insert(curbuf, tmp._buffers.front());
+      return tmp.c_str() + off;
     }
 
     return curbuf->c_str() + off;