]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: bch2_btree_lost_data() now uses run_explicit_rceovery_pass_persistent()
authorKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Sep 2024 03:40:01 +0000 (23:40 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 21 Dec 2024 06:36:15 +0000 (01:36 -0500)
Also get a bit more fine grained about which passes to run for which
btrees.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/recovery.c
fs/bcachefs/recovery.h
fs/bcachefs/recovery_passes.c
fs/bcachefs/recovery_passes.h

index 3c7f941dde39ad5fc934c57ff099865a394b0112..b1c83e72c0d8f300ddbd44dc493ba434ebaadab2 100644 (file)
 
 #define QSTR(n) { { { .len = strlen(n) } }, .name = n }
 
-void bch2_btree_lost_data(struct bch_fs *c, enum btree_id btree)
+int bch2_btree_lost_data(struct bch_fs *c, enum btree_id btree)
 {
-       if (btree >= BTREE_ID_NR_MAX)
-               return;
-
        u64 b = BIT_ULL(btree);
+       int ret = 0;
+
+       mutex_lock(&c->sb_lock);
 
        if (!(c->sb.btrees_lost_data & b)) {
                bch_err(c, "flagging btree %s lost data", bch2_btree_id_str(btree));
-
-               mutex_lock(&c->sb_lock);
                bch2_sb_field_get(c->disk_sb.sb, ext)->btrees_lost_data |= cpu_to_le64(b);
-               bch2_write_super(c);
-               mutex_unlock(&c->sb_lock);
        }
+
+       switch (btree) {
+       case BTREE_ID_alloc:
+               ret = bch2_run_explicit_recovery_pass_persistent_locked(c, BCH_RECOVERY_PASS_check_allocations) ?: ret;
+               ret = bch2_run_explicit_recovery_pass_persistent_locked(c, BCH_RECOVERY_PASS_check_alloc_info) ?: ret;
+               goto out;
+       case BTREE_ID_backpointers:
+               ret = bch2_run_explicit_recovery_pass_persistent_locked(c, BCH_RECOVERY_PASS_check_btree_backpointers) ?: ret;
+               ret = bch2_run_explicit_recovery_pass_persistent_locked(c, BCH_RECOVERY_PASS_check_extents_to_backpointers) ?: ret;
+               goto out;
+       case BTREE_ID_need_discard:
+               ret = bch2_run_explicit_recovery_pass_persistent_locked(c, BCH_RECOVERY_PASS_check_alloc_info) ?: ret;
+               goto out;
+       case BTREE_ID_freespace:
+               ret = bch2_run_explicit_recovery_pass_persistent_locked(c, BCH_RECOVERY_PASS_check_alloc_info) ?: ret;
+               goto out;
+       case BTREE_ID_bucket_gens:
+               ret = bch2_run_explicit_recovery_pass_persistent_locked(c, BCH_RECOVERY_PASS_check_alloc_info) ?: ret;
+               goto out;
+       case BTREE_ID_lru:
+               ret = bch2_run_explicit_recovery_pass_persistent_locked(c, BCH_RECOVERY_PASS_check_alloc_info) ?: ret;
+               goto out;
+       case BTREE_ID_accounting:
+               ret = bch2_run_explicit_recovery_pass_persistent_locked(c, BCH_RECOVERY_PASS_check_allocations) ?: ret;
+               goto out;
+       default:
+               ret = bch2_run_explicit_recovery_pass_persistent_locked(c, BCH_RECOVERY_PASS_scan_for_btree_nodes) ?: ret;
+               ret = bch2_run_explicit_recovery_pass_persistent_locked(c, BCH_RECOVERY_PASS_check_topology) ?: ret;
+               goto out;
+       }
+out:
+       bch2_write_super(c);
+       mutex_unlock(&c->sb_lock);
+
+       return ret;
 }
 
 /* for -o reconstruct_alloc: */
@@ -524,22 +555,10 @@ static int read_btree_roots(struct bch_fs *c)
                                        c, btree_root_read_error,
                                        "error reading btree root %s l=%u: %s",
                                        bch2_btree_id_str(i), r->level, bch2_err_str(ret))) {
-                       if (btree_id_is_alloc(i)) {
-                               c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_check_allocations);
-                               c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_check_alloc_info);
-                               c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_check_lrus);
-                               c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_check_extents_to_backpointers);
-                               c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_check_alloc_to_lru_refs);
-                               c->sb.compat &= ~(1ULL << BCH_COMPAT_alloc_info);
+                       if (btree_id_is_alloc(i))
                                r->error = 0;
-                       } else if (!(c->opts.recovery_passes & BIT_ULL(BCH_RECOVERY_PASS_scan_for_btree_nodes))) {
-                               bch_info(c, "will run btree node scan");
-                               c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_scan_for_btree_nodes);
-                               c->opts.recovery_passes |= BIT_ULL(BCH_RECOVERY_PASS_check_topology);
-                       }
 
-                       ret = 0;
-                       bch2_btree_lost_data(c, i);
+                       ret = bch2_btree_lost_data(c, i);
                }
        }
 
index 4bf818de1f2feb1f6010eaff3a8eccbbf1e6d2c6..b0d55754b21b98f93f8c221417dbaeb60fcc1fd4 100644 (file)
@@ -2,7 +2,7 @@
 #ifndef _BCACHEFS_RECOVERY_H
 #define _BCACHEFS_RECOVERY_H
 
-void bch2_btree_lost_data(struct bch_fs *, enum btree_id);
+int bch2_btree_lost_data(struct bch_fs *, enum btree_id);
 
 int bch2_journal_replay(struct bch_fs *);
 
index 5e7722cc0879a9579ab10c862f5ff1e38ac035fc..1240c5c19feaae2cfbb93b7a6826b4ae6190a0ef 100644 (file)
@@ -141,6 +141,17 @@ int bch2_run_explicit_recovery_pass(struct bch_fs *c,
        return ret;
 }
 
+int bch2_run_explicit_recovery_pass_persistent_locked(struct bch_fs *c,
+                                              enum bch_recovery_pass pass)
+{
+       lockdep_assert_held(&c->sb_lock);
+
+       struct bch_sb_field_ext *ext = bch2_sb_field_get(c->disk_sb.sb, ext);
+       __set_bit_le64(bch2_recovery_pass_to_stable(pass), ext->recovery_passes_required);
+
+       return bch2_run_explicit_recovery_pass(c, pass);
+}
+
 int bch2_run_explicit_recovery_pass_persistent(struct bch_fs *c,
                                               enum bch_recovery_pass pass)
 {
index 99b464e127b80b69c11a6955df564a60b836639b..7d7339c8fa294ffca6d5d41510866b835015ea1b 100644 (file)
@@ -9,6 +9,7 @@ u64 bch2_recovery_passes_from_stable(u64 v);
 u64 bch2_fsck_recovery_passes(void);
 
 int bch2_run_explicit_recovery_pass(struct bch_fs *, enum bch_recovery_pass);
+int bch2_run_explicit_recovery_pass_persistent_locked(struct bch_fs *, enum bch_recovery_pass);
 int bch2_run_explicit_recovery_pass_persistent(struct bch_fs *, enum bch_recovery_pass);
 
 int bch2_run_online_recovery_passes(struct bch_fs *);