From 255c38f87394bc38b0e35b60627f7cb26a4a80bb Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Mon, 20 Nov 2017 13:53:56 -0600 Subject: [PATCH] xfs_copy: don't hang if /all/ the targets hit write errors If xfs_copy is told to copy a filesystem and /all/ the writer threads hit an write error, there won't be any threads to unlock mainwait, which means that write_wbuf will deadlock with itself trying to lock mainwait. Therefore, if we discover that all the writer threads are dead, just bail out. Discovered by running xfs/073 with a tiny test device. Signed-off-by: Darrick J. Wong Reviewed-by: Eric Sandeen Signed-off-by: Eric Sandeen --- copy/xfs_copy.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c index 33e05dfd3..fb37375db 100644 --- a/copy/xfs_copy.c +++ b/copy/xfs_copy.c @@ -476,6 +476,7 @@ void write_wbuf(void) { int i; + int badness = 0; /* verify target threads */ for (i = 0; i < num_targets; i++) @@ -486,6 +487,17 @@ write_wbuf(void) for (i = 0; i < num_targets; i++) if (target[i].state != INACTIVE) pthread_mutex_unlock(&targ[i].wait); /* wake up */ + else + badness++; + + /* + * If all the targets are inactive then there won't be any io + * threads left to release mainwait. We're screwed, so bail out. + */ + if (badness == num_targets) { + check_errors(); + exit(1); + } signal_maskfunc(SIGCHLD, SIG_UNBLOCK); pthread_mutex_lock(&mainwait); -- 2.47.2