summaryrefslogtreecommitdiff
path: root/Monitor.c
diff options
context:
space:
mode:
authorAnna Czarnowska <anna.czarnowska@intel.com>2011-01-05 14:34:14 +1100
committerNeilBrown <neilb@suse.de>2011-01-05 14:34:14 +1100
commit326727d9c985b8f58fd53d6efcc4bd6e1721bfb5 (patch)
tree8e39e3946869d8f75b9772115714c1c0a84a1109 /Monitor.c
parented7fc6b4d91a5342886ba6fe6d175f69f0875d3b (diff)
Use one function chosing spares from container
container_chose_spares in Monitor.c and get_spares_for_grow in super-intel.c do the same thing: search for spares in a container. Another version will also be needed for Incremental so a more general solution is presented here and applied in two previous contexts. Normally domlist==NULL would lead an empty list but this is typically checked earlier so here it is interpreted as "do not test domains". Signed-off-by: Anna Czarnowska <anna.czarnowska@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'Monitor.c')
-rw-r--r--Monitor.c51
1 files changed, 13 insertions, 38 deletions
diff --git a/Monitor.c b/Monitor.c
index e79f658b..00db53f2 100644
--- a/Monitor.c
+++ b/Monitor.c
@@ -828,59 +828,34 @@ static dev_t container_choose_spare(struct state *from, struct state *to,
/* This is similar to choose_spare, but we cannot trust devstate,
* so we need to read the metadata instead
*/
-
+ struct mdinfo *list;
struct supertype *st = from->metadata;
int fd = open(from->devname, O_RDONLY);
int err;
- struct mdinfo *disks, *d;
dev_t dev = 0;
if (fd < 0)
return 0;
- if (!st->ss->getinfo_super_disks)
+ if (!st->ss->getinfo_super_disks) {
+ close(fd);
return 0;
+ }
err = st->ss->load_container(st, fd, NULL);
close(fd);
if (err)
return 0;
-
- disks = st->ss->getinfo_super_disks(st);
- st->ss->free_super(st);
-
- if (!disks)
- return 0;
- for (d = disks->devs ; d && !dev ; d = d->next) {
- if (d->disk.state == 0) {
- struct dev_policy *pol;
- unsigned long long dev_size;
- dev = makedev(d->disk.major,d->disk.minor);
-
- if (min_size &&
- dev_size_from_id(dev, &dev_size) &&
- dev_size < min_size) {
- dev = 0;
- continue;
- }
- if (from == to)
- /* Just checking if destination already has
- * a spare, no need to check policy, we are
- * done.
- */
- break;
-
- pol = devnum_policy(dev);
- if (from->spare_group)
- pol_add(&pol, pol_domain,
- from->spare_group, NULL);
- if (!domain_test(domlist, pol, to->metadata->ss->name))
- dev = 0;
-
- dev_policy_free(pol);
- }
+ /* We only need one spare so full list not needed */
+ list = container_choose_spares(st, min_size, domlist, from->spare_group,
+ to->metadata->ss->name, 1);
+ if (list) {
+ struct mdinfo *disks = list->devs;
+ if (disks)
+ dev = makedev(disks->disk.major, disks->disk.minor);
+ sysfs_free(list);
}
- sysfs_free(disks);
+ st->ss->free_super(st);
return dev;
}