]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Allow domain_test to report that no domains were found.
authorNeilBrown <neilb@suse.de>
Tue, 1 Feb 2011 03:44:02 +0000 (14:44 +1100)
committerNeilBrown <neilb@suse.de>
Tue, 1 Feb 2011 03:44:02 +0000 (14:44 +1100)
Sometime we will need to know the difference between no domains found
and domains didn't match.
So allow domain_test to return different values and fix up all callers
to maintain current behaviour.

Signed-off-by: NeilBrown <neilb@suse.de>
Assemble.c
Incremental.c
Monitor.c
policy.c
util.c

index a9c7875af3d61527933dda821273bf1d1cc31fd1..b3f54ce43a811b28f425bf1f92b9cb96361af19e 100644 (file)
@@ -597,7 +597,7 @@ int Assemble(struct supertype *st, char *mddev,
                } else {
                        struct dev_policy *pol = NULL;
                        pol = devnum_policy(stb.st_rdev);
-                       if (domain_test(domains, pol, NULL))
+                       if (domain_test(domains, pol, NULL) == 1)
                                /* take this spare if domains match */
                                tmpdev->used = 1;
                        else
index 0d0a1fdcae90420bfc4b0104bedda434c9429138..52558e4059d42aa4dd5fd7fb51925055ddaabcfe 100644 (file)
@@ -995,7 +995,7 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                }
 
                dl = domain_from_array(sra, st2->ss->name);
-               if (!domain_test(dl, pol, st2->ss->name)) {
+               if (domain_test(dl, pol, st2->ss->name) != 1) {
                        /* domain test fails */
                        if (verbose > 1)
                                fprintf(stderr, Name ": not adding %s to %s as"
@@ -1111,7 +1111,7 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                pol2 = path_policy(de->d_name, type_disk);
 
                domain_merge(&domlist, pol2, st ? st->ss->name : NULL);
-               if (domain_test(domlist, pol, st ? st->ss->name : NULL) == 0)
+               if (domain_test(domlist, pol, st ? st->ss->name : NULL) != 1)
                        /* new device is incompatible with this device. */
                        goto next;
 
@@ -1137,7 +1137,7 @@ static int partition_try_spare(char *devname, int *dfdp, struct dev_policy *pol,
                if (!st) {
                        /* Check domain policy again, this time referring to metadata */
                        domain_merge(&domlist, pol2, st2->ss->name);
-                       if (domain_test(domlist, pol, st2->ss->name) == 0)
+                       if (domain_test(domlist, pol, st2->ss->name) != 1)
                                /* Incompatible devices for this metadata type */
                                goto next;
                        if (!policy_action_allows(pol, st2->ss->name, act_spare))
index adc89d080a5bf7fd196953469b0c0d6a581760a9..452f62d8d1b13cc78ee6c7897c1f135ebf6fb30f 100644 (file)
--- a/Monitor.c
+++ b/Monitor.c
@@ -778,7 +778,7 @@ static dev_t choose_spare(struct state *from, struct state *to,
                        if (from->spare_group)
                                pol_add(&pol, pol_domain,
                                        from->spare_group, NULL);
-                       if (domain_test(domlist, pol, to->metadata->ss->name))
+                       if (domain_test(domlist, pol, to->metadata->ss->name) == 1)
                            dev = from->devid[d];
                        dev_policy_free(pol);
                }
index 38b0072b5d111ab6f76168185c575efc0a5d4d8c..afb640f594a48c74896b25de9cc59cf756a83b72 100644 (file)
--- a/policy.c
+++ b/policy.c
@@ -648,9 +648,12 @@ int domain_test(struct domainlist *dom, struct dev_policy *pol,
        /* Check that all domains in pol (for metadata) are also in
         * dom.  Both lists are sorted.
         * If pol has no domains, we don't really know about this device
-        * so we reject the match.
+        * so we allow caller to choose:
+        * -1:  has no domains
+        *  0:  has domains, not all match
+        *  1:  has domains, all match
         */
-       int found_any = 0;
+       int found_any = -1;
        struct dev_policy *p;
 
        pol = pol_find(pol, pol_domain);
diff --git a/util.c b/util.c
index a0d8283c79bdcedf7f96e18b7b63acef28595bb1..81f936018ff4c6367a55822719ed3be0a6323a31 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1956,7 +1956,7 @@ struct mdinfo *container_choose_spares(struct supertype *st,
                                if (spare_group)
                                        pol_add(&pol, pol_domain,
                                                spare_group, NULL);
-                               if (!domain_test(domlist, pol, metadata))
+                               if (domain_test(domlist, pol, metadata) != 1)
                                        found = 0;
                                dev_policy_free(pol);
                        }