1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-11 20:58:50 +03:00

lvmcache: unpair wrong PV devs and improve duplicate name warnings

After detecting that a VG has wrongly claimed a PV, unpair
the pv->dev setting.  This will cause the usual "missing PV"
message to appear for that VG.  Make this message, and some
others, clearer by using the VGID rather than the VG name
when there are multiple VGs with the same name.
This commit is contained in:
David Teigland 2025-03-06 10:02:29 -06:00
parent cff93e4d5c
commit 8efbffe086
2 changed files with 31 additions and 7 deletions

15
lib/cache/lvmcache.c vendored
View File

@ -1954,7 +1954,7 @@ static int _lvmcache_update_vgname(struct cmd_context *cmd,
log_warn("WARNING: VG name %s is used by VGs %s and %s.", log_warn("WARNING: VG name %s is used by VGs %s and %s.",
vgname, vgid_dashed, other_dashed); vgname, vgid_dashed, other_dashed);
log_warn("Fix duplicate VG names with vgrename uuid, a device filter, or system IDs."); log_warn("WARNING: fix duplicate VG names with vgrename uuid, or vgrename --devices");
} }
if (!vginfo_is_allowed && !other_is_allowed) { if (!vginfo_is_allowed && !other_is_allowed) {
@ -2342,8 +2342,17 @@ void lvmcache_update_vg_from_read(struct volume_group *vg, int *incorrect_pv_cla
*/ */
if (info->vginfo && !is_orphan_vg(info->vginfo->vgname) && if (info->vginfo && !is_orphan_vg(info->vginfo->vgname) &&
(strcmp(info->vginfo->vgname, vg->name) || memcmp(info->vginfo->vgid, &vg->id, ID_LEN))) { (strcmp(info->vginfo->vgname, vg->name) || memcmp(info->vginfo->vgid, &vg->id, ID_LEN))) {
log_warn("WARNING: PV %s %s belongs to VG %s, ignoring claim from VG %s.", char vgid_old[ID_LEN + 1] __attribute__((aligned(8))) = { 0 };
dev_name(info->dev), pvid, info->vginfo->vgname, vg->name); char vgid_new[ID_LEN + 1] __attribute__((aligned(8))) = { 0 };
memcpy(vgid_old, &vg->id, ID_LEN);
memcpy(vgid_new, info->vginfo->vgid, ID_LEN);
if (!strcmp(info->vginfo->vgname, vg->name))
log_warn("WARNING: PV %s %s belongs to VGID %s, ignoring claim from VGID %s (%s).",
dev_name(info->dev), pvid, vgid_new, vgid_old, vg->name);
else
log_warn("WARNING: PV %s %s belongs to VG %s, ignoring claim from VG %s.",
dev_name(info->dev), pvid, info->vginfo->vgname, vg->name);
pvl->pv->status |= WRONG_VG; pvl->pv->status |= WRONG_VG;
*incorrect_pv_claim = 1; *incorrect_pv_claim = 1;
continue; continue;

View File

@ -4663,6 +4663,7 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
struct format_instance_ctx fic; struct format_instance_ctx fic;
struct volume_group *vg, *vg_ret = NULL; struct volume_group *vg, *vg_ret = NULL;
struct metadata_area *mda, *mda2; struct metadata_area *mda, *mda2;
struct pv_list *pvl;
unsigned use_precommitted = precommitted; unsigned use_precommitted = precommitted;
struct device *mda_dev, *dev_ret = NULL; struct device *mda_dev, *dev_ret = NULL;
struct cached_vg_fmtdata *vg_fmtdata = NULL; /* Additional format-specific data about the vg */ struct cached_vg_fmtdata *vg_fmtdata = NULL; /* Additional format-specific data about the vg */
@ -4902,6 +4903,14 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
*/ */
lvmcache_update_vg_from_read(vg_ret, incorrect_pv_claim); lvmcache_update_vg_from_read(vg_ret, incorrect_pv_claim);
/* Undo set_pv_devices for PVs that are incorrectly claimed. */
if (incorrect_pv_claim) {
dm_list_iterate_items(pvl, &vg_ret->pvs) {
if (pvl->pv->status & WRONG_VG)
pvl->pv->dev = NULL;
}
}
/* /*
* lvmcache_update_vg identified outdated mdas that we read above that * lvmcache_update_vg identified outdated mdas that we read above that
* are not actually part of the VG. Remove those outdated mdas from * are not actually part of the VG. Remove those outdated mdas from
@ -4934,6 +4943,7 @@ struct volume_group *vg_read(struct cmd_context *cmd, const char *vg_name, const
int original_vgid_set = vgid ? 1 : 0; int original_vgid_set = vgid ? 1 : 0;
int writing = (vg_read_flags & READ_FOR_UPDATE); int writing = (vg_read_flags & READ_FOR_UPDATE);
int activating = (vg_read_flags & READ_FOR_ACTIVATE); int activating = (vg_read_flags & READ_FOR_ACTIVATE);
int is_duplicate_vgname;
int incorrect_pv_claim = 0; int incorrect_pv_claim = 0;
*error_flags = SUCCESS; *error_flags = SUCCESS;
@ -5010,11 +5020,13 @@ struct volume_group *vg_read(struct cmd_context *cmd, const char *vg_name, const
} }
} }
is_duplicate_vgname = lvmcache_has_duplicate_local_vgname(vgid, vg_name);
/* /*
* vgchange -ay (no vgname arg) will activate multiple local VGs with the same * vgchange -ay (no vgname arg) will activate multiple local VGs with the same
* name, but if the vgs have the same lv name, activating those lvs will fail. * name, but if the vgs have the same lv name, activating those lvs will fail.
*/ */
if (activating && original_vgid_set && lvmcache_has_duplicate_local_vgname(vgid, vg_name)) if (activating && original_vgid_set && is_duplicate_vgname)
log_warn("WARNING: activating multiple VGs with the same name is dangerous and may fail."); log_warn("WARNING: activating multiple VGs with the same name is dangerous and may fail.");
if (!(vg = _vg_read(cmd, vg_name, vgid, 0, writing, &incorrect_pv_claim))) { if (!(vg = _vg_read(cmd, vg_name, vgid, 0, writing, &incorrect_pv_claim))) {
@ -5066,11 +5078,14 @@ struct volume_group *vg_read(struct cmd_context *cmd, const char *vg_name, const
/* The obvious and common case of a missing device. */ /* The obvious and common case of a missing device. */
if ((vg_is_foreign(vg) && !cmd->include_foreign_vgs) || cmd->expect_missing_vg_device) if ((vg_is_foreign(vg) && !cmd->include_foreign_vgs) || cmd->expect_missing_vg_device)
log_debug("VG %s is missing PV %s (last written to %s)", vg_name, uuidstr, pvl->pv->device_hint ?: "na"); log_debug("VG %s is missing PV %s (last written to %s)",
is_duplicate_vgname ? vgid : vg_name, uuidstr, pvl->pv->device_hint ?: "na");
else if (pvl->pv->device_hint) else if (pvl->pv->device_hint)
log_warn("WARNING: VG %s is missing PV %s (last written to %s).", vg_name, uuidstr, pvl->pv->device_hint); log_warn("WARNING: VG %s is missing PV %s (last written to %s).",
is_duplicate_vgname ? vgid : vg_name, uuidstr, pvl->pv->device_hint);
else else
log_warn("WARNING: VG %s is missing PV %s.", vg_name, uuidstr); log_warn("WARNING: VG %s is missing PV %s.",
is_duplicate_vgname ? vgid : vg_name, uuidstr);
missing_pv_dev++; missing_pv_dev++;
} else if (pvl->pv->status & MISSING_PV) { } else if (pvl->pv->status & MISSING_PV) {