After mdadm -S /dev/md0, the device node /dev/md0 still exists. The Remove events are generated by md_free() -> del_gendisk() -> blk_unregister_queue(). After calling close(mdfd) the Remove events is generated. We should give udev a little time to handle the event. I tried usleep(100*1000), but the problem still can be reproduced sometime. So I choose to sleep(1). Because after close(mdfd) it can be generated CHANGE events too. So it's ok to choose to sleep(1) to wait udev to handle CHANGE events. Signed-off-by: Xiao Ni <xni@xxxxxxxxxx> --- Create.c | 2 +- mdadm.c | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Create.c b/Create.c index 239545f..24e852e 100644 --- a/Create.c +++ b/Create.c @@ -1054,7 +1054,7 @@ int Create(struct supertype *st, char *mddev, /* Give udev a moment to process the Change event caused * by the close. */ - usleep(100*1000); + sleep(1); udev_unblock(); return 0; diff --git a/mdadm.c b/mdadm.c index 7cdcdba..2905dea 100644 --- a/mdadm.c +++ b/mdadm.c @@ -1734,8 +1734,14 @@ int main(int argc, char *argv[]) autodetect(); break; } - if (mdfd > 0) + + if (mdfd > 0) { close(mdfd); + /* Give udev a moment to process the udev event caused + * by the close. + */ + sleep(1); + } exit(rv); } @@ -1897,6 +1903,10 @@ static int stop_scan(int verbose) else progress = 1; close(mdfd); + /* Give udev a moment to process the Remove event caused + * by the close. + */ + sleep(1); } put_md_name(name); @@ -1997,6 +2007,10 @@ static int misc_list(struct mddev_dev *devlist, break; } close(mdfd); + /* Give udev a moment to process the udev event caused + * by the close. + */ + sleep(1); } else rv |= 1; } -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-raid" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html