[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[lvm-devel] [PATCH LVM2] (10/12) calculate free pe counts before allocation attempt



This patch adds calculation of free pe counts and checks it
before doing any allocation attempt.


$ diffstat -p1 10.calcfree.patch
 lib/metadata/lv_manip.c |   30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)


Thanks,
-- 
Jun'ichi Nomura, NEC Corporation of America


diff -X dontdiff -urp LVM2.09.lvconvert/lib/metadata/lv_manip.c LVM2.10.calcfree/lib/metadata/lv_manip.c
--- LVM2.09.lvconvert/lib/metadata/lv_manip.c	2006-10-13 22:28:30.000000000 -0400
+++ LVM2.10.calcfree/lib/metadata/lv_manip.c	2006-10-13 22:28:35.000000000 -0400
@@ -1366,6 +1366,25 @@ static int _check_area_constraints(struc
 }
 
 /*
+ * Returns total number of free pe count in pv_map list
+ */
+static uint32_t _total_pe_count(struct list *pvms)
+{
+	struct pv_map *pvm;
+	struct pv_area *pva;
+	uint32_t count = 0;
+
+	list_iterate_items(pvm, pvms) {
+		if (list_empty(&pvm->areas))
+			continue;
+		list_iterate_items(pva, &pvm->areas)
+			count += pva->count;
+	}
+
+	return count;
+}
+
+/*
  * Choose sets of parallel areas to use, respecting any constraints.
  */
 static int _find_parallel_space(struct alloc_handle *ah, 
@@ -1522,7 +1541,7 @@ static int _allocate(struct alloc_handle
 		     struct logical_volume *lv, uint32_t status,
 		     struct list *allocatable_pvs)
 {
-	struct pv_area **areas;
+	struct pv_area **areas = NULL;
 	uint32_t old_allocated;
 	struct lv_segment *prev_lvseg = NULL;
 	unsigned can_split = 1;	/* Are we allowed more than one segment? */
@@ -1549,8 +1568,6 @@ static int _allocate(struct alloc_handle
 		return 0;
 	}
 
-	/* FIXME Calculate free extent counts before trying allocation */
-
 	if (!_log_parallel_areas(ah->mem, ah->parallel_areas))
 		stack;
 
@@ -1565,6 +1582,10 @@ static int _allocate(struct alloc_handle
 		areas_size = ah->area_count;
 	}
 
+	/* No space left to fulfill this request */
+ 	if (_total_pe_count(pvms) < ah->requested)
+		goto finished;
+
 	/* Upper bound if none of the PVs in prev_lvseg is in pvms */
 	if (prev_lvseg) {
 		uint32_t prev_lvseg_areas;
@@ -1643,7 +1664,8 @@ static int _allocate(struct alloc_handle
 	r = 1;
 
       out:
-	dm_free(areas);
+	if (areas)
+		dm_free(areas);
 	return r;
 }
 

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]