]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_copy: don't hang if /all/ the targets hit write errors
authorDarrick J. Wong <darrick.wong@oracle.com>
Mon, 20 Nov 2017 19:53:56 +0000 (13:53 -0600)
committerEric Sandeen <sandeen@redhat.com>
Mon, 20 Nov 2017 19:53:56 +0000 (13:53 -0600)
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 <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
copy/xfs_copy.c

index 33e05dfd36a1253546ca54aedf08bb934f0bac14..fb37375db051a45cc3a00c9076a5c5382c21bf8a 100644 (file)
@@ -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);