Skip to contentSkip to conversation

master - report: add --logonly arg to report only log for a command

PATCH Peter Rajnoha 1 participant 1 message Jun 20, 2016

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=92caebab95353e13b37fc724a6f31c23c8fd2cac
Commit:        92caebab95353e13b37fc724a6f31c23c8fd2cac
Parent:        3e8e8ddb4619bbc16e28ba0d84d43868271516e5
Author:        Peter Rajnoha <[email protected]>
AuthorDate:    Wed Jun 15 13:35:27 2016 +0200
Committer:     Peter Rajnoha <[email protected]>
CommitterDate: Mon Jun 20 11:33:43 2016 +0200

report: add --logonly arg to report only log for a command

---
 WHATS_NEW           |    1 +
 lib/report/report.h |    2 +-
 tools/args.h        |    1 +
 tools/commands.h    |   52 +++++++++++++++++++++++++++++---------------------
 tools/reporter.c    |   28 +++++++++++++++++---------
 tools/toollib.c     |    3 +-
 tools/toollib.h     |    1 +
 7 files changed, 54 insertions(+), 34 deletions(-)
WHATS_NEW +1 -0
index 8a4f7d5..86a53ce 100644
@@ -1,5 +1,6 @@
 Version 2.02.158 - 
 =================================
+  Add --logonly option to report only cmd log for a command, not other reports.
   Add log/command_log_selection to configure default selection used on cmd log.
   Use 'orphan' object type in cmd log for groups to collect PVs not yet in VGs.
   Add lvm lastlog command for query and display of last cmd's log in lvm shell.
lib/report/report.h +1 -1
index 9d9d01f..b9028fe 100644
@@ -83,7 +83,7 @@ typedef int (*field_report_fn) (struct report_handle * dh, struct field * field,
 
 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,
-		       log_report_t *saved_log_report_state);
+		       int *log_only, log_report_t *saved_log_report_state);
 
 void *report_init(struct cmd_context *cmd, const char *format, const char *keys,
 		  report_type_t *report_type, const char *separator,
tools/args.h +1 -0
index b7b2262..670d6a0 100644
@@ -55,6 +55,7 @@ arg(lockopt_ARG, '\0', "lockopt", string_arg, 0, 0)
 arg(lockstart_ARG, '\0', "lockstart", NULL, 0, 0)
 arg(lockstop_ARG, '\0', "lockstop", NULL, 0, 0)
 arg(locktype_ARG, '\0', "locktype", locktype_arg, 0, 0)
+arg(logonly_ARG, '\0', "logonly", NULL, 0, 0)
 arg(maxrecoveryrate_ARG, '\0', "maxrecoveryrate", size_kb_arg, 0, 0)
 arg(merge_ARG, '\0', "merge", NULL, 0, 0)
 arg(mergedconfig_ARG, '\0', "mergedconfig", NULL, 0, 0)
tools/commands.h +30 -22

136 lines not on this page · raw message

tools/reporter.c +18 -10
index f65676e..c7dee20 100644
@@ -54,6 +54,7 @@ struct report_args {
 	int columns_as_rows;
 	const char *separator;
 	struct volume_group *full_report_vg;
+	int log_only;
 	struct single_report_args single_args[REPORT_IDX_COUNT];
 };
 
@@ -1047,7 +1048,7 @@ static int _do_report(struct cmd_context *cmd, struct processing_handle *handle,
 				    &lv_segment_status_needed, &report_type))
 		goto_out;
 
