dev-peter-config-profiles - config: add support for loading profiles
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=070ffe7822089eefac9c4ed867ada0ee45634536 Commit: 070ffe7822089eefac9c4ed867ada0ee45634536 Parent: f15a403a256f033d18bd53f8d155cb2686e02a1c Author: Peter Rajnoha <[email protected]> AuthorDate: Tue Jun 25 12:27:04 2013 +0200 Committer: Peter Rajnoha <[email protected]> CommitterDate: Wed Jun 26 16:53:49 2013 +0200
config: add support for loading profiles
This patch adds --profile arg to lvm cmds and adds config/profile_dir configuration setting to select the directory where profile are stored By default it's /etc/lvm/profile.
The profiles are loaded using the new "load_profile" fn and all profiles are stored in a cmd context withing the new "struct profile_params":
struct profile_params {
const char *dir;
struct profile *global_profile;
struct dm_list profiles;
};
...where "dir" is the directory with profiles, "global_profile" is the profile that is set globally via the --profile arg (IOW, not set per VG/LV basis based on metadata record) and the "profiles" is the list with loaded profiles.
--- doc/example.conf.in | 3 + lib/commands/toolcontext.c | 89 +++++++++++++++++++++++++++++++++++++++++- lib/commands/toolcontext.h | 3 + lib/config/config.h | 14 +++++++ lib/config/config_settings.h | 1 + tools/args.h | 1 + tools/lvmcmdline.c | 13 ++++++- 7 files changed, 122 insertions(+), 2 deletions(-)
doc/example.conf.in +3 -0
@@ -23,6 +23,9 @@ config { # If enabled, any configuration mismatch aborts the LVM2 process. abort_on_errors = 0 + + # Directory where LVM looks for configuration profiles. + profile_dir = "@DEFAULT_SYS_DIR@/profiles" } # This section allows you to configure which block devices should
lib/commands/toolcontext.c +88 -1
130 lines not on this page · raw message
lib/commands/toolcontext.h +3 -0
@@ -51,6 +51,7 @@ struct config_info { };struct dm_config_tree ; +struct profile_params ;struct archive_params ;struct backup_params ;struct arg_values ;
@@ -104,6 +105,8 @@ struct cmd_context {struct config_info current_settings;struct dm_hash_table *cft_def_hash;/* cft definition hash used for validity check */ +struct profile_params *profile_params; +struct archive_params *archive_params;struct backup_params *backup_params;const char *stripe_filler;
lib/config/config.h +14 -0
@@ -34,6 +34,18 @@ typedef enum { CONFIG_PROFILE } config_source_t; +struct profile { +struct dm_list list; +const char *name; +struct dm_config_tree *cft; +}; + +struct profile_params { +const char *dir; +struct profile *global_profile; +struct dm_list profiles; +}; +#define CFG_PATH_MAX_LEN 64/*
@@ -114,6 +126,8 @@ enum {#undef cfg_array }; +struct profile *load_profile (struct cmd_context *cmd,const char *profile_name); +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);
lib/config/config_settings.h +1 -0
@@ -68,6 +68,7 @@ cfg_section(tags_CFG_SECTION, "tags", root_CFG_SECTION, 0, vsn(1, 0, 18), NULL) cfg(config_checks_CFG, "checks", config_CFG_SECTION, 0, CFG_TYPE_BOOL, 1, vsn(2, 2, 99), "Configuration tree check on each LVM command execution.") cfg(config_abort_on_errors_CFG, "abort_on_errors", config_CFG_SECTION, 0, CFG_TYPE_BOOL, 0, vsn(2,2,99), "Abort LVM command execution if configuration is invalid.") +cfg(config_profile_dir_CFG, "profile_dir", config_CFG_SECTION, 0, CFG_TYPE_STRING, 0, vsn(2, 2, 99), "Directory with configuration profiles.") cfg(devices_dir_CFG, "dir", devices_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_DEV_DIR, vsn(1, 0, 0), NULL)cfg_array (devices_scan_CFG,"scan" , devices_CFG_SECTION,0 ,CFG_TYPE_STRING ,"#S/dev" ,vsn (1 ,0 ,0 ),NULL )
tools/args.h +1 -0
@@ -91,6 +91,7 @@ arg(writemostly_ARG, '\0', "writemostly", string_arg, ARG_GROUPABLE) arg(writebehind_ARG, '\0', "writebehind", int_arg, 0) arg(minrecoveryrate_ARG, '\0', "minrecoveryrate", size_kb_arg, 0) arg(maxrecoveryrate_ARG, '\0', "maxrecoveryrate", size_kb_arg, 0) +arg (profile_ARG,'\0' ,"profile" , string_arg,0 ) /* Allow some variations */arg (resizable_ARG,'\0' ,"resizable" , yes_no_arg,0 )
tools/lvmcmdline.c +12 -1
@@ -620,7 +620,8 @@ void lvm_register_commands(void) debug_ARG, help_ARG, help2_ARG, \ version_ARG, verbose_ARG, \ yes_ARG, \ - quiet_ARG, config_ARG, -1); + quiet_ARG, config_ARG, \ + profile_ARG, -1);#include "commands.h" #undef xx }
@@ -1051,6 +1052,7 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)int locking_type;int monitoring;struct dm_config_tree *old_cft; +struct profile *profile;init_error_message_produced (0 );
@@ -1091,6 +1093,15 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv) } } +if (arg_count (cmd, profile_ARG)) { +if (!(profile =load_profile (cmd,arg_str_value (cmd, profile_ARG,NULL )))) { +log_error ("Failed to load configuration profile." ); +return ECMD_FAILED ; + } +log_debug ("Setting global configuration profile \"%s\"." , profile->name); + cmd->profile_params->global_profile = profile; + } +if ((ret =_get_settings (cmd))) goto_out;_apply_settings (cmd);