diff mbox series

[RFC,3/9] jfs: Convert direct_IO read support to use iomap

Message ID 20220526192910.357055-4-willy@infradead.org (mailing list archive)
State New, archived
Headers show
Series Convert JFS to use iomap | expand

Commit Message

Matthew Wilcox May 26, 2022, 7:29 p.m. UTC
Use the new iomap support to handle direct IO reads.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 fs/jfs/file.c      | 20 ++++++++++++++++++--
 fs/jfs/inode.c     |  4 ++++
 fs/jfs/jfs_inode.h |  1 +
 3 files changed, 23 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/fs/jfs/file.c b/fs/jfs/file.c
index 1d732fd223d4..0d074a9e0f77 100644
--- a/fs/jfs/file.c
+++ b/fs/jfs/file.c
@@ -4,10 +4,12 @@ 
  *   Portions Copyright (C) Christoph Hellwig, 2001-2002
  */
 
-#include <linux/mm.h>
 #include <linux/fs.h>
+#include <linux/iomap.h>
+#include <linux/mm.h>
 #include <linux/posix_acl.h>
 #include <linux/quotaops.h>
+#include <linux/uio.h>
 #include "jfs_incore.h"
 #include "jfs_inode.h"
 #include "jfs_dmap.h"
@@ -70,6 +72,20 @@  static int jfs_open(struct inode *inode, struct file *file)
 
 	return 0;
 }
+
+static ssize_t jfs_read_iter(struct kiocb *iocb, struct iov_iter *to)
+{
+	if (!iov_iter_count(to))
+		return 0; /* skip atime */
+
+	if (iocb->ki_flags & IOCB_DIRECT) {
+		file_accessed(iocb->ki_filp);
+		return iomap_dio_rw(iocb, to, &jfs_iomap_ops, NULL, 0, NULL, 0);
+	}
+
+	return generic_file_read_iter(iocb, to);
+}
+
 static int jfs_release(struct inode *inode, struct file *file)
 {
 	struct jfs_inode_info *ji = JFS_IP(inode);
@@ -141,7 +157,7 @@  const struct inode_operations jfs_file_inode_operations = {
 const struct file_operations jfs_file_operations = {
 	.open		= jfs_open,
 	.llseek		= generic_file_llseek,
-	.read_iter	= generic_file_read_iter,
+	.read_iter	= jfs_read_iter,
 	.write_iter	= generic_file_write_iter,
 	.mmap		= generic_file_mmap,
 	.splice_read	= generic_file_splice_read,
diff --git a/fs/jfs/inode.c b/fs/jfs/inode.c
index 1a5bdaf35e9b..22e8a5612fdc 100644
--- a/fs/jfs/inode.c
+++ b/fs/jfs/inode.c
@@ -294,6 +294,10 @@  int jfs_iomap_begin(struct inode *ip, loff_t pos, loff_t length,
 	return rc;
 }
 
+const struct iomap_ops jfs_iomap_ops = {
+	.iomap_begin =  jfs_iomap_begin,
+};
+
 int jfs_get_block(struct inode *ip, sector_t lblock,
 		  struct buffer_head *bh_result, int create)
 {
diff --git a/fs/jfs/jfs_inode.h b/fs/jfs/jfs_inode.h
index 7de961a81862..afd12de3c341 100644
--- a/fs/jfs/jfs_inode.h
+++ b/fs/jfs/jfs_inode.h
@@ -30,6 +30,7 @@  extern void jfs_set_inode_flags(struct inode *);
 extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
 extern int jfs_setattr(struct user_namespace *, struct dentry *, struct iattr *);
 
+extern const struct iomap_ops jfs_iomap_ops;
 extern const struct address_space_operations jfs_aops;
 extern const struct inode_operations jfs_dir_inode_operations;
 extern const struct file_operations jfs_dir_operations;