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 <neilb@suse.de>
This commit is contained in:
NeilBrown 2011-02-01 14:44:02 +11:00
parent d11128690b
commit e5508b361d
5 changed files with 11 additions and 8 deletions

View 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

View 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))

View File

@ -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);
}

View File

@ -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);

2
util.c
View File

@ -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);
}