From: Jianpeng Ma Date: Fri, 12 Dec 2014 03:47:59 +0000 (+0800) Subject: librbd: add new read/write api for librbd C++ interface which handle op flags. X-Git-Tag: v0.91~55^2~3^2~17 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d2b01520eb70fef72d868b41d763af32e811f180;p=ceph.git librbd: add new read/write api for librbd C++ interface which handle op flags. Signed-off-by: Jianpeng Ma --- diff --git a/src/include/rbd/librbd.hpp b/src/include/rbd/librbd.hpp index 097b21cc58c0..6b8712fef181 100644 --- a/src/include/rbd/librbd.hpp +++ b/src/include/rbd/librbd.hpp @@ -157,6 +157,8 @@ public: /* I/O */ ssize_t read(uint64_t ofs, size_t len, ceph::bufferlist& bl); + /* @parmam op_flags see librados.h constants beginning with LIBRADOS_OP_FLAG */ + ssize_t read2(uint64_t ofs, size_t len, ceph::bufferlist& bl, int op_flags); int64_t read_iterate(uint64_t ofs, size_t len, int (*cb)(uint64_t, size_t, const char *, void *), void *arg); int read_iterate2(uint64_t ofs, uint64_t len, @@ -184,10 +186,14 @@ public: uint64_t ofs, uint64_t len, int (*cb)(uint64_t, size_t, int, void *), void *arg); ssize_t write(uint64_t ofs, size_t len, ceph::bufferlist& bl); + /* @parmam op_flags see librados.h constants beginning with LIBRADOS_OP_FLAG */ + ssize_t write2(uint64_t ofs, size_t len, ceph::bufferlist& bl, int op_flags); int discard(uint64_t ofs, uint64_t len); int aio_write(uint64_t off, size_t len, ceph::bufferlist& bl, RBD::AioCompletion *c); - + /* @parmam op_flags see librados.h constants beginning with LIBRADOS_OP_FLAG */ + int aio_write2(uint64_t off, size_t len, ceph::bufferlist& bl, + RBD::AioCompletion *c, int op_flags); /** * read async from image * @@ -206,6 +212,9 @@ public: * @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); + /* @parmam op_flags see librados.h constants beginning with LIBRADOS_OP_FLAG */ + int aio_read2(uint64_t off, size_t len, ceph::bufferlist& bl, + RBD::AioCompletion *c, int op_flags); int aio_discard(uint64_t off, uint64_t len, RBD::AioCompletion *c); int flush(); diff --git a/src/librbd/librbd.cc b/src/librbd/librbd.cc index 0827caa37442..efbd24d66673 100644 --- a/src/librbd/librbd.cc +++ b/src/librbd/librbd.cc @@ -596,6 +596,18 @@ namespace librbd { return r; } + ssize_t Image::read2(uint64_t ofs, size_t len, bufferlist& bl, int op_flags) + { + ImageCtx *ictx = (ImageCtx *)ctx; + tracepoint(librbd, read2_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), + ictx->read_only, ofs, len, op_flags); + bufferptr ptr(len); + bl.push_back(ptr); + int r = librbd::read(ictx, ofs, len, bl.c_str(), op_flags); + tracepoint(librbd, read_exit, r); + return r; + } + int64_t Image::read_iterate(uint64_t ofs, size_t len, int (*cb)(uint64_t, size_t, const char *, void *), void *arg) @@ -645,6 +657,20 @@ namespace librbd { return r; } + ssize_t Image::write2(uint64_t ofs, size_t len, bufferlist& bl, int op_flags) + { + ImageCtx *ictx = (ImageCtx *)ctx; + tracepoint(librbd, write2_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, + ofs, len, bl.length() < len ? NULL : bl.c_str(), op_flags); + if (bl.length() < len) { + tracepoint(librbd, write_exit, -EINVAL); + return -EINVAL; + } + int r = librbd::write(ictx, ofs, len, bl.c_str(), op_flags); + tracepoint(librbd, write_exit, r); + return r; + } + int Image::discard(uint64_t ofs, uint64_t len) { ImageCtx *ictx = (ImageCtx *)ctx; @@ -669,6 +695,22 @@ namespace librbd { return r; } + int Image::aio_write2(uint64_t off, size_t len, bufferlist& bl, + RBD::AioCompletion *c, int op_flags) + { + ImageCtx *ictx = (ImageCtx *)ctx; + tracepoint(librbd, aio_write2_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), + ictx->read_only, off, len, bl.length() < len ? NULL : bl.c_str(), c->pc, op_flags); + if (bl.length() < len) { + tracepoint(librbd, aio_write_exit, -EINVAL); + return -EINVAL; + } + int r = librbd::aio_write(ictx, off, len, bl.c_str(), + (librbd::AioCompletion *)c->pc, op_flags); + tracepoint(librbd, aio_write_exit, r); + return r; + } + int Image::aio_discard(uint64_t off, uint64_t len, RBD::AioCompletion *c) { ImageCtx *ictx = (ImageCtx *)ctx; @@ -690,6 +732,19 @@ namespace librbd { return r; } + int Image::aio_read2(uint64_t off, size_t len, bufferlist& bl, + RBD::AioCompletion *c, int op_flags) + { + ImageCtx *ictx = (ImageCtx *)ctx; + tracepoint(librbd, aio_read2_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), + ictx->read_only, off, len, bl.c_str(), c->pc, op_flags); + ldout(ictx->cct, 10) << "Image::aio_read() buf=" << (void *)bl.c_str() << "~" + << (void *)(bl.c_str() + len - 1) << dendl; + int r = librbd::aio_read(ictx, off, len, NULL, &bl, (librbd::AioCompletion *)c->pc, op_flags); + tracepoint(librbd, aio_read_exit, r); + return r; + } + int Image::flush() { ImageCtx *ictx = (ImageCtx *)ctx;