1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-28 02:50:41 +03:00

systemid: silently ignore foreign vgs unless named

A foreign VG should be silently ignored by a reporting/display
command like 'vgs'.  If the reporting/display command specifies
a foreign VG by name on the command line, it should produce an
error message.

Scanning commands pvscan/vgscan/lvscan are always allowed to
read and update caches from all PVs, including those that belong
to foreign VGs.

Other non-report/display/scan commands always ignore a foreign
VG, or report an error if they attempt to use a foreign VG.

vgimport should always invalidate the lvmetad cache because
lvmetad likely holds a pre-vgexported copy of the VG.
(This is unrelated to using foreign VGs; the pre-vgexported
VG may have had no system_id at all.)
This commit is contained in:
David Teigland 2015-02-25 10:44:42 -06:00
parent 4ff9abd01f
commit 8668a9e81c
6 changed files with 40 additions and 17 deletions

View File

@ -98,6 +98,7 @@ struct cmd_context {
unsigned independent_metadata_areas:1; /* Active formats have MDAs outside PVs */
unsigned unknown_system_id:1;
unsigned include_foreign_vgs:1;
unsigned error_foreign_vgs:1;
struct dev_types *dev_types;

View File

@ -4430,8 +4430,19 @@ static int _access_vg_systemid(struct cmd_context *cmd, struct volume_group *vg)
return 0;
}
log_error("Cannot access VG %s with system id \"%s\" with local system ID %s.",
vg->name, vg->system_id, cmd->system_id);
/*
* Some commands always produce an error when accessing foreign VG.
*/
if (cmd->error_foreign_vgs) {
log_error("Cannot access VG %s with system id \"%s\" with local system ID %s.",
vg->name, vg->system_id, cmd->system_id);
return 0;
}
/*
* When include_foreign_vgs is 0 and error_foreign_vgs is 0,
* the result is to silently ignore foreign vgs.
*/
return 0;
}

View File

@ -356,7 +356,7 @@ xx(lvcreate,
xx(lvdisplay,
"Display information about a logical volume",
PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT,
PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT | ENABLE_FOREIGN_VGS,
"lvdisplay\n"
"\t[-a|--all]\n"
"\t[-c|--colon]\n"
@ -578,7 +578,7 @@ xx(lvresize,
xx(lvs,
"Display information about logical volumes",
PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT,
PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT | ENABLE_FOREIGN_VGS,
"lvs\n"
"\t[-a|--all]\n"
"\t[--aligned]\n"
@ -616,7 +616,7 @@ xx(lvs,
xx(lvscan,
"List all logical volumes in all volume groups",
PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT,
PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT | ENABLE_FOREIGN_VGS,
"lvscan\n"
"\t[-a|--all]\n"
"\t[-b|--blockdevice]\n"
@ -742,7 +742,7 @@ xx(pvdata,
xx(pvdisplay,
"Display various attributes of physical volume(s)",
CACHE_VGMETADATA | PERMITTED_READ_ONLY | ENABLE_ALL_DEVS,
CACHE_VGMETADATA | PERMITTED_READ_ONLY | ENABLE_ALL_DEVS | ENABLE_FOREIGN_VGS,
"pvdisplay\n"
"\t[-c|--colon]\n"
"\t[--commandprofile ProfileName]\n"
@ -833,7 +833,7 @@ xx(pvremove,
xx(pvs,
"Display information about physical volumes",
CACHE_VGMETADATA | PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT | ENABLE_ALL_DEVS,
CACHE_VGMETADATA | PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT | ENABLE_ALL_DEVS | ENABLE_FOREIGN_VGS,
"pvs\n"
"\t[-a|--all]\n"
"\t[--aligned]\n"
@ -871,7 +871,7 @@ xx(pvs,
xx(pvscan,
"List all physical volumes",
PERMITTED_READ_ONLY,
PERMITTED_READ_ONLY | ENABLE_FOREIGN_VGS,
"pvscan\n"
"\t[-b|--background]\n"
"\t[--cache [-a|--activate ay] [ DevicePath | -j|--major major --minor minor]...]\n"
@ -1056,7 +1056,7 @@ xx(vgcreate,
xx(vgdisplay,
"Display volume group information",
PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT,
PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT | ENABLE_FOREIGN_VGS,
"vgdisplay\n"
"\t[-A|--activevolumegroups]\n"
"\t[-c|--colon | -s|--short | -v|--verbose]\n"
@ -1142,7 +1142,7 @@ xx(vgextend,
xx(vgimport,
"Register exported volume group with system",
ALL_VGS_IS_DEFAULT | NEEDS_FOREIGN_VGS,
ALL_VGS_IS_DEFAULT,
"vgimport\n"
"\t[-a|--all]\n"
"\t[--commandprofile ProfileName]\n"
@ -1244,7 +1244,7 @@ xx(vgrename,
xx(vgs,
"Display information about volume groups",
PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT,
PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT | ENABLE_FOREIGN_VGS,
"vgs\n"
"\t[--aligned]\n"
"\t[--binary]\n"
@ -1281,7 +1281,7 @@ xx(vgs,
xx(vgscan,
"Search for all volume groups",
PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT,
PERMITTED_READ_ONLY | ALL_VGS_IS_DEFAULT | ENABLE_FOREIGN_VGS,
"vgscan "
"\t[--cache]\n"
"\t[--commandprofile ProfileName]\n"

View File

@ -1075,9 +1075,9 @@ static int _get_settings(struct cmd_context *cmd)
init_ignorelockingfailure(0);
cmd->ignore_clustered_vgs = arg_is_set(cmd, ignoreskippedcluster_ARG);
cmd->include_foreign_vgs =
((cmd->command->flags & NEEDS_FOREIGN_VGS) || arg_is_set(cmd, foreign_ARG)) ? 1 : 0;
cmd->error_foreign_vgs = cmd->command->flags & ENABLE_FOREIGN_VGS ? 0 : 1;
cmd->include_foreign_vgs = arg_is_set(cmd, foreign_ARG) ? 1 : 0;
if (!arg_count(cmd, sysinit_ARG))
lvmetad_connect_or_warn();

View File

@ -108,8 +108,8 @@ struct arg_value_group_list {
#define ENABLE_ALL_DEVS 0x00000008
/* Exactly one VG name argument required. */
#define ONE_VGNAME_ARG 0x00000010
/* Processes foreign VGs by default */
#define NEEDS_FOREIGN_VGS 0x00000020
/* Command is allowed to read foreign VGs. */
#define ENABLE_FOREIGN_VGS 0x00000020
/* a register of the lvm commands */
struct command {

View File

@ -85,6 +85,17 @@ int vgimport(struct cmd_context *cmd, int argc, char **argv)
cmd->handles_missing_pvs = 1;
}
/*
* Rescan devices and update lvmetad. lvmetad may hold a copy of the
* VG from before it was exported, if it was exported by another host.
* We need to reread it to see that it's been exported before we can
* import it.
*/
if (lvmetad_used() && !lvmetad_pvscan_all_devs(cmd, NULL)) {
log_error("Failed to scan devices.");
return ECMD_FAILED;
}
return process_each_vg(cmd, argc, argv,
READ_FOR_UPDATE | READ_ALLOW_EXPORTED,
NULL,