Skip to contentSkip to conversation

Misc patches

PATCH New Zdenek Kabelac 1 participant 17 messages Feb 11, 2011

lore
Share & tools
lore
#0 lore raw

cover Misc patches

Mixture of patches - should be easy for overview:

Hash needs decisions - I'd would vote for simple J.Belkins (Version3 seems too complex for our use case)

Do we still want to support build without DEVMAPPER_SUPPORT? (patch is fixing build in this case - but maybe we should drop this completely?)

Adding few missing stack traces.

Hiding some unused variables in comments (keeping it in sources).

Zdenek Kabelac (16):
Align orphan strings
Perf: speed up hash tables
Perf: New HASH function
Perf: optimize _eat_space and _get_token
Remove fs_unlock after failed suspend
Fix !DEVMAPPER_SUPPORT build
Void* arithmetic replaced with char*
API change - support more const arg
Use cleaner const *pointer
Const fixing
const - static merge to const patch
Add missing stacks to toollib.c
Add missing stack traces for polldaemon
Add debug message for open_count failure
Remove dead assignment of lock_flags
Remove dead assignment in vgconvert_single

 daemons/clvmd/clvmd-command.c    |    3 +-
 daemons/clvmd/clvmd.c            |    4 +-
 daemons/clvmd/clvmd.h            |    2 +-
 lib/activate/activate.c          |   40 +++++++--
 lib/activate/activate.h          |    2 +-
 lib/config/config.c              |   36 ++++----
 lib/filters/filter-regex.c       |    2 +-
 lib/format1/format1.c            |   10 ++-
 lib/format1/lvm1-label.c         |    9 ++-
 lib/format_pool/format_pool.c    |    4 +-
 lib/format_text/format-text.c    |   16 +++-
 lib/format_text/text_label.c     |    9 +-
 lib/metadata/lv.h                |    2 +-
 lib/metadata/lv_manip.c          |    3 +-
 lib/metadata/metadata-exported.h |    8 +-
 lib/metadata/metadata.c          |   27 +++--
 lib/metadata/mirror.c            |   18 ++--
 lib/mirror/mirrored.c            |    2 +
 lib/report/properties.c          |    3 +-
 lib/report/report.c              |   14 +--
 lib/snapshot/snapshot.c          |    2 +
 lib/uuid/uuid.c                  |    2 +-
 libdm/datastruct/hash.c          |  189 +++++++++++++++++++++++++++++++------
 libdm/libdevmapper.h             |    8 +-
 libdm/libdm-deptree.c            |    5 +-
 libdm/libdm-report.c             |    2 +-
 liblvm/lvm_vg.c                  |    4 +-
 tools/lvcreate.c                 |    2 +-
 tools/polldaemon.c               |    4 +-
 tools/reporter.c                 |    4 +-
 tools/toollib.c                  |   27 ++++--
 tools/toollib.h                  |    4 +-
 tools/vgcfgrestore.c             |    2 +-
 tools/vgconvert.c                |    5 +-
 tools/vgcreate.c                 |    2 +-
 tools/vgextend.c                 |    4 +-
 tools/vgmerge.c                  |    2 +-
 tools/vgreduce.c                 |    2 +-
 tools/vgrename.c                 |    2 +-
 tools/vgsplit.c                  |    2 +-
 40 files changed, 338 insertions(+), 150 deletions(-)
Signature · 1 line
1.7.4
#1 lore raw

PATCH 1/16 Align orphan strings

While checking for passed pointers to hash function - some buffers were not nicely aligned - and those were mainly 'static' strings.

So this code is a bit ugly but forces 8b alignment on these strings.

---
 lib/format1/format1.c         |   10 +++++++---
 lib/format1/lvm1-label.c      |    9 +++++++--
 lib/format_pool/format_pool.c |    4 +++-
 lib/format_text/format-text.c |   16 ++++++++++++----
 lib/format_text/text_label.c  |    5 +++--
 5 files changed, 32 insertions(+), 12 deletions(-)
lib/format1/format1.c +7 -3
index fc14444..c70d857 100644
@@ -578,6 +578,10 @@ struct format_type *init_format(struct cmd_context *cmd);
 struct format_type *init_format(struct cmd_context *cmd)
 #endif
 {
+	static const char lvm1_orphan_vg_name[] __attribute__((aligned(8)))
+		= FMT_LVM1_ORPHAN_VG_NAME;
+	static const char lvm1_name[] __attribute__((aligned(8)))
+		= FMT_LVM1_NAME;
 	struct format_type *fmt = dm_malloc(sizeof(*fmt));
 
 	if (!fmt)
@@ -585,9 +589,9 @@ struct format_type *init_format(struct cmd_context *cmd)
 
 	fmt->cmd = cmd;
 	fmt->ops = &_format1_ops;
-	fmt->name = FMT_LVM1_NAME;
+	fmt->name = lvm1_name;
 	fmt->alias = NULL;
-	fmt->orphan_vg_name = FMT_LVM1_ORPHAN_VG_NAME;
+	fmt->orphan_vg_name = lvm1_orphan_vg_name;
 	fmt->features = FMT_RESTRICTED_LVIDS | FMT_ORPHAN_ALLOCATABLE |
 			FMT_RESTRICTED_READAHEAD;
 	fmt->private = NULL;
@@ -597,7 +601,7 @@ struct format_type *init_format(struct cmd_context *cmd)
 		return NULL;
 	}
 
