Skip to contentSkip to conversation

master - config: differentiate command and metadata profiles and consolidate profile handling code

PATCH Peter Rajnoha 1 participant 1 message May 20, 2014

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=9e3e4d69944f072742fd13c5ac74d68e41a3db55
Commit:        9e3e4d69944f072742fd13c5ac74d68e41a3db55
Parent:        c5fbd2c59f1248b1315aae71dee032878d8476f8
Author:        Peter Rajnoha <[email protected]>
AuthorDate:    Tue May 20 14:13:10 2014 +0200
Committer:     Peter Rajnoha <[email protected]>
CommitterDate: Tue May 20 16:21:48 2014 +0200

config: differentiate command and metadata profiles and consolidate profile handling code

- When defining configuration source, the code now uses separate CONFIG_PROFILE_COMMAND and CONFIG_PROFILE_METADATA markers (before, it was just CONFIG_PROFILE that did not make the difference between the two). This helps when checking the configuration if it contains correct set of options which are all in either command-profilable or metadata-profilable group without mixing these groups together - so it's a firm distinction. The "command profile" can't contain "metadata profile" and vice versa! This is strictly checked and if the settings are mixed, such profile is rejected and it's not used. So in the end, the CONFIG_PROFILE_COMMAND set of options and CONFIG_PROFILE_METADATA are mutually exclusive sets.

- Marking configuration with one or the other marker will also determine the way these configuration sources are positioned in the configuration cascade which is now:

CONFIG_STRING -> CONFIG_PROFILE_COMMAND -> CONFIG_PROFILE_METADATA -> CONFIG_FILE/CONFIG_MERGED_FILES

- Marking configuration with one or the other marker will also make it possible to issue a command context refresh (will be probably a part of a future patch) if needed for settings in global profile set. For settings in metadata profile set this is impossible since we can't refresh cmd context in the middle of reading VG/LV metadata and for each VG/LV separately because each VG/LV can have a different metadata profile assinged and it's not possible to change these settings at this level.

- When command profile is incorrect, it's rejected *and also* the command exits immediately - the profile *must* be correct for the command that was run with a profile to be executed. Before this patch, when the profile was found incorrect, there was just the warning message and the command continued without profile applied. But it's more correct to exit immediately in this case.

- When metadata profile is incorrect, we reject it during command runtime (as we know the profile name from metadata and not early from command line as it is in case of command profiles) and we *do continue* with the command as we're in the middle of operation. Also, the metadata profile is applied directly and on the fly on find_config_tree_* fn call and even if the metadata profile is found incorrect, we still need to return the non-profiled value as found in the other configuration provided or default value. To exit immediately even in this case, we'd need to refactor existing find_config_tree_* fns so they can return error. Currently, these fns return only config values (which end up with default values in the end if the config is not found).

- To check the profile validity before use to be sure it's correct, one can use :

    lvm dumpconfig --commandprofile/--metadataprofile ProfileName --validate

(the --commandprofile/--metadataprofile for dumpconfig will come
as part of the subsequent patch)

- This patch also adds a reference to --commandprofile and --metadataprofile in the cmd help string (which was missing before for the --profile for some commands). We do not mention --profile now as people should use --commandprofile or --metadataprofile directly. However, the --profile is still supported for backward compatibility and it's translated as:

--profile == --metadataprofile for lvcreate, vgcreate, lvchange and vgchange
(as these commands are able to attach profile to metadata)

--profile == --commandprofile for all the other commands
(--metadataprofile is not allowed there as it makes no sense)

- This patch also contains some cleanups to make the code handling the profiles more readable...

---
 WHATS_NEW                     |    3 +
 lib/commands/toolcontext.c    |   20 ++-
 lib/config/config.c           |  322 ++++++++++++++++++++++++++++++-----------
 lib/config/config.h           |   15 +-
 lib/format_text/import_vsn1.c |    4 +-
 lib/metadata/lv_manip.c       |    2 +-
 lib/mm/memlock.c              |    2 +-
 tools/args.h                  |    2 +
 tools/commands.h              |  101 ++++++++++---
 tools/lvchange.c              |   22 ++-
 tools/lvmcmdline.c            |  141 ++++++++++++++++---
 tools/vgchange.c              |   14 ++-
 tools/vgcreate.c              |    2 +-
 13 files changed, 495 insertions(+), 155 deletions(-)
