Blame SOURCES/0001-Merge-master-up-to-commit-53803821de16.patch

d617b2
 base/data-struct/list.h                      |   4 +-
d617b2
 daemons/lvmlockd/lvmlockd-client.h           |   1 +
d617b2
 daemons/lvmlockd/lvmlockd-core.c             | 370 +++++++--------
d617b2
 daemons/lvmlockd/lvmlockd-dlm.c              |   8 +-
d617b2
 daemons/lvmlockd/lvmlockd-internal.h         |   7 +-
d617b2
 lib/cache/lvmcache.c                         | 551 ++++++++++------------
d617b2
 lib/cache/lvmcache.h                         |  12 +-
d617b2
 lib/commands/toolcontext.c                   |   3 +-
d617b2
 lib/device/dev-io.c                          |   3 +
d617b2
 lib/format_text/archiver.c                   |   2 +-
d617b2
 lib/format_text/format-text.c                |  28 +-
d617b2
 lib/format_text/text_label.c                 |   8 +-
d617b2
 lib/label/hints.c                            |   6 +
d617b2
 lib/label/label.c                            |   2 +-
d617b2
 lib/label/label.h                            |   2 +-
d617b2
 lib/locking/lvmlockd.c                       |  14 +-
d617b2
 lib/metadata/metadata-exported.h             |   3 -
d617b2
 lib/metadata/metadata.c                      |  68 +--
d617b2
 lib/metadata/metadata.h                      |   8 +-
d617b2
 man/lvmlockd.8_main                          |  14 +-
d617b2
 test/shell/duplicate-vgnames.sh              | 660 +++++++++++++++++++++++++++
d617b2
 test/shell/duplicate-vgrename.sh             | 319 +++++++++++++
d617b2
 test/shell/integrity-dmeventd.sh             |   6 +-
d617b2
 test/shell/integrity-large.sh                |   6 +-
d617b2
 test/shell/integrity-misc.sh                 |   6 +-
d617b2
 test/shell/integrity.sh                      |   6 +-
d617b2
 test/shell/process-each-duplicate-vgnames.sh |  55 ---
d617b2
 test/shell/thin-foreign-repair.sh            |   4 +-
d617b2
 tools/command.c                              |  12 +-
d617b2
 tools/lvconvert.c                            |   3 +-
d617b2
 tools/pvck.c                                 |   8 +-
d617b2
 tools/pvscan.c                               |   2 +-
d617b2
 tools/toollib.c                              |   2 -
d617b2
 tools/vgchange.c                             |   9 +-
d617b2
 tools/vgimportclone.c                        |   4 +-
d617b2
 tools/vgmerge.c                              |   4 +-
d617b2
 tools/vgrename.c                             |   2 +-
d617b2
 tools/vgsplit.c                              |   2 +-
d617b2
 39 files changed, 1571 insertions(+), 654 deletions(-)
d617b2
 create mode 100644 test/shell/duplicate-vgnames.sh
d617b2
 create mode 100644 test/shell/duplicate-vgrename.sh
d617b2
 delete mode 100644 test/shell/process-each-duplicate-vgnames.sh
d617b2
d617b2
diff --git a/base/data-struct/list.h b/base/data-struct/list.h
d617b2
index 54cb1c1..e0a6256 100644
d617b2
--- a/base/data-struct/list.h
d617b2
+++ b/base/data-struct/list.h
d617b2
@@ -1,7 +1,7 @@
d617b2
 #ifndef BASE_DATA_STRUCT_LIST_H
d617b2
 #define BASE_DATA_STRUCT_LIST_H
d617b2
 
d617b2
-#include <stddef.h> /* offsetof */
d617b2
+#include "base/memory/container_of.h"
d617b2
 
d617b2
 //----------------------------------------------------------------
d617b2
 
d617b2
@@ -100,7 +100,7 @@ struct dm_list *dm_list_next(const struct dm_list *head, const struct dm_list *e
d617b2
  * contained in a structure of type t, return the containing structure.
d617b2
  */
d617b2
 #define dm_list_struct_base(v, t, head) \
d617b2
-    ((t *)((const char *)(v) - offsetof(t, head)))
d617b2
+    container_of(v, t, head)
d617b2
 
d617b2
 /*
d617b2
  * Given the address v of an instance of 'struct dm_list list' contained in
d617b2
diff --git a/daemons/lvmlockd/lvmlockd-client.h b/daemons/lvmlockd/lvmlockd-client.h
d617b2
index 16d1613..62ffb73 100644
d617b2
--- a/daemons/lvmlockd/lvmlockd-client.h
d617b2
+++ b/daemons/lvmlockd/lvmlockd-client.h
d617b2
@@ -14,6 +14,7 @@
d617b2
 #include "libdaemon/client/daemon-client.h"
d617b2
 
d617b2
 #define LVMLOCKD_SOCKET DEFAULT_RUN_DIR "/lvmlockd.socket"
d617b2
+#define LVMLOCKD_ADOPT_FILE DEFAULT_RUN_DIR "/lvmlockd.adopt"
d617b2
 
d617b2
 /* Wrappers to open/close connection */
d617b2
 
d617b2
diff --git a/daemons/lvmlockd/lvmlockd-core.c b/daemons/lvmlockd/lvmlockd-core.c
d617b2
index 39275fb..84272c4 100644
d617b2
--- a/daemons/lvmlockd/lvmlockd-core.c
d617b2
+++ b/daemons/lvmlockd/lvmlockd-core.c
d617b2
@@ -38,6 +38,8 @@
d617b2
 #define EXTERN
d617b2
 #include "lvmlockd-internal.h"
d617b2
 
d617b2
+static int str_to_mode(const char *str);
d617b2
+
d617b2
 /*
d617b2
  * Basic operation of lvmlockd
d617b2
  *
d617b2
@@ -142,6 +144,8 @@ static const char *lvmlockd_protocol = "lvmlockd";
d617b2
 static const int lvmlockd_protocol_version = 1;
d617b2
 static int daemon_quit;
d617b2
 static int adopt_opt;
d617b2
+static uint32_t adopt_update_count;
d617b2
+static const char *adopt_file;
d617b2
 
d617b2
 /*
d617b2
  * We use a separate socket for dumping daemon info.
d617b2
@@ -812,6 +816,144 @@ int version_from_args(char *args, unsigned int *major, unsigned int *minor, unsi
d617b2
 }
d617b2
 
d617b2
 /*
d617b2
+ * Write new info when a command exits if that command has acquired a new LV
d617b2
+ * lock.  If the command has released an LV lock we don't bother updating the
d617b2
+ * info.  When adopting, we eliminate any LV lock adoptions if there is no dm
d617b2
+ * device for that LV.  If lvmlockd is terminated after acquiring but before
d617b2
+ * writing this file, those LV locks would not be adopted on restart.
d617b2
+ */
d617b2
+
d617b2
+#define ADOPT_VERSION_MAJOR 1
d617b2
+#define ADOPT_VERSION_MINOR 0
d617b2
+
d617b2
+static void write_adopt_file(void)
d617b2
+{
d617b2
+	struct lockspace *ls;
d617b2
+	struct resource *r;
d617b2
+	struct lock *lk;
d617b2
+	time_t t;
d617b2
+	FILE *fp;
d617b2
+
d617b2
+	if (!(fp = fopen(adopt_file, "w")))
d617b2
+		return;
d617b2
+
d617b2
+	adopt_update_count++;
d617b2
+
d617b2
+	t = time(NULL);
d617b2
+	fprintf(fp, "lvmlockd adopt_version %u.%u pid %d updates %u %s",
d617b2
+		ADOPT_VERSION_MAJOR, ADOPT_VERSION_MINOR, getpid(), adopt_update_count, ctime(&t);;
d617b2
+
d617b2
+	pthread_mutex_lock(&lockspaces_mutex);
d617b2
+	list_for_each_entry(ls, &lockspaces, list) {
d617b2
+		if (ls->lm_type == LD_LM_DLM && !strcmp(ls->name, gl_lsname_dlm))
d617b2
+			continue;
d617b2
+		fprintf(fp, "VG: %38s %s %s %s\n",
d617b2
+			ls->vg_uuid, ls->vg_name, lm_str(ls->lm_type), ls->vg_args);
d617b2
+		list_for_each_entry(r, &ls->resources, list) {
d617b2
+			if (r->type != LD_RT_LV)
d617b2
+				continue;
d617b2
+			if ((r->mode != LD_LK_EX) && (r->mode != LD_LK_SH))
d617b2
+				continue;
d617b2
+			list_for_each_entry(lk, &r->locks, list) {
d617b2
+				fprintf(fp, "LV: %38s %s %s %s %u\n",
d617b2
+					ls->vg_uuid, r->name, r->lv_args, mode_str(r->mode), r->version);
d617b2
+			}
d617b2
+		}
d617b2
+	}
d617b2
+	pthread_mutex_unlock(&lockspaces_mutex);
d617b2
+
d617b2
+	fflush(fp);
d617b2
+	fclose(fp);
d617b2
+}
d617b2
+
d617b2
+static int read_adopt_file(struct list_head *vg_lockd)
d617b2
+{
d617b2
+	char adopt_line[512];
d617b2
+	char vg_uuid[72];
d617b2
+	char lm_type_str[16];
d617b2
+	char mode[8];
d617b2
+	struct lockspace *ls, *ls2;
d617b2
+	struct resource *r;
d617b2
+	FILE *fp;
d617b2
+
d617b2
+	if (MAX_ARGS != 64 || MAX_NAME != 64)
d617b2
+		return -1;
d617b2
+
d617b2
+	if (!(fp = fopen(adopt_file, "r")))
d617b2
+		return 0;
d617b2
+
d617b2
+	while (fgets(adopt_line, sizeof(adopt_line), fp)) {
d617b2
+		if (adopt_line[0] == '#')
d617b2
+			continue;
d617b2
+		else if (!strncmp(adopt_line, "lvmlockd", 8)) {
d617b2
+			unsigned int v_major = 0, v_minor = 0;
d617b2
+			sscanf(adopt_line, "lvmlockd adopt_version %u.%u", &v_major, &v_minor);
d617b2
+			if (v_major != ADOPT_VERSION_MAJOR)
d617b2
+				goto fail;
d617b2
+
d617b2
+		} else if (!strncmp(adopt_line, "VG:", 3)) {
d617b2
+			if (!(ls = alloc_lockspace()))
d617b2
+				goto fail;
d617b2
+
d617b2
+			memset(vg_uuid, 0, sizeof(vg_uuid));
d617b2
+
d617b2
+			if (sscanf(adopt_line, "VG: %63s %64s %16s %64s",
d617b2
+				   vg_uuid, ls->vg_name, lm_type_str, ls->vg_args) != 4) {
d617b2
+				goto fail;
d617b2
+			}
d617b2
+
d617b2
+			memcpy(ls->vg_uuid, vg_uuid, 64);
d617b2
+
d617b2
+			if ((ls->lm_type = str_to_lm(lm_type_str)) < 0)
d617b2
+				goto fail;
d617b2
+
d617b2
+			list_add(&ls->list, vg_lockd);
d617b2
+
d617b2
+		} else if (!strncmp(adopt_line, "LV:", 3)) {
d617b2
+			if (!(r = alloc_resource()))
d617b2
+				goto fail;
d617b2
+
d617b2
+			r->type = LD_RT_LV;
d617b2
+
d617b2
+			memset(vg_uuid, 0, sizeof(vg_uuid));
d617b2
+
d617b2
+			if (sscanf(adopt_line, "LV: %64s %64s %s %8s %u",
d617b2
+				   vg_uuid, r->name, r->lv_args, mode, &r->version) != 5) {
d617b2
+				goto fail;
d617b2
+			}
d617b2
+
d617b2
+			if ((r->adopt_mode = str_to_mode(mode)) == LD_LK_IV)
d617b2
+				goto fail;
d617b2
+
d617b2
+			if (ls && !memcmp(ls->vg_uuid, vg_uuid, 64)) {
d617b2
+				list_add(&r->list, &ls->resources);
d617b2
+				r = NULL;
d617b2
+			} else {
d617b2
+				list_for_each_entry(ls2, vg_lockd, list) {
d617b2
+					if (memcmp(ls2->vg_uuid, vg_uuid, 64))
d617b2
+						continue;
d617b2
+					list_add(&r->list, &ls2->resources);
d617b2
+					r = NULL;
d617b2
+					break;
d617b2
+				}
d617b2
+			}
d617b2
+
d617b2
+			if (r) {
d617b2
+				log_error("No lockspace found for resource %s vg_uuid %s", r->name, vg_uuid);
d617b2
+				goto fail;
d617b2
+			}
d617b2
+		}
d617b2
+	}
d617b2
+
d617b2
+	fclose(fp);
d617b2
+	return 0;
d617b2
+
d617b2
+fail:
d617b2
+	fclose(fp);
d617b2
+	return -1;
d617b2
+}
d617b2
+
d617b2
+/*
d617b2
  * These are few enough that arrays of function pointers can
d617b2
  * be avoided.
d617b2
  */
d617b2
@@ -4689,6 +4831,7 @@ static void *client_thread_main(void *arg_in)
d617b2
 	struct client *cl;
d617b2
 	struct action *act;
d617b2
 	struct action *act_un;
d617b2
+	uint32_t lock_acquire_count = 0, lock_acquire_written = 0;
d617b2
 	int rv;
d617b2
 
d617b2
 	while (1) {
d617b2
@@ -4720,6 +4863,9 @@ static void *client_thread_main(void *arg_in)
d617b2
 				rv = -1;
d617b2
 			}
d617b2
 
d617b2
+			if (act->flags & LD_AF_LV_LOCK)
d617b2
+				lock_acquire_count++;
d617b2
+
d617b2
 			/*
d617b2
 			 * The client failed after we acquired an LV lock for
d617b2
 			 * it, but before getting this reply saying it's done.
d617b2
@@ -4741,6 +4887,11 @@ static void *client_thread_main(void *arg_in)
d617b2
 			continue;
d617b2
 		}
d617b2
 
d617b2
+		if (adopt_opt && (lock_acquire_count > lock_acquire_written)) {
d617b2
+			lock_acquire_written = lock_acquire_count;
d617b2
+			write_adopt_file();
d617b2
+		}
d617b2
+
d617b2
 		/*
d617b2
 		 * Queue incoming actions for lockspace threads
d617b2
 		 */
d617b2
@@ -4814,6 +4965,8 @@ static void *client_thread_main(void *arg_in)
d617b2
 			pthread_mutex_unlock(&client_mutex);
d617b2
 	}
d617b2
 out:
d617b2
+	if (adopt_opt && lock_acquire_written)
d617b2
+		unlink(adopt_file);
d617b2
 	return NULL;
d617b2
 }
d617b2
 
d617b2
@@ -4846,180 +4999,6 @@ static void close_client_thread(void)
d617b2
 		log_error("pthread_join client_thread error %d", perrno);
d617b2
 }
d617b2
 
d617b2
-/*
d617b2
- * Get a list of all VGs with a lockd type (sanlock|dlm).
d617b2
- * We'll match this list against a list of existing lockspaces that are
d617b2
- * found in the lock manager.
d617b2
- *
d617b2
- * For each of these VGs, also create a struct resource on ls->resources to
d617b2
- * represent each LV in the VG that uses a lock.  For each of these LVs
d617b2
- * that are active, we'll attempt to adopt a lock.
d617b2
- */
d617b2
-
d617b2
-static int get_lockd_vgs(struct list_head *vg_lockd)
d617b2
-{
d617b2
-	/* FIXME: get VGs some other way */
d617b2
-	return -1;
d617b2
-#if 0
d617b2
-	struct list_head update_vgs;
d617b2
-	daemon_reply reply;
d617b2
-	struct dm_config_node *cn;
d617b2
-	struct dm_config_node *metadata;
d617b2
-	struct dm_config_node *md_cn;
d617b2
-	struct dm_config_node *lv_cn;
d617b2
-	struct lockspace *ls, *safe;
d617b2
-	struct resource *r;
d617b2
-	const char *vg_name;
d617b2
-	const char *vg_uuid;
d617b2
-	const char *lv_uuid;
d617b2
-	const char *lock_type;
d617b2
-	const char *lock_args;
d617b2
-	char find_str_path[PATH_MAX];
d617b2
-	int rv = 0;
d617b2
-
d617b2
-	INIT_LIST_HEAD(&update_vgs);
d617b2
-
d617b2
-	reply = send_lvmetad("vg_list", "token = %s", "skip", NULL);
d617b2
-
d617b2
-	if (reply.error || strcmp(daemon_reply_str(reply, "response", ""), "OK")) {
d617b2
-		log_error("vg_list from lvmetad failed %d", reply.error);
d617b2
-		rv = -EINVAL;
d617b2
-		goto destroy;
d617b2
-	}
d617b2
-
d617b2
-	if (!(cn = dm_config_find_node(reply.cft->root, "volume_groups"))) {
d617b2
-		log_error("get_lockd_vgs no vgs");
d617b2
-		rv = -EINVAL;
d617b2
-		goto destroy;
d617b2
-	}
d617b2
-
d617b2
-	/* create an update_vgs list of all vg uuids */
d617b2
-
d617b2
-	for (cn = cn->child; cn; cn = cn->sib) {
d617b2
-		vg_uuid = cn->key;
d617b2
-
d617b2
-		if (!(ls = alloc_lockspace())) {
d617b2
-			rv = -ENOMEM;
d617b2
-			break;
d617b2
-		}
d617b2
-
d617b2
-		strncpy(ls->vg_uuid, vg_uuid, 64);
d617b2
-		list_add_tail(&ls->list, &update_vgs);
d617b2
-		log_debug("get_lockd_vgs %s", vg_uuid);
d617b2
-	}
d617b2
- destroy:
d617b2
-	daemon_reply_destroy(reply);
d617b2
-
d617b2
-	if (rv < 0)
d617b2
-		goto out;
d617b2
-
d617b2
-	/* get vg_name and lock_type for each vg uuid entry in update_vgs */
d617b2
-
d617b2
-	list_for_each_entry(ls, &update_vgs, list) {
d617b2
-		reply = send_lvmetad("vg_lookup",
d617b2
-				     "token = %s", "skip",
d617b2
-				     "uuid = %s", ls->vg_uuid,
d617b2
-				     NULL);
d617b2
-
d617b2
-		if (reply.error || strcmp(daemon_reply_str(reply, "response", ""), "OK")) {
d617b2
-			log_error("vg_lookup from lvmetad failed %d", reply.error);
d617b2
-			rv = -EINVAL;
d617b2
-			goto next;
d617b2
-		}
d617b2
-
d617b2
-		vg_name = daemon_reply_str(reply, "name", NULL);
d617b2
-		if (!vg_name) {
d617b2
-			log_error("get_lockd_vgs %s no name", ls->vg_uuid);
d617b2
-			rv = -EINVAL;
d617b2
-			goto next;
d617b2
-		}
d617b2
-
d617b2
-		strncpy(ls->vg_name, vg_name, MAX_NAME);
d617b2
-
d617b2
-		metadata = dm_config_find_node(reply.cft->root, "metadata");
d617b2
-		if (!metadata) {
d617b2
-			log_error("get_lockd_vgs %s name %s no metadata",
d617b2
-				  ls->vg_uuid, ls->vg_name);
d617b2
-			rv = -EINVAL;
d617b2
-			goto next;
d617b2
-		}
d617b2
-
d617b2
-		lock_type = dm_config_find_str(metadata, "metadata/lock_type", NULL);
d617b2
-		ls->lm_type = str_to_lm(lock_type);
d617b2
-
d617b2
-		if ((ls->lm_type != LD_LM_SANLOCK) && (ls->lm_type != LD_LM_DLM)) {
d617b2
-			log_debug("get_lockd_vgs %s not lockd type", ls->vg_name);
d617b2
-			continue;
d617b2
-		}
d617b2
-
d617b2
-		lock_args = dm_config_find_str(metadata, "metadata/lock_args", NULL);
d617b2
-		if (lock_args)
d617b2
-			strncpy(ls->vg_args, lock_args, MAX_ARGS);
d617b2
-
d617b2
-		log_debug("get_lockd_vgs %s lock_type %s lock_args %s",
d617b2
-			  ls->vg_name, lock_type, lock_args ?: "none");
d617b2
-
d617b2
-		/*
d617b2
-		 * Make a record (struct resource) of each lv that uses a lock.
d617b2
-		 * For any lv that uses a lock, we'll check if the lv is active
d617b2
-		 * and if so try to adopt a lock for it.
d617b2
-		 */
d617b2
-
d617b2
-		for (md_cn = metadata->child; md_cn; md_cn = md_cn->sib) {
d617b2
-			if (strcmp(md_cn->key, "logical_volumes"))
d617b2
-				continue;
d617b2
-
d617b2
-			for (lv_cn = md_cn->child; lv_cn; lv_cn = lv_cn->sib) {
d617b2
-				snprintf(find_str_path, PATH_MAX, "%s/lock_args", lv_cn->key);
d617b2
-				lock_args = dm_config_find_str(lv_cn, find_str_path, NULL);
d617b2
-				if (!lock_args)
d617b2
-					continue;
d617b2
-
d617b2
-				snprintf(find_str_path, PATH_MAX, "%s/id", lv_cn->key);
d617b2
-				lv_uuid = dm_config_find_str(lv_cn, find_str_path, NULL);
d617b2
-
d617b2
-				if (!lv_uuid) {
d617b2
-					log_error("get_lock_vgs no lv id for name %s", lv_cn->key);
d617b2
-					continue;
d617b2
-				}
d617b2
-
d617b2
-				if (!(r = alloc_resource())) {
d617b2
-					rv = -ENOMEM;
d617b2
-					goto next;
d617b2
-				}
d617b2
-
d617b2
-				r->use_vb = 0;
d617b2
-				r->type = LD_RT_LV;
d617b2
-				strncpy(r->name, lv_uuid, MAX_NAME);
d617b2
-				if (lock_args)
d617b2
-					strncpy(r->lv_args, lock_args, MAX_ARGS);
d617b2
-				list_add_tail(&r->list, &ls->resources);
d617b2
-				log_debug("get_lockd_vgs %s lv %s %s (name %s)",
d617b2
-					  ls->vg_name, r->name, lock_args ? lock_args : "", lv_cn->key);
d617b2
-			}
d617b2
-		}
d617b2
- next:
d617b2
-		daemon_reply_destroy(reply);
d617b2
-
d617b2
-		if (rv < 0)
d617b2
-			break;
d617b2
-	}
d617b2
-out:
d617b2
-	/* Return lockd VG's on the vg_lockd list. */
d617b2
-
d617b2
-	list_for_each_entry_safe(ls, safe, &update_vgs, list) {
d617b2
-		list_del(&ls->list);
d617b2
-
d617b2
-		if ((ls->lm_type == LD_LM_SANLOCK) || (ls->lm_type == LD_LM_DLM))
d617b2
-			list_add_tail(&ls->list, vg_lockd);
d617b2
-		else
d617b2
-			free(ls);
d617b2
-	}
d617b2
-
d617b2
-	return rv;
d617b2
-#endif
d617b2
-}
d617b2
-
d617b2
 static char _dm_uuid[DM_UUID_LEN];
