summaryrefslogtreecommitdiff
path: root/fs/bcachefs/buckets.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-04-05 20:44:18 +0300
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-23 00:09:30 +0300
commite1effd42a1cb40048002f594c12e823b5e33ed5d (patch)
tree24af42ba8fc1021eebfceb6896c14132d6edb635 /fs/bcachefs/buckets.c
parentafb6f7f61ba38f4d4d96e8d1bf5fb9e7809e6c10 (diff)
downloadlinux-e1effd42a1cb40048002f594c12e823b5e33ed5d.tar.xz
bcachefs: More improvements for alloc info checks
- Move checks for whether the device & bucket are valid from the .key_invalid method to bch2_check_alloc_key(). This is because .key_invalid() is called on keys that may no longer exist (post journal replay), which is a problem when removing/resizing devices. - We weren't checking the need_discard btree to ensure that every set bucket has a corresponding alloc key. This refactors the code for checking the freespace btree, so that it now checks both. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Diffstat (limited to 'fs/bcachefs/buckets.c')
-rw-r--r--fs/bcachefs/buckets.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/fs/bcachefs/buckets.c b/fs/bcachefs/buckets.c
index 5b78e8f983a1..31720093de45 100644
--- a/fs/bcachefs/buckets.c
+++ b/fs/bcachefs/buckets.c
@@ -511,14 +511,9 @@ int bch2_mark_alloc(struct btree_trans *trans,
u64 journal_seq = trans->journal_res.seq;
struct bch_fs *c = trans->c;
struct bch_alloc_v4 old_a, new_a;
- struct bch_dev *ca = bch_dev_bkey_exists(c, new.k->p.inode);
+ struct bch_dev *ca;
int ret = 0;
- if (bch2_trans_inconsistent_on(new.k->p.offset < ca->mi.first_bucket ||
- new.k->p.offset >= ca->mi.nbuckets, trans,
- "alloc key outside range of device's buckets"))
- return -EIO;
-
/*
* alloc btree is read in by bch2_alloc_read, not gc:
*/
@@ -526,6 +521,12 @@ int bch2_mark_alloc(struct btree_trans *trans,
!(flags & BTREE_TRIGGER_BUCKET_INVALIDATE))
return 0;
+ if (bch2_trans_inconsistent_on(!bch2_dev_bucket_exists(c, new.k->p), trans,
+ "alloc key for invalid device or bucket"))
+ return -EIO;
+
+ ca = bch_dev_bkey_exists(c, new.k->p.inode);
+
bch2_alloc_to_v4(old, &old_a);
bch2_alloc_to_v4(new, &new_a);