summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2022-07-07 16:06:01 -0500
committerDavid Teigland <teigland@redhat.com>2022-07-07 16:06:01 -0500
commit03653a0a570e94222eda49149e260cf1a8358bd1 (patch)
treef2c66fcf8bd12d7554bc19cbe14c481780491d3c
parentfc6330c1a85d8087cd44c975cb2592116a8122b8 (diff)
downloadlvm2-dev-dct-vgchange-majority.tar.gz
vgchange: allow changing system ID with majority of PVsdev-dct-vgchange-majority
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.
-rw-r--r--tools/args.h4
-rw-r--r--tools/command-lines.in1
-rw-r--r--tools/vgchange.c21
3 files changed, 26 insertions, 0 deletions
diff --git a/tools/args.h b/tools/args.h
index baae333e1..9ad53cadb 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -390,6 +390,10 @@ arg(logonly_ARG, '\0', "logonly", 0, 0, 0,
arg(longhelp_ARG, '\0', "longhelp", 0, 0, 0,
"Display long help text.\n")
+arg(majoritypvs_ARG, '\0', "majoritypvs", 0, 0, 0,
+ "Change the VG system ID if the majority of PVs in the VG\n"
+ "are present (one more than half).\n")
+
arg(maxrecoveryrate_ARG, '\0', "maxrecoveryrate", sizekb_VAL, 0, 0,
"Sets the maximum recovery rate for a RAID LV. The rate value\n"
"is an amount of data per second for each device in the array.\n"
diff --git a/tools/command-lines.in b/tools/command-lines.in
index b6a03d158..fd69f7420 100644
--- a/tools/command-lines.in
+++ b/tools/command-lines.in
@@ -1766,6 +1766,7 @@ ID: vgchange_refresh
DESC: Reactivate LVs using the latest metadata.
vgchange --systemid String VG
+OO: --majoritypvs
ID: vgchange_systemid
DESC: Change the system ID of a VG.
diff --git a/tools/vgchange.c b/tools/vgchange.c
index ea22bada0..3f622fc65 100644
--- a/tools/vgchange.c
+++ b/tools/vgchange.c
@@ -1344,6 +1344,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;
@@ -1376,6 +1394,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);