]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Assemble: Handle assembling from config file which is out of order.
authorNeilBrown <neilb@suse.de>
Wed, 24 Feb 2010 00:16:41 +0000 (11:16 +1100)
committerNeilBrown <neilb@suse.de>
Wed, 24 Feb 2010 00:16:56 +0000 (11:16 +1100)
Currently "mdadm -As" will process the entries in the config
file in order.  If any array is a component or member of a preceding
array, that array will not be assembled.

So if there are any failures during assembly, retry those arrays,
and look until everything is assembled, or nothing more can
be assembled.

Signed-off-by: NeilBrown <neilb@suse.de>
mdadm.c
mdadm.h

diff --git a/mdadm.c b/mdadm.c
index eb124d53dcfd4c99f1539412fb638b946fe42eea..d5e34c074c034f99d289124422ab38d944e8feee 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -1120,9 +1120,10 @@ int main(int argc, char *argv[])
                                               verbose-quiet, force);
                        }
                } else {
-                       mddev_ident_t array_list =  conf_get_ident(NULL);
+                       mddev_ident_t a, array_list =  conf_get_ident(NULL);
                        mddev_dev_t devlist = conf_get_devs();
                        int cnt = 0;
+                       int failures, successes;
                        if (devlist == NULL) {
                                fprintf(stderr, Name ": No devices listed in conf file were found.\n");
                                exit(1);
@@ -1135,21 +1136,38 @@ int main(int argc, char *argv[])
                                fprintf(stderr, Name ": --backup_file not meaningful with a --scan assembly.\n");
                                exit(1);
                        }
-                       for (; array_list; array_list = array_list->next) {
-                               if (array_list->devname &&
-                                   strcasecmp(array_list->devname, "<ignore>") == 0)
-                                       continue;
-                               if (array_list->autof == 0)
-                                       array_list->autof = autof;
+                       for (a = array_list; a ; a = a->next) {
+                               a->assembled = 0;
+                               if (a->autof == 0)
+                                       a->autof = autof;
+                       }
+                       do {
+                               failures = 0;
+                               successes = 0;
+                               rv = 0;
+                               for (a = array_list; a ; a = a->next) {
+                                       int r;
+                                       if (a->assembled)
+                                               continue;
+                                       if (a->devname &&
+                                           strcasecmp(a->devname, "<ignore>") == 0)
+                                               continue;
                                
-                               rv |= Assemble(ss, array_list->devname,
-                                              array_list,
-                                              NULL, NULL,
-                                              readonly, runstop, NULL,
-                                              homehost, require_homehost,
-                                              verbose-quiet, force);
-                               cnt++;
-                       }
+                                       r = Assemble(ss, a->devname,
+                                                    a,
+                                                    NULL, NULL,
+                                                    readonly, runstop, NULL,
+                                                    homehost, require_homehost,
+                                                    verbose-quiet, force);
+                                       if (r == 0) {
+                                               a->assembled = 1;
+                                               successes++;
+                                       } else
+                                               failures++;
+                                       rv |= r;
+                                       cnt++;
+                               }
+                       } while (failures && successes);
                        if (homehost && cnt == 0) {
                                /* Maybe we can auto-assemble something.
                                 * Repeatedly call Assemble in auto-assemble mode
diff --git a/mdadm.h b/mdadm.h
index a7d8b797530c097b95ea38a6eb489c9ff6aae59d..df3a056a5613d63981c48818b8c7446277b0c44e 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -301,6 +301,10 @@ typedef struct mddev_ident_s {
        char    *member;        /* subarray within a container */
 
        struct mddev_ident_s *next;
+       union {
+               /* fields needed by different users of this structure */
+               int assembled;  /* set when assembly succeeds */
+       };
 } *mddev_ident_t;
 
 /* List of device names - wildcards expanded */