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

[lvm-devel] [PATCH LVM2] (3/12) remove ix_offset from _find_parallel_space()



This patch removes ix_offset and related variables.

o Current code splits areas[] array in 2 parts.
  The first part is for contiguous areas and the 2nd part is for
  sorted-by-length areas.
  However, these 2 use are exclusive.
  If you are trying contiguous allocation, the 2nd part isn't used.
  Vice versa.


$ diffstat -p1 03.remove_ix_offset.patch
 lib/metadata/lv_manip.c |   66 ++++++++++++++++++++-------------------------
 1 file changed, 28 insertions(+), 38 deletions(-)


-- 
Jun'ichi Nomura, NEC Corporation of America

diff -X dontdiff -urp LVM2.02.alloc_requests/lib/metadata/lv_manip.c LVM2.03.remove_ix_offset/lib/metadata/lv_manip.c
--- LVM2.02.alloc_requests/lib/metadata/lv_manip.c	2006-10-13 20:58:46.000000000 -0400
+++ LVM2.03.remove_ix_offset/lib/metadata/lv_manip.c	2006-10-13 21:14:12.000000000 -0400
@@ -1047,33 +1047,24 @@ static int _find_parallel_space(struct a
 	struct pv_area *pva;
 	struct pv_list *pvl;
 	unsigned already_found_one = 0;
-	unsigned contiguous = 0, cling = 0, preferred_count = 0;
 	unsigned ix, areas_index;
-	uint32_t ix_offset = 0;	/* Offset for non-preferred allocations */
 	uint32_t req_len, goal, current_le;
 	struct seg_pvs *spvs;
 	struct list *parallel_pvs;
 
-	/* Are there any preceding segments we must follow on from? */
-	if (prev_lvseg) {
-		if (!_count_parallel_areas(prev_lvseg, &ix_offset))
-			return 0;
-		if ((alloc == ALLOC_CONTIGUOUS))
-			contiguous = 1;
-		else if ((alloc == ALLOC_CLING))
-			cling = 1;
-		else
-			ix_offset = 0;
-	}
+	/* ALLOC_CONTIGUOUS overrides can_split */
+	can_split = (alloc == ALLOC_CONTIGUOUS) ? 0 : can_split;
 
 	goal = ah->le + (req->len * req->multiple);
 
 	/* FIXME anywhere doesn't find all space yet */
-	/* ix_offset holds the number of allocations that must be contiguous */
-	/* ix holds the number of areas found on other PVs */
 	do {
+		/*
+		 * In case of ALLOC_CONTIGUOUS or ALLOC_CLING with prev_lvseg,
+		 * ix holds just the number of areas ready for allocation.
+		 * For other policies, it holds the last index of areas[].
+		 */
 		ix = 0;
-		preferred_count = 0;
 
 		/*
 		 * If there are existing parallel PVs, pick up subset
@@ -1111,31 +1102,29 @@ static int _find_parallel_space(struct a
 			already_found_one = 0;
 			/* First area in each list is the largest */
 			list_iterate_items(pva, &pvm->areas) {
-				if (contiguous) {
-					if (prev_lvseg &&
-					    _check_contiguous(ah->cmd,
+				if (prev_lvseg && alloc == ALLOC_CONTIGUOUS) {
+					if (_check_contiguous(ah->cmd,
 							      prev_lvseg,
 							      pva, 
 							      req->index,
 							      req->index + req->area_count - 1,
 							      areas,
 							      areas_size)) {
-						preferred_count++;
+						ix++;
 						goto next_pv;
 					}
 					continue;
 				}
 
-				if (cling) {
-					if (prev_lvseg &&
-					    _check_cling(ah->cmd,
+				if (prev_lvseg && alloc == ALLOC_CLING) {
+					if (_check_cling(ah->cmd,
 							   prev_lvseg,
 							   pva,
 							   req->index,
 							   req->index + req->area_count - 1,
 							   areas,
 							   areas_size)) {
-						preferred_count++;
+						ix++;
 					}
 					goto next_pv;
 				}
@@ -1150,7 +1139,7 @@ static int _find_parallel_space(struct a
 					already_found_one = 1;
 				}
 
-				areas[ix + ix_offset - 1] = pva;
+				areas[ix - 1] = pva;
 
 				goto next_pv;
 			}
@@ -1159,27 +1148,27 @@ static int _find_parallel_space(struct a
 				break;
 		}
 
-		if (contiguous || cling) {
-			if (preferred_count < req->area_count)
-				break;
-		} else if (ix < req->area_count)
+		if (ix < req->area_count)
 			break;
 
-		/* sort the areas so we allocate from the biggest */
-		if (ix > 1)
-			qsort(areas + ix_offset, ix, sizeof(*areas),
-			      _comp_area);
-
-		areas_index = ix_offset;
-		if (contiguous || cling)
+		/*
+		 * sort the areas so we allocate from the biggest.
+		 * Don't try to re-order areas[] if areas are assigned
+		 * based on PV index. (ALLOC_CONTIGUOUS or ALLOC_CLING)
+		 */
+		areas_index = 0;
+		if (prev_lvseg &&
+		    (alloc == ALLOC_CONTIGUOUS || alloc == ALLOC_CLING))
 			areas_index = req->index;
+		else if (ix > 1)
+			qsort(areas, ix, sizeof(*areas), _comp_area);
 
 		if (!_alloc_parallel_area(ah, req, req_len, &areas[areas_index])) {
 			stack;
 			return 0;
 		}
 
-	} while (!contiguous && req->allocated != req->len && can_split);
+	} while (req->allocated != req->len && can_split);
 
 	return 1;
 }
@@ -1265,7 +1254,8 @@ static int _allocate(struct alloc_handle
 		uint32_t prev_lvseg_areas;
 		if (!_count_parallel_areas(prev_lvseg, &prev_lvseg_areas))
 			return 0;
-		areas_size += prev_lvseg_areas;
+		if (prev_lvseg_areas > areas_size)
+			areas_size = prev_lvseg_areas;
 	}
 
 	/* Allocate an array of pv_areas to hold the largest space on each PV */

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