]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
bufferlist: Add new func is_provided_buffer(const char *dst)
authorJianpeng Ma <jianpeng.ma@intel.com>
Tue, 20 Jan 2015 02:40:11 +0000 (10:40 +0800)
committerHaomai Wang <haomai@xsky.com>
Sat, 20 Feb 2016 06:15:17 +0000 (14:15 +0800)
Using this function to judge whether copy data from bufferlist to
dst. It mainly used librados C interface to avoid copy data from librados
to caller.

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

index f819f039823baf1506d571e804e611b32d37d318..f705a0f87dca8883a99b1b8e7738daaa691fa471 100644 (file)
@@ -1315,6 +1315,13 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
     return true;
   }
 
+  bool buffer::list::is_provided_buffer(const char *dst) const
+  {
+    if (_buffers.empty())
+      return false;
+    return (is_contiguous() && (_buffers.front().c_str() == dst));
+  }
+
   bool buffer::list::is_aligned(unsigned align) const
   {
     for (std::list<ptr>::const_iterator it = _buffers.begin();
@@ -1385,7 +1392,7 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER;
        break;  // done
     }
   }
-  
+
   bool buffer::list::is_contiguous() const
   {
     return &(*_buffers.begin()) == &(*_buffers.rbegin());
index a1a273dd33177f07c1024d1e96e2585ad8a53ba1..6fbf481a74752bfe30a02bde9a1bc3d8cc1ea8cb 100644 (file)
@@ -409,6 +409,7 @@ namespace buffer CEPH_BUFFER_API {
     bool contents_equal(const buffer::list& other) const;
 
     bool can_zero_copy() const;
+    bool is_provided_buffer(const char *dst) const;
     bool is_aligned(unsigned align) const;
     bool is_page_aligned() const;
     bool is_n_align_sized(unsigned align) const;
index e66d17b638aca3e91aeeeb236127be552810b9a6..be25564c361293cd2d51fb27e569ca0db6e13389 100644 (file)
@@ -3095,7 +3095,7 @@ extern "C" int rados_read(rados_ioctx_t io, const char *o, char *buf, size_t len
       tracepoint(librados, rados_read_exit, -ERANGE, NULL);
       return -ERANGE;
     }
-    if (bl.c_str() != buf)
+    if (!bl.is_provided_buffer(buf))
       bl.copy(0, bl.length(), buf);
     ret = bl.length();    // hrm :/
   }
@@ -3445,7 +3445,7 @@ extern "C" int rados_getxattr(rados_ioctx_t io, const char *o, const char *name,
       tracepoint(librados, rados_getxattr_exit, -ERANGE, buf, 0);
       return -ERANGE;
     }
-    if (bl.c_str() !=  buf)
+    if (!bl.is_provided_buffer(buf))
       bl.copy(0, bl.length(), buf);
     ret = bl.length();
   }
@@ -4815,7 +4815,7 @@ public:
     }
     if (bytes_read)
       *bytes_read = out_bl.length();
-    if (out_buf && out_bl.c_str() != out_buf)
+    if (out_buf && !out_bl.is_provided_buffer(out_buf))
       out_bl.copy(0, out_bl.length(), out_buf);
   }
 };
index 969f2d814732f94d6599c9b6541286a43653f5b7..352fe390baccba94d1dda0d5efaff7cdf42fadbd 100644 (file)
@@ -395,7 +395,7 @@ extern "C" int rados_striper_read(rados_striper_t striper,
   if (ret >= 0) {
     if (bl.length() > len)
       return -ERANGE;
-    if (bl.c_str() != buf)
+    if (!bl.is_provided_buffer(buf))
       bl.copy(0, bl.length(), buf);
     ret = bl.length();    // hrm :/
   }