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

[lvm-devel] [PATCH LVM2] Clean up the iteration through policies



Hi,

This patch will clean up the iteration through allocation
policies.

Current code just duplicates the lines with changing only
the policy parameter, which is hard to read and error prone.

Patch applicable to LVM2 2.02.16.

Thanks,
-- 
Jun'ichi Nomura, NEC Corporation of America
Iteration of _find_parallel_space through applicable policies
should avoid unnecessary code duplication.

Patch applicable to LVM2 2.02.16.

---
 lib/metadata/lv_manip.c |   63 ++++++++++++++++--------------------------------
 1 file changed, 22 insertions(+), 41 deletions(-)

Index: LVM2.cvs/lib/metadata/lv_manip.c
===================================================================
--- LVM2.cvs.orig/lib/metadata/lv_manip.c	2006-12-13 00:08:45.000000000 -0500
+++ LVM2.cvs/lib/metadata/lv_manip.c	2006-12-13 00:08:46.000000000 -0500
@@ -1044,6 +1044,15 @@ static int _find_parallel_space(struct a
 	return 1;
 }
 
+/* allocation policies will be applied in this order */
+static alloc_policy_t alloc_policies[] = {
+	ALLOC_CONTIGUOUS,
+	ALLOC_CLING,
+	ALLOC_NORMAL,
+	ALLOC_ANYWHERE,
+	ALLOC_INVALID	/* terminate the iteration */
+};
+
 /*
  * Allocate several segments, each the same size, in parallel.
  * If mirrored_pv and mirrored_pe are supplied, it is used as
@@ -1065,6 +1074,7 @@ static int _allocate(struct alloc_handle
 	int r = 0;
 	struct list *pvms;
 	uint32_t areas_size;
+	alloc_policy_t *ap;
 
 	if (allocated >= new_extents && !ah->log_count) {
 		log_error("_allocate called with no work to do!");
@@ -1110,50 +1120,21 @@ static int _allocate(struct alloc_handle
 		return 0;
 	}
 
-	old_allocated = allocated;
-	if (!_find_parallel_space(ah, ALLOC_CONTIGUOUS, pvms, areas,
-				  areas_size, can_split,
-				  prev_lvseg, &allocated, new_extents)) {
-		stack;
-		goto out;
-	}
-
-	if ((allocated == new_extents) || (ah->alloc == ALLOC_CONTIGUOUS) ||
-	    (!can_split && (allocated != old_allocated)))
-		goto finished;
-
-	old_allocated = allocated;
-	if (!_find_parallel_space(ah, ALLOC_CLING, pvms, areas,
-				  areas_size, can_split,
-				  prev_lvseg, &allocated, new_extents)) {
-		stack;
-		goto out;
-	}
-
-	if ((allocated == new_extents) || (ah->alloc == ALLOC_CLING) ||
-	    (!can_split && (allocated != old_allocated)))
-		goto finished;
-
-	old_allocated = allocated;
-	if (!_find_parallel_space(ah, ALLOC_NORMAL, pvms, areas,
-				  areas_size, can_split,
-				  prev_lvseg, &allocated, new_extents)) {
-		stack;
-		goto out;
-	}
+	for (ap = alloc_policies; *ap != ALLOC_INVALID; ap++) {
+		old_allocated = allocated;
+		if (!_find_parallel_space(ah, *ap, pvms, areas,
+					  areas_size, can_split,
+					  prev_lvseg, &allocated,
+					  new_extents)) {
+			stack;
+			goto out;
+		}
 
-	if ((allocated == new_extents) || (ah->alloc == ALLOC_NORMAL) ||
-	    (!can_split && (allocated != old_allocated)))
-		goto finished;
-
-	if (!_find_parallel_space(ah, ALLOC_ANYWHERE, pvms, areas,
-				  areas_size, can_split,
-				  prev_lvseg, &allocated, new_extents)) {
-		stack;
-		goto out;
+		if ((allocated == new_extents) || (ah->alloc == *ap) ||
+		    (!can_split && (allocated != old_allocated)))
+			break;
 	}
 
-      finished:
 	if (allocated != new_extents) {
 		log_error("Insufficient suitable %sallocatable extents "
 			  "for logical volume %s: %u more required",

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