NeilBrown: map: rebuild map if it doesn't exist.

Martin F. Krafft madduck at alioth.debian.org
Mon Feb 16 11:24:11 UTC 2009


Module: mdadm
Branch: build
Commit: 3a56f223e94106102eed3fd2b08d3ecad353361b
URL:    http://git.debian.org/?p=pkg-mdadm/mdadm.git;a=commit;h=3a56f223e94106102eed3fd2b08d3ecad353361b

Author: NeilBrown <neilb at suse.de>
Date:   Thu Dec 18 16:23:46 2008 +1100

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 at suse.de>

---

 Incremental.c |   47 -----------------------------------------------
 mapfile.c     |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 47 deletions(-)

diff --git a/Incremental.c b/Incremental.c
index 1d326fd..08e0e6f 100644
--- a/Incremental.c
+++ b/Incremental.c
@@ -603,53 +603,6 @@ static int count_active(struct supertype *st, int mdfd, char **availp,
 	return cnt + cnt1;
 }
 
-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);
-}
-
 int IncrementalScan(int verbose)
 {
 	/* look at every device listed in the 'map' file.
diff --git a/mapfile.c b/mapfile.c
index f616f15..0d0aa39 100644
--- a/mapfile.c
+++ b/mapfile.c
@@ -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);
+}




More information about the pkg-mdadm-commits mailing list