d617b2
 
d617b2
 static char *get_dm_uuid(char *dm_name)
d617b2
@@ -5236,9 +5215,9 @@ static void adopt_locks(void)
d617b2
 	INIT_LIST_HEAD(&to_unlock);
d617b2
 
d617b2
 	/*
d617b2
-	 * Get list of lockspaces from lock managers.
d617b2
-	 * Get list of VGs from lvmetad with a lockd type.
d617b2
-	 * Get list of active lockd type LVs from /dev.
d617b2
+	 * Get list of lockspaces from currently running lock managers.
d617b2
+	 * Get list of shared VGs from file written by prior lvmlockd.
d617b2
+	 * Get list of active LVs (in the shared VGs) from the file.
d617b2
 	 */
d617b2
 
d617b2
 	if (lm_support_dlm() && lm_is_running_dlm()) {
d617b2
@@ -5262,12 +5241,17 @@ static void adopt_locks(void)
d617b2
 	 * Adds a struct lockspace to vg_lockd for each lockd VG.
d617b2
 	 * Adds a struct resource to ls->resources for each LV.
d617b2
 	 */
d617b2
-	rv = get_lockd_vgs(&vg_lockd);
d617b2
+	rv = read_adopt_file(&vg_lockd);
d617b2
 	if (rv < 0) {
d617b2
-		log_error("adopt_locks get_lockd_vgs failed");
d617b2
+		log_error("adopt_locks read_adopt_file failed");
d617b2
 		goto fail;
d617b2
 	}
d617b2
 
d617b2
+	if (list_empty(&vg_lockd)) {
d617b2
+		log_debug("No lockspaces in adopt file");
d617b2
+		return;
d617b2
+	}
d617b2
+
d617b2
 	/*
d617b2
 	 * For each resource on each lockspace, check if the
d617b2
 	 * corresponding LV is active.  If so, leave the
d617b2
@@ -5506,7 +5490,7 @@ static void adopt_locks(void)
d617b2
 				goto fail;
d617b2
 			act->op = LD_OP_LOCK;
d617b2
 			act->rt = LD_RT_LV;
d617b2
-			act->mode = LD_LK_EX;
d617b2
+			act->mode = r->adopt_mode;
d617b2
 			act->flags = (LD_AF_ADOPT | LD_AF_PERSISTENT);
d617b2
 			act->client_id = INTERNAL_CLIENT_ID;
d617b2
 			act->lm_type = ls->lm_type;
d617b2
@@ -5604,8 +5588,9 @@ static void adopt_locks(void)
d617b2
 			 * Adopt failed because the orphan has a different mode
d617b2
 			 * than initially requested.  Repeat the lock-adopt operation
d617b2
 			 * with the other mode.  N.B. this logic depends on first
d617b2
-			 * trying sh then ex for GL/VG locks, and ex then sh for
d617b2
-			 * LV locks.
d617b2
+			 * trying sh then ex for GL/VG locks; for LV locks the mode
d617b2
+			 * from the adopt file is tried first, the alternate
d617b2
+			 * (if the mode in adopt file was wrong somehow.)
d617b2
 			 */
d617b2
 
d617b2
 			if ((act->rt != LD_RT_LV) && (act->mode == LD_LK_SH)) {
d617b2
@@ -5613,9 +5598,12 @@ static void adopt_locks(void)
d617b2
 				act->mode = LD_LK_EX;
d617b2
 				rv = add_lock_action(act);
d617b2
 
d617b2
-			} else if ((act->rt == LD_RT_LV) && (act->mode == LD_LK_EX)) {
d617b2
-				/* LV locks: attempt to adopt sh after ex failed. */
d617b2
-				act->mode = LD_LK_SH;
d617b2
+			} else if (act->rt == LD_RT_LV) {
d617b2
+				/* LV locks: attempt to adopt the other mode. */
d617b2
+				if (act->mode == LD_LK_EX)
d617b2
+					act->mode = LD_LK_SH;
d617b2
+				else if (act->mode == LD_LK_SH)
d617b2
+					act->mode = LD_LK_EX;
d617b2
 				rv = add_lock_action(act);
d617b2
 
d617b2
 			} else {
d617b2
@@ -5750,10 +5738,13 @@ static void adopt_locks(void)
d617b2
 	if (count_start_fail || count_adopt_fail)
d617b2
 		goto fail;
d617b2
 
d617b2
+	unlink(adopt_file);
d617b2
+	write_adopt_file();
d617b2
 	log_debug("adopt_locks done");
d617b2
 	return;
d617b2
 
d617b2
 fail:
d617b2
+	unlink(adopt_file);
d617b2
 	log_error("adopt_locks failed, reset host");
d617b2
 }
d617b2
 
d617b2
@@ -6028,6 +6019,8 @@ static void usage(char *prog, FILE *file)
d617b2
 	fprintf(file, "        Set path to the pid file. [%s]\n", LVMLOCKD_PIDFILE);
d617b2
 	fprintf(file, "  --socket-path | -s <path>\n");
d617b2
 	fprintf(file, "        Set path to the socket to listen on. [%s]\n", LVMLOCKD_SOCKET);
d617b2
+	fprintf(file, "  --adopt-file <path>\n");
d617b2
+	fprintf(file, "        Set path to the adopt file. [%s]\n", LVMLOCKD_ADOPT_FILE);
d617b2
 	fprintf(file, "  --syslog-priority | -S err|warning|debug\n");
d617b2
 	fprintf(file, "        Write log messages from this level up to syslog. [%s]\n", _syslog_num_to_name(LOG_SYSLOG_PRIO));
d617b2
 	fprintf(file, "  --gl-type | -g <str>\n");
d617b2
@@ -6063,6 +6056,7 @@ int main(int argc, char *argv[])
d617b2
 		{"daemon-debug",    no_argument,       0, 'D' },
d617b2
 		{"pid-file",        required_argument, 0, 'p' },
d617b2
 		{"socket-path",     required_argument, 0, 's' },
d617b2
+		{"adopt-file",      required_argument, 0, 128 },
d617b2
 		{"gl-type",         required_argument, 0, 'g' },
d617b2
 		{"host-id",         required_argument, 0, 'i' },
d617b2
 		{"host-id-file",    required_argument, 0, 'F' },
d617b2
@@ -6085,6 +6079,9 @@ int main(int argc, char *argv[])
d617b2
 		switch (c) {
d617b2
 		case '0':
d617b2
 			break;
d617b2
+		case 128:
d617b2
+			adopt_file = strdup(optarg);
d617b2
+			break;
d617b2
 		case 'h':
d617b2
 			usage(argv[0], stdout);
d617b2
 			exit(EXIT_SUCCESS);
d617b2
@@ -6146,6 +6143,9 @@ int main(int argc, char *argv[])
d617b2
 	if (!ds.socket_path)
d617b2
 		ds.socket_path = LVMLOCKD_SOCKET;
d617b2
 
d617b2
+	if (!adopt_file)
d617b2
+		adopt_file = LVMLOCKD_ADOPT_FILE;
d617b2
+
d617b2
 	/* runs daemon_main/main_loop */
d617b2
 	daemon_start(ds);
d617b2
 
d617b2
diff --git a/daemons/lvmlockd/lvmlockd-dlm.c b/daemons/lvmlockd/lvmlockd-dlm.c
d617b2
index 75e6dee..7915cc0 100644
d617b2
--- a/daemons/lvmlockd/lvmlockd-dlm.c
d617b2
+++ b/daemons/lvmlockd/lvmlockd-dlm.c
d617b2
@@ -398,12 +398,18 @@ static int lm_adopt_dlm(struct lockspace *ls, struct resource *r, int ld_mode,
d617b2
 			  (void *)1, (void *)1, (void *)1,
d617b2
 			  NULL, NULL);
d617b2
 
d617b2
-	if (rv == -1 && errno == -EAGAIN) {
d617b2
+	if (rv == -1 && (errno == EAGAIN)) {
d617b2
 		log_debug("S %s R %s adopt_dlm adopt mode %d try other mode",
d617b2
 			  ls->name, r->name, ld_mode);
d617b2
 		rv = -EUCLEAN;
d617b2
 		goto fail;
d617b2
 	}
d617b2
+	if (rv == -1 && (errno == ENOENT)) {
d617b2
+		log_debug("S %s R %s adopt_dlm adopt mode %d no lock",
d617b2
+			  ls->name, r->name, ld_mode);
d617b2
+		rv = -ENOENT;
d617b2
+		goto fail;
d617b2
+	}
d617b2
 	if (rv < 0) {
d617b2
 		log_debug("S %s R %s adopt_dlm mode %d flags %x error %d errno %d",
d617b2
 			  ls->name, r->name, mode, flags, rv, errno);
d617b2
diff --git a/daemons/lvmlockd/lvmlockd-internal.h b/daemons/lvmlockd/lvmlockd-internal.h
d617b2
index 85e8caf..191c449 100644
d617b2
--- a/daemons/lvmlockd/lvmlockd-internal.h
d617b2
+++ b/daemons/lvmlockd/lvmlockd-internal.h
d617b2
@@ -11,6 +11,8 @@
d617b2
 #ifndef _LVM_LVMLOCKD_INTERNAL_H
d617b2
 #define _LVM_LVMLOCKD_INTERNAL_H
d617b2
 
d617b2
+#include "base/memory/container_of.h"
d617b2
+
d617b2
 #define MAX_NAME 64
d617b2
 #define MAX_ARGS 64
d617b2
 
d617b2
@@ -145,6 +147,7 @@ struct resource {
d617b2
 	char name[MAX_NAME+1];		/* vg name or lv name */
d617b2
 	int8_t type;			/* resource type LD_RT_ */
d617b2
 	int8_t mode;
d617b2
+	int8_t adopt_mode;
d617b2
 	unsigned int sh_count;		/* number of sh locks on locks list */
d617b2
 	uint32_t version;
d617b2
 	uint32_t last_client_id;	/* last client_id to lock or unlock resource */
d617b2
@@ -216,10 +219,6 @@ struct val_blk {
d617b2
 /* lm_unlock flags */
d617b2
 #define LMUF_FREE_VG 0x00000001
d617b2
 
d617b2
-#define container_of(ptr, type, member) ({                      \
d617b2
-	const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
d617b2
-	(type *)( (char *)__mptr - offsetof(type,member) );})
d617b2
-
d617b2
 static inline void INIT_LIST_HEAD(struct list_head *list)
d617b2
 {
d617b2
 	list->next = list;
d617b2
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
d617b2
index 2c8c614..6cb5ff0 100644
d617b2
--- a/lib/cache/lvmcache.c
d617b2
+++ b/lib/cache/lvmcache.c
d617b2
@@ -49,7 +49,7 @@ struct lvmcache_info {
d617b2
 
d617b2
 /* One per VG */
d617b2
 struct lvmcache_vginfo {
d617b2
-	struct dm_list list;	/* Join these vginfos together */
d617b2
+	struct dm_list list;	 /* _vginfos */
d617b2
 	struct dm_list infos;	/* List head for lvmcache_infos */
d617b2
 	struct dm_list outdated_infos; /* vg_read moves info from infos to outdated_infos */
d617b2
 	struct dm_list pvsummaries; /* pv_list taken directly from vgsummary */
d617b2
@@ -58,7 +58,6 @@ struct lvmcache_vginfo {
d617b2
 	uint32_t status;
d617b2
 	char vgid[ID_LEN + 1];
d617b2
 	char _padding[7];
d617b2
-	struct lvmcache_vginfo *next; /* Another VG with same name? */
d617b2
 	char *creation_host;
d617b2
 	char *system_id;
d617b2
 	char *lock_type;
d617b2
@@ -66,8 +65,16 @@ struct lvmcache_vginfo {
d617b2
 	size_t mda_size;
d617b2
 	int seqno;
d617b2
 	bool scan_summary_mismatch; /* vgsummary from devs had mismatching seqno or checksum */
d617b2
+	bool has_duplicate_local_vgname;   /* this local vg and another local vg have same name */
d617b2
+	bool has_duplicate_foreign_vgname; /* this foreign vg and another foreign vg have same name */
d617b2
 };
d617b2
 
d617b2
+/*
d617b2
+ * Each VG found during scan gets a vginfo struct.
d617b2
+ * Each vginfo is in _vginfos and _vgid_hash, and
d617b2
+ * _vgname_hash (unless disabled due to duplicate vgnames).
d617b2
+ */
d617b2
+
d617b2
 static struct dm_hash_table *_pvid_hash = NULL;
d617b2
 static struct dm_hash_table *_vgid_hash = NULL;
d617b2
 static struct dm_hash_table *_vgname_hash = NULL;
d617b2
@@ -262,16 +269,6 @@ void lvmcache_get_mdas(struct cmd_context *cmd,
d617b2
 	}
d617b2
 }
d617b2
 
d617b2
-static void _vginfo_attach_info(struct lvmcache_vginfo *vginfo,
d617b2
-				struct lvmcache_info *info)
d617b2
-{
d617b2
-	if (!vginfo)
d617b2
-		return;
d617b2
-
d617b2
-	info->vginfo = vginfo;
d617b2
-	dm_list_add(&vginfo->infos, &info->list);
d617b2
-}
d617b2
-
d617b2
 static void _vginfo_detach_info(struct lvmcache_info *info)
d617b2
 {
d617b2
 	if (!dm_list_empty(&info->list)) {
d617b2
@@ -282,57 +279,80 @@ static void _vginfo_detach_info(struct lvmcache_info *info)
d617b2
 	info->vginfo = NULL;
d617b2
 }
d617b2
 
d617b2
-/* If vgid supplied, require a match. */
d617b2
-struct lvmcache_vginfo *lvmcache_vginfo_from_vgname(const char *vgname, const char *vgid)
d617b2
+static struct lvmcache_vginfo *_search_vginfos_list(const char *vgname, const char *vgid)
d617b2
 {
d617b2
 	struct lvmcache_vginfo *vginfo;
d617b2
 
d617b2
-	if (!vgname)
d617b2
-		return lvmcache_vginfo_from_vgid(vgid);
d617b2
-
d617b2
-	if (!_vgname_hash) {
d617b2
-		log_debug_cache(INTERNAL_ERROR "Internal lvmcache is no yet initialized.");
d617b2
-		return NULL;
d617b2
-	}
d617b2
-
d617b2
-	if (!(vginfo = dm_hash_lookup(_vgname_hash, vgname))) {
d617b2
-		log_debug_cache("lvmcache has no info for vgname \"%s\"%s" FMTVGID ".",
d617b2
-				vgname, (vgid) ? " with VGID " : "", (vgid) ? : "");
d617b2
-		return NULL;
d617b2
-	}
d617b2
-
d617b2
-	if (vgid)
d617b2
-		do
d617b2
-			if (!strncmp(vgid, vginfo->vgid, ID_LEN))
d617b2
+	if (vgid) {
d617b2
+		dm_list_iterate_items(vginfo, &_vginfos) {
d617b2
+			if (!strcmp(vgid, vginfo->vgid))
d617b2
 				return vginfo;
d617b2
-		while ((vginfo = vginfo->next));
d617b2
-
d617b2
-	if  (!vginfo)
d617b2
-		log_debug_cache("lvmcache has not found vgname \"%s\"%s" FMTVGID ".",
d617b2
-				vgname, (vgid) ? " with VGID " : "", (vgid) ? : "");
d617b2
-
d617b2
-	return vginfo;
d617b2
+		}
d617b2
+	} else {
d617b2
+		dm_list_iterate_items(vginfo, &_vginfos) {
d617b2
+			if (!strcmp(vgname, vginfo->vgname))
d617b2
+				return vginfo;
d617b2
+		}
d617b2
+	}
d617b2
+	return NULL;
d617b2
 }
d617b2
 
d617b2
-struct lvmcache_vginfo *lvmcache_vginfo_from_vgid(const char *vgid)
d617b2
+static struct lvmcache_vginfo *_vginfo_lookup(const char *vgname, const char *vgid)
d617b2
 {
d617b2
 	struct lvmcache_vginfo *vginfo;
d617b2
 	char id[ID_LEN + 1] __attribute__((aligned(8)));
d617b2
 
d617b2
-	if (!_vgid_hash || !vgid) {
d617b2
-		log_debug_cache(INTERNAL_ERROR "Internal cache cannot lookup vgid.");
d617b2
-		return NULL;
d617b2
+	if (vgid) {
d617b2
+		/* vgid not necessarily NULL-terminated */
d617b2
+		(void) dm_strncpy(id, vgid, sizeof(id));
d617b2
+
d617b2
+		if ((vginfo = dm_hash_lookup(_vgid_hash, id))) {
d617b2
+			if (vgname && strcmp(vginfo->vgname, vgname)) {
d617b2
+				/* should never happen */
d617b2
+				log_error(INTERNAL_ERROR "vginfo_lookup vgid %s has two names %s %s",
d617b2
+					  id, vginfo->vgname, vgname);
d617b2
+				return NULL;
d617b2
+			}
d617b2
+			return vginfo;
d617b2
+		} else {
d617b2
+			/* lookup by vgid that doesn't exist */
d617b2
+			return NULL;
d617b2
+		}
d617b2
 	}
d617b2
 
d617b2
-	/* vgid not necessarily NULL-terminated */
d617b2
-	(void) dm_strncpy(id, vgid, sizeof(id));
d617b2
+	if (vgname && !_found_duplicate_vgnames) {
d617b2
+		if ((vginfo = dm_hash_lookup(_vgname_hash, vgname))) {
d617b2
+			if (vginfo->has_duplicate_local_vgname) {
d617b2
+				/* should never happen, found_duplicate_vgnames should be set */
d617b2
+				log_error(INTERNAL_ERROR "vginfo_lookup %s %s has_duplicate_local_vgname", vgname, vgid);
d617b2
+				return NULL;
d617b2
+			}
d617b2
+			return vginfo;
d617b2
+		}
d617b2
+	}
d617b2
 
d617b2
-	if (!(vginfo = dm_hash_lookup(_vgid_hash, id))) {
d617b2
-		log_debug_cache("lvmcache has no info for vgid \"%s\"", id);
d617b2
-		return NULL;
d617b2
+	if (vgname && _found_duplicate_vgnames) {
d617b2
+		if ((vginfo = _search_vginfos_list(vgname, vgid))) {
d617b2
+			if (vginfo->has_duplicate_local_vgname) {
d617b2
+				log_debug("vginfo_lookup %s %s has_duplicate_local_vgname return none", vgname, vgid);
d617b2
+				return NULL;
d617b2
+			}
d617b2
+			return vginfo;
d617b2
+		}
d617b2
 	}
d617b2
 
d617b2
-	return vginfo;
d617b2
+	/* lookup by vgname that doesn't exist */
d617b2
+	return NULL;
d617b2
+}
d617b2
+
d617b2
+struct lvmcache_vginfo *lvmcache_vginfo_from_vgname(const char *vgname, const char *vgid)
d617b2
+{
d617b2
+	return _vginfo_lookup(vgname, vgid);
d617b2
+}
d617b2
+
d617b2
+struct lvmcache_vginfo *lvmcache_vginfo_from_vgid(const char *vgid)
d617b2
+{
d617b2
+	return _vginfo_lookup(NULL, vgid);
d617b2
 }
d617b2
 
d617b2
 const char *lvmcache_vgname_from_vgid(struct dm_pool *mem, const char *vgid)
d617b2
@@ -353,17 +373,43 @@ const char *lvmcache_vgid_from_vgname(struct cmd_context *cmd, const char *vgnam
d617b2
 {
d617b2
 	struct lvmcache_vginfo *vginfo;
d617b2
 
d617b2
-	if (!(vginfo = dm_hash_lookup(_vgname_hash, vgname)))
d617b2
-		return_NULL;
d617b2
+	if (_found_duplicate_vgnames) {
d617b2
+		if (!(vginfo = _search_vginfos_list(vgname, NULL)))
d617b2
+			return_NULL;
d617b2
+	} else {
d617b2
+		if (!(vginfo = dm_hash_lookup(_vgname_hash, vgname)))
d617b2
+			return_NULL;
d617b2
+	}
d617b2
 
d617b2
-	if (!vginfo->next)
d617b2
-		return dm_pool_strdup(cmd->mem, vginfo->vgid);
d617b2
+	if (vginfo->has_duplicate_local_vgname) {
d617b2
+		/*
d617b2
+		 * return NULL if there is a local VG with the same name since
d617b2
+		 * we don't know which to use.
d617b2
+		 */
d617b2
+		return NULL;
d617b2
+	}
d617b2
 
d617b2
-	/*
d617b2
-	 * There are multiple VGs with this name to choose from.
d617b2
-	 * Return an error because we don't know which VG is intended.
d617b2
-	 */
d617b2
-	return NULL;
d617b2
+	if (vginfo->has_duplicate_foreign_vgname)
d617b2
+		return NULL;
d617b2
+
d617b2
+	return dm_pool_strdup(cmd->mem, vginfo->vgid);
d617b2
+}
d617b2
+
d617b2
+bool lvmcache_has_duplicate_local_vgname(const char *vgid, const char *vgname)
d617b2
+{
d617b2
+	struct lvmcache_vginfo *vginfo;
d617b2
+
d617b2
+	if (_found_duplicate_vgnames) {
d617b2
+		if (!(vginfo = _search_vginfos_list(vgname, vgid)))
d617b2
+			return false;
d617b2
+	} else {
d617b2
+		if (!(vginfo = dm_hash_lookup(_vgname_hash, vgname)))
d617b2
+			return false;
d617b2
+	}
d617b2
+
d617b2
+	if (vginfo->has_duplicate_local_vgname)
d617b2
+		return true;
d617b2
+	return false;
d617b2
 }
d617b2
 
d617b2
 /*
d617b2
@@ -986,15 +1032,6 @@ int lvmcache_label_scan(struct cmd_context *cmd)
d617b2
 
d617b2
 	log_debug_cache("Finding VG info");
d617b2
 
d617b2
-	/* FIXME: can this happen? */
d617b2
-	if (!cmd->filter) {
d617b2
-		log_error("label scan is missing filter");
d617b2
-		goto out;
d617b2
-	}
d617b2
-
d617b2
-	if (!refresh_filters(cmd))
d617b2
-		log_error("Scan failed to refresh device filter.");
d617b2
-
d617b2
 	/*
d617b2
 	 * Duplicates found during this label scan are added to _initial_duplicates.
d617b2
 	 */
d617b2
@@ -1057,7 +1094,6 @@ int lvmcache_label_scan(struct cmd_context *cmd)
d617b2
 
d617b2
 	r = 1;
d617b2
 
d617b2
-      out:
d617b2
 	dm_list_iterate_items(vginfo, &_vginfos) {
d617b2
 		if (is_orphan_vg(vginfo->vgname))
d617b2
 			continue;
d617b2
@@ -1148,49 +1184,20 @@ int lvmcache_pvid_in_unused_duplicates(const char *pvid)
d617b2
 	return 0;
d617b2
 }
d617b2
 
d617b2
-static int _free_vginfo(struct lvmcache_vginfo *vginfo)
d617b2
+static void _free_vginfo(struct lvmcache_vginfo *vginfo)
d617b2
 {
d617b2
-	struct lvmcache_vginfo *primary_vginfo, *vginfo2;
d617b2
-	int r = 1;
d617b2
-
d617b2
-	vginfo2 = primary_vginfo = lvmcache_vginfo_from_vgname(vginfo->vgname, NULL);
d617b2
-
d617b2
-	if (vginfo == primary_vginfo) {
d617b2
-		dm_hash_remove(_vgname_hash, vginfo->vgname);
d617b2
-		if (vginfo->next && !dm_hash_insert(_vgname_hash, vginfo->vgname,
d617b2
-						    vginfo->next)) {
d617b2
-			log_error("_vgname_hash re-insertion for %s failed",
d617b2
-				  vginfo->vgname);
d617b2
-			r = 0;
d617b2
-		}
d617b2
-	} else
d617b2
-		while (vginfo2) {
d617b2
-			if (vginfo2->next == vginfo) {
d617b2
-				vginfo2->next = vginfo->next;
d617b2
-				break;
d617b2
-			}
d617b2
-			vginfo2 = vginfo2->next;
d617b2
-		}
d617b2
-
d617b2
-	free(vginfo->system_id);
d617b2
 	free(vginfo->vgname);
d617b2
+	free(vginfo->system_id);
d617b2
 	free(vginfo->creation_host);
d617b2
-
d617b2
-	if (*vginfo->vgid && _vgid_hash &&
d617b2
-	    lvmcache_vginfo_from_vgid(vginfo->vgid) == vginfo)
d617b2
-		dm_hash_remove(_vgid_hash, vginfo->vgid);
d617b2
-
d617b2
-	dm_list_del(&vginfo->list);
d617b2
-
d617b2
+	if (vginfo->lock_type)
d617b2
+		free(vginfo->lock_type);
d617b2
 	free(vginfo);
d617b2
-
d617b2
-	return r;
d617b2
 }
d617b2
 
d617b2
 /*
d617b2
- * vginfo must be info->vginfo unless info is NULL
d617b2
+ * Remove vginfo from standard lists/hashes.
d617b2
  */
d617b2
-static int _drop_vginfo(struct lvmcache_info *info, struct lvmcache_vginfo *vginfo)
d617b2
+static void _drop_vginfo(struct lvmcache_info *info, struct lvmcache_vginfo *vginfo)
d617b2
 {
d617b2
 	if (info)
d617b2
 		_vginfo_detach_info(info);
d617b2
@@ -1198,12 +1205,16 @@ static int _drop_vginfo(struct lvmcache_info *info, struct lvmcache_vginfo *vgin
d617b2
 	/* vginfo still referenced? */
d617b2
 	if (!vginfo || is_orphan_vg(vginfo->vgname) ||
d617b2
 	    !dm_list_empty(&vginfo->infos))
d617b2
-		return 1;
d617b2
+		return;
d617b2
 
d617b2
-	if (!_free_vginfo(vginfo))
d617b2
-		return_0;
d617b2
+	if (dm_hash_lookup(_vgname_hash, vginfo->vgname) == vginfo)
d617b2
+		dm_hash_remove(_vgname_hash, vginfo->vgname);
d617b2
 
d617b2
-	return 1;
d617b2
+	dm_hash_remove(_vgid_hash, vginfo->vgid);
d617b2
+
d617b2
+	dm_list_del(&vginfo->list); /* _vginfos list */
d617b2
+
d617b2
+	_free_vginfo(vginfo);
d617b2
 }
d617b2
 
d617b2
 void lvmcache_del(struct lvmcache_info *info)
d617b2
@@ -1261,180 +1272,150 @@ static int _lvmcache_update_vgid(struct lvmcache_info *info,
d617b2
 	return 1;
d617b2
 }
d617b2
 
d617b2
-static int _insert_vginfo(struct lvmcache_vginfo *new_vginfo, const char *vgid,
d617b2
-			  uint32_t vgstatus, const char *creation_host,
d617b2
-			  struct lvmcache_vginfo *primary_vginfo)
d617b2
+static int _lvmcache_update_vgname(struct cmd_context *cmd,
d617b2
+				   struct lvmcache_info *info,
d617b2
+				   const char *vgname, const char *vgid,
d617b2
+				   const char *system_id,
d617b2
+				   const struct format_type *fmt)
d617b2
 {
d617b2
-	struct lvmcache_vginfo *last_vginfo = primary_vginfo;
d617b2
-	char uuid_primary[64] __attribute__((aligned(8)));
d617b2
-	char uuid_new[64] __attribute__((aligned(8)));
d617b2
-	int use_new = 0;
d617b2
-
d617b2
-	/* Pre-existing VG takes precedence. Unexported VG takes precedence. */
d617b2
-	if (primary_vginfo) {
d617b2
-		if (!id_write_format((const struct id *)vgid, uuid_new, sizeof(uuid_new)))
d617b2
-			return_0;
d617b2
+	char vgid_str[64] __attribute__((aligned(8)));
d617b2
+	char other_str[64] __attribute__((aligned(8)));
d617b2
+	struct lvmcache_vginfo *vginfo;
d617b2
+	struct lvmcache_vginfo *other;
d617b2
+	int vginfo_is_allowed;
d617b2
+	int other_is_allowed;
d617b2
 
d617b2
-		if (!id_write_format((const struct id *)&primary_vginfo->vgid, uuid_primary,
d617b2
-				     sizeof(uuid_primary)))
d617b2
-			return_0;
d617b2
+	if (!vgname || (info && info->vginfo && !strcmp(info->vginfo->vgname, vgname)))
d617b2
+		return 1;
d617b2
 
d617b2
-		_found_duplicate_vgnames = 1;
d617b2
+	if (!id_write_format((const struct id *)vgid, vgid_str, sizeof(vgid_str)))
d617b2
+		stack;
d617b2
 
d617b2
-		/*
d617b2
-		 * vginfo is kept for each VG with the same name.
d617b2
-		 * They are saved with the vginfo->next list.
d617b2
-		 * These checks just decide the ordering of
d617b2
-		 * that list.
d617b2
-		 *
d617b2
-		 * FIXME: it should no longer matter what order
d617b2
-		 * the vginfo's are kept in, so we can probably
d617b2
-		 * remove these comparisons and reordering entirely.
d617b2
-		 *
d617b2
-		 * If   Primary not exported, new exported => keep
d617b2
-		 * Else Primary exported, new not exported => change
d617b2
-		 * Else Primary has hostname for this machine => keep
d617b2
-		 * Else Primary has no hostname, new has one => change
d617b2
-		 * Else New has hostname for this machine => change
d617b2
-		 * Else Keep primary.
d617b2
-		 */
d617b2
-		if (!(primary_vginfo->status & EXPORTED_VG) &&
d617b2
-		    (vgstatus & EXPORTED_VG))
d617b2
-			log_verbose("Cache: Duplicate VG name %s: "
d617b2
-				    "Existing %s takes precedence over "
d617b2
-				    "exported %s", new_vginfo->vgname,
d617b2
-				    uuid_primary, uuid_new);
d617b2
-		else if ((primary_vginfo->status & EXPORTED_VG) &&
d617b2
-			   !(vgstatus & EXPORTED_VG)) {
d617b2
-			log_verbose("Cache: Duplicate VG name %s: "
d617b2
-				    "%s takes precedence over exported %s",
d617b2
-				    new_vginfo->vgname, uuid_new,
d617b2
-				    uuid_primary);
d617b2
-			use_new = 1;
d617b2
-		} else if (primary_vginfo->creation_host &&
d617b2
-			   !strcmp(primary_vginfo->creation_host,
d617b2
-				   primary_vginfo->fmt->cmd->hostname))
d617b2
-			log_verbose("Cache: Duplicate VG name %s: "
d617b2
-				    "Existing %s (created here) takes precedence "
d617b2
-				    "over %s", new_vginfo->vgname, uuid_primary,
d617b2
-				    uuid_new);
d617b2
-		else if (!primary_vginfo->creation_host && creation_host) {
d617b2
-			log_verbose("Cache: Duplicate VG name %s: "
d617b2
-				    "%s (with creation_host) takes precedence over %s",
d617b2
-				    new_vginfo->vgname, uuid_new,
d617b2
-				    uuid_primary);
d617b2
-			use_new = 1;
d617b2
-		} else if (creation_host &&
d617b2
-			   !strcmp(creation_host,
d617b2
-				   primary_vginfo->fmt->cmd->hostname)) {
d617b2
-			log_verbose("Cache: Duplicate VG name %s: "
d617b2
-				    "%s (created here) takes precedence over %s",
d617b2
-				    new_vginfo->vgname, uuid_new,
d617b2
-				    uuid_primary);
d617b2
-			use_new = 1;
d617b2
-		} else {
d617b2
-			log_verbose("Cache: Duplicate VG name %s: "
d617b2
-				    "Prefer existing %s vs new %s",
d617b2
-				    new_vginfo->vgname, uuid_primary, uuid_new);
d617b2
+	/*
d617b2
+	 * Add vginfo for orphan VG
d617b2
+	 */
d617b2
+	if (!info) {
d617b2
+		if (!(vginfo = zalloc(sizeof(*vginfo)))) {
d617b2
+			log_error("lvmcache adding vg list alloc failed %s", vgname);
d617b2
+			return 0;
d617b2
 		}
d617b2
-
d617b2
-		if (!use_new) {
d617b2
-			while (last_vginfo->next)
d617b2
-				last_vginfo = last_vginfo->next;
d617b2
-			last_vginfo->next = new_vginfo;
d617b2
-			return 1;
d617b2
+		if (!(vginfo->vgname = strdup(vgname))) {
d617b2
+			free(vginfo);
d617b2
+			log_error("lvmcache adding vg name alloc failed %s", vgname);
d617b2
+			return 0;
d617b2
 		}
d617b2
+		dm_list_init(&vginfo->infos);
d617b2
+		dm_list_init(&vginfo->outdated_infos);
d617b2
+		dm_list_init(&vginfo->pvsummaries);
d617b2
+		vginfo->fmt = fmt;
d617b2
 
d617b2
-		dm_hash_remove(_vgname_hash, primary_vginfo->vgname);
d617b2
-	}
d617b2
-
d617b2
-	if (!dm_hash_insert(_vgname_hash, new_vginfo->vgname, new_vginfo)) {
d617b2
-		log_error("cache_update: vg hash insertion failed: %s",
d617b2
-		  	new_vginfo->vgname);
d617b2
-		return 0;
d617b2
-	}
d617b2
-
d617b2
-	if (primary_vginfo)
d617b2
-		new_vginfo->next = primary_vginfo;
d617b2
-
d617b2
-	return 1;
d617b2
-}
d617b2
+		if (!dm_hash_insert(_vgname_hash, vgname, vginfo)) {
d617b2
+			free(vginfo->vgname);
d617b2
+			free(vginfo);
d617b2
+			return_0;
d617b2
+		}
d617b2
 
d617b2
-static int _lvmcache_update_vgname(struct lvmcache_info *info,
d617b2
-				   const char *vgname, const char *vgid,
d617b2
-				   uint32_t vgstatus, const char *creation_host,
d617b2
-				   const struct format_type *fmt)
d617b2
-{
d617b2
-	struct lvmcache_vginfo *vginfo, *primary_vginfo;
d617b2
-	char mdabuf[32];
d617b2
+		if (!_lvmcache_update_vgid(NULL, vginfo, vgid)) {
d617b2
+			free(vginfo->vgname);
d617b2
+			free(vginfo);
d617b2
+			return_0;
d617b2
+		}
d617b2
 
d617b2
-	if (!vgname || (info && info->vginfo && !strcmp(info->vginfo->vgname, vgname)))
d617b2
+		/* Ensure orphans appear last on list_iterate */
d617b2
+		dm_list_add(&_vginfos, &vginfo->list);
d617b2
 		return 1;
d617b2
+	}
d617b2
 
d617b2
-	/* Remove existing vginfo entry */
d617b2
-	if (info)
d617b2
-		_drop_vginfo(info, info->vginfo);
d617b2
+	_drop_vginfo(info, info->vginfo);
d617b2
 
d617b2
-	if (!(vginfo = lvmcache_vginfo_from_vgname(vgname, vgid))) {
d617b2
+	if (!(vginfo = lvmcache_vginfo_from_vgid(vgid))) {
d617b2
 		/*
d617b2
 	 	 * Create a vginfo struct for this VG and put the vginfo
d617b2
 	 	 * into the hash table.
d617b2
 	 	 */
d617b2
 
d617b2
+		log_debug_cache("lvmcache adding vginfo for %s %s", vgname, vgid_str);
d617b2
+
d617b2
 		if (!(vginfo = zalloc(sizeof(*vginfo)))) {
d617b2
-			log_error("lvmcache_update_vgname: list alloc failed");
d617b2
+			log_error("lvmcache adding vg list alloc failed %s", vgname);
d617b2
 			return 0;
d617b2
 		}
d617b2
 		if (!(vginfo->vgname = strdup(vgname))) {
d617b2
 			free(vginfo);
d617b2
-			log_error("cache vgname alloc failed for %s", vgname);
d617b2
+			log_error("lvmcache adding vg name alloc failed %s", vgname);
d617b2
 			return 0;
d617b2
 		}
d617b2
 		dm_list_init(&vginfo->infos);
d617b2
 		dm_list_init(&vginfo->outdated_infos);
d617b2
 		dm_list_init(&vginfo->pvsummaries);
d617b2
 
d617b2
-		/*
d617b2
-		 * A different VG (different uuid) can exist with the same name.
d617b2
-		 * In this case, the two VGs will have separate vginfo structs,
d617b2
-		 * but the second will be linked onto the existing vginfo->next,
d617b2
-		 * not in the hash.
d617b2
-		 */
d617b2
-		primary_vginfo = lvmcache_vginfo_from_vgname(vgname, NULL);
d617b2
+		if ((other = dm_hash_lookup(_vgname_hash, vgname))) {
d617b2
+			log_debug_cache("lvmcache adding vginfo found duplicate VG name %s", vgname);
d617b2
 
d617b2
-		if (!_insert_vginfo(vginfo, vgid, vgstatus, creation_host, primary_vginfo)) {
d617b2
-			free(vginfo->vgname);
d617b2
-			free(vginfo);
d617b2
-			return 0;
d617b2
+			/*
d617b2
+			 * A different VG (different uuid) can exist with the
d617b2
+			 * same name.  In this case, the two VGs will have
d617b2
+			 * separate vginfo structs, but one will be in the
d617b2
+			 * vgname_hash.  If both vginfos are local/accessible,
d617b2
+			 * then _found_duplicate_vgnames is set which will
d617b2
+			 * disable any further use of the vgname_hash.
d617b2
+			 */
d617b2
+
d617b2
+			if (!memcmp(other->vgid, vgid, ID_LEN)) {
d617b2
+				/* shouldn't happen since we looked up by vgid above */
d617b2
+				log_error(INTERNAL_ERROR "lvmcache_update_vgname %s %s %s %s",
d617b2
+					  vgname, vgid_str, other->vgname, other->vgid);
d617b2
+				free(vginfo->vgname);
d617b2
+				free(vginfo);
d617b2
+				return 0;
d617b2
+			}
d617b2
+
d617b2
+			vginfo_is_allowed = is_system_id_allowed(cmd, system_id);
d617b2
+			other_is_allowed = is_system_id_allowed(cmd, other->system_id);
d617b2
+
d617b2
+			if (vginfo_is_allowed && other_is_allowed) {
d617b2
+				if (!id_write_format((const struct id *)other->vgid, other_str, sizeof(other_str)))
d617b2
+					stack;
d617b2
+
d617b2
+				vginfo->has_duplicate_local_vgname = 1;
d617b2
+				other->has_duplicate_local_vgname = 1;
d617b2
+				_found_duplicate_vgnames = 1;
d617b2
+
d617b2
+				log_warn("WARNING: VG name %s is used by VGs %s and %s.",
d617b2
+					 vgname, vgid_str, other_str);
d617b2
+				log_warn("Fix duplicate VG names with vgrename uuid, a device filter, or system IDs.");
d617b2
+			}
d617b2
+
d617b2
+			if (!vginfo_is_allowed && !other_is_allowed) {
d617b2
+				vginfo->has_duplicate_foreign_vgname = 1;
d617b2
+				other->has_duplicate_foreign_vgname = 1;
d617b2
+			}
d617b2
+
d617b2
+			if (!other_is_allowed && vginfo_is_allowed) {
d617b2
+				/* the accessible vginfo must be in vgnames_hash */
d617b2
+				dm_hash_remove(_vgname_hash, vgname);
d617b2
+				if (!dm_hash_insert(_vgname_hash, vgname, vginfo)) {
d617b2
+					log_error("lvmcache adding vginfo to name hash failed %s", vgname);
d617b2
+					return 0;
d617b2
+				}
d617b2
+			}
d617b2
+		} else {
d617b2
+			if (!dm_hash_insert(_vgname_hash, vgname, vginfo)) {
d617b2
+				log_error("lvmcache adding vg to name hash failed %s", vgname);
d617b2
+				free(vginfo->vgname);
d617b2
+				free(vginfo);
d617b2
+				return 0;
d617b2
+			}
d617b2
 		}
d617b2
 
d617b2
-		/* Ensure orphans appear last on list_iterate */
d617b2
-		if (is_orphan_vg(vgname))
d617b2
-			dm_list_add(&_vginfos, &vginfo->list);
d617b2
-		else
d617b2
-			dm_list_add_h(&_vginfos, &vginfo->list);
d617b2
+		dm_list_add_h(&_vginfos, &vginfo->list);
d617b2
 	}
d617b2
 
d617b2
-	if (info)
d617b2
-		_vginfo_attach_info(vginfo, info);
d617b2
-	else if (!_lvmcache_update_vgid(NULL, vginfo, vgid)) /* Orphans */
d617b2
-		return_0;
d617b2
-
d617b2
-	/* FIXME Check consistency of list! */
d617b2
 	vginfo->fmt = fmt;
d617b2
+	info->vginfo = vginfo;
d617b2
+	dm_list_add(&vginfo->infos, &info->list);
d617b2
 
d617b2
-	if (info) {
d617b2
-		if (info->mdas.n)
d617b2
-			sprintf(mdabuf, " with %u mda(s)", dm_list_size(&info->mdas));
d617b2
-		else
d617b2
-			mdabuf[0] = '\0';
d617b2
-		log_debug_cache("lvmcache %s: now in VG %s%s%s%s%s.",
d617b2
-				dev_name(info->dev),
d617b2
-				vgname, vginfo->vgid[0] ? " (" : "",
d617b2
-				vginfo->vgid[0] ? vginfo->vgid : "",
d617b2
-				vginfo->vgid[0] ? ")" : "", mdabuf);
d617b2
-	} else
d617b2
-		log_debug_cache("lvmcache: Initialised VG %s.", vgname);
d617b2
+	log_debug_cache("lvmcache %s: now in VG %s %s", dev_name(info->dev), vgname, vgid_str);
d617b2
 
d617b2
 	return 1;
d617b2
 }
d617b2
@@ -1511,9 +1492,9 @@ out:
d617b2
 	return 1;
d617b2
 }
d617b2
 
d617b2
-int lvmcache_add_orphan_vginfo(const char *vgname, struct format_type *fmt)
d617b2
+int lvmcache_add_orphan_vginfo(struct cmd_context *cmd, const char *vgname, struct format_type *fmt)
d617b2
 {
d617b2
-	return _lvmcache_update_vgname(NULL, vgname, vgname, 0, "", fmt);
d617b2
+	return _lvmcache_update_vgname(cmd, NULL, vgname, vgname, "", fmt);
d617b2
 }
d617b2
 
d617b2
 static void _lvmcache_update_pvsummaries(struct lvmcache_vginfo *vginfo, struct lvmcache_vgsummary *vgsummary)
d617b2
@@ -1532,7 +1513,7 @@ static void _lvmcache_update_pvsummaries(struct lvmcache_vginfo *vginfo, struct
d617b2
  * Returning 0 causes the caller to remove the info struct for this
d617b2
  * device from lvmcache, which will make it look like a missing device.
d617b2
  */
d617b2
-int lvmcache_update_vgname_and_id(struct lvmcache_info *info, struct lvmcache_vgsummary *vgsummary)
d617b2
+int lvmcache_update_vgname_and_id(struct cmd_context *cmd, struct lvmcache_info *info, struct lvmcache_vgsummary *vgsummary)
d617b2
 {
d617b2
 	const char *vgname = vgsummary->vgname;
d617b2
 	const char *vgid = (char *)&vgsummary->vgid;
d617b2
@@ -1545,6 +1526,7 @@ int lvmcache_update_vgname_and_id(struct lvmcache_info *info, struct lvmcache_vg
d617b2
 		vgid = vgname;
d617b2
 	}
d617b2
 
d617b2
+	/* FIXME: remove this, it shouldn't be needed */
d617b2
 	/* If PV without mdas is already in a real VG, don't make it orphan */
d617b2
 	if (is_orphan_vg(vgname) && info->vginfo &&
d617b2
 	    mdas_empty_or_ignored(&info->mdas) &&
d617b2
@@ -1556,7 +1538,7 @@ int lvmcache_update_vgname_and_id(struct lvmcache_info *info, struct lvmcache_vg
d617b2
 	 * and attaches the info struct for the dev to the vginfo.
d617b2
 	 * Puts the vginfo into the vgname hash table.
d617b2
 	 */
d617b2
-	if (!_lvmcache_update_vgname(info, vgname, vgid, vgsummary->vgstatus, vgsummary->creation_host, info->fmt)) {
d617b2
+	if (!_lvmcache_update_vgname(cmd, info, vgname, vgid, vgsummary->system_id, info->fmt)) {
d617b2
 		/* shouldn't happen, internal error */
d617b2
 		log_error("Failed to update VG %s info in lvmcache.", vgname);
d617b2
 		return 0;
d617b2
@@ -1735,7 +1717,7 @@ int lvmcache_update_vg_from_write(struct volume_group *vg)
d617b2
 		(void) dm_strncpy(pvid_s, (char *) &pvl->pv->id, sizeof(pvid_s));
d617b2
 		/* FIXME Could pvl->pv->dev->pvid ever be different? */
d617b2
 		if ((info = lvmcache_info_from_pvid(pvid_s, pvl->pv->dev, 0)) &&
d617b2
-		    !lvmcache_update_vgname_and_id(info, &vgsummary))
d617b2
+		    !lvmcache_update_vgname_and_id(vg->cmd, info, &vgsummary))
d617b2
 			return_0;
d617b2
 	}
d617b2
 
d617b2
@@ -1819,7 +1801,7 @@ int lvmcache_update_vg_from_read(struct volume_group *vg, unsigned precommitted)
d617b2
 		 * info's for PVs without metadata were not connected to the
d617b2
 		 * vginfo by label_scan, so do it here.
d617b2
 		 */
d617b2
-		if (!lvmcache_update_vgname_and_id(info, &vgsummary)) {
d617b2
+		if (!lvmcache_update_vgname_and_id(vg->cmd, info, &vgsummary)) {
d617b2
 			log_debug_cache("lvmcache_update_vg %s failed to update info for %s",
d617b2
 					vg->name, dev_name(info->dev));
d617b2
 		}
d617b2
@@ -1927,7 +1909,7 @@ static struct lvmcache_info * _create_info(struct labeller *labeller, struct dev
d617b2
 	return info;
d617b2
 }
d617b2
 
d617b2
-struct lvmcache_info *lvmcache_add(struct labeller *labeller,
d617b2
+struct lvmcache_info *lvmcache_add(struct cmd_context *cmd, struct labeller *labeller,
d617b2
 				   const char *pvid, struct device *dev, uint64_t label_sector,
d617b2
 				   const char *vgname, const char *vgid, uint32_t vgstatus,
d617b2
 				   int *is_duplicate)
d617b2
@@ -2042,7 +2024,7 @@ update_vginfo:
d617b2
 	if (vgid)
d617b2
 		strncpy((char *)&vgsummary.vgid, vgid, sizeof(vgsummary.vgid));
d617b2
 
d617b2
-	if (!lvmcache_update_vgname_and_id(info, &vgsummary)) {
d617b2
+	if (!lvmcache_update_vgname_and_id(cmd, info, &vgsummary)) {
d617b2
 		if (created) {
d617b2
 			dm_hash_remove(_pvid_hash, pvid_s);
d617b2
 			strcpy(info->dev->pvid, "");
d617b2
@@ -2055,7 +2037,7 @@ update_vginfo:
d617b2
 	return info;
d617b2
 }
d617b2
 
d617b2
-static void _lvmcache_destroy_entry(struct lvmcache_info *info)
d617b2
+static void _lvmcache_destroy_info(struct lvmcache_info *info)
d617b2
 {
d617b2
 	_vginfo_detach_info(info);
d617b2
 	info->dev->pvid[0] = 0;
d617b2
@@ -2063,20 +2045,11 @@ static void _lvmcache_destroy_entry(struct lvmcache_info *info)
d617b2
 	free(info);
d617b2
 }
d617b2
 
d617b2
-static void _lvmcache_destroy_vgnamelist(struct lvmcache_vginfo *vginfo)
d617b2
-{
d617b2
-	struct lvmcache_vginfo *next;
d617b2
-
d617b2
-	do {
d617b2
-		next = vginfo->next;
d617b2
-		if (!_free_vginfo(vginfo))
d617b2
-			stack;
d617b2
-	} while ((vginfo = next));
d617b2
-}
d617b2
-
d617b2
 void lvmcache_destroy(struct cmd_context *cmd, int retain_orphans, int reset)
d617b2
 {
d617b2
-	log_debug_cache("Dropping VG info");
d617b2
+	struct lvmcache_vginfo *vginfo, *vginfo2;
d617b2
+
d617b2
+	log_debug_cache("Destroy lvmcache content");
d617b2
 
d617b2
 	if (_vgid_hash) {
d617b2
 		dm_hash_destroy(_vgid_hash);
d617b2
@@ -2084,20 +2057,24 @@ void lvmcache_destroy(struct cmd_context *cmd, int retain_orphans, int reset)
d617b2
 	}
d617b2
 
d617b2
 	if (_pvid_hash) {
d617b2
-		dm_hash_iter(_pvid_hash, (dm_hash_iterate_fn) _lvmcache_destroy_entry);
d617b2
+		dm_hash_iter(_pvid_hash, (dm_hash_iterate_fn) _lvmcache_destroy_info);
d617b2
 		dm_hash_destroy(_pvid_hash);
d617b2
 		_pvid_hash = NULL;
d617b2
 	}
d617b2
 
d617b2
 	if (_vgname_hash) {
d617b2
-		dm_hash_iter(_vgname_hash,
d617b2
-			  (dm_hash_iterate_fn) _lvmcache_destroy_vgnamelist);
d617b2
 		dm_hash_destroy(_vgname_hash);
d617b2
 		_vgname_hash = NULL;
d617b2
 	}
d617b2
 
d617b2
+	dm_list_iterate_items_safe(vginfo, vginfo2, &_vginfos) {
d617b2
+		dm_list_del(&vginfo->list);
d617b2
+		_free_vginfo(vginfo);
d617b2
+	}
d617b2
+
d617b2
 	if (!dm_list_empty(&_vginfos))
d617b2
-		log_error(INTERNAL_ERROR "_vginfos list should be empty");
d617b2
+		log_error(INTERNAL_ERROR "vginfos list should be empty");
d617b2
+
d617b2
 	dm_list_init(&_vginfos);
d617b2
 
d617b2
 	/*
d617b2
@@ -2109,6 +2086,8 @@ void lvmcache_destroy(struct cmd_context *cmd, int retain_orphans, int reset)
d617b2
 	 * We want the same preferred devices to be chosen each time, so save
d617b2
 	 * the unpreferred devs here so that _choose_preferred_devs can use
d617b2
 	 * this to make the same choice each time.
d617b2
+	 *
d617b2
+	 * FIXME: I don't think is is needed any more.
d617b2
 	 */
d617b2
 	_destroy_device_list(&_prev_unused_duplicate_devs);
d617b2
 	dm_list_splice(&_prev_unused_duplicate_devs, &_unused_duplicates);
d617b2
@@ -2122,7 +2101,7 @@ void lvmcache_destroy(struct cmd_context *cmd, int retain_orphans, int reset)
d617b2
 			stack;
d617b2
 
d617b2
 		dm_list_iterate_items(fmt, &cmd->formats) {
d617b2
-			if (!lvmcache_add_orphan_vginfo(fmt->orphan_vg_name, fmt))
d617b2
+			if (!lvmcache_add_orphan_vginfo(cmd, fmt->orphan_vg_name, fmt))
d617b2
 				stack;
d617b2
 		}
d617b2
 	}
d617b2
@@ -2567,36 +2546,6 @@ int lvmcache_vginfo_has_pvid(struct lvmcache_vginfo *vginfo, char *pvid)
d617b2
 	return 0;
d617b2
 }
d617b2
 
d617b2
-struct metadata_area *lvmcache_get_mda(struct cmd_context *cmd,
d617b2
-				       const char *vgname,
d617b2
-				       struct device *dev,
d617b2
-				       int use_mda_num)
d617b2
-{
d617b2
-	struct lvmcache_vginfo *vginfo;
d617b2
-	struct lvmcache_info *info;
d617b2
-	struct metadata_area *mda;
d617b2
-
d617b2
-	if (!use_mda_num)
d617b2
-		use_mda_num = 1;
d617b2
-
d617b2
-	if (!(vginfo = lvmcache_vginfo_from_vgname(vgname, NULL)))
d617b2
-		return NULL;
d617b2
-
d617b2
-	dm_list_iterate_items(info, &vginfo->infos) {
d617b2
-		if (info->dev != dev)
d617b2
-			continue;
d617b2
-
d617b2
-		dm_list_iterate_items(mda, &info->mdas) {
d617b2
-			if ((use_mda_num == 1) && (mda->status & MDA_PRIMARY))
d617b2
-				return mda;
d617b2
-			if ((use_mda_num == 2) && !(mda->status & MDA_PRIMARY))
d617b2
-				return mda;
d617b2
-		}
d617b2
-		return NULL;
d617b2
-	}
d617b2
-	return NULL;
d617b2
-}
d617b2
-
d617b2
 /*
d617b2
  * This is used by the metadata repair command to check if
d617b2
  * the metadata on a dev needs repair because it's old.
d617b2
diff --git a/lib/cache/lvmcache.h b/lib/cache/lvmcache.h
d617b2
index 0c8c789..6cef4d1 100644
d617b2
--- a/lib/cache/lvmcache.h
d617b2
+++ b/lib/cache/lvmcache.h
d617b2
@@ -71,16 +71,16 @@ int lvmcache_label_rescan_vg(struct cmd_context *cmd, const char *vgname, const
d617b2
 int lvmcache_label_rescan_vg_rw(struct cmd_context *cmd, const char *vgname, const char *vgid);
d617b2
 
d617b2
 /* Add/delete a device */
d617b2
-struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid,
d617b2
+struct lvmcache_info *lvmcache_add(struct cmd_context *cmd, struct labeller *labeller, const char *pvid,
d617b2
                                    struct device *dev, uint64_t label_sector,
d617b2
                                    const char *vgname, const char *vgid,
d617b2
                                    uint32_t vgstatus, int *is_duplicate);
d617b2
-int lvmcache_add_orphan_vginfo(const char *vgname, struct format_type *fmt);
d617b2
+int lvmcache_add_orphan_vginfo(struct cmd_context *cmd, const char *vgname, struct format_type *fmt);
d617b2
 void lvmcache_del(struct lvmcache_info *info);
d617b2
 void lvmcache_del_dev(struct device *dev);
d617b2
 
d617b2
 /* Update things */
d617b2
-int lvmcache_update_vgname_and_id(struct lvmcache_info *info,
d617b2
+int lvmcache_update_vgname_and_id(struct cmd_context *cmd, struct lvmcache_info *info,
d617b2
 				  struct lvmcache_vgsummary *vgsummary);
d617b2
 int lvmcache_update_vg_from_read(struct volume_group *vg, unsigned precommitted);
d617b2
 int lvmcache_update_vg_from_write(struct volume_group *vg);
d617b2
@@ -161,11 +161,6 @@ struct device *lvmcache_device(struct lvmcache_info *info);
d617b2
 unsigned lvmcache_mda_count(struct lvmcache_info *info);
d617b2
 uint64_t lvmcache_smallest_mda_size(struct lvmcache_info *info);
d617b2
 
d617b2
-struct metadata_area *lvmcache_get_mda(struct cmd_context *cmd,
d617b2
-                                      const char *vgname,
d617b2
-                                      struct device *dev,
d617b2
-                                      int use_mda_num);
d617b2
-
d617b2
 bool lvmcache_has_duplicate_devs(void);
d617b2
 void lvmcache_del_dev_from_duplicates(struct device *dev);
d617b2
 bool lvmcache_dev_is_unused_duplicate(struct device *dev);
d617b2
@@ -174,6 +169,7 @@ int lvmcache_get_unused_duplicates(struct cmd_context *cmd, struct dm_list *head
d617b2
 int vg_has_duplicate_pvs(struct volume_group *vg);
d617b2
 
d617b2
 int lvmcache_found_duplicate_vgnames(void);
d617b2
+bool lvmcache_has_duplicate_local_vgname(const char *vgid, const char *vgname);
d617b2
 
d617b2
 int lvmcache_contains_lock_type_sanlock(struct cmd_context *cmd);
d617b2
 
d617b2
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
d617b2
index 88d5b3e..63b6811 100644
d617b2
--- a/lib/commands/toolcontext.c
d617b2
+++ b/lib/commands/toolcontext.c
d617b2
@@ -1276,7 +1276,7 @@ int init_lvmcache_orphans(struct cmd_context *cmd)
d617b2
 	struct format_type *fmt;
d617b2
 
d617b2
 	dm_list_iterate_items(fmt, &cmd->formats)
d617b2
-		if (!lvmcache_add_orphan_vginfo(fmt->orphan_vg_name, fmt))
d617b2
+		if (!lvmcache_add_orphan_vginfo(cmd, fmt->orphan_vg_name, fmt))
d617b2
 			return_0;
d617b2
 
d617b2
 	return 1;
d617b2
@@ -1598,6 +1598,7 @@ struct cmd_context *create_toolcontext(unsigned is_clvmd,
d617b2
 	dm_list_init(&cmd->formats);
d617b2
 	dm_list_init(&cmd->segtypes);
d617b2
 	dm_list_init(&cmd->tags);
d617b2
+	dm_list_init(&cmd->hints);
d617b2
 	dm_list_init(&cmd->config_files);
d617b2
 	label_init();
d617b2
 
d617b2
diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c
d617b2
index 735441f..33b9345 100644
d617b2
--- a/lib/device/dev-io.c
d617b2
+++ b/lib/device/dev-io.c
d617b2
@@ -86,6 +86,9 @@ static int _dev_get_size_dev(struct device *dev, uint64_t *size)
d617b2
 	int fd = dev->bcache_fd;
d617b2
 	int do_close = 0;
d617b2
 
d617b2
+	if (dm_list_empty(&dev->aliases))
d617b2
+		return 0;
d617b2
+
d617b2
 	if (dev->size_seqno == _dev_size_seqno) {
d617b2
 		log_very_verbose("%s: using cached size %" PRIu64 " sectors",
d617b2
 				 name, dev->size);
d617b2
diff --git a/lib/format_text/archiver.c b/lib/format_text/archiver.c
d617b2
index 3a741da..733e62b 100644
d617b2
--- a/lib/format_text/archiver.c
d617b2
+++ b/lib/format_text/archiver.c
d617b2
@@ -315,7 +315,7 @@ struct volume_group *backup_read_vg(struct cmd_context *cmd,
d617b2
 	}
d617b2
 
d617b2
 	dm_list_iterate_items(mda, &tf->metadata_areas_in_use) {
d617b2
-		if (!(vg = mda->ops->vg_read(tf, vg_name, mda, NULL, NULL)))
d617b2
+		if (!(vg = mda->ops->vg_read(cmd, tf, vg_name, mda, NULL, NULL)))
d617b2
 			stack;
d617b2
 		break;
d617b2
 	}
d617b2
diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c
d617b2
index 268bd64..e448712 100644
d617b2
--- a/lib/format_text/format-text.c
d617b2
+++ b/lib/format_text/format-text.c
d617b2
@@ -290,7 +290,8 @@ static int _raw_write_mda_header(const struct format_type *fmt,
d617b2
  * in the label scanning path.
d617b2
  */
d617b2
 
d617b2
-static struct raw_locn *_read_metadata_location_vg(struct device_area *dev_area,
d617b2
+static struct raw_locn *_read_metadata_location_vg(struct cmd_context *cmd,
d617b2
+				       struct device_area *dev_area,
d617b2
 				       struct mda_header *mdah, int primary_mda,
d617b2
 				       const char *vgname,
d617b2
 				       int *precommitted)
d617b2
@@ -369,7 +370,7 @@ static struct raw_locn *_read_metadata_location_vg(struct device_area *dev_area,
d617b2
 		  vgnamebuf, vgname);
d617b2
 
d617b2
 	if ((info = lvmcache_info_from_pvid(dev_area->dev->pvid, dev_area->dev, 0)) &&
d617b2
-	    !lvmcache_update_vgname_and_id(info, &vgsummary_orphan))
d617b2
+	    !lvmcache_update_vgname_and_id(cmd, info, &vgsummary_orphan))
d617b2
 		stack;
d617b2
 
d617b2
 	return NULL;
d617b2
@@ -447,7 +448,8 @@ static uint64_t _next_rlocn_offset(struct volume_group *vg, struct raw_locn *rlo
d617b2
 	return new_start;
d617b2
 }
d617b2
 
d617b2
-static struct volume_group *_vg_read_raw_area(struct format_instance *fid,
d617b2
+static struct volume_group *_vg_read_raw_area(struct cmd_context *cmd,
d617b2
+					      struct format_instance *fid,
d617b2
 					      const char *vgname,
d617b2
 					      struct device_area *area,
d617b2
 					      struct cached_vg_fmtdata **vg_fmtdata,
d617b2
@@ -468,7 +470,7 @@ static struct volume_group *_vg_read_raw_area(struct format_instance *fid,
d617b2
 		goto out;
d617b2
 	}
d617b2
 
d617b2
-	if (!(rlocn = _read_metadata_location_vg(area, mdah, primary_mda, vgname, &precommitted))) {
d617b2
+	if (!(rlocn = _read_metadata_location_vg(cmd, area, mdah, primary_mda, vgname, &precommitted))) {
d617b2
 		log_debug_metadata("VG %s not found on %s", vgname, dev_name(area->dev));
d617b2
 		goto out;
d617b2
 	}
d617b2
@@ -503,7 +505,8 @@ static struct volume_group *_vg_read_raw_area(struct format_instance *fid,
d617b2
 	return vg;
d617b2
 }
d617b2
 
d617b2
-static struct volume_group *_vg_read_raw(struct format_instance *fid,
d617b2
+static struct volume_group *_vg_read_raw(struct cmd_context *cmd,
d617b2
+					 struct format_instance *fid,
d617b2
 					 const char *vgname,
d617b2
 					 struct metadata_area *mda,
d617b2
 					 struct cached_vg_fmtdata **vg_fmtdata,
d617b2
@@ -512,12 +515,13 @@ static struct volume_group *_vg_read_raw(struct format_instance *fid,
d617b2
 	struct mda_context *mdac = (struct mda_context *) mda->metadata_locn;
d617b2
 	struct volume_group *vg;
d617b2
 
d617b2
-	vg = _vg_read_raw_area(fid, vgname, &mdac->area, vg_fmtdata, use_previous_vg, 0, mda_is_primary(mda));
d617b2
+	vg = _vg_read_raw_area(cmd, fid, vgname, &mdac->area, vg_fmtdata, use_previous_vg, 0, mda_is_primary(mda));
d617b2
 
d617b2
 	return vg;
d617b2
 }
d617b2
 
d617b2
-static struct volume_group *_vg_read_precommit_raw(struct format_instance *fid,
d617b2
+static struct volume_group *_vg_read_precommit_raw(struct cmd_context *cmd,
d617b2
+						   struct format_instance *fid,
d617b2
 						   const char *vgname,
d617b2
 						   struct metadata_area *mda,
d617b2
 						   struct cached_vg_fmtdata **vg_fmtdata,
d617b2
@@ -526,7 +530,7 @@ static struct volume_group *_vg_read_precommit_raw(struct format_instance *fid,
d617b2
 	struct mda_context *mdac = (struct mda_context *) mda->metadata_locn;
d617b2
 	struct volume_group *vg;
d617b2
 
d617b2
-	vg = _vg_read_raw_area(fid, vgname, &mdac->area, vg_fmtdata, use_previous_vg, 1, mda_is_primary(mda));
d617b2
+	vg = _vg_read_raw_area(cmd, fid, vgname, &mdac->area, vg_fmtdata, use_previous_vg, 1, mda_is_primary(mda));
d617b2
 
d617b2
 	return vg;
d617b2
 }
d617b2
@@ -1321,7 +1325,7 @@ static struct volume_group *_vg_read_file_name(struct format_instance *fid,
d617b2
 	return vg;
d617b2
 }
d617b2
 
d617b2
-static struct volume_group *_vg_read_file(struct format_instance *fid,
d617b2
+static struct volume_group *_vg_read_file(struct cmd_context *cmd, struct format_instance *fid,
d617b2
 					  const char *vgname,
d617b2
 					  struct metadata_area *mda,
d617b2
 					  struct cached_vg_fmtdata **vg_fmtdata,
d617b2
@@ -1332,7 +1336,7 @@ static struct volume_group *_vg_read_file(struct format_instance *fid,
d617b2
 	return _vg_read_file_name(fid, vgname, tc->path_live);
d617b2
 }
d617b2
 
d617b2
-static struct volume_group *_vg_read_precommit_file(struct format_instance *fid,
d617b2
+static struct volume_group *_vg_read_precommit_file(struct cmd_context *cmd, struct format_instance *fid,
d617b2
 						    const char *vgname,
d617b2
 						    struct metadata_area *mda,
d617b2
 						    struct cached_vg_fmtdata **vg_fmtdata,
d617b2
@@ -1713,7 +1717,7 @@ static int _set_ext_flags(struct physical_volume *pv, struct lvmcache_info *info
d617b2
 }
d617b2
 
d617b2
 /* Only for orphans - FIXME That's not true any more */
d617b2
-static int _text_pv_write(const struct format_type *fmt, struct physical_volume *pv)
d617b2
+static int _text_pv_write(struct cmd_context *cmd, const struct format_type *fmt, struct physical_volume *pv)
d617b2
 {
d617b2
 	struct format_instance *fid = pv->fid;
d617b2
 	const char *pvid = (const char *) (*pv->old_id.uuid ? &pv->old_id : &pv->id);
d617b2
@@ -1725,7 +1729,7 @@ static int _text_pv_write(const struct format_type *fmt, struct physical_volume
d617b2
 	unsigned mda_index;
d617b2
 
d617b2
 	/* Add a new cache entry with PV info or update existing one. */
d617b2
-	if (!(info = lvmcache_add(fmt->labeller, (const char *) &pv->id,
d617b2
+	if (!(info = lvmcache_add(cmd, fmt->labeller, (const char *) &pv->id,
d617b2
 				  pv->dev,  pv->label_sector, pv->vg_name,
d617b2
 				  is_orphan_vg(pv->vg_name) ? pv->vg_name : pv->vg ? (const char *) &pv->vg->id : NULL, 0, NULL)))
d617b2
 		return_0;
d617b2
diff --git a/lib/format_text/text_label.c b/lib/format_text/text_label.c
d617b2
index 9241eca..1674126 100644
d617b2
--- a/lib/format_text/text_label.c
d617b2
+++ b/lib/format_text/text_label.c
d617b2
@@ -370,7 +370,7 @@ static int _read_mda_header_and_metadata(const struct format_type *fmt,
d617b2
  * the metadata is at for those PVs.
d617b2
  */
d617b2
 
d617b2
-static int _text_read(struct labeller *labeller, struct device *dev, void *label_buf,
d617b2
+static int _text_read(struct cmd_context *cmd, struct labeller *labeller, struct device *dev, void *label_buf,
d617b2
 		      uint64_t label_sector, int *is_duplicate)
d617b2
 {
d617b2
 	struct lvmcache_vgsummary vgsummary;
d617b2
@@ -410,7 +410,7 @@ static int _text_read(struct labeller *labeller, struct device *dev, void *label
d617b2
 	 *
d617b2
 	 * Other reasons for lvmcache_add to return NULL are internal errors.
d617b2
 	 */
d617b2
-	if (!(info = lvmcache_add(labeller, (char *)pvhdr->pv_uuid, dev, label_sector,
d617b2
+	if (!(info = lvmcache_add(cmd, labeller, (char *)pvhdr->pv_uuid, dev, label_sector,
d617b2
 				  FMT_TEXT_ORPHAN_VG_NAME,
d617b2
 				  FMT_TEXT_ORPHAN_VG_NAME, 0, is_duplicate)))
d617b2
 		return_0;
d617b2
@@ -503,7 +503,7 @@ static int _text_read(struct labeller *labeller, struct device *dev, void *label
d617b2
 		rv1 = _read_mda_header_and_metadata(fmt, mda1, &vgsummary, &bad_fields);
d617b2
 
d617b2
 		if (rv1 && !vgsummary.zero_offset && !vgsummary.mda_ignored) {
d617b2
-			if (!lvmcache_update_vgname_and_id(info, &vgsummary)) {
d617b2
+			if (!lvmcache_update_vgname_and_id(cmd, info, &vgsummary)) {
d617b2
 				/* I believe this is only an internal error. */
d617b2
 
d617b2
 				dm_list_del(&mda1->list);
d617b2
@@ -554,7 +554,7 @@ static int _text_read(struct labeller *labeller, struct device *dev, void *label
d617b2
 		rv2 = _read_mda_header_and_metadata(fmt, mda2, &vgsummary, &bad_fields);
d617b2
 
d617b2
 		if (rv2 && !vgsummary.zero_offset && !vgsummary.mda_ignored) {
d617b2
-			if (!lvmcache_update_vgname_and_id(info, &vgsummary)) {
d617b2
+			if (!lvmcache_update_vgname_and_id(cmd, info, &vgsummary)) {
d617b2
 				dm_list_del(&mda2->list);
d617b2
 
d617b2
 				/* Are there other cases besides mismatch and internal error? */
d617b2
diff --git a/lib/label/hints.c b/lib/label/hints.c
d617b2
index 48fb661..9546f48 100644
d617b2
--- a/lib/label/hints.c
d617b2
+++ b/lib/label/hints.c
d617b2
@@ -351,6 +351,7 @@ static void _unlock_hints(struct cmd_context *cmd)
d617b2
 
d617b2
 void hints_exit(struct cmd_context *cmd)
d617b2
 {
d617b2
+	free_hints(&cmd->hints);
d617b2
 	if (_hints_fd == -1)
d617b2
 		return;
d617b2
 	return _unlock_hints(cmd);
d617b2
@@ -419,6 +420,9 @@ static int _dev_in_hint_hash(struct cmd_context *cmd, struct device *dev)
d617b2
 {
d617b2
 	uint64_t devsize = 0;
d617b2
 
d617b2
+	if (dm_list_empty(&dev->aliases))
d617b2
+		return 0;
d617b2
+
d617b2
 	if (!cmd->filter->passes_filter(cmd, cmd->filter, dev, "regex"))
d617b2
 		return 0;
d617b2
 
d617b2
@@ -1318,6 +1322,7 @@ int get_hints(struct cmd_context *cmd, struct dm_list *hints_out, int *newhints,
d617b2
 	 */
d617b2
 	if (!_read_hint_file(cmd, &hints_list, &needs_refresh)) {
d617b2
 		log_debug("get_hints: read fail");
d617b2
+		free_hints(&hints_list);
d617b2
 		_unlock_hints(cmd);
d617b2
 		return 0;
d617b2
 	}
d617b2
@@ -1330,6 +1335,7 @@ int get_hints(struct cmd_context *cmd, struct dm_list *hints_out, int *newhints,
d617b2
 	 */
d617b2
 	if (needs_refresh) {
d617b2
 		log_debug("get_hints: needs refresh");
d617b2
+		free_hints(&hints_list);
d617b2
 
d617b2
 		if (!_lock_hints(cmd, LOCK_EX, NONBLOCK))
d617b2
 			return 0;
d617b2
diff --git a/lib/label/label.c b/lib/label/label.c
d617b2
index 0458313..4d37cef 100644
d617b2
--- a/lib/label/label.c
d617b2
+++ b/lib/label/label.c
d617b2
@@ -431,7 +431,7 @@ static int _process_block(struct cmd_context *cmd, struct dev_filter *f,
d617b2
 	 * info/vginfo structs.  That lvmcache info is used later when the
d617b2
 	 * command wants to read the VG to do something to it.
d617b2
 	 */
d617b2
-	ret = labeller->ops->read(labeller, dev, label_buf, sector, &is_duplicate);
d617b2
+	ret = labeller->ops->read(cmd, labeller, dev, label_buf, sector, &is_duplicate);
d617b2
 
d617b2
 	if (!ret) {
d617b2
 		if (is_duplicate) {
d617b2
diff --git a/lib/label/label.h b/lib/label/label.h
d617b2
index 4108906..9a4b630 100644
d617b2
--- a/lib/label/label.h
d617b2
+++ b/lib/label/label.h
d617b2
@@ -64,7 +64,7 @@ struct label_ops {
d617b2
 	/*
d617b2
 	 * Read a label from a volume.
d617b2
 	 */
d617b2
-	int (*read) (struct labeller * l, struct device * dev,
d617b2
+	int (*read) (struct cmd_context *cmd, struct labeller * l, struct device * dev,
d617b2
 		     void *label_buf, uint64_t label_sector, int *is_duplicate);
d617b2
 
d617b2
 	/*
d617b2
diff --git a/lib/locking/lvmlockd.c b/lib/locking/lvmlockd.c
d617b2
index e378fe6..dca7954 100644
d617b2
--- a/lib/locking/lvmlockd.c
d617b2
+++ b/lib/locking/lvmlockd.c
d617b2
@@ -635,7 +635,6 @@ static int _init_vg_sanlock(struct cmd_context *cmd, struct volume_group *vg, in
d617b2
 	const char *vg_lock_args = NULL;
d617b2
 	const char *opts = NULL;
d617b2
 	struct pv_list *pvl;
d617b2
-	struct device *sector_dev;
d617b2
 	uint32_t sector_size = 0;
d617b2
 	unsigned int physical_block_size, logical_block_size;
d617b2
 	int num_mb = 0;
d617b2
@@ -656,16 +655,11 @@ static int _init_vg_sanlock(struct cmd_context *cmd, struct volume_group *vg, in
d617b2
 	dm_list_iterate_items(pvl, &vg->pvs) {
d617b2
 		if (!dev_get_direct_block_sizes(pvl->pv->dev, &physical_block_size, &logical_block_size))
d617b2
 			continue;
d617b2
-
d617b2
-		if (!sector_size) {
d617b2
-			sector_size = logical_block_size;
d617b2
-			sector_dev = pvl->pv->dev;
d617b2
-		} else if (sector_size != logical_block_size) {
d617b2
-			log_error("Inconsistent logical block sizes for %s and %s.",
d617b2
-				  dev_name(pvl->pv->dev), dev_name(sector_dev));
d617b2
-			return 0;
d617b2
-		}
d617b2
+		if ((physical_block_size == 4096) || (logical_block_size == 4096))
d617b2
+			sector_size = 4096;
d617b2
 	}
d617b2
+	if (!sector_size)
d617b2
+		sector_size = 512;
d617b2
 
d617b2
 	log_debug("Using sector size %u for sanlock LV", sector_size);
d617b2
 
d617b2
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
d617b2
index 52bc776..083f74a 100644
d617b2
--- a/lib/metadata/metadata-exported.h
d617b2
+++ b/lib/metadata/metadata-exported.h
d617b2
@@ -744,9 +744,6 @@ struct volume_group *vg_read_for_update(struct cmd_context *cmd, const char *vg_
d617b2
 			 const char *vgid, uint32_t read_flags, uint32_t lockd_state);
d617b2
 struct volume_group *vg_read_orphans(struct cmd_context *cmd, const char *orphan_vgname);
d617b2
 
d617b2
-/* this is historical and being removed, don't use */
d617b2
-uint32_t vg_read_error(struct volume_group *vg_handle);
d617b2
-
d617b2
 /* pe_start and pe_end relate to any existing data so that new metadata
d617b2
 * areas can avoid overlap */
d617b2
 struct physical_volume *pv_create(const struct cmd_context *cmd,
d617b2
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
d617b2
index 9c44388..4b8dce9 100644
d617b2
--- a/lib/metadata/metadata.c
d617b2
+++ b/lib/metadata/metadata.c
d617b2
@@ -3666,7 +3666,7 @@ int pv_write(struct cmd_context *cmd,
d617b2
 		return 0;
d617b2
 	}
d617b2
 
d617b2
-	if (!pv->fmt->ops->pv_write(pv->fmt, pv))
d617b2
+	if (!pv->fmt->ops->pv_write(cmd, pv->fmt, pv))
d617b2
 		return_0;
d617b2
 
d617b2
 	pv->status &= ~UNLABELLED_PV;
d617b2
@@ -4010,17 +4010,6 @@ static int _access_vg_exported(struct cmd_context *cmd, struct volume_group *vg)
d617b2
 	return 0;
d617b2
 }
d617b2
 
d617b2
-/*
d617b2
- * Test the validity of a VG handle returned by vg_read() or vg_read_for_update().
d617b2
- */
d617b2
-uint32_t vg_read_error(struct volume_group *vg_handle)
d617b2
-{
d617b2
-	if (!vg_handle)
d617b2
-		return FAILED_ALLOCATION;
d617b2
-
d617b2
-	return SUCCESS;
d617b2
-}
d617b2
-
d617b2
 struct format_instance *alloc_fid(const struct format_type *fmt,
d617b2
 				  const struct format_instance_ctx *fic)
d617b2
 {
d617b2
@@ -4751,18 +4740,6 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
d617b2
 			lvmcache_label_rescan_vg(cmd, vgname, vgid);
d617b2
 	}
d617b2
 
d617b2
-	/* Now determine the correct vgname if none was supplied */
d617b2
-	if (!vgname && !(vgname = lvmcache_vgname_from_vgid(cmd->mem, vgid))) {
d617b2
-		log_debug_metadata("Cache did not find VG name from vgid %s", vgid);
d617b2
-		return NULL;
d617b2
-	}
d617b2
-
d617b2
-	/* Determine the correct vgid if none was supplied */
d617b2
-	if (!vgid && !(vgid = lvmcache_vgid_from_vgname(cmd, vgname))) {
d617b2
-		log_debug_metadata("Cache did not find VG vgid from name %s", vgname);
d617b2
-		return NULL;
d617b2
-	}
d617b2
-
d617b2
 	/*
d617b2
 	 * A "format instance" is an abstraction for a VG location,
d617b2
 	 * i.e. where a VG's metadata exists on disk.
d617b2
@@ -4841,7 +4818,7 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
d617b2
 			log_debug_metadata("Reading VG %s precommit metadata from %s %llu",
d617b2
 				 vgname, dev_name(mda_dev), (unsigned long long)mda->header_start);
d617b2
 
d617b2
-			vg = mda->ops->vg_read_precommit(fid, vgname, mda, &vg_fmtdata, &use_previous_vg);
d617b2
+			vg = mda->ops->vg_read_precommit(cmd, fid, vgname, mda, &vg_fmtdata, &use_previous_vg);
d617b2
 
d617b2
 			if (!vg && !use_previous_vg) {
d617b2
 				log_warn("WARNING: Reading VG %s precommit on %s failed.", vgname, dev_name(mda_dev));
d617b2
@@ -4852,7 +4829,7 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
d617b2
 			log_debug_metadata("Reading VG %s metadata from %s %llu",
d617b2
 				 vgname, dev_name(mda_dev), (unsigned long long)mda->header_start);
d617b2
 
d617b2
-			vg = mda->ops->vg_read(fid, vgname, mda, &vg_fmtdata, &use_previous_vg);
d617b2
+			vg = mda->ops->vg_read(cmd, fid, vgname, mda, &vg_fmtdata, &use_previous_vg);
d617b2
 
d617b2
 			if (!vg && !use_previous_vg) {
d617b2
 				log_warn("WARNING: Reading VG %s on %s failed.", vgname, dev_name(mda_dev));
d617b2
@@ -4999,6 +4976,7 @@ struct volume_group *vg_read(struct cmd_context *cmd, const char *vg_name, const
d617b2
 	int missing_pv_dev = 0;
d617b2
 	int missing_pv_flag = 0;
d617b2
 	uint32_t failure = 0;
d617b2
+	int original_vgid_set = vgid ? 1 : 0;
d617b2
 	int writing = (vg_read_flags & READ_FOR_UPDATE);
d617b2
 	int activating = (vg_read_flags & READ_FOR_ACTIVATE);
d617b2
 
d617b2
@@ -5033,7 +5011,45 @@ struct volume_group *vg_read(struct cmd_context *cmd, const char *vg_name, const
d617b2
 		goto bad;
d617b2
 	}
d617b2
 
d617b2
+	/* I belive this is unused, the name is always set. */
d617b2
+	if (!vg_name && !(vg_name = lvmcache_vgname_from_vgid(cmd->mem, vgid))) {
d617b2
+		unlock_vg(cmd, NULL, vg_name);
d617b2
+		log_error("VG name not found for vgid %s", vgid);
d617b2
+		failure |= FAILED_NOTFOUND;
d617b2
+		goto_bad;
d617b2
+	}
d617b2
+
d617b2
+	/*
d617b2
+	 * If the command is process all vgs, process_each will get a list of vgname+vgid
d617b2
+	 * pairs, and then call vg_read() for each vgname+vigd.  In this case we know
d617b2
+	 * which VG to read even if there are duplicate names, and we don't fail.
d617b2
+	 *
d617b2
+	 * If the user has requested one VG by name, process_each passes only the vgname
d617b2
+	 * to vg_read(), and we look up the vgid from lvmcache.  lvmcache finds duplicate
d617b2
+	 * vgnames, doesn't know which is intended, returns a NULL vgid, and we fail.
d617b2
+	 */
d617b2
+
d617b2
+	if (!vgid)
d617b2
+		vgid = lvmcache_vgid_from_vgname(cmd, vg_name);
d617b2
+
d617b2
+	if (!vgid) {
d617b2
+		unlock_vg(cmd, NULL, vg_name);
d617b2
+		/* Some callers don't care if the VG doesn't exist and don't want an error message. */
d617b2
+		if (!(vg_read_flags & READ_OK_NOTFOUND))
d617b2
+			log_error("Volume group \"%s\" not found", vg_name);
d617b2
+		failure |= FAILED_NOTFOUND;
d617b2
+		goto_bad;
d617b2
+	}
d617b2
+
d617b2
+	/*
d617b2
+	 * vgchange -ay (no vgname arg) will activate multiple local VGs with the same
d617b2
+	 * name, but if the vgs have the same lv name, activating those lvs will fail.
d617b2
+	 */
d617b2
+	if (activating && original_vgid_set && lvmcache_has_duplicate_local_vgname(vgid, vg_name))
d617b2
+		log_warn("WARNING: activating multiple VGs with the same name is dangerous and may fail.");
d617b2
+
d617b2
 	if (!(vg = _vg_read(cmd, vg_name, vgid, 0, writing))) {
d617b2
+		unlock_vg(cmd, NULL, vg_name);
d617b2
 		/* Some callers don't care if the VG doesn't exist and don't want an error message. */
d617b2
 		if (!(vg_read_flags & READ_OK_NOTFOUND))
d617b2
 			log_error("Volume group \"%s\" not found.", vg_name);
d617b2
diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h
d617b2
index f199fc4..2c22450 100644
d617b2
--- a/lib/metadata/metadata.h
d617b2
+++ b/lib/metadata/metadata.h
d617b2
@@ -76,12 +76,14 @@ struct cached_vg_fmtdata;
d617b2
 /* Per-format per-metadata area operations */
d617b2
 struct metadata_area_ops {
d617b2
 	struct dm_list list;
d617b2
-	struct volume_group *(*vg_read) (struct format_instance * fi,
d617b2
+	struct volume_group *(*vg_read) (struct cmd_context *cmd,
d617b2
+					 struct format_instance * fi,
d617b2
 					 const char *vg_name,
d617b2
 					 struct metadata_area * mda,
d617b2
 					 struct cached_vg_fmtdata **vg_fmtdata,
d617b2
 					 unsigned *use_previous_vg);
d617b2
-	struct volume_group *(*vg_read_precommit) (struct format_instance * fi,
d617b2
+	struct volume_group *(*vg_read_precommit) (struct cmd_context *cmd,
d617b2
+					 struct format_instance * fi,
d617b2
 					 const char *vg_name,
d617b2
 					 struct metadata_area * mda,
d617b2
 					 struct cached_vg_fmtdata **vg_fmtdata,
d617b2
@@ -326,7 +328,7 @@ struct format_handler {
d617b2
 	 * Write a PV structure to disk. Fails if the PV is in a VG ie
d617b2
 	 * pv->vg_name must be a valid orphan VG name
d617b2
 	 */
d617b2
-	int (*pv_write) (const struct format_type * fmt,
d617b2
+	int (*pv_write) (struct cmd_context *cmd, const struct format_type * fmt,
d617b2
 			 struct physical_volume * pv);
d617b2
 
d617b2
 	/*
d617b2
diff --git a/man/lvmlockd.8_main b/man/lvmlockd.8_main
d617b2
index 8ed5400..c21f7a9 100644
d617b2
--- a/man/lvmlockd.8_main
d617b2
+++ b/man/lvmlockd.8_main
d617b2
@@ -58,6 +58,10 @@ For default settings, see lvmlockd -h.
d617b2
 .I path
d617b2
         Set path to the socket to listen on.
d617b2
 
d617b2
+.B  --adopt-file
d617b2
+.I path
d617b2
+        Set path to the adopt file.
d617b2
+
d617b2
 .B  --syslog-priority | -S err|warning|debug
d617b2
         Write log messages from this level up to syslog.
d617b2
 
d617b2
@@ -76,6 +80,8 @@ For default settings, see lvmlockd -h.
d617b2
 .I seconds
d617b2
         Override the default sanlock I/O timeout.
d617b2
 
d617b2
+.B --adopt | -A 0|1
d617b2
+        Enable (1) or disable (0) lock adoption.
d617b2
 
d617b2
 .SH USAGE
d617b2
 
d617b2
@@ -548,7 +554,13 @@ necessary locks.
d617b2
 .B lvmlockd failure
d617b2
 
d617b2
 If lvmlockd fails or is killed while holding locks, the locks are orphaned
d617b2
-in the lock manager.
d617b2
+in the lock manager.  Orphaned locks must be cleared or adopted before the
d617b2
+associated resources can be accessed normally.  If lock adoption is
d617b2
+enabled, lvmlockd keeps a record of locks in the adopt-file.  A subsequent
d617b2
+instance of lvmlockd will then adopt locks orphaned by the previous
d617b2
+instance.  Adoption must be enabled in both instances (--adopt|-A 1).
d617b2
+Without adoption, the lock manager or host would require a reset to clear
d617b2
+orphaned lock state.
d617b2
 
d617b2
 .B dlm/corosync failure
d617b2
 
d617b2
diff --git a/test/shell/duplicate-vgnames.sh b/test/shell/duplicate-vgnames.sh
d617b2
new file mode 100644
d617b2
index 0000000..0f98f9c
d617b2
--- /dev/null
d617b2
+++ b/test/shell/duplicate-vgnames.sh
d617b2
@@ -0,0 +1,660 @@
d617b2
+#!/usr/bin/env bash
d617b2
+
d617b2
+# Copyright (C) 2008-2013 Red Hat, Inc. All rights reserved.
d617b2
+#
d617b2
+# This copyrighted material is made available to anyone wishing to use,
d617b2
+# modify, copy, or redistribute it subject to the terms and conditions
d617b2
+# of the GNU General Public License v.2.
d617b2
+
d617b2
+SKIP_WITH_LVMLOCKD=1
d617b2
+SKIP_WITH_LVMPOLLD=1
d617b2
+
d617b2
+. lib/inittest
d617b2
+
d617b2
+aux prepare_devs 7
d617b2
+
d617b2
+# test setups:
d617b2
+#    # local vgs named foo  # foreign vg named foo
d617b2
+# a. 0                      1
d617b2
+# b. 0                      2
d617b2
+# c. 1                      1
d617b2
+# d. 1                      2
d617b2
+# e. 2                      0
d617b2
+# f. 2                      1
d617b2
+# g. 2                      2
d617b2
+# h. 3                      3
d617b2
+#
d617b2
+# commands to run for each test setup:
d617b2
+#
d617b2
+# vgs
d617b2
+# all cases show all local
d617b2
+#
d617b2
+# vgs --foreign
d617b2
+# all cases show all local and foreign
d617b2
+#
d617b2
+# vgs foo
d617b2
+# a. not found
d617b2
+# b. not found
d617b2
+# c. show 1 local
d617b2
+# d. show 1 local
d617b2
+# e-g. dup error
d617b2
+#
d617b2
+# vgs --foreign foo
d617b2
+# a. show 1 foreign
d617b2
+# b. dup error
d617b2
+# c. show 1 local
d617b2
+# d. show 1 local
d617b2
+# e-g. dup error
d617b2
+#
d617b2
+# vgchange -ay
d617b2
+# a. none
d617b2
+# b. none
d617b2
+# c. activate 1 local
d617b2
+# d. activate 1 local
d617b2
+# e-g. activate 2 local
d617b2
+# (if both local vgs have lvs with same name the second will fail to activate)
d617b2
+#
d617b2
+# vgchange -ay foo
d617b2
+# a. none
d617b2
+# b. none
d617b2
+# c. activate 1 local
d617b2
+# d. activate 1 local
d617b2
+# e-g. dup error
d617b2
+#
d617b2
+# lvcreate foo
d617b2
+# a. none
d617b2
+# b. none
d617b2
+# c. create 1 local
d617b2
+# d. create 1 local
d617b2
+# e-g. dup error
d617b2
+#
d617b2
+# vgremove foo
d617b2
+# a. none
d617b2
+# b. none
d617b2
+# c. remove 1 local
d617b2
+# d. remove 1 local
d617b2
+# e-g. dup error
d617b2
+# (in a couple cases test that vgremove -S vg_uuid=N works for local vg when local dups exist)
d617b2
+
d617b2
+
d617b2
+# a. 0 local, 1 foreign
d617b2
+# setup
d617b2
+vgcreate $vg1 "$dev1"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID1=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+vgchange -y --systemid "other" $vg1
d617b2
+
d617b2
+vgs -o+uuid |tee out
d617b2
+not grep $vg1 out
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+
d617b2
+not vgs -o+uuid $vg1 |tee out
d617b2
+not grep $vg1 out
d617b2
+vgs --foreign -o+uuid $vg1 |tee out
d617b2
+grep $vg1 out
d617b2
+
d617b2
+vgchange -ay
d617b2
+lvs --foreign -o vguuid,active |tee out
d617b2
+not grep active out
d617b2
+vgchange -an
d617b2
+
d617b2
+not vgchange -ay $vg1
d617b2
+lvs --foreign -o vguuid,active |tee out
d617b2
+not grep active out
d617b2
+vgchange -an
d617b2
+
d617b2
+not lvcreate -l1 -an -n $lv2 $vg1
d617b2
+lvs --foreign -o vguuid,name |tee out
d617b2
+grep $UUID1 out | not grep $lv2
d617b2
+
d617b2
+not vgremove $vg1
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+grep $UUID1 out
d617b2
+vgremove -y -S vg_uuid=$UUID1
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+grep $UUID1 out
d617b2
+
d617b2
+aux wipefs_a "$dev1"
d617b2
+aux wipefs_a "$dev2"
d617b2
+
d617b2
+# b. 0 local, 2 foreign
d617b2
+# setup
d617b2
+vgcreate $vg1 "$dev1"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID1=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+vgchange -y --systemid "other" $vg1
d617b2
+aux disable_dev "$dev1"
d617b2
+vgcreate $vg1 "$dev2"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID2=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+vgchange -y --systemid "other2" $vg1
d617b2
+aux enable_dev "$dev1"
d617b2
+
d617b2
+vgs -o+uuid |tee out
d617b2
+not grep $vg1 out
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+
d617b2
+not vgs -o+uuid $vg1 |tee out
d617b2
+not grep $vg1 out
d617b2
+not vgs --foreign -o+uuid $vg1 |tee out
d617b2
+not grep $vg1 out
d617b2
+
d617b2
+vgchange -ay
d617b2
+lvs --foreign -o vguuid,active |tee out
d617b2
+not grep active out
d617b2
+vgchange -an
d617b2
+
d617b2
+not vgchange -ay $vg1
d617b2
+lvs --foreign -o vguuid,active |tee out
d617b2
+not grep active out
d617b2
+vgchange -an
d617b2
+
d617b2
+not lvcreate -l1 -an -n $lv2 $vg1
d617b2
+lvs --foreign -o vguuid,name |tee out
d617b2
+grep $UUID1 out | not grep $lv2
d617b2
+grep $UUID2 out | not grep $lv2
d617b2
+
d617b2
+not vgremove $vg1
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+grep $UUID1 out
d617b2
+
d617b2
+aux wipefs_a "$dev1"
d617b2
+aux wipefs_a "$dev2"
d617b2
+aux wipefs_a "$dev3"
d617b2
+
d617b2
+# c. 1 local, 1 foreign
d617b2
+# setup
d617b2
+vgcreate $vg1 "$dev1"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID1=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+aux disable_dev "$dev1"
d617b2
+vgcreate $vg1 "$dev2"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID2=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+vgchange -y --systemid "other" $vg1
d617b2
+aux enable_dev "$dev1"
d617b2
+
d617b2
+vgs -o+uuid |tee out
d617b2
+cat out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+not grep $UUID2 out
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+
d617b2
+vgs -o+uuid $vg1 |tee out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+not grep $UUID2 out
d617b2
+vgs --foreign -o+uuid $vg1 |tee out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+not grep $UUID2 out
d617b2
+
d617b2
+vgchange -ay
d617b2
+lvs --foreign -o vguuid,active |tee out
d617b2
+grep $UUID1 out | grep active
d617b2
+grep $UUID2 out | not grep active
d617b2
+vgchange -an
d617b2
+
d617b2
+vgchange -ay $vg1
d617b2
+lvs --foreign -o vguuid,active |tee out
d617b2
+grep $UUID1 out | grep active
d617b2
+grep $UUID2 out | not grep active
d617b2
+vgchange -an
d617b2
+
d617b2
+lvcreate -l1 -an -n $lv2 $vg1
d617b2
+lvs --foreign -o vguuid,name |tee out
d617b2
+grep $UUID1 out | grep $lv2
d617b2
+grep $UUID2 out | not grep $lv2
d617b2
+
d617b2
+vgremove -y $vg1
d617b2
+vgs -o+uuid |tee out
d617b2
+not grep $UUID1 out
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+grep $UUID2 out
d617b2
+
d617b2
+aux wipefs_a "$dev1"
d617b2
+aux wipefs_a "$dev2"
d617b2
+aux wipefs_a "$dev3"
d617b2
+
d617b2
+# d. 1 local, 2 foreign
d617b2
+# setup
d617b2
+vgcreate $vg1 "$dev1"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID1=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+aux disable_dev "$dev1"
d617b2
+vgcreate $vg1 "$dev2"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID2=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+vgchange -y --systemid "other" $vg1
d617b2
+aux disable_dev "$dev2"
d617b2
+vgcreate $vg1 "$dev3"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID3=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+vgchange -y --systemid "other2" $vg1
d617b2
+aux enable_dev "$dev1"
d617b2
+aux enable_dev "$dev2"
d617b2
+
d617b2
+vgs -o+uuid |tee out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+not grep $UUID2 out
d617b2
+not grep $UUID3 out
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+
d617b2
+vgs -o+uuid $vg1 |tee out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+not grep $UUID2 out
d617b2
+not grep $UUID3 out
d617b2
+vgs --foreign -o+uuid $vg1 |tee out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+not grep $UUID2 out
d617b2
+not grep $UUID3 out
d617b2
+
d617b2
+vgchange -ay
d617b2
+lvs --foreign -o vguuid,active |tee out
d617b2
+grep $UUID1 out | grep active
d617b2
+grep $UUID2 out | not grep active
d617b2
+grep $UUID3 out | not grep active
d617b2
+vgchange -an
d617b2
+
d617b2
+vgchange -ay $vg1
d617b2
+lvs --foreign -o vguuid,active |tee out
d617b2
+grep $UUID1 out | grep active
d617b2
+grep $UUID2 out | not grep active
d617b2
+grep $UUID3 out | not grep active
d617b2
+vgchange -an
d617b2
+
d617b2
+lvcreate -l1 -an -n $lv2 $vg1
d617b2
+lvs --foreign -o vguuid,name |tee out
d617b2
+grep $UUID1 out | grep $lv2
d617b2
+grep $UUID2 out | not grep $lv2
d617b2
+grep $UUID3 out | not grep $lv2
d617b2
+
d617b2
+vgremove -y $vg1
d617b2
+vgs -o+uuid |tee out
d617b2
+not grep $UUID1 out
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+
d617b2
+aux wipefs_a "$dev1"
d617b2
+aux wipefs_a "$dev2"
d617b2
+aux wipefs_a "$dev3"
d617b2
+aux wipefs_a "$dev4"
d617b2
+
d617b2
+# e. 2 local, 0 foreign
d617b2
+# setup
d617b2
+vgcreate $vg1 "$dev1"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID1=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+aux disable_dev "$dev1"
d617b2
+vgcreate $vg1 "$dev2"
d617b2
+# diff lvname to prevent clash in vgchange -ay
d617b2
+lvcreate -n ${lv1}_b -l1 -an $vg1
d617b2
+UUID2=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+aux enable_dev "$dev1"
d617b2
+
d617b2
+vgs -o+uuid |tee out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+
d617b2
+not vgs -o+uuid $vg1 |tee out
d617b2
+not grep $vg1 out
d617b2
+not vgs --foreign -o+uuid $vg1 |tee out
d617b2
+not grep $vg1 out
d617b2
+
d617b2
+vgchange -ay
d617b2
+lvs --foreign -o vguuid,active |tee out
d617b2
+grep $UUID1 out | grep active
d617b2
+grep $UUID2 out | grep active
d617b2
+vgchange -an
d617b2
+
d617b2
+not vgchange -ay $vg1
d617b2
+lvs --foreign -o vguuid,active |tee out
d617b2
+grep $UUID1 out | not grep active
d617b2
+grep $UUID2 out | not grep active
d617b2
+vgchange -an
d617b2
+
d617b2
+not lvcreate -l1 -an -n $lv2 $vg1
d617b2
+lvs --foreign -o vguuid,name |tee out
d617b2
+grep $UUID1 out | not grep $lv2
d617b2
+grep $UUID2 out | not grep $lv2
d617b2
+
d617b2
+not vgremove $vg1
d617b2
+vgs -o+uuid |tee out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+vgremove -y -S vg_uuid=$UUID1
d617b2
+vgs -o+uuid |tee out
d617b2
+not grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+vgremove -y -S vg_uuid=$UUID2
d617b2
+vgs -o+uuid |tee out
d617b2
+not grep $UUID1 out
d617b2
+not grep $UUID2 out
d617b2
+
d617b2
+aux wipefs_a "$dev1"
d617b2
+aux wipefs_a "$dev2"
d617b2
+aux wipefs_a "$dev3"
d617b2
+
d617b2
+# f. 2 local, 1 foreign
d617b2
+# setup
d617b2
+vgcreate $vg1 "$dev1"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID1=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+aux disable_dev "$dev1"
d617b2
+vgcreate $vg1 "$dev2"
d617b2
+# diff lvname to prevent clash in vgchange -ay
d617b2
+lvcreate -n ${lv1}_b -l1 -an $vg1
d617b2
+UUID2=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+aux disable_dev "$dev2"
d617b2
+vgcreate $vg1 "$dev3"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID3=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+vgchange -y --systemid "other" $vg1
d617b2
+aux enable_dev "$dev1"
d617b2
+aux enable_dev "$dev2"
d617b2
+
d617b2
+vgs -o+uuid |tee out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+not group $UUID3 out
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+
d617b2
+not vgs -o+uuid $vg1 |tee out
d617b2
+not grep $vg1 out
d617b2
+not vgs --foreign -o+uuid $vg1 |tee out
d617b2
+not grep $vg1 out
d617b2
+
d617b2
+vgchange -ay
d617b2
+lvs --foreign -o vguuid,active |tee out
d617b2
+grep $UUID1 out | grep active
d617b2
+grep $UUID2 out | grep active
d617b2
+grep $UUID3 out | not grep active
d617b2
+vgchange -an
d617b2
+
d617b2
+not vgchange -ay $vg1
d617b2
+lvs --foreign -o vguuid,active |tee out
d617b2
+grep $UUID1 out | not grep active
d617b2
+grep $UUID2 out | not grep active
d617b2
+grep $UUID3 out | not grep active
d617b2
+vgchange -an
d617b2
+
d617b2
+not lvcreate -l1 -an -n $lv2 $vg1
d617b2
+lvs --foreign -o vguuid,name |tee out
d617b2
+grep $UUID1 out | not grep $lv2
d617b2
+grep $UUID2 out | not grep $lv2
d617b2
+grep $UUID3 out | not grep $lv2
d617b2
+
d617b2
+not vgremove $vg1
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+vgremove -y -S vg_uuid=$UUID1
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+not grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+vgremove -y -S vg_uuid=$UUID2
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+not grep $UUID1 out
d617b2
+not grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+
d617b2
+aux wipefs_a "$dev1"
d617b2
+aux wipefs_a "$dev2"
d617b2
+aux wipefs_a "$dev3"
d617b2
+aux wipefs_a "$dev4"
d617b2
+
d617b2
+# g. 2 local, 2 foreign
d617b2
+# setup
d617b2
+vgcreate $vg1 "$dev1"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID1=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+aux disable_dev "$dev1"
d617b2
+vgcreate $vg1 "$dev2"
d617b2
+# diff lvname to prevent clash in vgchange -ay
d617b2
+lvcreate -n ${lv1}_b -l1 -an $vg1
d617b2
+UUID2=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+aux disable_dev "$dev2"
d617b2
+vgcreate $vg1 "$dev3"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID3=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+vgchange -y --systemid "other" $vg1
d617b2
+aux disable_dev "$dev3"
d617b2
+vgcreate $vg1 "$dev4"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID4=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+vgchange -y --systemid "other2" $vg1
d617b2
+aux enable_dev "$dev1"
d617b2
+aux enable_dev "$dev2"
d617b2
+aux enable_dev "$dev3"
d617b2
+
d617b2
+vgs -o+uuid |tee out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+not group $UUID3 out
d617b2
+not group $UUID4 out
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+grep $UUID4 out
d617b2
+
d617b2
+not vgs -o+uuid $vg1 |tee out
d617b2
+not grep $vg1 out
d617b2
+not vgs --foreign -o+uuid $vg1 |tee out
d617b2
+not grep $vg1 out
d617b2
+
d617b2
+vgchange -ay
d617b2
+lvs --foreign -o vguuid,active |tee out
d617b2
+grep $UUID1 out | grep active
d617b2
+grep $UUID2 out | grep active
d617b2
+grep $UUID3 out | not grep active
d617b2
+grep $UUID4 out | not grep active
d617b2
+vgchange -an
d617b2
+
d617b2
+not vgchange -ay $vg1
d617b2
+lvs --foreign -o vguuid,active |tee out
d617b2
+grep $UUID1 out | not grep active
d617b2
+grep $UUID2 out | not grep active
d617b2
+grep $UUID3 out | not grep active
d617b2
+grep $UUID4 out | not grep active
d617b2
+vgchange -an
d617b2
+
d617b2
+not lvcreate -l1 -an -n $lv2 $vg1
d617b2
+lvs --foreign -o vguuid,name |tee out
d617b2
+grep $UUID1 out | not grep $lv2
d617b2
+grep $UUID2 out | not grep $lv2
d617b2
+grep $UUID3 out | not grep $lv2
d617b2
+grep $UUID4 out | not grep $lv2
d617b2
+
d617b2
+not vgremove $vg1
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+grep $UUID4 out
d617b2
+
d617b2
+aux wipefs_a "$dev1"
d617b2
+aux wipefs_a "$dev2"
d617b2
+aux wipefs_a "$dev3"
d617b2
+aux wipefs_a "$dev4"
d617b2
+aux wipefs_a "$dev5"
d617b2
+
d617b2
+# h. 3 local, 3 foreign
d617b2
+# setup
d617b2
+vgcreate $vg1 "$dev1"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID1=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+aux disable_dev "$dev1"
d617b2
+vgcreate $vg1 "$dev2"
d617b2
+# diff lvname to prevent clash in vgchange -ay
d617b2
+lvcreate -n ${lv1}_b -l1 -an $vg1
d617b2
+UUID2=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+aux disable_dev "$dev2"
d617b2
+vgcreate $vg1 "$dev3"
d617b2
+# diff lvname to prevent clash in vgchange -ay
d617b2
+lvcreate -n ${lv1}_bb -l1 -an $vg1
d617b2
+UUID3=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+aux disable_dev "$dev3"
d617b2
+vgcreate $vg1 "$dev4"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID4=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+vgchange -y --systemid "other" $vg1
d617b2
+aux disable_dev "$dev4"
d617b2
+vgcreate $vg1 "$dev5"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID5=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+vgchange -y --systemid "other2" $vg1
d617b2
+aux disable_dev "$dev5"
d617b2
+vgcreate $vg1 "$dev6"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID6=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+vgchange -y --systemid "other3" $vg1
d617b2
+aux enable_dev "$dev1"
d617b2
+aux enable_dev "$dev2"
d617b2
+aux enable_dev "$dev3"
d617b2
+aux enable_dev "$dev4"
d617b2
+aux enable_dev "$dev5"
d617b2
+
d617b2
+vgs -o+uuid |tee out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+not group $UUID4 out
d617b2
+not group $UUID5 out
d617b2
+not group $UUID6 out
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+grep $UUID4 out
d617b2
+grep $UUID5 out
d617b2
+grep $UUID6 out
d617b2
+
d617b2
+not vgs -o+uuid $vg1 |tee out
d617b2
+not grep $vg1 out
d617b2
+not vgs --foreign -o+uuid $vg1 |tee out
d617b2
+not grep $vg1 out
d617b2
+
d617b2
+vgchange -ay
d617b2
+lvs --foreign -o vguuid,active |tee out
d617b2
+grep $UUID1 out | grep active
d617b2
+grep $UUID2 out | grep active
d617b2
+grep $UUID3 out | grep active
d617b2
+grep $UUID4 out | not grep active
d617b2
+grep $UUID5 out | not grep active
d617b2
+grep $UUID6 out | not grep active
d617b2
+vgchange -an
d617b2
+
d617b2
+not vgchange -ay $vg1
d617b2
+lvs --foreign -o vguuid,active |tee out
d617b2
+grep $UUID1 out | not grep active
d617b2
+grep $UUID2 out | not grep active
d617b2
+grep $UUID3 out | not grep active
d617b2
+grep $UUID4 out | not grep active
d617b2
+grep $UUID5 out | not grep active
d617b2
+grep $UUID6 out | not grep active
d617b2
+vgchange -an
d617b2
+
d617b2
+not lvcreate -l1 -an -n $lv2 $vg1
d617b2
+lvs --foreign -o vguuid,name |tee out
d617b2
+grep $UUID1 out | not grep $lv2
d617b2
+grep $UUID2 out | not grep $lv2
d617b2
+grep $UUID3 out | not grep $lv2
d617b2
+grep $UUID4 out | not grep $lv2
d617b2
+grep $UUID5 out | not grep $lv2
d617b2
+grep $UUID6 out | not grep $lv2
d617b2
+
d617b2
+not vgremove $vg1
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+grep $UUID4 out
d617b2
+grep $UUID5 out
d617b2
+grep $UUID6 out
d617b2
+
d617b2
+aux wipefs_a "$dev1"
d617b2
+aux wipefs_a "$dev2"
d617b2
+aux wipefs_a "$dev3"
d617b2
+aux wipefs_a "$dev4"
d617b2
+aux wipefs_a "$dev5"
d617b2
+aux wipefs_a "$dev6"
d617b2
+
d617b2
+# vgreduce test with 1 local and 1 foreign vg.
d617b2
+# setup
d617b2
+vgcreate $vg1 "$dev1" "$dev7"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1 "$dev1"
d617b2
+UUID1=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+PV1UUID=$(pvs --noheading -o uuid "$dev1")
d617b2
+PV7UUID=$(pvs --noheading -o uuid "$dev7")
d617b2
+aux disable_dev "$dev1"
d617b2
+aux disable_dev "$dev7"
d617b2
+vgcreate $vg1 "$dev2"
d617b2
+PV2UUID=$(pvs --noheading -o uuid "$dev2")
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID2=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+vgchange -y --systemid "other" $vg1
d617b2
+aux enable_dev "$dev1"
d617b2
+aux enable_dev "$dev7"
d617b2
+
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+grep $vg1 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+pvs --foreign -o+uuid |tee out
d617b2
+grep $PV1UUID out
d617b2
+grep $PV7UUID out
d617b2
+grep $PV2UUID out
d617b2
+
d617b2
+vgreduce $vg1 "$dev7"
d617b2
+
d617b2
+pvs --foreign -o+uuid |tee out
d617b2
+grep $PV1UUID out
d617b2
+grep $PV7UUID out
d617b2
+grep $PV2UUID out
d617b2
+
d617b2
+grep $PV7UUID out >out2
d617b2
+not grep $vg1 out2
d617b2
+
d617b2
+vgremove -ff $vg1
d617b2
+
d617b2
+aux wipefs_a "$dev1"
d617b2
+aux wipefs_a "$dev2"
d617b2
+aux wipefs_a "$dev7"
d617b2
diff --git a/test/shell/duplicate-vgrename.sh b/test/shell/duplicate-vgrename.sh
d617b2
new file mode 100644
d617b2
index 0000000..8628220
d617b2
--- /dev/null
d617b2
+++ b/test/shell/duplicate-vgrename.sh
d617b2
@@ -0,0 +1,319 @@
d617b2
+#!/usr/bin/env bash
d617b2
+
d617b2
+# Copyright (C) 2008-2013 Red Hat, Inc. All rights reserved.
d617b2
+#
d617b2
+# This copyrighted material is made available to anyone wishing to use,
d617b2
+# modify, copy, or redistribute it subject to the terms and conditions
d617b2
+# of the GNU General Public License v.2.
d617b2
+
d617b2
+SKIP_WITH_LVMLOCKD=1
d617b2
+SKIP_WITH_LVMPOLLD=1
d617b2
+
d617b2
+. lib/inittest
d617b2
+
d617b2
+aux prepare_devs 4
d617b2
+
d617b2
+# a. 0 local, 1 foreign
d617b2
+# setup
d617b2
+vgcreate $vg1 "$dev1"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID1=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+vgchange -y --systemid "other" $vg1
d617b2
+
d617b2
+not vgrename $vg1 $vg2
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+grep $UUID1 out
d617b2
+not vgrename $UUID1 $vg2
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+grep $UUID1 out
d617b2
+
d617b2
+lvs --foreign
d617b2
+
d617b2
+aux wipefs_a "$dev1"
d617b2
+
d617b2
+# b. 0 local, 2 foreign
d617b2
+# setup
d617b2
+vgcreate $vg1 "$dev1"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID1=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+vgchange -y --systemid "other" $vg1
d617b2
+aux disable_dev "$dev1"
d617b2
+vgcreate $vg1 "$dev2"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID2=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+vgchange -y --systemid "other2" $vg1
d617b2
+aux enable_dev "$dev1"
d617b2
+
d617b2
+not vgrename $vg1 $vg2
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+lvs --foreign
d617b2
+grep $vg1 out
d617b2
+not grep $vg2 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+not vgrename $UUID1 $vg2
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+lvs --foreign
d617b2
+grep $vg1 out
d617b2
+not grep $vg2 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+
d617b2
+lvs --foreign
d617b2
+
d617b2
+aux wipefs_a "$dev1"
d617b2
+aux wipefs_a "$dev2"
d617b2
+
d617b2
+# c. 1 local, 1 foreign
d617b2
+# setup
d617b2
+vgcreate $vg1 "$dev1"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID1=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+aux disable_dev "$dev1"
d617b2
+vgcreate $vg1 "$dev2"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID2=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+vgchange -y --systemid "other" $vg1
d617b2
+aux enable_dev "$dev1"
d617b2
+
d617b2
+vgrename $vg1 $vg2
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+lvs --foreign
d617b2
+grep $vg1 out
d617b2
+grep $vg2 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+not vgrename $vg2 $vg1
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+lvs --foreign
d617b2
+grep $vg1 out
d617b2
+grep $vg2 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+
d617b2
+lvs --foreign
d617b2
+
d617b2
+aux wipefs_a "$dev1"
d617b2
+aux wipefs_a "$dev2"
d617b2
+
d617b2
+# d. 1 local, 2 foreign
d617b2
+# setup
d617b2
+vgcreate $vg1 "$dev1"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID1=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+aux disable_dev "$dev1"
d617b2
+vgcreate $vg1 "$dev2"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID2=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+vgchange -y --systemid "other" $vg1
d617b2
+aux disable_dev "$dev2"
d617b2
+vgcreate $vg1 "$dev3"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID3=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+vgchange -y --systemid "other2" $vg1
d617b2
+aux enable_dev "$dev1"
d617b2
+aux enable_dev "$dev2"
d617b2
+
d617b2
+vgrename $vg1 $vg2
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+lvs --foreign
d617b2
+grep $vg1 out
d617b2
+grep $vg2 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+not vgrename $vg2 $vg1
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+lvs --foreign
d617b2
+grep $vg1 out
d617b2
+grep $vg2 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+
d617b2
+lvs --foreign
d617b2
+
d617b2
+aux wipefs_a "$dev1"
d617b2
+aux wipefs_a "$dev2"
d617b2
+aux wipefs_a "$dev3"
d617b2
+
d617b2
+# e. 2 local, 0 foreign
d617b2
+# setup
d617b2
+vgcreate $vg1 "$dev1"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID1=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+aux disable_dev "$dev1"
d617b2
+vgcreate $vg1 "$dev2"
d617b2
+lvcreate -n ${lv1}_b -l1 -an $vg1
d617b2
+UUID2=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+aux enable_dev "$dev1"
d617b2
+
d617b2
+not vgrename $vg1 $vg2
d617b2
+vgs -o+uuid |tee out
d617b2
+lvs --foreign
d617b2
+grep $vg1 out
d617b2
+not grep $vg2 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+vgrename $UUID1 $vg2
d617b2
+vgs -o+uuid |tee out
d617b2
+lvs --foreign
d617b2
+grep $vg1 out
d617b2
+grep $vg2 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+not vgrename $UUID2 $vg2
d617b2
+vgs -o+uuid |tee out
d617b2
+lvs --foreign
d617b2
+grep $vg1 out
d617b2
+grep $vg2 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+
d617b2
+lvs --foreign
d617b2
+
d617b2
+aux wipefs_a "$dev1"
d617b2
+aux wipefs_a "$dev2"
d617b2
+
d617b2
+# f. 2 local, 1 foreign
d617b2
+# setup
d617b2
+vgcreate $vg1 "$dev1"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID1=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+aux disable_dev "$dev1"
d617b2
+vgcreate $vg1 "$dev2"
d617b2
+lvcreate -n ${lv1}_b -l1 -an $vg1
d617b2
+UUID2=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+aux disable_dev "$dev2"
d617b2
+vgcreate $vg1 "$dev3"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID3=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+vgchange -y --systemid "other" $vg1
d617b2
+aux enable_dev "$dev1"
d617b2
+aux enable_dev "$dev2"
d617b2
+lvs --foreign
d617b2
+
d617b2
+not vgrename $vg1 $vg2
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+lvs --foreign
d617b2
+grep $vg1 out
d617b2
+not grep $vg2 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+vgrename $UUID1 $vg2
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+lvs --foreign
d617b2
+grep $vg1 out
d617b2
+grep $vg2 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+vgrename $vg1 $vg3
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+lvs --foreign
d617b2
+grep $vg1 out
d617b2
+grep $vg2 out
d617b2
+grep $vg3 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+not vgrename $vg2 $vg1
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+lvs --foreign
d617b2
+grep $vg1 out
d617b2
+grep $vg2 out
d617b2
+grep $vg3 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+not vgrename $vg2 $vg3
d617b2
+vgs --foreign -o+uuid |tee out
d617b2
+lvs --foreign
d617b2
+grep $vg1 out
d617b2
+grep $vg2 out
d617b2
+grep $vg3 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+
d617b2
+lvs --foreign
d617b2
+
d617b2
+aux wipefs_a "$dev1"
d617b2
+aux wipefs_a "$dev2"
d617b2
+aux wipefs_a "$dev3"
d617b2
+
d617b2
+# g. 3 local, 0 foreign
d617b2
+# setup
d617b2
+vgcreate $vg1 "$dev1"
d617b2
+lvcreate -n $lv1 -l1 -an $vg1
d617b2
+UUID1=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+aux disable_dev "$dev1"
d617b2
+vgcreate $vg1 "$dev2"
d617b2
+lvcreate -n ${lv1}_b -l1 -an $vg1
d617b2
+UUID2=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+aux disable_dev "$dev2"
d617b2
+vgcreate $vg1 "$dev3"
d617b2
+lvcreate -n ${lv1}_c -l1 -an $vg1
d617b2
+UUID3=$(vgs --noheading -o vg_uuid $vg1 | xargs)
d617b2
+aux enable_dev "$dev1"
d617b2
+aux enable_dev "$dev2"
d617b2
+
d617b2
+not vgrename $vg1 $vg2
d617b2
+vgs -o+uuid |tee out
d617b2
+lvs --foreign
d617b2
+grep $vg1 out
d617b2
+not grep $vg2 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+vgrename $UUID1 $vg2
d617b2
+vgs -o+uuid |tee out
d617b2
+lvs --foreign
d617b2
+grep $vg1 out
d617b2
+grep $vg2 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+not vgrename $vg1 $vg2
d617b2
+vgs -o+uuid |tee out
d617b2
+lvs --foreign
d617b2
+grep $vg1 out
d617b2
+grep $vg2 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+not vgrename $vg1 $vg3
d617b2
+vgs -o+uuid |tee out
d617b2
+lvs --foreign
d617b2
+grep $vg1 out
d617b2
+grep $vg2 out
d617b2
+not grep $vg3 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+not vgrename $UUID2 $vg2
d617b2
+vgs -o+uuid |tee out
d617b2
+lvs --foreign
d617b2
+grep $vg1 out
d617b2
+grep $vg2 out
d617b2
+not grep $vg3 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+vgrename $UUID2 $vg3
d617b2
+vgs -o+uuid |tee out
d617b2
+lvs --foreign
d617b2
+grep $vg1 out
d617b2
+grep $vg2 out
d617b2
+grep $vg3 out
d617b2
+grep $UUID1 out
d617b2
+grep $UUID2 out
d617b2
+grep $UUID3 out
d617b2
+
d617b2
+lvs --foreign
d617b2
+
d617b2
+aux wipefs_a "$dev1"
d617b2
+aux wipefs_a "$dev2"
d617b2
+aux wipefs_a "$dev3"
d617b2
+
d617b2
diff --git a/test/shell/integrity-dmeventd.sh b/test/shell/integrity-dmeventd.sh
d617b2
index 58899ca..ed2436a 100644
d617b2
--- a/test/shell/integrity-dmeventd.sh
d617b2
+++ b/test/shell/integrity-dmeventd.sh
d617b2
@@ -22,9 +22,9 @@ mkdir -p $mnt
d617b2
 
d617b2
 aux prepare_devs 6 64
d617b2
 
d617b2
-for i in `seq 1 16384`; do echo -n "A" >> fileA; done
d617b2
-for i in `seq 1 16384`; do echo -n "B" >> fileB; done
d617b2
-for i in `seq 1 16384`; do echo -n "C" >> fileC; done
d617b2
+printf "%0.sA" {1..16384} >> fileA
d617b2
+printf "%0.sB" {1..16384} >> fileB
d617b2
+printf "%0.sC" {1..16384} >> fileC
d617b2
 
d617b2
 # generate random data
d617b2
 dd if=/dev/urandom of=randA bs=512K count=2
d617b2
diff --git a/test/shell/integrity-large.sh b/test/shell/integrity-large.sh
d617b2
index 0c36e4d..7a333c1 100644
d617b2
--- a/test/shell/integrity-large.sh
d617b2
+++ b/test/shell/integrity-large.sh
d617b2
@@ -25,9 +25,9 @@ mkdir -p $mnt
d617b2
 # raid1 LV needs to be extended to 512MB to test imeta being exended
d617b2
 aux prepare_devs 4 600
d617b2
 
d617b2
-for i in `seq 1 16384`; do echo -n "A" >> fileA; done
d617b2
-for i in `seq 1 16384`; do echo -n "B" >> fileB; done
d617b2
-for i in `seq 1 16384`; do echo -n "C" >> fileC; done
d617b2
+printf "%0.sA" {1..16384} >> fileA
d617b2
+printf "%0.sB" {1..16384} >> fileB
d617b2
+printf "%0.sC" {1..16384} >> fileC
d617b2
 
d617b2
 # generate random data
d617b2
 dd if=/dev/urandom of=randA bs=512K count=2
d617b2
diff --git a/test/shell/integrity-misc.sh b/test/shell/integrity-misc.sh
d617b2
index 73b0a67..a176f18 100644
d617b2
--- a/test/shell/integrity-misc.sh
d617b2
+++ b/test/shell/integrity-misc.sh
d617b2
@@ -22,9 +22,9 @@ mkdir -p $mnt
d617b2
 
d617b2
 aux prepare_devs 5 64
d617b2
 
d617b2
-for i in `seq 1 16384`; do echo -n "A" >> fileA; done
d617b2
-for i in `seq 1 16384`; do echo -n "B" >> fileB; done
d617b2
-for i in `seq 1 16384`; do echo -n "C" >> fileC; done
d617b2
+printf "%0.sA" {1..16384} >> fileA
d617b2
+printf "%0.sB" {1..16384} >> fileB
d617b2
+printf "%0.sC" {1..16384} >> fileC
d617b2
 
d617b2
 # generate random data
d617b2
 dd if=/dev/urandom of=randA bs=512K count=2
d617b2
diff --git a/test/shell/integrity.sh b/test/shell/integrity.sh
d617b2
index 7e4f2cb..6baccf0 100644
d617b2
--- a/test/shell/integrity.sh
d617b2
+++ b/test/shell/integrity.sh
d617b2
@@ -23,9 +23,9 @@ mkdir -p $mnt
d617b2
 
d617b2
 aux prepare_devs 5 64
d617b2
 
d617b2
-for i in `seq 1 16384`; do echo -n "A" >> fileA; done
d617b2
-for i in `seq 1 16384`; do echo -n "B" >> fileB; done
d617b2
-for i in `seq 1 16384`; do echo -n "C" >> fileC; done
d617b2
+printf "%0.sA" {1..16384} >> fileA
d617b2
+printf "%0.sB" {1..16384} >> fileB
d617b2
+printf "%0.sC" {1..16384} >> fileC
d617b2
 
d617b2
 # generate random data
d617b2
 dd if=/dev/urandom of=randA bs=512K count=2
d617b2
diff --git a/test/shell/process-each-duplicate-vgnames.sh b/test/shell/process-each-duplicate-vgnames.sh
d617b2
deleted file mode 100644
d617b2
index a59c3bd..0000000
d617b2
--- a/test/shell/process-each-duplicate-vgnames.sh
d617b2
+++ /dev/null
d617b2
@@ -1,55 +0,0 @@
d617b2
-#!/usr/bin/env bash
d617b2
-
d617b2
-# Copyright (C) 2008-2013 Red Hat, Inc. All rights reserved.
d617b2
-#
d617b2
-# This copyrighted material is made available to anyone wishing to use,
d617b2
-# modify, copy, or redistribute it subject to the terms and conditions
d617b2
-# of the GNU General Public License v.2.
d617b2
-
d617b2
-test_description='Test vgs with duplicate vg names'
d617b2
-SKIP_WITH_LVMLOCKD=1
d617b2
-SKIP_WITH_LVMPOLLD=1
d617b2
-
d617b2
-. lib/inittest
d617b2
-
d617b2
-aux prepare_devs 2
d617b2
-
d617b2
-pvcreate "$dev1"
d617b2
-pvcreate "$dev2"
d617b2
-
d617b2
-aux disable_dev "$dev1" "$dev2"
d617b2
-
d617b2
-aux enable_dev "$dev1"
d617b2
-vgcreate $vg1 "$dev1"
d617b2
-UUID1=$(vgs --noheading -o vg_uuid $vg1)
d617b2
-aux disable_dev "$dev1"
d617b2
-
d617b2
-aux enable_dev "$dev2"
d617b2
-vgcreate $vg1 "$dev2"
d617b2
-UUID2=$(vgs --noheading -o vg_uuid $vg1)
d617b2
-
d617b2
-aux enable_dev "$dev1"
d617b2
-pvscan --cache "$dev1"
d617b2
-pvs "$dev1"
d617b2
-pvs "$dev2"
d617b2
-
d617b2
-vgs -o+vg_uuid | tee err
d617b2
-grep $UUID1 err
d617b2
-grep $UUID2 err
d617b2
-
d617b2
-# should we specify and test which should be displayed?
d617b2
-# vgs --noheading -o vg_uuid $vg1 >err
d617b2
-# grep $UUID1 err
d617b2
-
d617b2
-aux disable_dev "$dev2"
d617b2
-vgs -o+vg_uuid | tee err
d617b2
-grep $UUID1 err
d617b2
-not grep $UUID2 err
d617b2
-aux enable_dev "$dev2"
d617b2
-pvscan --cache "$dev2"
d617b2
-
d617b2
-aux disable_dev "$dev1"
d617b2
-vgs -o+vg_uuid | tee err
d617b2
-grep $UUID2 err
d617b2
-not grep $UUID1 err
d617b2
-aux enable_dev "$dev1"
d617b2
diff --git a/test/shell/thin-foreign-repair.sh b/test/shell/thin-foreign-repair.sh
d617b2
index 147a9a0..8b4018e 100644
d617b2
--- a/test/shell/thin-foreign-repair.sh
d617b2
+++ b/test/shell/thin-foreign-repair.sh
d617b2
@@ -56,7 +56,9 @@ dmsetup create "$THIN" --table "0 40960 thin $DM_DEV_DIR/mapper/$POOL 0"
d617b2
 
d617b2
 mkfs.ext4 "$DM_DEV_DIR/mapper/$THIN"
d617b2
 
d617b2
-dmsetup remove "$THIN"
d617b2
+aux udev_wait
d617b2
+
d617b2
+dmsetup remove "$THIN" || { sleep .5 ; dmsetup remove "$THIN" }
d617b2
 
d617b2
 lvchange -an $vg/pool
d617b2
 
d617b2
diff --git a/tools/command.c b/tools/command.c
d617b2
index 50791b1..511dda1 100644
d617b2
--- a/tools/command.c
d617b2
+++ b/tools/command.c
d617b2
@@ -2319,7 +2319,8 @@ static void _print_val_man(struct command_name *cname, int opt_enum, int val_enu
d617b2
 	}
d617b2
 
d617b2
 	if (strchr(str, '|')) {
d617b2
-		line = strdup(str);
d617b2
+		if (!(line = strdup(str)))
d617b2
+			return;
d617b2
 		_split_line(line, &line_argc, line_argv, '|');
d617b2
 		for (i = 0; i < line_argc; i++) {
d617b2
 			if (i)
d617b2
@@ -3606,9 +3607,12 @@ int main(int argc, char *argv[])
d617b2
 		goto out_free;
d617b2
 	}
d617b2
 
d617b2
-	if (optind < argc)
d617b2
-		cmdname = strdup(argv[optind++]);
d617b2
-	else {
d617b2
+	if (optind < argc) {
d617b2
+		if (!(cmdname = strdup(argv[optind++]))) {
d617b2
+			log_error("Out of memory.");
d617b2
+			goto out_free;
d617b2
+		}
d617b2
+	} else {
d617b2
 		log_error("Missing command name.");
d617b2
 		goto out_free;
d617b2
 	}
d617b2
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
d617b2
index e969b44..cf93538 100644
d617b2
--- a/tools/lvconvert.c
d617b2
+++ b/tools/lvconvert.c
d617b2
@@ -5589,7 +5589,8 @@ static struct logical_volume *_lv_writecache_create(struct cmd_context *cmd,
d617b2
 
d617b2
 	memcpy(&seg->writecache_settings, settings, sizeof(struct writecache_settings));
d617b2
 
d617b2
-	add_seg_to_segs_using_this_lv(lv_fast, seg);
d617b2
+	if (!add_seg_to_segs_using_this_lv(lv_fast, seg))
d617b2
+		return_NULL;
d617b2
 
d617b2
 	return lv_wcorig;
d617b2
 }
d617b2
diff --git a/tools/pvck.c b/tools/pvck.c
d617b2
index 71bfc1b..a0f567e 100644
d617b2
--- a/tools/pvck.c
d617b2
+++ b/tools/pvck.c
d617b2
@@ -3065,11 +3065,9 @@ int pvck(struct cmd_context *cmd, int argc, char **argv)
d617b2
 
d617b2
 	label_scan_setup_bcache();
d617b2
 
d617b2
-	if (arg_is_set(cmd, dump_ARG)) {
d617b2
+	if ((dump = arg_str_value(cmd, dump_ARG, NULL))) {
d617b2
 		cmd->use_hints = 0;
d617b2
 
d617b2
-		dump = arg_str_value(cmd, dump_ARG, NULL);
d617b2
-
d617b2
 		if (!strcmp(dump, "metadata"))
d617b2
 			ret = _dump_metadata(cmd, dump, &set, labelsector, dev, def, PRINT_CURRENT, 0);
d617b2
 
d617b2
@@ -3096,11 +3094,9 @@ int pvck(struct cmd_context *cmd, int argc, char **argv)
d617b2
 		return ECMD_PROCESSED;
d617b2
 	}
d617b2
 
d617b2
-	if (arg_is_set(cmd, repairtype_ARG)) {
d617b2
+	if ((repair = arg_str_value(cmd, repairtype_ARG, NULL))) {
d617b2
 		cmd->use_hints = 0;
d617b2
 
d617b2
-		repair = arg_str_value(cmd, repairtype_ARG, NULL);
d617b2
-
d617b2
 		if (!strcmp(repair, "label_header"))
d617b2
 			ret = _repair_label_header(cmd, repair, &set, labelsector, dev);
d617b2
 
d617b2
diff --git a/tools/pvscan.c b/tools/pvscan.c
d617b2
index 1bf543c..4d811da 100644
d617b2
--- a/tools/pvscan.c
d617b2
+++ b/tools/pvscan.c
d617b2
@@ -582,7 +582,7 @@ static int _online_pvscan_single(struct metadata_area *mda, void *baton)
d617b2
 
d617b2
 	if (mda_is_ignored(mda))
d617b2
 		return 1;
d617b2
-	vg = mda->ops->vg_read(b->fid, "", mda, NULL, NULL);
d617b2
+	vg = mda->ops->vg_read(b->cmd, b->fid, "", mda, NULL, NULL);
d617b2
 	if (!vg) {
d617b2
 		/*
d617b2
 		 * Many or most cases of bad metadata would be found in
d617b2
diff --git a/tools/toollib.c b/tools/toollib.c
d617b2
index 96d0d6d..89b6374 100644
d617b2
--- a/tools/toollib.c
d617b2
+++ b/tools/toollib.c
d617b2
@@ -1853,8 +1853,6 @@ static int _resolve_duplicate_vgnames(struct cmd_context *cmd,
d617b2
 			if (lvmcache_vg_is_foreign(cmd, vgnl->vg_name, vgnl->vgid)) {
d617b2
 				if (!id_write_format((const struct id*)vgnl->vgid, uuid, sizeof(uuid)))
d617b2
 					stack;
d617b2
-				log_warn("WARNING: Ignoring foreign VG with matching name %s UUID %s.",
d617b2
-					 vgnl->vg_name, uuid);
d617b2
 				dm_list_del(&vgnl->list);
d617b2
 			} else {
d617b2
 				found++;
d617b2
diff --git a/tools/vgchange.c b/tools/vgchange.c
d617b2
index a10bf11..58c8ddc 100644
d617b2
--- a/tools/vgchange.c
d617b2
+++ b/tools/vgchange.c
d617b2
@@ -991,8 +991,13 @@ static int _vgchange_locktype_single(struct cmd_context *cmd, const char *vg_nam
d617b2
 	 * deactivate it.
d617b2
 	 */
d617b2
 	if (vg->lock_type && !strcmp(vg->lock_type, "sanlock") &&
d617b2
-	    (cmd->command->command_enum == vgchange_locktype_CMD))
d617b2
-		deactivate_lv(cmd, vg->sanlock_lv);
d617b2
+	    (cmd->command->command_enum == vgchange_locktype_CMD)) {
d617b2
+		if (!deactivate_lv(cmd, vg->sanlock_lv)) {
d617b2
+			log_error("Failed to deativate %s.",
d617b2
+				  display_lvname(vg->sanlock_lv));
d617b2
+			return ECMD_FAILED;
d617b2
+		}
d617b2
+	}
d617b2
 
d617b2
 	log_print_unless_silent("Volume group \"%s\" successfully changed", vg->name);
d617b2
 
d617b2
diff --git a/tools/vgimportclone.c b/tools/vgimportclone.c
d617b2
index be01861..ee1c28f 100644
d617b2
--- a/tools/vgimportclone.c
d617b2
+++ b/tools/vgimportclone.c
d617b2
@@ -315,6 +315,8 @@ retry_name:
d617b2
 		goto_out;
d617b2
 	log_debug("Using new VG name %s.", vp.new_vgname);
d617b2
 
d617b2
+	lvmcache_destroy(cmd, 1, 0);
d617b2
+
d617b2
 	/*
d617b2
 	 * Create a device filter so that we are only working with the devices
d617b2
 	 * in arg_import.  With the original devs hidden (that arg_import were
d617b2
@@ -325,7 +327,7 @@ retry_name:
d617b2
 	init_internal_filtering(1);
d617b2
 	dm_list_iterate_items(vd, &vp.arg_import)
d617b2
 		internal_filter_allow(cmd->mem, vd->dev);
d617b2
-	lvmcache_destroy(cmd, 1, 0);
d617b2
+	refresh_filters(cmd);
d617b2
 
d617b2
 	log_debug("Changing VG %s to %s.", vp.old_vgname, vp.new_vgname);
d617b2
 
d617b2
diff --git a/tools/vgmerge.c b/tools/vgmerge.c
d617b2
index 903504c..895018a 100644
d617b2
--- a/tools/vgmerge.c
d617b2
+++ b/tools/vgmerge.c
d617b2
@@ -21,10 +21,8 @@ static struct volume_group *_vgmerge_vg_read(struct cmd_context *cmd,
d617b2
 	struct volume_group *vg;
d617b2
 	log_verbose("Checking for volume group \"%s\"", vg_name);
d617b2
 	vg = vg_read_for_update(cmd, vg_name, NULL, 0, 0);
d617b2
-	if (vg_read_error(vg)) {
d617b2
-		release_vg(vg);
d617b2
+	if (!vg)
d617b2
 		return NULL;
d617b2
-	}
d617b2
 
d617b2
 	if (vg_is_shared(vg)) {
d617b2
 		log_error("vgmerge not allowed for lock_type %s", vg->lock_type);
d617b2
diff --git a/tools/vgrename.c b/tools/vgrename.c
d617b2
index 8b76d0b..f442f73 100644
d617b2
--- a/tools/vgrename.c
d617b2
+++ b/tools/vgrename.c
d617b2
@@ -183,7 +183,7 @@ int vgrename(struct cmd_context *cmd, int argc, char **argv)
d617b2
 	vg_name_new = skip_dev_dir(cmd, argv[1], NULL);
d617b2
 
d617b2
 	if (!validate_vg_rename_params(cmd, vg_name_old, vg_name_new))
d617b2
-		return_0;
d617b2
+		return_ECMD_FAILED;
d617b2
 
d617b2
 	if (!(vp.vg_name_old = dm_pool_strdup(cmd->mem, vg_name_old)))
d617b2
 		return_ECMD_FAILED;
d617b2
diff --git a/tools/vgsplit.c b/tools/vgsplit.c
d617b2
index 3dc19ec..1a422e6 100644
d617b2
--- a/tools/vgsplit.c
d617b2
+++ b/tools/vgsplit.c
d617b2
@@ -691,7 +691,7 @@ int vgsplit(struct cmd_context *cmd, int argc, char **argv)
d617b2
 
d617b2
 		vg_to = vg_read_for_update(cmd, vg_name_to, NULL, 0, 0);
d617b2
 
d617b2
-		if (vg_read_error(vg_to)) {
d617b2
+		if (!vg_to) {
d617b2
 			log_error("Volume group \"%s\" became inconsistent: "
d617b2
 				  "please fix manually", vg_name_to);
d617b2
 			goto bad;
d617b2
-- 
d617b2
1.8.3.1
d617b2