Replace _apply_settings() after create_toolcontext() with equivalent inline.
PATCH 1/11 Replace _apply_settings() after create_toolcontext() with equivalent inline.
Subsequent patches will refactor / remove each of these lines, as many of them are redundant when called immediately after create_toolcontext().
--- tools/lvmcmdline.c | 18 +++++++++++++++++- 1 files changed, 17 insertions(+), 1 deletions(-)
tools/lvmcmdline.c +17 -1
@@ -1091,7 +1091,23 @@ struct cmd_context *init_lvm(unsigned is_static)if (!(cmd =create_toolcontext (_cmdline.the_args, is_static,0 ))) return_NULL; -_apply_settings (cmd); +init_debug (cmd->current_settings.debug); +init_verbose (cmd->current_settings.verbose +VERBOSE_BASE_LEVEL ); +init_test (cmd->current_settings.test); +init_full_scan_done (0 ); +init_mirror_in_sync (0 ); + +init_msg_prefix (cmd->default_settings.msg_prefix); +init_cmd_name (cmd->default_settings.cmd_name); + +archive_enable (cmd, cmd->current_settings.archive); +backup_enable (cmd, cmd->current_settings.backup); + +set_activation (cmd->current_settings.activation); + + cmd->fmt =arg_ptr_value (cmd, metadatatype_ARG, + cmd->current_settings.fmt); + cmd->handles_missing_pvs =0 ;return cmd; }
Signature · 1 line
1.5.5.1
PATCH 2/11 Remove init_debug() calls immediately after create_toolcontext() call.
We can safely remove because create_toolcontext() calls _init_logging(), which makes these calls:
/* Debug level for log file output */
cmd->default_settings.debug =
find_config_tree_int(cmd, "log/level", DEFAULT_LOGLEVEL);
init_debug(cmd->default_settings.debug);Then at the bottom of create_toolcontext() we do this:
cmd->current_settings = cmd->default_settings;
So the call we are removing from init_lvm() functions (clvmd and lvmcmdline):
init_debug(cmd->current_settings.debug);
Just sets the value of debug based on 'cmd->current_settings.debug'. Since cmd->current_settings is equivalent to cmd->default_settings, and init_debug() was called with cmd->default_settings, the call we remove is redundant.
--- daemons/clvmd/lvm-functions.c | 1 - tools/lvmcmdline.c | 1 - 2 files changed, 0 insertions(+), 2 deletions(-)
daemons/clvmd/lvm-functions.c +0 -1
@@ -732,7 +732,6 @@ int init_lvm(int using_gulm)/* Use LOG_DAEMON for syslog messages instead of LOG_USER */ init_syslog (LOG_DAEMON );openlog ("clvmd" ,LOG_PID ,LOG_DAEMON ); -init_debug (cmd->current_settings.debug);init_verbose (cmd->current_settings.verbose +VERBOSE_BASE_LEVEL );set_activation (cmd->current_settings.activation);archive_enable (cmd, cmd->current_settings.archive);
tools/lvmcmdline.c +0 -1
@@ -1091,7 +1091,6 @@ struct cmd_context *init_lvm(unsigned is_static)if (!(cmd =create_toolcontext (_cmdline.the_args, is_static,0 ))) return_NULL; -init_debug (cmd->current_settings.debug);init_verbose (cmd->current_settings.verbose +VERBOSE_BASE_LEVEL );init_test (cmd->current_settings.test);init_full_scan_done (0 );
Signature · 1 line
1.5.5.1
PATCH 3/11 Remove init_verbose() calls immediately after create_toolcontext() calls.
The rationale for removing init_verbose() call is very similar to removing init_debug() call. create_toolcontext() calls _init_logging() which makes these calls:
/* Verbose level for tty output */
cmd->default_settings.verbose =
find_config_tree_int(cmd, "log/verbose", DEFAULT_VERBOSE);
init_verbose(cmd->default_settings.verbose + VERBOSE_BASE_LEVEL);And being that create_toolcontext() copies default_settings into current_settings at the bottom, the init_verbose() call we are removing:
init_verbose(cmd->current_settings.verbose + VERBOSE_BASE_LEVEL);
is redundant.
--- daemons/clvmd/lvm-functions.c | 1 - tools/lvmcmdline.c | 1 - 2 files changed, 0 insertions(+), 2 deletions(-)
daemons/clvmd/lvm-functions.c +0 -1
@@ -732,7 +732,6 @@ int init_lvm(int using_gulm)/* Use LOG_DAEMON for syslog messages instead of LOG_USER */ init_syslog (LOG_DAEMON );openlog ("clvmd" ,LOG_PID ,LOG_DAEMON ); -init_verbose (cmd->current_settings.verbose +VERBOSE_BASE_LEVEL );set_activation (cmd->current_settings.activation);archive_enable (cmd, cmd->current_settings.archive);backup_enable (cmd, cmd->current_settings.backup);
tools/lvmcmdline.c +0 -1
@@ -1091,7 +1091,6 @@ struct cmd_context *init_lvm(unsigned is_static)if (!(cmd =create_toolcontext (_cmdline.the_args, is_static,0 ))) return_NULL; -init_verbose (cmd->current_settings.verbose +VERBOSE_BASE_LEVEL );init_test (cmd->current_settings.test);init_full_scan_done (0 );init_mirror_in_sync (0 );
Signature · 1 line
1.5.5.1
PATCH 4/11 Remove handles_missing_pvs assignment after call to create_toolcontext().
This variable is set at the top of create_toolcontext() to 0. Nothing later in create_toolcontext() changes the value.
In init_lvm(), nothing between create_toolcontext() call and this assignment changes the value. Thus, the assignment is redundant.
--- tools/lvmcmdline.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
tools/lvmcmdline.c +0 -1
@@ -1105,7 +1105,6 @@ struct cmd_context *init_lvm(unsigned is_static) cmd->fmt =arg_ptr_value (cmd, metadatatype_ARG, cmd->current_settings.fmt); - cmd->handles_missing_pvs =0 ;return cmd; }
Signature · 1 line
1.5.5.1
PATCH 5/11 Move init_test() from _apply_settings into _init_logging().
This one we actually need to move. _init_logging() is called from
create_toolcontext(), which makes this call:
/* Test mode */
cmd->default_settings.test =
find_config_tree_int(cmd, "global/test", 0);But it does not call init_test(). So we need an init_test() somewhere. The most logical place is to put it inside _init_logging(), since this is where the config value is read and default_settings are set. Placing the init_test() call here matches what is done with other variables and seems to make sense.
--- lib/commands/toolcontext.c | 1 + tools/lvmcmdline.c | 1 - 2 files changed, 1 insertions(+), 1 deletions(-)
lib/commands/toolcontext.c +1 -0
@@ -162,6 +162,7 @@ static void _init_logging(struct cmd_context *cmd)/* Test mode */ cmd->default_settings.test =find_config_tree_int (cmd,"global/test" ,0 ); +init_test (cmd->default_settings.test);/* Settings for logging to file */ if (find_config_tree_int (cmd,"log/overwrite" ,DEFAULT_OVERWRITE ))
tools/lvmcmdline.c +0 -1
@@ -1091,7 +1091,6 @@ struct cmd_context *init_lvm(unsigned is_static)if (!(cmd =create_toolcontext (_cmdline.the_args, is_static,0 ))) return_NULL; -init_test (cmd->current_settings.test);init_full_scan_done (0 );init_mirror_in_sync (0 );
Signature · 1 line
1.5.5.1
PATCH 6/11 Remove archive_enable() calls after create_toolcontext() calls.
_init_backup() calls archive_init(), which originally set 'enabled' to a hardcoded '1' value. This seems incorrect based on my read of other areas of the code so here we add a 'enabled' paramter to archive_init(). We pass in cmd->default_settings.archive, which is obtained from the config tree. Later in create_toolcontext, cmd->current_settings is set to cmd->default_settings. The archive_enable() call we remove here was using cmd->current_settings to set the 'archive' enable value. The final value of cmd->archive_params->enabled should thus be equivalent to the original code.
--- daemons/clvmd/lvm-functions.c | 1 - lib/commands/toolcontext.c | 5 +++-- lib/format_text/archiver.c | 5 +++-- lib/format_text/archiver.h | 3 ++- tools/lvmcmdline.c | 1 - 5 files changed, 8 insertions(+), 7 deletions(-)
daemons/clvmd/lvm-functions.c +0 -1
@@ -733,7 +733,6 @@ int init_lvm(int using_gulm)init_syslog (LOG_DAEMON );openlog ("clvmd" ,LOG_PID ,LOG_DAEMON );set_activation (cmd->current_settings.activation); -archive_enable (cmd, cmd->current_settings.archive);backup_enable (cmd, cmd->current_settings.backup); cmd->cmd_line = (char *)"clvmd" ;
lib/commands/toolcontext.c +3 -2
@@ -926,7 +926,7 @@ static int _init_backup(struct cmd_context *cmd)if (!cmd->sys_dir) {log_warn ("WARNING: Metadata changes will NOT be backed up" );backup_init (cmd,"" ); -archive_init (cmd,"" ,0 ,0 ); +archive_init (cmd,"" ,0 ,0 ,0 );return 1 ; }
@@ -952,7 +952,8 @@ static int _init_backup(struct cmd_context *cmd) dir =find_config_tree_str (cmd,"backup/archive_dir" , default_dir); -if (!archive_init (cmd, dir, days, min)) { +if (!archive_init (cmd, dir, days, min, + cmd->default_settings.archive)) {log_debug ("backup_init failed." );return 0 ; }
lib/format_text/archiver.c +3 -2
@@ -36,7 +36,8 @@ struct backup_params { };int archive_init (struct cmd_context *cmd,const char *dir, -unsigned int keep_days,unsigned int keep_min) +unsigned int keep_days,unsigned int keep_min, +int enabled) {if (!(cmd->archive_params =dm_pool_zalloc (cmd->libmem,sizeof (*cmd->archive_params)))) {
@@ -56,7 +57,7 @@ int archive_init(struct cmd_context *cmd, const char *dir, cmd->archive_params->keep_days = keep_days; cmd->archive_params->keep_number = keep_min; - cmd->archive_params->enabled =1 ; + cmd->archive_params->enabled = enabled;return 1 ; }
lib/format_text/archiver.h +2 -1
@@ -32,7 +32,8 @@*/ int archive_init (struct cmd_context *cmd,const char *dir, -unsigned int keep_days,unsigned int keep_min); +unsigned int keep_days,unsigned int keep_min, +int enabled);void archive_exit (struct cmd_context *cmd);void archive_enable (struct cmd_context *cmd,int flag);
tools/lvmcmdline.c +0 -1
@@ -1097,7 +1097,6 @@ struct cmd_context *init_lvm(unsigned is_static)init_msg_prefix (cmd->default_settings.msg_prefix);init_cmd_name (cmd->default_settings.cmd_name); -archive_enable (cmd, cmd->current_settings.archive);backup_enable (cmd, cmd->current_settings.backup);set_activation (cmd->current_settings.activation);
Signature · 1 line
1.5.5.1
PATCH 7/11 Remove backup_enable() calls after create_toolcontext() calls.
Identical argument to previous patch which removed archive_enable() calls. We add a new parameter to backup_init() which sets the enable value based on the cmd->default_settings.backup value. This value was used to set cmd->current_settings.backup, used in the removed backup_enable() call.
--- daemons/clvmd/lvm-functions.c | 1 - lib/commands/toolcontext.c | 4 ++-- lib/format_text/archiver.c | 4 +++- lib/format_text/archiver.h | 2 +- tools/lvmcmdline.c | 2 -- 5 files changed, 6 insertions(+), 7 deletions(-)
daemons/clvmd/lvm-functions.c +0 -1
@@ -733,7 +733,6 @@ int init_lvm(int using_gulm)init_syslog (LOG_DAEMON );openlog ("clvmd" ,LOG_PID ,LOG_DAEMON );set_activation (cmd->current_settings.activation); -backup_enable (cmd, cmd->current_settings.backup); cmd->cmd_line = (char *)"clvmd" ;/* Check lvm.conf is setup for cluster-LVM */
lib/commands/toolcontext.c +2 -2
@@ -925,7 +925,7 @@ static int _init_backup(struct cmd_context *cmd)if (!cmd->sys_dir) {log_warn ("WARNING: Metadata changes will NOT be backed up" ); -backup_init (cmd,"" ); +backup_init (cmd,"" ,0 );archive_init (cmd,"" ,0 ,0 ,0 );return 1 ; }
@@ -973,7 +973,7 @@ static int _init_backup(struct cmd_context *cmd) dir =find_config_tree_str (cmd,"backup/backup_dir" , default_dir); -if (!backup_init (cmd, dir)) { +if (!backup_init (cmd, dir, cmd->default_settings.backup)) {log_debug ("backup_init failed." );return 0 ; }
lib/format_text/archiver.c +3 -1
@@ -150,7 +150,8 @@ int archive_display_file(struct cmd_context *cmd, const char *file)return r; } -int backup_init (struct cmd_context *cmd,const char *dir) +int backup_init (struct cmd_context *cmd,const char *dir, +int enabled) {if (!(cmd->backup_params =dm_pool_zalloc (cmd->libmem,sizeof (*cmd->archive_params)))) {
@@ -166,6 +167,7 @@ int backup_init(struct cmd_context *cmd, const char *dir)log_error ("Couldn't copy backup directory name." );return 0 ; } + cmd->backup_params->enabled = enabled;return 1 ; }
lib/format_text/archiver.h +1 -1
@@ -41,7 +41,7 @@ int archive(struct volume_group *vg);int archive_display (struct cmd_context *cmd,const char *vg_name);int archive_display_file (struct cmd_context *cmd,const char *file); -int backup_init (struct cmd_context *cmd,const char *dir); +int backup_init (struct cmd_context *cmd,const char *dir,int enabled);void backup_exit (struct cmd_context *cmd);void backup_enable (struct cmd_context *cmd,int flag);
tools/lvmcmdline.c +0 -2
@@ -1097,8 +1097,6 @@ struct cmd_context *init_lvm(unsigned is_static)init_msg_prefix (cmd->default_settings.msg_prefix);init_cmd_name (cmd->default_settings.cmd_name); -backup_enable (cmd, cmd->current_settings.backup); -set_activation (cmd->current_settings.activation); cmd->fmt = arg_ptr_value(cmd, metadatatype_ARG,
Signature · 1 line
1.5.5.1
PATCH 8/11 Remove redundant set_activation() call after create_toolcontext() calls.
Very similar argument to removal of init_debug() and other calls.
create_toolcontext() calls _process_config() which sets cmd->default_settings.activation, then calls set_activation(cmd->default_settings.activation). Later, create_toolcontext() sets cmd->current_settings = cmd->default_settings. So these calls set_activation(cmd->current_settings.activation) are redundant.
--- daemons/clvmd/lvm-functions.c | 1 - tools/lvmcmdline.c | 2 -- 2 files changed, 0 insertions(+), 3 deletions(-)
daemons/clvmd/lvm-functions.c +0 -1
@@ -732,7 +732,6 @@ int init_lvm(int using_gulm)/* Use LOG_DAEMON for syslog messages instead of LOG_USER */ init_syslog (LOG_DAEMON );openlog ("clvmd" ,LOG_PID ,LOG_DAEMON ); -set_activation (cmd->current_settings.activation); cmd->cmd_line = (char *)"clvmd" ;/* Check lvm.conf is setup for cluster-LVM */
tools/lvmcmdline.c +0 -2
@@ -1097,8 +1097,6 @@ struct cmd_context *init_lvm(unsigned is_static)init_msg_prefix (cmd->default_settings.msg_prefix);init_cmd_name (cmd->default_settings.cmd_name); -set_activation (cmd->current_settings.activation); - cmd->fmt =arg_ptr_value (cmd, metadatatype_ARG, cmd->current_settings.fmt);
Signature · 1 line
1.5.5.1
PATCH 9/11 Remove redundant init_msg_prefix() and init_cmd_name().
This is very obvious - _init_logging() makes the identical init_msg_prefix() and init_cmd_name() calls with cmd->default_settings so these calls are clearly redundant after calling create_toolcontext().
--- tools/lvmcmdline.c | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-)
tools/lvmcmdline.c +0 -3
@@ -1094,9 +1094,6 @@ struct cmd_context *init_lvm(unsigned is_static)init_full_scan_done (0 );init_mirror_in_sync (0 ); -init_msg_prefix (cmd->default_settings.msg_prefix); -init_cmd_name (cmd->default_settings.cmd_name); - cmd->fmt =arg_ptr_value (cmd, metadatatype_ARG, cmd->current_settings.fmt);
Signature · 1 line
1.5.5.1
PATCH 10/11 Remove redundant init_mirror_in_sync() call in init_lvm().
_mirror_in_sync is statically initialized to 0 in lvm-globals.c, so no need to set it in init_lvm(). Only other callers that may set this are later in execution.
--- tools/lvmcmdline.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-)
tools/lvmcmdline.c +0 -1
@@ -1092,7 +1092,6 @@ struct cmd_context *init_lvm(unsigned is_static) return_NULL;init_full_scan_done (0 ); -init_mirror_in_sync (0 ); cmd->fmt =arg_ptr_value (cmd, metadatatype_ARG, cmd->current_settings.fmt);
Signature · 1 line
1.5.5.1
PATCH 11/11 Move initialization of cmd->fmt into init_formats().
init_formats() sets up the command formats, and currently sets cmd->fmt_backup but does not set cmd->fmt to a default value. This seems incorrect so we set it to cmd->default_settings.fmt before returning.
The call we remove here may set cmd->fmt based on a command line setting. But it is safe to remove this, because the only caller of init_lvm() that cares about the cmdline override is the cmdline tools (clvmd does not care), called from lvm2_main(). After lvm2_main() calls init_lvm(), it later calls lvm_run_command(). In lvm_run_command(), we have a call to _apply_settings(), which has the identical assignment of cmd->fmt that this patch removes.
--- lib/commands/toolcontext.c | 1 + tools/lvmcmdline.c | 3 --- 2 files changed, 1 insertions(+), 3 deletions(-)
lib/commands/toolcontext.c +1 -0
@@ -787,6 +787,7 @@ static int _init_formats(struct cmd_context *cmd)return 1 ; } } + cmd->fmt = cmd->default_settings.fmt;log_error ("_init_formats: Default format (%s) not found" , format);return 0 ;
tools/lvmcmdline.c +0 -3
@@ -1093,9 +1093,6 @@ struct cmd_context *init_lvm(unsigned is_static)init_full_scan_done (0 ); - cmd->fmt =arg_ptr_value (cmd, metadatatype_ARG, - cmd->current_settings.fmt); -return cmd; }
Signature · 1 line
1.5.5.1
PATCH 11/11 Move initialization of cmd->fmt into init_formats().
lib/commands/toolcontext.c static int _init_formats(struct cmd_context *cmd) · line 790
Quoted 9 lines · Dave Wysochanski
lib/commands/toolcontext.c +1
-0@@ -787,6 +787,7 @@ static int _init_formats(struct cmd_context *cmd)return 1 ; } } + cmd->fmt = cmd->default_settings.fmt;
Move up just before the 'return 1' above?
Alasdair
Signature · 1 line
agk at redhat.com
PATCH 11/11 Move initialization of cmd->fmt into init_formats().
Quoted 13 lines · Alasdair G Kergon
lib/commands/toolcontext.c static int _init_formats(struct cmd_context *cmd) · line 790
Quoted 9 lines · Dave Wysochanski
lib/commands/toolcontext.c +1
-0@@ -787,6 +787,7 @@ static int _init_formats(struct cmd_context *cmd)return 1 ; } } + cmd->fmt = cmd->default_settings.fmt;Move up just before the 'return 1' above?
Indeed, that's an error. Nice catch.
PATCH 10/11 Remove redundant init_mirror_in_sync() call in init_lvm().
In reply to Dave WysochanskiQuoted 3 lines · Dave Wysochanski
_mirror_in_syncis statically initialized to 0 inlvm-globals.c, so no need to set it ininit_lvm(). Only other callers that may set this are later in execution.
Can the statics be relied upon if a handle is created, then destroyed then a new handle created within the same process?
It basically depends if that initial value is relied upon anywhere, or if later code always sets this before using it.
Alasdair
Signature · 1 line
agk at redhat.com
PATCH 10/11 Remove redundant init_mirror_in_sync() call in init_lvm().
Quoted 11 lines · Alasdair G Kergon
Quoted 3 lines · Dave Wysochanski
_mirror_in_syncis statically initialized to 0 inlvm-globals.c, so no need to set it ininit_lvm(). Only other callers that may set this are later in execution.Can the statics be relied upon if a handle is created, then destroyed then a new handle created within the same process?
It basically depends if that initial value is relied upon anywhere, or if later code always sets this before using it.
This is a good point. We will have some global state and this needs thought out. We may need to export _apply_settings() or something like it to reset the global state. Or perhaps the global state should be reset at the bottom of create_toolcontext()?
For the the handle re-use case of the existing lvmcmdlib.c, we do a _apply_settings() in lvm_run_command() so the global state is reset. We won't have lvm_run_command() to rely on for liblvm, but I guess we need the equivalent.
PATCH 10/11 Remove redundant init_mirror_in_sync() call in init_lvm().
Quoted 10 lines · Dave Wysochanski
Quoted 8 lines · Alasdair G Kergon
Quoted 3 lines · Dave Wysochanski
_mirror_in_syncis statically initialized to 0 inlvm-globals.c, so no need to set it ininit_lvm(). Only other callers that may set this are later in execution.Can the statics be relied upon if a handle is created, then destroyed then a new handle created within the same process?
It basically depends if that initial value is relied upon anywhere, or if later code always sets this before using it.
Quoted 8 lines
This is a good point. We will have some global state and this needs thought out. We may need to export
_apply_settings()or something like it to reset the global state. Or perhaps the global state should be reset at the bottom ofcreate_toolcontext()?
For the the handle re-use case of the existinglvmcmdlib.c, we do a_apply_settings()inlvm_run_command()so the global state is reset. We won't havelvm_run_command()to rely on for liblvm, but I guess we need the equivalent.
I'm talking *new* handle here - in other words when creating a new handle the code must not rely upon pre-existing values of those static variables: it must initialise them.
Alasdair
Signature · 1 line
agk at redhat.com
PATCH 10/11 Remove redundant init_mirror_in_sync() call in init_lvm().
Quoted 11 lines · Alasdair G Kergon
Quoted 8 lines · Dave Wysochanski
This is a good point. We will have some global state and this needs thought out. We may need to export
_apply_settings()or something like it to reset the global state. Or perhaps the global state should be reset at the bottom ofcreate_toolcontext()?
For the the handle re-use case of the existinglvmcmdlib.c, we do a_apply_settings()inlvm_run_command()so the global state is reset. We won't havelvm_run_command()to rely on for liblvm, but I guess we need the equivalent.
Quoted 4 lines
I'm talking *new* handle here - in other words when creating a new handle the code must not rely upon pre-existing values of those static variables: it must initialise them.
Are there other globals we need to worry about or do you think the create/destroy/create handle scenario will work with the existing variable resets in the code (e.g. _apply_settings())?
PATCH 6/11 Remove archive_enable() calls after create_toolcontext() calls.
In reply to Dave WysochanskiQuoted 3 lines · Dave Wysochanski
The
archive_enable()call we remove
here was usingcmd->current_settingsto set the 'archive' enable value.
Does that make archive_enable() unused?
lib/commands/toolcontext.c static int _init_backup(struct cmd_context *cmd) · line 956
Quoted 3 lines
lib/commands/toolcontext.c +2
-1-if (!archive_init (cmd, dir, days, min)) { +if (!archive_init (cmd, dir, days, min, + cmd->default_settings.archive)) {
Call archive_enable() here instead, or have archive_init() call it internally or comment out the function as unused?
Alasdair
Signature · 1 line
agk at redhat.com
PATCH 6/11 Remove archive_enable() calls after create_toolcontext() calls.
Quoted 7 lines · Alasdair G Kergon
Quoted 3 lines · Dave Wysochanski
The
archive_enable()call we remove
here was usingcmd->current_settingsto set the 'archive' enable value.Does that make
archive_enable()unused?
it's called from _apply_settings() too.
Quoted 7 lines
lib/commands/toolcontext.c static int _init_backup(struct cmd_context *cmd) · line 956
Quoted 3 lines
lib/commands/toolcontext.c +2
-1-if (!archive_init (cmd, dir, days, min)) { +if (!archive_init (cmd, dir, days, min, + cmd->default_settings.archive)) {Call
archive_enable()here instead, or havearchive_init()call it internally or comment out the function as unused?
I can call it internally.