Linux XFS filesystem development
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: Patrick Fischer <patrick.fischer@siedl.net>,
	Andrey Albershteyn <aalbersh@redhat.com>
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH] xfs_scrub_all: fix deadlock if lsblk produces a lot of output
Date: Thu, 30 Apr 2026 08:54:06 -0700	[thread overview]
Message-ID: <20260430155406.GF7751@frogsfrogsfrogs> (raw)

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

Patrick Fischer reported a deadlock in find_mounts() that is the result
of lsblk producing so much output that it fills the pipe buffer.  When
this happens, lsblk blocks on write()ing the pipe, at which point
waiting for lsblk to exit will also block forever.

Now that we can be reasonably assured that everyone has Python 3.5
(because RHEL6 is long dead), we can replace this whole mess with a call
to subprocess.run that captures the output.  The json library can
convert a byte array directly to a python dict, which means we don't
need to concatenate iterated lines or any of that stuff anymore.

Reported-by: patrick.fischer@siedl.net
Link: https://lore.kernel.org/linux-xfs/323580211.1220195.1777554001363.JavaMail.zimbra@siedl.net/
Cc: <linux-xfs@vger.kernel.org> # v4.15.0
Fixes: f1dca11cad1308 ("xfs_scrub: create a script to scrub all xfs filesystems")
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
 scrub/xfs_scrub_all.py.in |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/scrub/xfs_scrub_all.py.in b/scrub/xfs_scrub_all.py.in
index 9f861639a43ce4..dbb6c36e467d3f 100644
--- a/scrub/xfs_scrub_all.py.in
+++ b/scrub/xfs_scrub_all.py.in
@@ -53,15 +53,16 @@ def find_mounts():
 
 	fs = {}
 	cmd=['lsblk', '-o', 'NAME,KNAME,TYPE,FSTYPE,MOUNTPOINT', '-J']
-	result = subprocess.Popen(cmd, stdout=subprocess.PIPE)
-	result.wait()
-	if result.returncode != 0:
+	try:
+		proc = subprocess.run(cmd, capture_output = True, text = True, check = True)
+	except Exception as e:
+		print(e)
+		return fs
+	if proc.returncode != 0:
 		return fs
-	sarray = [x.decode(sys.stdout.encoding) for x in result.stdout.readlines()]
-	output = ' '.join(sarray)
-	bdevdata = json.loads(output)
 
 	# The lsblk output had better be in disks-then-partitions order
+	bdevdata = json.loads(proc.stdout)
 	for bdev in bdevdata['blockdevices']:
 		lastdisk = bdev['kname']
 		find_xfs_mounts(bdev, fs, lastdisk)

             reply	other threads:[~2026-04-30 15:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-30 15:54 Darrick J. Wong [this message]
2026-04-30 16:57 ` [PATCH] xfs_scrub_all: fix deadlock if lsblk produces a lot of output Andrey Albershteyn
2026-05-07  5:35 ` Christoph Hellwig

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=20260430155406.GF7751@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=aalbersh@redhat.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=patrick.fischer@siedl.net \
    /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