Skip to content

Commit 8287474

Browse files
Al Virobrauner
authored andcommitted
direct_write_fallback(): on error revert the ->ki_pos update from buffered write
If we fail filemap_write_and_wait_range() on the range the buffered write went into, we only report the "number of bytes which we direct-written", to quote the comment in there. Which is fine, but buffered write has already advanced iocb->ki_pos, so we need to roll that back. Otherwise we end up with e.g. write(2) advancing position by more than the amount it reports having written. Fixes: 182c25e "filemap: update ki_pos in generic_perform_write" Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Message-Id: <20230827214518.GU3390869@ZenIV> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 2251588 commit 8287474

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

fs/libfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,7 @@ ssize_t direct_write_fallback(struct kiocb *iocb, struct iov_iter *iter,
19031903
* We don't know how much we wrote, so just return the number of
19041904
* bytes which were direct-written
19051905
*/
1906+
iocb->ki_pos -= buffered_written;
19061907
if (direct_written)
19071908
return direct_written;
19081909
return err;

0 commit comments

Comments
 (0)