1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

systemid: Extend --foreign to reporting commands.

Add --foreign to the remaining reporting and display commands plus
vgcfgbackup.
Add a NEEDS_FOREIGN_VGS flag for vgimport to always set --foreign.
If lvmetad is being used with --foreign, scan foreign VGs (currently
implemented as a full PV scan).
Handle these things centrally in lvmcmdline.c.
Also allow lvchange and vgchange -an/-aln to deactivate any foreign
LVs that happen to be active if something went wrong.
Remember to set the system ID when creating a new VG in vgsplit.
This commit is contained in:
Alasdair G Kergon 2015-02-23 23:41:38 +00:00
parent b18feb98e5
commit 5793ecd165
9 changed files with 56 additions and 39 deletions

View File

@ -1,5 +1,7 @@
Version 2.02.117 - Version 2.02.117 -
==================================== ====================================
Add NEEDS_FOREIGN_VGS flag to vgimport so --foreign is always supplied.
Add --foreign to the 6 display and reporting tools and vgcfgbackup.
Install /etc/lvm/lvmlocal.conf template with local section for systemid. Install /etc/lvm/lvmlocal.conf template with local section for systemid.
Record creation_host_system_id in lvm2 metadata. Record creation_host_system_id in lvm2 metadata.
Reinstate recursive config file tag section processing. (2.02.99) Reinstate recursive config file tag section processing. (2.02.99)
@ -7,6 +9,8 @@ Version 2.02.117 -
Fix configure to properly recognize --with-default-raid10-segtype option. Fix configure to properly recognize --with-default-raid10-segtype option.
Do not refresh filters/rescan if no signature is wiped during pvcreate. Do not refresh filters/rescan if no signature is wiped during pvcreate.
Enforce none external dev info for wiping during pvcreate to avoid races. Enforce none external dev info for wiping during pvcreate to avoid races.
Add global/system_id_source and system_id_file to lvm.conf.
Add --systemid to vgcreate and vchange to set / change a system ID.
Add support for VG system_id to control host access to VGs. Add support for VG system_id to control host access to VGs.
Update vgextend to use process_each_vg. Update vgextend to use process_each_vg.
Add --ignoreskippedcluster to pvchange. Add --ignoreskippedcluster to pvchange.

View File

