mdadm: fix hang when fork fails
PATCH 1/1 mdadm: fix hang when fork fails
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 <[email protected]>
--- Create.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
Create.c +5 -2
@@ -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 )
Signature · 1 line
2.43.0