/*
* mdadm - manage Linux "md" devices aka RAID arrays.
*
- * Copyright (C) 2001-2012 Neil Brown <neilb@suse.de>
+ * Copyright (C) 2001-2013 Neil Brown <neilb@suse.de>
*
*
* This program is free software; you can redistribute it and/or modify
#include "md_p.h"
#include <ctype.h>
-
static int scan_assemble(struct supertype *ss,
struct context *c,
struct mddev_ident *ident);
char *dump_directory,
struct supertype *ss, struct context *c);
-
int main(int argc, char *argv[])
{
int mode = 0;
ident.container = NULL;
ident.member = NULL;
- /*
- * set first char of argv[0] to @. This is used by
- * systemd to signal that the task was launched from
- * initrd/initramfs and should be preserved during shutdown
- */
- argv[0][0] = '@';
-
while ((option_index = -1) ,
(opt=getopt_long(argc, argv,
shortopt, long_options,
break;
case 'a':
case Add:
+ case AddSpare:
case 'r':
case Remove:
case Replace:
case ExamineBB:
case Dump:
case Restore:
+ case Action:
newmode = MISC;
break;
writemostly = 2;
continue;
-
case O(GROW,'z'):
case O(CREATE,'z'):
case O(BUILD,'z'): /* size */
continue;
if (strcmp(c.update, "metadata") == 0)
continue;
+ if (strcmp(c.update, "revert-reshape") == 0)
+ continue;
if (strcmp(c.update, "byteorder")==0) {
if (ss) {
pr_err("must not set metadata"
fprintf(outf, "Valid --update options are:\n"
" 'sparc2.2', 'super-minor', 'uuid', 'name', 'resync',\n"
" 'summaries', 'homehost', 'byteorder', 'devicesize',\n"
- " 'no-bitmap', 'metadata'\n");
+ " 'no-bitmap', 'metadata', 'revert-reshape'\n");
exit(outf == stdout ? 0 : 2);
case O(MANAGE,'U'):
case O(MISC, ConfigFile):
case O(MONITOR,'c'):
case O(MONITOR,ConfigFile):
+ case O(CREATE,ConfigFile):
if (configfile) {
pr_err("configfile cannot be set twice. "
"Second value is %s.\n", optarg);
case O(MANAGE,Add): /* add a drive */
devmode = 'a';
continue;
+ case O(MANAGE,AddSpare): /* add drive - never re-add */
+ devmode = 'S';
+ continue;
case O(MANAGE,ReAdd):
devmode = 'A';
continue;
case O(MISC, UpdateSubarray):
case O(MISC, Dump):
case O(MISC, Restore):
+ case O(MISC ,Action):
if (opt == KillSubarray || opt == UpdateSubarray) {
if (c.subarray) {
pr_err("subarray can only"
}
c.subarray = optarg;
}
+ if (opt == Action) {
+ if (c.action) {
+ pr_err("Only one --action can be specified\n");
+ exit(2);
+ }
+ if (strcmp(optarg, "idle") == 0 ||
+ strcmp(optarg, "frozen") == 0 ||
+ strcmp(optarg, "check") == 0 ||
+ strcmp(optarg, "repair") == 0)
+ c.action = optarg;
+ else {
+ pr_err("action must be one of idle, frozen, check, repair\n");
+ exit(2);
+ }
+ }
if (devmode && devmode != opt &&
(devmode == 'E' || (opt == 'E' && devmode != 'Q'))) {
pr_err("--examine/-E cannot be given with ");
c.update, c.force);
if (!rv && c.readonly < 0)
rv = Manage_ro(devlist->devname, mdfd, c.readonly);
- if (!rv && c.runstop)
- rv = Manage_runstop(devlist->devname, mdfd, c.runstop, c.verbose, 0);
+ if (!rv && c.runstop > 0)
+ rv = Manage_run(devlist->devname, mdfd, &c);
+ if (!rv && c.runstop < 0)
+ rv = Manage_stop(devlist->devname, mdfd, c.verbose, 0);
break;
case ASSEMBLE:
if (devs_found == 1 && ident.uuid_set == 0 &&
break;
}
}
- if (devs_found > 1 && s.raiddisks == 0) {
+ if (devs_found > 1 && s.raiddisks == 0 && s.level == UnSet) {
/* must be '-a'. */
if (s.size > 0 || s.chunk || s.layout_str != NULL || s.bitmap_file) {
pr_err("--add cannot be used with "
RebuildMap();
}
if (c.scan) {
+ rv = 1;
+ if (devlist) {
+ pr_err("In --incremental mode, a device cannot be given with --scan.\n");
+ break;
+ }
if (c.runstop <= 0) {
pr_err("--incremental --scan meaningless without --run.\n");
break;
pr_err("--incremental --scan --fail not supported.\n");
break;
}
- rv = IncrementalScan(c.verbose);
+ rv = IncrementalScan(&c, NULL);
}
if (!devlist) {
if (!rebuild_map && !c.scan) {
}
break;
}
- if (devlist->next) {
- pr_err("--incremental can only handle one device.\n");
- rv = 1;
- break;
- }
- if (devmode == 'f')
+ if (devmode == 'f') {
+ if (devlist->next) {
+ pr_err("'--incremental --fail' can only handle one device.\n");
+ rv = 1;
+ break;
+ }
rv = IncrementalRemove(devlist->devname, remove_path,
c.verbose);
- else
- rv = Incremental(devlist->devname, &c, ss);
+ } else
+ rv = Incremental(devlist, &c, ss);
break;
case AUTODETECT:
autodetect();
if (a->devname &&
strcasecmp(a->devname, "<ignore>") == 0)
continue;
-
+
r = Assemble(ss, a->devname,
a, NULL, c);
if (r == 0) {
}
mdfd = open_mddev(name, 1);
if (mdfd >= 0) {
- if (Manage_runstop(name, mdfd, -1, verbose, !last))
+ if (Manage_stop(name, mdfd, verbose, !last))
err = 1;
else
progress = 1;
rv |= Restore_metadata(dv->devname, dump_directory, c, ss,
(dv == devlist && dv->next == NULL));
continue;
+ case Action:
+ rv |= SetAction(dv->devname, c->action);
+ continue;
+ }
+ if (dv->devname[0] == '/')
+ mdfd = open_mddev(dv->devname, 1);
+ else {
+ mdfd = open_dev(dv->devname);
+ if (mdfd < 0)
+ pr_err("Cannot open %s\n", dv->devname);
}
- mdfd = open_mddev(dv->devname, 1);
if (mdfd>=0) {
switch(dv->disposition) {
case 'R':
- rv |= Manage_runstop(dv->devname, mdfd, 1, c->verbose, 0); break;
+ c->runstop = 1;
+ rv |= Manage_run(dv->devname, mdfd, c); break;
case 'S':
- rv |= Manage_runstop(dv->devname, mdfd, -1, c->verbose, 0); break;
+ rv |= Manage_stop(dv->devname, mdfd, c->verbose, 0); break;
case 'o':
rv |= Manage_ro(dv->devname, mdfd, 1); break;
case 'w':
}
return rv;
}
+
+int SetAction(char *dev, char *action)
+{
+ int fd = open(dev, O_RDONLY);
+ struct mdinfo mdi;
+ if (fd < 0) {
+ pr_err("Couldn't open %s: %s\n", dev, strerror(errno));
+ return 1;
+ }
+ sysfs_init(&mdi, fd, NULL);
+ close(fd);
+ if (!mdi.sys_name[0]) {
+ pr_err("%s is no an md array\n", dev);
+ return 1;
+ }
+
+ if (sysfs_set_str(&mdi, NULL, "sync_action", action) < 0) {
+ pr_err("Count not set action for %s to %s: %s\n",
+ dev, action, strerror(errno));
+ return 1;
+ }
+ return 0;
+}