linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libxfs: fix crash on second attempt to initialize library
@ 2021-10-05 22:32 Darrick J. Wong
  2021-10-15 20:29 ` Eric Sandeen
  0 siblings, 1 reply; 2+ messages in thread
From: Darrick J. Wong @ 2021-10-05 22:32 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: xfs

From: Darrick J. Wong <djwong@kernel.org>

xfs_repair crashes when it tries to initialize the libxfs library but
the initialization fails because the fs is already mounted:

# xfs_repair /dev/sdd
xfs_repair: /dev/sdd contains a mounted filesystem
xfs_repair: urcu.c:553: urcu_memb_register_thread: Assertion `!URCU_TLS(rcu_reader).registered' failed.
Aborted

This is because libxfs_init() registers the main thread with liburcu,
but doesn't unregister the thread if libxfs library initialization
fails.  When repair sets more dangerous options and tries again, the
second initialization attempt causes liburcu to abort.  Fix this by
unregistering the thread with liburcu if libxfs initialization fails.

Observed by running xfs/284.

Fixes: e4da1b16 ("xfsprogs: introduce liburcu support")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 libxfs/init.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libxfs/init.c b/libxfs/init.c
index d0753ce5..14911596 100644
--- a/libxfs/init.c
+++ b/libxfs/init.c
@@ -407,8 +407,10 @@ libxfs_init(libxfs_init_t *a)
 		unlink(rtpath);
 	if (fd >= 0)
 		close(fd);
-	if (!rval)
+	if (!rval) {
 		libxfs_close_devices(a);
+		rcu_unregister_thread();
+	}
 
 	return rval;
 }

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] libxfs: fix crash on second attempt to initialize library
  2021-10-05 22:32 [PATCH] libxfs: fix crash on second attempt to initialize library Darrick J. Wong
@ 2021-10-15 20:29 ` Eric Sandeen
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Sandeen @ 2021-10-15 20:29 UTC (permalink / raw)
  To: Darrick J. Wong, Eric Sandeen; +Cc: xfs

On 10/5/21 5:32 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> xfs_repair crashes when it tries to initialize the libxfs library but
> the initialization fails because the fs is already mounted:

Sorry for missing this; looks right to me. For some reason I did not hit
it in testing, old library version I guess.

Reviewed-by: Eric Sandeen <sandeen@redhat.com>

> 
> # xfs_repair /dev/sdd
> xfs_repair: /dev/sdd contains a mounted filesystem
> xfs_repair: urcu.c:553: urcu_memb_register_thread: Assertion `!URCU_TLS(rcu_reader).registered' failed.
> Aborted
> 
> This is because libxfs_init() registers the main thread with liburcu,
> but doesn't unregister the thread if libxfs library initialization
> fails.  When repair sets more dangerous options and tries again, the
> second initialization attempt causes liburcu to abort.  Fix this by
> unregistering the thread with liburcu if libxfs initialization fails.
> 
> Observed by running xfs/284.
> 
> Fixes: e4da1b16 ("xfsprogs: introduce liburcu support")
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
>   libxfs/init.c |    4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/libxfs/init.c b/libxfs/init.c
> index d0753ce5..14911596 100644
> --- a/libxfs/init.c
> +++ b/libxfs/init.c
> @@ -407,8 +407,10 @@ libxfs_init(libxfs_init_t *a)
>   		unlink(rtpath);
>   	if (fd >= 0)
>   		close(fd);
> -	if (!rval)
> +	if (!rval) {
>   		libxfs_close_devices(a);
> +		rcu_unregister_thread();
> +	}
>   
>   	return rval;
>   }
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-15 20:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-05 22:32 [PATCH] libxfs: fix crash on second attempt to initialize library Darrick J. Wong
2021-10-15 20:29 ` Eric Sandeen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).