]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - mdadm.c
Consistently print program Name and __func__ in debug messages.
[thirdparty/mdadm.git] / mdadm.c
diff --git a/mdadm.c b/mdadm.c
index a46a716b29617014aeb6aab83698ce465467f3e5..fd64e0e31610f18c1a94822dc6dd2911f872b26d 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -1,7 +1,7 @@
 /*
  * 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
@@ -38,6 +38,7 @@ static int misc_list(struct mddev_dev *devlist,
                     struct mddev_ident *ident,
                     char *dump_directory,
                     struct supertype *ss, struct context *c);
+const char Name[] = "mdadm";
 
 int main(int argc, char *argv[])
 {
@@ -116,13 +117,6 @@ int main(int argc, char *argv[])
        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,
@@ -194,6 +188,7 @@ int main(int argc, char *argv[])
                        break;
                case 'a':
                case Add:
+               case AddSpare:
                case 'r':
                case Remove:
                case Replace:
@@ -236,6 +231,7 @@ int main(int argc, char *argv[])
                case ExamineBB:
                case Dump:
                case Restore:
+               case Action:
                        newmode = MISC;
                        break;
 
@@ -776,17 +772,19 @@ int main(int argc, char *argv[])
                        if (strcmp(c.update,"?") == 0 ||
                            strcmp(c.update, "help") == 0) {
                                outf = stdout;
-                               fprintf(outf, Name ": ");
+                               fprintf(outf, "%s: ", Name);
                        } else {
                                outf = stderr;
                                fprintf(outf,
-                                       Name ": '--update=%s' is invalid.  ",
-                                       c.update);
+                                       "%s: '--update=%s' is invalid.  ",
+                                       Name, c.update);
                        }
                        fprintf(outf, "Valid --update options are:\n"
                "     'sparc2.2', 'super-minor', 'uuid', 'name', 'resync',\n"
                "     'summaries', 'homehost', 'byteorder', 'devicesize',\n"
-               "     'no-bitmap', 'metadata', 'revert-reshape'\n");
+               "     'no-bitmap', 'metadata', 'revert-reshape'\n"
+               "     'bbl', 'no-bbl'\n"
+                               );
                        exit(outf == stdout ? 0 : 2);
 
                case O(MANAGE,'U'):
@@ -922,6 +920,9 @@ int main(int argc, char *argv[])
                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;
@@ -990,6 +991,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"
@@ -998,6 +1000,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 ");
@@ -1300,7 +1317,7 @@ int main(int argc, char *argv[])
                if (!rv && c.readonly < 0)
                        rv = Manage_ro(devlist->devname, mdfd, c.readonly);
                if (!rv && c.runstop > 0)
-                       rv = Manage_run(devlist->devname, mdfd, c.verbose);
+                       rv = Manage_run(devlist->devname, mdfd, &c);
                if (!rv && c.runstop < 0)
                        rv = Manage_stop(devlist->devname, mdfd, c.verbose, 0);
                break;
@@ -1534,6 +1551,11 @@ int main(int argc, char *argv[])
                        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;
@@ -1542,7 +1564,7 @@ int main(int argc, char *argv[])
                                pr_err("--incremental --scan --fail not supported.\n");
                                break;
                        }
-                       rv = IncrementalScan(c.verbose);
+                       rv = IncrementalScan(&c, NULL);
                }
                if (!devlist) {
                        if (!rebuild_map && !c.scan) {
@@ -1551,16 +1573,16 @@ int main(int argc, char *argv[])
                        }
                        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();
@@ -1595,9 +1617,7 @@ static int scan_assemble(struct supertype *ss,
                        a->autof = c->autof;
        }
        if (map_lock(&map))
-               pr_err("%s: failed to get "
-                      "exclusive lock on mapfile\n",
-                      __func__);
+               pr_err("failed to get exclusive lock on mapfile\n");
        do {
                failures = 0;
                successes = 0;
@@ -1800,6 +1820,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);
@@ -1811,7 +1834,8 @@ static int misc_list(struct mddev_dev *devlist,
                if (mdfd>=0) {
                        switch(dv->disposition) {
                        case 'R':
-                               rv |= Manage_run(dv->devname, mdfd, c->verbose); break;
+                               c->runstop = 1;
+                               rv |= Manage_run(dv->devname, mdfd, c); break;
                        case 'S':
                                rv |= Manage_stop(dv->devname, mdfd, c->verbose, 0); break;
                        case 'o':
@@ -1825,3 +1849,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;
+}