]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - config.c
Create: cleanup after failed create in duplicated array member case
[thirdparty/mdadm.git] / config.c
index d171b1e92ef3b406bd3fd685f8ce33b5c5da438d..20c46e9eb1fc058cb5290b1502f63d735defdc73 100644 (file)
--- a/config.c
+++ b/config.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>
  */
 
 #include       "mdadm.h"
@@ -682,12 +677,21 @@ void homehostline(char *line)
 static char *auto_options = NULL;
 void autoline(char *line)
 {
+       char *w;
+
        if (auto_options) {
                fprintf(stderr, Name ": AUTO line may only be give once."
                        "  Subsequent lines ignored\n");
                return;
        }
-       auto_options = line;            
+
+       auto_options = dl_strdup(line);
+       dl_init(auto_options);
+
+       for (w=dl_next(line); w != line ; w=dl_next(w)) {
+               char *w2 = dl_strdup(w);
+               dl_add(auto_options, w2);
+       }
 }
 
 int loaded = 0;
@@ -887,18 +891,26 @@ int conf_test_dev(char *devname)
        return 0;
 }
 
-int conf_test_metadata(const char *version)
+int conf_test_metadata(const char *version, int is_homehost)
 {
        /* Check if the given metadata version is allowed
         * to be auto-assembled.
         * The default is 'yes' but the 'auto' line might over-ride that.
-        * Word in auto_options are processed in order with the first
+        * Words in auto_options are processed in order with the first
         * match winning.
         * word can be:
         *   +version   - that version can be assembled
         *   -version   - that version cannot be auto-assembled
         *   yes or +all - any other version can be assembled
         *   no or -all  - no other version can be assembled.
+        *   homehost   - any array associated by 'homehost' to this
+        *                host can be assembled.
+        *
+        * Thus:
+        *   +ddf -0.90 homehost -all
+        * will auto-assemble any ddf array, no 0.90 array, and
+        * any other array (imsm, 1.x) if and only if it is identified
+        * as belonging to this host.
         */
        char *w;
        load_conffile();
@@ -910,6 +922,12 @@ int conf_test_metadata(const char *version)
                        return 1;
                if (strcasecmp(w, "no") == 0)
                        return 0;
+               if (strcasecmp(w, "homehost") == 0) {
+                       if (is_homehost)
+                               return 1;
+                       else
+                               continue;
+               }
                if (w[0] == '+')
                        rv = 1;
                else if (w[0] == '-')
@@ -1013,3 +1031,73 @@ int conf_name_is_free(char *name)
        }
        return 1;
 }
+
+struct mddev_ident_s *conf_match(struct mdinfo *info, struct supertype *st)
+{
+       struct mddev_ident_s *array_list, *match;
+       int verbose = 0;
+       char *devname = NULL;
+       array_list = conf_get_ident(NULL);
+       match = NULL;
+       for (; array_list; array_list = array_list->next) {
+               if (array_list->uuid_set &&
+                   same_uuid(array_list->uuid, info->uuid, st->ss->swapuuid)
+                   == 0) {
+                       if (verbose >= 2 && array_list->devname)
+                               fprintf(stderr, Name
+                                       ": UUID differs from %s.\n",
+                                       array_list->devname);
+                       continue;
+               }
+               if (array_list->name[0] &&
+                   strcasecmp(array_list->name, info->name) != 0) {
+                       if (verbose >= 2 && array_list->devname)
+                               fprintf(stderr, Name
+                                       ": Name differs from %s.\n",
+                                       array_list->devname);
+                       continue;
+               }
+               if (array_list->devices && devname &&
+                   !match_oneof(array_list->devices, devname)) {
+                       if (verbose >= 2 && array_list->devname)
+                               fprintf(stderr, Name
+                                       ": Not a listed device for %s.\n",
+                                       array_list->devname);
+                       continue;
+               }
+               if (array_list->super_minor != UnSet &&
+                   array_list->super_minor != info->array.md_minor) {
+                       if (verbose >= 2 && array_list->devname)
+                               fprintf(stderr, Name
+                                       ": Different super-minor to %s.\n",
+                                       array_list->devname);
+                       continue;
+               }
+               if (!array_list->uuid_set &&
+                   !array_list->name[0] &&
+                   !array_list->devices &&
+                   array_list->super_minor == UnSet) {
+                       if (verbose >= 2 && array_list->devname)
+                               fprintf(stderr, Name
+                            ": %s doesn't have any identifying information.\n",
+                                       array_list->devname);
+                       continue;
+               }
+               /* FIXME, should I check raid_disks and level too?? */
+
+               if (match) {
+                       if (verbose >= 0) {
+                               if (match->devname && array_list->devname)
+                                       fprintf(stderr, Name
+                  ": we match both %s and %s - cannot decide which to use.\n",
+                                               match->devname, array_list->devname);
+                               else
+                                       fprintf(stderr, Name
+                                               ": multiple lines in mdadm.conf match\n");
+                       }
+                       return NULL;
+               }
+               match = array_list;
+       }
+       return match;
+}