From 3c558363a1991430e8a9e10c93ee9ee3f8996940 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Tue, 19 Aug 2008 17:55:15 +1000 Subject: [PATCH] Factor out test for subarray version string. We are about to change the syntax of the version string for 'subarray's. So factor out the test into a single function. Signed-off-by: NeilBrown --- Create.c | 2 +- Manage.c | 4 ++-- managemon.c | 3 ++- mdadm.h | 5 +++++ util.c | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Create.c b/Create.c index 69192abb..9058af18 100644 --- a/Create.c +++ b/Create.c @@ -523,7 +523,7 @@ int Create(struct supertype *st, char *mddev, int mdfd, st->ss->getinfo_super(st, &info); if (did_default && verbose >= 0) { - if (info.text_version[0] == '/') { + if (is_subarray(info.text_version)) { int dnum = devname2devnum(info.text_version+1); char *path; int mdp = get_mdp_major(); diff --git a/Manage.c b/Manage.c index 98f9fb76..084e2701 100644 --- a/Manage.c +++ b/Manage.c @@ -123,7 +123,7 @@ int Manage_runstop(char *devname, int fd, int runstop, int quiet) mdi = sysfs_read(fd, -1, GET_LEVEL|GET_VERSION); if (mdi && mdi->array.level > 0 && - mdi->text_version[0] == '/') { + is_subarray(mdi->text_version)) { char *cp; /* This is mdmon managed. */ @@ -147,7 +147,7 @@ int Manage_runstop(char *devname, int fd, int runstop, int quiet) } else if (mdi && mdi->array.major_version == -1 && mdi->array.minor_version == -2 && - mdi->text_version[0] != '/') { + !is_subarray(mdi->text_version)) { /* container, possibly mdmon-managed. * Make sure mdmon isn't opening it, which * would interfere with the 'stop' diff --git a/managemon.c b/managemon.c index 96120077..1c329c58 100644 --- a/managemon.c +++ b/managemon.c @@ -492,7 +492,8 @@ void manage(struct mdstat_ent *mdstat, struct supertype *container) continue; } if (mdstat->metadata_version == NULL || - strncmp(mdstat->metadata_version, "external:/", 10) != 0 || + strncmp(mdstat->metadata_version, "external:", 9) != 0 || + !is_subarray(mdstat->metadata_version+9) || strncmp(mdstat->metadata_version+10, container->devname, strlen(container->devname)) != 0 || mdstat->metadata_version[10+strlen(container->devname)] diff --git a/mdadm.h b/mdadm.h index 3e47fea0..489fe30c 100644 --- a/mdadm.h +++ b/mdadm.h @@ -805,6 +805,11 @@ static inline int ROUND_UP(int a, int base) return ((a+base-1)/base)*base; } +static inline int is_subarray(char *vers) +{ + return (*vers == '/'); +} + #define LEVEL_MULTIPATH (-4) #define LEVEL_LINEAR (-1) #define LEVEL_FAULTY (-5) diff --git a/util.c b/util.c index 3bf4cbe3..60fe6c0a 100644 --- a/util.c +++ b/util.c @@ -821,7 +821,7 @@ struct supertype *super_by_fd(int fd) sprintf(version, "%d.%d", vers, minor); verstr = version; } - if (minor == -2 && verstr[0] == '/') { + if (minor == -2 && is_subarray(verstr)) { char *dev = verstr+1; subarray = strchr(dev, '/'); int devnum; -- 2.39.2