-	if (handle->report_group) {
+	if (!(args->log_only && (single_args->report_type != CMDLOG))) {
 		if (!dm_report_group_push(handle->report_group, report_handle, (void *) single_args->report_name))
 			goto_out;
 		report_in_group = 1;
@@ -1160,7 +1161,8 @@ static int _do_report(struct cmd_context *cmd, struct processing_handle *handle,
 			log_error("Failed to compact given columns in report output.");
 	}
 
-	dm_report_output(report_handle);
+	if (!(args->log_only && (single_args->report_type != CMDLOG)))
+		dm_report_output(report_handle);
 
 	if (lock_global)
 		unlock_vg(cmd, VG_GLOBAL);
@@ -1189,7 +1191,7 @@ static int _full_report_single(struct cmd_context *cmd,
 
 	args->full_report_vg = vg;
 
-	if (!dm_report_group_push(handle->report_group, NULL, NULL))
+	if (!args->log_only && !dm_report_group_push(handle->report_group, NULL, NULL))
 		goto out;
 
 	if (orphan) {
@@ -1205,7 +1207,7 @@ static int _full_report_single(struct cmd_context *cmd,
 			stack;
 	}
 
-	if (!dm_report_group_pop(handle->report_group))
+	if (!args->log_only && !dm_report_group_pop(handle->report_group))
 		goto_out;
 out:
 	args->full_report_vg = NULL;
@@ -1360,13 +1362,14 @@ static int _report(struct cmd_context *cmd, int argc, char **argv, report_type_t
 	handle->include_historical_lvs = cmd->include_historical_lvs;
 
 	args.report_group_type = handle->report_group_type;
+	args.log_only = handle->log_only;
 
 	if (!_config_report(cmd, &args, single_args)) {
 		destroy_processing_handle(cmd, handle);
 		return_ECMD_FAILED;
 	}
 
-	if (!dm_report_group_push(handle->report_group, NULL, report_name)) {
+	if (!args.log_only && !dm_report_group_push(handle->report_group, NULL, report_name)) {
 		log_error("Failed to add main report section to report group.");
 		destroy_processing_handle(cmd, handle);
 		return ECMD_FAILED;
@@ -1426,20 +1429,23 @@ int devtypes(struct cmd_context *cmd, int argc, char **argv)
 
 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,
-		       log_report_t *saved_log_report_state)
+		       int *log_only, log_report_t *saved_log_report_state)
 {
 	int config_set = find_config_tree_node(cmd, report_output_format_CFG, NULL) != NULL;
 	const char *config_format_str = find_config_tree_str(cmd, report_output_format_CFG, NULL);
 	const char *format_str = arg_str_value(cmd, reportformat_ARG, config_set ? config_format_str : NULL);
-	int report_command_log = find_config_tree_bool(cmd, log_report_command_log_CFG, NULL);
+	int report_command_log;
 	struct report_args args = {0};
 	struct single_report_args *single_args;
 	struct dm_report_group *new_report_group;
 	struct dm_report *tmp_log_rh = NULL;
 
+	args.log_only = arg_is_set(cmd, logonly_ARG) || *log_rh;
+	report_command_log = args.log_only || find_config_tree_bool(cmd, log_report_command_log_CFG, NULL);
+
 	if (!format_str || !strcmp(format_str, REPORT_FORMAT_NAME_BASIC)) {
-		args.report_group_type = report_command_log ? DM_REPORT_GROUP_BASIC
-							    : DM_REPORT_GROUP_SINGLE;
+		args.report_group_type = (report_command_log && !args.log_only) ? DM_REPORT_GROUP_BASIC
+										: DM_REPORT_GROUP_SINGLE;
 	} else if (!strcmp(format_str, REPORT_FORMAT_NAME_JSON)) {
 		args.report_group_type = DM_REPORT_GROUP_JSON;
 	} else {
@@ -1452,6 +1458,8 @@ int report_format_init(struct cmd_context *cmd, dm_report_group_type_t *report_g
 
 	if (report_group_type)
 		*report_group_type = args.report_group_type;
+	if (log_only)
+		*log_only = args.log_only;
 
 	if (!(new_report_group = dm_report_group_create(args.report_group_type, NULL))) {
 		log_error("Failed to create report group.");
@@ -1517,7 +1525,7 @@ int lastlog(struct cmd_context *cmd, int argc, char **argv)
 		goto out;
 	}
 
-	if (!report_format_init(cmd, NULL, &report_group, &cmd->log_rh, NULL))
+	if (!report_format_init(cmd, NULL, &report_group, &cmd->log_rh, NULL, NULL))
 		goto_out;
 
 	if (arg_count(cmd, select_ARG) &&
tools/toollib.c +2 -1
index 0eb2887..fe9f9c0 100644
@@ -1733,7 +1733,8 @@ struct processing_handle *init_processing_handle(struct cmd_context *cmd, struct
 
 	if (!parent_handle) {
 		if (!report_format_init(cmd, &handle->report_group_type, &handle->report_group,
-					&handle->log_rh, &handle->saved_log_report_state)) {
+					&handle->log_rh, &handle->log_only,
+					&handle->saved_log_report_state)) {
 			dm_pool_free(cmd->mem, handle);
 			return NULL;
 		}
tools/toollib.h +1 -0
index 1144793..42e7f7a 100644
@@ -76,6 +76,7 @@ struct processing_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;
 };