From: Christoph Hellwig Date: Thu, 1 Jun 2023 14:59:02 +0000 (+0200) Subject: fuse: update ki_pos in fuse_perform_write X-Git-Tag: v6.6.7~2549^2~208 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=70e986c3b4f43ae7096be6de9a39c947f182e0c0;p=platform%2Fkernel%2Flinux-starfive.git 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.de Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal Cc: Al Viro Cc: Andreas Gruenbacher Cc: Anna Schumaker Cc: Chao Yu Cc: Christian Brauner Cc: "Darrick J. Wong" Cc: Hannes Reinecke Cc: Ilya Dryomov Cc: Jaegeuk Kim Cc: Jens Axboe Cc: Johannes Thumshirn Cc: Matthew Wilcox Cc: Miklos Szeredi Cc: Miklos Szeredi Cc: Theodore Ts'o Cc: Trond Myklebust Cc: Xiubo Li Signed-off-by: Andrew Morton --- diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 97d4358..d590250 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -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) @@ -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) */ @@ -1375,19 +1377,20 @@ writethrough: 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); @@ -1399,11 +1402,8 @@ writethrough: 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);