[PATCH 003/437] fs: add helpers for defining read/write iterator helpers

Jens Axboe
2024-04-11T15:31:34Z

To ease conversion for drivers, add helpers that allow a driver to simply
wrap their existing read/write file_operations hook and turn it into one
that is appropriate for ->read_iter() or ->write_iter().

Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
include/linux/fs.h | 16 ++++++++++++++++
1 file changed, 16 insertions(+)

diff --git a/include/linux/fs.h b/include/linux/fs.h
index fd862985a309..72de0b1d5647 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2141,6 +2141,22 @@ extern loff_t vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos,
struct file *dst_file, loff_t dst_pos,
loff_t len, unsigned int remap_flags);

+/*
+ * Drivers can use these to ease transition to using ->read_iter() instead
+ * of ->read(), and ->write_iter() instead of ->write(). Ideally these will
+ * go away one day.
+ */
+#define FOPS_READ_ITER_HELPER(name) \
+static ssize_t name## _iter(struct kiocb *iocb, struct iov_iter *to) \
+{ \
+ return vfs_read_iter(iocb, to, name); \
+}
+#define FOPS_WRITE_ITER_HELPER(name) \
+static ssize_t name## _iter(struct kiocb *iocb, struct iov_iter *from) \
+{ \
+ return vfs_write_iter(iocb, from, name); \
+}
+
/**
* enum freeze_holder - holder of the freeze
* @FREEZE_HOLDER_KERNEL: kernel wants to freeze or thaw filesystem
--
2.43.0