[PATCH] gfs2: stop logd and quotad before kill_sb log flush

Jiaming Zhang posted 1 patch 2 weeks, 1 day ago
fs/gfs2/ops_fstype.c | 2 ++
1 file changed, 2 insertions(+)
[PATCH] gfs2: stop logd and quotad before kill_sb log flush
Posted by Jiaming Zhang 2 weeks, 1 day ago
gfs2_kill_sb() issues a synchronous log flush before stopping the gfs2_logd and
gfs2_quotad kthreads. Given a corrupted filesystem image, that flush can spend a
long time while holding sd_log_flush_lock. Since the background threads are
still alive at that point, gfs2_logd can be woken and block on sd_log_flush_lock
in gfs2_logd(), and gfs2_quotad can block on the same lock through
gfs2_statfs_sync() -> __gfs2_trans_begin(). The threads can then remain in
uninterruptible sleep long enough to trigger the hung task.

Stop the background threads before the kill_sb log flush. gfs2_destroy_threads()
waits for both kthreads to exit via kthread_stop_put(), so after it returns
there is no live logd or quotad thread that can wait behind sd_log_flush_lock.

Closes: https://lore.kernel.org/lkml/CANypQFasb8voDrg=O9xJikYHdRFeupb5VP2VeJaZ_wFNMoGr2Q@mail.gmail.com/
Assisted-by: Codex:gpt-5.5-xhigh
Signed-off-by: Jiaming Zhang <r772577952@gmail.com>
---
 fs/gfs2/ops_fstype.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index 9b9e70f14d25..d087845a75d6 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -1776,6 +1776,8 @@ static void gfs2_kill_sb(struct super_block *sb)
 		return;
 	}
 
+	gfs2_destroy_threads(sdp);
+
 	gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_SYNC | GFS2_LFC_KILL_SB);
 	dput(sdp->sd_root_dir);
 	dput(sdp->sd_master_dir);
-- 
2.43.0
Re: [PATCH] gfs2: stop logd and quotad before kill_sb log flush
Posted by Jiaming Zhang 2 days, 17 hours ago
Hi,

Jiaming Zhang <r772577952@gmail.com> 于2026年7月10日周五 17:29写道:
>
> gfs2_kill_sb() issues a synchronous log flush before stopping the gfs2_logd and
> gfs2_quotad kthreads. Given a corrupted filesystem image, that flush can spend a
> long time while holding sd_log_flush_lock. Since the background threads are
> still alive at that point, gfs2_logd can be woken and block on sd_log_flush_lock
> in gfs2_logd(), and gfs2_quotad can block on the same lock through
> gfs2_statfs_sync() -> __gfs2_trans_begin(). The threads can then remain in
> uninterruptible sleep long enough to trigger the hung task.
>
> Stop the background threads before the kill_sb log flush. gfs2_destroy_threads()
> waits for both kthreads to exit via kthread_stop_put(), so after it returns
> there is no live logd or quotad thread that can wait behind sd_log_flush_lock.
>
> Closes: https://lore.kernel.org/lkml/CANypQFasb8voDrg=O9xJikYHdRFeupb5VP2VeJaZ_wFNMoGr2Q@mail.gmail.com/
> Assisted-by: Codex:gpt-5.5-xhigh
> Signed-off-by: Jiaming Zhang <r772577952@gmail.com>
> ---
>  fs/gfs2/ops_fstype.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
> index 9b9e70f14d25..d087845a75d6 100644
> --- a/fs/gfs2/ops_fstype.c
> +++ b/fs/gfs2/ops_fstype.c
> @@ -1776,6 +1776,8 @@ static void gfs2_kill_sb(struct super_block *sb)
>                 return;
>         }
>
> +       gfs2_destroy_threads(sdp);
> +
>         gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_SYNC | GFS2_LFC_KILL_SB);
>         dput(sdp->sd_root_dir);
>         dput(sdp->sd_master_dir);
> --
> 2.43.0
>

Friendly ping. Please let me know if there's anything you'd like me to change.

Best Regards,
Jiaming Zhang