#include <ctype.h>
-
int main(int argc, char *argv[])
{
int mode = 0;
char *help_text;
char *c;
int rv;
+ int i;
int chunk = 0;
int size = -1;
int daemonise = 0;
char *pidfile = NULL;
int oneshot = 0;
+ struct superswitch *ss = NULL;
int copies;
case 'a':
case 'r':
case 'f':
- case 1 : if (!mode) newmode = MANAGE; break;
+ if (!mode) newmode = MANAGE;
+ break;
case 'A': newmode = ASSEMBLE; break;
case 'B': newmode = BUILD; break;
fprintf(stderr, "--%s", long_options[option_index].name);
else
fprintf(stderr, "-%c", opt);
- fprintf(stderr, " would set mode to %s, but it is already %s.\n",
+ fprintf(stderr, " would set mdadm mode to \"%s\", but it is already set to \"%s\".\n",
map_num(modes, newmode),
map_num(modes, mode));
exit(2);
fputs(Help_config, stderr);
exit(0);
}
+
+ /* If first option is a device, don't force the mode yet */
+ if (opt == 1) {
+ if (devs_found == 0) {
+ dv = malloc(sizeof(*dv));
+ if (dv == NULL) {
+ fprintf(stderr, Name ": malloc failed\n");
+ exit(3);
+ }
+ dv->devname = optarg;
+ dv->disposition = devmode;
+ dv->next = NULL;
+ *devlistend = dv;
+ devlistend = &dv->next;
+
+ devs_found++;
+ continue;
+ }
+ /* No mode yet, and this is the second device ... */
+ fprintf(stderr, Name ": An option must be given to set the mode before a second device is listed\n");
+ exit(2);
+ }
if (option_index >= 0)
- fprintf(stderr, "--%s", long_options[option_index].name);
+ fprintf(stderr, Name ": --%s", long_options[option_index].name);
else
- fprintf(stderr, "-%c", opt);
- fprintf(stderr, " does not set the mode, and so cannot be first.\n");
+ fprintf(stderr, Name ": -%c", opt);
+ fprintf(stderr, " does not set the mode, and so cannot be the first option.\n");
exit(2);
}
}
continue;
+ case O(CREATE,'e'):
+ case O(ASSEMBLE,'e'):
+ case O(MISC,'e'): /* set metadata (superblock) information */
+ if (ss) {
+ fprintf(stderr, Name ": metadata information already given\n");
+ exit(2);
+ }
+ for(i=0; superlist[i]; i++)
+ if (superlist[i]->match_metadata_desc(optarg)) {
+ ss = superlist[i];
+ break;
+ }
+ if (!ss) {
+ fprintf(stderr, Name ": unrecognised metadata identifier: %s\n", optarg);
+ exit(2);
+ }
+ continue;
+
case O(GROW,'z'):
case O(CREATE,'z'): /* size */
if (size >= 0) {
}
+ if (!mode && devs_found) {
+ mode = MISC;
+ devmode = 'Q';
+ if (devlist->disposition == 0)
+ devlist->disposition = devmode;
+ }
if (!mode) {
fputs(Usage, stderr);
exit(2);
if (mdfd < 0)
rv |= 1;
else {
- rv |= Assemble(devlist->devname, mdfd, array_ident, configfile,
+ rv |= Assemble(ss, devlist->devname, mdfd, array_ident, configfile,
NULL,
readonly, runstop, update, verbose, force);
close(mdfd);
}
}
} else if (!scan)
- rv = Assemble(devlist->devname, mdfd, &ident, configfile,
+ rv = Assemble(ss, devlist->devname, mdfd, &ident, configfile,
devlist->next,
readonly, runstop, update, verbose, force);
else if (devs_found>0) {
rv |= 1;
continue;
}
- rv |= Assemble(dv->devname, mdfd, array_ident, configfile,
+ rv |= Assemble(ss, dv->devname, mdfd, array_ident, configfile,
NULL,
readonly, runstop, update, verbose, force);
close(mdfd);
}
if (ioctl(mdfd, GET_ARRAY_INFO, &array)>=0)
/* already assembled, skip */
- continue;
- rv |= Assemble(array_list->devname, mdfd,
- array_list, configfile,
- NULL,
- readonly, runstop, NULL, verbose, force);
+ ;
+ else
+ rv |= Assemble(ss, array_list->devname, mdfd,
+ array_list, configfile,
+ NULL,
+ readonly, runstop, NULL, verbose, force);
+ close(mdfd);
}
}
break;
rv = Build(devlist->devname, mdfd, chunk, level, layout, raiddisks, devlist->next, assume_clean);
break;
case CREATE:
- rv = Create(devlist->devname, mdfd, chunk, level, layout, size<0 ? 0 : size,
+ if (ss == NULL) {
+ for(i=0; superlist[i]; i++)
+ if (superlist[i]->match_metadata_desc("default")) {
+ ss = superlist[i];
+ break;
+ }
+ }
+ if (!ss) {
+ fprintf(stderr, Name ": internal error - no default metadata style\n");
+ exit(2);
+ }
+
+ rv = Create(ss, devlist->devname, mdfd, chunk, level, layout, size<0 ? 0 : size,
raiddisks, sparedisks,
devs_found-1, devlist->next, runstop, verbose, force);
break;
/* apply to all devices in /proc/mdstat */
struct mdstat_ent *ms = mdstat_read(0);
struct mdstat_ent *e;
+ if (devmode == 'S') {
+ /* reverse order so that arrays made of arrays are stopped properly */
+ struct mdstat_ent *sm = NULL;
+ while ((e=ms) != NULL) {
+ ms = e->next;
+ e->next = sm;
+ sm = e;
+ }
+ ms = sm;
+ }
for (e=ms ; e ; e=e->next) {
char *name = get_md_name(e->devnum);
rv |= Detail(name, !verbose, test);
else if (devmode=='S') {
mdfd = open_mddev(name, 0);
- if (mdfd >= 0)
+ if (mdfd >= 0) {
rv |= Manage_runstop(name, mdfd, -1);
+ close(mdfd);
+ }
}
put_md_name(name);
}
rv |= Query(dv->devname); continue;
}
mdfd = open_mddev(dv->devname, 0);
- if (mdfd>=0)
+ if (mdfd>=0) {
switch(dv->disposition) {
case 'R':
rv |= Manage_runstop(dv->devname, mdfd, 1); break;
case 'w':
rv |= Manage_ro(dv->devname, mdfd, -1); break;
}
+ close(mdfd);
+ }
}
}
break;