Commit 70e986c3 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Andrew Morton

fuse: update ki_pos in fuse_perform_write

Both callers of fuse_perform_write need to updated ki_pos, move it into
common code.

Link: https://lkml.kernel.org/r/20230601145904.1385409-11-hch@lst.deSigned-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDamien Le Moal <dlemoal@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: "Darrick J. Wong" <djwong@kernel.org>
Cc: Hannes Reinecke <hare@suse.de>
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: Theodore Ts'o <tytso@mit.edu>
Cc: Trond Myklebust <trond.myklebust@hammerspace.com>
Cc: Xiubo Li <xiubli@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 44fff0fa
...@@ -1329,7 +1329,10 @@ static ssize_t fuse_perform_write(struct kiocb *iocb, ...@@ -1329,7 +1329,10 @@ static ssize_t fuse_perform_write(struct kiocb *iocb,
fuse_write_update_attr(inode, pos, res); fuse_write_update_attr(inode, pos, res);
clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state); clear_bit(FUSE_I_SIZE_UNSTABLE, &fi->state);
return res > 0 ? res : err; if (!res)
return err;
iocb->ki_pos += res;
return res;
} }
static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from)
...@@ -1341,7 +1344,6 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) ...@@ -1341,7 +1344,6 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from)
struct inode *inode = mapping->host; struct inode *inode = mapping->host;
ssize_t err; ssize_t err;
struct fuse_conn *fc = get_fuse_conn(inode); struct fuse_conn *fc = get_fuse_conn(inode);
loff_t endbyte = 0;
if (fc->writeback_cache) { if (fc->writeback_cache) {
/* Update size (EOF optimization) and mode (SUID clearing) */ /* Update size (EOF optimization) and mode (SUID clearing) */
...@@ -1375,19 +1377,20 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) ...@@ -1375,19 +1377,20 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from)
goto out; goto out;
if (iocb->ki_flags & IOCB_DIRECT) { if (iocb->ki_flags & IOCB_DIRECT) {
loff_t pos = iocb->ki_pos; loff_t pos, endbyte;
written = generic_file_direct_write(iocb, from); written = generic_file_direct_write(iocb, from);
if (written < 0 || !iov_iter_count(from)) if (written < 0 || !iov_iter_count(from))
goto out; goto out;
pos += written; written_buffered = fuse_perform_write(iocb, mapping, from,
iocb->ki_pos);
written_buffered = fuse_perform_write(iocb, mapping, from, pos);
if (written_buffered < 0) { if (written_buffered < 0) {
err = written_buffered; err = written_buffered;
goto out; goto out;
} }
endbyte = pos + written_buffered - 1; pos = iocb->ki_pos - written_buffered;
endbyte = iocb->ki_pos - 1;
err = filemap_write_and_wait_range(file->f_mapping, pos, err = filemap_write_and_wait_range(file->f_mapping, pos,
endbyte); endbyte);
...@@ -1399,11 +1402,8 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from) ...@@ -1399,11 +1402,8 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from)
endbyte >> PAGE_SHIFT); endbyte >> PAGE_SHIFT);
written += written_buffered; written += written_buffered;
iocb->ki_pos = pos + written_buffered;
} else { } else {
written = fuse_perform_write(iocb, mapping, from, iocb->ki_pos); written = fuse_perform_write(iocb, mapping, from, iocb->ki_pos);
if (written >= 0)
iocb->ki_pos += written;
} }
out: out:
inode_unlock(inode); inode_unlock(inode);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment