From e5508b361d970a7657c9f81303223fa114bdcd9b Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Tue, 1 Feb 2011 14:44:02 +1100 Subject: [PATCH] Allow domain_test to report that no domains were found. 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 --- Assemble.c | 2 +- Incremental.c | 6 +++--- Monitor.c | 2 +- policy.c | 7 +++++-- util.c | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Assemble.c b/Assemble.c index a9c7875a..b3f54ce4 100644 --- a/Assemble.c +++ b/Assemble.c @@ -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 diff --git a/Incremental.c b/Incremental.c index 0d0a1fdc..52558e40 100644 --- a/Incremental.c +++ b/Incremental.c @@ -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)) diff --git a/Monitor.c b/Monitor.c index adc89d08..452f62d8 100644 --- 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); } diff --git a/policy.c b/policy.c index 38b0072b..afb640f5 100644 --- 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 a0d8283c..81f93601 100644 --- 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); } -- 2.39.2