bcachefs: Fix swallowing of data in buffered write path
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 15 Aug 2023 02:29:41 +0000 (22:29 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:10:11 +0000 (17:10 -0400)
In __bch2_buffered_write, if we fail to write to an entire !uptodate
folio, we have to back out the write, bail out and retry.

But we were missing an iov_iter_revert() call, so the data written to
the folio was lost and the rest of the write shifted to the wrong
offset.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/fs-io-buffered.c

index 102c70887f76b95c5fe1af471b8220f02a2617f2..dc22182d532feff69baa699865498a9c73862329 100644 (file)
@@ -909,6 +909,7 @@ static int __bch2_buffered_write(struct bch_inode_info *inode,
                if (!folio_test_uptodate(f) &&
                    f_copied != folio_size(f) &&
                    pos + copied + f_copied < inode->v.i_size) {
+                       iov_iter_revert(iter, f_copied);
                        folio_zero_range(f, 0, folio_size(f));
                        folios_trunc(&folios, fi);
                        break;