diff options
Diffstat (limited to 'tools/vgchange.c')
-rw-r--r-- | tools/vgchange.c | 84 |
1 files changed, 71 insertions, 13 deletions
diff --git a/tools/vgchange.c b/tools/vgchange.c index 9a9fe4866..7234bad69 100644 --- a/tools/vgchange.c +++ b/tools/vgchange.c @@ -336,6 +336,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; @@ -475,6 +480,52 @@ static int _vgchange_profile(struct cmd_context *cmd, return 1; } +static int _vgchange_system_id(struct cmd_context *cmd, struct volume_group *vg) +{ + const char *arg_str = arg_str_value(cmd, systemid_ARG, NULL); + const char *source = arg_str_value(cmd, systemidsource_ARG, NULL); + char *system_id; + + if (!arg_str && !source) + return 0; + + if (vg->system_id && vg->system_id[0] && !arg_is_set(cmd, force_ARG)) { + log_error("Volume group \"%s\" already has system id \"%s\"", + vg->name, vg->system_id); + return 0; + } + + if (arg_str) { + system_id = system_id_from_string(cmd, arg_str); + goto change; + } + + if (!strcmp(source, "none")) { + system_id = NULL; + goto change; + } + + if ((system_id = system_id_from_source(cmd, source))) + goto change; + + log_error("No system_id found from source %s", source); + return 0; + +change: + if (system_id && cmd->system_id && strcmp(system_id, cmd->system_id)) { + log_warn("VG \"%s\" system id \"%s\" will not be accessible to 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, void *handle __attribute__((unused))) @@ -498,8 +549,10 @@ 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 }, + { systemidsource_ARG, &_vgchange_system_id }, }; if (vg_is_exported(vg)) { @@ -593,13 +646,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) || @@ -608,18 +667,14 @@ 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) || + arg_count(cmd, systemidsource_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; } @@ -709,6 +764,9 @@ int vgchange(struct cmd_context *cmd, int argc, char **argv) if (!update || !update_partial_unsafe) cmd->handles_missing_pvs = 1; + if (arg_is_set(cmd, systemid_ARG) && arg_is_set(cmd, force_ARG)) + cmd->skip_systemid_check = 1; + return process_each_vg(cmd, argc, argv, update ? READ_FOR_UPDATE : 0, NULL, &vgchange_single); } |