Skip to content

Commit

Permalink
fuse: update ki_pos in fuse_perform_write
Browse files Browse the repository at this point in the history
Both callers of fuse_perform_write need to updated ki_pos, move it into
common code.

Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Christoph Hellwig <[email protected]>
Reviewed-by: Damien Le Moal <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Andreas Gruenbacher <[email protected]>
Cc: Anna Schumaker <[email protected]>
Cc: Chao Yu <[email protected]>
Cc: Christian Brauner <[email protected]>
Cc: "Darrick J. Wong" <[email protected]>
Cc: Hannes Reinecke <[email protected]>
Cc: Ilya Dryomov <[email protected]>
Cc: Jaegeuk Kim <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: Johannes Thumshirn <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: Miklos Szeredi <[email protected]>
Cc: Miklos Szeredi <[email protected]>
Cc: Theodore Ts'o <[email protected]>
Cc: Trond Myklebust <[email protected]>
Cc: Xiubo Li <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
Christoph Hellwig authored and akpm00 committed Jun 9, 2023
1 parent 44fff0f commit 70e986c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions fs/fuse/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,10 @@ static ssize_t fuse_perform_write(struct kiocb *iocb,
fuse_write_update_attr(inode, pos, res);
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)
Expand All @@ -1341,7 +1344,6 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from)
struct inode *inode = mapping->host;
ssize_t err;
struct fuse_conn *fc = get_fuse_conn(inode);
loff_t endbyte = 0;

if (fc->writeback_cache) {
/* Update size (EOF optimization) and mode (SUID clearing) */
Expand Down Expand Up @@ -1375,19 +1377,20 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from)
goto out;

if (iocb->ki_flags & IOCB_DIRECT) {
loff_t pos = iocb->ki_pos;
loff_t pos, endbyte;

written = generic_file_direct_write(iocb, from);
if (written < 0 || !iov_iter_count(from))
goto out;

pos += written;

written_buffered = fuse_perform_write(iocb, mapping, from, pos);
written_buffered = fuse_perform_write(iocb, mapping, from,
iocb->ki_pos);
if (written_buffered < 0) {
err = written_buffered;
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,
endbyte);
Expand All @@ -1399,11 +1402,8 @@ static ssize_t fuse_cache_write_iter(struct kiocb *iocb, struct iov_iter *from)
endbyte >> PAGE_SHIFT);

written += written_buffered;
iocb->ki_pos = pos + written_buffered;
} else {
written = fuse_perform_write(iocb, mapping, from, iocb->ki_pos);
if (written >= 0)
iocb->ki_pos += written;
}
out:
inode_unlock(inode);
Expand Down

0 comments on commit 70e986c

Please sign in to comment.