From b4e39f3eccd6734f1ed13c700c136e3aef1777f8 Mon Sep 17 00:00:00 2001 From: "Frank S. Filz" Date: Wed, 11 May 2022 14:35:53 -0700 Subject: [PATCH] libcephfs: Add nonblocking readv/writev I/O interface Signed-off-by: Frank S. Filz --- src/include/cephfs/libcephfs.h | 13 +++++++++++++ src/libcephfs.cc | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h index dc62698fa48..703dd900b5d 100644 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -118,6 +118,17 @@ struct ceph_snapdiff_entry_t { uint64_t snapid; //should be snapid_t but prefer not to exposure it }; +struct ceph_ll_io_info { + void (*callback) (struct ceph_ll_io_info *cb_info); + void *priv; // private for caller + struct Fh *fh; + const struct iovec *iov; + int iovcnt; + int64_t off; + int64_t result; + bool write; +}; + /* setattr mask bits (up to an int in size) */ #ifndef CEPH_SETATTR_MODE #define CEPH_SETATTR_MODE (1 << 0) @@ -1934,6 +1945,8 @@ int64_t ceph_ll_readv(struct ceph_mount_info *cmount, struct Fh *fh, const struct iovec *iov, int iovcnt, int64_t off); int64_t ceph_ll_writev(struct ceph_mount_info *cmount, struct Fh *fh, const struct iovec *iov, int iovcnt, int64_t off); +int64_t ceph_ll_nonblocking_readv_writev(struct ceph_mount_info *cmount, + struct ceph_ll_io_info *io_info); int ceph_ll_close(struct ceph_mount_info *cmount, struct Fh* filehandle); int ceph_ll_iclose(struct ceph_mount_info *cmount, struct Inode *in, int mode); /** diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 51e73efdb65..a9387c32502 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -17,6 +17,7 @@ #include #include +#include "include/Context.h" #include "auth/Crypto.h" #include "client/Client.h" #include "client/Inode.h" @@ -2018,6 +2019,32 @@ extern "C" int64_t ceph_ll_writev(class ceph_mount_info *cmount, return (cmount->get_client()->ll_writev(fh, iov, iovcnt, off)); } +class LL_Onfinish : public Context { +public: + LL_Onfinish(struct ceph_ll_io_info *io_info) + : io_info(io_info) {} + bufferlist bl; +private: + struct ceph_ll_io_info *io_info; + void finish(int r) override { + if (!io_info->write && r > 0) { + copy_bufferlist_to_iovec(io_info->iov, io_info->iovcnt, &bl, r); + } + io_info->result = r; + io_info->callback(io_info); + } +}; + +extern "C" int64_t ceph_ll_nonblocking_readv_writev(class ceph_mount_info *cmount, + struct ceph_ll_io_info *io_info) +{ + LL_Onfinish *onfinish = new LL_Onfinish(io_info); + + return (cmount->get_client()->ll_preadv_pwritev( + io_info->fh, io_info->iov, io_info->iovcnt, + io_info->off, io_info->write, onfinish, &onfinish->bl)); +} + extern "C" int ceph_ll_close(class ceph_mount_info *cmount, Fh* fh) { return (cmount->get_client()->ll_release(fh)); -- 2.39.5