From f16183f90abba3c2d3d26262926f1454275a9d3f Mon Sep 17 00:00:00 2001 From: Shachar Sharon Date: Mon, 24 Jun 2024 11:39:43 +0300 Subject: [PATCH] vfs_ceph_new: use low-level APIs for fstat Use libcephfs' low-level APIs and apply the same logic as stat, but via explicit inode-reference. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15686 Signed-off-by: Shachar Sharon Reviewed-by: Guenther Deschner Reviewed-by: Anoop C S --- source3/modules/vfs_ceph_new.c | 50 ++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/source3/modules/vfs_ceph_new.c b/source3/modules/vfs_ceph_new.c index 346bf6fbbdf..f7482a9f0e2 100644 --- a/source3/modules/vfs_ceph_new.c +++ b/source3/modules/vfs_ceph_new.c @@ -535,18 +535,14 @@ static int vfs_ceph_ll_statfs(const struct vfs_handle_struct *handle, return ceph_ll_statfs(cmount_of(handle), iref->inode, stbuf); } -static int vfs_ceph_ll_getattr(const struct vfs_handle_struct *handle, - const struct vfs_ceph_iref *iref, - SMB_STRUCT_STAT *st) +static int vfs_ceph_ll_getattr2(const struct vfs_handle_struct *handle, + const struct vfs_ceph_iref *iref, + struct UserPerm *uperm, + SMB_STRUCT_STAT *st) { struct ceph_statx stx = {0}; - struct UserPerm *uperm = NULL; int ret = -1; - uperm = vfs_ceph_userperm_new(handle); - if (uperm == NULL) { - return -ENOMEM; - } ret = ceph_ll_getattr(cmount_of(handle), iref->inode, &stx, @@ -556,6 +552,21 @@ static int vfs_ceph_ll_getattr(const struct vfs_handle_struct *handle, if (ret == 0) { smb_stat_from_ceph_statx(st, &stx); } + return ret; +} + +static int vfs_ceph_ll_getattr(const struct vfs_handle_struct *handle, + const struct vfs_ceph_iref *iref, + SMB_STRUCT_STAT *st) +{ + struct UserPerm *uperm = NULL; + int ret = -1; + + uperm = vfs_ceph_userperm_new(handle); + if (uperm == NULL) { + return -ENOMEM; + } + ret = vfs_ceph_ll_getattr2(handle, iref, uperm, st); vfs_ceph_userperm_del(uperm); return ret; } @@ -1440,20 +1451,23 @@ static int vfs_ceph_fstat(struct vfs_handle_struct *handle, SMB_STRUCT_STAT *sbuf) { int result = -1; - struct ceph_statx stx = { 0 }; - int fd = fsp_get_pathref_fd(fsp); + struct vfs_ceph_fh *cfh = NULL; - DBG_DEBUG("[CEPH] fstat(%p, %d)\n", handle, fd); - result = ceph_fstatx(handle->data, fd, &stx, - SAMBA_STATX_ATTR_MASK, 0); - DBG_DEBUG("[CEPH] fstat(...) = %d\n", result); - if (result < 0) { - return status_code(result); + DBG_DEBUG("[CEPH] fstat(%p)\n", handle); + + result = vfs_ceph_fetch_fh(handle, fsp, &cfh); + if (result != 0) { + goto out; } - init_stat_ex_from_ceph_statx(sbuf, &stx); + result = vfs_ceph_ll_getattr2(handle, &cfh->iref, cfh->uperm, sbuf); + if (result != 0) { + goto out; + } DBG_DEBUG("[CEPH] mode = 0x%x\n", sbuf->st_ex_mode); - return result; +out: + DBG_DEBUG("[CEPH] fstat(...) = %d\n", result); + return status_code(result); } static int vfs_ceph_fstatat(struct vfs_handle_struct *handle, -- 2.47.3