Skip to contentSkip to conversation

toollib: read vgs before processing

PATCH New David Teigland 1 participant 1 message Mar 18, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 toollib: read vgs before processing

In process_each_vg,lv, read all vgs, then process each, rather than reading and processing one at a time.

Locking is currently hidden within vg_read, so another effect of this change is that all locks are acquired and held together at the start rather than being acquired and released individually.

---
 lib/datastruct/str_list.c |  38 +++++++++++
 lib/datastruct/str_list.h |   1 +
 tools/toollib.c           | 169 ++++++++++++++++++++++++++++++++++++----------
 3 files changed, 173 insertions(+), 35 deletions(-)
lib/datastruct/str_list.c +38 -0
index dfce69c..374de5c 100644
@@ -50,6 +50,44 @@ int str_list_add(struct dm_pool *mem, struct dm_list *sll, const char *str)
 	return 1;
 }
 
+int str_list_add_order(struct dm_pool *mem, struct dm_list *sll, const char *str)
+{
+	struct str_list *sl_tmp;
+	struct str_list *sl_new;
+
+	if (!str)
+		return_0;
+
+	/* Already in list? */
+	if (str_list_match_item(sll, str))
+		return 1;
+
+	if (!(sl_new = dm_pool_alloc(mem, sizeof(*sl_new))))
+		return_0;
+
+	sl_new->str = str;
+
+	if (dm_list_empty(sll)) {
+		dm_list_add(sll, &sl_new->list);
+		return 1;
+	}
+
+	dm_list_iterate_items(sl_tmp, sll) {
+		/*
+		 * If new str (s1) is less than existing/tmp str (s2),
+		 * then break and insert new before existing.
+		 */
+		if (strcmp(sl_new->str, sl_tmp->str) < 0)
+			break;
+	}
+
+	sl_new->list.n    = &sl_tmp->list;
+	sl_new->list.p    = sl_tmp->list.p;
+	sl_tmp->list.p->n = &sl_new->list;
+	sl_tmp->list.p    = &sl_new->list;
+	return 1;
+}
+
 void str_list_del(struct dm_list *sll, const char *str)
 {
 	struct dm_list *slh, *slht;
lib/datastruct/str_list.h +1 -0
index 42f47da..bab6d9b 100644
@@ -18,6 +18,7 @@
 
 struct dm_list *str_list_create(struct dm_pool *mem);
 int str_list_add(struct dm_pool *mem, struct dm_list *sll, const char *str);
+int str_list_add_order(struct dm_pool *mem, struct dm_list *sll, const char *str);
 void str_list_del(struct dm_list *sll, const char *str);
 int str_list_match_item(const struct dm_list *sll, const char *str);
 int str_list_match_list(const struct dm_list *sll, const struct dm_list *sll2, const char **tag_matched);
tools/toollib.c +134 -35

284 lines not on this page · raw message

Signature · 1 line
1.8.1.rc1.5.g7e0651a