]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libxfs: fix crash on second attempt to initialize library
authorDarrick J. Wong <djwong@kernel.org>
Fri, 15 Oct 2021 20:28:14 +0000 (16:28 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Fri, 15 Oct 2021 20:28:14 +0000 (16:28 -0400)
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>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/init.c

index d0753ce5edf6f4e151eacd7014285cd90b794da7..14911596c7701b68d143a7b6594e3c19f34c7b35 100644 (file)
@@ -407,8 +407,10 @@ done:
                unlink(rtpath);
        if (fd >= 0)
                close(fd);
-       if (!rval)
+       if (!rval) {
                libxfs_close_devices(a);
+               rcu_unregister_thread();
+       }
 
        return rval;
 }