]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: Check for read_time == 0 in bch2_alloc_v4_invalid()
authorKent Overstreet <kent.overstreet@gmail.com>
Wed, 6 Apr 2022 21:22:47 +0000 (17:22 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:30 +0000 (17:09 -0400)
We've been seeing this error in fsck and we weren't able to track down
where it came from - but now that .key_invalid methods take a rw
argument, we can safely check for this.

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

index cad39119949ad8cd1c83c9d998938fcc0b8f00e4..f030030a8b5033474959d4f9e1c271e58e38cc1e 100644 (file)
@@ -346,12 +346,23 @@ int bch2_alloc_v3_invalid(const struct bch_fs *c, struct bkey_s_c k,
 int bch2_alloc_v4_invalid(const struct bch_fs *c, struct bkey_s_c k,
                          int rw, struct printbuf *err)
 {
+       struct bkey_s_c_alloc_v4 a = bkey_s_c_to_alloc_v4(k);
+
        if (bkey_val_bytes(k.k) != sizeof(struct bch_alloc_v4)) {
                pr_buf(err, "bad val size (%zu != %zu)",
                       bkey_val_bytes(k.k), sizeof(struct bch_alloc_v4));
                return -EINVAL;
        }
 
+       if (rw == WRITE) {
+               if (a.v->cached_sectors &&
+                   !a.v->dirty_sectors &&
+                   !a.v->io_time[READ]) {
+                       pr_buf(err, "cached bucket with read_time == 0");
+                       return -EINVAL;
+               }
+       }
+
        return 0;
 }