WHATS_NEW +3 -0
index 6cbd622..b57a1c3 100644
@@ -1,5 +1,8 @@
 Version 2.02.107 - 
 ==================================
+  Exit immediately with error if command profile is found invalid.
+  Separate --profile cmd line arg into --commandprofile and --metadataprofile.
+  Strictly separate command profiles and per-VG/LV profiles referenced in mda.
   Fix dumpconfig --type diff when run as second and later cmd in lvm shell.
   Fix wrong profile reuse from previous run if another cmd is run in lvm shell.
   Move cache description from lvm(8) to lvmcache(7) man page.
lib/commands/toolcontext.c +14 -6
index 904ae83..519d36a 100644
@@ -717,7 +717,8 @@ static void _destroy_config(struct cmd_context *cmd)
 
 	/* CONFIG_PROFILE */
 	if (cmd->profile_params) {
-		remove_config_tree_by_source(cmd, CONFIG_PROFILE);
+		remove_config_tree_by_source(cmd, CONFIG_PROFILE_COMMAND);
+		remove_config_tree_by_source(cmd, CONFIG_PROFILE_METADATA);
 		/*
 		 * Destroy config trees for any loaded profiles and
 		 * move these profiles to profile_to_load list.
@@ -1605,7 +1606,7 @@ int refresh_filters(struct cmd_context *cmd)
 int refresh_toolcontext(struct cmd_context *cmd)
 {
 	struct dm_config_tree *cft_cmdline, *cft_tmp;
-	const char *profile_name;
+	const char *profile_command_name, *profile_metadata_name;
 	struct profile *profile;
 
 	log_verbose("Reloading config files");
@@ -1633,8 +1634,10 @@ int refresh_toolcontext(struct cmd_context *cmd)
 	cft_cmdline = remove_config_tree_by_source(cmd, CONFIG_STRING);
 
 	/* save the global profile name used */
-	profile_name = cmd->profile_params->global_profile ?
-			cmd->profile_params->global_profile->name : NULL;
+	profile_command_name = cmd->profile_params->global_command_profile ?
+				cmd->profile_params->global_command_profile->name : NULL;
+	profile_metadata_name = cmd->profile_params->global_metadata_profile ?
+				cmd->profile_params->global_metadata_profile->name : NULL;
 
 	_destroy_config(cmd);
 
@@ -1653,8 +1656,13 @@ int refresh_toolcontext(struct cmd_context *cmd)
 		cmd->cft = dm_config_insert_cascaded_tree(cft_cmdline, cft_tmp);
 
 	/* Reload the global profile. */
-	if (profile_name) {
-		if (!(profile = add_profile(cmd, profile_name)) ||
+	if (profile_command_name) {
+		if (!(profile = add_profile(cmd, profile_command_name, CONFIG_PROFILE_COMMAND)) ||
+		    !override_config_tree_from_profile(cmd, profile))
+			return_0;
+	}
+	if (profile_metadata_name) {
+		if (!(profile = add_profile(cmd, profile_metadata_name, CONFIG_PROFILE_METADATA)) ||
 		    !override_config_tree_from_profile(cmd, profile))
 			return_0;
 	}
lib/config/config.c +235 -87

546 lines not on this page · raw message

lib/config/config.h +9 -6
index f06fb68..0618045 100644
@@ -30,21 +30,24 @@ typedef enum {
 	CONFIG_FILE,		/* one file config */
 	CONFIG_MERGED_FILES,	/* config that is a result of merging more config files */
 	CONFIG_STRING,		/* config string typed on cmdline using '--config' arg */
-	CONFIG_PROFILE,		/* profile config */
+	CONFIG_PROFILE_COMMAND,	/* command profile config */
+	CONFIG_PROFILE_METADATA,/* metadata profile config */
 	CONFIG_FILE_SPECIAL	/* special purpose file config (e.g. metadata, persistent filter...) */
 } config_source_t;
 
 struct profile {
 	struct dm_list list;
+	config_source_t source; /* either CONFIG_PROFILE_COMMAND or CONFIG_PROFILE_METADATA */
 	const char *name;
 	struct dm_config_tree *cft;
 };
 
 struct profile_params {
-	char dir[PATH_MAX];             /* 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 */
+	char dir[PATH_MAX];                      /* subdir in LVM_SYSTEM_DIR where LVM looks for profiles */
+	struct profile *global_command_profile;  /* profile (as given by --commandprofile cmd arg) used as global command profile */
+	struct profile *global_metadata_profile; /* profile (as given by --metadataprofile cmd arg) that overrides any other VG/LV-based profile */
+	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
@@ -166,7 +169,7 @@ enum {
 #undef cfg_array_runtime
 };
 
-struct profile *add_profile(struct cmd_context *cmd, const char *profile_name);
+struct profile *add_profile(struct cmd_context *cmd, const char *profile_name, config_source_t source);
 int load_profile(struct cmd_context *cmd, struct profile *profile);
 int load_pending_profiles(struct cmd_context *cmd);
 
lib/format_text/import_vsn1.c +2 -2
index 59603bb..7d4304e 100644
@@ -576,7 +576,7 @@ static int _read_lvnames(struct format_instance *fid __attribute__((unused)),
 	if (dm_config_get_str(lvn, "profile", &str)) {
 		log_debug_metadata("Adding profile configuration %s for LV %s/%s.",
 				   str, vg->name, lv->name);
-		lv->profile = add_profile(vg->cmd, str);
+		lv->profile = add_profile(vg->cmd, str, CONFIG_PROFILE_METADATA);
 		if (!lv->profile) {
 			log_error("Failed to add configuration profile %s for LV %s/%s",
 				  str, vg->name, lv->name);
@@ -814,7 +814,7 @@ static struct volume_group *_read_vg(struct format_instance *fid,
 
 	if (dm_config_get_str(vgn, "profile", &str)) {
 		log_debug_metadata("Adding profile configuration %s for VG %s.", str, vg->name);
-		vg->profile = add_profile(vg->cmd, str);
+		vg->profile = add_profile(vg->cmd, str, CONFIG_PROFILE_METADATA);
 		if (!vg->profile) {
 			log_error("Failed to add configuration profile %s for VG %s", str, vg->name);
 			goto bad;
lib/metadata/lv_manip.c +1 -1
index 0eaa719..91a15f2 100644
@@ -4525,7 +4525,7 @@ struct logical_volume *lv_create_empty(const char *name,
 		goto_bad;
 
 	if (vg->fid->fmt->features & FMT_CONFIG_PROFILE)
-		lv->profile = vg->cmd->profile_params->global_profile;
+		lv->profile = vg->cmd->profile_params->global_metadata_profile;
  
 	return lv;
 bad:
lib/mm/memlock.c +1 -1
index 5382b69..84b93db 100644
@@ -417,7 +417,7 @@ void critical_section_inc(struct cmd_context *cmd, const char *reason)
 	 * entering the critical section all needed profiles are
 	 * loaded to avoid the disk access later.
 	 */
-	load_pending_profiles(cmd);
+	(void) load_pending_profiles(cmd);
 
 	if (!_critical_section) {
 		_critical_section = 1;
tools/args.h +2 -0
index 2e63adb..6a594c3 100644
@@ -99,6 +99,8 @@ arg(minrecoveryrate_ARG, '\0', "minrecoveryrate", size_kb_arg, 0)
 arg(raidminrecoveryrate_ARG, '\0', "raidminrecoveryrate", size_kb_arg, 0)
 arg(maxrecoveryrate_ARG, '\0', "maxrecoveryrate", size_kb_arg, 0)
 arg(raidmaxrecoveryrate_ARG, '\0', "raidmaxrecoveryrate", size_kb_arg, 0)
+arg(commandprofile_ARG, '\0', "commandprofile", string_arg, 0)
+arg(metadataprofile_ARG, '\0', "metadataprofile", string_arg, 0)
 arg(profile_ARG, '\0', "profile", string_arg, 0)
 arg(detachprofile_ARG, '\0', "detachprofile", NULL, 0)
 arg(mergedconfig_ARG, '\0', "mergedconfig", NULL, 0)
tools/commands.h +79 -22

492 lines not on this page · raw message

tools/lvchange.c +15 -7
index bddc079..48e48d4 100644
@@ -898,8 +898,11 @@ static int lvchange_profile(struct logical_volume *lv)
 		new_profile_name = "(inherited)";
 		lv->profile = NULL;
 	} else {
-		new_profile_name = arg_str_value(lv->vg->cmd, profile_ARG, NULL);
-		if (!(new_profile = add_profile(lv->vg->cmd, new_profile_name)))
+		if (arg_count(lv->vg->cmd, metadataprofile_ARG))
+			new_profile_name = arg_str_value(lv->vg->cmd, metadataprofile_ARG, NULL);
+		else
+			new_profile_name = arg_str_value(lv->vg->cmd, profile_ARG, NULL);
+		if (!(new_profile = add_profile(lv->vg->cmd, new_profile_name, CONFIG_PROFILE_METADATA)))
 			return_0;
 		lv->profile = new_profile;
 	}
@@ -944,7 +947,8 @@ static int _lvchange_single(struct cmd_context *cmd, struct logical_volume *lv,
 	    (arg_count(cmd, contiguous_ARG) || arg_count(cmd, permission_ARG) ||
 	     arg_count(cmd, readahead_ARG) || arg_count(cmd, persistent_ARG) ||
 	     arg_count(cmd, discards_ARG) || arg_count(cmd, zero_ARG) ||
-	     arg_count(cmd, alloc_ARG) || arg_count(cmd, profile_ARG))) {
+	     arg_count(cmd, alloc_ARG) || arg_count(cmd, profile_ARG) ||
+	     arg_count(cmd, metadataprofile_ARG))) {
 		log_error("Only -a permitted with read-only volume "
 			  "group \"%s\"", lv->vg->name);
 		return EINVALID_CMD_LINE;
@@ -958,7 +962,8 @@ static int _lvchange_single(struct cmd_context *cmd, struct logical_volume *lv,
 	if (lv_is_origin(lv) && !lv_is_thin_volume(lv) &&
 	    (arg_count(cmd, contiguous_ARG) || arg_count(cmd, permission_ARG) ||
 	     arg_count(cmd, readahead_ARG) || arg_count(cmd, persistent_ARG) ||
-	     arg_count(cmd, alloc_ARG) || arg_count(cmd, profile_ARG))) {
+	     arg_count(cmd, alloc_ARG) || arg_count(cmd, profile_ARG) ||
+	     arg_count(cmd, metadataprofile_ARG))) {
 		log_error("Can't change logical volume \"%s\" under snapshot",
 			  lv->name);
 		return ECMD_FAILED;
@@ -1108,7 +1113,8 @@ static int _lvchange_single(struct cmd_context *cmd, struct logical_volume *lv,
 	}
 
 	/* change configuration profile */
-	if (arg_count(cmd, profile_ARG) || arg_count(cmd, detachprofile_ARG)) {
+	if (arg_count(cmd, profile_ARG) || arg_count(cmd, metadataprofile_ARG) ||
+	    arg_count(cmd, detachprofile_ARG)) {
 		if (!archive(lv->vg))
 			return_ECMD_FAILED;
 		doit += lvchange_profile(lv);
@@ -1170,6 +1176,7 @@ int lvchange(struct cmd_context *cmd, int argc, char **argv)
 		arg_count(cmd, persistent_ARG) ||
 		arg_count(cmd, addtag_ARG) ||
 		arg_count(cmd, deltag_ARG) ||
+		arg_count(cmd, metadataprofile_ARG) ||
 		arg_count(cmd, profile_ARG) ||
 		arg_count(cmd, detachprofile_ARG) ||
 		arg_count(cmd, setactivationskip_ARG);
@@ -1194,8 +1201,9 @@ int lvchange(struct cmd_context *cmd, int argc, char **argv)
 		return EINVALID_CMD_LINE;
 	}
 
-	if (arg_count(cmd, profile_ARG) && arg_count(cmd, detachprofile_ARG)) {
-		log_error("Only one of --profile and --detachprofile permitted.");
+	if ((arg_count(cmd, profile_ARG) || arg_count(cmd, metadataprofile_ARG)) &&
+	     arg_count(cmd, detachprofile_ARG)) {
+		log_error("Only one of --metadataprofile and --detachprofile permitted.");
 		return EINVALID_CMD_LINE;
 	}
 
tools/lvmcmdline.c +123 -18

168 lines not on this page · raw message

tools/vgchange.c +10 -4
index d24b17e..05e7aea 100644
@@ -441,8 +441,11 @@ static int _vgchange_profile(struct cmd_context *cmd,
 		new_profile_name = "(no profile)";
 		vg->profile = NULL;
 	} else {
-		new_profile_name = arg_str_value(cmd, profile_ARG, NULL);
-		if (!(new_profile = add_profile(cmd, new_profile_name)))
+		if (arg_count(cmd, metadataprofile_ARG))
+			new_profile_name = arg_str_value(cmd, metadataprofile_ARG, NULL);
+		else
+			new_profile_name = arg_str_value(cmd, profile_ARG, NULL);
+		if (!(new_profile = add_profile(cmd, new_profile_name, CONFIG_PROFILE_METADATA)))
 			return_0;
 		vg->profile = new_profile;
 	}
@@ -473,6 +476,7 @@ static int vgchange_single(struct cmd_context *cmd, const char *vg_name,
 		{ alloc_ARG, &_vgchange_alloc },
 		{ clustered_ARG, &_vgchange_clustered },
 		{ vgmetadatacopies_ARG, &_vgchange_metadata_copies },
+		{ metadataprofile_ARG, &_vgchange_profile },
 		{ profile_ARG, &_vgchange_profile},
 		{ detachprofile_ARG, &_vgchange_profile},
 	};
@@ -547,6 +551,7 @@ int vgchange(struct cmd_context *cmd, int argc, char **argv)
 	int update_partial_safe =
 		arg_count(cmd, deltag_ARG) ||
 		arg_count(cmd, addtag_ARG) ||
+		arg_count(cmd, metadataprofile_ARG) ||
 		arg_count(cmd, profile_ARG) ||
 		arg_count(cmd, detachprofile_ARG);
 	int update_partial_unsafe =
@@ -572,8 +577,9 @@ int vgchange(struct cmd_context *cmd, int argc, char **argv)
 		return EINVALID_CMD_LINE;
 	}
 
-	if (arg_count(cmd, profile_ARG) && arg_count(cmd, detachprofile_ARG)) {
-		log_error("Only one of --profile and --detachprofile permitted.");
+	if ((arg_count(cmd, profile_ARG) || arg_count(cmd, metadataprofile_ARG)) &&
+	     arg_count(cmd, detachprofile_ARG)) {
+		log_error("Only one of --metadataprofile and --detachprofile permitted.");
 		return EINVALID_CMD_LINE;
 	}
 
tools/vgcreate.c +1 -1
index 45f4c04..9d701c8 100644
@@ -63,7 +63,7 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
 	}
 
 	if (vg->fid->fmt->features & FMT_CONFIG_PROFILE)
-		vg->profile = vg->cmd->profile_params->global_profile;
+		vg->profile = vg->cmd->profile_params->global_metadata_profile;
 
 	if (!vg_set_extent_size(vg, vp_new.extent_size) ||
 	    !vg_set_max_lv(vg, vp_new.max_lv) ||