Skip to contentSkip to conversation

master - lvm: shell: extend log report to cover whole lvm shell's main loop

PATCH Peter Rajnoha 1 participant 1 message Aug 9, 2016

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=f21afddeb71c052617afb41fed9a2bd68ad532cf
Commit:        f21afddeb71c052617afb41fed9a2bd68ad532cf
Parent:        7d1125e5b785014d3bae34acd158c528a4222871
Author:        Peter Rajnoha <[email protected]>
AuthorDate:    Thu Aug 4 13:42:57 2016 +0200
Committer:     Peter Rajnoha <[email protected]>
CommitterDate: Tue Aug 9 18:49:10 2016 +0200

lvm: shell: extend log report to cover whole lvm shell's main loop

When lvm commands are executed in lvm shell, we cover the whole lvm command execution within this shell now. That means, all messages logged and status caught during each command execution is now recorded in the log report, including overall command's return code.

---
 lib/commands/toolcontext.c |    5 ---
 tools/lvm.c                |   64 +++++++++++++++++++++++++++++++++++--------
 tools/reporter.c           |   25 +++++++----------
 tools/toollib.c            |   14 ++++++---
 4 files changed, 71 insertions(+), 37 deletions(-)
lib/commands/toolcontext.c +0 -5
index 57d3bdc..a7f76ba 100644
@@ -2218,11 +2218,6 @@ void destroy_toolcontext(struct cmd_context *cmd)
 	if (cmd->cft_def_hash)
 		dm_hash_destroy(cmd->cft_def_hash);
 
-	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);
 
tools/lvm.c +52 -12

135 lines not on this page · raw message

tools/reporter.c +10 -15
index d386efc..4a622ed 100644
@@ -1387,6 +1387,11 @@ static int _report(struct cmd_context *cmd, int argc, char **argv, report_type_t
 	} else
 		r = _do_report(cmd, handle, &args, single_args);
 
+	if (!args.log_only && !dm_report_group_pop(cmd->cmd_report.report_group)) {
+		log_error("Failed to finalize main report section in report group.");
+		r = ECMD_FAILED;
+	}
+
 	destroy_processing_handle(cmd, handle);
 	return r;
 }
@@ -1508,32 +1513,22 @@ bad:
 	return 0;
 }
 
-int lastlog(struct cmd_context *cmd, int argc, char **argv)
+int lastlog(struct cmd_context *cmd, int argc __attribute((unused)), char **argv __attribute__((unused)))
 {
-	struct dm_report_group *report_group = NULL;
 	const char *selection;
-	int r = ECMD_FAILED;
 
 	if (!cmd->cmd_report.log_rh) {
 		log_error("No log report stored.");
-		goto out;
+		return ECMD_FAILED;
 	}
 
 	if (!_do_report_get_selection(cmd, CMDLOG, 1, NULL, &selection))
-		goto_out;
+		return_ECMD_FAILED;
 
 	if (!dm_report_set_selection(cmd->cmd_report.log_rh, selection)) {
 		log_error("Failed to set selection for log report.");
-		goto out;
+		return ECMD_FAILED;
 	}
 
-	if (!dm_report_output(cmd->cmd_report.log_rh) ||
-	    !dm_report_group_pop(report_group))
-		goto_out;
-
-	r = ECMD_PROCESSED;
-out:
-	if (!dm_report_group_destroy(report_group))
-		stack;
-	return r;
+	return ECMD_PROCESSED;
 }
tools/toollib.c +9 -5
index bcf94ea..e24946f 100644
@@ -1798,11 +1798,15 @@ void destroy_processing_handle(struct cmd_context *cmd, struct processing_handle
 
 		log_restore_report_state(cmd->cmd_report.saved_log_report_state);
 
-		if (!dm_report_group_destroy(cmd->cmd_report.report_group))
-			stack;
-		if (!cmd->is_interactive && cmd->cmd_report.log_rh) {
-			dm_report_free(cmd->cmd_report.log_rh);
-			cmd->cmd_report.log_rh = NULL;
+		if (!cmd->is_interactive) {
+			if (!dm_report_group_destroy(cmd->cmd_report.report_group))
+				stack;
+			cmd->cmd_report.report_group = NULL;
+
+			if (cmd->cmd_report.log_rh) {
+				dm_report_free(cmd->cmd_report.log_rh);
+				cmd->cmd_report.log_rh = NULL;
+			}
 		}
 		/*
 		 * TODO: think about better alternatives: