]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - mapfile.c
mdadm: load default sysfs attributes after assemblation
[thirdparty/mdadm.git] / mapfile.c
index 4e7f24214b8ad8b4430855b186df3eaa1ce7163b..8d7acb3cc389ca0ce49c1dabb99bfe2782875993 100644 (file)
--- a/mapfile.c
+++ b/mapfile.c
@@ -143,6 +143,8 @@ void map_unlock(struct map_ent **melp)
                unlink(mapname[2]);
                fclose(lf);
        }
+       if (*melp)
+               map_free(*melp);
        lf = NULL;
 }
 
@@ -176,7 +178,7 @@ void map_read(struct map_ent **melp)
 {
        FILE *f;
        char buf[8192];
-       char path[200];
+       char path[201];
        int uuid[4];
        char devnm[32];
        char metadata[30];
@@ -266,6 +268,7 @@ void map_remove(struct map_ent **mapp, char *devnm)
        map_delete(mapp, devnm);
        map_write(*mapp);
        map_free(*mapp);
+       *mapp = NULL;
 }
 
 struct map_ent *map_by_uuid(struct map_ent **map, int uuid[4])
@@ -374,7 +377,7 @@ void RebuildMap(void)
                        char dn[30];
                        int dfd;
                        int ok;
-                       int devid;
+                       dev_t devid;
                        struct supertype *st;
                        char *subarray = NULL;
                        char *path;
@@ -439,8 +442,8 @@ void RebuildMap(void)
                                        if ((homehost == NULL ||
                                             st->ss->match_home(st, homehost) != 1) &&
                                            st->ss->match_home(st, "any") != 1 &&
-                                           (require_homehost
-                                            || ! conf_name_is_free(info->name)))
+                                           (require_homehost ||
+                                            !conf_name_is_free(info->name)))
                                                /* require a numeric suffix */
                                                unum = 0;
                                        else
@@ -455,12 +458,19 @@ void RebuildMap(void)
                                                        sep = "";
                                                }
                                        }
-                                       if (strchr(name, ':'))
-                                               /* probably a uniquifying
+                                       if (strchr(name, ':')) {
+                                               /* Probably a uniquifying
                                                 * hostname prefix.  Allow
-                                                * without a suffix
+                                                * without a suffix, and strip
+                                                * hostname if it is us.
                                                 */
+                                               if (homehost && unum == -1 &&
+                                                   strncmp(name, homehost,
+                                                           strlen(homehost)) == 0 &&
+                                                   name[strlen(homehost)] == ':')
+                                                       name += strlen(homehost)+1;
                                                unum = -1;
+                                       }
 
                                        while (conflict) {
                                                if (unum >= 0)