Linux RAID subsystem development
 help / color / mirror / Atom feed
* [PATCH] mdadm: fix hang when fork fails
@ 2026-10-27 13:58 Abd-Alrhman Masalkhi
  0 siblings, 0 replies; only message in thread
From: Abd-Alrhman Masalkhi @ 2026-10-27 13:58 UTC (permalink / raw)
  To: blazej.kucman, mtkaczyk, ncroxon, xni, song, yukuai
  Cc: linux-raid, Abd-Alrhman Masalkhi

write_zeroes_fork() may return a negative value if the fork fails.
Currently, this value is stored directly in the zero_pids array,
causing wait_zero_forks() to hang while waiting for a child that
failed to fork.

wait_zero_forks() counts children based on non-zero entries in
zero_pids, so the negative return value is incorrectly treated as
a valid child process.

Fixes: 577fd10486d8 ("mdadm: Add --write-zeros option for Create")
Signed-off-by: Abd-Alrhman Masalkhi <abd.masalkhi@gmail.com>
---
 Create.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/Create.c b/Create.c
index 85c23d830272..4b8aac90c0b6 100644
--- a/Create.c
+++ b/Create.c
@@ -304,12 +304,15 @@ static int add_disk_to_super(int mdfd, struct shape *s, struct context *c,
 	st->ss->getinfo_super(st, info, NULL);
 
 	if (fd >= 0 && s->write_zeroes) {
-		*zero_pid = write_zeroes_fork(fd, s, st, dv);
-		if (*zero_pid <= 0) {
+		pid_t pid;
+
+		pid = write_zeroes_fork(fd, s, st, dv);
+		if (pid <= 0) {
 			ioctl(mdfd, STOP_ARRAY, NULL);
 			close(fd);
 			return 1;
 		}
+		*zero_pid = pid;
 	}
 
 	if (have_container && c->verbose > 0)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-27 13:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-27 13:58 [PATCH] mdadm: fix hang when fork fails Abd-Alrhman Masalkhi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox