bcachefs: Don't issue discards when in nochanges mode
authorKent Overstreet <kent.overstreet@gmail.com>
Mon, 21 Feb 2022 10:05:29 +0000 (05:05 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:24 +0000 (17:09 -0400)
When the nochanges option is selected, we're supposed to never issue
writes. Unfortunately, it seems discards were missed when implemnting
this, leading to some painful filesystem corruption.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
fs/bcachefs/alloc_background.c
fs/bcachefs/journal_reclaim.c

index 700d1e00aaf9264c0faccffa531186595a8c17b0..fac040aa0d5a2096b4a7a3fe401ed8be03a45df7 100644 (file)
@@ -801,7 +801,8 @@ static int push_invalidated_bucket(struct bch_fs *c, struct bch_dev *ca, u64 b)
 
 static void discard_one_bucket(struct bch_fs *c, struct bch_dev *ca, u64 b)
 {
-       if (ca->mi.discard &&
+       if (!c->opts.nochanges &&
+           ca->mi.discard &&
            bdev_max_discard_sectors(ca->disk_sb.bdev))
                blkdev_issue_discard(ca->disk_sb.bdev, bucket_to_sector(ca, b),
                                     ca->mi.bucket_size, GFP_NOFS);
index d72b17dc935ac805ae338c342f4c03d3e86228c5..84cc952a7ac56a5db289627c43ab53e7072bb06e 100644 (file)
@@ -286,7 +286,8 @@ void bch2_journal_do_discards(struct journal *j)
                struct journal_device *ja = &ca->journal;
 
                while (should_discard_bucket(j, ja)) {
-                       if (ca->mi.discard &&
+                       if (!c->opts.nochanges &&
+                           ca->mi.discard &&
                            bdev_max_discard_sectors(ca->disk_sb.bdev))
                                blkdev_issue_discard(ca->disk_sb.bdev,
                                        bucket_to_sector(ca,