summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2022-03-28 18:29:23 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2022-04-17 15:44:28 -0400
commit9cea8ab32ed59cf03266aee16550f30f69fb9888 (patch)
treed71259e12ec9cf52e021b8281037323a3f4a7d7b
parent0c05e238bab290bc15cba9ae514d2f1904ea444f (diff)
bcachefs: Fix for freespace version upgrade path
It's currently possible to end up in a half-upgraded state where we haven't set the superblock to the new version, but we have run the freespace initialization path. Previously, this meant when running fsck on such a filesystem we wouldn't check the freespace btrees - which is a problem, if they have been initialized and there's something fsck needs to check and fix. Fix this by making bch2_check_alloc_info() check if freespace has been initialized on each device, not by making it run conditionally on the superblock version. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
-rw-r--r--fs/bcachefs/alloc_background.c13
-rw-r--r--fs/bcachefs/recovery.c3
2 files changed, 13 insertions, 3 deletions
diff --git a/fs/bcachefs/alloc_background.c b/fs/bcachefs/alloc_background.c
index 0c33424393be..81cbfeb58cd1 100644
--- a/fs/bcachefs/alloc_background.c
+++ b/fs/bcachefs/alloc_background.c
@@ -724,12 +724,23 @@ int bch2_check_alloc_info(struct bch_fs *c, bool initial)
struct btree_trans trans;
struct btree_iter iter;
struct bkey_s_c k;
- int ret = 0;
+ int ret = 0, last_dev = -1;
bch2_trans_init(&trans, c, 0, 0);
for_each_btree_key(&trans, iter, BTREE_ID_alloc, POS_MIN,
BTREE_ITER_PREFETCH, k, ret) {
+ if (k.k->p.inode != last_dev) {
+ struct bch_dev *ca = bch_dev_bkey_exists(c, k.k->p.inode);
+
+ if (!ca->mi.freespace_initialized) {
+ bch2_btree_iter_set_pos(&iter, POS(k.k->p.inode + 1, 0));
+ continue;
+ }
+
+ last_dev = k.k->p.inode;
+ }
+
ret = __bch2_trans_do(&trans, NULL, NULL, 0,
bch2_check_alloc_key(&trans, &iter));
if (ret)
diff --git a/fs/bcachefs/recovery.c b/fs/bcachefs/recovery.c
index 66492dde7930..68612d52aa83 100644
--- a/fs/bcachefs/recovery.c
+++ b/fs/bcachefs/recovery.c
@@ -1174,8 +1174,7 @@ use_clean:
bch_verbose(c, "done checking allocations");
}
- if (c->opts.fsck &&
- c->sb.version >= bcachefs_metadata_version_freespace) {
+ if (c->opts.fsck) {
bch_info(c, "checking need_discard and freespace btrees");
err = "error checking need_discard and freespace btrees";
ret = bch2_check_alloc_info(c, true);