From efb3842fc57ff4afb76413425180a005320707a8 Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Mon, 5 May 2025 18:25:11 -0400 Subject: [PATCH] Switch to .iterate_shared Since v4.6-rc3-29-g6192269444eb there has been a special readdir VFS method that can be called for the same directory multiple times in parallel, without any additional VFS locking. The VFS has provided a WRAP_DIR_ITER() macro to re-wrap the method with extra locking, in case the method wasn't safe for this. With el10, the old .readdir method is now gone, and we have no choice but to either use the wrapper, or just hook up our readdir() method to the .iterate_shared op. From what I can see, our implementation is safe to do this. Signed-off-by: Auke Kok --- kmod/src/Makefile.kernelcompat | 8 ++++++++ kmod/src/dir.c | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/kmod/src/Makefile.kernelcompat b/kmod/src/Makefile.kernelcompat index 116d0ad9..be8c2c2e 100644 --- a/kmod/src/Makefile.kernelcompat +++ b/kmod/src/Makefile.kernelcompat @@ -326,6 +326,14 @@ ifneq (,$(shell grep 'ssize_t generic_file_splice_read.struct file' include/linu ccflags-y += -DKC_HAVE_GENERIC_FILE_SPLICE_READ endif +# +# v4.6-rc3-29-g6192269444eb +# +# Adds .iterate_shared readdir() iterator vfs method. +ifneq (,$(shell grep 'iterate_shared...struct file.., struct dir_context' include/linux/fs.h)) +ccflags-y += -DKC_HAVE_ITERATE_SHARED +endif + # # v6.15-13744-g41cb08555c41 # diff --git a/kmod/src/dir.c b/kmod/src/dir.c index f708c3d9..61130c69 100644 --- a/kmod/src/dir.c +++ b/kmod/src/dir.c @@ -1971,7 +1971,11 @@ const struct inode_operations scoutfs_symlink_iops = { }; const struct file_operations scoutfs_dir_fops = { +#ifdef KC_HAVE_ITERATE_SHARED + .iterate_shared = scoutfs_readdir, +#else .iterate = scoutfs_readdir, +#endif .unlocked_ioctl = scoutfs_ioctl, .fsync = scoutfs_file_fsync, .llseek = generic_file_llseek,