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

[lvm-devel] [PATCH LVM2] (12/12) sort the allocation requests



This patch adds sorting of allocation requests.

o This patch sorts the allocation request based on its type.
  Allocation for log device is done before allocation of others.


$ diffstat -p1 12.sort_requests.patch
 lib/metadata/lv_manip.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)


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


diff -X dontdiff -urp LVM2.11.log_coverage/lib/metadata/lv_manip.c LVM2.12.sort_requests/lib/metadata/lv_manip.c
--- LVM2.11.log_coverage/lib/metadata/lv_manip.c	2006-10-13 22:47:34.000000000 -0400
+++ LVM2.12.sort_requests/lib/metadata/lv_manip.c	2006-10-13 22:47:52.000000000 -0400
@@ -484,6 +484,24 @@ struct alloc_handle {
 };
 
 /*
+ * sort the request order
+ */
+static int _comp_requests(const void *l, const void *r)
+{
+	const struct allocation_request *lhs = (const struct allocation_request *) l;
+	const struct allocation_request *rhs = (const struct allocation_request *) r;
+
+	/* we prefer log allocation first */
+	if ((lhs->flags & ALLOC_TYPE_LOG) && !(rhs->flags & ALLOC_TYPE_LOG))
+		return 1;
+
+	if (!(lhs->flags & ALLOC_TYPE_LOG) && (rhs->flags & ALLOC_TYPE_LOG))
+		return -1;
+
+	return 0;
+}
+
+/*
  * Preparation for a specific allocation attempt
  */
 static struct alloc_handle *_alloc_init(struct cmd_context *cmd,
@@ -559,6 +577,9 @@ static struct alloc_handle *_alloc_init(
 		req[1].index = req[0].area_count;
 	}
 
+	/* requests will be processed in the order in the array */
+	qsort(req, nr_requests, sizeof(*req), _comp_requests);
+
 	/* size the total request */
 	area_count = 0;
 	requested = 0;

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