]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Config: use better device names for "DEVICES container"
authorNeilBrown <neilb@suse.de>
Tue, 2 Jul 2013 00:46:43 +0000 (10:46 +1000)
committerNeilBrown <neilb@suse.de>
Tue, 2 Jul 2013 00:46:43 +0000 (10:46 +1000)
When "containers" appears on the "DEVICES" line (which is does by
default), use names from the mdadm map file instead of kernel names,
when possible.
This mean that the name will be more likely to appear in mdadm.conf
and so more likely to match "container=" tags.

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

index 5cf6ae5f1043f7dff1b292d3619bcb2e7b7f0a59..5c8b03a3838d7a1548aef5a2b326663ef097b399 100644 (file)
--- a/config.c
+++ b/config.c
@@ -154,6 +154,7 @@ struct mddev_dev *load_containers(void)
        struct mdstat_ent *ent;
        struct mddev_dev *d;
        struct mddev_dev *rv = NULL;
+       struct map_ent *map = NULL, *me;
 
        if (!mdstat)
                return NULL;
@@ -164,7 +165,10 @@ struct mddev_dev *load_containers(void)
                    !is_subarray(&ent->metadata_version[9])) {
                        d = xmalloc(sizeof(*d));
                        memset(d, 0, sizeof(*d));
-                       if (asprintf(&d->devname, "/dev/%s", ent->dev) < 0) {
+                       me = map_by_devnm(&map, ent->dev);
+                       if (me)
+                               d->devname = xstrdup(me->path);
+                       else if (asprintf(&d->devname, "/dev/%s", ent->dev) < 0) {
                                free(d);
                                continue;
                        }
@@ -172,6 +176,7 @@ struct mddev_dev *load_containers(void)
                        rv = d;
                }
        free_mdstat(mdstat);
+       map_free(map);
 
        return rv;
 }
diff --git a/mdadm.h b/mdadm.h
index 13aa84ab685f224ac560b3a28c722975f1163f5a..fed3bc8ca015f75a8256d6e1611e530ec9580113 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -484,12 +484,22 @@ extern int map_update(struct map_ent **mpp, char *devnm, char *metadata,
                      int uuid[4], char *path);
 extern void map_remove(struct map_ent **map, char *devnm);
 extern struct map_ent *map_by_uuid(struct map_ent **map, int uuid[4]);
+#ifdef MDASSEMBLE
+static inline struct map_ent *map_by_devnm(struct map_ent **map, char *name)
+{
+       return NULL;
+}
+static inline void map_free(struct map_ent *map)
+{
+}
+#else
 extern struct map_ent *map_by_devnm(struct map_ent **map, char *devnm);
+extern void map_free(struct map_ent *map);
+#endif
 extern struct map_ent *map_by_name(struct map_ent **map, char *name);
 extern void map_read(struct map_ent **melp);
 extern int map_write(struct map_ent *mel);
 extern void map_delete(struct map_ent **mapp, char *devnm);
-extern void map_free(struct map_ent *map);
 extern void map_add(struct map_ent **melp,
                    char *devnm, char *metadata, int uuid[4], char *path);
 extern int map_lock(struct map_ent **melp);