Support auto-assembling of stacked devices
and assorted bugfixes. Signed-off-by: Neil Brown <neilb@suse.de>
This commit is contained in:
parent
2e2642f2c5
commit
d55e3aefc0
20
Assemble.c
20
Assemble.c
|
@ -110,6 +110,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
|
||||||
* START_ARRAY
|
* START_ARRAY
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
int must_close = 0;
|
||||||
int old_linux = 0;
|
int old_linux = 0;
|
||||||
int vers;
|
int vers;
|
||||||
void *first_super = NULL, *super = NULL;
|
void *first_super = NULL, *super = NULL;
|
||||||
|
@ -367,7 +368,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
|
||||||
mdu_array_info_t inf;
|
mdu_array_info_t inf;
|
||||||
char *c;
|
char *c;
|
||||||
if (!first_super) {
|
if (!first_super) {
|
||||||
return 1;
|
return 2;
|
||||||
}
|
}
|
||||||
st->ss->getinfo_super(&info, first_super);
|
st->ss->getinfo_super(&info, first_super);
|
||||||
c = strchr(info.name, ':');
|
c = strchr(info.name, ':');
|
||||||
|
@ -383,6 +384,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
|
||||||
free(first_super);
|
free(first_super);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
must_close = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ok, no bad inconsistancy, we can try updating etc */
|
/* Ok, no bad inconsistancy, we can try updating etc */
|
||||||
|
@ -517,6 +519,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
|
||||||
fprintf(stderr, Name ": no devices found for %s\n",
|
fprintf(stderr, Name ": no devices found for %s\n",
|
||||||
mddev);
|
mddev);
|
||||||
free(first_super);
|
free(first_super);
|
||||||
|
if (must_close) close(mdfd);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -632,18 +635,21 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
|
||||||
if ((fd=dev_open(devices[j].devname, O_RDONLY|O_EXCL))< 0) {
|
if ((fd=dev_open(devices[j].devname, O_RDONLY|O_EXCL))< 0) {
|
||||||
fprintf(stderr, Name ": Cannot open %s: %s\n",
|
fprintf(stderr, Name ": Cannot open %s: %s\n",
|
||||||
devices[j].devname, strerror(errno));
|
devices[j].devname, strerror(errno));
|
||||||
|
if (must_close) close(mdfd);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (st->ss->load_super(st,fd, &super, NULL)) {
|
if (st->ss->load_super(st,fd, &super, NULL)) {
|
||||||
close(fd);
|
close(fd);
|
||||||
fprintf(stderr, Name ": RAID superblock has disappeared from %s\n",
|
fprintf(stderr, Name ": RAID superblock has disappeared from %s\n",
|
||||||
devices[j].devname);
|
devices[j].devname);
|
||||||
|
if (must_close) close(mdfd);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
if (super == NULL) {
|
if (super == NULL) {
|
||||||
fprintf(stderr, Name ": No suitable drives found for %s\n", mddev);
|
fprintf(stderr, Name ": No suitable drives found for %s\n", mddev);
|
||||||
|
if (must_close) close(mdfd);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
st->ss->getinfo_super(&info, super);
|
st->ss->getinfo_super(&info, super);
|
||||||
|
@ -699,12 +705,14 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
fprintf(stderr, Name ": Could not open %s for write - cannot Assemble array.\n",
|
fprintf(stderr, Name ": Could not open %s for write - cannot Assemble array.\n",
|
||||||
devices[chosen_drive].devname);
|
devices[chosen_drive].devname);
|
||||||
|
if (must_close) close(mdfd);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (st->ss->store_super(st, fd, super)) {
|
if (st->ss->store_super(st, fd, super)) {
|
||||||
close(fd);
|
close(fd);
|
||||||
fprintf(stderr, Name ": Could not re-write superblock on %s\n",
|
fprintf(stderr, Name ": Could not re-write superblock on %s\n",
|
||||||
devices[chosen_drive].devname);
|
devices[chosen_drive].devname);
|
||||||
|
if (must_close) close(mdfd);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
@ -739,6 +747,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
|
||||||
}
|
}
|
||||||
if (err) {
|
if (err) {
|
||||||
fprintf(stderr, Name ": Failed to restore critical section for reshape, sorry.\n");
|
fprintf(stderr, Name ": Failed to restore critical section for reshape, sorry.\n");
|
||||||
|
if (must_close) close(mdfd);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -763,11 +772,13 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
|
||||||
if (rv) {
|
if (rv) {
|
||||||
fprintf(stderr, Name ": SET_ARRAY_INFO failed for %s: %s\n",
|
fprintf(stderr, Name ": SET_ARRAY_INFO failed for %s: %s\n",
|
||||||
mddev, strerror(errno));
|
mddev, strerror(errno));
|
||||||
|
if (must_close) close(mdfd);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (ident->bitmap_fd >= 0) {
|
if (ident->bitmap_fd >= 0) {
|
||||||
if (ioctl(mdfd, SET_BITMAP_FILE, ident->bitmap_fd) != 0) {
|
if (ioctl(mdfd, SET_BITMAP_FILE, ident->bitmap_fd) != 0) {
|
||||||
fprintf(stderr, Name ": SET_BITMAP_FILE failed.\n");
|
fprintf(stderr, Name ": SET_BITMAP_FILE failed.\n");
|
||||||
|
if (must_close) close(mdfd);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} else if (ident->bitmap_file) {
|
} else if (ident->bitmap_file) {
|
||||||
|
@ -776,11 +787,13 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
|
||||||
if (bmfd < 0) {
|
if (bmfd < 0) {
|
||||||
fprintf(stderr, Name ": Could not open bitmap file %s\n",
|
fprintf(stderr, Name ": Could not open bitmap file %s\n",
|
||||||
ident->bitmap_file);
|
ident->bitmap_file);
|
||||||
|
if (must_close) close(mdfd);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (ioctl(mdfd, SET_BITMAP_FILE, bmfd) != 0) {
|
if (ioctl(mdfd, SET_BITMAP_FILE, bmfd) != 0) {
|
||||||
fprintf(stderr, Name ": Failed to set bitmapfile for %s\n", mddev);
|
fprintf(stderr, Name ": Failed to set bitmapfile for %s\n", mddev);
|
||||||
close(bmfd);
|
close(bmfd);
|
||||||
|
if (must_close) close(mdfd);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
close(bmfd);
|
close(bmfd);
|
||||||
|
@ -833,10 +846,12 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
|
||||||
fprintf(stderr, " and %d spare%s", sparecnt, sparecnt==1?"":"s");
|
fprintf(stderr, " and %d spare%s", sparecnt, sparecnt==1?"":"s");
|
||||||
fprintf(stderr, ".\n");
|
fprintf(stderr, ".\n");
|
||||||
}
|
}
|
||||||
|
if (must_close) close(mdfd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
fprintf(stderr, Name ": failed to RUN_ARRAY %s: %s\n",
|
fprintf(stderr, Name ": failed to RUN_ARRAY %s: %s\n",
|
||||||
mddev, strerror(errno));
|
mddev, strerror(errno));
|
||||||
|
if (must_close) close(mdfd);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (runstop == -1) {
|
if (runstop == -1) {
|
||||||
|
@ -845,6 +860,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
|
||||||
if (okcnt != info.array.raid_disks)
|
if (okcnt != info.array.raid_disks)
|
||||||
fprintf(stderr, " (out of %d)", info.array.raid_disks);
|
fprintf(stderr, " (out of %d)", info.array.raid_disks);
|
||||||
fprintf(stderr, ", but not started.\n");
|
fprintf(stderr, ", but not started.\n");
|
||||||
|
if (must_close) close(mdfd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (verbose >= 0) {
|
if (verbose >= 0) {
|
||||||
|
@ -861,6 +877,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
|
||||||
fprintf(stderr, " (use --run to insist).\n");
|
fprintf(stderr, " (use --run to insist).\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (must_close) close(mdfd);
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
/* The "chosen_drive" is a good choice, and if necessary, the superblock has
|
/* The "chosen_drive" is a good choice, and if necessary, the superblock has
|
||||||
|
@ -876,5 +893,6 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (must_close) close(mdfd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
30
mdadm.c
30
mdadm.c
|
@ -873,6 +873,8 @@ int main(int argc, char *argv[])
|
||||||
fprintf(stderr, Name ": --super-minor=dev is incompatible with --auto\n");
|
fprintf(stderr, Name ": --super-minor=dev is incompatible with --auto\n");
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
if (mode == MANAGE && runstop < 0)
|
||||||
|
autof=1; /* Don't create */
|
||||||
mdfd = open_mddev(devlist->devname, autof);
|
mdfd = open_mddev(devlist->devname, autof);
|
||||||
if (mdfd < 0)
|
if (mdfd < 0)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
@ -1022,15 +1024,23 @@ int main(int argc, char *argv[])
|
||||||
* until it fails
|
* until it fails
|
||||||
*/
|
*/
|
||||||
int rv2;
|
int rv2;
|
||||||
|
int acnt;
|
||||||
|
ident.autof = autof;
|
||||||
do {
|
do {
|
||||||
ident.autof = autof;
|
acnt = 0;
|
||||||
rv2 = Assemble(ss, NULL, -1,
|
do {
|
||||||
&ident, configfile,
|
rv2 = Assemble(ss, NULL, -1,
|
||||||
devlist, NULL,
|
&ident, configfile,
|
||||||
readonly, runstop, NULL, homehost, verbose-quiet, force);
|
devlist, NULL,
|
||||||
if (rv2==0)
|
readonly, runstop, NULL, homehost, verbose-quiet, force);
|
||||||
cnt++;
|
if (rv2==0) {
|
||||||
} while (rv2==0);
|
cnt++;
|
||||||
|
acnt++;
|
||||||
|
}
|
||||||
|
} while (rv2!=2);
|
||||||
|
/* Incase there are stacked devices, we need to go around again */
|
||||||
|
devlist = conf_get_devs(configfile);
|
||||||
|
} while (acnt);
|
||||||
if (cnt == 0 && rv == 0) {
|
if (cnt == 0 && rv == 0) {
|
||||||
fprintf(stderr, Name ": No arrays found in config file or automatically\n");
|
fprintf(stderr, Name ": No arrays found in config file or automatically\n");
|
||||||
rv = 1;
|
rv = 1;
|
||||||
|
@ -1125,7 +1135,7 @@ int main(int argc, char *argv[])
|
||||||
e->dev);
|
e->dev);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
mdfd = open_mddev(name, 0);
|
mdfd = open_mddev(name, 1);
|
||||||
if (mdfd >= 0) {
|
if (mdfd >= 0) {
|
||||||
if (Manage_runstop(name, mdfd, -1, !last))
|
if (Manage_runstop(name, mdfd, -1, !last))
|
||||||
err = 1;
|
err = 1;
|
||||||
|
@ -1154,7 +1164,7 @@ int main(int argc, char *argv[])
|
||||||
case 'X':
|
case 'X':
|
||||||
rv |= ExamineBitmap(dv->devname, brief, ss); continue;
|
rv |= ExamineBitmap(dv->devname, brief, ss); continue;
|
||||||
}
|
}
|
||||||
mdfd = open_mddev(dv->devname, 0);
|
mdfd = open_mddev(dv->devname, 1);
|
||||||
if (mdfd>=0) {
|
if (mdfd>=0) {
|
||||||
switch(dv->disposition) {
|
switch(dv->disposition) {
|
||||||
case 'R':
|
case 'R':
|
||||||
|
|
2
mdopen.c
2
mdopen.c
|
@ -167,7 +167,7 @@ int open_mddev(char *dev, int autof)
|
||||||
if (ioctl(mdfd, GET_ARRAY_INFO, &array)==0) {
|
if (ioctl(mdfd, GET_ARRAY_INFO, &array)==0) {
|
||||||
/* already active */
|
/* already active */
|
||||||
close(mdfd);
|
close(mdfd);
|
||||||
fprintf(sterr, Name ": %s is alreadyt active.\n",
|
fprintf(stderr, Name ": %s is already active.\n",
|
||||||
dev);
|
dev);
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue