diff options
author | NeilBrown <neilb@suse.de> | 2014-05-22 07:55:31 +0200 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2014-05-22 07:55:31 +0200 |
commit | a740cf6432245d607ee216b5380a3215084f101d (patch) | |
tree | 1fac1c8b732596a5b7ff20290c1828eda5337058 /mdadm.c | |
parent | --examine-bitmap: give useful message if no bitmap found on md array. (diff) | |
download | mdadm-a740cf6432245d607ee216b5380a3215084f101d.tar.xz mdadm-a740cf6432245d607ee216b5380a3215084f101d.zip |
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.c | 43 |
1 files changed, 43 insertions, 0 deletions
@@ -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; +} |