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

config: add validation for configuration profiles

Besides the classical configuration checks (type checking and
checking whether the item is recognized by lvm tools) for profiles,
do an extra check whether the configuration setting is customizable
by a profile at all. Give a warning message if not.
This commit is contained in:
Peter Rajnoha 2013-06-26 16:27:28 +02:00
parent f1c292cc38
commit e8832917f6
3 changed files with 43 additions and 1 deletions

View File

@ -654,6 +654,19 @@ static int _config_def_check_node(struct cft_check_handle *handle,
if (!_config_def_check_node_value(handle, rp, cn->v, def))
return 0;
/*
* Also check whether this configuration item is allowed
* in certain types of configuration trees as in some
* the use of configuration is restricted, e.g. profiles...
*/
if (handle->source == CONFIG_PROFILE &&
!(def->flags & CFG_PROFILABLE)) {
log_warn_suppress(handle->suppress_messages,
"Configuration %s \"%s\" is not customizable by "
"a profile.", cn->v ? "option" : "section", rp);
return 0;
}
handle->status[def->id] |= CFG_VALID;
return 1;
}
@ -1405,6 +1418,29 @@ struct dm_config_tree *config_def_create_tree(struct config_def_tree_spec *spec)
return cft;
}
static int _check_profile(struct cmd_context *cmd, struct profile *profile)
{
struct cft_check_handle *handle;
int r;
if (!(handle = dm_pool_zalloc(cmd->libmem, sizeof(*handle)))) {
log_debug("_check_profile: profile check handle allocation failed");
return 0;
}
handle->cft = profile->cft;
handle->source = CONFIG_PROFILE;
/* the check is compulsory - allow only profilable items in a profile config! */
handle->force_check = 1;
/* provide warning messages only if config/checks=1 */
handle->suppress_messages = !find_config_tree_bool(cmd, config_checks_CFG, NULL);
r = config_def_check(cmd, handle);
dm_pool_free(cmd->libmem, handle);
return r;
}
struct profile *add_profile(struct cmd_context *cmd, const char *profile_name)
{
struct profile *profile;
@ -1464,6 +1500,8 @@ int load_profile(struct cmd_context *cmd, struct profile *profile) {
dm_list_move(&cmd->profile_params->profiles, &profile->list);
(void) _check_profile(cmd, profile);
return 1;
}

View File

@ -78,8 +78,10 @@ typedef union {
#define CFG_ALLOW_EMPTY 0x02
/* whether the configuration item is for advanced use only */
#define CFG_ADVANCED 0x04
/* whether the configuraton item is not officially supported */
/* whether the configuration item is not officially supported */
#define CFG_UNSUPPORTED 0x08
/* whether the configuration item is customizable by a profile */
#define CFG_PROFILABLE 0x10
/* configuration definition item structure */
typedef struct cfg_def_item {
@ -136,6 +138,7 @@ int load_pending_profiles(struct cmd_context *cmd);
/* configuration check handle for each instance of the validation check */
struct cft_check_handle {
struct dm_config_tree *cft; /* the tree for which the check is done */
config_source_t source; /* configuration source */
unsigned force_check:1; /* force check even if disabled by config/checks setting */
unsigned skip_if_checked:1; /* skip the check if already done before - return last state */
unsigned suppress_messages:1; /* suppress messages during the check if config item is found invalid */

View File

@ -31,6 +31,7 @@
* CFG_ALLOW_EMPTY - node value can be emtpy
* CFG_ADVANCED - this node belongs to advanced config set
* CFG_UNSUPPORTED - this node belongs to unsupported config set
* CFG_PROFILABLE - this node is customizable by a profile
* type: allowed type for the value of simple configuation setting
* types: allowed types for the values of array configuration setting
* (use logical "OR" to define more than one allowed type,