]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
libcephfs: Add nonblocking readv/writev I/O interface
authorFrank S. Filz <ffilzlnx@mindspring.com>
Wed, 11 May 2022 21:35:53 +0000 (14:35 -0700)
committerFrank S. Filz <ffilzlnx@mindspring.com>
Mon, 24 Jul 2023 18:49:03 +0000 (11:49 -0700)
Signed-off-by: Frank S. Filz <ffilzlnx@mindspring.com>
src/include/cephfs/libcephfs.h
src/libcephfs.cc

index dc62698fa482a3f9346c9104012a03137af8925b..703dd900b5d17082d0620d828598fa8b8cb57b7b 100644 (file)
@@ -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);
 /**
index 51e73efdb65ec572bdf9dede5f17e3a4803e40f4..a9387c32502fefedb2173e9609d7b302a319c97b 100644 (file)
@@ -17,6 +17,7 @@
 #include <string.h>
 #include <string>
 
+#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));