From: Kent Overstreet Date: Wed, 6 Apr 2022 21:22:47 +0000 (-0400) Subject: bcachefs: Check for read_time == 0 in bch2_alloc_v4_invalid() X-Git-Tag: v6.7-rc1~201^2~1004 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=11c7d3e8176a2e674faefa9d9d14210f5062326c;p=thirdparty%2Fkernel%2Flinux.git bcachefs: Check for read_time == 0 in bch2_alloc_v4_invalid() 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 --- diff --git a/fs/bcachefs/alloc_background.c b/fs/bcachefs/alloc_background.c index cad39119949ad..f030030a8b503 100644 --- a/fs/bcachefs/alloc_background.c +++ b/fs/bcachefs/alloc_background.c @@ -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; }