From 5f7e44b29fe3fd9bf77c27e375c92046bf00d0c4 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 23 Nov 2010 15:31:18 +1100 Subject: [PATCH] Initialize st->devnum and st->container_dev in super_by_fd Precludes needing to deduce this information later, like in Detail.c and soon in Grow.c. Signed-off-by: Dan Williams Signed-off-by: NeilBrown --- Detail.c | 11 ++++------- util.c | 10 +++++++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Detail.c b/Detail.c index 2cd4e9d3..94156288 100644 --- a/Detail.c +++ b/Detail.c @@ -98,16 +98,13 @@ int Detail(char *dev, int brief, int export, int test, char *homehost) if (st) max_disks = st->max_devs; - if (sra && is_subarray(sra->text_version) && - strchr(sra->text_version+1, '/')) { + if (subarray) { /* This is a subarray of some container. * We want the name of the container, and the member */ - char *s = strchr(sra->text_version+1, '/'); - int dn; - *s++ = '\0'; - member = s; - dn = devname2devnum(sra->text_version+1); + int dn = st->container_dev; + + member = subarray; container = map_dev(dev2major(dn), dev2minor(dn), 1); } diff --git a/util.c b/util.c index e26aba91..b018d299 100644 --- a/util.c +++ b/util.c @@ -1068,6 +1068,7 @@ struct supertype *super_by_fd(int fd, char **subarrayp) char version[20]; int i; char *subarray = NULL; + int container = NoMdDev; sra = sysfs_read(fd, 0, GET_VERSION); @@ -1089,15 +1090,15 @@ struct supertype *super_by_fd(int fd, char **subarrayp) } if (minor == -2 && is_subarray(verstr)) { char *dev = verstr+1; + subarray = strchr(dev, '/'); - int devnum; if (subarray) *subarray++ = '\0'; - devnum = devname2devnum(dev); subarray = strdup(subarray); + container = devname2devnum(dev); if (sra) sysfs_free(sra); - sra = sysfs_read(-1, devnum, GET_VERSION); + sra = sysfs_read(-1, container, GET_VERSION); if (sra && sra->text_version[0]) verstr = sra->text_version; else @@ -1113,8 +1114,11 @@ struct supertype *super_by_fd(int fd, char **subarrayp) st->sb = NULL; if (subarrayp) *subarrayp = subarray; + st->container_dev = container; + st->devnum = fd2devnum(fd); } else free(subarray); + return st; } #endif /* !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO) */ -- 2.39.2