summaryrefslogtreecommitdiff
path: root/tools/vgchange.c
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2014-10-24 12:29:04 -0500
committerDavid Teigland <teigland@redhat.com>2015-02-11 11:35:04 -0600
commit35026b747866712106617eaf353aa5c0a61c4006 (patch)
tree58db0aa13911c1edb74782b5c6204a7dac822205 /tools/vgchange.c
parent263f7831df111a431a064d30b639e4769445f841 (diff)
downloadlvm2-35026b747866712106617eaf353aa5c0a61c4006.tar.gz
system_id: use for VG ownershipdev-dct-systemid-final1
See included lvmsystemid(7) for full description.
Diffstat (limited to 'tools/vgchange.c')
-rw-r--r--tools/vgchange.c65
1 files changed, 52 insertions, 13 deletions
diff --git a/tools/vgchange.c b/tools/vgchange.c
index e3f852b8d..d56b3df02 100644
--- a/tools/vgchange.c
+++ b/tools/vgchange.c
@@ -332,6 +332,11 @@ static int _vgchange_clustered(struct cmd_context *cmd,
}
}
+ if (clustered)
+ vg->system_id = NULL;
+ else if (cmd->system_id && cmd->system_id[0])
+ vg->system_id = dm_pool_strdup(cmd->mem, cmd->system_id);
+
if (!vg_set_clustered(vg, clustered))
return_0;
@@ -471,6 +476,38 @@ static int _vgchange_profile(struct cmd_context *cmd,
return 1;
}
+/*
+ * This function will not be called unless the local host is allowed to use the
+ * VG. Either the VG has no system_id, or the VG and host have matching
+ * system_ids, or the host has the VG's current system_id in its
+ * allow_system_id list. This function is not allowed to change the system_id
+ * of a foreign VG (VG owned by another host).
+ */
+
+static int _vgchange_system_id(struct cmd_context *cmd, struct volume_group *vg)
+{
+ const char *arg_str = arg_str_value(cmd, systemid_ARG, NULL);
+ char *system_id;
+
+ if (!arg_str)
+ return 0;
+
+ system_id = system_id_from_string(cmd, arg_str);
+
+ if (system_id && cmd->system_id && strcmp(system_id, cmd->system_id)) {
+ log_warn("VG \"%s\" system id \"%s\" does not match local system id \"%s\"",
+ vg->name, system_id, cmd->system_id);
+
+ if (yes_no_prompt("Change system id? [y/n]: ") == 'n') {
+ log_error("Volume group \"%s\" not changed.", vg->name);
+ return 0;
+ }
+ }
+
+ vg->system_id = system_id;
+ return 1;
+}
+
static int vgchange_single(struct cmd_context *cmd, const char *vg_name,
struct volume_group *vg,
struct processing_handle *handle __attribute__((unused)))
@@ -494,8 +531,9 @@ static int vgchange_single(struct cmd_context *cmd, const char *vg_name,
{ clustered_ARG, &_vgchange_clustered },
{ vgmetadatacopies_ARG, &_vgchange_metadata_copies },
{ metadataprofile_ARG, &_vgchange_profile },
- { profile_ARG, &_vgchange_profile},
- { detachprofile_ARG, &_vgchange_profile},
+ { profile_ARG, &_vgchange_profile },
+ { detachprofile_ARG, &_vgchange_profile },
+ { systemid_ARG, &_vgchange_system_id },
};
if (vg_is_exported(vg)) {
@@ -589,13 +627,19 @@ static int vgchange_single(struct cmd_context *cmd, const char *vg_name,
int vgchange(struct cmd_context *cmd, int argc, char **argv)
{
- /* Update commands that can be combined */
+ int noupdate =
+ arg_count(cmd, activate_ARG) ||
+ arg_count(cmd, monitor_ARG) ||
+ arg_count(cmd, poll_ARG) ||
+ arg_count(cmd, refresh_ARG);
+
int update_partial_safe =
arg_count(cmd, deltag_ARG) ||
arg_count(cmd, addtag_ARG) ||
arg_count(cmd, metadataprofile_ARG) ||
arg_count(cmd, profile_ARG) ||
arg_count(cmd, detachprofile_ARG);
+
int update_partial_unsafe =
arg_count(cmd, logicalvolume_ARG) ||
arg_count(cmd, maxphysicalvolumes_ARG) ||
@@ -604,18 +648,13 @@ int vgchange(struct cmd_context *cmd, int argc, char **argv)
arg_count(cmd, physicalextentsize_ARG) ||
arg_count(cmd, clustered_ARG) ||
arg_count(cmd, alloc_ARG) ||
- arg_count(cmd, vgmetadatacopies_ARG);
+ arg_count(cmd, vgmetadatacopies_ARG) ||
+ arg_count(cmd, systemid_ARG);
+
int update = update_partial_safe || update_partial_unsafe;
- if (!update &&
- !arg_count(cmd, activate_ARG) &&
- !arg_count(cmd, monitor_ARG) &&
- !arg_count(cmd, poll_ARG) &&
- !arg_count(cmd, refresh_ARG)) {
- log_error("Need 1 or more of -a, -c, -l, -p, -s, -x, "
- "--refresh, --uuid, --alloc, --addtag, --deltag, "
- "--monitor, --poll, --vgmetadatacopies or "
- "--metadatacopies");
+ if (!update && !noupdate) {
+ log_error("Need one or more command options.");
return EINVALID_CMD_LINE;
}