diff options
author | NeilBrown <neilb@suse.de> | 2008-12-18 06:23:46 +0100 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2008-12-18 06:23:46 +0100 |
commit | 3a56f223e94106102eed3fd2b08d3ecad353361b (patch) | |
tree | 8604aae606146e65447d58a653a69a7a0da72721 /mapfile.c | |
parent | Assemble: set stripe_cache_size properly when restarting a reshape. (diff) | |
download | mdadm-3a56f223e94106102eed3fd2b08d3ecad353361b.tar.xz mdadm-3a56f223e94106102eed3fd2b08d3ecad353361b.zip |
map: rebuild map if it doesn't exist.
It is possible for some arrays to be created e.g. by initrd, and so
not get mentioned in /var/run/mdadm/map.
As "-I" depends on things being listed in 'map', we create it by
scanning all devices if it doesn't exist.
Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'mapfile.c')
-rw-r--r-- | mapfile.c | 53 |
1 files changed, 53 insertions, 0 deletions
@@ -113,6 +113,12 @@ void map_read(struct map_ent **melp) f = fopen("/var/run/mdadm/map", "r"); if (!f) f = fopen("/var/run/mdadm.map", "r"); + if (!f) { + RebuildMap(); + f = fopen("/var/run/mdadm/map", "r"); + } + if (!f) + f = fopen("/var/run/mdadm.map", "r"); if (!f) return; @@ -195,3 +201,50 @@ struct map_ent *map_by_uuid(struct map_ent **map, int uuid[4]) return NULL; } + +void RebuildMap(void) +{ + struct mdstat_ent *mdstat = mdstat_read(0, 0); + struct mdstat_ent *md; + struct map_ent *map = NULL; + int mdp = get_mdp_major(); + + for (md = mdstat ; md ; md = md->next) { + struct mdinfo *sra = sysfs_read(-1, md->devnum, GET_DEVS); + struct mdinfo *sd; + + for (sd = sra->devs ; sd ; sd = sd->next) { + char dn[30]; + int dfd; + int ok; + struct supertype *st; + char *path; + struct mdinfo info; + + sprintf(dn, "%d:%d", sd->disk.major, sd->disk.minor); + dfd = dev_open(dn, O_RDONLY); + if (dfd < 0) + continue; + st = guess_super(dfd); + if ( st == NULL) + ok = -1; + else + ok = st->ss->load_super(st, dfd, NULL); + close(dfd); + if (ok != 0) + continue; + st->ss->getinfo_super(st, &info); + if (md->devnum > 0) + path = map_dev(MD_MAJOR, md->devnum, 0); + else + path = map_dev(mdp, (-1-md->devnum)<< 6, 0); + map_add(&map, md->devnum, st->ss->major, + st->minor_version, + info.uuid, path ? : "/unknown"); + st->ss->free_super(st); + break; + } + } + map_write(map); + map_free(map); +} |