Skip to content

Commit 97535cd

Browse files
author
Kent Overstreet
committed
bcachefs: Fix data corruption on -ENOSPC in buffered write path
Found by generic/299: When we have to truncate a write due to -ENOSPC, we may have to read in the folio we're writing to if we're now no longer doing a complete write to a !uptodate folio. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 335d318 commit 97535cd

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

fs/bcachefs/fs-io-buffered.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,12 @@ static int __bch2_buffered_write(struct bch_inode_info *inode,
856856
folios_trunc(&fs, fi);
857857
end = min(end, folio_end_pos(darray_last(fs)));
858858
} else {
859+
if (!folio_test_uptodate(f)) {
860+
ret = bch2_read_single_folio(f, mapping);
861+
if (ret)
862+
goto out;
863+
}
864+
859865
folios_trunc(&fs, fi + 1);
860866
end = f_pos + f_reserved;
861867
}

0 commit comments

Comments
 (0)