]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - mdadm.c
imsm: add support for checkpointing via 'curr_migr_unit'
[thirdparty/mdadm.git] / mdadm.c
diff --git a/mdadm.c b/mdadm.c
index 6b571d70b51ab33be056fef37f51ddfe19840cf4..74a39a88584b9bf4ac9885d9b21f534f8d8175f2 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -1,7 +1,7 @@
 /*
  * mdadm - manage Linux "md" devices aka RAID arrays.
  *
- * Copyright (C) 2001-2006 Neil Brown <neilb@suse.de>
+ * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
  *
  *
  *    This program is free software; you can redistribute it and/or modify
  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  *    Author: Neil Brown
- *    Email: <neilb@cse.unsw.edu.au>
- *    Paper: Neil Brown
- *           School of Computer Science and Engineering
- *           The University of New South Wales
- *           Sydney, 2052
- *           Australia
+ *    Email: <neilb@suse.de>
  *
  *    Additions for bitmap and write-behind RAID options, Copyright (C) 2003-2004,
  *    Paul Clements, SteelEye Technology, Inc.
@@ -96,6 +91,7 @@ int main(int argc, char *argv[])
        int require_homehost = 1;
        char *mailaddr = NULL;
        char *program = NULL;
+       int increments = 20;
        int delay = 0;
        int daemonise = 0;
        char *pidfile = NULL;
@@ -345,9 +341,11 @@ int main(int argc, char *argv[])
                        }
                        continue;
 
+#if 0
                case O(ASSEMBLE,AutoHomeHost):
                        auto_update_home = 1;
                        continue;
+#endif
                case O(INCREMENTAL, 'e'):
                case O(CREATE,'e'):
                case O(ASSEMBLE,'e'):
@@ -433,7 +431,10 @@ int main(int argc, char *argv[])
                                        optarg);
                                exit(2);
                        }
-                       if (level != 0 && level != -1 && level != 1 && level != -4 && level != -5 && mode == BUILD) {
+                       if (level != 0 && level != LEVEL_LINEAR && level != 1 &&
+                           level != LEVEL_MULTIPATH && level != LEVEL_FAULTY &&
+                           level != 10 &&
+                           mode == BUILD) {
                                fprintf(stderr, Name ": Raid level %s not permitted with --build.\n",
                                        optarg);
                                exit(2);
@@ -714,6 +715,14 @@ int main(int argc, char *argv[])
                                program = optarg;
                        continue;
 
+               case O(MONITOR,'r'): /* rebuild increments */
+                       increments = atoi(optarg);
+                       if (increments>99 || increments<1) {
+                               fprintf(stderr, Name ": please specify positive integer between 1 and 99 as rebuild increments.\n");
+                               exit(2);
+                       }
+                       continue;
+
                case O(MONITOR,'d'): /* delay in seconds */
                case O(GROW, 'd'):
                case O(BUILD,'d'): /* delay for bitmap updates */
@@ -1166,6 +1175,7 @@ int main(int argc, char *argv[])
                                        } while (rv2!=2);
                                        /* Incase there are stacked devices, we need to go around again */
                                } while (acnt);
+#if 0
                                if (cnt == 0 && auto_update_home && homehost) {
                                        /* Nothing found, maybe we need to bootstrap homehost info */
                                        do {
@@ -1185,6 +1195,7 @@ int main(int argc, char *argv[])
                                                /* Incase there are stacked devices, we need to go around again */
                                        } while (acnt);
                                }
+#endif
                                if (cnt == 0 && rv == 0) {
                                        fprintf(stderr, Name ": No arrays found in config file or automatically\n");
                                        rv = 1;
@@ -1268,11 +1279,18 @@ int main(int argc, char *argv[])
                                        struct mdstat_ent *ms = mdstat_read(0, 1);
                                        struct mdstat_ent *e;
                                        struct map_ent *map = NULL;
+                                       int members;
                                        int v = verbose>1?0:verbose+1;
 
+                                       for (members = 0; members <= 1; members++) {
                                        for (e=ms ; e ; e=e->next) {
                                                char *name;
                                                struct map_ent *me;
+                                               int member = e->metadata_version &&
+                                                       strncmp(e->metadata_version,
+                                                               "external:/", 10) == 0;
+                                               if (members != member)
+                                                       continue;
                                                me = map_by_devnum(&map, e->devnum);
                                                if (me && me->path
                                                    && strcmp(me->path, "/unknown") != 0)
@@ -1290,9 +1308,10 @@ int main(int argc, char *argv[])
                                                                     export, test,
                                                                     homehost);
                                                else
-                                                       rv |= WaitClean(name, v);
+                                                       rv |= WaitClean(name, -1, v);
                                                put_md_name(name);
                                        }
+                                       }
                                        free_mdstat(ms);
                                } else  if (devmode == 'S' && scan) {
                                        /* apply --stop to all devices in /proc/mdstat */
@@ -1342,7 +1361,16 @@ int main(int argc, char *argv[])
                                                     export, test, homehost);
                                        continue;
                                case 'K': /* Zero superblock */
-                                       rv |= Kill(dv->devname, force, quiet,0);
+                                       if (ss)
+                                               rv |= Kill(dv->devname, ss, force, quiet,0);
+                                       else {
+                                               int q = quiet;
+                                               do {
+                                                       rv |= Kill(dv->devname, NULL, force, q, 0);
+                                                       q = 1;
+                                               } while ((rv & 2) == 0);
+                                               rv &= ~2;
+                                       }
                                        continue;
                                case 'Q':
                                        rv |= Query(dv->devname); continue;
@@ -1351,7 +1379,7 @@ int main(int argc, char *argv[])
                                case 'W':
                                        rv |= Wait(dv->devname); continue;
                                case Waitclean:
-                                       rv |= WaitClean(dv->devname, verbose-quiet); continue;
+                                       rv |= WaitClean(dv->devname, -1, verbose-quiet); continue;
                                }
                                mdfd = open_mddev(dv->devname, 1);
                                if (mdfd>=0) {
@@ -1382,18 +1410,34 @@ int main(int argc, char *argv[])
                        rv = 1;
                        break;
                }
+               if (delay == 0) {
+                       if (get_linux_version() > 20616)
+                               /* mdstat responds to poll */
+                               delay = 1000;
+                       else
+                               delay = 60;
+               }
                rv= Monitor(devlist, mailaddr, program,
                            delay?delay:60, daemonise, scan, oneshot,
-                           dosyslog, test, pidfile);
+                           dosyslog, test, pidfile, increments);
                break;
 
        case GROW:
                if (array_size >= 0) {
                        /* alway impose array size first, independent of
                         * anything else
+                        * Do not allow level or raid_disks changes at the
+                        * same time as that can be irreversibly destructive.
                         */
                        struct mdinfo sra;
                        int err;
+                       if (raiddisks || level != UnSet) {
+                               fprintf(stderr, Name ": cannot change array size in same operation "
+                                       "as changing raiddisks or level.\n"
+                                       "    Change size first, then check that data is still intact.\n");
+                               rv = 1;
+                               break;
+                       }
                        sysfs_init(&sra, mdfd, 0);
                        if (array_size == 0)
                                err = sysfs_set_str(&sra, NULL, "array_size", "default");