Skip to contentSkip to conversation

master - config: add support for loading profiles

PATCH Peter Rajnoha 1 participant 1 message Jul 2, 2013

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=ebc236d085116e869b5873e2b5409674c2cd2a8d
Commit:        ebc236d085116e869b5873e2b5409674c2cd2a8d
Parent:        f89a8b81cf795d9e658341b4755046b3824acdaa
Author:        Peter Rajnoha <[email protected]>
AuthorDate:    Tue Jun 25 12:27:04 2013 +0200
Committer:     Peter Rajnoha <[email protected]>
CommitterDate: Tue Jul 2 15:19:08 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 profiles are stored By default it's /etc/lvm/profile.

The profiles are added by using new "add_profile" fn and then loaded using the "load_profile" fn. All profiles are stored in a cmd context within the new "struct profile_params":

struct profile_params {
const char *dir;
struct profile *global_profile;
struct dm_list profiles_to_load;
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   |   47 +++++++++++++++++++++++++-
 lib/commands/toolcontext.h   |    3 ++
 lib/config/config.c          |   75 ++++++++++++++++++++++++++++++++++++++++++
 lib/config/config.h          |   17 +++++++++
 lib/config/config_settings.h |    1 +
 lib/mm/memlock.c             |    7 ++++
 tools/args.h                 |    1 +
 tools/lvmcmdline.c           |   14 +++++++-
 9 files changed, 166 insertions(+), 2 deletions(-)
doc/example.conf.in +3 -0
index 1620721..3bc8c3c 100644
@@ -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@/@DEFAULT_PROFILE_SUBDIR"
 }
 
 # This section allows you to configure which block devices should
lib/commands/toolcontext.c +46 -1

80 lines not on this page · raw message

lib/commands/toolcontext.h +3 -0
index f6a09a7..7551245 100644
@@ -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.c +75 -0

84 lines not on this page · raw message

lib/config/config.h +17 -0
index f4c77ed..ef75580 100644
@@ -34,6 +34,19 @@ typedef enum {
 	CONFIG_PROFILE		/* profile config */
 } config_source_t;
 
+struct profile {
+	struct dm_list list;
+	const char *name;
+	struct dm_config_tree *cft;
+};
+
+struct profile_params {
+	const char *dir;                /* subdir in LVM_SYSTEM_DIR where LVM looks for profiles */
+	struct profile *global_profile; /* profile that overrides any other VG/LV-based profile ('--profile' cmd line arg) */
+	struct dm_list profiles_to_load;/* list of profiles which are only added, but still need to be loaded for any use */
+	struct dm_list profiles;	/* list of profiles which are loaded already and which are ready for use */
+};
+
 #define CFG_PATH_MAX_LEN 64
 
 /*
@@ -114,6 +127,10 @@ enum {
 #undef cfg_array
 };
 
+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);
+
 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
index 6229f2e..65d869b 100644
@@ -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)
lib/mm/memlock.c +7 -0
index 08876b0..fda3bb8 100644
@@ -406,6 +406,13 @@ static void _unlock_mem_if_possible(struct cmd_context *cmd)
 
 void critical_section_inc(struct cmd_context *cmd, const char *reason)
 {
+	/*
+	 * Profiles are loaded on-demand so make sure that before
+	 * entering the critical section all needed profiles are
+	 * loaded to avoid the disk access later.
+	 */
+	load_pending_profiles(cmd);
+
 	if (!_critical_section) {
 		_critical_section = 1;
 		log_debug_mem("Entering critical section (%s).", reason);
tools/args.h +1 -0
index 2fed97e..cadd211 100644
@@ -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 +13 -1
index 0372434..1111df6 100644
@@ -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);
 
@@ -1089,6 +1091,16 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
 		}
 	}
 
+	if (arg_count(cmd, profile_ARG)) {
+		if (!(profile = add_profile(cmd, arg_str_value(cmd, profile_ARG, NULL)))) {
+			log_error("Failed to add configuration profile.");
+			return ECMD_FAILED;
+		}
+		log_debug("Setting global configuration profile \"%s\".", profile->name);
+		/* This profile will override any VG/LV-based profile if present */
+		cmd->profile_params->global_profile = profile;
+	}
+
 	if ((ret = _get_settings(cmd)))
 		goto_out;
 	_apply_settings(cmd);