[Devel] [PATCH rh7 02/30] fs: generic_file_direct_write() switch to iov_iter
Kirill Tkhai
ktkhai at virtuozzo.com
Wed May 20 19:03:07 MSK 2020
generic_file_direct_write_iter() is not needed anymore.
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
fs/btrfs/file.c | 6 ++----
fs/fuse/file.c | 9 ++-------
fs/ocfs2/file.c | 10 ++++++----
include/linux/fs.h | 4 ++--
mm/filemap.c | 24 +++---------------------
5 files changed, 15 insertions(+), 38 deletions(-)
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 80dcf423266c..3abb3567112a 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -1756,15 +1756,13 @@ static ssize_t __btrfs_direct_write(struct kiocb *iocb,
loff_t endbyte;
int err;
- written = generic_file_direct_write(iocb, iov, &nr_segs, pos, ppos,
- count, ocount);
+ iov_iter_init(&i, iov, nr_segs, count, 0);
+ written = generic_file_direct_write(iocb, &i, pos, ppos, ocount);
if (written < 0 || written == count)
return written;
pos += written;
- count -= written;
- iov_iter_init(&i, iov, nr_segs, count, written);
written_buffered = __btrfs_buffered_write(file, &i, pos);
if (written_buffered < 0) {
err = written_buffered;
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 4c58d527ec7e..973f1513868a 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1598,16 +1598,11 @@ static ssize_t fuse_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
goto out;
if (file->f_flags & O_DIRECT) {
- written = generic_file_direct_write(iocb, iov, &nr_segs,
- pos, &iocb->ki_pos,
- count, ocount);
+ iov_iter_init(&i, iov, nr_segs, count, 0);
+ written = generic_file_direct_write(iocb, &i, pos, &pos, ocount);
if (written < 0 || written == count)
goto out;
- pos += written;
- count -= written;
-
- iov_iter_init(&i, iov, nr_segs, count, written);
written_buffered = fuse_perform_write(file, mapping, &i, pos);
if (written_buffered < 0) {
err = written_buffered;
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index 2bcf1677a59b..60ea07def7e2 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -2238,6 +2238,7 @@ static ssize_t ocfs2_file_aio_write(struct kiocb *iocb,
int full_coherency = !(osb->s_mount_opt &
OCFS2_MOUNT_COHERENCY_BUFFERED);
int unaligned_dio = 0;
+ struct iov_iter from;
trace_ocfs2_file_aio_write(inode, file, file->f_path.dentry,
(unsigned long long)OCFS2_I(inode)->ip_blkno,
@@ -2354,17 +2355,18 @@ static ssize_t ocfs2_file_aio_write(struct kiocb *iocb,
if (ret)
goto out_dio;
+ iov_iter_init(&from, iov, nr_segs, count, 0);
if (direct_io) {
- written = generic_file_direct_write(iocb, iov, &nr_segs, *ppos,
- ppos, count, ocount);
+ written = generic_file_direct_write_iter(iocb, &from, *ppos,
+ ppos, ocount);
if (written < 0) {
ret = written;
goto out_dio;
}
} else {
current->backing_dev_info = file->f_mapping->backing_dev_info;
- written = generic_file_buffered_write(iocb, iov, nr_segs, *ppos,
- ppos, count, 0);
+ written = generic_file_buffered_write_iter(iocb, &from, *ppos, ppos, 0);
+
current->backing_dev_info = NULL;
}
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 73c1c55c5362..f778fcc3bcc5 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -3216,8 +3216,8 @@ extern ssize_t __generic_file_aio_write(struct kiocb *, const struct iovec *, un
extern ssize_t __generic_file_write_iter(struct kiocb *, struct iov_iter *, loff_t *);
extern ssize_t generic_file_aio_write(struct kiocb *, const struct iovec *, unsigned long, loff_t);
extern ssize_t generic_file_write_iter(struct kiocb *, struct iov_iter *, loff_t);
-extern ssize_t generic_file_direct_write(struct kiocb *, const struct iovec *,
- unsigned long *, loff_t, loff_t *, size_t, size_t);
+extern ssize_t generic_file_direct_write(struct kiocb *iocb, struct iov_iter *iter,
+ loff_t pos, loff_t *ppos, size_t count);
extern ssize_t generic_file_direct_write_iter(struct kiocb *, struct iov_iter *,
loff_t, loff_t *, size_t);
extern ssize_t generic_file_buffered_write(struct kiocb *, const struct iovec *,
diff --git a/mm/filemap.c b/mm/filemap.c
index 3c2eb02778c7..d13bc7fef066 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2825,7 +2825,7 @@ int pagecache_write_end(struct file *file, struct address_space *mapping,
EXPORT_SYMBOL(pagecache_write_end);
ssize_t
-generic_file_direct_write_iter(struct kiocb *iocb, struct iov_iter *iter,
+generic_file_direct_write(struct kiocb *iocb, struct iov_iter *iter,
loff_t pos, loff_t *ppos, size_t count)
{
struct file *file = iocb->ki_filp;
@@ -2881,6 +2881,7 @@ generic_file_direct_write_iter(struct kiocb *iocb, struct iov_iter *iter,
if (written > 0) {
pos += written;
+ iov_iter_advance(iter, written);
if (pos > i_size_read(inode) && !S_ISBLK(inode->i_mode)) {
i_size_write(inode, pos);
mark_inode_dirty(inode);
@@ -2890,23 +2891,6 @@ generic_file_direct_write_iter(struct kiocb *iocb, struct iov_iter *iter,
out:
return written;
}
-EXPORT_SYMBOL(generic_file_direct_write_iter);
-
-ssize_t
-generic_file_direct_write(struct kiocb *iocb, const struct iovec *iov,
- unsigned long *nr_segs, loff_t pos, loff_t *ppos,
- size_t count, size_t ocount)
-{
- struct iov_iter iter;
- ssize_t ret;
-
- iov_iter_init(&iter, iov, *nr_segs, ocount, 0);
- ret = generic_file_direct_write_iter(iocb, &iter, pos, ppos, count);
- /* generic_file_direct_write_iter() might have shortened the vec */
- if (*nr_segs != iter.nr_segs)
- *nr_segs = iter.nr_segs;
- return ret;
-}
EXPORT_SYMBOL(generic_file_direct_write);
/*
@@ -3124,8 +3108,7 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *iter,
loff_t endbyte;
ssize_t written_buffered;
- written = generic_file_direct_write_iter(iocb, iter, pos,
- ppos, count);
+ written = generic_file_direct_write(iocb, iter, pos, ppos, count);
/*
* If the write stopped short of completing, fall back to
* buffered writes. Some filesystems do this for writes to
@@ -3138,7 +3121,6 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *iter,
pos += written;
count -= written;
- iov_iter_advance(iter, written);
written_buffered = generic_file_buffered_write_iter(iocb, iter,
pos, ppos, written);
/*
More information about the Devel
mailing list