Wait for name to appear after create/assemble etc.

We don't really want mdadm to exit until udev has
created the names in /dev.  So wait.

Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
NeilBrown 2008-11-04 21:56:42 +11:00
parent 195254b87a
commit a714580e02
6 changed files with 23 additions and 3 deletions

View File

@ -1216,6 +1216,10 @@ int assemble_container_content(struct supertype *st, int mdfd,
/* Nothing new, don't try to start */ ;
else if (runstop > 0 ||
(working + preexist) >= content->array.working_disks) {
map_update(&map, fd2devnum(mdfd),
content->text_version,
content->uuid, chosen_name);
switch(content->array.level) {
case LEVEL_LINEAR:
case LEVEL_MULTIPATH:
@ -1241,6 +1245,7 @@ int assemble_container_content(struct supertype *st, int mdfd,
fprintf(stderr, " (%d new)", working);
fprintf(stderr, "\n");
}
wait_for(chosen_name);
/* FIXME should have an O_EXCL and wait for read-auto */
} else
if (verbose >= 0)
@ -1248,9 +1253,6 @@ int assemble_container_content(struct supertype *st, int mdfd,
": %s assembled with %d devices but "
"not started\n",
chosen_name, working);
map_update(&map, fd2devnum(mdfd),
content->text_version,
content->uuid, chosen_name);
return 0;
}

View File

@ -124,6 +124,7 @@ int Build(char *mddev, int chunk, int level, int layout,
map_unlock(&map);
return 1;
}
mddev = chosen_name;
map_update(&map, fd2devnum(mdfd), "none", uuid, chosen_name);
map_unlock(&map);
@ -281,6 +282,7 @@ int Build(char *mddev, int chunk, int level, int layout,
fprintf(stderr, Name ": array %s built and started.\n",
mddev);
close(mdfd);
wait_for(mddev);
return 0;
abort:

View File

@ -784,6 +784,7 @@ int Create(struct supertype *st, char *mddev,
fprintf(stderr, Name ": not starting array - not enough devices.\n");
}
close(mdfd);
wait_for(chosen_name);
return 0;
abort:

View File

@ -390,6 +390,7 @@ int Incremental(char *devname, int verbose, int runstop,
fprintf(stderr, Name
": container %s now has %d devices\n",
chosen_name, info.array.working_disks);
wait_for(chosen_name);
return Incremental(chosen_name, verbose, runstop,
NULL, homehost, autof);
}
@ -461,6 +462,7 @@ int Incremental(char *devname, int verbose, int runstop,
": %s attached to %s, which has been started.\n",
devname, chosen_name);
rv = 0;
wait_for(chosen_name);
} else {
fprintf(stderr, Name
": %s attached to %s, but failed to start: %s.\n",

View File

@ -646,6 +646,7 @@ extern struct supertype *dup_super(struct supertype *st);
extern int get_dev_size(int fd, char *dname, unsigned long long *sizep);
extern void get_one_disk(int mdfd, mdu_array_info_t *ainf,
mdu_disk_info_t *disk);
void wait_for(char *dev);
#if __GNUC__ < 3
struct stat64;

12
util.c
View File

@ -842,6 +842,18 @@ int same_dev(char *one, char *two)
return st1.st_rdev == st2.st_rdev;
}
void wait_for(char *dev)
{
int i;
for (i=0 ; i<25 ; i++) {
struct stat stb;
if (stat(dev, &stb) == 0)
return;
usleep(200000);
}
}
struct superswitch *superlist[] = { &super0, &super1, &super_ddf, &super_imsm, NULL };
#if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO)