From 4e1f059222bd9b002060291a71cb1fdfa69f79e8 Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Wed, 7 Feb 2018 09:57:47 -0500 Subject: [PATCH] client: hook up ceph_ll_readv and ceph_ll_writev Break the core of _preadv_pwritev out into a function that takes a Fh. Make _preadv_pwritev into a wrapper around that. Then add in plumbing for ceph_ll_readv and ceph_ll_writev. Tracker: http://tracker.ceph.com/issues/22948 Signed-off-by: Jeff Layton --- src/client/Client.cc | 50 +++++++++++++++++++++++++++++++------------- src/client/Client.h | 3 +++ src/libcephfs.cc | 4 ++-- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index b3474d3e512a8..a121a894487e0 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -9022,18 +9022,9 @@ int Client::pwritev(int fd, const struct iovec *iov, int iovcnt, int64_t offset) return _preadv_pwritev(fd, iov, iovcnt, offset, true); } -int Client::_preadv_pwritev(int fd, const struct iovec *iov, unsigned iovcnt, int64_t offset, bool write) +int64_t Client::_preadv_pwritev_locked(Fh *fh, const struct iovec *iov, + unsigned iovcnt, int64_t offset, bool write) { - Mutex::Locker lock(client_lock); - tout(cct) << fd << std::endl; - tout(cct) << offset << std::endl; - - if (unmounting) - return -ENOTCONN; - - Fh *fh = get_filehandle(fd); - if (!fh) - return -EBADF; #if defined(__linux__) && defined(O_PATH) if (fh->flags & O_PATH) return -EBADF; @@ -9044,12 +9035,12 @@ int Client::_preadv_pwritev(int fd, const struct iovec *iov, unsigned iovcnt, in } if (write) { int64_t w = _write(fh, offset, totallen, NULL, iov, iovcnt); - ldout(cct, 3) << "pwritev(" << fd << ", \"...\", " << totallen << ", " << offset << ") = " << w << dendl; + ldout(cct, 3) << "pwritev(" << fh << ", \"...\", " << totallen << ", " << offset << ") = " << w << dendl; return w; } else { bufferlist bl; int64_t r = _read(fh, offset, totallen, &bl); - ldout(cct, 3) << "preadv(" << fd << ", " << offset << ") = " << r << dendl; + ldout(cct, 3) << "preadv(" << fh << ", " << offset << ") = " << r << dendl; if (r <= 0) return r; @@ -9072,6 +9063,21 @@ int Client::_preadv_pwritev(int fd, const struct iovec *iov, unsigned iovcnt, in } } +int Client::_preadv_pwritev(int fd, const struct iovec *iov, unsigned iovcnt, int64_t offset, bool write) +{ + Mutex::Locker lock(client_lock); + tout(cct) << fd << std::endl; + tout(cct) << offset << std::endl; + + if (unmounting) + return -ENOTCONN; + + Fh *fh = get_filehandle(fd); + if (!fh) + return -EBADF; + return _preadv_pwritev_locked(fh, iov, iovcnt, offset, write); +} + int64_t Client::_write(Fh *f, int64_t offset, uint64_t size, const char *buf, const struct iovec *iov, int iovcnt) { @@ -9106,7 +9112,7 @@ int64_t Client::_write(Fh *f, int64_t offset, uint64_t size, const char *buf, * change out from under us. */ if (f->flags & O_APPEND) { - int64_t r = _lseek(f, 0, SEEK_END); + int r = _lseek(f, 0, SEEK_END); if (r < 0) { unlock_fh_pos(f); return r; @@ -12785,6 +12791,22 @@ int Client::ll_write(Fh *fh, loff_t off, loff_t len, const char *data) return r; } +int64_t Client::ll_writev(struct Fh *fh, const struct iovec *iov, int iovcnt, int64_t off) +{ + Mutex::Locker lock(client_lock); + if (unmounting) + return -ENOTCONN; + return _preadv_pwritev_locked(fh, iov, iovcnt, off, true); +} + +int64_t Client::ll_readv(struct Fh *fh, const struct iovec *iov, int iovcnt, int64_t off) +{ + Mutex::Locker lock(client_lock); + if (unmounting) + return -ENOTCONN; + return _preadv_pwritev_locked(fh, iov, iovcnt, off, false); +} + int Client::ll_flush(Fh *fh) { Mutex::Locker lock(client_lock); diff --git a/src/client/Client.h b/src/client/Client.h index df388fc6d5f34..c936a90d35f54 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -835,6 +835,7 @@ private: int64_t _read(Fh *fh, int64_t offset, uint64_t size, bufferlist *bl); int64_t _write(Fh *fh, int64_t offset, uint64_t size, const char *buf, const struct iovec *iov, int iovcnt); + int64_t _preadv_pwritev_locked(Fh *f, const struct iovec *iov, unsigned iovcnt, int64_t offset, bool write); int _preadv_pwritev(int fd, const struct iovec *iov, unsigned iovcnt, int64_t offset, bool write); int _flush(Fh *fh); int _fsync(Fh *fh, bool syncdataonly); @@ -1214,6 +1215,8 @@ public: int ll_read(Fh *fh, loff_t off, loff_t len, bufferlist *bl); int ll_write(Fh *fh, loff_t off, loff_t len, const char *data); + int64_t ll_readv(struct Fh *fh, const struct iovec *iov, int iovcnt, int64_t off); + int64_t ll_writev(struct Fh *fh, const struct iovec *iov, int iovcnt, int64_t off); loff_t ll_lseek(Fh *fh, loff_t offset, int whence); int ll_flush(Fh *fh); int ll_fsync(Fh *fh, bool syncdataonly); diff --git a/src/libcephfs.cc b/src/libcephfs.cc index c9c3c5619ecda..3085e43720c0c 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -1559,14 +1559,14 @@ extern "C" int64_t ceph_ll_readv(class ceph_mount_info *cmount, struct Fh *fh, const struct iovec *iov, int iovcnt, int64_t off) { - return -1; // TODO: implement + return (cmount->get_client()->ll_readv(fh, iov, iovcnt, off)); } extern "C" int64_t ceph_ll_writev(class ceph_mount_info *cmount, struct Fh *fh, const struct iovec *iov, int iovcnt, int64_t off) { - return -1; // TODO: implement + return (cmount->get_client()->ll_writev(fh, iov, iovcnt, off)); } extern "C" int ceph_ll_close(class ceph_mount_info *cmount, Fh* fh) -- 2.39.5