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

Konstantin Khorenko khorenko at virtuozzo.com
Mon May 25 17:52:04 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 1fa208181f31dc0865a58f6b4f3044c18f476f77
Author: Al Viro <viro at zeniv.linux.org.uk>
Date:   Mon May 25 17:52:04 2020 +0300

    __btrfs_direct_write(): switch to iov_iter
    
    ms commit 0ae5e4d37059
    
    Signed-off-by: Al Viro <viro at zeniv.linux.org.uk>
    
    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/btrfs/file.c | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 3abb3567112aa..44daeffd851e4 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1744,26 +1744,24 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file,
 }
 
 static ssize_t __btrfs_direct_write(struct kiocb *iocb,
-				    const struct iovec *iov,
-				    unsigned long nr_segs, loff_t pos,
+				    struct iov_iter *from,
+				    loff_t pos,
 				    loff_t *ppos, size_t count, size_t ocount)
 {
 	struct file *file = iocb->ki_filp;
 	struct inode *inode = file_inode(file);
-	struct iov_iter i;
 	ssize_t written;
 	ssize_t written_buffered;
 	loff_t endbyte;
 	int err;
 
-	iov_iter_init(&i, iov, nr_segs, count, 0);
-	written = generic_file_direct_write(iocb, &i, pos, ppos, ocount);
+	written = generic_file_direct_write(iocb, from, pos, ppos, ocount);
 
 	if (written < 0 || written == count)
 		return written;
 
 	pos += written;
-	written_buffered = __btrfs_buffered_write(file, &i, pos);
+	written_buffered = __btrfs_buffered_write(file, from, pos);
 	if (written_buffered < 0) {
 		err = written_buffered;
 		goto out;
@@ -1819,6 +1817,7 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb,
 	ssize_t err = 0;
 	size_t count, ocount;
 	bool sync = (file->f_flags & O_DSYNC) || IS_SYNC(file->f_mapping->host);
+	struct iov_iter i;
 
 	mutex_lock(&inode->i_mutex);
 
@@ -1881,14 +1880,12 @@ static ssize_t btrfs_file_aio_write(struct kiocb *iocb,
 	if (sync)
 		atomic_inc(&BTRFS_I(inode)->sync_writers);
 
+	iov_iter_init(&i, iov, nr_segs, count, 0);
+
 	if (file->f_flags & O_DIRECT) {
-		num_written = __btrfs_direct_write(iocb, iov, nr_segs,
+		num_written = __btrfs_direct_write(iocb, &i,
 						   pos, ppos, count, ocount);
 	} else {
-		struct iov_iter i;
-
-		iov_iter_init(&i, iov, nr_segs, count, num_written);
-
 		num_written = __btrfs_buffered_write(file, &i, pos);
 		if (num_written > 0)
 			*ppos = pos + num_written;


More information about the Devel mailing list