]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
fix: Allowed to assemble 2 volumes with the same names from config file.
authorLukasz Orlowski <lukasz.orlowski@intel.com>
Mon, 7 Nov 2011 01:20:34 +0000 (12:20 +1100)
committerNeilBrown <neilb@suse.de>
Mon, 7 Nov 2011 01:20:34 +0000 (12:20 +1100)
mdadm allowes to assemble 2 volumes with the same names based on the
config file. The issue is fixed by iterating over the list of md device
identifiers and comparing the names of md devices against each other,
detecting identical names and blocking the assembly should the same names
be found.
Now having detected duplicate names, mdadm terminates without assembling
the container, displaying appropriate prompt.

Signed-off-by: Lukasz Orlowski <lukasz.orlowski@intel.com>
Signed-off-by: NeilBrown <neilb@suse.de>
config.c
mdadm.c
mdadm.h

index 597e04601ff834cd9fee06c466c5be75b75179a6..6a398cfa449eb0392a98c7e55236f2f904371d03 100644 (file)
--- a/config.c
+++ b/config.c
@@ -1096,3 +1096,36 @@ struct mddev_ident *conf_match(struct supertype *st,
        }
        return match;
 }
+
+int conf_verify_devnames(struct mddev_ident *array_list)
+{
+       struct mddev_ident *a1, *a2;
+
+       for (a1 = array_list; a1; a1 = a1->next) {
+               if (!a1->devname)
+                       continue;
+               for (a2 = a1->next; a2; a2 = a2->next) {
+                       if (!a2->devname)
+                               continue;
+                       if (strcmp(a1->devname, a2->devname) != 0)
+                               continue;
+
+                       if (a1->uuid_set && a2->uuid_set) {
+                               char nbuf[64];
+                               __fname_from_uuid(a1->uuid, 0, nbuf, ':');
+                               fprintf(stderr,
+                                       Name ": Devices %s and ",
+                                       nbuf);
+                               __fname_from_uuid(a2->uuid, 0, nbuf, ':');
+                               fprintf(stderr,
+                                       "%s have the same name: %s\n",
+                                       nbuf, a1->devname);
+                       } else
+                               fprintf(stderr, Name ": Device %s given twice"
+                                       " in config file\n", a1->devname);
+                       return 1;
+               }
+       }
+
+       return 0;
+}
diff --git a/mdadm.c b/mdadm.c
index 8e0ce18656d496a80a049475efbbf900dacdbf58..c6a887a87b1065ed9168a85e3e1dfdd25b6c50d3 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -1292,6 +1292,13 @@ int main(int argc, char *argv[])
                        struct map_ent *map = NULL;
                        int cnt = 0;
                        int failures, successes;
+
+                       if (conf_verify_devnames(array_list)) {
+                               fprintf(stderr, Name
+                                       ": Duplicate MD device names in "
+                                       "conf file were found.\n");
+                               exit(1);
+                       }
                        if (devlist == NULL) {
                                fprintf(stderr, Name ": No devices listed in conf file were found.\n");
                                exit(1);
diff --git a/mdadm.h b/mdadm.h
index e5dac79ca8829fb9d2d8116c182f654faf9c930d..1351d420cffb71c8b4c63bb98d2a5080ffe6caab 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -1145,6 +1145,7 @@ extern char *conf_get_homehost(int *require_homehostp);
 extern char *conf_line(FILE *file);
 extern char *conf_word(FILE *file, int allow_key);
 extern int conf_name_is_free(char *name);
+extern int conf_verify_devnames(struct mddev_ident *array_list);
 extern int devname_matches(char *name, char *match);
 extern struct mddev_ident *conf_match(struct supertype *st,
                                      struct mdinfo *info,