* [PATCH] xfs_scrub_all: fix deadlock if lsblk produces a lot of output
@ 2026-04-30 15:54 Darrick J. Wong
2026-04-30 16:57 ` Andrey Albershteyn
2026-05-07 5:35 ` Christoph Hellwig
0 siblings, 2 replies; 3+ messages in thread
From: Darrick J. Wong @ 2026-04-30 15:54 UTC (permalink / raw)
To: Patrick Fischer, Andrey Albershteyn; +Cc: linux-xfs
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)
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] xfs_scrub_all: fix deadlock if lsblk produces a lot of output
2026-04-30 15:54 [PATCH] xfs_scrub_all: fix deadlock if lsblk produces a lot of output Darrick J. Wong
@ 2026-04-30 16:57 ` Andrey Albershteyn
2026-05-07 5:35 ` Christoph Hellwig
1 sibling, 0 replies; 3+ messages in thread
From: Andrey Albershteyn @ 2026-04-30 16:57 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: Patrick Fischer, Andrey Albershteyn, linux-xfs
On 2026-04-30 08:54:06, Darrick J. Wong wrote:
> 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>
Looks good to me
Reviewed-by: Andrey Albershteyn <aalbersh@kernel.org>
--
- Andrey
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] xfs_scrub_all: fix deadlock if lsblk produces a lot of output
2026-04-30 15:54 [PATCH] xfs_scrub_all: fix deadlock if lsblk produces a lot of output Darrick J. Wong
2026-04-30 16:57 ` Andrey Albershteyn
@ 2026-05-07 5:35 ` Christoph Hellwig
1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2026-05-07 5:35 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: Patrick Fischer, Andrey Albershteyn, linux-xfs
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-07 5:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-30 15:54 [PATCH] xfs_scrub_all: fix deadlock if lsblk produces a lot of output Darrick J. Wong
2026-04-30 16:57 ` Andrey Albershteyn
2026-05-07 5:35 ` Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox