[Devel] [PATCH RHEL7 COMMIT] ext4: ext4_write_checks(): switch to iov_iter

Konstantin Khorenko khorenko at virtuozzo.com
Mon May 25 17:52:32 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 c15a87fd66857cded14df75dde085f583f87b7aa
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Mon May 25 17:52:32 2020 +0300

    ext4: ext4_write_checks(): switch to iov_iter
    
    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/file.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 2808aadd40336..36622e82d152f 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -118,12 +118,11 @@ static bool ext4_overwrite_io(struct inode *inode, loff_t pos, loff_t len)
 	return err == blklen && (map.m_flags & EXT4_MAP_MAPPED);
 }
 
-static ssize_t ext4_write_checks(struct kiocb *iocb, const struct iovec *iov,
-				 unsigned long nr_segs, loff_t *pos)
+static ssize_t ext4_write_checks(struct kiocb *iocb, struct iov_iter *iter, loff_t *pos)
 {
 	struct file *file = iocb->ki_filp;
 	struct inode *inode = file_inode(iocb->ki_filp);
-	size_t length = iov_length(iov, nr_segs);
+	size_t length = iov_iter_count(iter);
 	ssize_t ret;
 
 	ret = generic_write_checks(file, pos, &length, S_ISBLK(inode->i_mode));
@@ -144,11 +143,15 @@ static ssize_t ext4_write_checks(struct kiocb *iocb, const struct iovec *iov,
 			return -EFBIG;
 
 		if (*pos + length > sbi->s_bitmap_maxbytes) {
-			nr_segs = iov_shorten((struct iovec *)iov, nr_segs,
+			int err;
+
+			err = iov_iter_shorten(iter,
 					      sbi->s_bitmap_maxbytes - *pos);
+			if (WARN_ON_ONCE(err))
+				return err;
 		}
 	}
-	return iov_length(iov, nr_segs);
+	return iov_iter_count(iter);
 }
 
 static ssize_t
@@ -222,8 +225,10 @@ ext4_file_dax_write(
 	size_t			size = iov_length(iovp, nr_segs);
 	struct iov_iter iter;
 
+	iov_iter_init(&iter, iovp, nr_segs, size, 0);
+
 	inode_lock(inode);
-	ret = ext4_write_checks(iocb, iovp, nr_segs, &pos);
+	ret = ext4_write_checks(iocb, &iter, &pos);
 	if (ret < 0)
 		goto out;
 	ret = file_remove_privs(iocb->ki_filp);
@@ -232,9 +237,6 @@ ext4_file_dax_write(
 	ret = file_update_time(iocb->ki_filp);
 	if (ret)
 		goto out;
-
-	iov_iter_init(&iter, iovp, nr_segs, size, 0);
-
 	ret = dax_iomap_rw(WRITE, iocb, &iter, pos,
 					size, &ext4_iomap_ops);
 out:
@@ -257,8 +259,11 @@ ext4_file_write(struct kiocb *iocb, const struct iovec *iov,
 	struct inode *inode = file_inode(iocb->ki_filp);
 	ssize_t ret;
 	int overwrite = 0;
+	struct iov_iter iter;
+
+	iov_iter_init(&iter, iov, nr_segs, iov_length(iov, nr_segs), 0);
 
-	ret = ext4_write_checks(iocb, iov, nr_segs, &pos);
+	ret = ext4_write_checks(iocb, &iter, &pos);
 	if (ret <= 0)
 		return ret;
 


More information about the Devel mailing list