summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Brown <neilb@suse.de>2006-05-26 03:11:57 +0000
committerNeil Brown <neilb@suse.de>2006-05-26 03:11:57 +0000
commitd55e3aefc00b6762338c2676934c3bb19ed4da4b (patch)
tree45102805b14aa19157e0b8bd9411d1d0f2390e97
parent2e2642f2c530369ff4f905932860681a48ca4d22 (diff)
downloadmdadm-d55e3aefc00b6762338c2676934c3bb19ed4da4b.tar.gz
mdadm-d55e3aefc00b6762338c2676934c3bb19ed4da4b.tar.xz
mdadm-d55e3aefc00b6762338c2676934c3bb19ed4da4b.zip
Support auto-assembling of stacked devices
and assorted bugfixes. Signed-off-by: Neil Brown <neilb@suse.de>
-rw-r--r--Assemble.c20
-rw-r--r--mdadm.c30
-rw-r--r--mdopen.c2
3 files changed, 40 insertions, 12 deletions
diff --git a/Assemble.c b/Assemble.c
index 6d89a24..cde0fa7 100644
--- a/Assemble.c
+++ b/Assemble.c
@@ -110,6 +110,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
* START_ARRAY
*
*/
+ int must_close = 0;
int old_linux = 0;
int vers;
void *first_super = NULL, *super = NULL;
@@ -367,7 +368,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
mdu_array_info_t inf;
char *c;
if (!first_super) {
- return 1;
+ return 2;
}
st->ss->getinfo_super(&info, first_super);
c = strchr(info.name, ':');
@@ -383,6 +384,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
free(first_super);
return 1;
}
+ must_close = 1;
}
/* 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",
mddev);
free(first_super);
+ if (must_close) close(mdfd);
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) {
fprintf(stderr, Name ": Cannot open %s: %s\n",
devices[j].devname, strerror(errno));
+ if (must_close) close(mdfd);
return 1;
}
if (st->ss->load_super(st,fd, &super, NULL)) {
close(fd);
fprintf(stderr, Name ": RAID superblock has disappeared from %s\n",
devices[j].devname);
+ if (must_close) close(mdfd);
return 1;
}
close(fd);
}
if (super == NULL) {
fprintf(stderr, Name ": No suitable drives found for %s\n", mddev);
+ if (must_close) close(mdfd);
return 1;
}
st->ss->getinfo_super(&info, super);
@@ -699,12 +705,14 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
if (fd < 0) {
fprintf(stderr, Name ": Could not open %s for write - cannot Assemble array.\n",
devices[chosen_drive].devname);
+ if (must_close) close(mdfd);
return 1;
}
if (st->ss->store_super(st, fd, super)) {
close(fd);
fprintf(stderr, Name ": Could not re-write superblock on %s\n",
devices[chosen_drive].devname);
+ if (must_close) close(mdfd);
return 1;
}
close(fd);
@@ -739,6 +747,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
}
if (err) {
fprintf(stderr, Name ": Failed to restore critical section for reshape, sorry.\n");
+ if (must_close) close(mdfd);
return err;
}
}
@@ -763,11 +772,13 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
if (rv) {
fprintf(stderr, Name ": SET_ARRAY_INFO failed for %s: %s\n",
mddev, strerror(errno));
+ if (must_close) close(mdfd);
return 1;
}
if (ident->bitmap_fd >= 0) {
if (ioctl(mdfd, SET_BITMAP_FILE, ident->bitmap_fd) != 0) {
fprintf(stderr, Name ": SET_BITMAP_FILE failed.\n");
+ if (must_close) close(mdfd);
return 1;
}
} else if (ident->bitmap_file) {
@@ -776,11 +787,13 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
if (bmfd < 0) {
fprintf(stderr, Name ": Could not open bitmap file %s\n",
ident->bitmap_file);
+ if (must_close) close(mdfd);
return 1;
}
if (ioctl(mdfd, SET_BITMAP_FILE, bmfd) != 0) {
fprintf(stderr, Name ": Failed to set bitmapfile for %s\n", mddev);
close(bmfd);
+ if (must_close) close(mdfd);
return 1;
}
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, ".\n");
}
+ if (must_close) close(mdfd);
return 0;
}
fprintf(stderr, Name ": failed to RUN_ARRAY %s: %s\n",
mddev, strerror(errno));
+ if (must_close) close(mdfd);
return 1;
}
if (runstop == -1) {
@@ -845,6 +860,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
if (okcnt != info.array.raid_disks)
fprintf(stderr, " (out of %d)", info.array.raid_disks);
fprintf(stderr, ", but not started.\n");
+ if (must_close) close(mdfd);
return 0;
}
if (verbose >= 0) {
@@ -861,6 +877,7 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
fprintf(stderr, " (use --run to insist).\n");
}
}
+ if (must_close) close(mdfd);
return 1;
} else {
/* 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;
}
diff --git a/mdadm.c b/mdadm.c
index 6c30058..ff656e4 100644
--- a/mdadm.c
+++ b/mdadm.c
@@ -873,6 +873,8 @@ int main(int argc, char *argv[])
fprintf(stderr, Name ": --super-minor=dev is incompatible with --auto\n");
exit(2);
}
+ if (mode == MANAGE && runstop < 0)
+ autof=1; /* Don't create */
mdfd = open_mddev(devlist->devname, autof);
if (mdfd < 0)
exit(1);
@@ -1022,15 +1024,23 @@ int main(int argc, char *argv[])
* until it fails
*/
int rv2;
+ int acnt;
+ ident.autof = autof;
do {
- ident.autof = autof;
- rv2 = Assemble(ss, NULL, -1,
- &ident, configfile,
- devlist, NULL,
- readonly, runstop, NULL, homehost, verbose-quiet, force);
- if (rv2==0)
- cnt++;
- } while (rv2==0);
+ acnt = 0;
+ do {
+ rv2 = Assemble(ss, NULL, -1,
+ &ident, configfile,
+ devlist, NULL,
+ readonly, runstop, NULL, homehost, verbose-quiet, force);
+ if (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) {
fprintf(stderr, Name ": No arrays found in config file or automatically\n");
rv = 1;
@@ -1125,7 +1135,7 @@ int main(int argc, char *argv[])
e->dev);
continue;
}
- mdfd = open_mddev(name, 0);
+ mdfd = open_mddev(name, 1);
if (mdfd >= 0) {
if (Manage_runstop(name, mdfd, -1, !last))
err = 1;
@@ -1154,7 +1164,7 @@ int main(int argc, char *argv[])
case 'X':
rv |= ExamineBitmap(dv->devname, brief, ss); continue;
}
- mdfd = open_mddev(dv->devname, 0);
+ mdfd = open_mddev(dv->devname, 1);
if (mdfd>=0) {
switch(dv->disposition) {
case 'R':
diff --git a/mdopen.c b/mdopen.c
index d76ebf9..534a509 100644
--- a/mdopen.c
+++ b/mdopen.c
@@ -167,7 +167,7 @@ int open_mddev(char *dev, int autof)
if (ioctl(mdfd, GET_ARRAY_INFO, &array)==0) {
/* already active */
close(mdfd);
- fprintf(sterr, Name ": %s is alreadyt active.\n",
+ fprintf(stderr, Name ": %s is already active.\n",
dev);
return -1;
} else {