]> www.infradead.org Git - users/hch/dma-mapping.git/commitdiff
bcachefs: Fix data corruption on -ENOSPC in buffered write path
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 17 Oct 2024 05:10:49 +0000 (01:10 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Fri, 18 Oct 2024 04:49:48 +0000 (00:49 -0400)
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>
fs/bcachefs/fs-io-buffered.c

index 48a1ab9a649bc11fea05f1aaed6b32cdfe772b36..95972809e76d7f5740b7bb007a370dbba7340c8a 100644 (file)
@@ -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;
                        }