master - systemid: Extend --foreign to reporting commands.
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=5793ecd1654196...
Commit: 5793ecd16541961ebb91239395dc82504ad31906
Parent: b18feb98e50093d66f03ff63120b6a0f14d7fddd
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Mon Feb 23 23:41:38 2015 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Mon Feb 23 23:41:38 2015 +0000
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.
---
WHATS_NEW | 4 ++++
tools/commands.h | 36 +++++++++++++++++++++++-------------
tools/lvchange.c | 5 +++++
tools/lvmcmdline.c | 17 ++++++++++++++++-
tools/reporter.c | 10 ----------
tools/tools.h | 2 ++
tools/vgcreate.c | 5 +++--
tools/vgimport.c | 15 ++-------------
tools/vgsplit.c | 1 +
9 files changed, 56 insertions(+), 39 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 983189c..6220398 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,7 @@
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.
Record creation_host_system_id in lvm2 metadata.
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.
Do not refresh filters/rescan if no signature is wiped during pvcreate.
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.
Update vgextend to use process_each_vg.
Add --ignoreskippedcluster to pvchange.
diff --git a/tools/commands.h b/tools/commands.h
index 05ee186..00708f6 100644
--- a/tools/commands.h
+++ b/tools/commands.h
@@ -362,6 +362,7 @@ xx(lvdisplay,
"\t[-c|--colon]\n"
"\t[--commandprofile ProfileName]\n"
"\t[-d|--debug]\n"
+ "\t[--foreign]\n"
"\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n"
@@ -381,6 +382,7 @@ xx(lvdisplay,
"\t[--binary]\n"
"\t[--commandprofile ProfileName]\n"
"\t[-d|--debug]\n"
+ "\t[--foreign]\n"
"\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n"
@@ -399,7 +401,7 @@ xx(lvdisplay,
"\t[--version]\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,
noheadings_ARG, nosuffix_ARG, options_ARG, sort_ARG, partial_ARG,
readonly_ARG, segments_ARG, select_ARG, separator_ARG,
@@ -583,6 +585,7 @@ xx(lvs,
"\t[--binary]\n"
"\t[--commandprofile ProfileName]\n"
"\t[-d|--debug]\n"
+ "\t[--foreign]\n"
"\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n"
@@ -605,7 +608,7 @@ xx(lvs,
"\t[--version]\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,
nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG,
readonly_ARG, rows_ARG, segments_ARG, select_ARG, separator_ARG,
@@ -744,6 +747,7 @@ xx(pvdisplay,
"\t[-c|--colon]\n"
"\t[--commandprofile ProfileName]\n"
"\t[-d|--debug]\n"
+ "\t[--foreign]\n"
"\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n"
@@ -763,6 +767,7 @@ xx(pvdisplay,
"\t[--binary]\n"
"\t[--commandprofile ProfileName]\n"
"\t[-d|--debug]\n"
+ "\t[--foreign]\n"
"\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n"
@@ -779,7 +784,7 @@ xx(pvdisplay,
"\t[--version]\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,
noheadings_ARG, nosuffix_ARG, options_ARG, readonly_ARG,
select_ARG, separator_ARG, short_ARG, sort_ARG, unbuffered_ARG,
@@ -835,6 +840,7 @@ xx(pvs,
"\t[--binary]\n"
"\t[--commandprofile ProfileName]\n"
"\t[-d|--debug]\n"
+ "\t[--foreign]\n"
"\t[-h|-?|--help]\n"
"\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n"
@@ -857,7 +863,7 @@ xx(pvs,
"\t[--version]\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,
nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG, rows_ARG,
segments_ARG, select_ARG, separator_ARG, sort_ARG, trustcache_ARG,
@@ -907,6 +913,7 @@ xx(vgcfgbackup,
"\t[--commandprofile ProfileName]\n"
"\t[-d|--debug]\n"
"\t[-f|--file filename]\n"
+ "\t[--foreign]\n"
"\t[-h|-?|--help]\n"
"\t[--ignorelockingfailure]\n"
"\t[-P|--partial]\n"
@@ -915,7 +922,7 @@ xx(vgcfgbackup,
"\t[--version]\n"
"\t[VolumeGroupName...]\n",
- file_ARG, ignorelockingfailure_ARG, partial_ARG, readonly_ARG)
+ file_ARG, foreign_ARG, ignorelockingfailure_ARG, partial_ARG, readonly_ARG)
xx(vgcfgrestore,
"Restore volume group configuration",
@@ -955,11 +962,10 @@ xx(vgchange,
"\t[--[vg]metadatacopies #copies]\n"
"\t[--poll {y|n}]\n"
"\t[--noudevsync]\n"
- "\t[--systemid SystemID]\n"
"\t[--refresh]\n"
"\t[-S|--select Selection]\n"
- "\t[--systemid SystemID]\n"
"\t[--sysinit]\n"
+ "\t[--systemid SystemID]\n"
"\t[-t|--test]\n"
"\t[-u|--uuid]\n"
"\t[-v|--verbose]\n"
@@ -1033,6 +1039,7 @@ xx(vgcreate,
"\t[--[vg]metadatacopies #copies]\n"
"\t[-p|--maxphysicalvolumes MaxPhysicalVolumes]\n"
"\t[-s|--physicalextentsize PhysicalExtentSize[bBsSkKmMgGtTpPeE]]\n"
+ "\t[--systemid SystemID]\n"
"\t[-t|--test]\n"
"\t[-v|--verbose]\n"
"\t[--version]\n"
@@ -1055,6 +1062,7 @@ xx(vgdisplay,
"\t[-c|--colon | -s|--short | -v|--verbose]\n"
"\t[--commandprofile ProfileName]\n"
"\t[-d|--debug]\n"
+ "\t[--foreign]\n"
"\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n"
@@ -1071,6 +1079,7 @@ xx(vgdisplay,
"\t[--binary]\n"
"\t[--commandprofile ProfileName]\n"
"\t[-d|--debug]\n"
+ "\t[--foreign]\n"
"\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n"
@@ -1089,9 +1098,9 @@ xx(vgdisplay,
"\t[VolumeGroupName [VolumeGroupName...]]\n",
activevolumegroups_ARG, aligned_ARG, binary_ARG, colon_ARG, columns_ARG,
- ignorelockingfailure_ARG, ignoreskippedcluster_ARG, noheadings_ARG,
- nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG, select_ARG,
- short_ARG, separator_ARG, sort_ARG, unbuffered_ARG, units_ARG)
+ foreign_ARG, ignorelockingfailure_ARG, ignoreskippedcluster_ARG,
+ noheadings_ARG, nosuffix_ARG, options_ARG, partial_ARG, readonly_ARG,
+ select_ARG, short_ARG, separator_ARG, sort_ARG, unbuffered_ARG, units_ARG)
xx(vgexport,
"Unregister volume group(s) from the system",
@@ -1133,7 +1142,7 @@ xx(vgextend,
xx(vgimport,
"Register exported volume group with system",
- ALL_VGS_IS_DEFAULT,
+ ALL_VGS_IS_DEFAULT | NEEDS_FOREIGN_VGS,
"vgimport\n"
"\t[-a|--all]\n"
"\t[--commandprofile ProfileName]\n"
@@ -1242,6 +1251,7 @@ xx(vgs,
"\t[-a|--all]\n"
"\t[--commandprofile ProfileName]\n"
"\t[-d|--debug]\n"
+ "\t[--foreign]\n"
"\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n"
"\t[--ignoreskippedcluster]\n"
@@ -1263,11 +1273,11 @@ xx(vgs,
"\t[--version]\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,
nolocking_ARG, nosuffix_ARG, options_ARG, partial_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,
"Search for all volume groups",
diff --git a/tools/lvchange.c b/tools/lvchange.c
index c9466ec..1ed0dd5 100644
--- a/tools/lvchange.c
+++ b/tools/lvchange.c
@@ -1178,6 +1178,11 @@ int lvchange(struct cmd_context *cmd, int argc, char **argv)
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,
* we want to rely on autoactivation to take place. Also, we
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 6bdb00b..b38039b 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -1074,7 +1074,9 @@ static int _get_settings(struct cmd_context *cmd)
else
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))
lvmetad_connect_or_warn();
@@ -1500,6 +1502,19 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
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);
fin_locking();
diff --git a/tools/reporter.c b/tools/reporter.c
index cd0db6f..779e0bd 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -581,16 +581,6 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
int lv_info_needed, lv_segment_status_needed;
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);
buffered = find_config_tree_bool(cmd, report_buffered_CFG, NULL);
headings = find_config_tree_bool(cmd, report_headings_CFG, NULL);
diff --git a/tools/tools.h b/tools/tools.h
index 109834a..be4b166 100644
--- a/tools/tools.h
+++ b/tools/tools.h
@@ -108,6 +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
/* a register of the lvm commands */
struct command {
diff --git a/tools/vgcreate.c b/tools/vgcreate.c
index 5e03845..0a6ad6f 100644
--- a/tools/vgcreate.c
+++ b/tools/vgcreate.c
@@ -124,8 +124,9 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
backup(vg);
- log_print_unless_silent("%s%colume group \"%s\" successfully created",
- clustered_message, *clustered_message ? 'v' : 'V', vg->name);
+ log_print_unless_silent("%s%colume group \"%s\" successfully created%s%s",
+ clustered_message, *clustered_message ? 'v' : 'V', vg->name,
+ vg->system_id ? " with system ID " : "", vg->system_id ? : "");
release_vg(vg);
return ECMD_PROCESSED;
diff --git a/tools/vgimport.c b/tools/vgimport.c
index 41fd393..7000284 100644
--- a/tools/vgimport.c
+++ b/tools/vgimport.c
@@ -15,7 +15,7 @@
#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,
struct volume_group *vg,
struct processing_handle *handle __attribute__((unused)))
@@ -37,7 +37,7 @@ static int vgimport_single(struct cmd_context *cmd __attribute__((unused)),
goto_bad;
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) {
pv = pvl->pv;
@@ -85,17 +85,6 @@ 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,
diff --git a/tools/vgsplit.c b/tools/vgsplit.c
index 607f8e0..53f3975 100644
--- a/tools/vgsplit.c
+++ b/tools/vgsplit.c
@@ -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_alloc_policy(vg_to, vp_new.alloc) ||
!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))
goto_bad;
}
9 years, 1 month
master - systemid: Fix access restrictions.
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b18feb98e50093...
Commit: b18feb98e50093d66f03ff63120b6a0f14d7fddd
Parent: df227be37cb113a1093b2ed092af582c5a900315
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Mon Feb 23 23:19:36 2015 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Mon Feb 23 23:19:36 2015 +0000
systemid: Fix access restrictions.
When checking whether the system ID permits access to a VG, check for
each permitted situation first, and only then issue the appropriate
error message. Always issue a message for now. (We'll try to
suppress some of those later when the VG concerned wasn't explicitly
requested.)
Add more messages to try to ensure every return code is checked and
every error path (and only an error path) contains a log_error().
Add self-correction to vgchange -c to deal with situations where
the cluster state and system ID state are out-of-sync (e.g. if
old tools were used).
---
lib/format_text/import_vsn1.c | 9 ++--
lib/metadata/metadata.c | 46 ++++++++++------------
tools/toollib.c | 49 +++++++++++------------
tools/vgchange.c | 85 +++++++++++++++++++++++++++--------------
4 files changed, 106 insertions(+), 83 deletions(-)
diff --git a/lib/format_text/import_vsn1.c b/lib/format_text/import_vsn1.c
index c6a0cf9..42ff451 100644
--- a/lib/format_text/import_vsn1.c
+++ b/lib/format_text/import_vsn1.c
@@ -737,6 +737,7 @@ static struct volume_group *_read_vg(struct format_instance *fid,
struct volume_group *vg;
struct dm_hash_table *pv_hash = NULL, *lv_hash = NULL;
unsigned scan_done_once = use_cached_pvs;
+ char *system_id;
/* skip any top-level values */
for (vgn = cft->root; (vgn && vgn->v); vgn = vgn->sib)
@@ -750,8 +751,9 @@ static struct volume_group *_read_vg(struct format_instance *fid,
if (!(vg = alloc_vg("read_vg", fid->fmt->cmd, vgn->key)))
return_NULL;
- if (!(vg->system_id = dm_pool_zalloc(vg->vgmem, NAME_LEN + 1)))
+ if (!(system_id = dm_pool_zalloc(vg->vgmem, NAME_LEN + 1)))
goto_bad;
+ vg->system_id = system_id;
/*
* The pv hash memorises the pv section names -> pv
@@ -773,9 +775,8 @@ static struct volume_group *_read_vg(struct format_instance *fid,
vgn = vgn->child;
- if (dm_config_get_str(vgn, "system_id", &str)) {
- strncpy(vg->system_id, str, NAME_LEN);
- }
+ if (dm_config_get_str(vgn, "system_id", &str))
+ strncpy(system_id, str, NAME_LEN);
if (!_read_id(&vg->id, vgn, "id")) {
log_error("Couldn't read uuid for volume group %s.", vg->name);
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 9fb289d..71197ba 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -4338,7 +4338,7 @@ static struct volume_group *_recover_vg(struct cmd_context *cmd,
return (struct volume_group *)vg;
}
-static int allow_system_id(struct cmd_context *cmd, const char *system_id)
+static int _allow_system_id(struct cmd_context *cmd, const char *system_id)
{
const struct dm_config_node *cn;
const struct dm_config_value *cv;
@@ -4395,16 +4395,28 @@ static int _access_vg_systemid(struct cmd_context *cmd, struct volume_group *vg)
return 1;
/*
- * We sometimes want to report foreign vgs.
+ * A few commands allow read-only access to foreign VGs.
*/
if (cmd->include_foreign_vgs)
return 1;
/*
+ * A host can access a VG with a matching system_id.
+ */
+ if (cmd->system_id && !strcmp(vg->system_id, cmd->system_id))
+ return 1;
+
+ /*
+ * A host can access a VG if the VG's system_id is in extra_system_ids list.
+ */
+ if (cmd->system_id && _allow_system_id(cmd, vg->system_id))
+ return 1;
+
+ /*
* Allow VG access if the local host has active LVs in it.
*/
if (lvs_in_vg_activated(vg)) {
- log_error("LVs should not be active in VG %s with foreign system id \"%s\"",
+ log_warn("WARNING: Found LVs active in VG %s with foreign system ID \"%s\". Possible data corruption.",
vg->name, vg->system_id);
return 1;
}
@@ -4413,29 +4425,13 @@ static int _access_vg_systemid(struct cmd_context *cmd, struct volume_group *vg)
* A host without a system_id cannot access a VG with a system_id.
*/
if (!cmd->system_id || cmd->unknown_system_id) {
- log_warn("Cannot access VG %s with system id \"%s\" with unknown local system id.",
- vg->name, vg->system_id);
+ log_error("Cannot access VG %s with system id \"%s\" with unknown local system ID.",
+ vg->name, vg->system_id);
return 0;
}
- /*
- * A host can access a VG with a matching system_id.
- */
- if (!strcmp(vg->system_id, cmd->system_id))
- return 1;
-
- /*
- * A host can access a VG if the VG's system_id is in the allow list.
- */
- if (allow_system_id(cmd, vg->system_id))
- return 1;
-
- /*
- * Silently ignore foreign VGs. They will only cause the
- * command to fail if they were named as explicit command
- * args, in which case the command will fail indicating the
- * VG was not found.
- */
+ 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;
}
@@ -4443,7 +4439,7 @@ static int _access_vg_systemid(struct cmd_context *cmd, struct volume_group *vg)
/*
* FIXME: move _vg_bad_status_bits() checks in here.
*/
-static int _access_vg(struct cmd_context *cmd, struct volume_group *vg, uint32_t *failure)
+static int _vg_access_permitted(struct cmd_context *cmd, struct volume_group *vg, uint32_t *failure)
{
if (!is_real_vg(vg->name)) {
/* Disallow use of LVM1 orphans when a host system ID is set. */
@@ -4526,7 +4522,7 @@ static struct volume_group *_vg_lock_and_read(struct cmd_context *cmd, const cha
goto bad;
}
- if (!_access_vg(cmd, vg, &failure))
+ if (!_vg_access_permitted(cmd, vg, &failure))
goto bad;
/* consistent == 0 when VG is not found, but failed == FAILED_NOTFOUND */
diff --git a/tools/toollib.c b/tools/toollib.c
index 659eab5..b1795e7 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -200,12 +200,12 @@ static int _ignore_vg(struct volume_group *vg, const char *vg_name,
*/
if (read_error & FAILED_SYSTEMID) {
if (arg_vgnames && str_list_match_item(arg_vgnames, vg->name)) {
- log_error("Skipping volume group %s with system id %s",
- vg->name, vg->system_id);
+ log_error("Skipping volume group %s with system ID %s",
+ vg->name, vg->system_id ? : vg->lvm1_system_id ? : "");
return 1;
} else {
read_error &= ~FAILED_SYSTEMID; /* Check for other errors */
- log_verbose("Skipping volume group %s", vg_name);
+ log_verbose("Skipping foreign volume group %s", vg_name);
*skip = 1;
}
}
@@ -666,6 +666,7 @@ int vgcreate_params_set_defaults(struct cmd_context *cmd,
{
int64_t extent_size;
+ /* Only vgsplit sets vg */
if (vg) {
vp_def->vg_name = NULL;
vp_def->extent_size = vg->extent_size;
@@ -674,7 +675,7 @@ int vgcreate_params_set_defaults(struct cmd_context *cmd,
vp_def->alloc = vg->alloc;
vp_def->clustered = vg_is_clustered(vg);
vp_def->vgmetadatacopies = vg->mda_copies;
- vp_def->system_id = vg->system_id ? dm_pool_strdup(cmd->mem, vg->system_id) : NULL;
+ vp_def->system_id = vg->system_id; /* No need to clone this */
} else {
vp_def->vg_name = NULL;
extent_size = find_config_tree_int64(cmd,
@@ -689,7 +690,7 @@ int vgcreate_params_set_defaults(struct cmd_context *cmd,
vp_def->alloc = DEFAULT_ALLOC_POLICY;
vp_def->clustered = DEFAULT_CLUSTERED;
vp_def->vgmetadatacopies = DEFAULT_VGMETADATACOPIES;
- vp_def->system_id = cmd->system_id ? dm_pool_strdup(cmd->mem, cmd->system_id) : NULL;
+ vp_def->system_id = cmd->system_id;
}
return 1;
@@ -705,7 +706,7 @@ int vgcreate_params_set_from_args(struct cmd_context *cmd,
struct vgcreate_params *vp_new,
struct vgcreate_params *vp_def)
{
- const char *arg_str;
+ const char *system_id_arg_str;
vp_new->vg_name = skip_dev_dir(cmd, vp_def->vg_name, NULL);
vp_new->max_lv = arg_uint_value(cmd, maxlogicalvolumes_ARG,
@@ -745,37 +746,35 @@ int vgcreate_params_set_from_args(struct cmd_context *cmd,
return 0;
}
- if (arg_count(cmd, metadatacopies_ARG)) {
+ if (arg_count(cmd, metadatacopies_ARG))
vp_new->vgmetadatacopies = arg_int_value(cmd, metadatacopies_ARG,
DEFAULT_VGMETADATACOPIES);
- } else if (arg_count(cmd, vgmetadatacopies_ARG)) {
+ else if (arg_count(cmd, vgmetadatacopies_ARG))
vp_new->vgmetadatacopies = arg_int_value(cmd, vgmetadatacopies_ARG,
DEFAULT_VGMETADATACOPIES);
- } else {
+ else
vp_new->vgmetadatacopies = find_config_tree_int(cmd, metadata_vgmetadatacopies_CFG, NULL);
- }
- if ((arg_str = arg_str_value(cmd, systemid_ARG, NULL))) {
- vp_new->system_id = system_id_from_string(cmd, arg_str);
- } else {
+ /* A clustered VG has no system ID. */
+ if (vp_new->clustered) {
+ if (arg_is_set(cmd, systemid_ARG)) {
+ log_error("System ID cannot be set on clustered Volume Groups.");
+ return 0;
+ }
+ vp_new->system_id = NULL;
+ } else if (!(system_id_arg_str = arg_str_value(cmd, systemid_ARG, NULL)))
vp_new->system_id = vp_def->system_id;
- }
-
- if (arg_str) {
- if (!vp_new->system_id)
- log_warn("No local system id found, VG will not have a system id.");
+ else {
+ if (!(vp_new->system_id = system_id_from_string(cmd, system_id_arg_str)))
+ return_0;
+ /* 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 system id \"%s\" will not be accessible to local system id \"%s\"",
+ 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);
- }
}
- /* A clustered vg has no system_id. */
- if (vp_new->clustered)
- vp_new->system_id = NULL;
-
return 1;
}
diff --git a/tools/vgchange.c b/tools/vgchange.c
index 19aeee7..0b78230 100644
--- a/tools/vgchange.c
+++ b/tools/vgchange.c
@@ -301,41 +301,47 @@ static int _vgchange_clustered(struct cmd_context *cmd,
{
int clustered = arg_int_value(cmd, clustered_ARG, 0);
- if (clustered && (vg_is_clustered(vg))) {
- log_error("Volume group \"%s\" is already clustered",
- vg->name);
- return 0;
+ if (clustered && vg_is_clustered(vg)) {
+ if (vg->system_id && *vg->system_id)
+ log_warn("WARNING: Clearing invalid system ID %s from volume group %s.",
+ vg->system_id, vg->name);
+ else {
+ log_error("Volume group \"%s\" is already clustered", vg->name);
+ return 0;
+ }
}
- if (!clustered && !(vg_is_clustered(vg))) {
- log_error("Volume group \"%s\" is already not clustered",
- vg->name);
- return 0;
+ if (!clustered && !vg_is_clustered(vg)) {
+ if ((!vg->system_id || !*vg->system_id) && cmd->system_id && *cmd->system_id)
+ log_warn("Setting missing system ID on Volume Group %s to %s.",
+ vg->name, cmd->system_id);
+ else {
+ log_error("Volume group \"%s\" is already not clustered",
+ vg->name);
+ return 0;
+ }
}
if (clustered && !arg_count(cmd, yes_ARG)) {
if (!clvmd_is_running()) {
- if (yes_no_prompt("LVM cluster daemon (clvmd) is not"
- " running.\n"
- "Make volume group \"%s\" clustered"
- " anyway? [y/n]: ", vg->name) == 'n') {
+ if (yes_no_prompt("LVM cluster daemon (clvmd) is not running. "
+ "Make volume group \"%s\" clustered "
+ "anyway? [y/n]: ", vg->name) == 'n') {
log_error("No volume groups changed.");
return 0;
}
} else if (!locking_is_clustered() &&
- (yes_no_prompt("LVM locking type is not clustered.\n"
- "Make volume group \"%s\" clustered"
- " anyway? [y/n]: ", vg->name) == 'n')) {
+ (yes_no_prompt("LVM locking type is not clustered. "
+ "Make volume group \"%s\" clustered "
+ "anyway? [y/n]: ", vg->name) == 'n')) {
log_error("No volume groups changed.");
return 0;
}
}
- 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_system_id(vg, clustered ? NULL : cmd->system_id))
+ return_0;
if (!vg_set_clustered(vg, clustered))
return_0;
@@ -483,28 +489,49 @@ static int _vgchange_profile(struct cmd_context *cmd,
* extra_system_ids 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;
+ const char *system_id;
+ const char *system_id_arg_str = arg_str_value(cmd, systemid_ARG, NULL);
- if (!arg_str)
+ if (!system_id_arg_str || !*system_id_arg_str) {
+ log_error("Invalid system ID supplied: %s", system_id_arg_str);
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;
+ }
- system_id = system_id_from_string(cmd, arg_str);
+ 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 && 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);
+ 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 (yes_no_prompt("Change system id? [y/n]: ") == 'n') {
- log_error("Volume group \"%s\" not changed.", 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;
}
}
+ log_verbose("Changing system ID for VG %s: %s -> %s.",
+ vg->name, vg->system_id, system_id);
+
vg->system_id = system_id;
+
return 1;
}
9 years, 1 month
master - lvm1: Reenable sys ID.
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=df227be37cb113...
Commit: df227be37cb113a1093b2ed092af582c5a900315
Parent: 2fc2928978bb592a6b62a18bbbb0acee10efbfe2
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Mon Feb 23 23:03:52 2015 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Mon Feb 23 23:03:52 2015 +0000
lvm1: Reenable sys ID.
Move the lvm1 sys ID into vg->lvm1_system_id and reenable the #if 0
LVM1 code. Still display the new-style system ID in the same
reporting field, though, as only one can be set.
Add a format feature flag FMT_SYSTEM_ON_PVS for LVM1 and disallow
access to LVM1 VGs if a new-style system ID has been set.
Treat the new vg->system_id as const.
---
WHATS_NEW | 1 +
lib/commands/toolcontext.c | 10 ++++----
lib/commands/toolcontext.h | 2 +-
lib/format1/format1.c | 3 +-
lib/format1/import-export.c | 48 +++++++++++++++-----------------------
lib/metadata/metadata-exported.h | 3 ++
lib/metadata/metadata.c | 21 ++++++++++++++--
lib/metadata/vg.c | 13 ++++++++--
lib/metadata/vg.h | 3 +-
lib/report/columns.h | 4 +-
lib/report/report.c | 11 ++++++++
11 files changed, 74 insertions(+), 45 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 0ae007d..983189c 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.117 -
====================================
+ Install /etc/lvm/lvmlocal.conf template with local section for systemid.
Record creation_host_system_id in lvm2 metadata.
Reinstate recursive config file tag section processing. (2.02.99)
Add 'lvm systemid' to display the current system ID.
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index d81de97..7539b4a 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -58,7 +58,7 @@ static const size_t linebuffer_size = 4096;
/*
* Copy the input string, removing invalid characters.
*/
-char *system_id_from_string(struct cmd_context *cmd, const char *str)
+const char *system_id_from_string(struct cmd_context *cmd, const char *str)
{
char *system_id;
@@ -82,12 +82,12 @@ char *system_id_from_string(struct cmd_context *cmd, const char *str)
return system_id;
}
-static char *_read_system_id_from_file(struct cmd_context *cmd, const char *file)
+static const char *_read_system_id_from_file(struct cmd_context *cmd, const char *file)
{
char *line = NULL;
size_t line_size;
char *start, *end;
- char *system_id = NULL;
+ const char *system_id = NULL;
FILE *fp;
if (!file || !strlen(file) || !file[0])
@@ -132,13 +132,13 @@ static char *_read_system_id_from_file(struct cmd_context *cmd, const char *file
return system_id;
}
-static char *_system_id_from_source(struct cmd_context *cmd, const char *source)
+static const char *_system_id_from_source(struct cmd_context *cmd, const char *source)
{
char filebuf[PATH_MAX];
const char *file;
const char *etc_str;
const char *str;
- char *system_id = NULL;
+ const char *system_id = NULL;
if (!strcasecmp(source, "uname")) {
if (cmd->hostname)
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index 8b3e48e..8b38fb1 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -163,6 +163,6 @@ int init_lvmcache_orphans(struct cmd_context *cmd);
struct format_type *get_format_by_name(struct cmd_context *cmd, const char *format);
-char *system_id_from_string(struct cmd_context *cmd, const char *system_id_string);
+const char *system_id_from_string(struct cmd_context *cmd, const char *str);
#endif
diff --git a/lib/format1/format1.c b/lib/format1/format1.c
index b0943b1..f7df7c3 100644
--- a/lib/format1/format1.c
+++ b/lib/format1/format1.c
@@ -590,7 +590,8 @@ struct format_type *init_format(struct cmd_context *cmd)
fmt->alias = NULL;
fmt->orphan_vg_name = FMT_LVM1_ORPHAN_VG_NAME;
fmt->features = FMT_RESTRICTED_LVIDS | FMT_ORPHAN_ALLOCATABLE |
- FMT_RESTRICTED_READAHEAD | FMT_OBSOLETE;
+ FMT_RESTRICTED_READAHEAD | FMT_OBSOLETE |
+ FMT_SYSTEMID_ON_PVS;
fmt->private = NULL;
dm_list_init(&fmt->mda_ops);
diff --git a/lib/format1/import-export.c b/lib/format1/import-export.c
index 9318945..a3c060f 100644
--- a/lib/format1/import-export.c
+++ b/lib/format1/import-export.c
@@ -69,14 +69,14 @@ int import_pv(const struct format_type *fmt, struct dm_pool *mem,
memcpy(&pv->vgid, vgd->vg_uuid, sizeof(vg->id));
/* Store system_id from first PV if PV belongs to a VG */
- if (vg && !*vg->system_id)
- strncpy(vg->system_id, (char *)pvd->system_id, NAME_LEN);
+ if (vg && !*vg->lvm1_system_id)
+ strncpy(vg->lvm1_system_id, (char *)pvd->system_id, NAME_LEN);
if (vg &&
- strncmp(vg->system_id, (char *)pvd->system_id, sizeof(pvd->system_id)))
+ strncmp(vg->lvm1_system_id, (char *)pvd->system_id, sizeof(pvd->system_id)))
log_very_verbose("System ID %s on %s differs from %s for "
"volume group", pvd->system_id,
- pv_dev_name(pv), vg->system_id);
+ pv_dev_name(pv), vg->lvm1_system_id);
/*
* If exported, we still need to flag in pv->status too because
@@ -125,19 +125,17 @@ int import_pv(const struct format_type *fmt, struct dm_pool *mem,
return 1;
}
-#if 0
-static int _system_id(struct cmd_context *cmd, char *s, const char *prefix)
+static int _lvm1_system_id(struct cmd_context *cmd, char *s, const char *prefix)
{
if (dm_snprintf(s, NAME_LEN, "%s%s%lu",
prefix, cmd->hostname, time(NULL)) < 0) {
- log_error("Generated system_id too long");
+ log_error("Generated LVM1 format system_id too long");
return 0;
}
return 1;
}
-#endif
int export_pv(struct cmd_context *cmd, struct dm_pool *mem __attribute__((unused)),
struct volume_group *vg,
@@ -158,22 +156,18 @@ int export_pv(struct cmd_context *cmd, struct dm_pool *mem __attribute__((unused
}
/* Preserve existing system_id if it exists */
-#if 0
- if (vg && *vg->system_id)
- strncpy((char *)pvd->system_id, vg->system_id, sizeof(pvd->system_id));
-#endif
+ if (vg && *vg->lvm1_system_id)
+ strncpy((char *)pvd->system_id, vg->lvm1_system_id, sizeof(pvd->system_id));
/* Is VG already exported or being exported? */
if (vg && vg_is_exported(vg)) {
-#if 0
/* Does system_id need setting? */
- if (!*vg->system_id ||
- strncmp(vg->system_id, EXPORTED_TAG,
+ if (!*vg->lvm1_system_id ||
+ strncmp(vg->lvm1_system_id, EXPORTED_TAG,
sizeof(EXPORTED_TAG) - 1)) {
- if (!_system_id(cmd, (char *)pvd->system_id, EXPORTED_TAG))
+ if (!_lvm1_system_id(cmd, (char *)pvd->system_id, EXPORTED_TAG))
return_0;
}
-#endif
if (strlen((char *)pvd->vg_name) + sizeof(EXPORTED_TAG) >
sizeof(pvd->vg_name)) {
log_error("Volume group name %s too long to export",
@@ -183,25 +177,23 @@ int export_pv(struct cmd_context *cmd, struct dm_pool *mem __attribute__((unused
strcat((char *)pvd->vg_name, EXPORTED_TAG);
}
-#if 0
/* Is VG being imported? */
- if (vg && !vg_is_exported(vg) && *vg->system_id &&
- !strncmp(vg->system_id, EXPORTED_TAG, sizeof(EXPORTED_TAG) - 1)) {
- if (!_system_id(cmd, (char *)pvd->system_id, IMPORTED_TAG))
+ if (vg && !vg_is_exported(vg) && *vg->lvm1_system_id &&
+ !strncmp(vg->lvm1_system_id, EXPORTED_TAG, sizeof(EXPORTED_TAG) - 1)) {
+ if (!_lvm1_system_id(cmd, (char *)pvd->system_id, IMPORTED_TAG))
return_0;
}
/* Generate system_id if PV is in VG */
if (!pvd->system_id[0])
- if (!_system_id(cmd, (char *)pvd->system_id, ""))
+ if (!_lvm1_system_id(cmd, (char *)pvd->system_id, ""))
return_0;
/* Update internal system_id if we changed it */
if (vg &&
- (!*vg->system_id ||
- strncmp(vg->system_id, (char *)pvd->system_id, sizeof(pvd->system_id))))
- strncpy(vg->system_id, (char *)pvd->system_id, NAME_LEN);
-#endif
+ (!*vg->lvm1_system_id ||
+ strncmp(vg->lvm1_system_id, (char *)pvd->system_id, sizeof(pvd->system_id))))
+ strncpy(vg->lvm1_system_id, (char *)pvd->system_id, NAME_LEN);
//pvd->pv_major = MAJOR(pv->dev);
@@ -233,11 +225,9 @@ int import_vg(struct dm_pool *mem,
if (!(vg->name = dm_pool_strdup(mem, (char *)dl->pvd.vg_name)))
return_0;
- if (!(vg->system_id = dm_pool_zalloc(mem, NAME_LEN + 1)))
+ if (!(vg->lvm1_system_id = dm_pool_zalloc(mem, NAME_LEN + 1)))
return_0;
- *vg->system_id = '\0';
-
if (vgd->vg_status & VG_EXPORTED)
vg->status |= EXPORTED_VG;
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index 6631b1f..2dbaaf0 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -139,6 +139,9 @@
#define FMT_CONFIG_PROFILE 0x000000800U /* Supports configuration profiles? */
#define FMT_OBSOLETE 0x000001000U /* Obsolete format? */
#define FMT_NON_POWER2_EXTENTS 0x000002000U /* Non-power-of-2 extent sizes? */
+#define FMT_SYSTEMID_ON_PVS 0x000004000U /* System ID is stored on PVs not VG */
+
+#define systemid_on_pvs(vg) ((vg)->fid->fmt->features & FMT_SYSTEMID_ON_PVS)
/* Mirror conversion type flags */
#define MIRROR_BY_SEG 0x00000001U /* segment-by-segment mirror */
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index c04b67c..9fb289d 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -1045,10 +1045,10 @@ struct volume_group *vg_create(struct cmd_context *cmd, const char *vg_name)
}
vg->status = (RESIZEABLE_VG | LVM_READ | LVM_WRITE);
- if (!(vg->system_id = dm_pool_zalloc(vg->vgmem, NAME_LEN + 1)))
+ vg->system_id = NULL;
+ if (!(vg->lvm1_system_id = dm_pool_zalloc(vg->vgmem, NAME_LEN + 1)))
goto_bad;
- *vg->system_id = '\0';
vg->extent_size = DEFAULT_EXTENT_SIZE * 2;
vg->max_lv = DEFAULT_MAX_LV;
vg->max_pv = DEFAULT_MAX_PV;
@@ -4380,6 +4380,15 @@ static int _access_vg_clustered(struct cmd_context *cmd, struct volume_group *vg
static int _access_vg_systemid(struct cmd_context *cmd, struct volume_group *vg)
{
/*
+ * LVM1 VGs must not be accessed if a new-style LVM2 system ID is set.
+ */
+ if (cmd->system_id && systemid_on_pvs(vg)) {
+ log_error("Cannot access VG %s with LVM1 system ID \"%s\" when host system ID is set.",
+ vg->name, vg->lvm1_system_id);
+ return 0;
+ }
+
+ /*
* A VG without a system_id can be accessed by anyone.
*/
if (!vg->system_id || !vg->system_id[0])
@@ -4436,8 +4445,14 @@ static int _access_vg_systemid(struct cmd_context *cmd, struct volume_group *vg)
*/
static int _access_vg(struct cmd_context *cmd, struct volume_group *vg, uint32_t *failure)
{
- if (!is_real_vg(vg->name))
+ if (!is_real_vg(vg->name)) {
+ /* Disallow use of LVM1 orphans when a host system ID is set. */
+ if (cmd->system_id && *cmd->system_id && systemid_on_pvs(vg)) {
+ *failure |= FAILED_SYSTEMID;
+ return_0;
+ }
return 1;
+ }
if (!_access_vg_clustered(cmd, vg)) {
*failure |= FAILED_CLUSTERED;
diff --git a/lib/metadata/vg.c b/lib/metadata/vg.c
index dbc791b..0143b7b 100644
--- a/lib/metadata/vg.c
+++ b/lib/metadata/vg.c
@@ -121,7 +121,7 @@ char *vg_name_dup(const struct volume_group *vg)
char *vg_system_id_dup(const struct volume_group *vg)
{
- return dm_pool_strdup(vg->vgmem, vg->system_id);
+ return dm_pool_strdup(vg->vgmem, vg->system_id ? : vg->lvm1_system_id ? : "");
}
char *vg_uuid_dup(const struct volume_group *vg)
@@ -605,15 +605,22 @@ int vg_set_clustered(struct volume_group *vg, int clustered)
int vg_set_system_id(struct volume_group *vg, const char *system_id)
{
- if (!system_id) {
+ if (!system_id || !*system_id) {
vg->system_id = NULL;
return 1;
}
+ if (systemid_on_pvs(vg)) {
+ log_error("Metadata format %s does not support this type of system id.",
+ vg->fid->fmt->name);
+ return 0;
+ }
+
if (!(vg->system_id = dm_pool_strdup(vg->vgmem, system_id))) {
- log_error("vg_set_system_id no mem");
+ log_error("Failed to allocate memory for system_id in vg_set_system_id.");
return 0;
}
+
return 1;
}
diff --git a/lib/metadata/vg.h b/lib/metadata/vg.h
index 23d60ac..2964b82 100644
--- a/lib/metadata/vg.h
+++ b/lib/metadata/vg.h
@@ -67,7 +67,8 @@ struct volume_group {
struct id id;
const char *name;
const char *old_name; /* Set during vgrename and vgcfgrestore */
- char *system_id;
+ const char *system_id;
+ char *lvm1_system_id;
uint32_t extent_size;
uint32_t extent_count;
diff --git a/lib/report/columns.h b/lib/report/columns.h
index 1dd56ac..a957d98 100644
--- a/lib/report/columns.h
+++ b/lib/report/columns.h
@@ -139,8 +139,8 @@ FIELD(VGS, vg, STR, "AllocPol", cmd, 10, vgallocationpolicy, vg_allocation_polic
FIELD(VGS, vg, BIN, "Clustered", cmd, 10, vgclustered, vg_clustered, "Set if VG is clustered.", 0)
FIELD(VGS, vg, SIZ, "VSize", cmd, 5, vgsize, vg_size, "Total size of VG in current units.", 0)
FIELD(VGS, vg, SIZ, "VFree", cmd, 5, vgfree, vg_free, "Total amount of free space in current units.", 0)
-FIELD(VGS, vg, STR, "SYS ID", system_id, 6, string, vg_sysid, "System ID of the VG indicating its owner.", 0)
-FIELD(VGS, vg, STR, "System ID", system_id, 9, string, vg_systemid, "System ID of the VG indicating its owner.", 0)
+FIELD(VGS, vg, STR, "SYS ID", cmd, 6, vgsystemid, vg_sysid, "System ID of the VG indicating which host owns it.", 0)
+FIELD(VGS, vg, STR, "System ID", cmd, 9, vgsystemid, vg_systemid, "System ID of the VG indicating which host owns it.", 0)
FIELD(VGS, vg, SIZ, "Ext", extent_size, 3, size32, vg_extent_size, "Size of Physical Extents in current units.", 0)
FIELD(VGS, vg, NUM, "#Ext", extent_count, 4, uint32, vg_extent_count, "Total number of Physical Extents.", 0)
FIELD(VGS, vg, NUM, "Free", free_count, 4, uint32, vg_free_count, "Total number of unallocated Physical Extents.", 0)
diff --git a/lib/report/report.c b/lib/report/report.c
index cf3d9b6..b5418e5 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -984,6 +984,16 @@ static int _vgfree_disp(struct dm_report *rh, struct dm_pool *mem,
return _size64_disp(rh, mem, field, &freespace, private);
}
+static int _vgsystemid_disp(struct dm_report *rh, struct dm_pool *mem,
+ struct dm_report_field *field,
+ const void *data, void *private)
+{
+ const struct volume_group *vg = (const struct volume_group *) data;
+ const char *repstr = vg->system_id ? : vg->lvm1_system_id ? : "";
+
+ return _string_disp(rh, mem, field, &repstr, private);
+}
+
static int _uuid_disp(struct dm_report *rh __attribute__((unused)), struct dm_pool *mem,
struct dm_report_field *field,
const void *data, void *private __attribute__((unused)))
@@ -1864,6 +1874,7 @@ static struct volume_group _dummy_vg = {
.fid = &_dummy_fid,
.name = "",
.system_id = (char *) "",
+ .lvm1_system_id = (char *) "",
.pvs = DM_LIST_HEAD_INIT(_dummy_vg.pvs),
.lvs = DM_LIST_HEAD_INIT(_dummy_vg.lvs),
.tags = DM_LIST_HEAD_INIT(_dummy_vg.tags),
9 years, 1 month
master - config: Rename allow_system_id to extra_system_ids.
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=2fc2928978bb59...
Commit: 2fc2928978bb592a6b62a18bbbb0acee10efbfe2
Parent: 3d406e5a8dfe254f45585759aafa0720a251f0ad
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Mon Feb 23 22:19:08 2015 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Mon Feb 23 22:19:08 2015 +0000
config: Rename allow_system_id to extra_system_ids.
Add warnings to the config file templates and briefly document
each value.
Configure lvmlocal.conf and install in /etc/lvm.
---
conf/Makefile.in | 13 +++++++-
conf/example.conf.in | 41 ++++++++++++++++++++------
conf/lvmlocal.conf.in | 63 ++++++++++++++++++++++++++++--------------
configure | 3 +-
configure.in | 1 +
lib/config/config_settings.h | 2 +-
lib/metadata/metadata.c | 12 +++----
man/lvmsystemid.7.in | 8 ++--
test/shell/system_id.sh | 2 +-
tools/vgchange.c | 2 +-
10 files changed, 99 insertions(+), 48 deletions(-)
diff --git a/conf/Makefile.in b/conf/Makefile.in
index e56b25e..2d48fb9 100644
--- a/conf/Makefile.in
+++ b/conf/Makefile.in
@@ -17,24 +17,33 @@ top_builddir = @top_builddir@
CONFSRC=example.conf
CONFDEST=lvm.conf
+CONFLOCAL=lvmlocal.conf
PROFILE_TEMPLATES=command_profile_template.profile metadata_profile_template.profile
PROFILES=$(PROFILE_TEMPLATES) $(srcdir)/thin-generic.profile $(srcdir)/thin-performance.profile
include $(top_builddir)/make.tmpl
+.PHONY: install_conf install_localconf install_profiles
+
install_conf: $(CONFSRC)
@if [ ! -e $(confdir)/$(CONFDEST) ]; then \
echo "$(INSTALL_WDATA) -D $< $(confdir)/$(CONFDEST)"; \
$(INSTALL_WDATA) -D $< $(confdir)/$(CONFDEST); \
fi
+install_localconf: $(CONFLOCAL)
+ @if [ ! -e $(confdir)/$(CONFLOCAL) ]; then \
+ echo "$(INSTALL_WDATA) -D $< $(confdir)/$(CONFLOCAL)"; \
+ $(INSTALL_WDATA) -D $< $(confdir)/$(CONFLOCAL); \
+ fi
+
install_profiles: $(PROFILES)
$(INSTALL_DIR) $(DESTDIR)$(DEFAULT_PROFILE_DIR)
$(INSTALL_DATA) $(PROFILES) $(DESTDIR)$(DEFAULT_PROFILE_DIR)/
-install_lvm2: install_conf install_profiles
+install_lvm2: install_conf install_localconf install_profiles
install: install_lvm2
-DISTCLEAN_TARGETS += $(CONFSRC) $(PROFILE_TEMPLATES)
+DISTCLEAN_TARGETS += $(CONFSRC) $(CONFLOCAL) $(PROFILE_TEMPLATES)
diff --git a/conf/example.conf.in b/conf/example.conf.in
index 777280e..574842a 100644
--- a/conf/example.conf.in
+++ b/conf/example.conf.in
@@ -838,18 +838,39 @@ global {
#
# cache_dump_executable = "@CACHE_DUMP_CMD@"
- # Defines the method lvm will use to find the local system_id.
- # The options are: none, machineid, uname, lvmlocal, or file.
- # Unset, or set to an empty string is equivalent to "none".
- # See lvmsystemid(7) for more information.
+ # The method, if any, used to define a local system ID on this host.
+ # By placing the same system ID on a Volume Group you can prevent
+ # other co-operating hosts in a cluster (each with a different
+ # system ID) from accessing the same Volume Group.
#
- # system_id_source = ""
-
- # Specifies the path to a file containing the local system_id.
- # It is only used when system_id_source = "file".
- # See lvmsystemid(7) for more information.
+ # Set this to one of: none, machineid, uname, lvmlocal, or file.
+ #
+ # N.B. Do not use this feature without reading 'man lvmsystemid' to
+ # understand the correct ways to use it and its limitations.
+ #
+ # system_id_source = "none"
+ #
+ # Obtain the system ID from the "system_id" setting in the "local"
+ # section of a configuration file such as @DEFAULT_SYS_DIR(a)/lvmlocal.conf.
+ #
+ # system_id_source = "lvmlocal"
+ #
+ # Set the system ID from the hostname of the system.
+ # System IDs beginning "localhost" are not permitted.
+ #
+ # system_id_source = "uname"
+ #
+ # Use the contents of the file @DEFAULT_SYS_DIR@/machine-id
+ # to set the system ID.
+ # Comments starting with the character # are ignored.
+ #
+ # system_id_source = "machineid"
+ #
+ # Use the contents of an alternative file to set the system ID.
+ # Comments starting with the character # are ignored.
#
- # system_id_file = ""
+ # system_id_source = "file"
+ # system_id_file = "/etc/systemid"
}
activation {
diff --git a/conf/lvmlocal.conf.in b/conf/lvmlocal.conf.in
index b95ab37..48965e4 100644
--- a/conf/lvmlocal.conf.in
+++ b/conf/lvmlocal.conf.in
@@ -1,33 +1,54 @@
-# This is an example local configuration file for the LVM2 system.
-# It contains the default settings that would be used if there was no
-# @DEFAULT_SYS_DIR(a)/lvmlocal.conf file.
+# This is a local configuration file template for the LVM2 system
+# which should be installed as @DEFAULT_SYS_DIR(a)/lvmlocal.conf .
#
-# Refer to 'man lvm.conf' for further information including the file layout.
+# This file allows you to assign a unique identity to a host running
+# LVM2 that is permitted to access storage devices visible to more than
+# one machine simultaneously.
#
-# To put this file in a different directory and override @DEFAULT_SYS_DIR@ set
-# the environment variable LVM_SYSTEM_DIR before running the tools.
+# You must ensure that every such host uses a different system_id
+# identifier, otherwise LVM2 cannot protect you from simultaneous
+# access from multiple hosts and possible data corruption.
#
-# N.B. Take care that each setting only appears once if uncommenting
-# example settings in this file.
+# Refer to 'man lvmsystemid' for information about the correct ways
+# to use this and its limitations.
#
-# The lvmlocal.conf file should contain only the "local { }" section
-# which contains settings that should not be shared or repeated among
-# different hosts.
+# Refer to 'man lvm.conf' for information about the file layout.
#
-# This file should not be copied among hosts.
+# To put this file in a different directory and override
+# @DEFAULT_SYS_DIR@ set the environment variable LVM_SYSTEM_DIR before
+# running the tools.
+#
+# The lvmlocal.conf file is normally expected to contain only the
+# "local" section which contains settings that should not be shared or
+# repeated among different hosts. (But if other sections are present,
+# they *will* get processed. Settings in this file override equivalent
+# ones in lvm.conf and are in turn overridden by ones in any enabled
+# lvm_<tag>.conf files.)
+#
+# Please take care that each setting only appears once if uncommenting
+# example settings in this file and never copy this file between
+# hosts to avoid accidentally assigning the same system ID to
+# more than one host!
local {
- # This defines the system_id of the local host. It is
- # only used if lvm.conf system_id_source = "lvmlocal".
- # When used, it should be set to a unique value.
- # See lvmsystemid(7) for more information.
+ # This defines the system ID of the local host. This is used
+ # when global/system_id_source is set to "lvmlocal" in the main
+ # configuration file, conventionally @DEFAULT_SYS_DIR(a)/lvm.conf.
+ # When used, it must be set to a unique value - often a hostname -
+ # across all the hosts sharing access to the storage.
#
+ # By default, no system_id is set.
# system_id = ""
+ #
+ # Set the system_id to the string "host1".
+ # system_id = "host1"
- # This defines system_id's other than the local system_id
- # that the local host is allowed to access.
- # See lvmsystemid(7) for more information.
+ # This defines a list of extra system_ids other than the local
+ # system_id that the local host is allowed to access. These are
+ # used for all values of global/system_id_source except "none".
#
- # allow_system_id = []
+ # Only use this if you have read 'man lvmsystemid' and you are sure
+ # you understand why you need to use it!
+ #
+ # extra_system_ids = []
}
-
diff --git a/configure b/configure
index 935702a..c5c3b85 100755
--- a/configure
+++ b/configure
@@ -13069,7 +13069,7 @@ LVM_LIBAPI=`echo "$VER" | $AWK -F '[()]' '{print $2}'`
################################################################################
-ac_config_files="$ac_config_files Makefile make.tmpl daemons/Makefile daemons/clvmd/Makefile daemons/cmirrord/Makefile daemons/dmeventd/Makefile daemons/dmeventd/libdevmapper-event.pc daemons/dmeventd/plugins/Makefile daemons/dmeventd/plugins/lvm2/Makefile daemons/dmeventd/plugins/raid/Makefile daemons/dmeventd/plugins/mirror/Makefile daemons/dmeventd/plugins/snapshot/Makefile daemons/dmeventd/plugins/thin/Makefile daemons/lvmetad/Makefile conf/Makefile conf/example.conf conf/command_profile_template.profile conf/metadata_profile_template.profile include/.symlinks include/Makefile lib/Makefile lib/format1/Makefile lib/format_pool/Makefile lib/locking/Makefile lib/mirror/Makefile lib/replicator/Makefile lib/misc/lvm-version.h lib/raid/Makefile lib/snapshot/Makefile lib/thin/Makefile lib/cache_segtype/Makefile libdaemon/Makefile libdaemon/client/Makefile libdaemon/server/Makefile libdm/Makefile libdm/libdevmapper.pc liblvm/Makefile liblvm/liblvm2app.pc man/Makefile po/Makefile
python/Makefile python/setup.py scripts/blkdeactivate.sh scripts/blk_availability_init_red_hat scripts/blk_availability_systemd_red_hat.service scripts/clvmd_init_red_hat scripts/cmirrord_init_red_hat scripts/dm_event_systemd_red_hat.service scripts/dm_event_systemd_red_hat.socket scripts/lvm2_cluster_activation_red_hat.sh scripts/lvm2_cluster_activation_systemd_red_hat.service scripts/lvm2_clvmd_systemd_red_hat.service scripts/lvm2_cmirrord_systemd_red_hat.service scripts/lvm2_lvmetad_init_red_hat scripts/lvm2_lvmetad_systemd_red_hat.service scripts/lvm2_lvmetad_systemd_red_hat.socket scripts/lvm2_monitoring_init_red_hat scripts/lvm2_monitoring_systemd_red_hat.service scripts/lvm2_pvscan_systemd_red_hat@.service scripts/lvm2_tmpfiles_red_hat.conf scripts/Makefile test/Makefile test/api/Makefile test/unit/Makefile tools/Makefile udev/Makefile unit-tests/datastruct/Makefile unit-tests/regex/Makefile unit-tests/mm/Makefile"
+ac_config_files="$ac_config_files Makefile make.tmpl daemons/Makefile daemons/clvmd/Makefile daemons/cmirrord/Makefile daemons/dmeventd/Makefile daemons/dmeventd/libdevmapper-event.pc daemons/dmeventd/plugins/Makefile daemons/dmeventd/plugins/lvm2/Makefile daemons/dmeventd/plugins/raid/Makefile daemons/dmeventd/plugins/mirror/Makefile daemons/dmeventd/plugins/snapshot/Makefile daemons/dmeventd/plugins/thin/Makefile daemons/lvmetad/Makefile conf/Makefile conf/example.conf conf/lvmlocal.conf conf/command_profile_template.profile conf/metadata_profile_template.profile include/.symlinks include/Makefile lib/Makefile lib/format1/Makefile lib/format_pool/Makefile lib/locking/Makefile lib/mirror/Makefile lib/replicator/Makefile lib/misc/lvm-version.h lib/raid/Makefile lib/snapshot/Makefile lib/thin/Makefile lib/cache_segtype/Makefile libdaemon/Makefile libdaemon/client/Makefile libdaemon/server/Makefile libdm/Makefile libdm/libdevmapper.pc liblvm/Makefile liblvm/liblvm2app.pc man/M
akefile po/Makefile python/Makefile python/setup.py scripts/blkdeactivate.sh scripts/blk_availability_init_red_hat scripts/blk_availability_systemd_red_hat.service scripts/clvmd_init_red_hat scripts/cmirrord_init_red_hat scripts/dm_event_systemd_red_hat.service scripts/dm_event_systemd_red_hat.socket scripts/lvm2_cluster_activation_red_hat.sh scripts/lvm2_cluster_activation_systemd_red_hat.service scripts/lvm2_clvmd_systemd_red_hat.service scripts/lvm2_cmirrord_systemd_red_hat.service scripts/lvm2_lvmetad_init_red_hat scripts/lvm2_lvmetad_systemd_red_hat.service scripts/lvm2_lvmetad_systemd_red_hat.socket scripts/lvm2_monitoring_init_red_hat scripts/lvm2_monitoring_systemd_red_hat.service scripts/lvm2_pvscan_systemd_red_hat@.service scripts/lvm2_tmpfiles_red_hat.conf scripts/Makefile test/Makefile test/api/Makefile test/unit/Makefile tools/Makefile udev/Makefile unit-tests/datastruct/Makefile unit-tests/regex/Makefile unit-tests/mm/Makefile"
cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure
@@ -13780,6 +13780,7 @@ do
"daemons/lvmetad/Makefile") CONFIG_FILES="$CONFIG_FILES daemons/lvmetad/Makefile" ;;
"conf/Makefile") CONFIG_FILES="$CONFIG_FILES conf/Makefile" ;;
"conf/example.conf") CONFIG_FILES="$CONFIG_FILES conf/example.conf" ;;
+ "conf/lvmlocal.conf") CONFIG_FILES="$CONFIG_FILES conf/lvmlocal.conf" ;;
"conf/command_profile_template.profile") CONFIG_FILES="$CONFIG_FILES conf/command_profile_template.profile" ;;
"conf/metadata_profile_template.profile") CONFIG_FILES="$CONFIG_FILES conf/metadata_profile_template.profile" ;;
"include/.symlinks") CONFIG_FILES="$CONFIG_FILES include/.symlinks" ;;
diff --git a/configure.in b/configure.in
index 7c855bf..15d371b 100644
--- a/configure.in
+++ b/configure.in
@@ -1822,6 +1822,7 @@ daemons/dmeventd/plugins/thin/Makefile
daemons/lvmetad/Makefile
conf/Makefile
conf/example.conf
+conf/lvmlocal.conf
conf/command_profile_template.profile
conf/metadata_profile_template.profile
include/.symlinks
diff --git a/lib/config/config_settings.h b/lib/config/config_settings.h
index fe4218e..4083785 100644
--- a/lib/config/config_settings.h
+++ b/lib/config/config_settings.h
@@ -282,6 +282,6 @@ cfg_section(tag_CFG_SUBSECTION, "tag", tags_CFG_SECTION, CFG_NAME_VARIABLE | CFG
cfg(tag_host_list_CFG, "host_list", tag_CFG_SUBSECTION, CFG_ALLOW_EMPTY | CFG_DEFAULT_UNDEFINED, CFG_TYPE_STRING, NULL, vsn(1, 0, 18), NULL)
cfg(local_system_id_CFG, "system_id", local_CFG_SECTION, CFG_ALLOW_EMPTY | CFG_DEFAULT_UNDEFINED, CFG_TYPE_STRING, NULL, vsn(2, 2, 117), NULL)
-cfg_array(local_allow_system_id_CFG, "allow_system_id", local_CFG_SECTION, CFG_DEFAULT_UNDEFINED, CFG_TYPE_STRING, NULL, vsn(2, 2, 117), NULL)
+cfg_array(local_extra_system_ids_CFG, "extra_system_ids", local_CFG_SECTION, CFG_ALLOW_EMPTY | CFG_DEFAULT_UNDEFINED, CFG_TYPE_STRING, NULL, vsn(2, 2, 117), NULL)
cfg(CFG_COUNT, NULL, root_CFG_SECTION, 0, CFG_TYPE_INT, 0, vsn(0, 0, 0), NULL)
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 5acb2b4..c04b67c 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -4344,21 +4344,18 @@ static int allow_system_id(struct cmd_context *cmd, const char *system_id)
const struct dm_config_value *cv;
const char *str;
- if (!(cn = find_config_tree_node(cmd, local_allow_system_id_CFG, NULL)))
+ if (!(cn = find_config_tree_node(cmd, local_extra_system_ids_CFG, NULL)))
return 0;
for (cv = cn->v; cv; cv = cv->next) {
if (cv->type == DM_CFG_EMPTY_ARRAY)
break;
- if (cv->type != DM_CFG_STRING) {
- log_error("Ignoring invalid string in allow_system_id list");
+ /* Ignore invalid data: Warning message already issued by config.c */
+ if (cv->type != DM_CFG_STRING)
continue;
- }
str = cv->v.str;
- if (!*str) {
- log_error("Ignoring empty string in config file");
+ if (!*str)
continue;
- }
if (!strcmp(str, system_id))
return 1;
@@ -4376,6 +4373,7 @@ static int _access_vg_clustered(struct cmd_context *cmd, struct volume_group *vg
log_verbose("Skipping clustered volume group %s", vg->name);
return 0;
}
+
return 1;
}
diff --git a/man/lvmsystemid.7.in b/man/lvmsystemid.7.in
index c0dd78b..741aafe 100644
--- a/man/lvmsystemid.7.in
+++ b/man/lvmsystemid.7.in
@@ -197,24 +197,24 @@ global {
Changing system_id_source will often cause the system_id to change, which
may prevent the host from using VGs that it previously used (see
-allow_system_id below to handle this.)
+extra_system_ids below to handle this.)
If a system_id_source other than none fails to resolve a system_id, the
host will be allowed to access VGs with no system_id, but will not be
allowed to access VGs with a defined system_id.
-.SS allow_system_id
+.SS extra_system_ids
In some cases, it may be useful for a host to access VGs with different
system_id's, e.g. if a host's system_id changes, and it wants to use VGs
that it created with its old system_id. To allow a host to access VGs
with other system_id's, those other system_id's can be listed in
-lvmlocal.conf local/allow_system_id.
+lvmlocal.conf local/extra_system_ids.
.I lvmlocal.conf
.nf
local {
- allow_system_id = [ "my_other_name" ]
+ extra_system_ids = [ "my_other_name" ]
}
.fi
diff --git a/test/shell/system_id.sh b/test/shell/system_id.sh
index 98924b0..3312ab6 100644
--- a/test/shell/system_id.sh
+++ b/test/shell/system_id.sh
@@ -386,7 +386,7 @@ rm -f $SIDFILE
# lvs --foreign: lvs in a foreign vg are reported
# TODO
-# use allow_system_id to read a foreign VG
+# use extra_system_ids to read a foreign VG
# TODO
diff --git a/tools/vgchange.c b/tools/vgchange.c
index d56b3df..19aeee7 100644
--- a/tools/vgchange.c
+++ b/tools/vgchange.c
@@ -480,7 +480,7 @@ static int _vgchange_profile(struct cmd_context *cmd,
* 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
+ * extra_system_ids list. This function is not allowed to change the system_id
* of a foreign VG (VG owned by another host).
*/
9 years, 1 month
master - config: Adjust system_id defaults.
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3d406e5a8dfe25...
Commit: 3d406e5a8dfe254f45585759aafa0720a251f0ad
Parent: e15b439bf346f8dc618bef9380b12eb595519a2c
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Mon Feb 23 21:20:51 2015 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Mon Feb 23 21:20:51 2015 +0000
config: Adjust system_id defaults.
Allow cmd->unknown_system_id to be cleared during toolcontext
refresh.
Set a default value of "none" for global/system_id_source.
Allow local/system_id to be empty so it's not impossible for
a later config file to remove it.
---
lib/commands/toolcontext.c | 9 ++++++---
lib/config/config_settings.h | 4 ++--
lib/config/defaults.h | 1 +
3 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 58f3b5e..d81de97 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -424,12 +424,15 @@ int process_profilable_config(struct cmd_context *cmd)
static int _init_system_id(struct cmd_context *cmd)
{
- const char *source;
- int local_set;
+ const char *source, *system_id;
+ int local_set = 0;
cmd->system_id = NULL;
+ cmd->unknown_system_id = 0;
- local_set = !!find_config_tree_str(cmd, local_system_id_CFG, NULL);
+ system_id = find_config_tree_str_allow_empty(cmd, local_system_id_CFG, NULL);
+ if (system_id && *system_id)
+ local_set = 1;
source = find_config_tree_str(cmd, global_system_id_source_CFG, NULL);
if (!source)
diff --git a/lib/config/config_settings.h b/lib/config/config_settings.h
index 7360420..fe4218e 100644
--- a/lib/config/config_settings.h
+++ b/lib/config/config_settings.h
@@ -193,7 +193,7 @@ cfg_array(global_cache_check_options_CFG, "cache_check_options", global_CFG_SECT
cfg(global_cache_dump_executable_CFG, "cache_dump_executable", global_CFG_SECTION, CFG_ALLOW_EMPTY, CFG_TYPE_STRING, CACHE_DUMP_CMD, vsn(2, 2, 108), NULL)
cfg(global_cache_repair_executable_CFG, "cache_repair_executable", global_CFG_SECTION, CFG_ALLOW_EMPTY, CFG_TYPE_STRING, CACHE_REPAIR_CMD, vsn(2, 2, 108), NULL)
cfg_array(global_cache_repair_options_CFG, "cache_repair_options", global_CFG_SECTION, 0, CFG_TYPE_STRING, "#S" DEFAULT_CACHE_REPAIR_OPTIONS, vsn(2, 2, 108), NULL)
-cfg(global_system_id_source_CFG, "system_id_source", global_CFG_SECTION, CFG_DEFAULT_UNDEFINED, CFG_TYPE_STRING, NULL, vsn(2, 2, 117), NULL)
+cfg(global_system_id_source_CFG, "system_id_source", global_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_SYSTEM_ID_SOURCE, vsn(2, 2, 117), NULL)
cfg(global_system_id_file_CFG, "system_id_file", global_CFG_SECTION, CFG_DEFAULT_UNDEFINED, CFG_TYPE_STRING, NULL, vsn(2, 2, 117), NULL)
cfg(activation_checks_CFG, "checks", activation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_ACTIVATION_CHECKS, vsn(2, 2, 86), NULL)
@@ -281,7 +281,7 @@ cfg(tags_hosttags_CFG, "hosttags", tags_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_H
cfg_section(tag_CFG_SUBSECTION, "tag", tags_CFG_SECTION, CFG_NAME_VARIABLE | CFG_DEFAULT_UNDEFINED, vsn(1, 0, 18), NULL)
cfg(tag_host_list_CFG, "host_list", tag_CFG_SUBSECTION, CFG_ALLOW_EMPTY | CFG_DEFAULT_UNDEFINED, CFG_TYPE_STRING, NULL, vsn(1, 0, 18), NULL)
-cfg(local_system_id_CFG, "system_id", local_CFG_SECTION, CFG_DEFAULT_UNDEFINED, CFG_TYPE_STRING, NULL, vsn(2, 2, 117), NULL)
+cfg(local_system_id_CFG, "system_id", local_CFG_SECTION, CFG_ALLOW_EMPTY | CFG_DEFAULT_UNDEFINED, CFG_TYPE_STRING, NULL, vsn(2, 2, 117), NULL)
cfg_array(local_allow_system_id_CFG, "allow_system_id", local_CFG_SECTION, CFG_DEFAULT_UNDEFINED, CFG_TYPE_STRING, NULL, vsn(2, 2, 117), NULL)
cfg(CFG_COUNT, NULL, root_CFG_SECTION, 0, CFG_TYPE_INT, 0, vsn(0, 0, 0), NULL)
diff --git a/lib/config/defaults.h b/lib/config/defaults.h
index 9d2cff9..8339c1a 100644
--- a/lib/config/defaults.h
+++ b/lib/config/defaults.h
@@ -29,6 +29,7 @@
#define DEFAULT_DEV_DIR "/dev"
#define DEFAULT_PROC_DIR "/proc"
+#define DEFAULT_SYSTEM_ID_SOURCE "none"
#define DEFAULT_OBTAIN_DEVICE_LIST_FROM_UDEV 1
#define DEFAULT_EXTERNAL_DEVICE_INFO_SOURCE "none"
#define DEFAULT_SYSFS_SCAN 1
9 years, 1 month
master - systemid: Define file content more precisely.
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=e15b439bf346f8...
Commit: e15b439bf346f8dc618bef9380b12eb595519a2c
Parent: c2ed5feee504185faeba8e85c32769b5dba8a3f2
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Mon Feb 23 20:49:15 2015 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Mon Feb 23 20:49:15 2015 +0000
systemid: Define file content more precisely.
In a file containing a system ID:
Any whitespace at the start of a line is ignored;
Blank lines are ignored;
Any characters after a # are ignored along with the #.
The system ID is obtained by processing the first line with
non-ignored characters.
If further lines with non-ignored characters follow, a warning is
issued.
---
lib/commands/toolcontext.c | 41 +++++++++++++++++++++++++++++++----------
1 files changed, 31 insertions(+), 10 deletions(-)
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 164b344..58f3b5e 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -84,31 +84,52 @@ char *system_id_from_string(struct cmd_context *cmd, const char *str)
static char *_read_system_id_from_file(struct cmd_context *cmd, const char *file)
{
- char line[NAME_LEN + 1];
+ char *line = NULL;
+ size_t line_size;
+ char *start, *end;
+ char *system_id = NULL;
FILE *fp;
if (!file || !strlen(file) || !file[0])
- return NULL;
+ return_NULL;
if (!(fp = fopen(file, "r"))) {
- log_warn("WARNING: Error %d opening system_id_file %s", errno, file);
+ log_warn("WARNING: %s: fopen failed: %s", file, strerror(errno));
return NULL;
}
- memset(line, 0, sizeof(line));
+ while (getline(&line, &line_size, fp) > 0) {
+ start = line;
+
+ /* Ignore leading whitespace */
+ while (*start && isspace(*start))
+ start++;
- while (fgets(line, NAME_LEN, fp)) {
- if (line[0] == '#' || line[0] == '\n')
+ /* Ignore rest of line after # */
+ if (!*start || *start == '#')
continue;
- if (fclose(fp))
- stack;
- return system_id_from_string(cmd, line);
+ if (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++)
+ if (*end == '#') {
+ *end = '\0';
+ break;
+ }
+
+ system_id = system_id_from_string(cmd, start);
}
+ free(line);
+
if (fclose(fp))
stack;
- return NULL;
+
+ return system_id;
}
static char *_system_id_from_source(struct cmd_context *cmd, const char *source)
9 years, 1 month
master - systemid: Add warnings if invalid.
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c2ed5feee50418...
Commit: c2ed5feee504185faeba8e85c32769b5dba8a3f2
Parent: 6b6934b009f57fe4677cf357bfb26746ce89747a
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Mon Feb 23 20:36:27 2015 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Mon Feb 23 20:36:27 2015 +0000
systemid: Add warnings if invalid.
Add WARNING messages if there are problems setting the requested
system ID.
Ban "localhost" as a prefix regardless of the system_id_source.
Use cmd->hostname instead of calling uname again.
Make system_id_source values case-insensitive (as with new settings like
log_debug_classes) and also accept machine-id to match the filename.
---
lib/commands/toolcontext.c | 38 ++++++++++++++++++++++++--------------
lib/commands/toolcontext.h | 1 -
2 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 0a253f3..164b344 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -55,20 +55,29 @@
static const size_t linebuffer_size = 4096;
-
-/* Copy the input string, removing invalid characters. */
-
+/*
+ * Copy the input string, removing invalid characters.
+ */
char *system_id_from_string(struct cmd_context *cmd, const char *str)
{
char *system_id;
- if (!(system_id = dm_pool_zalloc(cmd->mem, strlen(str) + 1)))
+ if (!(system_id = dm_pool_zalloc(cmd->mem, strlen(str) + 1))) {
+ log_warn("WARNING: Failed to allocate system ID.");
return NULL;
+ }
copy_systemid_chars(str, system_id);
- if (!system_id[0])
+ if (!*system_id) {
+ log_warn("WARNING: Invalid system ID format: %s", str);
+ return NULL;
+ }
+
+ if (!strncmp(system_id, "localhost", 9)) {
+ log_warn("WARNING: System ID may not begin with the string \"localhost\".");
return NULL;
+ }
return system_id;
}
@@ -104,39 +113,40 @@ static char *_read_system_id_from_file(struct cmd_context *cmd, const char *file
static char *_system_id_from_source(struct cmd_context *cmd, const char *source)
{
- struct utsname uts;
char filebuf[PATH_MAX];
const char *file;
const char *etc_str;
const char *str;
char *system_id = NULL;
- if (!strcmp(source, "uname")) {
- if (!uname(&uts) && strncmp(uts.nodename, "localhost", 9))
- system_id = system_id_from_string(cmd, uts.nodename);
+ if (!strcasecmp(source, "uname")) {
+ if (cmd->hostname)
+ system_id = system_id_from_string(cmd, cmd->hostname);
goto out;
}
/* lvm.conf and lvmlocal.conf are merged into one config tree */
- if (!strcmp(source, "lvmlocal")) {
+ if (!strcasecmp(source, "lvmlocal")) {
if ((str = find_config_tree_str(cmd, local_system_id_CFG, NULL)))
system_id = system_id_from_string(cmd, str);
goto out;
}
- if (!strcmp(source, "machineid")) {
- memset(filebuf, 0, sizeof(filebuf));
+ if (!strcasecmp(source, "machineid") || !strcasecmp(source, "machine-id")) {
etc_str = find_config_tree_str(cmd, global_etc_CFG, NULL);
- if (dm_snprintf(filebuf, sizeof(filebuf), "%s/machine-id", etc_str) >= 0)
+ if (dm_snprintf(filebuf, sizeof(filebuf), "%s/machine-id", etc_str) != -1)
system_id = _read_system_id_from_file(cmd, filebuf);
goto out;
}
- if (!strcmp(source, "file")) {
+ if (!strcasecmp(source, "file")) {
file = find_config_tree_str(cmd, global_system_id_file_CFG, NULL);
system_id = _read_system_id_from_file(cmd, file);
goto out;
}
+
+ log_warn("WARNING: Unrecognised system_id_source \"%s\".", source);
+
out:
return system_id;
}
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index a3aaf7c..8b3e48e 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -163,7 +163,6 @@ int init_lvmcache_orphans(struct cmd_context *cmd);
struct format_type *get_format_by_name(struct cmd_context *cmd, const char *format);
-char *system_id_from_source(struct cmd_context *cmd, const char *system_id_source);
char *system_id_from_string(struct cmd_context *cmd, const char *system_id_string);
#endif
9 years, 1 month
master - toolcontext: Include system_id in refresh.
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6b6934b009f57f...
Commit: 6b6934b009f57fe4677cf357bfb26746ce89747a
Parent: 72e6888dc3aaeecc869715366b7d3fdcc7732992
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Mon Feb 23 20:21:00 2015 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Mon Feb 23 20:21:00 2015 +0000
toolcontext: Include system_id in refresh.
Move _init_system_id() into _process_config() so it's also called when
refreshing the toolcontext. Add WARNING to log_warn messages.
---
lib/commands/toolcontext.c | 74 ++++++++++++++++++++++----------------------
1 files changed, 37 insertions(+), 37 deletions(-)
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 1b0a427..0a253f3 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -102,7 +102,7 @@ static char *_read_system_id_from_file(struct cmd_context *cmd, const char *file
return NULL;
}
-char *system_id_from_source(struct cmd_context *cmd, const char *source)
+static char *_system_id_from_source(struct cmd_context *cmd, const char *source)
{
struct utsname uts;
char filebuf[PATH_MAX];
@@ -391,6 +391,39 @@ int process_profilable_config(struct cmd_context *cmd)
return 1;
}
+static int _init_system_id(struct cmd_context *cmd)
+{
+ const char *source;
+ int local_set;
+
+ cmd->system_id = NULL;
+
+ local_set = !!find_config_tree_str(cmd, local_system_id_CFG, NULL);
+
+ source = find_config_tree_str(cmd, global_system_id_source_CFG, NULL);
+ if (!source)
+ source = "none";
+
+ /* Defining local system_id but not using it is probably a config mistake. */
+ if (local_set && strcmp(source, "lvmlocal"))
+ log_warn("WARNING: local/system_id is set, so should global/system_id_source be \"lvmlocal\" not \"%s\"?", source);
+
+ if (!strcmp(source, "none"))
+ return 1;
+
+ if ((cmd->system_id = _system_id_from_source(cmd, source)))
+ return 1;
+
+ /*
+ * The source failed to resolve a system_id. In this case allow
+ * VGs with no system_id to be accessed, but not VGs with a system_id.
+ */
+ log_warn("WARNING: No system ID found from system_id_source \"%s\".", source);
+ cmd->unknown_system_id = 1;
+
+ return 1;
+}
+
static int _process_config(struct cmd_context *cmd)
{
mode_t old_umask;
@@ -567,6 +600,9 @@ static int _process_config(struct cmd_context *cmd)
lvmetad_init(cmd);
+ if (!_init_system_id(cmd))
+ return_0;
+
return 1;
}
@@ -1446,39 +1482,6 @@ static int _init_hostname(struct cmd_context *cmd)
return 1;
}
-static int _init_system_id(struct cmd_context *cmd)
-{
- const char *source;
- int local_set;
-
- cmd->system_id = NULL;
-
- local_set = !!find_config_tree_str(cmd, local_system_id_CFG, NULL);
-
- source = find_config_tree_str(cmd, global_system_id_source_CFG, NULL);
- if (!source)
- source = "none";
-
- /* Defining local system_id but not using it is probably a config mistake. */
- if (local_set && strcmp(source, "lvmlocal"))
- log_warn("Local system_id is not used by system_id_source %s.", source);
-
- if (!strcmp(source, "none"))
- return 1;
-
- if ((cmd->system_id = system_id_from_source(cmd, source)))
- return 1;
-
- /*
- * The source failed to resolve a system_id. In this case allow
- * VGs with no system_id to be accessed, but not VGs with a system_id.
- */
-
- log_warn("No system_id found from system_id_source %s.", source);
- cmd->unknown_system_id = 1;
- return 1;
-}
-
static int _init_backup(struct cmd_context *cmd)
{
uint32_t days, min;
@@ -1711,9 +1714,6 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived,
if (!_init_profiles(cmd))
goto_out;
- if (!_init_system_id(cmd))
- goto_out;
-
if (!(cmd->dev_types = create_dev_types(cmd->proc_dir,
find_config_tree_node(cmd, devices_types_CFG, NULL))))
goto_out;
9 years, 1 month
master - toolcontext: Move lvmlocal.conf loading.
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=72e6888dc3aaee...
Commit: 72e6888dc3aaeecc869715366b7d3fdcc7732992
Parent: 0551d1c56e2e901a885aba09a94ebc391930bbc5
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Mon Feb 23 20:11:00 2015 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Mon Feb 23 20:11:00 2015 +0000
toolcontext: Move lvmlocal.conf loading.
Load lvmlocal.conf after basic initialisation from lvm.conf.
---
lib/commands/toolcontext.c | 16 +++++++++++-----
1 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 190f9bd..1b0a427 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -374,7 +374,8 @@ static int _check_config(struct cmd_context *cmd)
return 1;
}
-int process_profilable_config(struct cmd_context *cmd) {
+int process_profilable_config(struct cmd_context *cmd)
+{
if (!(cmd->default_settings.unit_factor =
dm_units_to_factor(find_config_tree_str(cmd, global_units_CFG, NULL),
&cmd->default_settings.unit_type, 1, NULL))) {
@@ -699,9 +700,8 @@ static int _load_config_file(struct cmd_context *cmd, const char *tag, int local
}
/*
- * Find and read lvm.conf and lvmlocal.conf.
+ * Find and read lvm.conf.
*/
-
static int _init_lvm_conf(struct cmd_context *cmd)
{
/* No config file if LVM_SYSTEM_DIR is empty */
@@ -716,8 +716,6 @@ static int _init_lvm_conf(struct cmd_context *cmd)
if (!_load_config_file(cmd, "", 0))
return_0;
- _load_config_file(cmd, "", 1);
-
return 1;
}
@@ -1697,6 +1695,10 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived,
if (!_init_tags(cmd, cmd->cft))
goto_out;
+ /* Load lvmlocal.conf */
+ if (*cmd->system_dir && !_load_config_file(cmd, "", 1))
+ return_0;
+
if (!_init_tag_configs(cmd))
goto_out;
@@ -1904,6 +1906,10 @@ int refresh_toolcontext(struct cmd_context *cmd)
if (!_init_tags(cmd, cft_tmp))
return_0;
+ /* Load lvmlocal.conf */
+ if (*cmd->system_dir && !_load_config_file(cmd, "", 1))
+ return_0;
+
/* Doesn't change cmd->cft */
if (!_init_tag_configs(cmd))
return_0;
9 years, 1 month
master - systemid: Require alphanumeric 1st character.
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=0551d1c56e2e90...
Commit: 0551d1c56e2e901a885aba09a94ebc391930bbc5
Parent: a5df78e0f045e374f44be2fad3c09d44d39314f7
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Mon Feb 23 19:47:03 2015 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Mon Feb 23 19:47:03 2015 +0000
systemid: Require alphanumeric 1st character.
Require system ID to begin with an alphanumeric character.
Rename fn to make clear it's only validation for systemid
and always terminate result rather than imposing this on the caller.
---
lib/commands/toolcontext.c | 2 +-
lib/misc/lvm-string.c | 32 +++++++++++---------------------
lib/misc/lvm-string.h | 2 +-
3 files changed, 13 insertions(+), 23 deletions(-)
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 2e15086..190f9bd 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -65,7 +65,7 @@ char *system_id_from_string(struct cmd_context *cmd, const char *str)
if (!(system_id = dm_pool_zalloc(cmd->mem, strlen(str) + 1)))
return NULL;
- copy_valid_chars(str, system_id);
+ copy_systemid_chars(str, system_id);
if (!system_id[0])
return NULL;
diff --git a/lib/misc/lvm-string.c b/lib/misc/lvm-string.c
index 61941b3..5d63858 100644
--- a/lib/misc/lvm-string.c
+++ b/lib/misc/lvm-string.c
@@ -102,46 +102,36 @@ int validate_name(const char *n)
}
/*
- * Copy valid characters from source to destination.
+ * Copy valid systemid characters from source to destination.
* Invalid characters are skipped. Copying is stopped
* when NAME_LEN characters have been copied.
+ * A terminating NUL is appended.
*/
-
-void copy_valid_chars(const char *src, char *dst)
+void copy_systemid_chars(const char *src, char *dst)
{
const char *s = src;
char *d = dst;
int len = 0;
- int i;
char c;
if (!s || !*s)
return;
- /* Omit leading hypens. */
- for (i = 0; i < strlen(src); i++) {
- c = *s;
- if (c != '-')
- break;
+ /* Skip non-alphanumeric starting characters */
+ while (*s && !isalnum(*s))
s++;
- }
-
- for (i = 0; i < strlen(src); i++) {
- c = *s;
- if (!isalnum(c) && c != '.' && c != '_' && c != '-' && c != '+') {
- s++;
+ while ((c = *s++)) {
+ if (!isalnum(c) && c != '.' && c != '_' && c != '-' && c != '+')
continue;
- }
- *d = *s;
- d++;
- s++;
- len++;
+ *d++ = c;
- if (len == NAME_LEN)
+ if (++len >= NAME_LEN)
break;
}
+
+ *d = '\0';
}
static const char *_lvname_has_reserved_prefix(const char *lvname)
diff --git a/lib/misc/lvm-string.h b/lib/misc/lvm-string.h
index 065c19f..251aab8 100644
--- a/lib/misc/lvm-string.h
+++ b/lib/misc/lvm-string.h
@@ -44,7 +44,7 @@ int validate_name(const char *n);
name_error_t validate_name_detailed(const char *n);
int validate_tag(const char *n);
-void copy_valid_chars(const char *src, char *dst);
+void copy_systemid_chars(const char *src, char *dst);
int apply_lvname_restrictions(const char *name);
int is_reserved_lvname(const char *name);
9 years, 1 month