From aa48835ac0b57f4fa0cfcd4a0e726817816a4f9e Mon Sep 17 00:00:00 2001 From: Jeff Layton Date: Mon, 29 Aug 2016 07:16:41 -0400 Subject: [PATCH] client: add a ceph_fstatx Signed-off-by: Jeff Layton --- src/client/Client.cc | 25 +++++++++++++++++++++++++ src/client/Client.h | 1 + src/include/cephfs/libcephfs.h | 13 +++++++++++++ src/libcephfs.cc | 8 ++++++++ 4 files changed, 47 insertions(+) diff --git a/src/client/Client.cc b/src/client/Client.cc index 16b4ffaf33f..9c15f17a3bf 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -9030,6 +9030,31 @@ int Client::fstat(int fd, struct stat *stbuf, int mask) return r; } +int Client::fstatx(int fd, struct ceph_statx *stx, unsigned int want, unsigned int flags) +{ + Mutex::Locker lock(client_lock); + tout(cct) << "fstatx flags " << hex << flags << " want " << want << dec << std::endl; + tout(cct) << fd << std::endl; + + Fh *f = get_filehandle(fd); + if (!f) + return -EBADF; + + unsigned mask = statx_to_mask(flags, want); + + int r = 0; + if (mask && !f->inode->caps_issued_mask(mask)) { + r = _getattr(f->inode, mask); + if (r < 0) { + ldout(cct, 3) << "fstatx exit on error!" << dendl; + return r; + } + } + + fill_statx(f->inode, mask, stx); + ldout(cct, 3) << "fstatx(" << fd << ", " << stx << ") = " << r << dendl; + return r; +} // not written yet, but i want to link! diff --git a/src/client/Client.h b/src/client/Client.h index e5c655c4fbd..8b674464a90 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -1034,6 +1034,7 @@ public: int ftruncate(int fd, loff_t size); int fsync(int fd, bool syncdataonly); int fstat(int fd, struct stat *stbuf, int mask=CEPH_STAT_CAP_INODE_ALL); + int fstatx(int fd, struct ceph_statx *stx, unsigned int want, unsigned int flags); int fallocate(int fd, int mode, loff_t offset, loff_t length); // full path xattr ops diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h index 688702130b6..bf38b2b8f22 100644 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -928,6 +928,19 @@ int ceph_fallocate(struct ceph_mount_info *cmount, int fd, int mode, */ int ceph_fstat(struct ceph_mount_info *cmount, int fd, struct stat *stbuf); +/** + * Get an open file's extended statistics and attributes. + * + * @param cmount the ceph mount handle to use for performing the stat. + * @param fd the file descriptor of the file to get statistics of. + * @param stx the ceph_statx struct that will be filled in with the file's statistics. + * @param want bitfield of CEPH_STATX_* flags showing designed attributes + * @param flags bitfield that can be used to set AT_* modifier flags (only AT_NO_ATTR_SYNC and AT_SYMLINK_NOFOLLOW) + * @returns 0 on success or negative error code on failure. + */ +int ceph_fstatx(struct ceph_mount_info *cmount, int fd, struct ceph_statx *stx, + unsigned int want, unsigned int flags); + /** @} file */ /** diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 05ddf8e82b4..9e65bff95d2 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -890,6 +890,14 @@ extern "C" int ceph_fstat(struct ceph_mount_info *cmount, int fd, struct stat *s return cmount->get_client()->fstat(fd, stbuf); } +extern "C" int ceph_fstatx(struct ceph_mount_info *cmount, int fd, struct ceph_statx *stx, + unsigned int want, unsigned int flags) +{ + if (!cmount->is_mounted()) + return -ENOTCONN; + return cmount->get_client()->fstatx(fd, stx, want, flags); +} + extern "C" int ceph_sync_fs(struct ceph_mount_info *cmount) { if (!cmount->is_mounted()) -- 2.39.5