]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: avoid read copy for c++ api read
authorSage Weil <sage@inktank.com>
Fri, 5 Oct 2012 18:01:05 +0000 (11:01 -0700)
committerSage Weil <sage@inktank.com>
Mon, 15 Oct 2012 22:34:05 +0000 (15:34 -0700)
Read directly into the user's bufferlist instead of copying the buffer
contents.

NOTE: this potentially exposes cached buffers to C++ API users.  Document
this!

Signed-off-by: Sage Weil <sage@inktank.com>
src/include/rbd/librbd.hpp
src/librbd/librbd.cc

index d888dc700750759f89b1f4325169b8e95c6b61d6..fe6bd92d44282641ab51bc44142cef58f6b9fc36 100644 (file)
@@ -150,6 +150,24 @@ public:
   int discard(uint64_t ofs, uint64_t len);
 
   int aio_write(uint64_t off, size_t len, ceph::bufferlist& bl, RBD::AioCompletion *c);
+
+  /**
+   * read async from image
+   *
+   * The target bufferlist is populated with references to buffers
+   * that contain the data for the given extent of the image.
+   *
+   * NOTE: If caching is enabled, the bufferlist will directly
+   * reference buffers in the cache to avoid an unnecessary data copy.
+   * As a result, if the user intends to modify the buffer contents
+   * directly, they should make a copy first (unconditionally, or when
+   * the reference count on ther underlying buffer is more than 1).
+   *
+   * @param off offset in image
+   * @param len length of read
+   * @param bl bufferlist to read into
+   * @param c aio completion to notify when read is complete
+   */
   int aio_read(uint64_t off, size_t len, ceph::bufferlist& bl, RBD::AioCompletion *c);
   int aio_discard(uint64_t off, uint64_t len, RBD::AioCompletion *c);
 
index 0bef213974d0d9df65456712d2b259d1b2635a55..f37eadfea400e068cc8d25bd96e5086bd24d78f5 100644 (file)
@@ -428,11 +428,9 @@ namespace librbd {
                      RBD::AioCompletion *c)
   {
     ImageCtx *ictx = (ImageCtx *)ctx;
-    bufferptr ptr(len);
-    bl.push_back(ptr);
     ldout(ictx->cct, 10) << "Image::aio_read() buf=" << (void *)bl.c_str() << "~"
                         << (void *)(bl.c_str() + len - 1) << dendl;
-    return librbd::aio_read(ictx, off, len, bl.c_str(), NULL, (librbd::AioCompletion *)c->pc);
+    return librbd::aio_read(ictx, off, len, NULL, &bl, (librbd::AioCompletion *)c->pc);
   }
 
   int Image::flush()