Commit 97535cd8 authored by Kent Overstreet's avatar Kent Overstreet
Browse files

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: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 335d318e
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -856,6 +856,12 @@ static int __bch2_buffered_write(struct bch_inode_info *inode,
				folios_trunc(&fs, fi);
				end = min(end, folio_end_pos(darray_last(fs)));
			} else {
				if (!folio_test_uptodate(f)) {
					ret = bch2_read_single_folio(f, mapping);
					if (ret)
						goto out;
				}

				folios_trunc(&fs, fi + 1);
				end = f_pos + f_reserved;
			}