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 <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2024-10-17 01:10:49 -04:00
parent 335d318ef5
commit 97535cd84f

View File

@ -856,6 +856,12 @@ static int __bch2_buffered_write(struct bch_inode_info *inode,
folios_trunc(&fs, fi); folios_trunc(&fs, fi);
end = min(end, folio_end_pos(darray_last(fs))); end = min(end, folio_end_pos(darray_last(fs)));
} else { } else {
if (!folio_test_uptodate(f)) {
ret = bch2_read_single_folio(f, mapping);
if (ret)
goto out;
}
folios_trunc(&fs, fi + 1); folios_trunc(&fs, fi + 1);
end = f_pos + f_reserved; end = f_pos + f_reserved;
} }