]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: read into user's bufferlist for aio_read
authorRutger ter Borg <rutger@terborg.net>
Wed, 27 Nov 2013 08:49:00 +0000 (00:49 -0800)
committerJosh Durgin <josh.durgin@inktank.com>
Mon, 30 Dec 2013 19:10:26 +0000 (11:10 -0800)
* The 'buf' argument to read() used to be passed into
  AioCompletionImpl, and the results would be copied back after
  reading. This is replaced with the creation of a static buffer of
  that buf.

* The pbl argument in AioCompletionImpl is removed.

The patch is tested against an application using librados. I've
assumed that 'pbl' in

aio_read( ...., pbl, )

is allocated by the user. It may even speed things up: a buffer copy
is prevented.

Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
src/librados/AioCompletionImpl.h
src/librados/IoCtxImpl.cc

index 63a56db8aa8d69c601b5e1cc7a2e928c068641cc..48941bb2b4942a3fde3d5a789641e24062ffce5b 100644 (file)
@@ -39,8 +39,7 @@ struct librados::AioCompletionImpl {
 
   // for read
   bool is_read;
-  bufferlist bl, *pbl;
-  char *buf;
+  bufferlist bl;
   unsigned maxlen;
 
   IoCtxImpl *io;
@@ -54,7 +53,7 @@ struct librados::AioCompletionImpl {
                        callback_safe(0),
                        callback_complete_arg(0),
                        callback_safe_arg(0),
-                       is_read(false), pbl(0), buf(0), maxlen(0),
+                       is_read(false), maxlen(0),
                        io(NULL), aio_write_seq(0), aio_write_list_item(this) { }
 
   int set_complete_callback(void *cb_arg, rados_callback_t cb) {
index fa5930ffe7e388738c57f123a86c47ef28c78f40..f16c1caa8cf4988eb62f934990c8987f477bff69 100644 (file)
@@ -592,7 +592,6 @@ int librados::IoCtxImpl::aio_operate_read(const object_t &oid,
 
   c->is_read = true;
   c->io = this;
-  c->pbl = pbl;
 
   Objecter::Op *objecter_op = objecter->prepare_read_op(oid, oloc,
                 *o, snap_seq, pbl, flags,
@@ -635,11 +634,10 @@ int librados::IoCtxImpl::aio_read(const object_t oid, AioCompletionImpl *c,
 
   c->is_read = true;
   c->io = this;
-  c->pbl = pbl;
 
   Mutex::Locker l(*lock);
   objecter->read(oid, oloc,
-                off, len, snapid, &c->bl, 0,
+                off, len, snapid, pbl, 0,
                 onack, &c->objver);
   return 0;
 }
@@ -655,8 +653,9 @@ int librados::IoCtxImpl::aio_read(const object_t oid, AioCompletionImpl *c,
 
   c->is_read = true;
   c->io = this;
-  c->buf = buf;
   c->maxlen = len;
+  c->bl.clear();
+  c->bl.push_back(buffer::create_static(len, buf));
 
   Mutex::Locker l(*lock);
   objecter->read(oid, oloc,
@@ -691,7 +690,6 @@ int librados::IoCtxImpl::aio_sparse_read(const object_t oid,
 
   c->is_read = true;
   c->io = this;
-  c->pbl = NULL;
 
   onack->m_ops.sparse_read(off, len, m, data_bl, NULL);
 
@@ -1233,14 +1231,9 @@ void librados::IoCtxImpl::C_aio_Ack::finish(int r)
     c->safe = true;
   c->cond.Signal();
 
-  if (c->buf && c->bl.length() > 0) {
-    unsigned l = MIN(c->bl.length(), c->maxlen);
-    c->bl.copy(0, l, c->buf);
+  if (c->bl.length() > 0) {
     c->rval = c->bl.length();
   }
-  if (c->pbl) {
-    *c->pbl = c->bl;
-  }
 
   if (c->callback_complete) {
     c->io->client->finisher.queue(new C_AioComplete(c));