From 11c7d3e8176a2e674faefa9d9d14210f5062326c Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Wed, 6 Apr 2022 17:22:47 -0400 Subject: [PATCH] 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 --- fs/bcachefs/alloc_background.c | 11 +++++++++++ 1 file changed, 11 insertions(+) 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; } -- 2.39.5