1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-02-24 17:57:48 +03:00

systemid: Allow empty systemid with warnings.

Add warning messages when empty system ID is set.
This commit is contained in:
Alasdair G Kergon 2015-02-25 14:12:24 +00:00
parent 7d615a3fe5
commit ac6a4cd707
3 changed files with 44 additions and 25 deletions

View File

@ -62,6 +62,11 @@ const char *system_id_from_string(struct cmd_context *cmd, const char *str)
{
char *system_id;
if (!str || !*str) {
log_warn("WARNING: Empty system ID supplied.");
return "";
}
if (!(system_id = dm_pool_zalloc(cmd->mem, strlen(str) + 1))) {
log_warn("WARNING: Failed to allocate system ID.");
return NULL;
@ -109,13 +114,13 @@ static const char *_read_system_id_from_file(struct cmd_context *cmd, const char
if (!*start || *start == '#')
continue;
if (system_id) {
if (system_id && *system_id) {
log_warn("WARNING: Ignoring extra line(s) in system ID file %s.", file);
break;
}
/* Remove any comments from end of line */
for (end = start; *end; start++)
for (end = start; *end; end++)
if (*end == '#') {
*end = '\0';
break;
@ -445,8 +450,10 @@ static int _init_system_id(struct cmd_context *cmd)
if (!strcmp(source, "none"))
return 1;
if ((cmd->system_id = _system_id_from_source(cmd, source)))
if ((system_id = _system_id_from_source(cmd, source)) && *system_id) {
cmd->system_id = system_id;
return 1;
}
/*
* The source failed to resolve a system_id. In this case allow

View File

@ -770,9 +770,13 @@ int vgcreate_params_set_from_args(struct cmd_context *cmd,
/* FIXME Take local/extra_system_ids into account */
if (vp_new->system_id && cmd->system_id &&
strcmp(vp_new->system_id, cmd->system_id))
log_warn("VG with system ID \"%s\" might become inaccessible as local system ID is \"%s\"",
vp_new->system_id, cmd->system_id);
strcmp(vp_new->system_id, cmd->system_id)) {
if (*vp_new->system_id)
log_warn("VG with system ID \"%s\" might become inaccessible as local system ID is \"%s\"",
vp_new->system_id, cmd->system_id);
else
log_warn("WARNING: A VG without a system ID allows concurrent access from other hosts.");
}
}
return 1;

View File

@ -494,36 +494,44 @@ static int _vgchange_system_id(struct cmd_context *cmd, struct volume_group *vg)
const char *system_id;
const char *system_id_arg_str = arg_str_value(cmd, systemid_ARG, NULL);
if (!system_id_arg_str || !*system_id_arg_str) {
log_error("Invalid system ID supplied: %s", system_id_arg_str);
if (!(system_id = system_id_from_string(cmd, system_id_arg_str))) {
log_error("Unable to set system ID.");
return 0;
}
if (!(system_id = system_id_from_string(cmd, system_id_arg_str)))
return_0;
if (!strcmp(vg->system_id, system_id)) {
log_error("Volume Group system ID is already \"%s\"", vg->system_id);
return 0;
}
if (cmd->system_id && strcmp(system_id, cmd->system_id)) {
if (lvs_in_vg_activated(vg)) {
log_error("Logical Volumes in VG %s must be deactivated before system ID can be changed.",
vg->name);
return 0;
}
if (!*system_id) {
log_warn("WARNING: Removing the system ID allows concurrent access from other hosts.");
log_warn("WARNING: Requested system ID \"%s\" does not match local system ID \"%s\"",
system_id, cmd->system_id);
log_warn("WARNING: Volume group %s might become inaccessible from this machine.",
vg->name);
if (!arg_count(cmd, yes_ARG) &&
yes_no_prompt("Remove system ID %s on volume group %s? [y/n]: ",
vg->system_id, vg->name) == 'n') {
log_error("Volume group \"%s\" system ID not changed.", vg->name);
return 0;
}
} else {
if (lvs_in_vg_activated(vg)) {
log_error("Logical Volumes in VG %s must be deactivated before system ID can be changed.",
vg->name);
return 0;
}
if (!arg_count(cmd, yes_ARG) &&
yes_no_prompt("Set foreign system ID %s on volume group %s? [y/n]: ",
system_id, vg->name) == 'n') {
log_error("Volume group \"%s\" system ID not changed.", vg->name);
return 0;
log_warn("WARNING: Requested system ID \"%s\" does not match local system ID \"%s\"",
system_id, cmd->system_id);
log_warn("WARNING: Volume group %s might become inaccessible from this machine.",
vg->name);
if (!arg_count(cmd, yes_ARG) &&
yes_no_prompt("Set foreign system ID %s on volume group %s? [y/n]: ",
system_id, vg->name) == 'n') {
log_error("Volume group \"%s\" system ID not changed.", vg->name);
return 0;
}
}
}