summaryrefslogtreecommitdiff
path: root/tools/vgchange.c
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2022-07-07 16:06:01 -0500
committerDavid Teigland <teigland@redhat.com>2023-03-08 16:30:54 -0600
commitaa85ed1784b2b8e731ac7bd05a8988bac30405f0 (patch)
treef7976e12869c1bacb65bed4d626498ef38f460bb /tools/vgchange.c
parentda44f2b6fe1e0edbd3ee875c831f3e467f242bc0 (diff)
downloadlvm2-aa85ed1784b2b8e731ac7bd05a8988bac30405f0.tar.gz
vgchange: allow changing system ID with majority of PVs
when used with --majoritypvs. This allows the fail-over of a VG between systems by changing the VG system ID when a PV is missing.
Diffstat (limited to 'tools/vgchange.c')
-rw-r--r--tools/vgchange.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/tools/vgchange.c b/tools/vgchange.c
index 09ade96a6..f07b245bd 100644
--- a/tools/vgchange.c
+++ b/tools/vgchange.c
@@ -1383,6 +1383,24 @@ static int _vgchange_systemid_single(struct cmd_context *cmd, const char *vg_nam
struct volume_group *vg,
struct processing_handle *handle)
{
+ if (arg_is_set(cmd, majoritypvs_ARG)) {
+ struct pv_list *pvl;
+ int missing_pvs = 0;
+ int found_pvs = 0;
+
+ dm_list_iterate_items(pvl, &vg->pvs) {
+ if (!pvl->pv->dev)
+ missing_pvs++;
+ else
+ found_pvs++;
+ }
+ if (found_pvs <= missing_pvs) {
+ log_error("Cannot change system ID without the majority of PVs (found %d of %d)",
+ found_pvs, found_pvs+missing_pvs);
+ return ECMD_FAILED;
+ }
+ }
+
if (!_vgchange_system_id(cmd, vg))
return_ECMD_FAILED;
@@ -1415,6 +1433,9 @@ int vgchange_systemid_cmd(struct cmd_context *cmd, int argc, char **argv)
return ECMD_FAILED;
}
+ if (arg_is_set(cmd, majoritypvs_ARG))
+ cmd->handles_missing_pvs = 1;
+
ret = process_each_vg(cmd, argc, argv, NULL, NULL, READ_FOR_UPDATE, 0, handle, &_vgchange_systemid_single);
destroy_processing_handle(cmd, handle);