-	if (!(label_register_handler(FMT_LVM1_NAME, fmt->labeller))) {
+	if (!(label_register_handler(lvm1_name, fmt->labeller))) {
 		log_error("Couldn't register lvm1 label handler.");
 		return NULL;
 	}
lib/format1/lvm1-label.c +7 -2
index 07596a5..2af444a 100644
@@ -57,11 +57,16 @@ static int _lvm1_write(struct label *label __attribute__((unused)), void *buf __
 static int _lvm1_read(struct labeller *l, struct device *dev, void *buf,
 		 struct label **label)
 {
+	static const char orphan_vgid[] __attribute__((aligned(8)))
+		= FMT_LVM1_ORPHAN_VG_NAME;
+	static const char orphan_vg_name[] __attribute__((aligned(8)))
+		= FMT_LVM1_ORPHAN_VG_NAME;
+
 	struct pv_disk *pvd = (struct pv_disk *) buf;
 	struct vg_disk vgd;
 	struct lvmcache_info *info;
-	const char *vgid = FMT_LVM1_ORPHAN_VG_NAME;
-	const char *vgname = FMT_LVM1_ORPHAN_VG_NAME;
+	const char *vgid = orphan_vgid;
+	const char *vgname = orphan_vg_name;
 	unsigned exported = 0;
 
 	munge_pvd(dev, pvd);
lib/format_pool/format_pool.c +3 -1
index 730da87..6f6f261 100644
@@ -308,6 +308,8 @@ struct format_type *init_format(struct cmd_context *cmd);
 struct format_type *init_format(struct cmd_context *cmd)
 #endif
 {
+	static const char pool_orphan_vg_name[] __attribute__((aligned(8)))
+		= FMT_POOL_ORPHAN_VG_NAME;
 	struct format_type *fmt = dm_malloc(sizeof(*fmt));
 
 	if (!fmt) {
@@ -320,7 +322,7 @@ struct format_type *init_format(struct cmd_context *cmd)
 	fmt->ops = &_format_pool_ops;
 	fmt->name = FMT_POOL_NAME;
 	fmt->alias = NULL;
-	fmt->orphan_vg_name = FMT_POOL_ORPHAN_VG_NAME;
+	fmt->orphan_vg_name = pool_orphan_vg_name;
 	fmt->features = 0;
 	fmt->private = NULL;
 
lib/format_text/format-text.c +12 -4
index 13e1668..a065908 100644
@@ -1594,6 +1594,8 @@ static int _populate_pv_fields(struct lvmcache_info *info,
 			       struct physical_volume *pv,
 			       int scan_label_only)
 {
+	static const char orphan_vg_name[] __attribute__((aligned(8)))
+		= FMT_TEXT_ORPHAN_VG_NAME;
 	struct data_area_list *da;
 
 	/* Have we already cached vgname? */
@@ -1612,7 +1614,7 @@ static int _populate_pv_fields(struct lvmcache_info *info,
 	pv->dev = info->dev;
 	pv->fmt = info->fmt;
 	pv->size = info->device_size >> SECTOR_SHIFT;
-	pv->vg_name = FMT_TEXT_ORPHAN_VG_NAME;
+	pv->vg_name = orphan_vg_name;
 	memcpy(&pv->id, &info->dev->pvid, sizeof(pv->id));
 
 	/* Currently only support exactly one data area */
@@ -2132,6 +2134,12 @@ static int _get_config_disk_area(struct cmd_context *cmd,
 
 struct format_type *create_text_format(struct cmd_context *cmd)
 {
+	static const char text_name[] __attribute__((aligned(8)))
+		= FMT_TEXT_NAME;
+	static const char text_alias[] __attribute__((aligned(8)))
+		= FMT_TEXT_ALIAS;
+	static const char orphan_vg_name[] __attribute__((aligned(8)))
+		= ORPHAN_VG_NAME(FMT_TEXT_NAME);
 	struct format_type *fmt;
 	const struct config_node *cn;
 	const struct config_value *cv;
@@ -2142,9 +2150,9 @@ struct format_type *create_text_format(struct cmd_context *cmd)
 
 	fmt->cmd = cmd;
 	fmt->ops = &_text_handler;
-	fmt->name = FMT_TEXT_NAME;
-	fmt->alias = FMT_TEXT_ALIAS;
-	fmt->orphan_vg_name = ORPHAN_VG_NAME(FMT_TEXT_NAME);
+	fmt->name = text_name;
+	fmt->alias = text_alias;
+	fmt->orphan_vg_name = orphan_vg_name;
 	fmt->features = FMT_SEGMENTS | FMT_MDAS | FMT_TAGS | FMT_PRECOMMIT |
 			FMT_UNLIMITED_VOLS | FMT_RESIZE_PV |
 			FMT_UNLIMITED_STRIPESIZE;
lib/format_text/text_label.c +3 -2
index e459cde..ce250e6 100644
@@ -253,6 +253,8 @@ static int _text_initialise_label(struct labeller *l __attribute__((unused)),
 static int _text_read(struct labeller *l, struct device *dev, void *buf,
 		 struct label **label)
 {
+	static const char text_orphan_vg_name[] __attribute__((aligned(8)))
+		= FMT_TEXT_ORPHAN_VG_NAME;
 	struct label_header *lh = (struct label_header *) buf;
 	struct pv_header *pvhdr;
 	struct lvmcache_info *info;
@@ -269,8 +271,7 @@ static int _text_read(struct labeller *l, struct device *dev, void *buf,
 	pvhdr = (struct pv_header *) ((void *) buf + xlate32(lh->offset_xl));
 
 	if (!(info = lvmcache_add(l, (char *)pvhdr->pv_uuid, dev,
-				  FMT_TEXT_ORPHAN_VG_NAME,
-				  FMT_TEXT_ORPHAN_VG_NAME, 0)))
+				  text_orphan_vg_name, text_orphan_vg_name, 0)))
 		return_0;
 	*label = info->label;
 
Signature · 1 line
1.7.4
#2 lore raw

PATCH 2/16 Perf: speed up hash tables

In reply to Zdenek Kabelac

Improve considerably hash perfomance:
Remember calculated hash value for node - allows to speedup lookup of nodes with same hash & mask value.

Add statistic counters for hashes and print stats in debug mode on hash destruction - so bad perfomance of hash can be optimized.

API change:
dm_hash binary functions takes void* pointer - so there
is no need to cast other pointers to char*. This is slight API change, but presents no change on user side it just allows to write code easier.

---
 libdm/datastruct/hash.c |   85 ++++++++++++++++++++++++++++++-----------------
 libdm/libdevmapper.h    |    6 ++--
 2 files changed, 57 insertions(+), 34 deletions(-)
libdm/datastruct/hash.c +54 -31
index d4543df..4d0cf5f 100644
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
- * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved.
  *
  * This file is part of the device-mapper userspace tools.
  *
@@ -19,12 +19,18 @@ struct dm_hash_node {
 	struct dm_hash_node *next;
 	void *data;
 	unsigned keylen;
+	unsigned long hash;
 	char key[0];
 };
 
 struct dm_hash_table {
 	unsigned num_nodes;
 	unsigned num_slots;
+	unsigned num_hint;
+	unsigned collisions;
+	unsigned search;
+	unsigned same_hash;
+	unsigned mask;
 	struct dm_hash_node **slots;
 };
 
@@ -92,26 +98,26 @@ struct dm_hash_table *dm_hash_create(unsigned size_hint)
 	unsigned new_size = 16u;
 	struct dm_hash_table *hc = dm_zalloc(sizeof(*hc));
 
-	if (!hc)
-		return_0;
+	if (!hc) {
+		log_error("Failed to allocate memory for hash.");
+		return 0;
+	}
 
+	hc->num_hint = size_hint;
 	/* round size hint up to a power of two */
 	while (new_size < size_hint)
 		new_size = new_size << 1;
 
 	hc->num_slots = new_size;
+	hc->mask = new_size - 1;
 	len = sizeof(*(hc->slots)) * new_size;
-	if (!(hc->slots = dm_malloc(len))) {
-		stack;
-		goto bad;
+	if (!(hc->slots = dm_zalloc(len))) {
+		dm_free(hc);
+		log_error("Failed to allocate slots for hash.");
+		return 0;
 	}
-	memset(hc->slots, 0, len);
-	return hc;
 
-      bad:
-	dm_free(hc->slots);
-	dm_free(hc);
-	return 0;
+	return hc;
 }
 
 static void _free_nodes(struct dm_hash_table *t)
@@ -119,6 +125,13 @@ static void _free_nodes(struct dm_hash_table *t)
 	struct dm_hash_node *c, *n;
 	unsigned i;
 
+	log_debug("Released hash - used:%d size:%d hint:%d  (c:%d s:%d h:%d)",
+		  t->num_nodes, t->num_slots, t->num_hint,
+		  t->collisions, t->search, t->same_hash);
+
+	if (!t->num_nodes)
+		return;
+
 	for (i = 0; i < t->num_slots; i++)
 		for (c = t->slots[i]; c; c = n) {
 			n = c->next;
@@ -133,45 +146,57 @@ void dm_hash_destroy(struct dm_hash_table *t)
 	dm_free(t);
 }
 
-static struct dm_hash_node **_find(struct dm_hash_table *t, const char *key,
-				   uint32_t len)
+static struct dm_hash_node **_findh(struct dm_hash_table *t, const void *key,
+				    uint32_t len, unsigned long hash)
 {
-	unsigned h = _hash(key, len) & (t->num_slots - 1);
 	struct dm_hash_node **c;
 
-	for (c = &t->slots[h]; *c; c = &((*c)->next)) {
-		if ((*c)->keylen != len)
-			continue;
-
-		if (!memcmp(key, (*c)->key, len))
-			break;
+	for (c = &t->slots[hash & t->mask]; *c; c = &((*c)->next)) {
+		if ((*c)->hash == hash && (*c)->keylen == len) {
+			if (!memcmp(key, (*c)->key, len)) {
+				++t->search;
+				break;
+			}
+			++t->same_hash;
+		}
+		++t->collisions;
 	}
 
 	return c;
 }
 
-void *dm_hash_lookup_binary(struct dm_hash_table *t, const char *key,
-			 uint32_t len)
+static struct dm_hash_node **_find(struct dm_hash_table *t, const void *key,
+				   uint32_t len)
+{
+	return _findh(t, key, len, _hash(key, len));
+}
+
+void *dm_hash_lookup_binary(struct dm_hash_table *t, const void *key,
+			    uint32_t len)
 {
 	struct dm_hash_node **c = _find(t, key, len);
 
 	return *c ? (*c)->data : 0;
 }
 
-int dm_hash_insert_binary(struct dm_hash_table *t, const char *key,
+int dm_hash_insert_binary(struct dm_hash_table *t, const void *key,
 			  uint32_t len, void *data)
 {
-	struct dm_hash_node **c = _find(t, key, len);
+	unsigned long hash = _hash(key, len);
+	struct dm_hash_node **c = _findh(t, key, len, hash);
 
 	if (*c)
 		(*c)->data = data;
 	else {
 		struct dm_hash_node *n = _create_node(key, len);
 
-		if (!n)
+		if (!n) {
+			log_error("Failed to allocate new hash node.");
 			return 0;
+		}
 
 		n->data = data;
+		n->hash = hash;
 		n->next = 0;
 		*c = n;
 		t->num_nodes++;
@@ -180,7 +205,7 @@ int dm_hash_insert_binary(struct dm_hash_table *t, const char *key,
 	return 1;
 }
 
-void dm_hash_remove_binary(struct dm_hash_table *t, const char *key,
+void dm_hash_remove_binary(struct dm_hash_table *t, const void *key,
 			uint32_t len)
 {
 	struct dm_hash_node **c = _find(t, key, len);
@@ -229,7 +254,7 @@ void dm_hash_wipe(struct dm_hash_table *t)
 {
 	_free_nodes(t);
 	memset(t->slots, 0, sizeof(struct dm_hash_node *) * t->num_slots);
-	t->num_nodes = 0u;
+	t->num_nodes = t->collisions = t->search = t->same_hash = 0u;
 }
 
 char *dm_hash_get_key(struct dm_hash_table *t __attribute__((unused)),
@@ -262,7 +287,5 @@ struct dm_hash_node *dm_hash_get_first(struct dm_hash_table *t)
 
 struct dm_hash_node *dm_hash_get_next(struct dm_hash_table *t, struct dm_hash_node *n)
 {
-	unsigned h = _hash(n->key, n->keylen) & (t->num_slots - 1);
-
-	return n->next ? n->next : _next_slot(t, h + 1);
+	return n->next ? n->next : _next_slot(t, (n->hash & t->mask) + 1);
 }
libdm/libdevmapper.h +3 -3
index 297b2c6..e3528d3 100644
@@ -713,10 +713,10 @@ void *dm_hash_lookup(struct dm_hash_table *t, const char *key);
 int dm_hash_insert(struct dm_hash_table *t, const char *key, void *data);
 void dm_hash_remove(struct dm_hash_table *t, const char *key);
 
-void *dm_hash_lookup_binary(struct dm_hash_table *t, const char *key, uint32_t len);
-int dm_hash_insert_binary(struct dm_hash_table *t, const char *key, uint32_t len,
+void *dm_hash_lookup_binary(struct dm_hash_table *t, const void *key, uint32_t len);
+int dm_hash_insert_binary(struct dm_hash_table *t, const void *key, uint32_t len,
 		       void *data);
-void dm_hash_remove_binary(struct dm_hash_table *t, const char *key, uint32_t len);
+void dm_hash_remove_binary(struct dm_hash_table *t, const void *key, uint32_t len);
 
 unsigned dm_hash_get_num_entries(struct dm_hash_table *t);
 void dm_hash_iter(struct dm_hash_table *t, dm_hash_iterate_fn f);
Signature · 1 line
1.7.4
#3 lore raw

PATCH 3/16 Perf: New HASH function

In reply to Zdenek Kabelac

Providing 2 new hash function for selection.

Performance of my modified Bob Jenkins hash function (completely free code) is reasonably good and in my test is seems to be equal with larger but slightly more advanced SuperFastHash (LGPL).

Our current hash is producing a lot of hash collisions (i.e. a lot of strings are hashed to same number) and also requires extra derefernce during hash calculation.

---
 libdm/datastruct/hash.c |  104 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 104 insertions(+), 0 deletions(-)
libdm/datastruct/hash.c +104 -0
index 4d0cf5f..70e69a4 100644
@@ -34,6 +34,7 @@ struct dm_hash_table {
 	struct dm_hash_node **slots;
 };
 
+#if 0
 /* Permutation of the Integers 0 through 255 */
 static unsigned char _nums[] = {
 	1, 14, 110, 25, 97, 174, 132, 119, 138, 170, 125, 118, 27, 233, 140, 51,
@@ -61,6 +62,7 @@ static unsigned char _nums[] = {
 	163, 200, 222, 235, 248, 243, 219, 10, 152, 131, 123, 229, 203, 76, 120,
 	209
 };
+#endif
 
 static struct dm_hash_node *_create_node(const char *str, unsigned len)
 {
@@ -74,6 +76,7 @@ static struct dm_hash_node *_create_node(const char *str, unsigned len)
 	return n;
 }
 
+#if 0
 static unsigned long _hash(const char *str, unsigned len)
 {
 	unsigned long h = 0, g;
@@ -91,6 +94,107 @@ static unsigned long _hash(const char *str, unsigned len)
 
 	return h;
 }
+#endif
+
+#if 1
+/*
+ * Adapted Bob Jenkins hash to read by 2 bytes if possible.
+ * https://secure.wikimedia.org/wikipedia/en/wiki/Jenkins_hash_function
+ *
+ * reduces amount of hash collisions
+ */
+static unsigned long _hash(const char *str, unsigned len)
+{
+	const uint16_t *str16 = (const uint16_t*)str;
+	uint32_t hash = 0, i;
+	int sz = len / 2;
+
+	//if ((int)str & 1) abort(); // catch odd addresses
+	for(i = 0; i < sz; ++i) {
+		hash += str16[i];
+		hash += (hash << 10);
+		hash ^= (hash >> 6);
+	}
+
+	if (len & 1) {
+		hash += str[len - 1];
+		hash += (hash << 10);
+		hash ^= (hash >> 6);
+	}
+
+	hash += (hash << 3);
+	hash ^= (hash >> 11);
+	hash += (hash << 15);
+
+	return hash;
+}
+#endif
+
+#if 0
+/*
+ * SuperFastHash
+ * http://www.azillionmonkeys.com/qed/hash.html
+ */
+#undef get16bits
+#if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \
+  || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__)
+#define get16bits(d) (*((const uint16_t *) (d)))
+#endif
+
+#if !defined (get16bits)
+#define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\
+                       +(uint32_t)(((const uint8_t *)(d))[0]) )
+#endif
+
+static unsigned long _hash(const char *data, unsigned len)
+{
+	unsigned long hash = len, tmp;
+	int rem;
+
+	if (len <= 0 || data == NULL) return 0;
+
+	rem = len & 3;
+	len >>= 2;
+
+	/* Main loop */
+	for (;len > 0; len--) {
+		hash  += get16bits (data);
+		tmp    = (get16bits (data+2) << 11) ^ hash;
+		hash   = (hash << 16) ^ tmp;
+		data  += 2*sizeof (uint16_t);
+		hash  += hash >> 11;
+	}
+
+	/* Handle end cases */
+	switch (rem) {
+	case 3:
+		hash += get16bits (data);
+		hash ^= hash << 16;
+		hash ^= data[sizeof (uint16_t)] << 18;
+		hash += hash >> 11;
+		break;
+	case 2:
+		hash += get16bits (data);
+		hash ^= hash << 11;
+		hash += hash >> 17;
+		break;
+	case 1:
+		hash += *data;
+		hash ^= hash << 10;
+		hash += hash >> 1;
+	}
+
+	/* Force "avalanching" of final 127 bits */
+	hash ^= hash << 3;
+	hash += hash >> 5;
+	hash ^= hash << 4;
+	hash += hash >> 17;
+	hash ^= hash << 25;
+	hash += hash >> 6;
+
+	return hash;
+}
+#endif
 
 struct dm_hash_table *dm_hash_create(unsigned size_hint)
 {
Signature · 1 line
1.7.4
#4 lore raw

PATCH 4/16 Perf: optimize _eat_space and _get_token

In reply to Zdenek Kabelac

Makes the code more readable and has a smaller number of memory accesses.

For _get_token() optimize number parsing. Check for '.' char only if it's not a digit. Move pointer incrementation into one place.

For _eat_space() check only p->te for '\0' in skipping of comment line. Avoid check for '\0' when we know it is space. Also master while loop doesn't need checking p->tb for '\0'. We just need to check p->tb isn't already at the end of buffer. This could give 'extra' loop cycle if we are already there - but safes memory access in every other case.

---
 lib/config/config.c |   36 ++++++++++++++++++------------------
 1 files changed, 18 insertions(+), 18 deletions(-)
lib/config/config.c +18 -18
index 237c610..53a6a57 100644
@@ -821,18 +821,20 @@ static void _get_token(struct parser *p, int tok_prev)
 	case '+':
 	case '-':
 		if (values_allowed) {
-			te++;
-			while ((te != p->fe) && (*te)) {
-				if (*te == '.') {
-					if (p->t == TOK_FLOAT)
-						break;
-					p->t = TOK_FLOAT;
-				} else if (!isdigit((int) *te))
+			while (++te != p->fe) {
+				if (!isdigit((int) *te)) {
+					if (*te == '.') {
+						if (p->t != TOK_FLOAT) {
+							p->t = TOK_FLOAT;
+							continue;
+						}
+					}
 					break;
-				te++;
+				}
 			}
 			break;
 		}
+		/* fall through */
 
 	default:
 		p->t = TOK_IDENTIFIER;
@@ -849,21 +851,19 @@ static void _get_token(struct parser *p, int tok_prev)
 
 static void _eat_space(struct parser *p)
 {
-	while ((p->tb != p->fe) && (*p->tb)) {
+	while (p->tb != p->fe) {
 		if (*p->te == '#')
 			while ((p->te != p->fe) && (*p->te) && (*p->te != '\n'))
 				p->te++;
 
-		else if (isspace(*p->te)) {
-			while ((p->te != p->fe) && (*p->te) && isspace(*p->te)) {
-				if (*p->te == '\n')
-					p->line++;
-				p->te++;
-			}
-		}
+		else if (!isspace(*p->te))
+			break;
 
-		else
-			return;
+		while ((p->te != p->fe) && isspace(*p->te)) {
+			if (*p->te == '\n')
+				p->line++;
+			p->te++;
+		}
 
 		p->tb = p->te;
 	}
Signature · 1 line
1.7.4
#5 lore raw

PATCH 5/16 Remove fs_unlock after failed suspend

In reply to Zdenek Kabelac

Explicit fs_unlock() after failed suspend is not need - as it will happen automatically with nearest lv_info() or vg_unlock().

---
 lib/activate/activate.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
lib/activate/activate.c +0 -1
index ad9459a..e75415b 100644
@@ -1126,7 +1126,6 @@ static int _lv_suspend(struct cmd_context *cmd, const char *lvid_s,
 
 	if (!_lv_suspend_lv(lv, origin_only, lockfs, flush_required)) {
 		critical_section_dec(cmd);
-		fs_unlock();
 		goto out;
 	}
 
Signature · 1 line
1.7.4
#6 lore raw

PATCH 6/16 Fix !DEVMAPPER_SUPPORT build

In reply to Zdenek Kabelac
---
 lib/activate/activate.c |   35 ++++++++++++++++++++++++++++++-----
 lib/mirror/mirrored.c   |    2 ++
 lib/snapshot/snapshot.c |    2 ++
 3 files changed, 34 insertions(+), 5 deletions(-)
lib/activate/activate.c +30 -5
index e75415b..f39a066 100644
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
- * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved.
  *
  * This file is part of LVM2.
  *
@@ -171,7 +171,7 @@ int lvs_in_vg_activated(struct volume_group *vg)
 {
 	return 0;
 }
-int lvs_in_vg_opened(struct volume_group *vg)
+int lvs_in_vg_opened(const struct volume_group *vg)
 {
 	return 0;
 }
@@ -181,15 +181,15 @@ int lv_suspend(struct cmd_context *cmd, const char *lvid_s)
 	return 1;
 }
 *******/
-int lv_suspend_if_active(struct cmd_context *cmd, const char *lvid_s)
+int lv_suspend_if_active(struct cmd_context *cmd, const char *lvid_s, unsigned origin_only)
 {
 	return 1;
 }
-int lv_resume(struct cmd_context *cmd, const char *lvid_s)
+int lv_resume(struct cmd_context *cmd, const char *lvid_s, unsigned origin_only)
 {
 	return 1;
 }
-int lv_resume_if_active(struct cmd_context *cmd, const char *lvid_s)
+int lv_resume_if_active(struct cmd_context *cmd, const char *lvid_s, unsigned origin_only)
 {
 	return 1;
 }
@@ -232,6 +232,31 @@ void activation_exit(void)
 	return;
 }
 
+int lv_is_active(struct logical_volume *lv)
+{
+	return 0;
+}
+
+int lv_is_active_exclusive_locally(struct logical_volume *lv)
+{
+	return 0;
+}
+
+int lv_is_active_exclusive_remotely(struct logical_volume *lv)
+{
+	return 0;
+}
+
+int lv_check_transient(struct logical_volume *lv)
+{
+	return 0;
+}
+
+int monitor_dev_for_events(struct cmd_context *cmd, struct logical_volume *lv,
+			   unsigned origin_only, int monitor)
+{
+	return 1;
+}
 #else				/* DEVMAPPER_SUPPORT */
 
 static int _activation = 1;
lib/mirror/mirrored.c +2 -0
index 0bf3b3b..7de2f70 100644
@@ -641,10 +641,12 @@ struct segment_type *init_segtype(struct cmd_context *cmd)
 	segtype->private = NULL;
 	segtype->flags = SEG_AREAS_MIRRORED;
 
+#ifdef DEVMAPPER_SUPPORT
 #ifdef DMEVENTD
 	if (_get_mirror_dso_path(cmd))
 		segtype->flags |= SEG_MONITORED;
 #endif
+#endif
 
 	log_very_verbose("Initialised segtype: %s", segtype->name);
 
lib/snapshot/snapshot.c +2 -0
index 1a98d7e..af5d708 100644
@@ -260,10 +260,12 @@ struct segment_type *init_segtype(struct cmd_context *cmd)
 	segtype->private = NULL;
 	segtype->flags = SEG_SNAPSHOT;
 
+#ifdef DEVMAPPER_SUPPORT
 #ifdef DMEVENTD
 	if (_get_snapshot_dso_path(cmd))
 		segtype->flags |= SEG_MONITORED;
 #endif
+#endif
 	log_very_verbose("Initialised segtype: %s", segtype->name);
 
 	return segtype;
Signature · 1 line
1.7.4
#7 lore raw

PATCH 7/16 Void* arithmetic replaced with char*

In reply to Zdenek Kabelac
---
 daemons/clvmd/clvmd.c        |    2 +-
 lib/format_text/text_label.c |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
daemons/clvmd/clvmd.c +1 -1
index 8e21732..3726324 100644
@@ -1867,7 +1867,7 @@ static int send_message(void *buf, int msglen, const char *csid, int fd,
 				break;
 			}
 
-			len = write(fd, buf + ptr, msglen - ptr);
+			len = write(fd, (char*)buf + ptr, msglen - ptr);
 
 			if (len <= 0) {
 				if (errno == EINTR)
lib/format_text/text_label.c +2 -2
index ce250e6..b12250f 100644
@@ -52,7 +52,7 @@ static int _text_write(struct label *label, void *buf)
 
 	strncpy((char *)lh->type, label->type, sizeof(label->type));
 
-	pvhdr = (struct pv_header *) ((void *) buf + xlate32(lh->offset_xl));
+	pvhdr = (struct pv_header *) ((char *) buf + xlate32(lh->offset_xl));
 	info = (struct lvmcache_info *) label->info;
 	pvhdr->device_size_xl = xlate64(info->device_size);
 	memcpy(pvhdr->pv_uuid, &info->dev->pvid, sizeof(struct id));
@@ -268,7 +268,7 @@ static int _text_read(struct labeller *l, struct device *dev, void *buf,
 	char *creation_host;
 	struct mda_header *mdah;
 
-	pvhdr = (struct pv_header *) ((void *) buf + xlate32(lh->offset_xl));
+	pvhdr = (struct pv_header *) ((char *) buf + xlate32(lh->offset_xl));
 
 	if (!(info = lvmcache_add(l, (char *)pvhdr->pv_uuid, dev,
 				  text_orphan_vg_name, text_orphan_vg_name, 0)))
Signature · 1 line
1.7.4
#8 lore raw

PATCH 8/16 API change - support more const arg

In reply to Zdenek Kabelac

As dm_report_field_string doesn't modify content of data pointer, it could be also marked as const.

It's slight API change - but doesn't require any change on user side and supports wide range of arguments without const casting. (i.e. we may use as paramater const lv struct this way: &lv->name)

---
 libdm/libdevmapper.h |    2 +-
 libdm/libdm-report.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
libdm/libdevmapper.h +1 -1
index e3528d3..d7936bf 100644
@@ -1123,7 +1123,7 @@ int dm_report_set_output_field_name_prefix(struct dm_report *rh,
  * They take care of allocating copies of the data.
  */
 int dm_report_field_string(struct dm_report *rh, struct dm_report_field *field,
-			   const char **data);
+			   const char *const *data);
 int dm_report_field_int32(struct dm_report *rh, struct dm_report_field *field,
 			  const int32_t *data);
 int dm_report_field_uint32(struct dm_report *rh, struct dm_report_field *field,
libdm/libdm-report.c +1 -1
index 4f47c46..0212284 100644
@@ -102,7 +102,7 @@ static const struct dm_report_object_type *_find_type(struct dm_report *rh,
  */
 
 int dm_report_field_string(struct dm_report *rh,
-			   struct dm_report_field *field, const char **data)
+			   struct dm_report_field *field, const char *const *data)
 {
 	char *repstr;
 
Signature · 1 line
1.7.4
#9 lore raw

PATCH 9/16 Use cleaner const *pointer

In reply to Zdenek Kabelac

Now it's warning free -
Const cast in _string_disp() is not even needed,
but keep it for explicitely readable conversion.

---
 lib/report/report.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
lib/report/report.c +3 -5
index 136ad4c..f470840 100644
@@ -44,7 +44,7 @@ static int _string_disp(struct dm_report *rh, struct dm_pool *mem __attribute__(
 			struct dm_report_field *field,
 			const void *data, void *private __attribute__((unused)))
 {
-	return dm_report_field_string(rh, field, (const char **) data);
+	return dm_report_field_string(rh, field, (const char * const *) data);
 }
 
 static int _dev_name_disp(struct dm_report *rh, struct dm_pool *mem __attribute__((unused)),
@@ -307,10 +307,8 @@ static int _lvname_disp(struct dm_report *rh, struct dm_pool *mem,
 	char *repstr, *lvname;
 	size_t len;
 
-	if (lv_is_visible(lv)) {
-		repstr = lv->name;
-		return dm_report_field_string(rh, field, (const char **) &repstr);
-	}
+	if (lv_is_visible(lv))
+		return dm_report_field_string(rh, field, &lv->name);
 
 	len = strlen(lv->name) + 3;
 	if (!(repstr = dm_pool_zalloc(mem, len))) {
Signature · 1 line
1.7.4
#10 lore raw

PATCH 10/16 Const fixing

In reply to Zdenek Kabelac

Fixing some of the remaining const warnings - major change:

int vg_extend(struct volume_group *vg, int pv_count, const char *const *pv_names,

Change is needed - as lvm2api seems to expect const behaviour here. So vg_extend() is doing local strdup for unescaping.

skip_dev_dir return const char* from const char* vg_name.

Rest of the patch is cleanup of related warnings.

---
 daemons/clvmd/clvmd.c            |    2 +-
 daemons/clvmd/clvmd.h            |    2 +-
 lib/activate/activate.c          |    4 ++--
 lib/activate/activate.h          |    2 +-
 lib/filters/filter-regex.c       |    2 +-
 lib/metadata/lv.h                |    2 +-
 lib/metadata/lv_manip.c          |    3 ++-
 lib/metadata/metadata-exported.h |    8 ++++----
 lib/metadata/metadata.c          |   27 ++++++++++++++++-----------
 lib/metadata/mirror.c            |   18 +++++++++---------
 lib/report/properties.c          |    3 +--
 lib/report/report.c              |    6 +++---
 liblvm/lvm_vg.c                  |    4 ++--
 tools/lvcreate.c                 |    2 +-
 tools/reporter.c                 |    4 ++--
 tools/toollib.c                  |   10 +++++-----
 tools/toollib.h                  |    4 ++--
 tools/vgcfgrestore.c             |    2 +-
 tools/vgcreate.c                 |    2 +-
 tools/vgextend.c                 |    4 ++--
 tools/vgmerge.c                  |    2 +-
 tools/vgreduce.c                 |    2 +-
 tools/vgrename.c                 |    2 +-
 tools/vgsplit.c                  |    2 +-
 24 files changed, 62 insertions(+), 57 deletions(-)
daemons/clvmd/clvmd.c +1 -1
index 3726324..1f3184e 100644
@@ -2091,7 +2091,7 @@ error:
 	return -1;
 }
 
-void process_message(struct local_client *client, const char *buf, int len,
+void process_message(struct local_client *client, char *buf, int len,
 		     const char *csid)
 {
 	struct clvm_header *inheader;
daemons/clvmd/clvmd.h +1 -1
index 95244e1..5bad43a 100644
@@ -112,7 +112,7 @@ extern void cmd_client_cleanup(struct local_client *client);
 extern int add_client(struct local_client *new_client);
 
 extern void clvmd_cluster_init_completed(void);
-extern void process_message(struct local_client *client, const char *buf,
+extern void process_message(struct local_client *client, char *buf,
 			    int len, const char *csid);
 extern void debuglog(const char *fmt, ... )
   __attribute__ ((format(printf, 1, 2)));
lib/activate/activate.c +2 -2
index f39a066..6e8ff0d 100644
@@ -162,7 +162,7 @@ int lv_snapshot_percent(const struct logical_volume *lv, percent_t *percent)
 {
 	return 0;
 }
-int lv_mirror_percent(struct cmd_context *cmd, struct logical_volume *lv,
+int lv_mirror_percent(struct cmd_context *cmd, const struct logical_volume *lv,
 		      int wait, percent_t *percent, uint32_t *event_nr)
 {
 	return 0;
@@ -578,7 +578,7 @@ int lv_snapshot_percent(const struct logical_volume *lv, percent_t *percent)
 }
 
 /* FIXME Merge with snapshot_percent */
-int lv_mirror_percent(struct cmd_context *cmd, struct logical_volume *lv,
+int lv_mirror_percent(struct cmd_context *cmd, const struct logical_volume *lv,
 		      int wait, percent_t *percent, uint32_t *event_nr)
 {
 	int r;
lib/activate/activate.h +1 -1
index c054c6d..d97d6cd 100644
@@ -84,7 +84,7 @@ int lv_check_transient(struct logical_volume *lv);
  * Returns 1 if percent has been set, else 0.
  */
 int lv_snapshot_percent(const struct logical_volume *lv, percent_t *percent);
-int lv_mirror_percent(struct cmd_context *cmd, struct logical_volume *lv,
+int lv_mirror_percent(struct cmd_context *cmd, const struct logical_volume *lv,
 		      int wait, percent_t *percent, uint32_t *event_nr);
 
 /*
lib/filters/filter-regex.c +1 -1
index e046c71..fc83469 100644
@@ -135,7 +135,7 @@ static int _build_matcher(struct rfilter *rf, const struct config_value *val)
 	/*
 	 * build the matcher.
 	 */
-	if (!(rf->engine = dm_regex_create(rf->mem, (const char **) regex,
+	if (!(rf->engine = dm_regex_create(rf->mem, (const char * const*) regex,
 					   count)))
 		goto_out;
 	r = 1;
lib/metadata/lv.h +1 -1
index bff36d2..50afa28 100644
@@ -23,7 +23,7 @@ struct replicator_device;
 
 struct logical_volume {
 	union lvid lvid;
-	char *name;
+	const char *name;
 
 	struct volume_group *vg;
 
lib/metadata/lv_manip.c +2 -1
index eb2a3e4..684eb83 100644
@@ -1897,7 +1897,8 @@ static int _rename_sub_lv(struct cmd_context *cmd,
 			  struct logical_volume *lv,
 			  const char *lv_name_old, const char *lv_name_new)
 {
-	char *suffix, *new_name;
+	const char *suffix;
+	char *new_name;
 	size_t len;
 
 	/*
lib/metadata/metadata-exported.h +4 -4
index 4e2463a..32f0ac3 100644
@@ -410,9 +410,9 @@ void vg_remove_pvs(struct volume_group *vg);
 int vg_remove(struct volume_group *vg);
 int vg_rename(struct cmd_context *cmd, struct volume_group *vg,
 	      const char *new_name);
-int vg_extend(struct volume_group *vg, int pv_count, char **pv_names,
+int vg_extend(struct volume_group *vg, int pv_count, const char *const *pv_names,
 	      struct pvcreate_params *pp);
-int vg_reduce(struct volume_group *vg, char *pv_name);
+int vg_reduce(struct volume_group *vg, const char *pv_name);
 int vg_change_tag(struct volume_group *vg, const char *tag, int add_tag);
 int vg_split_mdas(struct cmd_context *cmd, struct volume_group *vg_from,
 		  struct volume_group *vg_to);
@@ -698,7 +698,7 @@ struct logical_volume *find_pvmove_lv_from_pvname(struct cmd_context *cmd,
 						  uint32_t lv_type);
 const char *get_pvmove_pvname_from_lv(struct logical_volume *lv);
 const char *get_pvmove_pvname_from_lv_mirr(struct logical_volume *lv_mirr);
-percent_t copy_percent(struct logical_volume *lv_mirr);
+percent_t copy_percent(const struct logical_volume *lv_mirr);
 struct dm_list *lvs_using_lv(struct cmd_context *cmd, struct volume_group *vg,
 			  struct logical_volume *lv);
 
@@ -721,7 +721,7 @@ int lv_has_unknown_segments(const struct logical_volume *lv);
 int vg_has_unknown_segments(const struct volume_group *vg);
 
 struct vgcreate_params {
-	char *vg_name;
+	const char *vg_name;
 	uint32_t extent_size;
 	size_t max_pv;
 	size_t max_lv;
lib/metadata/metadata.c +16 -11
index f76e10a..5cff6dd 100644
@@ -662,33 +662,38 @@ static int vg_extend_single_pv(struct volume_group *vg, char *pv_name,
  * - pp: parameters to pass to implicit pvcreate; if NULL, do not pvcreate
  *
  */
-int vg_extend(struct volume_group *vg, int pv_count, char **pv_names,
+int vg_extend(struct volume_group *vg, int pv_count, const char *const *pv_names,
 	      struct pvcreate_params *pp)
 {
 	int i;
+	char *pv_name;
 
 	if (_vg_bad_status_bits(vg, RESIZEABLE_VG))
 		return 0;
 
 	/* attach each pv */
 	for (i = 0; i < pv_count; i++) {
-		unescape_colons_and_at_signs(pv_names[i], NULL, NULL);
-		if (!vg_extend_single_pv(vg, pv_names[i], pp))
-			goto bad;
+		if (!(pv_name = dm_strdup(pv_names[i]))) {
+			log_error("Failed to duplicate pv name %s.", pv_names[i]);
+			return 0;
+		}
+		unescape_colons_and_at_signs(pv_name, NULL, NULL);
+		if (!vg_extend_single_pv(vg, pv_name, pp)) {
+			log_error("Unable to add physical volume '%s' to "
+				  "volume group '%s'.", pv_name, vg->name);
+			dm_free(pv_name);
+			return 0;
+		}
+		dm_free(pv_name);
 	}
 
 /* FIXME Decide whether to initialise and add new mdahs to format instance */
 
 	return 1;
-
-      bad:
-	log_error("Unable to add physical volume '%s' to "
-		  "volume group '%s'.", pv_names[i], vg->name);
-	return 0;
 }
 
 /* FIXME: use this inside vgreduce_single? */
-int vg_reduce(struct volume_group *vg, char *pv_name)
+int vg_reduce(struct volume_group *vg, const char *pv_name)
 {
 	struct physical_volume *pv;
 	struct pv_list *pvl;
@@ -1875,7 +1880,7 @@ int vgs_are_compatible(struct cmd_context *cmd __attribute__((unused)),
 {
 	struct lv_list *lvl1, *lvl2;
 	struct pv_list *pvl;
-	char *name1, *name2;
+	const char *name1, *name2;
 
 	if (lvs_in_vg_activated(vg_from)) {
 		log_error("Logical volumes in \"%s\" must be inactive",
lib/metadata/mirror.c +9 -9
index 318ac03..03e73cd 100644
@@ -1514,7 +1514,7 @@ struct dm_list *lvs_using_lv(struct cmd_context *cmd, struct volume_group *vg,
 	return lvs;
 }
 
-percent_t copy_percent(struct logical_volume *lv_mirr)
+percent_t copy_percent(const struct logical_volume *lv_mirr)
 {
 	uint32_t numerator = 0u, denominator = 0u;
 	struct lv_segment *seg;
@@ -1727,8 +1727,8 @@ static struct logical_volume *_set_up_mirror_log(struct cmd_context *cmd,
 						 int in_sync)
 {
 	struct logical_volume *log_lv;
-	const char *suffix, *c;
-	char *lv_name;
+	const char *suffix, *lv_name;
+	char *tmp_name;
 	size_t len;
 	struct lv_segment *seg;
 
@@ -1747,21 +1747,21 @@ static struct logical_volume *_set_up_mirror_log(struct cmd_context *cmd,
 	    strstr(seg_lv(seg, 0)->name, MIRROR_SYNC_LAYER)) {
 		lv_name = lv->name;
 		suffix = "_mlogtmp_%d";
-	} else if ((c = strstr(lv->name, MIRROR_SYNC_LAYER))) {
-		len = c - lv->name + 1;
-		if (!(lv_name = alloca(len)) ||
-		    !dm_snprintf(lv_name, len, "%s", lv->name)) {
+	} else if ((lv_name = strstr(lv->name, MIRROR_SYNC_LAYER))) {
+		len = lv_name - lv->name + 1;
+		if (!(tmp_name = alloca(len)) ||
+		    !dm_snprintf(tmp_name, len, "%s", lv->name)) {
 			log_error("mirror log name allocation failed");
 			return 0;
 		}
+		lv_name = tmp_name;
 		suffix = "_mlog";
 	} else {
 		lv_name = lv->name;
 		suffix = "_mlog";
 	}
 
-	if (!(log_lv = _create_mirror_log(lv, ah, alloc,
-					  (const char *) lv_name, suffix))) {
+	if (!(log_lv = _create_mirror_log(lv, ah, alloc, lv_name, suffix))) {
 		log_error("Failed to create mirror log.");
 		return NULL;
 	}
lib/report/properties.c +1 -2
index 06e11ba..a08470c 100644
@@ -88,8 +88,7 @@ static int _not_implemented_set(void *obj, struct lvm_property_type *prop)
 
 static percent_t _copy_percent(const struct logical_volume *lv) {
 	percent_t perc;
-	if (!lv_mirror_percent(lv->vg->cmd, (struct logical_volume *) lv,
-			   0, &perc, NULL))
+	if (!lv_mirror_percent(lv->vg->cmd, lv, 0, &perc, NULL))
 		perc = PERCENT_INVALID;
 	return perc;
 }
lib/report/report.c +3 -3
index f470840..0b1523f 100644
@@ -613,7 +613,7 @@ static int _uuid_disp(struct dm_report *rh __attribute__((unused)), struct dm_po
 {
 	char *repstr = NULL;
 
-	if (!(repstr = id_format_and_copy(mem, (struct id *)data)))
+	if (!(repstr = id_format_and_copy(mem, data)))
 		return_0;
 
 	dm_report_field_set_value(field, repstr, NULL);
@@ -851,7 +851,7 @@ static int _copypercent_disp(struct dm_report *rh __attribute__((unused)),
 			     struct dm_report_field *field,
 			     const void *data, void *private __attribute__((unused)))
 {
-	struct logical_volume *lv = (struct logical_volume *) data;
+	const struct logical_volume *lv = (const struct logical_volume *) data;
 	percent_t percent;
 	uint64_t *sortval;
 	char *repstr;
@@ -897,7 +897,7 @@ static struct format_instance _dummy_fid = {
 
 static struct volume_group _dummy_vg = {
 	.fid = &_dummy_fid,
-	.name = (char *) "",
+	.name = "",
 	.system_id = (char *) "",
 	.pvs = { &(_dummy_vg.pvs), &(_dummy_vg.pvs) },
 	.lvs = { &(_dummy_vg.lvs), &(_dummy_vg.lvs) },
liblvm/lvm_vg.c +2 -2
index f087ba4..dfc0c5e 100644
@@ -79,7 +79,7 @@ int lvm_vg_extend(vg_t vg, const char *device)
 	}
 
 	pvcreate_params_set_defaults(&pp);
-	if (!vg_extend(vg, 1, (char **) &device, &pp)) {
+	if (!vg_extend(vg, 1, &device, &pp)) {
 		unlock_vg(vg->cmd, VG_ORPHANS);
 		return -1;
 	}
@@ -98,7 +98,7 @@ int lvm_vg_reduce(vg_t vg, const char *device)
 	if (!vg_check_write_mode(vg))
 		return -1;
 
-	if (!vg_reduce(vg, (char *)device))
+	if (!vg_reduce(vg, device))
 		return -1;
 	return 0;
 }
tools/lvcreate.c +1 -1
index 7016417..d1abdf7 100644
@@ -31,7 +31,7 @@ static int _lvcreate_name_params(struct lvcreate_params *lp,
 {
 	int argc = *pargc;
 	char **argv = *pargv, *ptr;
-	char *vg_name;
+	const char *vg_name;
 
 	lp->lv_name = arg_str_value(cmd, name_ARG, NULL);
 
tools/reporter.c +2 -2
index fbd0c27..ebe85e7 100644
@@ -61,7 +61,7 @@ static int _pvsegs_sub_single(struct cmd_context *cmd,
 
 	struct volume_group _free_vg = {
 		.cmd = cmd,
-		.name = (char *)"",
+		.name = "",
 	};
 
         if (!(_free_vg.vgmem = dm_pool_create("_free_vg", 10240)))
@@ -69,7 +69,7 @@ static int _pvsegs_sub_single(struct cmd_context *cmd,
 
 	struct logical_volume _free_logical_volume = {
 		.vg = vg ?: &_free_vg,
-		.name = (char *) "",
+		.name = "",
 		.snapshot = NULL,
 		.status = VISIBLE_LV,
 		.major = -1,
tools/toollib.c +5 -5
index c85b7f0..5467a3b 100644
@@ -28,7 +28,7 @@ const char *command_name(struct cmd_context *cmd)
 /*
  * Strip dev_dir if present
  */
-char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name,
+const char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name,
 		   unsigned *dev_dir_found)
 {
 	const char *dmdir = dm_dir();
@@ -54,7 +54,7 @@ char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name,
 		    *layer) {
 			log_error("skip_dev_dir: Couldn't split up device name %s",
 				  vg_name);
-			return (char *) vg_name;
+			return vg_name;
 		}
 		vglv_sz = strlen(vgname) + strlen(lvname) + 2;
 		if (!(vglv = dm_pool_alloc(cmd->mem, vglv_sz)) ||
@@ -62,7 +62,7 @@ char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name,
 				 *lvname ? "/" : "",
 				 lvname) < 0) {
 			log_error("vg/lv string alloc failed");
-			return (char *) vg_name;
+			return vg_name;
 		}
 		return vglv;
 	}
@@ -76,7 +76,7 @@ char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name,
 	} else if (dev_dir_found)
 		*dev_dir_found = 0;
 
-	return (char *) vg_name;
+	return vg_name;
 }
 
 /*
@@ -898,7 +898,7 @@ const char *extract_vgname(struct cmd_context *cmd, const char *lv_name)
  */
 char *default_vgname(struct cmd_context *cmd)
 {
-	char *vg_path;
+	const char *vg_path;
 
 	/* Take default VG from environment? */
 	vg_path = getenv("LVM_VG_NAME");
tools/toollib.h +2 -2
index 506945a..1ef83f6 100644
@@ -84,8 +84,8 @@ int process_each_lv_in_vg(struct cmd_context *cmd,
 
 char *default_vgname(struct cmd_context *cmd);
 const char *extract_vgname(struct cmd_context *cmd, const char *lv_name);
-char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name,
-		   unsigned *dev_dir_found);
+const char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name,
+			 unsigned *dev_dir_found);
 
 /*
  * Builds a list of pv's from the names in argv.  Used in
tools/vgcfgrestore.c +1 -1
index dc0158f..1f1ab52 100644
@@ -17,7 +17,7 @@
 
 int vgcfgrestore(struct cmd_context *cmd, int argc, char **argv)
 {
-	char *vg_name = NULL;
+	const char *vg_name = NULL;
 
 	if (argc == 1) {
 		vg_name = skip_dev_dir(cmd, argv[0], NULL);
tools/vgcreate.c +1 -1
index 49574f3..62b5ac7 100644
@@ -74,7 +74,7 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
 	}
 
 	/* attach the pv's */
-	if (!vg_extend(vg, argc, argv, &pp))
+	if (!vg_extend(vg, argc, (const char* const*)argv, &pp))
 		goto_bad;
 
 	if (vp_new.max_lv != vg->max_lv)
tools/vgextend.c +2 -2
index a0c166b..5d2b54d 100644
@@ -40,7 +40,7 @@ static int _restore_pv(struct volume_group *vg, char *pv_name)
 
 int vgextend(struct cmd_context *cmd, int argc, char **argv)
 {
-	char *vg_name;
+	const char *vg_name;
 	struct volume_group *vg = NULL;
 	int r = ECMD_FAILED;
 	struct pvcreate_params pp;
@@ -107,7 +107,7 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
 		}
 
 		/* extend vg */
-		if (!vg_extend(vg, argc, argv, &pp))
+		if (!vg_extend(vg, argc, (const char* const*)argv, &pp))
 			goto_bad;
 
 		if (arg_count(cmd, metadataignore_ARG) &&
tools/vgmerge.c +1 -1
index 391764f..adb00a0 100644
@@ -163,7 +163,7 @@ bad:
 
 int vgmerge(struct cmd_context *cmd, int argc, char **argv)
 {
-	char *vg_name_to, *vg_name_from;
+	const char *vg_name_to, *vg_name_from;
 	int opt = 0;
 	int ret = 0, ret_max = 0;
 
tools/vgreduce.c +1 -1
index 4aa8f01..5e61cf8 100644
@@ -457,7 +457,7 @@ bad:
 int vgreduce(struct cmd_context *cmd, int argc, char **argv)
 {
 	struct volume_group *vg;
-	char *vg_name;
+	const char *vg_name;
 	int ret = ECMD_FAILED;
 	int fixed = 1;
 	int repairing = arg_count(cmd, removemissing_ARG);
tools/vgrename.c +1 -1
index 7a4e730..2f83fc6 100644
@@ -63,7 +63,7 @@ static int vg_rename_path(struct cmd_context *cmd, const char *old_vg_path,
 	int found_id = 0;
 	struct dm_list *vgids;
 	struct str_list *sl;
-	char *vg_name_new;
+	const char *vg_name_new;
 	const char *vgid = NULL, *vg_name, *vg_name_old;
 	char old_path[NAME_LEN], new_path[NAME_LEN];
 	struct volume_group *vg = NULL;
tools/vgsplit.c +1 -1
index bd2f0ab..b97db97 100644
@@ -281,7 +281,7 @@ int vgsplit(struct cmd_context *cmd, int argc, char **argv)
 {
 	struct vgcreate_params vp_new;
 	struct vgcreate_params vp_def;
-	char *vg_name_from, *vg_name_to;
+	const char *vg_name_from, *vg_name_to;
 	struct volume_group *vg_to = NULL, *vg_from = NULL;
 	int opt;
 	int existing_vg = 0;
Signature · 1 line
1.7.4
#11 lore raw

PATCH 11/16 const - static merge to const patch

In reply to Zdenek Kabelac
---
 lib/uuid/uuid.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
lib/uuid/uuid.c +1 -1
index edcb1ba..c85b822 100644
@@ -158,7 +158,7 @@ int id_write_format(const struct id *id, char *buffer, size_t size)
 {
 	int i, tot;
 
-	static unsigned group_size[] = { 6, 4, 4, 4, 4, 4, 6 };
+	static const unsigned group_size[] = { 6, 4, 4, 4, 4, 4, 6 };
 
 	assert(ID_LEN == 32);
 
Signature · 1 line
1.7.4
#12 lore raw

PATCH 12/16 Add missing stacks to toollib.c

In reply to Zdenek Kabelac
---
 tools/toollib.c |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)
tools/toollib.c +13 -4
index 5467a3b..2a52a51 100644
@@ -169,8 +169,10 @@ int process_each_lv_in_vg(struct cmd_context *cmd,
 		}
 		if (ret > ret_max)
 			ret_max = ret;
-		if (sigint_caught())
+		if (sigint_caught()) {
+			stack;
 			return ret_max;
+		}
 	}
 
 	if (lvargs_supplied && lvargs_matched != dm_list_size(arg_lvnames)) {
@@ -253,8 +255,10 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv,
 				while (*lv_name == '/')
 					lv_name++;
 				if (!(vgname = extract_vgname(cmd, vgname))) {
-					if (ret_max < ECMD_FAILED)
+					if (ret_max < ECMD_FAILED) {
+						stack;
 						ret_max = ECMD_FAILED;
+					}
 					continue;
 				}
 			} else if (!dev_dir_found &&
@@ -348,8 +352,10 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv,
 						    tags_arg, &failed_lvnames,
 						    handle, process_single_lv);
 			if (ret != ECMD_PROCESSED ||
-			    dm_list_empty(&failed_lvnames))
+			    dm_list_empty(&failed_lvnames)) {
+				stack;
 				break;
+			}
 
 			/* Try again with failed LVs in this VG */
 			dm_list_init(&lvnames);
@@ -357,6 +363,7 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv,
 
 			free_cmd_vgs(&cmd_vgs);
 			if (!cmd_vg_read(cmd, &cmd_vgs)) {
+				stack;
 				ret = ECMD_FAILED; /* break */
 				break;
 			}
@@ -366,8 +373,10 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv,
 
 		free_cmd_vgs(&cmd_vgs);
 		/* FIXME: logic for breaking command is not consistent */
-		if (sigint_caught())
+		if (sigint_caught()) {
+			stack;
 			return ECMD_FAILED;
+		}
 	}
 
 	return ret_max;
Signature · 1 line
1.7.4
#13 lore raw

PATCH 13/16 Add missing stack traces for polldaemon

In reply to Zdenek Kabelac

Traces for failing calls

---
 tools/polldaemon.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
tools/polldaemon.c +2 -2
index 94e52a3..0555b94 100644
@@ -148,7 +148,7 @@ static int _check_lv_status(struct cmd_context *cmd,
 	/* Finished? Or progress to next segment? */
 	if (progress == PROGRESS_FINISHED_ALL) {
 		if (!parms->poll_fns->finish_copy(cmd, vg, lv, lvs_changed))
-			return 0;
+			return_0;
 	} else {
 		if (parms->poll_fns->update_metadata &&
 		    !parms->poll_fns->update_metadata(cmd, vg, lv, lvs_changed, 0)) {
@@ -211,7 +211,7 @@ static int _wait_for_single_lv(struct cmd_context *cmd, const char *name, const
 
 		if (!_check_lv_status(cmd, vg, lv, name, parms, &finished)) {
 			unlock_and_free_vg(cmd, vg, vg->name);
-			return 0;
+			return_0;
 		}
 
 		unlock_and_free_vg(cmd, vg, vg->name);
Signature · 1 line
1.7.4
#14 lore raw

PATCH 14/16 Add debug message for open_count failure

In reply to Zdenek Kabelac

Report open_count problem as debug.

Function using _node_has_closed_parents decides whether it's error or could be ignored.

---
 libdm/libdm-deptree.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
libdm/libdm-deptree.c +4 -1
index 8d00514..2293826 100644
@@ -938,8 +938,11 @@ static int _node_has_closed_parents(struct dm_tree_node *node,
 		    !info.exists)
 			continue;
 
-		if (info.open_count)
+		if (info.open_count) {
+			log_debug("Node %s %d:%d is opened:%d", uuid_prefix,
+				  dinfo->major, dinfo->minor, info.open_count);
 			return 0;
+		}
 	}
 
 	return 1;
Signature · 1 line
1.7.4
#15 lore raw

PATCH 15/16 Remove dead assignment of lock_flags

In reply to Zdenek Kabelac

Variable 'lock_flags' is not used - so put into a comment.

---
 daemons/clvmd/clvmd-command.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
daemons/clvmd/clvmd-command.c +1 -2
index 6d0dee4..0c0a6cb 100644
@@ -185,7 +185,6 @@ static int lock_vg(struct local_client *client)
     struct clvm_header *header =
 	(struct clvm_header *) client->bits.localsock.cmd;
     unsigned char lock_cmd;
-    unsigned char lock_flags;
     int lock_mode;
     char *args = header->node + strlen(header->node) + 1;
     int lkid;
@@ -207,7 +206,7 @@ static int lock_vg(struct local_client *client)
 
     lock_cmd = args[0] & (LCK_NONBLOCK | LCK_HOLD | LCK_SCOPE_MASK | LCK_TYPE_MASK);
     lock_mode = ((int)lock_cmd & LCK_TYPE_MASK);
-    lock_flags = args[1];
+    /* lock_flags = args[1]; */
     lockname = &args[2];
     DEBUGLOG("doing PRE command LOCK_VG '%s' at %x (client=%p)\n", lockname, lock_cmd, client);
 
Signature · 1 line
1.7.4
#16 lore raw

PATCH 16/16 Remove dead assignment in vgconvert_single

In reply to Zdenek Kabelac

'pe_end' is unused, so hiding it as a comment in the code.

---
 tools/vgconvert.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
tools/vgconvert.c +2 -3
index acae0fc..729ce38 100644
@@ -26,7 +26,7 @@ static int vgconvert_single(struct cmd_context *cmd, const char *vg_name,
 	struct dm_list mdas;
 	int pvmetadatacopies = 0;
 	uint64_t pvmetadatasize = 0;
-	uint64_t pe_end = 0, pe_start = 0;
+	uint64_t pe_start = 0;
 	struct pv_list *pvl;
 	int change_made = 0;
 	struct lvinfo info;
@@ -119,8 +119,7 @@ static int vgconvert_single(struct cmd_context *cmd, const char *vg_name,
 		existing_pv = pvl->pv;
 
 		pe_start = pv_pe_start(existing_pv);
-		pe_end = pv_pe_count(existing_pv) * pv_pe_size(existing_pv)
-		    + pe_start - 1;
+		/* pe_end = pv_pe_count(existing_pv) * pv_pe_size(existing_pv) + pe_start - 1; */
 
 		dm_list_init(&mdas);
 		if (!(pv = pv_create(cmd, pv_dev(existing_pv),
Signature · 1 line
1.7.4