]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - mdadm.c
wait_for improvement.
[thirdparty/mdadm.git] / mdadm.c
diff --git a/mdadm.c b/mdadm.c
index b2ec6f904163203252935898257e17147184c908..4402eba846762325cc206c330af6e144d257c5ca 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -132,7 +132,7 @@ int main(int argc, char *argv[])
                                shortopt, long_options,
                                &option_index)) != -1) {
                int newmode = mode;
-               /* firstly, some mode-independant options */
+               /* firstly, some mode-independent options */
                switch(opt) {
                case 'h':
                        if (option_index > 0 &&
@@ -217,6 +217,7 @@ int main(int argc, char *argv[])
                case 'w':
                case 'W':
                case Waitclean:
+               case DetailPlatform:
                case 'K': if (!mode) newmode = MISC; break;
                }
                if (mode && newmode == mode) {
@@ -256,6 +257,7 @@ int main(int argc, char *argv[])
                                        dv->writemostly = writemostly;
                                        dv->re_add = re_add;
                                        dv->used = 0;
+                                       dv->content = NULL;
                                        dv->next = NULL;
                                        *devlistend = dv;
                                        devlistend = &dv->next;
@@ -308,6 +310,8 @@ int main(int argc, char *argv[])
                        dv->disposition = devmode;
                        dv->writemostly = writemostly;
                        dv->re_add = re_add;
+                       dv->used = 0;
+                       dv->content = NULL;
                        dv->next = NULL;
                        *devlistend = dv;
                        devlistend = &dv->next;
@@ -433,7 +437,6 @@ int main(int argc, char *argv[])
                                exit(2);
 
                        case 5:
-                       case 6:
                                layout = map_name(r5layout, optarg);
                                if (layout==UnSet) {
                                        fprintf(stderr, Name ": layout %s not understood for raid5.\n",
@@ -441,6 +444,14 @@ int main(int argc, char *argv[])
                                        exit(2);
                                }
                                break;
+                       case 6:
+                               layout = map_name(r6layout, optarg);
+                               if (layout==UnSet) {
+                                       fprintf(stderr, Name ": layout %s not understood for raid6.\n",
+                                               optarg);
+                                       exit(2);
+                               }
+                               break;
 
                        case 10:
                                /* 'f', 'o' or 'n' followed by a number <= raid_disks */
@@ -640,6 +651,7 @@ int main(int argc, char *argv[])
                "     'summaries', 'homehost', 'byteorder', 'devicesize'.\n");
                        exit(outf == stdout ? 0 : 2);
 
+               case O(INCREMENTAL,NoDegraded):
                case O(ASSEMBLE,NoDegraded): /* --no-degraded */
                        runstop = -1; /* --stop isn't allowed for --assemble,
                                       * so we overload slightly */
@@ -766,6 +778,7 @@ int main(int argc, char *argv[])
                case O(MISC,'w'):
                case O(MISC,'W'):
                case O(MISC, Waitclean):
+               case O(MISC, DetailPlatform):
                        if (devmode && devmode != opt &&
                            (devmode == 'E' || (opt == 'E' && devmode != 'Q'))) {
                                fprintf(stderr, Name ": --examine/-E cannot be given with -%c\n",
@@ -997,7 +1010,7 @@ int main(int argc, char *argv[])
 
        if (homehost == NULL)
                homehost = conf_get_homehost();
-       if (homehost && strcmp(homehost, "<system>")==0) {
+       if (homehost == NULL || strcmp(homehost, "<system>")==0) {
                if (gethostname(sys_hostname, sizeof(sys_hostname)) == 0) {
                        sys_hostname[sizeof(sys_hostname)-1] = 0;
                        homehost = sys_hostname;
@@ -1089,9 +1102,9 @@ int main(int argc, char *argv[])
                                               array_list,
                                               NULL, NULL,
                                               readonly, runstop, NULL, homehost, verbose-quiet, force);
-                               if (rv == 0) cnt++;
+                               cnt++;
                        }
-                       if (homehost) {
+                       if (homehost && cnt == 0) {
                                /* Maybe we can auto-assemble something.
                                 * Repeatedly call Assemble in auto-assemble mode
                                 * until it fails
@@ -1208,24 +1221,42 @@ int main(int argc, char *argv[])
                        rv = Examine(devlist, scan?(verbose>1?0:verbose+1):brief,
                                     export, scan,
                                     SparcAdjust, ss, homehost);
+               } else if (devmode == DetailPlatform) {
+                       rv = Detail_Platform(ss ? ss->ss : NULL, ss ? scan : 1, verbose);
                } else {
                        if (devlist == NULL) {
-                               if (devmode=='D' && scan) {
-                                       /* apply --detail to all devices in /proc/mdstat */
+                               if ((devmode=='D' || devmode == Waitclean) && scan) {
+                                       /* apply --detail or --wait-clean to
+                                        * all devices in /proc/mdstat
+                                        */
                                        struct mdstat_ent *ms = mdstat_read(0, 1);
                                        struct mdstat_ent *e;
+                                       struct map_ent *map = NULL;
+                                       int v = verbose>1?0:verbose+1;
+
                                        for (e=ms ; e ; e=e->next) {
-                                               char *name = get_md_name(e->devnum);
+                                               char *name;
+                                               struct map_ent *me;
+                                               me = map_by_devnum(&map, e->devnum);
+                                               if (me && me->path)
+                                                       name = me->path;
+                                               else
+                                                       name = get_md_name(e->devnum);
 
                                                if (!name) {
                                                        fprintf(stderr, Name ": cannot find device file for %s\n",
                                                                e->dev);
                                                        continue;
                                                }
-                                               rv |= Detail(name, verbose>1?0:verbose+1,
-                                                            export, test, homehost);
+                                               if (devmode == 'D')
+                                                       rv |= Detail(name, v,
+                                                                    export, test,
+                                                                    homehost);
+                                               else
+                                                       rv |= WaitClean(name, v);
                                                put_md_name(name);
                                        }
+                                       free_mdstat(ms);
                                } else  if (devmode == 'S' && scan) {
                                        /* apply --stop to all devices in /proc/mdstat */
                                        /* Due to possible stacking of devices, repeat until
@@ -1258,6 +1289,7 @@ int main(int argc, char *argv[])
 
                                                        put_md_name(name);
                                                }
+                                               free_mdstat(ms);
                                        } while (!last && err);
                                        if (err) rv |= 1;
                                } else {