diff --git a/WHATS_NEW b/WHATS_NEW index cc5cfc954..7200491da 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.13 - =================================== + Perform high-level free space check before each allocation attempt. Don't allow a node to remove an LV that's exclusively active on anther node. Cope if same PV is included more than once in cmdline PE range list. Set PV size to current device size if it is found to be zero. diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index 54de8bd7f..3c9efbd9f 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -890,8 +890,17 @@ static int _find_parallel_space(struct alloc_handle *ah, alloc_policy_t alloc, uint32_t next_le; struct seg_pvs *spvs; struct list *parallel_pvs; + uint32_t free_pes; + + /* Is there enough total space? */ + free_pes = pv_maps_size(pvms); + if (needed > free_pes) { + log_error("Insufficient free space: %" PRIu32 " extents needed," + " but only %" PRIu32 " available", needed, + free_pes); + return 0; + } - /* FIXME Do calculations on free extent counts before selecting space */ /* FIXME Select log PV appropriately if there isn't one yet */ /* Are there any preceding segments we must follow on from? */ diff --git a/lib/metadata/pv_map.c b/lib/metadata/pv_map.c index 2d10af7e8..f9004ff8f 100644 --- a/lib/metadata/pv_map.c +++ b/lib/metadata/pv_map.c @@ -32,6 +32,7 @@ static void _insert_area(struct list *head, struct pv_area *a) } list_add(&pva->list, &a->list); + a->map->pe_count += a->count; } static int _create_single_area(struct dm_pool *mem, struct pv_map *pvm, @@ -191,6 +192,7 @@ struct list *create_pv_maps(struct dm_pool *mem, struct volume_group *vg, void consume_pv_area(struct pv_area *pva, uint32_t to_go) { list_del(&pva->list); + pva->map->pe_count -= pva->count; assert(to_go <= pva->count); @@ -201,3 +203,14 @@ void consume_pv_area(struct pv_area *pva, uint32_t to_go) _insert_area(&pva->map->areas, pva); } } + +uint32_t pv_maps_size(struct list *pvms) +{ + struct pv_map *pvm; + uint32_t pe_count = 0; + + list_iterate_items(pvm, pvms) + pe_count += pvm->pe_count; + + return pe_count; +} diff --git a/lib/metadata/pv_map.h b/lib/metadata/pv_map.h index 431eda93b..a5ade282a 100644 --- a/lib/metadata/pv_map.h +++ b/lib/metadata/pv_map.h @@ -37,6 +37,7 @@ struct pv_area { struct pv_map { struct physical_volume *pv; struct list areas; /* struct pv_areas */ + uint32_t pe_count; /* Total number of PEs */ struct list list; }; @@ -49,4 +50,6 @@ struct list *create_pv_maps(struct dm_pool *mem, struct volume_group *vg, void consume_pv_area(struct pv_area *area, uint32_t to_go); +uint32_t pv_maps_size(struct list *pvms); + #endif