@ -362,6 +362,7 @@ xx(lvdisplay,
"\t[-c|--colon]\n" "\t[-c|--colon]\n"
"\t[--commandprofile ProfileName]\n" "\t[--commandprofile ProfileName]\n"
"\t[-d|--debug]\n" "\t[-d|--debug]\n"
"\t[--foreign]\n"
"\t[-h|--help]\n" "\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n" "\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n" "\t[--ignoreskippedcluster]\n"
@ -381,6 +382,7 @@ xx(lvdisplay,
"\t[--binary]\n" "\t[--binary]\n"
"\t[--commandprofile ProfileName]\n" "\t[--commandprofile ProfileName]\n"
"\t[-d|--debug]\n" "\t[-d|--debug]\n"
"\t[--foreign]\n"
"\t[-h|--help]\n" "\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n" "\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n" "\t[--ignoreskippedcluster]\n"
@ -399,7 +401,7 @@ xx(lvdisplay,
"\t[--version]\n" "\t[--version]\n"
"\t[LogicalVolume[Path] [LogicalVolume[Path]...]]\n", "\t[LogicalVolume[Path] [LogicalVolume[Path]...]]\n",
aligned_ARG, all_ARG, binary_ARG, colon_ARG, columns_ARG, aligned_ARG, all_ARG, binary_ARG, colon_ARG, columns_ARG, foreign_ARG,
ignorelockingfailure_ARG, ignoreskippedcluster_ARG, maps_ARG, ignorelockingfailure_ARG, ignoreskippedcluster_ARG, maps_ARG,
noheadings_ARG, nosuffix_ARG, options_ARG, sort_ARG, partial_ARG, noheadings_ARG, nosuffix_ARG, options_ARG, sort_ARG, partial_ARG,
readonly_ARG, segments_ARG, select_ARG, separator_ARG, readonly_ARG, segments_ARG, select_ARG, separator_ARG,
@ -583,6 +585,7 @@ xx(lvs,
"\t[--binary]\n" "\t[--binary]\n"
"\t[--commandprofile ProfileName]\n" "\t[--commandprofile ProfileName]\n"
"\t[-d|--debug]\n" "\t[-d|--debug]\n"
"\t[--foreign]\n"
"\t[-h|--help]\n" "\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n" "\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n" "\t[--ignoreskippedcluster]\n"
@ -605,7 +608,7 @@ xx(lvs,
"\t[--version]\n" "\t[--version]\n"
"\t[LogicalVolume[Path] [LogicalVolume[Path]...]]\n", "\t[LogicalVolume[Path] [LogicalVolume[Path]...]]\n",
aligned_ARG, all_ARG, binary_ARG, ignorelockingfailure_ARG, aligned_ARG, all_ARG, binary_ARG, foreign_ARG, ignorelockingfailure_ARG,
ignoreskippedcluster_ARG, nameprefixes_ARG, noheadings_ARG, ignoreskippedcluster_ARG, nameprefixes_ARG, noheadings_ARG,
nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG,
readonly_ARG, rows_ARG, segments_ARG, select_ARG, separator_ARG, readonly_ARG, rows_ARG, segments_ARG, select_ARG, separator_ARG,
@ -744,6 +747,7 @@ xx(pvdisplay,
"\t[-c|--colon]\n" "\t[-c|--colon]\n"
"\t[--commandprofile ProfileName]\n" "\t[--commandprofile ProfileName]\n"
"\t[-d|--debug]\n" "\t[-d|--debug]\n"
"\t[--foreign]\n"
"\t[-h|--help]\n" "\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n" "\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n" "\t[--ignoreskippedcluster]\n"
@ -763,6 +767,7 @@ xx(pvdisplay,
"\t[--binary]\n" "\t[--binary]\n"
"\t[--commandprofile ProfileName]\n" "\t[--commandprofile ProfileName]\n"
"\t[-d|--debug]\n" "\t[-d|--debug]\n"
"\t[--foreign]\n"
"\t[-h|--help]\n" "\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n" "\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n" "\t[--ignoreskippedcluster]\n"
@ -779,7 +784,7 @@ xx(pvdisplay,
"\t[--version]\n" "\t[--version]\n"
"\t[PhysicalVolumePath [PhysicalVolumePath...]]\n", "\t[PhysicalVolumePath [PhysicalVolumePath...]]\n",
aligned_ARG, all_ARG, binary_ARG, colon_ARG, columns_ARG, aligned_ARG, all_ARG, binary_ARG, colon_ARG, columns_ARG, foreign_ARG,
ignorelockingfailure_ARG, ignoreskippedcluster_ARG, maps_ARG, ignorelockingfailure_ARG, ignoreskippedcluster_ARG, maps_ARG,
noheadings_ARG, nosuffix_ARG, options_ARG, readonly_ARG, noheadings_ARG, nosuffix_ARG, options_ARG, readonly_ARG,
select_ARG, separator_ARG, short_ARG, sort_ARG, unbuffered_ARG, select_ARG, separator_ARG, short_ARG, sort_ARG, unbuffered_ARG,
@ -835,6 +840,7 @@ xx(pvs,
"\t[--binary]\n" "\t[--binary]\n"
"\t[--commandprofile ProfileName]\n" "\t[--commandprofile ProfileName]\n"
"\t[-d|--debug]\n" "\t[-d|--debug]\n"
"\t[--foreign]\n"
"\t[-h|-?|--help]\n" "\t[-h|-?|--help]\n"
"\t[--ignorelockingfailure]\n" "\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n" "\t[--ignoreskippedcluster]\n"
@ -857,7 +863,7 @@ xx(pvs,
"\t[--version]\n" "\t[--version]\n"
"\t[PhysicalVolume [PhysicalVolume...]]\n", "\t[PhysicalVolume [PhysicalVolume...]]\n",
aligned_ARG, all_ARG, binary_ARG, ignorelockingfailure_ARG, aligned_ARG, all_ARG, binary_ARG, foreign_ARG, ignorelockingfailure_ARG,
ignoreskippedcluster_ARG, nameprefixes_ARG, noheadings_ARG, nolocking_ARG, ignoreskippedcluster_ARG, nameprefixes_ARG, noheadings_ARG, nolocking_ARG,
nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG, rows_ARG, nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG, rows_ARG,
segments_ARG, select_ARG, separator_ARG, sort_ARG, trustcache_ARG, segments_ARG, select_ARG, separator_ARG, sort_ARG, trustcache_ARG,
@ -907,6 +913,7 @@ xx(vgcfgbackup,
"\t[--commandprofile ProfileName]\n" "\t[--commandprofile ProfileName]\n"
"\t[-d|--debug]\n" "\t[-d|--debug]\n"
"\t[-f|--file filename]\n" "\t[-f|--file filename]\n"
"\t[--foreign]\n"
"\t[-h|-?|--help]\n" "\t[-h|-?|--help]\n"
"\t[--ignorelockingfailure]\n" "\t[--ignorelockingfailure]\n"
"\t[-P|--partial]\n" "\t[-P|--partial]\n"
@ -915,7 +922,7 @@ xx(vgcfgbackup,
"\t[--version]\n" "\t[--version]\n"
"\t[VolumeGroupName...]\n", "\t[VolumeGroupName...]\n",
file_ARG, ignorelockingfailure_ARG, partial_ARG, readonly_ARG) file_ARG, foreign_ARG, ignorelockingfailure_ARG, partial_ARG, readonly_ARG)
xx(vgcfgrestore, xx(vgcfgrestore,
"Restore volume group configuration", "Restore volume group configuration",
@ -955,11 +962,10 @@ xx(vgchange,
"\t[--[vg]metadatacopies #copies]\n" "\t[--[vg]metadatacopies #copies]\n"
"\t[--poll {y|n}]\n" "\t[--poll {y|n}]\n"
"\t[--noudevsync]\n" "\t[--noudevsync]\n"
"\t[--systemid SystemID]\n"
"\t[--refresh]\n" "\t[--refresh]\n"
"\t[-S|--select Selection]\n" "\t[-S|--select Selection]\n"
"\t[--systemid SystemID]\n"
"\t[--sysinit]\n" "\t[--sysinit]\n"
"\t[--systemid SystemID]\n"
"\t[-t|--test]\n" "\t[-t|--test]\n"
"\t[-u|--uuid]\n" "\t[-u|--uuid]\n"
"\t[-v|--verbose]\n" "\t[-v|--verbose]\n"
@ -1033,6 +1039,7 @@ xx(vgcreate,
"\t[--[vg]metadatacopies #copies]\n" "\t[--[vg]metadatacopies #copies]\n"
"\t[-p|--maxphysicalvolumes MaxPhysicalVolumes]\n" "\t[-p|--maxphysicalvolumes MaxPhysicalVolumes]\n"
"\t[-s|--physicalextentsize PhysicalExtentSize[bBsSkKmMgGtTpPeE]]\n" "\t[-s|--physicalextentsize PhysicalExtentSize[bBsSkKmMgGtTpPeE]]\n"
"\t[--systemid SystemID]\n"
"\t[-t|--test]\n" "\t[-t|--test]\n"
"\t[-v|--verbose]\n" "\t[-v|--verbose]\n"
"\t[--version]\n" "\t[--version]\n"
@ -1055,6 +1062,7 @@ xx(vgdisplay,
"\t[-c|--colon | -s|--short | -v|--verbose]\n" "\t[-c|--colon | -s|--short | -v|--verbose]\n"
"\t[--commandprofile ProfileName]\n" "\t[--commandprofile ProfileName]\n"
"\t[-d|--debug]\n" "\t[-d|--debug]\n"
"\t[--foreign]\n"
"\t[-h|--help]\n" "\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n" "\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n" "\t[--ignoreskippedcluster]\n"
@ -1071,6 +1079,7 @@ xx(vgdisplay,
"\t[--binary]\n" "\t[--binary]\n"
"\t[--commandprofile ProfileName]\n" "\t[--commandprofile ProfileName]\n"
"\t[-d|--debug]\n" "\t[-d|--debug]\n"
"\t[--foreign]\n"
"\t[-h|--help]\n" "\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n" "\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n" "\t[--ignoreskippedcluster]\n"
@ -1089,9 +1098,9 @@ xx(vgdisplay,
"\t[VolumeGroupName [VolumeGroupName...]]\n", "\t[VolumeGroupName [VolumeGroupName...]]\n",
activevolumegroups_ARG, aligned_ARG, binary_ARG, colon_ARG, columns_ARG, activevolumegroups_ARG, aligned_ARG, binary_ARG, colon_ARG, columns_ARG,
ignorelockingfailure_ARG, ignoreskippedcluster_ARG, noheadings_ARG, foreign_ARG, ignorelockingfailure_ARG, ignoreskippedcluster_ARG,
nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG, select_ARG, noheadings_ARG, nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG,
short_ARG, separator_ARG, sort_ARG, unbuffered_ARG, units_ARG) select_ARG, short_ARG, separator_ARG, sort_ARG, unbuffered_ARG, units_ARG)
xx(vgexport, xx(vgexport,
"Unregister volume group(s) from the system", "Unregister volume group(s) from the system",
@ -1133,7 +1142,7 @@ xx(vgextend,
xx(vgimport, xx(vgimport,
"Register exported volume group with system", "Register exported volume group with system",
ALL_VGS_IS_DEFAULT, ALL_VGS_IS_DEFAULT | NEEDS_FOREIGN_VGS,
"vgimport\n" "vgimport\n"
"\t[-a|--all]\n" "\t[-a|--all]\n"
"\t[--commandprofile ProfileName]\n" "\t[--commandprofile ProfileName]\n"
@ -1242,6 +1251,7 @@ xx(vgs,
"\t[-a|--all]\n" "\t[-a|--all]\n"
"\t[--commandprofile ProfileName]\n" "\t[--commandprofile ProfileName]\n"
"\t[-d|--debug]\n" "\t[-d|--debug]\n"
"\t[--foreign]\n"
"\t[-h|--help]\n" "\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n" "\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n" "\t[--ignoreskippedcluster]\n"
@ -1263,11 +1273,11 @@ xx(vgs,
"\t[--version]\n" "\t[--version]\n"
"\t[VolumeGroupName [VolumeGroupName...]]\n", "\t[VolumeGroupName [VolumeGroupName...]]\n",
aligned_ARG, all_ARG, binary_ARG, ignorelockingfailure_ARG, aligned_ARG, all_ARG, binary_ARG, foreign_ARG, ignorelockingfailure_ARG,
ignoreskippedcluster_ARG, nameprefixes_ARG, noheadings_ARG, ignoreskippedcluster_ARG, nameprefixes_ARG, noheadings_ARG,
nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG,
readonly_ARG, rows_ARG, select_ARG, separator_ARG, sort_ARG, readonly_ARG, rows_ARG, select_ARG, separator_ARG, sort_ARG,
trustcache_ARG, unbuffered_ARG, units_ARG, unquoted_ARG, foreign_ARG) trustcache_ARG, unbuffered_ARG, units_ARG, unquoted_ARG)
xx(vgscan, xx(vgscan,
"Search for all volume groups", "Search for all volume groups",

View File

@ -1178,6 +1178,11 @@ int lvchange(struct cmd_context *cmd, int argc, char **argv)
return EINVALID_CMD_LINE; return EINVALID_CMD_LINE;
} }
if (!update && !arg_count(cmd, refresh_ARG) && !arg_count(cmd, monitor_ARG) && !arg_count(cmd, poll_ARG) &&
arg_count(cmd, activate_ARG) &&
!is_change_activating((activation_change_t) arg_uint_value(cmd, activate_ARG, CHANGE_AY)))
cmd->include_foreign_vgs = 1;
/* /*
* If --sysinit -aay is used and at the same time lvmetad is used, * If --sysinit -aay is used and at the same time lvmetad is used,
* we want to rely on autoactivation to take place. Also, we * we want to rely on autoactivation to take place. Also, we

View File

@ -1074,7 +1074,9 @@ static int _get_settings(struct cmd_context *cmd)
else else
init_ignorelockingfailure(0); init_ignorelockingfailure(0);
cmd->ignore_clustered_vgs = arg_count(cmd, ignoreskippedcluster_ARG) ? 1 : 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;
if (!arg_count(cmd, sysinit_ARG)) if (!arg_count(cmd, sysinit_ARG))
lvmetad_connect_or_warn(); lvmetad_connect_or_warn();
@ -1500,6 +1502,19 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
goto_out; goto_out;
} }
/*
* Other hosts might have changed foreign VGs so enforce a rescan
* before processing any command using them.
*/
if (cmd->include_foreign_vgs && lvmetad_used() &&
!lvmetad_pvscan_foreign_vgs(cmd, NULL)) {
log_error("Failed to scan devices.");
return ECMD_FAILED;
}
/*
* FIXME Break up into multiple functions.
*/
ret = cmd->command->fn(cmd, argc, argv); ret = cmd->command->fn(cmd, argc, argv);
fin_locking(); fin_locking();

View File

@ -581,16 +581,6 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
int lv_info_needed, lv_segment_status_needed; int lv_info_needed, lv_segment_status_needed;
int lock_global = 0; int lock_global = 0;
/*
* When reporting foreign VGs we want to refresh our cached
* copy of them, since other hosts have probably made changes
* to their own VGs. We also want to override the default
* behavior which skips over foreign VGs.
*/
cmd->include_foreign_vgs = arg_is_set(cmd, foreign_ARG);
if (cmd->include_foreign_vgs && lvmetad_used())
lvmetad_pvscan_all_devs(cmd, NULL);
aligned = find_config_tree_bool(cmd, report_aligned_CFG, NULL); aligned = find_config_tree_bool(cmd, report_aligned_CFG, NULL);
buffered = find_config_tree_bool(cmd, report_buffered_CFG, NULL); buffered = find_config_tree_bool(cmd, report_buffered_CFG, NULL);
headings = find_config_tree_bool(cmd, report_headings_CFG, NULL); headings = find_config_tree_bool(cmd, report_headings_CFG, NULL);

View File

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

View File

@ -124,8 +124,9 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
backup(vg); backup(vg);
log_print_unless_silent("%s%colume group \"%s\" successfully created", log_print_unless_silent("%s%colume group \"%s\" successfully created%s%s",
clustered_message, *clustered_message ? 'v' : 'V', vg->name); clustered_message, *clustered_message ? 'v' : 'V', vg->name,
vg->system_id ? " with system ID " : "", vg->system_id ? : "");
release_vg(vg); release_vg(vg);
return ECMD_PROCESSED; return ECMD_PROCESSED;

View File

@ -15,7 +15,7 @@
#include "tools.h" #include "tools.h"
static int vgimport_single(struct cmd_context *cmd __attribute__((unused)), static int vgimport_single(struct cmd_context *cmd,
const char *vg_name, const char *vg_name,
struct volume_group *vg, struct volume_group *vg,
struct processing_handle *handle __attribute__((unused))) struct processing_handle *handle __attribute__((unused)))
@ -37,7 +37,7 @@ static int vgimport_single(struct cmd_context *cmd __attribute__((unused)),
goto_bad; goto_bad;
vg->status &= ~EXPORTED_VG; vg->status &= ~EXPORTED_VG;
vg->system_id = cmd->system_id ? dm_pool_strdup(cmd->mem, cmd->system_id) : NULL; vg->system_id = cmd->system_id ? dm_pool_strdup(vg->vgmem, cmd->system_id) : NULL;
dm_list_iterate_items(pvl, &vg->pvs) { dm_list_iterate_items(pvl, &vg->pvs) {
pv = pvl->pv; pv = pvl->pv;
@ -85,17 +85,6 @@ int vgimport(struct cmd_context *cmd, int argc, char **argv)
cmd->handles_missing_pvs = 1; 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, return process_each_vg(cmd, argc, argv,
READ_FOR_UPDATE | READ_ALLOW_EXPORTED, READ_FOR_UPDATE | READ_ALLOW_EXPORTED,
NULL, NULL,

View File

@ -570,6 +570,7 @@ int vgsplit(struct cmd_context *cmd, int argc, char **argv)
!vg_set_max_pv(vg_to, vp_new.max_pv) || !vg_set_max_pv(vg_to, vp_new.max_pv) ||
!vg_set_alloc_policy(vg_to, vp_new.alloc) || !vg_set_alloc_policy(vg_to, vp_new.alloc) ||
!vg_set_clustered(vg_to, vp_new.clustered) || !vg_set_clustered(vg_to, vp_new.clustered) ||
!vg_set_system_id(vg_to, vp_new.system_id) ||
!vg_set_mda_copies(vg_to, vp_new.vgmetadatacopies)) !vg_set_mda_copies(vg_to, vp_new.vgmetadatacopies))
goto_bad; goto_bad;
} }