master - refactor: move report grouping and log reporting handles from processing_handle to cmd_context
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=1fde4bf4d08cbf579dbbe5eb08661eac67eb68f7 Commit: 1fde4bf4d08cbf579dbbe5eb08661eac67eb68f7 Parent: ef69934746e7c31aef224129b19ac0cfb8101b5b Author: Peter Rajnoha <[email protected]> AuthorDate: Wed Aug 3 15:37:14 2016 +0200 Committer: Peter Rajnoha <[email protected]> CommitterDate: Tue Aug 9 18:24:45 2016 +0200
refactor: move report grouping and log reporting handles from processing_handle to cmd_context
With patches that will follow, this will make it possible to widen log report coverage when commands are executed from lvm shell so the amount of messages that may end up in stderr/stdout instead of log report are minimized.
--- lib/commands/toolcontext.c | 6 ++- lib/commands/toolcontext.h | 13 ++++++- lib/report/report.h | 4 +-- tools/lvm.c | 10 +++--- tools/reporter.c | 78 ++++++++++++++++++-------------------------- tools/toollib.c | 24 ++++--------- tools/toollib.h | 5 --- 7 files changed, 61 insertions(+), 79 deletions(-)
lib/commands/toolcontext.c +4 -2
@@ -2218,8 +2218,10 @@ void destroy_toolcontext(struct cmd_context *cmd)if (cmd->cft_def_hash)dm_hash_destroy (cmd->cft_def_hash); -if (cmd->log_rh) -dm_report_free (cmd->log_rh); +if (cmd->cmd_report.log_rh) { +dm_report_free (cmd->cmd_report.log_rh); + cmd->cmd_report.log_rh =NULL ; + }if (cmd->libmem)dm_pool_destroy (cmd->libmem);
lib/commands/toolcontext.h +11 -2
@@ -66,6 +66,15 @@ struct cmd_context_initialized_parts { unsigned connections:1; }; +struct cmd_report { +int log_only; +dm_report_group_type_t report_group_type; +struct dm_report_group *report_group; +struct dm_report *log_rh; +const char *log_name; +log_report_t saved_log_report_state; +}; +/* FIXME Split into tool & library contexts */ /* command-instance-related variables needed by library */ struct cmd_context {
@@ -186,9 +195,9 @@ struct cmd_context {char proc_dir[PATH_MAX ];/* -* Command log reporting. +* Reporting. */ -struct dm_report *log_rh;/* keep log report of last cmd for further queries if cmd line is interactive (e.g. lvm shell) */ +struct cmd_report cmd_report;/* * Buffers.
lib/report/report.h +1 -3
@@ -81,9 +81,7 @@ struct processing_handle;typedef int (*field_report_fn ) (struct report_handle * dh,struct field * field,const void *data); -int report_format_init (struct cmd_context *cmd,dm_report_group_type_t *report_group_type, -struct dm_report_group **report_group,struct dm_report **log_rh, -int *log_only,log_report_t *saved_log_report_state); +int report_format_init (struct cmd_context *cmd); void *report_init(struct cmd_context *cmd, const char *format, const char *keys, report_type_t *report_type, const char *separator,
tools/lvm.c +5 -5
@@ -185,12 +185,12 @@ static int _log_shell_command_status(struct cmd_context *cmd, int ret_code) {log_report_t log_state; -if (!cmd->log_rh) +if (!cmd->cmd_report.log_rh)return 1 ; log_state =log_get_report_state (); - return report_cmdlog(cmd->log_rh, REPORT_OBJECT_CMDLOG_NAME, + return report_cmdlog(cmd->cmd_report.log_rh, REPORT_OBJECT_CMDLOG_NAME, log_get_report_context_name(log_state.context), log_get_report_object_type_name(log_state.object_type), log_state.object_name, log_state.object_id,
@@ -263,10 +263,10 @@ int lvm_shell(struct cmd_context *cmd, struct cmdline_context *cmdline) is_lastlog_cmd = !strcmp (argv[0 ],"lastlog" ); -if (cmd->log_rh && !is_lastlog_cmd) { +if (cmd->cmd_report.log_rh && !is_lastlog_cmd) {/* drop old log report */ -dm_report_free (cmd->log_rh); - cmd->log_rh =NULL ; +dm_report_free (cmd->cmd_report.log_rh); + cmd->cmd_report.log_rh =NULL ; } ret =lvm_run_command (cmd, argc, argv);
tools/reporter.c +32 -46
164 lines not on this page · raw message
tools/toollib.c +8 -16
@@ -1754,15 +1754,13 @@ struct processing_handle *init_processing_handle(struct cmd_context *cmd, struct handle->internal_report_for_select =arg_is_set (cmd, select_ARG); handle->include_historical_lvs = cmd->include_historical_lvs; -if (!parent_handle) { -if (!report_format_init (cmd, &handle->report_group_type, &handle->report_group, - &handle->log_rh, &handle->log_only, - &handle->saved_log_report_state)) { +if (!parent_handle && !cmd->cmd_report.report_group) { +if (!report_format_init (cmd)) {dm_pool_free (cmd->mem, handle);return NULL ; } }else - handle->saved_log_report_state =log_get_report_state (); + cmd->cmd_report.saved_log_report_state =log_get_report_state ();log_set_report_context (LOG_REPORT_CONTEXT_PROCESSING );return handle;
@@ -1798,19 +1796,13 @@ void destroy_processing_handle(struct cmd_context *cmd, struct processing_handleif (handle->selection_handle && handle->selection_handle->selection_rh)dm_report_free (handle->selection_handle->selection_rh); -log_restore_report_state (handle->saved_log_report_state); +log_restore_report_state (cmd->cmd_report.saved_log_report_state); -if (!dm_report_group_destroy (handle->report_group)) +if (!dm_report_group_destroy (cmd->cmd_report.report_group)) stack; -if (handle->log_rh) { -if (cmd->is_interactive) { -/* -* Keep log report if we're interactive so -* we can do further queries on this report. -*/ - cmd->log_rh = handle->log_rh; - }else -dm_report_free (handle->log_rh); +if (!cmd->is_interactive && cmd->cmd_report.log_rh) { +dm_report_free (cmd->cmd_report.log_rh); + cmd->cmd_report.log_rh =NULL ; }/* * TODO: think about better alternatives:
tools/toollib.h +0 -5
@@ -73,11 +73,6 @@ struct processing_handle {int internal_report_for_select;int include_historical_lvs;struct selection_handle *selection_handle; -dm_report_group_type_t report_group_type; -struct dm_report_group *report_group; -struct dm_report *log_rh; -int log_only; -log_report_t saved_log_report_state;void *custom_handle; };