From 001c1d146f38620d6d969b66421460a5d8fd966d Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Fri, 9 May 2025 23:22:23 -0400 Subject: [PATCH] bcachefs: online_fsck_mutex -> run_recovery_passes_lock Prep work for automatically running recovery passes asynchronously. Signed-off-by: Kent Overstreet --- fs/bcachefs/bcachefs.h | 2 +- fs/bcachefs/fsck.c | 6 +++--- fs/bcachefs/recovery_passes.c | 8 ++++++++ fs/bcachefs/recovery_passes.h | 2 ++ fs/bcachefs/super.c | 4 ++-- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h index b4209e270712..5392a0ec6439 100644 --- a/fs/bcachefs/bcachefs.h +++ b/fs/bcachefs/bcachefs.h @@ -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; diff --git a/fs/bcachefs/fsck.c b/fs/bcachefs/fsck.c index 942a03d06074..7c10325a1fac 100644 --- a/fs/bcachefs/fsck.c +++ b/fs/bcachefs/fsck.c @@ -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; diff --git a/fs/bcachefs/recovery_passes.c b/fs/bcachefs/recovery_passes.c index 4da3f6463db8..5f2bd8c10ce6 100644 --- a/fs/bcachefs/recovery_passes.c +++ b/fs/bcachefs/recovery_passes.c @@ -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); +} diff --git a/fs/bcachefs/recovery_passes.h b/fs/bcachefs/recovery_passes.h index d39856f908da..4c03472be5b9 100644 --- a/fs/bcachefs/recovery_passes.h +++ b/fs/bcachefs/recovery_passes.h @@ -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 */ diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c index 77b834cfe126..95ed5ab541d3 100644 --- a/fs/bcachefs/super.c +++ b/fs/bcachefs/super.c @@ -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); -- 2.25.1