summaryrefslogtreecommitdiff
path: root/mdadm.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2014-05-22 15:55:31 +1000
committerNeilBrown <neilb@suse.de>2014-05-22 15:55:31 +1000
commita740cf6432245d607ee216b5380a3215084f101d (patch)
tree1fac1c8b732596a5b7ff20290c1828eda5337058 /mdadm.c
parent1e781e07ab565993f36292e7ec0dc3f574556759 (diff)
MISC: add --action option to set or abort check/repair.
Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'mdadm.c')
-rw-r--r--mdadm.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/mdadm.c b/mdadm.c
index f6f5b53a..be990b8a 100644
--- a/mdadm.c
+++ b/mdadm.c
@@ -230,6 +230,7 @@ int main(int argc, char *argv[])
case ExamineBB:
case Dump:
case Restore:
+ case Action:
newmode = MISC;
break;
@@ -987,6 +988,7 @@ int main(int argc, char *argv[])
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"
@@ -995,6 +997,21 @@ int main(int argc, char *argv[])
}
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 ");
@@ -1802,6 +1819,9 @@ static int misc_list(struct mddev_dev *devlist,
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);
@@ -1828,3 +1848,26 @@ static int misc_list(struct mddev_dev *devlist,
}
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;
+}