From 0e5beb92c5ca04af8c3a625ac7e50e4ac5e30acf Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Thu, 31 Oct 2024 14:42:16 +0100 Subject: [PATCH] config: introduce validate_metadata Add lvm.conf config/validate_metadata configurable setting. Allows to disable validation of volume_group structure before writing to disk. Call of vg_validate() is supposed to catch any inconsistency of in-memory volume group structure and possibly early aborting commnand before making any more 'damage' in case the VG struct is found insistent after some metadata manipulation. This is almost always useful for devel - and also for normal user as for small metadata size this doesn't add too much overhead. However if the volume_group size is large and operations are just adding removing simple LVs - this validation time may add noticable to final command running time. So if the user seeks the highest perfomance of command and does not do any 'complex' metadata manipulation - it's reasonably safe to disable validation (with the use of setting "none") here. --- conf/example.conf.in | 13 +++++++++++++ lib/commands/toolcontext.c | 11 ++++++++++- lib/commands/toolcontext.h | 1 + lib/config/config_settings.h | 10 ++++++++++ lib/config/defaults.h | 1 + lib/metadata/metadata.c | 9 +++++++-- 6 files changed, 42 insertions(+), 3 deletions(-) diff --git a/conf/example.conf.in b/conf/example.conf.in index c6a0f45ee..fa0777764 100644 --- a/conf/example.conf.in +++ b/conf/example.conf.in @@ -36,6 +36,19 @@ config { # This configuration option has an automatic default value. # checks = 1 + # Configuration option config/validate_metadata. + # Allows to select the level of validation after metadata transformation. + # Validation takes extra CPU time to verify internal consistency. + # Accepted values: + # full + # Do a full metadata validation before disk write. + # none + # Skip any checks (unrecommended, slightly faster). + # + # This configuration option is advanced. + # This configuration option has an automatic default value. + # validate_metadata = "full" + # Configuration option config/abort_on_errors. # Abort the LVM process if a configuration mismatch is found. # This configuration option has an automatic default value. diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c index fa4359456..30fc5d4f2 100644 --- a/lib/commands/toolcontext.c +++ b/lib/commands/toolcontext.c @@ -658,7 +658,7 @@ static int _process_config(struct cmd_context *cmd) { mode_t old_umask; const char *dev_ext_info_src = NULL; - const char *read_ahead; + const char *read_ahead, *validate_metadata; struct stat st; const struct dm_config_node *cn; const struct dm_config_value *cv; @@ -744,6 +744,15 @@ static int _process_config(struct cmd_context *cmd) return 0; } + cmd->vg_write_validates_vg = 1; + if ((validate_metadata = find_config_tree_str(cmd, config_validate_metadata_CFG, NULL))) { + if (!strcasecmp(validate_metadata, "none")) + cmd->vg_write_validates_vg = 0; + else if (strcasecmp(validate_metadata, "full")) + log_warn("WARNING: Ignoring unknown validate_metadata setting: %s.", + validate_metadata); + } + /* * If udev is disabled using DM_DISABLE_UDEV environment * variable, override existing config and hardcode these: diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h index b12f5c37b..ffdd0ee93 100644 --- a/lib/commands/toolcontext.h +++ b/lib/commands/toolcontext.h @@ -218,6 +218,7 @@ struct cmd_context { unsigned device_ids_invalid:1; unsigned device_ids_auto_import:1; unsigned get_vgname_from_options:1; /* used by lvconvert */ + unsigned vg_write_validates_vg:1; /* * Devices and filtering. diff --git a/lib/config/config_settings.h b/lib/config/config_settings.h index c99f9143e..918f229dd 100644 --- a/lib/config/config_settings.h +++ b/lib/config/config_settings.h @@ -214,6 +214,16 @@ cfg(config_checks_CFG, "checks", config_CFG_SECTION, CFG_DEFAULT_COMMENTED, CFG_ "without any warning (a message about the configuration key not being\n" "found is issued in verbose mode only).\n") +cfg(config_validate_metadata_CFG, "validate_metadata", config_CFG_SECTION, CFG_DEFAULT_COMMENTED | CFG_ADVANCED, CFG_TYPE_STRING, DEFAULT_VALIDATE_METADATA, vsn(2, 3, 28), NULL, 0, NULL, + "Allows to select the level of validation after metadata transformation.\n" + "Validation takes extra CPU time to verify internal consistency.\n" + "Accepted values:\n" + " full\n" + " Do a full metadata validation before disk write.\n" + " none\n" + " Skip any checks (unrecommended, slightly faster).\n" + "#\n") + cfg(config_abort_on_errors_CFG, "abort_on_errors", config_CFG_SECTION, CFG_DEFAULT_COMMENTED, CFG_TYPE_BOOL, 0, vsn(2,2,99), NULL, 0, NULL, "Abort the LVM process if a configuration mismatch is found.\n") diff --git a/lib/config/defaults.h b/lib/config/defaults.h index 54dba8191..7dac1c563 100644 --- a/lib/config/defaults.h +++ b/lib/config/defaults.h @@ -33,6 +33,7 @@ #define DEFAULT_ARCHIVE_ENABLED 1 #define DEFAULT_BACKUP_ENABLED 1 +#define DEFAULT_VALIDATE_METADATA "full" /* full | none */ #define DEFAULT_CACHE_FILE_PREFIX "" diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index e56ab12e3..bc5f43c52 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -2951,8 +2951,13 @@ int vg_write(struct volume_group *vg) return 0; } - if (!vg_validate(vg)) - return_0; + if (vg->cmd->vg_write_validates_vg) { + log_debug_metadata("Validating volume group structure."); + if (!vg_validate(vg)) + return_0; + } else + log_debug_metadata("Skipping validation of volume group structure."); + if (vg->status & PARTIAL_VG) { log_error("Cannot update partial volume group %s.", vg->name);