linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Eric Sandeen <sandeen@redhat.com>
Cc: xfs <linux-xfs@vger.kernel.org>, djwong@kernel.org
Subject: [PATCH for 4.14] xfs_copy: don't hang if /all/ the targets hit write errors
Date: Wed, 15 Nov 2017 17:14:27 -0800	[thread overview]
Message-ID: <20171116011232.GG5119@magnolia> (raw)

From: Darrick J. Wong <darrick.wong@oracle.com>

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>
---
 copy/xfs_copy.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c
index 33e05df..fb37375 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);

             reply	other threads:[~2017-11-16  1:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-16  1:14 Darrick J. Wong [this message]
2017-11-16 21:10 ` [PATCH for 4.14] xfs_copy: don't hang if /all/ the targets hit write errors Eric Sandeen
2017-11-17  3:45   ` Darrick J. Wong
2017-11-17  4:48     ` Darrick J. Wong
2017-11-17  5:05       ` Eric Sandeen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171116011232.GG5119@magnolia \
    --to=djwong@kernel.org \
    --cc=darrick.wong@oracle.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).