diff options
author | NeilBrown <neilb@suse.de> | 2008-12-18 06:56:13 +0100 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2008-12-18 06:56:13 +0100 |
commit | 8a659c33212f85cc0dcecc759b7b36b0bb2b4fe4 (patch) | |
tree | 8c09f1ce1ab41c6218a0e4705e3227bc7b7c022b /mapfile.c | |
parent | DDF: improve --examine output (diff) | |
parent | map: rebuild map if it doesn't exist. (diff) | |
download | mdadm-8a659c33212f85cc0dcecc759b7b36b0bb2b4fe4.tar.xz mdadm-8a659c33212f85cc0dcecc759b7b36b0bb2b4fe4.zip |
Merge branch 'master' into devel-3.0
Conflicts:
Assemble.c
Incremental.c
Kill.c
ReadMe.c
inventory
mapfile.c
mdadm.8
mdadm.spec
mdassemble.8
Diffstat (limited to 'mapfile.c')
-rw-r--r-- | mapfile.c | 59 |
1 files changed, 59 insertions, 0 deletions
@@ -152,6 +152,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; @@ -279,3 +285,56 @@ struct map_ent *map_by_name(struct map_ent **map, char *name) } 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, + info.text_version, + info.uuid, path ? : "/unknown"); + st->ss->free_super(st); + break; + } + sysfs_free(sra); + } + map_write(map); + map_free(map); + for (md = mdstat ; md ; md = md->next) { + struct mdinfo *sra = sysfs_read(-1, md->devnum, GET_VERSION); + sysfs_uevent(sra, "change"); + sysfs_free(sra); + } +} |