[Devel] [PATCH RHEL7 COMMIT] ext4: Use iov_iter argument in direct_IO functions

Konstantin Khorenko khorenko at virtuozzo.com
Mon May 25 17:52:15 MSK 2020


The commit is pushed to "branch-rh7-3.10.0-1127.8.2.vz7.161.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1127.8.2.vz7.161.1
------>
commit 6072179f278a01d27d631f117aa4c617f2e95313
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Mon May 25 17:52:14 2020 +0300

    ext4: Use iov_iter argument in direct_IO functions
    
    Propagate iov_iter down into ext4 functions.
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
    
    =====================
    Patchset description:
    [00/30] fs,direct_IO: Switch to iov_iter and allow bio_vec for ext4
    
    This patchset transforms direct_IO callbacks, blockdev_direct_IO
    and its underlining functions to iov_iter, and introduces complete
    support of iov_iter for ext4.
    
    Supported iov_iter subtypes for ext4 is iovec and bio_vec. The first
    is for traditional user-submitted aio, while bio_vec is the type,
    which is important for us, since we use it in ploop.
    
    bio_vec operates with pages instead of user addresses (like iovec
    does), so it requires specific callbacks in do_blockdev_direct_IO()
    and in the functions it calls.
    
    The patchset reworks do_blockdev_direct_IO() in the same manner
    as in mainstrean. The most of rest patches are prepared manually,
    since we have significant differences to ms (RHEL7 patches, our
    direct IO patches for FUSE; all they have changed many functions).
    At the end, kaio engine (resulting in direct_IO) became possible
    to be enabled for ext4.
    
    https://jira.sw.ru/browse/PSBM-99793
---
 fs/ext4/ext4.h     |  3 +--
 fs/ext4/indirect.c | 15 +++++++--------
 fs/ext4/inode.c    | 21 +++++++++------------
 3 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 33d761aa7c96b..f2d849c05cdea 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -2257,8 +2257,7 @@ extern int ext4_issue_zeroout(struct inode *inode, ext4_lblk_t lblk,
 extern int ext4_ind_map_blocks(handle_t *handle, struct inode *inode,
 				struct ext4_map_blocks *map, int flags);
 extern ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb,
-				const struct iovec *iov, loff_t offset,
-				unsigned long nr_segs);
+				struct iov_iter *iter, loff_t offset);
 extern int ext4_ind_calc_metadata_amount(struct inode *inode, sector_t lblock);
 extern int ext4_ind_trans_blocks(struct inode *inode, int nrblocks);
 extern void ext4_ind_truncate(handle_t *, struct inode *inode);
diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c
index d34dc4de4bd28..aa16a40b82587 100644
--- a/fs/ext4/indirect.c
+++ b/fs/ext4/indirect.c
@@ -665,8 +665,7 @@ int ext4_ind_map_blocks(handle_t *handle, struct inode *inode,
  * VFS code falls back into buffered path in that case so we are safe.
  */
 ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb,
-			   const struct iovec *iov, loff_t offset,
-			   unsigned long nr_segs)
+			   struct iov_iter *iter, loff_t offset)
 {
 	struct file *file = iocb->ki_filp;
 	struct inode *inode = file->f_mapping->host;
@@ -674,7 +673,7 @@ ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb,
 	handle_t *handle;
 	ssize_t ret;
 	int orphan = 0;
-	size_t count = iov_length(iov, nr_segs);
+	size_t count = iov_iter_count(iter);
 	int retries = 0;
 
 	/* DAX uses iomap path now */
@@ -717,18 +716,18 @@ ssize_t ext4_ind_direct_IO(int rw, struct kiocb *iocb,
 			goto locked;
 		}
 		ret = __blockdev_direct_IO(rw, iocb, inode,
-					inode->i_sb->s_bdev, iov,
-					offset, nr_segs,
+					inode->i_sb->s_bdev, iov_iter_iovec(iter),
+					offset, iter->nr_segs,
 					ext4_get_block, NULL, NULL, 0);
 		inode_dio_end(inode);
 	} else {
 locked:
-		ret = blockdev_direct_IO(rw, iocb, inode, iov,
-					offset, nr_segs, ext4_get_block);
+		ret = blockdev_direct_IO(rw, iocb, inode, iov_iter_iovec(iter),
+					offset, iter->nr_segs, ext4_get_block);
 
 		if (unlikely((rw & WRITE) && ret < 0)) {
 			loff_t isize = i_size_read(inode);
-			loff_t end = offset + iov_length(iov, nr_segs);
+			loff_t end = offset + iov_iter_count(iter);
 
 			if (end > isize)
 				ext4_truncate_failed_write(inode);
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 6e7b341ea9197..d8798831afe59 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -3349,14 +3349,13 @@ static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset,
  *
  */
 static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
-			      const struct iovec *iov, loff_t offset,
-			      unsigned long nr_segs)
+			      struct iov_iter *iter, loff_t offset)
 {
 	struct file *file = iocb->ki_filp;
 	struct inode *inode = file->f_mapping->host;
 	struct ext4_inode_info *ei = EXT4_I(inode);
 	ssize_t ret;
-	size_t count = iov_length(iov, nr_segs);
+	size_t count = iov_iter_count(iter);
 	int overwrite = 0;
 	get_block_t *get_block_func = NULL;
 	int dio_flags = 0;
@@ -3366,7 +3365,7 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
 	/* Use the old path for reads and writes beyond i_size. */
 	if (rw != WRITE ||
 	    final_size > inode->i_size || final_size > ei->i_disksize)
-		return ext4_ind_direct_IO(rw, iocb, iov, offset, nr_segs);
+		return ext4_ind_direct_IO(rw, iocb, iter, offset);
 
 	BUG_ON(iocb->private == NULL);
 
@@ -3431,8 +3430,8 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
 		dio_flags = DIO_LOCKING;
 	}
 	ret = __blockdev_direct_IO(rw, iocb, inode,
-				   inode->i_sb->s_bdev, iov, offset,
-				   nr_segs, get_block_func,
+				   inode->i_sb->s_bdev, iov_iter_iovec(iter), offset,
+				   iter->nr_segs, get_block_func,
 				   ext4_end_io_dio, NULL, dio_flags);
 
 	/*
@@ -3475,8 +3474,6 @@ static ssize_t ext4_direct_IO(int rw, struct kiocb *iocb,
 {
 	struct file *file = iocb->ki_filp;
 	struct inode *inode = file->f_mapping->host;
-	const struct iovec *iov = iov_iter_iovec(iter);
-	unsigned long nr_segs = iter->nr_segs;
 	ssize_t ret;
 
 	/*
@@ -3493,13 +3490,13 @@ static ssize_t ext4_direct_IO(int rw, struct kiocb *iocb,
 	    ext4_test_inode_state(inode, EXT4_STATE_PFCACHE_CSUM))
 		ext4_truncate_data_csum(inode, -1);
 
-	trace_ext4_direct_IO_enter(inode, offset, iov_length(iov, nr_segs), rw);
+	trace_ext4_direct_IO_enter(inode, offset, iov_iter_count(iter), rw);
 	if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
-		ret = ext4_ext_direct_IO(rw, iocb, iov, offset, nr_segs);
+		ret = ext4_ext_direct_IO(rw, iocb, iter, offset);
 	else
-		ret = ext4_ind_direct_IO(rw, iocb, iov, offset, nr_segs);
+		ret = ext4_ind_direct_IO(rw, iocb, iter, offset);
 	trace_ext4_direct_IO_exit(inode, offset,
-				iov_length(iov, nr_segs), rw, ret);
+				iov_iter_count(iter), rw, ret);
 	return ret;
 }
 


More information about the Devel mailing list