1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-08-03 08:22:00 +03:00

config: attach cft_check_handle to each config tree instead of global cmd_context

Before, the cft_check_handle used to direct configuration checking
was part of cmd_context. It's better to attach this as part of the
exact config tree against which the check is done. This patch moves
the cft_check_handle out of cmd_context and it attaches it to the
config tree directly as dm_config_tree->custom->config_source->check_handle.

This change makes it easier to track the config tree check results
and provides less space for bugs as the results are directly attached
to the tree and we don't need to be cautious whether the global value
is correct or not (and whether it needs reinitialization) as it was
in the case when the cft_check_handle was part of cmd_context.
This commit is contained in:
Peter Rajnoha
2014-05-19 13:23:12 +02:00
parent ff9d27a1c7
commit c42f72867a
5 changed files with 90 additions and 53 deletions

View File

@ -256,24 +256,32 @@ static int _check_disable_udev(const char *msg) {
return 0;
}
static int _check_config_by_source(struct cmd_context *cmd, config_source_t source)
{
struct dm_config_tree *cft;
struct cft_check_handle *handle;
if (!(cft = get_config_tree_by_source(cmd, source)) ||
!(handle = get_config_tree_check_handle(cmd, cft)))
return 1;
return config_def_check(handle);
}
static int _check_config(struct cmd_context *cmd)
{
int abort_on_error;
if (!find_config_tree_bool(cmd, config_checks_CFG, NULL))
return 1;
if (!cmd->cft_check_handle) {
if (!(cmd->cft_check_handle = dm_pool_zalloc(cmd->libmem, sizeof(*cmd->cft_check_handle)))) {
log_error("Configuration check handle allocation failed.");
return 0;
}
}
abort_on_error = find_config_tree_bool(cmd, config_abort_on_errors_CFG, NULL);
cmd->cft_check_handle->cft = cmd->cft;
cmd->cft_check_handle->cmd = cmd;
if (!config_def_check(cmd->cft_check_handle) &&
find_config_tree_bool(cmd, config_abort_on_errors_CFG, NULL)) {
log_error("LVM configuration invalid.");
if ((!_check_config_by_source(cmd, CONFIG_STRING) ||
!_check_config_by_source(cmd, CONFIG_MERGED_FILES) ||
!_check_config_by_source(cmd, CONFIG_FILE)) &&
abort_on_error) {
log_error("LVM_ configuration invalid.");
return 0;
}
@ -571,7 +579,7 @@ static int _load_config_file(struct cmd_context *cmd, const char *tag)
return 0;
}
if (!(cfl->cft = config_file_open_and_read(config_file, CONFIG_FILE)))
if (!(cfl->cft = config_file_open_and_read(config_file, CONFIG_FILE, cmd)))
return_0;
dm_list_add(&cmd->config_files, &cfl->list);

View File

@ -105,7 +105,6 @@ struct cmd_context {
int config_initialized; /* used to reinitialize config if previous init was not successful */
struct dm_hash_table *cft_def_hash; /* config definition hash used for validity check (item type + item recognized) */
struct cft_check_handle *cft_check_handle;
/* selected settings with original default/configured value which can be changed during cmd processing */
struct config_info default_settings;