Skip to contentSkip to conversation

main - handle duplicate vgids

PATCH David Teigland 1 participant 1 message Jan 13, 2022

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=18f451e09e943eb3d51f8394f6fe8967e1e9f565
Commit:        18f451e09e943eb3d51f8394f6fe8967e1e9f565
Parent:        cb798ee1c102aadde93965a894c5aa59d4e76e4a
Author:        David Teigland <[email protected]>
AuthorDate:    Thu Jan 6 10:15:16 2022 -0600
Committer:     David Teigland <[email protected]>
CommitterDate: Thu Jan 13 10:01:24 2022 -0600

handle duplicate vgids

The approach to duplicate VGIDs has been that it is not possible or not allowed, so the behavior has been undefined. The actual result was unpredictable and/or broken, and generally unhelpful.

Improve this by recognizing the problem, displaying the VGs, and printing a warning to fix the problem. Beyond this, using VGs with duplicate VGIDs remains undefined, but should work well enough to correct the problem with vgchange -u.

It's possible to create this condition without too much difficulty by cloning PVs, followed by an incomplete attempt at making the two VGs unique (vgrename and pvchange -u, but missing vgchange -u.)

---
 lib/cache/lvmcache.c         | 20 +++++++++++++----
 test/shell/duplicate-vgid.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 4 deletions(-)
lib/cache/lvmcache.c +16 -4
index 6569f983d..22edcfd84 100644
@@ -354,9 +354,11 @@ static struct lvmcache_vginfo *_vginfo_lookup(const char *vgname, const char *vg
 	if (vgid_arg) {
 		if ((vginfo = dm_hash_lookup(_vgid_hash, vgid))) {
 			if (vgname && strcmp(vginfo->vgname, vgname)) {
-				/* should never happen */
-				log_error(INTERNAL_ERROR "vginfo_lookup vgid %s has two names %s %s",
-					  vgid, vginfo->vgname, vgname);
+				log_warn("WARNING: lookup found duplicate VGID %s for VGs %s and %s.", vgid, vginfo->vgname, vgname);
+				if ((vginfo = dm_hash_lookup(_vgname_hash, vgname))) {
+					if (!memcmp(vginfo->vgid, vgid, ID_LEN))
+						return vginfo;
+				}
 				return NULL;
 			}
 			return vginfo;
@@ -1884,7 +1886,17 @@ static int _lvmcache_update_vgname(struct cmd_context *cmd,
 
 	_drop_vginfo(info, info->vginfo);
 
-	if (!(vginfo = lvmcache_vginfo_from_vgid(vgid))) {
+	vginfo = lvmcache_vginfo_from_vgid(vgid);
+	if (vginfo && strcmp(vginfo->vgname, vgname)) {
+		log_warn("WARNING: fix duplicate VGID %s for VGs %s and %s (see vgchange -u).", vgid_dashed, vgname, vginfo->vgname);
+		vginfo = lvmcache_vginfo_from_vgname(vgname, NULL);
+		if (vginfo && memcmp(vginfo->vgid, vgid, ID_LEN)) {
+			log_error("Ignoring %s with conflicting VG info %s %s.", dev_name(info->dev), vgid_dashed, vgname);
+			return_0;
+		}
+	}
+
+	if (!vginfo) {
 		/*
 	 	 * Create a vginfo struct for this VG and put the vginfo
 	 	 * into the hash table.
test/shell/duplicate-vgid.sh new file +52 -0

52 lines not on this page · raw message