]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bcachefs: online_fsck_mutex -> run_recovery_passes_lock
authorKent Overstreet <kent.overstreet@linux.dev>
Sat, 10 May 2025 03:22:23 +0000 (23:22 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 22 May 2025 00:14:53 +0000 (20:14 -0400)
Prep work for automatically running recovery passes asynchronously.

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

index b4209e270712947bd11363d9aabb2e1dd7fec076..5392a0ec6439cbdc69809a72bb5efbe9f76825bd 100644 (file)
@@ -1128,7 +1128,7 @@ struct bch_fs {
        /* never rewinds version of curr_recovery_pass */
        enum bch_recovery_pass  recovery_pass_done;
        spinlock_t              recovery_pass_lock;
-       struct semaphore        online_fsck_mutex;
+       struct semaphore        run_recovery_passes_lock;
 
        /* DEBUG JUNK */
        struct dentry           *fs_debug_dir;
index 942a03d060743c32cc7ec1bd85fdb2cb6c347369..7c10325a1facbb2bca6fdb8e53b33d50a5a40879 100644 (file)
@@ -3204,7 +3204,7 @@ static int bch2_fsck_online_thread_fn(struct thread_with_stdio *stdio)
        c->stdio_filter = NULL;
        c->opts.fix_errors = old_fix_errors;
 
-       up(&c->online_fsck_mutex);
+       up(&c->run_recovery_passes_lock);
        bch2_ro_ref_put(c);
        return ret;
 }
@@ -3228,7 +3228,7 @@ long bch2_ioctl_fsck_online(struct bch_fs *c, struct bch_ioctl_fsck_online arg)
        if (!bch2_ro_ref_tryget(c))
                return -EROFS;
 
-       if (down_trylock(&c->online_fsck_mutex)) {
+       if (down_trylock(&c->run_recovery_passes_lock)) {
                bch2_ro_ref_put(c);
                return -EAGAIN;
        }
@@ -3260,7 +3260,7 @@ err:
                bch_err_fn(c, ret);
                if (thr)
                        bch2_fsck_thread_exit(&thr->thr);
-               up(&c->online_fsck_mutex);
+               up(&c->run_recovery_passes_lock);
                bch2_ro_ref_put(c);
        }
        return ret;
index 4da3f6463db89c7b41d4f48561a1f86cbc5c7a0a..5f2bd8c10ce628e20f870ee9cbc4b19fa593e5da 100644 (file)
@@ -380,6 +380,7 @@ int bch2_run_recovery_passes(struct bch_fs *c)
         */
        c->opts.recovery_passes_exclude &= ~BCH_RECOVERY_PASS_set_may_go_rw;
 
+       down(&c->run_recovery_passes_lock);
        spin_lock_irq(&c->recovery_pass_lock);
 
        while (c->curr_recovery_pass < ARRAY_SIZE(recovery_pass_fns) && !ret) {
@@ -423,6 +424,13 @@ int bch2_run_recovery_passes(struct bch_fs *c)
        }
 
        spin_unlock_irq(&c->recovery_pass_lock);
+       up(&c->run_recovery_passes_lock);
 
        return ret;
 }
+
+void bch2_fs_recovery_passes_init(struct bch_fs *c)
+{
+       spin_lock_init(&c->recovery_pass_lock);
+       sema_init(&c->run_recovery_passes_lock, 1);
+}
index d39856f908da4535ae750502560e359b42c06401..4c03472be5b903351d63f99fed4b7d8ae1290199 100644 (file)
@@ -20,4 +20,6 @@ int bch2_run_explicit_recovery_pass_persistent(struct bch_fs *, struct printbuf
 int bch2_run_online_recovery_passes(struct bch_fs *);
 int bch2_run_recovery_passes(struct bch_fs *);
 
+void bch2_fs_recovery_passes_init(struct bch_fs *);
+
 #endif /* _BCACHEFS_RECOVERY_PASSES_H */
index 77b834cfe12645b323b68f0e6f92dcdcc65c6ad5..95ed5ab541d36d654a3c663423444569f1be07aa 100644 (file)
@@ -51,6 +51,7 @@
 #include "quota.h"
 #include "rebalance.h"
 #include "recovery.h"
+#include "recovery_passes.h"
 #include "replicas.h"
 #include "sb-clean.h"
 #include "sb-counters.h"
@@ -848,8 +849,6 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts *opts,
 
        refcount_set(&c->ro_ref, 1);
        init_waitqueue_head(&c->ro_ref_wait);
-       spin_lock_init(&c->recovery_pass_lock);
-       sema_init(&c->online_fsck_mutex, 1);
 
        for (i = 0; i < BCH_TIME_STAT_NR; i++)
                bch2_time_stats_init(&c->times[i]);
@@ -869,6 +868,7 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts *opts,
        bch2_fs_move_init(c);
        bch2_fs_nocow_locking_init_early(c);
        bch2_fs_quota_init(c);
+       bch2_fs_recovery_passes_init(c);
        bch2_fs_sb_errors_init_early(c);
        bch2_fs_snapshots_init_early(c);
        bch2_fs_subvolumes_init_early(c);