master - config: make it possible to run several instances of configuration check at once
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=f1c292cc38f4ba2e8d9b7272bc1a1ce17bd729a5 Commit: f1c292cc38f4ba2e8d9b7272bc1a1ce17bd729a5 Parent: 8769033e078c79ee4167c5186d7407d1729fd8a4 Author: Peter Rajnoha <[email protected]> AuthorDate: Wed Jun 26 14:53:57 2013 +0200 Committer: Peter Rajnoha <[email protected]> CommitterDate: Tue Jul 2 15:22:11 2013 +0200
config: make it possible to run several instances of configuration check at once
Before, the status of the configuration check (config_def_check fn call) was saved directly in global configuration definitinion array (as part of the cfg_def_item_t/flags)
This patch introduces the "struct cft_check_handle" that defines configuration check parameters as well as separate place to store the status (status here means CFG_USED and CFG_VALID flags, formerly saved in cfg_def_item_t/flags). This struct can hold config check parameters as well as the status for each config tree separately, thus making it possible to run several instances of config_def_check without interference.
--- lib/commands/toolcontext.c | 29 +++++++++++-- lib/commands/toolcontext.h | 2 + lib/config/config.c | 103 +++++++++++++++++++++---------------------- lib/config/config.h | 21 +++++++-- tools/dumpconfig.c | 36 ++++++++++++++- 5 files changed, 127 insertions(+), 64 deletions(-)
lib/commands/toolcontext.c +25 -4
@@ -263,6 +263,29 @@ static int _check_disable_udev(const char *msg) {return 0 ; } +static int _check_config (struct cmd_context *cmd) +{ +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 ; + } + } + + cmd->cft_check_handle->cft = cmd->cft; + +if (!config_def_check (cmd, cmd->cft_check_handle) && +find_config_tree_bool (cmd, config_abort_on_errors_CFG,NULL )) { +log_error ("LVM configuration invalid." ); +return 0 ; + } + +return 1 ; +} +static int _process_config (struct cmd_context *cmd) {mode_t old_umask;
@@ -275,10 +298,8 @@ static int _process_config(struct cmd_context *cmd)int udev_disabled =0 ;char sysfs_dir[PATH_MAX ]; -if (!config_def_check (cmd,0 ,0 ,0 ) &&find_config_tree_bool (cmd, config_abort_on_errors_CFG,NULL )) { -log_error ("LVM configuration invalid." ); -return 0 ; - } +if (!_check_config (cmd)) + return_0;/* umask */ cmd->default_settings.umask =find_config_tree_int (cmd, global_umask_CFG,NULL );
lib/commands/toolcontext.h +2 -0
@@ -102,7 +102,9 @@ struct cmd_context {struct profile_params *profile_params;/* profile handling params including loaded profile configs */ struct dm_config_tree *cft;/* the whole cascade: CONFIG_STRING -> CONFIG_PROFILE -> CONFIG_FILE/CONFIG_MERGED_FILES */ 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;
lib/config/config.c +50 -53
208 lines not on this page · raw message
lib/config/config.h +16 -5
@@ -80,10 +80,6 @@ typedef union {#define CFG_ADVANCED 0x04/* whether the configuraton item is not officially supported */ #define CFG_UNSUPPORTED 0x08 -/* helper flag to mark the item as used in a config tree instance */ -#define CFG_USED 0x10 -/* helper flag to mark the item as valid in a config tree instance */ -#define CFG_VALID 0x20/* configuration definition item structure */ typedef struct cfg_def_item {
@@ -114,6 +110,12 @@ struct config_def_tree_spec {int ignoreunsupported;/* do not include unsupported configs */ }; + +/* flag to mark the item as used in a config tree instance during validation */ +#define CFG_USED 0x01 +/* flag to mark the item as valid in a config tree instance during validation */ +#define CFG_VALID 0x02 +/* * Register ID for each possible item in the configuration tree. */
@@ -131,8 +133,17 @@ struct profile *add_profile(struct cmd_context *cmd, const char *profile_name);int load_profile (struct cmd_context *cmd,struct profile *profile);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 */ +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 */ +uint8_t status[CFG_COUNT ];/* flags for each configuration item - the result of the check */ +}; +int config_def_get_path (char *buf,size_t buf_size,int id); -int config_def_check (struct cmd_context *cmd,int force,int skip,int suppress_messages); +int config_def_check (struct cmd_context *cmd,struct cft_check_handle *handle);int override_config_tree_from_string (struct cmd_context *cmd,const char *config_settings);int override_config_tree_from_profile (struct cmd_context *cmd,struct profile *profile);
tools/dumpconfig.c +34 -2
@@ -31,6 +31,22 @@ static int _get_vsn(struct cmd_context *cmd, unsigned int *major,return 1 ; } +static struct cft_check_handle *_get_cft_check_handle (struct cmd_context *cmd) +{ +struct cft_check_handle *handle = cmd->cft_check_handle; + +if (!handle) { +if (!(handle =dm_pool_zalloc (cmd->libmem,sizeof (*cmd->cft_check_handle)))) { +log_error ("Configuration check handle allocation failed." ); +return NULL ; + } + handle->cft = cmd->cft; + cmd->cft_check_handle = handle; + } + +return handle; +} +int dumpconfig (struct cmd_context *cmd,int argc,char **argv) {const char *file =arg_str_value (cmd, file_ARG,NULL );
@@ -38,6 +54,7 @@ int dumpconfig(struct cmd_context *cmd, int argc, char **argv)unsigned int major, minor, patchlevel;struct config_def_tree_spec tree_spec = {0 };struct dm_config_tree *cft = cmd->cft; +struct cft_check_handle *cft_check_handle;int r =ECMD_PROCESSED ;if (arg_count (cmd, configtype_ARG) &&arg_count (cmd, validate_ARG)) {
@@ -57,7 +74,14 @@ int dumpconfig(struct cmd_context *cmd, int argc, char **argv) tree_spec.ignoreunsupported =1 ;if (arg_count (cmd, validate_ARG)) { -if (config_def_check (cmd,1 ,1 ,0 )) { +if (!(cft_check_handle =_get_cft_check_handle (cmd))) +return ECMD_FAILED ; + + cft_check_handle->force_check =1 ; + cft_check_handle->skip_if_checked =1 ; + cft_check_handle->suppress_messages =0 ; + +if (config_def_check (cmd, cft_check_handle)) {log_print ("LVM configuration valid." );return ECMD_PROCESSED ; }else {
@@ -72,7 +96,15 @@ int dumpconfig(struct cmd_context *cmd, int argc, char **argv)return EINVALID_CMD_LINE ; } tree_spec.type =CFG_DEF_TREE_CURRENT ; -config_def_check (cmd,1 ,1 ,1 ); + +if (!(cft_check_handle =_get_cft_check_handle (cmd))) +return ECMD_FAILED ; + + cft_check_handle->force_check =1 ; + cft_check_handle->skip_if_checked =1 ; + cft_check_handle->suppress_messages =1 ; + +config_def_check (cmd, cft_check_handle); }else if (!strcmp (type,"default" ))