From 1c52b36e3234aedaaa4b467f64c01636e96c1946 Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Thu, 30 Apr 2026 08:54:06 -0700 Subject: [PATCH] xfs_scrub_all: fix deadlock if lsblk produces a lot of output 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: # v4.15.0 Fixes: f1dca11cad1308 ("xfs_scrub: create a script to scrub all xfs filesystems") Signed-off-by: "Darrick J. Wong" Reviewed-by: Andrey Albershteyn --- 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 9f861639..dbb6c36e 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) -- 2.47.3