gfs2: Flag a withdraw if init_threads() fails
PATCH 1/1 gfs2: Flag a withdraw if init_threads() fails
Interrupting mount with ^C quickly enough can cause the kthread_run() calls in gfs2's init_threads() to fail and the error path leads to a deadlock on the s_umount rwsem. The abridged chain of events is:
[mount path]
get_tree_bdev()
sget_fc()
alloc_super()
down_write_nested(&s->s_umount, SINGLE_DEPTH_NESTING); [acquired]
gfs2_fill_super()
gfs2_make_fs_rw()
init_threads()
kthread_run()
( Interrupted )
[Error path]
gfs2_gl_hash_clear()
flush_workqueue(glock_workqueue)
wait_for_completion() [workqueue context]
glock_work_func()
run_queue()
do_xmote()
freeze_go_sync()
freeze_super()
down_write(&sb->s_umount) [deadlock]In freeze_go_sync() there is a gfs2_withdrawn() check that we can use to make sure freeze_super() is not called in the error path, so add a gfs2_withdraw_delayed() call when init_threads() fails.
Ref: https://bugzilla.kernel.org/show_bug.cgi?id=212231
--- fs/gfs2/super.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/gfs2/super.c +3 -1
@@ -162,8 +162,10 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp)int error; error =init_threads (sdp); -if (error) +if (error) { +gfs2_withdraw_delayed (sdp);return error; + } j_gl->gl_ops->go_inval (j_gl,DIO_METADATA );if (gfs2_withdrawn (sdp)) {
Signature · 1 line
2.29.2
Andreas Gruenbacher
maintainerPATCH 1/1 gfs2: Flag a withdraw if init_threads() fails
Quoted 44 lines · Andrew Price
Interrupting mount with ^C quickly enough can cause the
kthread_run()calls in gfs2'sinit_threads()to fail and the error path leads to a deadlock on thes_umountrwsem. The abridged chain of events is:[mount path]
get_tree_bdev()sget_fc() alloc_super() down_write_nested(&s->s_umount, SINGLE_DEPTH_NESTING); [acquired] gfs2_fill_super() gfs2_make_fs_rw() init_threads() kthread_run() ( Interrupted ) [Error path] gfs2_gl_hash_clear() flush_workqueue(glock_workqueue) wait_for_completion()[workqueue context]
glock_work_func()run_queue() do_xmote() freeze_go_sync() freeze_super() down_write(&sb->s_umount) [deadlock]In
freeze_go_sync()there is agfs2_withdrawn()check that we can use to make surefreeze_super()is not called in the error path, so add agfs2_withdraw_delayed()call wheninit_threads()fails.Ref: https://bugzilla.kernel.org/show_bug.cgi?id=212231
Reported-by Alexander Aring <[email protected]>Signed-off-by Andrew Price <[email protected]>--- fs/gfs2/super.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/gfs2/super.c +0
-0
fs/gfs2/super.c int gfs2_make_fs_rw(struct gfs2_sbd *sdp) · line 166
Quoted 6 lines
fs/gfs2/super.c +2
-1@@ -162,8 +162,10 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp)int error; error =init_threads (sdp); -if (error) +if (error) { +gfs2_withdraw_delayed (sdp);
Hmm, marking the filesystem as withdrawing before we've even started looks a bit odd, but given that we're already checking for withdrawing / withdrawn filesystems all over the place, it should be okay. I'll push this to for-next.
Quoted 7 lines
fs/gfs2/super.c +1
-1return error; + } j_gl->gl_ops->go_inval (j_gl,DIO_METADATA );if (gfs2_withdrawn (sdp)) { --2.29.2
Thanks,
Andreas
PATCH 1/1 gfs2: Flag a withdraw if init_threads() fails
Quoted 47 lines · Andreas Gruenbacher
Quoted 46 lines · Andrew Price
Interrupting mount with ^C quickly enough can cause the
kthread_run()calls in gfs2'sinit_threads()to fail and the error path leads to a deadlock on thes_umountrwsem. The abridged chain of events is:[mount path] get_tree_bdev() sget_fc() alloc_super() down_write_nested(&s->s_umount, SINGLE_DEPTH_NESTING); [acquired] gfs2_fill_super() gfs2_make_fs_rw() init_threads() kthread_run() ( Interrupted ) [Error path] gfs2_gl_hash_clear() flush_workqueue(glock_workqueue) wait_for_completion() [workqueue context] glock_work_func() run_queue() do_xmote() freeze_go_sync() freeze_super() down_write(&sb->s_umount) [deadlock]In
freeze_go_sync()there is agfs2_withdrawn()check that we can use to make surefreeze_super()is not called in the error path, so add agfs2_withdraw_delayed()call wheninit_threads()fails.Ref: https://bugzilla.kernel.org/show_bug.cgi?id=212231
Reported-by Alexander Aring <[email protected]>Signed-off-by Andrew Price <[email protected]>--- fs/gfs2/super.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)fs/gfs2/super.c +0
-0@@ -162,8 +162,10 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp)int error;
Quoted 7 lines
fs/gfs2/super.c int gfs2_make_fs_rw(struct gfs2_sbd *sdp) · line 166
Quoted 4 lines
fs/gfs2/super.c +2
-1error =init_threads (sdp); -if (error) +if (error) { +gfs2_withdraw_delayed (sdp);Hmm, marking the filesystem as withdrawing before we've even started looks a bit odd,
I agree, it's not elegant. I'm not confident that I understand why there is work queued to freeze the fs at this point but this is the cleanest way I can think of to prevent that right now. Perhaps we can come up with something better.
Andy
Quoted 15 lines
but given that we're already checking for withdrawing
/ withdrawn filesystems all over the place, it should be okay. I'll push this to for-next.Quoted 7 lines
fs/gfs2/super.c +1
-1return error; + } j_gl->gl_ops->go_inval (j_gl,DIO_METADATA );if (gfs2_withdrawn (sdp)) { --2.29.2
Thanks,
Andreas