filemap: update ki_pos in generic_perform_write
authorChristoph Hellwig <hch@lst.de>
Thu, 1 Jun 2023 14:58:55 +0000 (16:58 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 9 Jun 2023 23:25:52 +0000 (16:25 -0700)
All callers of generic_perform_write need to updated ki_pos, move it into
common code.

Link: https://lkml.kernel.org/r/20230601145904.1385409-4-hch@lst.de
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Xiubo Li <xiubli@redhat.com>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Acked-by: Theodore Ts'o <tytso@mit.edu>
Acked-by: Darrick J. Wong <djwong@kernel.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andreas Gruenbacher <agruenba@redhat.com>
Cc: Anna Schumaker <anna@kernel.org>
Cc: Chao Yu <chao@kernel.org>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Ilya Dryomov <idryomov@gmail.com>
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Miklos Szeredi <miklos@szeredi.hu>
Cc: Miklos Szeredi <mszeredi@redhat.com>
Cc: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/ceph/file.c
fs/ext4/file.c
fs/f2fs/file.c
fs/nfs/file.c
mm/filemap.c

index c8ef72f723badde884f1dba4e371a98738466485..767f4dfe7def6456a75faea8cc16fe47c89a407e 100644 (file)
@@ -1891,8 +1891,6 @@ retry_snap:
                 * can not run at the same time
                 */
                written = generic_perform_write(iocb, from);
-               if (likely(written >= 0))
-                       iocb->ki_pos = pos + written;
                ceph_end_io_write(inode);
        }
 
index bc430270c23c19a28608da52805036d91bb1b2d2..ea0ada3985cba21c852a7a5acee8c723dd3c4717 100644 (file)
@@ -289,12 +289,9 @@ static ssize_t ext4_buffered_write_iter(struct kiocb *iocb,
 
 out:
        inode_unlock(inode);
-       if (likely(ret > 0)) {
-               iocb->ki_pos += ret;
-               ret = generic_write_sync(iocb, ret);
-       }
-
-       return ret;
+       if (unlikely(ret <= 0))
+               return ret;
+       return generic_write_sync(iocb, ret);
 }
 
 static ssize_t ext4_handle_inode_extension(struct inode *inode, loff_t offset,
index 4f423d367a44b9d191eab3003b75aa84bce2644b..7134fe8bd008cbb735602386659d35ca7930a1ef 100644 (file)
@@ -4520,7 +4520,6 @@ static ssize_t f2fs_buffered_write_iter(struct kiocb *iocb,
        ret = generic_perform_write(iocb, from);
 
        if (ret > 0) {
-               iocb->ki_pos += ret;
                f2fs_update_iostat(F2FS_I_SB(inode), inode,
                                                APP_BUFFERED_IO, ret);
        }
index 665ce3fc62eaf480a5453245a2fd405121d81d01..e8bb4c48a3210a8f9f8ffb4081885f31b6433f1a 100644 (file)
@@ -655,7 +655,6 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_iter *from)
                goto out;
 
        written = result;
-       iocb->ki_pos += written;
        nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, written);
 
        if (mntflags & NFS_MOUNT_WRITE_EAGER) {
index 0d371ed91a680bdbffb570c415e696594cf2070a..3a80a69fa9fa86f9b1d8fd7a3cf534b03b6a995d 100644 (file)
@@ -3930,7 +3930,10 @@ again:
                balance_dirty_pages_ratelimited(mapping);
        } while (iov_iter_count(i));
 
-       return written ? written : status;
+       if (!written)
+               return status;
+       iocb->ki_pos += written;
+       return written;
 }
 EXPORT_SYMBOL(generic_perform_write);
 
@@ -4007,7 +4010,6 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
                endbyte = pos + status - 1;
                err = filemap_write_and_wait_range(mapping, pos, endbyte);
                if (err == 0) {
-                       iocb->ki_pos = endbyte + 1;
                        written += status;
                        invalidate_mapping_pages(mapping,
                                                 pos >> PAGE_SHIFT,
@@ -4020,8 +4022,6 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
                }
        } else {
                written = generic_perform_write(iocb, from);
-               if (likely(written > 0))
-                       iocb->ki_pos += written;
        }
 out:
        return written ? written : err;