Linux RAID subsystem development
 help / color / mirror / Atom feed
From: Abd-Alrhman Masalkhi <abd.masalkhi@gmail.com>
To: blazej.kucman@graidtech.com, mtkaczyk@kernel.org,
	ncroxon@redhat.com, xni@redhat.com, song@kernel.org,
	yukuai@kernel.org
Cc: linux-raid@vger.kernel.org,
	Abd-Alrhman Masalkhi <abd.masalkhi@gmail.com>
Subject: [PATCH] mdadm: fix hang when fork fails
Date: Tue, 27 Oct 2026 13:58:08 +0000	[thread overview]
Message-ID: <20261027135808.243274-1-abd.masalkhi@gmail.com> (raw)

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


                 reply	other threads:[~2026-10-27 13:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261027135808.243274-1-abd.masalkhi@gmail.com \
    --to=abd.masalkhi@gmail.com \
    --cc=blazej.kucman@graidtech.com \
    --cc=linux-raid@vger.kernel.org \
    --cc=mtkaczyk@kernel.org \
    --cc=ncroxon@redhat.com \
    --cc=song@kernel.org \
    --cc=xni@redhat.com \
    --cc=yukuai@kernel.org \
    /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