From c099f531fbb1702ea0aed16e5deec0368e7e7250 Mon Sep 17 00:00:00 2001 From: Peter Rajnoha Date: Mon, 23 May 2016 10:16:29 +0200 Subject: [PATCH] toollib: add report_group and log_rh to processing_handle and initialize cmd processing log report Wire up report group creation with log report in struct processing_handle and call report_format_init during processing handle initialization (init_processing_handle fn) and destroy it while destroing processing handle (destroy_processing_handle fn). This way, all the LVM command processing using processing handle has access to log report via which the current command log can be reported as items are processed. --- WHATS_NEW | 1 + tools/toollib.c | 10 ++++++++++ tools/toollib.h | 3 +++ 3 files changed, 14 insertions(+) diff --git a/WHATS_NEW b/WHATS_NEW index ebddfd0b4..349bd309d 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.158 - ================================= + Integrate report group handling and cmd log report into cmd processing code. Add log/report_command_log to lvm.conf to enable or disable cmd log report. Add log/report_output_format to lvm.conf for default report output format. Recognize --reportformat {basic|json} option to select report output format. diff --git a/tools/toollib.c b/tools/toollib.c index 935381441..e09146790 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -1725,6 +1725,12 @@ struct processing_handle *init_processing_handle(struct cmd_context *cmd) handle->internal_report_for_select = arg_is_set(cmd, select_ARG); handle->include_historical_lvs = cmd->include_historical_lvs; + if (!report_format_init(cmd, &handle->report_group_type, &handle->report_group, + &handle->log_rh)) { + dm_pool_free(cmd->mem, handle); + return NULL; + } + return handle; } @@ -1754,6 +1760,10 @@ void destroy_processing_handle(struct cmd_context *cmd, struct processing_handle if (handle) { if (handle->selection_handle && handle->selection_handle->selection_rh) dm_report_free(handle->selection_handle->selection_rh); + if (!dm_report_group_destroy(handle->report_group)) + stack; + if (handle->log_rh) + dm_report_free(handle->log_rh); /* * TODO: think about better alternatives: * handle mempool, dm_alloc for handle memory... diff --git a/tools/toollib.h b/tools/toollib.h index 06d0ef9fc..622badcc7 100644 --- a/tools/toollib.h +++ b/tools/toollib.h @@ -72,6 +72,9 @@ 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; void *custom_handle; };