File bug-1063051_0002-refactor-toolcontext-add-struct-cmd_context_initiali.patch of Package lvm2.7683

From 52ac7a78fde508fc1ffb2c15b15ee9aa30bd2b3d Mon Sep 17 00:00:00 2001
From: Peter Rajnoha <prajnoha@redhat.com>
Date: Thu, 30 Jul 2015 09:59:39 +0200
Subject: [PATCH 03/10] refactor: toolcontext: add struct
 cmd_context_initialized_parts

Add struct cmd_context_initialized_parts to wrap up information
about which cmd context pieces are initialized and add variable
of this struct type into struct cmd_context.

Also, move existing "config_initialized" variable that was directly
part of cmd_context into the new cmd_context.initialized wrapper.

We'll be adding more items into the struct cmd_context_initialized_parts
with subsequent patches...

(cherry picked from commit 6b0c464a3462c568931c22fe71cc4f80b7ead508)
---
 daemons/clvmd/lvm-functions.c | 2 +-
 lib/commands/toolcontext.c    | 8 ++++----
 lib/commands/toolcontext.h    | 8 +++++++-
 tools/lvmcmdline.c            | 2 +-
 4 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/daemons/clvmd/lvm-functions.c b/daemons/clvmd/lvm-functions.c
index a5c1fc5..2446fd1 100644
--- a/daemons/clvmd/lvm-functions.c
+++ b/daemons/clvmd/lvm-functions.c
@@ -513,7 +513,7 @@ int do_lock_lv(unsigned char command, unsigned char lock_flags, char *resource)
 	DEBUGLOG("do_lock_lv: resource '%s', cmd = %s, flags = %s, critical_section = %d\n",
 		 resource, decode_locking_cmd(command), decode_flags(lock_flags), critical_section());
 
-	if (!cmd->config_initialized || config_files_changed(cmd)) {
+	if (!cmd->initialized.config || config_files_changed(cmd)) {
 		/* Reinitialise various settings inc. logging, filters */
 		if (do_refresh_cache()) {
 			log_error("Updated config file invalid. Aborting.");
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index b688c3b..55fd493 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -1804,9 +1804,9 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived,
 	cmd->default_settings.cache_vgmetadata = 1;
 	cmd->current_settings = cmd->default_settings;
 
-	cmd->config_initialized = 1;
+	cmd->initialized.config = 1;
 out:
-	if (!cmd->config_initialized) {
+	if (!cmd->initialized.config) {
 		destroy_toolcontext(cmd);
 		cmd = NULL;
 	}
@@ -1932,7 +1932,7 @@ int refresh_toolcontext(struct cmd_context *cmd)
 
 	_destroy_config(cmd);
 
-	cmd->config_initialized = 0;
+	cmd->initialized.config = 0;
 
 	cmd->hosttags = 0;
 
@@ -2010,7 +2010,7 @@ int refresh_toolcontext(struct cmd_context *cmd)
 	if (!_init_backup(cmd))
 		return_0;
 
-	cmd->config_initialized = 1;
+	cmd->initialized.config = 1;
 
 	reset_lvm_errno(1);
 	return 1;
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index afe033f..38a2c31 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -60,6 +60,10 @@ struct config_tree_list {
 	struct dm_config_tree *cft;
 };
 
+struct cmd_context_initialized_parts {
+	unsigned config:1; /* used to reinitialize config if previous init was not successful */
+};
+
 /* FIXME Split into tool & library contexts */
 /* command-instance-related variables needed by library */
 struct cmd_context {
@@ -82,6 +86,9 @@ struct cmd_context {
 	char **argv;
 	struct arg_values *arg_values;
 	struct dm_list arg_value_groups;
+
+	struct cmd_context_initialized_parts initialized;
+
 	unsigned is_long_lived:1;	/* Optimises persistent_filter handling */
 	unsigned check_pv_dev_sizes:1;
 	unsigned handles_missing_pvs:1;
@@ -125,7 +132,6 @@ struct cmd_context {
 	struct dm_list config_files; /* master lvm config + any existing tag configs */
 	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) */
 
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 78974df..6374ae6 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -1443,7 +1443,7 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
 			goto_out;
 		}
 
-	if (arg_count(cmd, config_ARG) || !cmd->config_initialized || config_files_changed(cmd)) {
+	if (arg_count(cmd, config_ARG) || !cmd->initialized.config || config_files_changed(cmd)) {
 		/* Reinitialise various settings inc. logging, filters */
 		if (!refresh_toolcontext(cmd)) {
 			if ((config_string_cft = remove_config_tree_by_source(cmd, CONFIG_STRING)))
-- 
2.10.2

openSUSE Build Service is sponsored by