From ce958aeef1afe8e54c82383ac81ab9765c78e040 Mon Sep 17 00:00:00 2001 From: Shachar Sharon Date: Tue, 30 Jul 2024 17:36:09 +0300 Subject: [PATCH] vfs_ceph_new: handle errno properly for 'readdir' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Take special care for readdir errno setting: in case of error, update errno by libcephfs (and protect from possible over-write by debug logging); in the case of successful result or end-of-stream restore errno to its previous value before calling the readdir_fn VFS hook. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15686 Signed-off-by: Shachar Sharon Reviewed-by: Guenther Deschner Reviewed-by: Anoop C S Autobuild-User(master): Günther Deschner Autobuild-Date(master): Wed Aug 7 14:20:02 UTC 2024 on atb-devel-224 (cherry picked from commit aa043a5808b73fc272de585c1446372fa3f21d08) --- source3/modules/vfs_ceph_new.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/source3/modules/vfs_ceph_new.c b/source3/modules/vfs_ceph_new.c index c11f5f24616..cf7e6b121db 100644 --- a/source3/modules/vfs_ceph_new.c +++ b/source3/modules/vfs_ceph_new.c @@ -1482,19 +1482,20 @@ static struct dirent *vfs_ceph_readdir(struct vfs_handle_struct *handle, { const struct vfs_ceph_fh *dircfh = (const struct vfs_ceph_fh *)dirp; struct dirent *result = NULL; - int errval = 0; + int saved_errno = errno; DBG_DEBUG("[CEPH] readdir(%p, %p)\n", handle, dirp); + errno = 0; result = vfs_ceph_ll_readdir(handle, dircfh); - errval = errno; - if ((result == NULL) && (errval != 0)) { - DBG_DEBUG("[CEPH] readdir(...) = %d\n", errval); + if ((result == NULL) && (errno != 0)) { + saved_errno = errno; + DBG_DEBUG("[CEPH] readdir(...) = %d\n", errno); } else { DBG_DEBUG("[CEPH] readdir(...) = %p\n", result); } - /* re-assign errno to avoid possible over-write by DBG_DEBUG */ - errno = errval; + + errno = saved_errno; return result; }