]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Factor out test for subarray version string.
authorNeilBrown <neilb@suse.de>
Tue, 19 Aug 2008 07:55:15 +0000 (17:55 +1000)
committerNeilBrown <neilb@suse.de>
Tue, 19 Aug 2008 07:55:15 +0000 (17:55 +1000)
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 <neilb@suse.de>
Create.c
Manage.c
managemon.c
mdadm.h
util.c

index 69192abb23b415147a19c60c898dd221d722e329..9058af1837bef34de8dc0ec776174bfb8c6c689f 100644 (file)
--- 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();
index 98f9fb7684e3b13e54b14f7af92bb40f0a756047..084e2701324197d2302912d6ea17f276e882445f 100644 (file)
--- 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'
index 9612007752e1cd6f1771b45629fea2313e6b4780..1c329c583a2a8d58ce7d42bb311e21e7bcd28b8e 100644 (file)
@@ -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 3e47fea0bfa71bd6591590178dfa92f2c4a1d1de..489fe30c5e7eab59380313ce9f004dba5dca701d 100644 (file)
--- 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 3bf4cbe31d832eb124f5bf37315ec67f70ce912c..60fe6c0a0c2f9f1d97727da18a9de7f449f41793 100644 (file)
--- 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;