Add module parameter options

The options allow the modules to impose type specific restrictions on the
parameters. This can be used to offload file permission and mandatory
parameter checks to the core.
This commit is contained in:
Markus Mäkelä 2017-01-05 09:13:34 +02:00
parent 2b50ce6548
commit e0ad6188ad
2 changed files with 58 additions and 6 deletions

View File

@ -85,12 +85,22 @@ enum mxs_module_param_type
MXS_MODULE_PARAM_ENUM /**< Enumeration of string values */
};
enum mxs_module_param_options
{
MXS_MODULE_OPT_NONE = 0,
MXS_MODULE_OPT_REQUIRED = (1 << 0), /**< A required parameter */
MXS_MODULE_OPT_PATH_X_OK = (1 << 1), /**< PATH: Execute permission to path required */
MXS_MODULE_OPT_PATH_R_OK = (1 << 2), /**< PATH: Read permission to path required */
MXS_MODULE_OPT_PATH_W_OK = (1 << 3) /**< PATH: Write permission to path required */
};
/** Module parameter declaration */
typedef struct mxs_module_param
{
const char *name; /**< Name of the parameter */
enum mxs_module_param_type type; /**< Type of the parameter */
const char *default_value;
const char *default_value; /**< Default value for the parameter, NULL for no default value */
uint64_t options; /**< Parameter options */
const char **accepted_values; /**< Only for enum values */
} MXS_MODULE_PARAM;

View File

@ -1913,6 +1913,38 @@ process_config_update(CONFIG_CONTEXT *context)
return true;
}
/**
* @brief Check if required parameters are missing
*
* @param name Module name
* @param type Module type
* @param params List of parameters for the object
* @return True if at least one of the required parameters is missing
*/
static bool missing_required_parameters(const char *name, const char *type,
CONFIG_PARAMETER *params)
{
bool rval = false;
const MXS_MODULE *mod = get_module(name, type);
if (mod)
{
for (int i = 0; mod->parameters[i].name; i++)
{
if ((mod->parameters[i].options & MXS_MODULE_OPT_REQUIRED) &&
config_get_param(params, mod->parameters[i].name) == NULL)
{
MXS_ERROR("Mandatory parameter '%s' for module '%s' of type %s is not defined.",
mod->parameters[i].name, name, type);
rval = true;
}
}
}
return rval;
}
/**
* @brief Check that the configuration objects have valid parameters
*
@ -1986,6 +2018,13 @@ check_config_objects(CONFIG_CONTEXT *context)
params = params->next;
}
}
if (module && module_type &&
missing_required_parameters(module, module_type, obj->parameters))
{
rval = false;
}
obj = obj->next;
}
@ -2628,12 +2667,15 @@ static void config_add_defaults(CONFIG_CONTEXT *ctx, const char *module, const c
{
for (int i = 0; mod->parameters[i].name; i++)
{
ss_dassert(config_param_is_valid(module, type, mod->parameters[i].name,
mod->parameters[i].default_value));
if (mod->parameters[i].default_value)
{
ss_dassert(config_param_is_valid(module, type, mod->parameters[i].name,
mod->parameters[i].default_value, ctx));
bool rv = config_add_param(ctx, mod->parameters[i].name,
mod->parameters[i].default_value);
MXS_ABORT_IF_FALSE(rv);
bool rv = config_add_param(ctx, mod->parameters[i].name,
mod->parameters[i].default_value);
MXS_ABORT_IF_FALSE(rv);
}
}
}
}