[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <176169810808.1424854.3451236931304006986.stgit@frogsfrogsfrogs>
Date: Tue, 28 Oct 2025 17:50:25 -0700
From: "Darrick J. Wong" <djwong@...nel.org>
To: djwong@...nel.org, miklos@...redi.hu
Cc: joannelkoong@...il.com, bernd@...ernd.com, neal@...pa.dev,
linux-ext4@...r.kernel.org, linux-fsdevel@...r.kernel.org
Subject: [PATCH 21/31] fuse: implement fadvise for iomap files
From: Darrick J. Wong <djwong@...nel.org>
If userspace asks us to perform readahead on a file, take i_rwsem so
that it can't race with hole punching or writes.
Signed-off-by: "Darrick J. Wong" <djwong@...nel.org>
---
fs/fuse/fuse_i.h | 3 +++
fs/fuse/file.c | 1 +
fs/fuse/file_iomap.c | 20 ++++++++++++++++++++
3 files changed, 24 insertions(+)
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 3fdffbeabe3306..8e3e2e5591c760 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -1792,6 +1792,8 @@ int fuse_iomap_flush_unmap_range(struct inode *inode, loff_t pos,
int fuse_dev_ioctl_iomap_support(struct file *file,
struct fuse_iomap_support __user *argp);
+
+int fuse_iomap_fadvise(struct file *file, loff_t start, loff_t end, int advice);
#else
# define fuse_iomap_enabled(...) (false)
# define fuse_has_iomap(...) (false)
@@ -1817,6 +1819,7 @@ int fuse_dev_ioctl_iomap_support(struct file *file,
# define fuse_iomap_fallocate(...) (-ENOSYS)
# define fuse_iomap_flush_unmap_range(...) (-ENOSYS)
# define fuse_dev_ioctl_iomap_support(...) (-EOPNOTSUPP)
+# define fuse_iomap_fadvise NULL
#endif
#endif /* _FS_FUSE_I_H */
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index adcd9e3bd6a4d9..8a2daee7e58e27 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -3199,6 +3199,7 @@ static const struct file_operations fuse_file_operations = {
.poll = fuse_file_poll,
.fallocate = fuse_file_fallocate,
.copy_file_range = fuse_copy_file_range,
+ .fadvise = fuse_iomap_fadvise,
};
static const struct address_space_operations fuse_file_aops = {
diff --git a/fs/fuse/file_iomap.c b/fs/fuse/file_iomap.c
index ff61f7880b3332..9fd2600f599d95 100644
--- a/fs/fuse/file_iomap.c
+++ b/fs/fuse/file_iomap.c
@@ -7,6 +7,7 @@
#include <linux/fiemap.h>
#include <linux/pagemap.h>
#include <linux/falloc.h>
+#include <linux/fadvise.h>
#include "fuse_i.h"
#include "fuse_trace.h"
#include "iomap_i.h"
@@ -1877,3 +1878,22 @@ int fuse_dev_ioctl_iomap_support(struct file *file,
return -EFAULT;
return 0;
}
+
+int fuse_iomap_fadvise(struct file *file, loff_t start, loff_t end, int advice)
+{
+ struct inode *inode = file_inode(file);
+ bool needlock = advice == POSIX_FADV_WILLNEED &&
+ fuse_inode_has_iomap(inode);
+ int ret;
+
+ /*
+ * Operations creating pages in page cache need protection from hole
+ * punching and similar ops
+ */
+ if (needlock)
+ inode_lock_shared(inode);
+ ret = generic_fadvise(file, start, end, advice);
+ if (needlock)
+ inode_unlock_shared(inode);
+ return ret;
+}
Powered by blists - more mailing lists