1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-03-11 20:58:50 +03:00

cleanup: use common init/destroy_processing_handle in _report fn and cleanup error paths

This commit is contained in:
Peter Rajnoha 2016-04-08 11:01:19 +02:00
parent f2e59e05ed
commit 50866034a2

View File

@ -733,10 +733,10 @@ out:
static int _report(struct cmd_context *cmd, int argc, char **argv, static int _report(struct cmd_context *cmd, int argc, char **argv,
report_type_t report_type) report_type_t report_type)
{ {
void *report_handle; void *report_handle = NULL;
struct processing_handle handle = {0}; struct processing_handle *handle = NULL;
const char *keys = NULL, *options = NULL, *selection = NULL, *separator; const char *keys = NULL, *options = NULL, *selection = NULL, *separator;
int r = ECMD_PROCESSED; int r = ECMD_FAILED;
int aligned, buffered, headings, field_prefixes, quoted; int aligned, buffered, headings, field_prefixes, quoted;
int columns_as_rows; int columns_as_rows;
unsigned args_are_pvs; unsigned args_are_pvs;
@ -809,13 +809,13 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
break; break;
default: default:
log_error(INTERNAL_ERROR "Unknown report type."); log_error(INTERNAL_ERROR "Unknown report type.");
return ECMD_FAILED; goto out;
} }
/* If -o supplied use it, else use default for report_type */ /* If -o supplied use it, else use default for report_type */
if (arg_count(cmd, options_ARG) && if (arg_count(cmd, options_ARG) &&
((r = _get_report_options(cmd, report_type, &options, &fields_to_compact) != ECMD_PROCESSED))) ((r = _get_report_options(cmd, report_type, &options, &fields_to_compact) != ECMD_PROCESSED)))
return r; goto_out;
/* -O overrides default sort settings */ /* -O overrides default sort settings */
keys = arg_str_value(cmd, sort_ARG, keys); keys = arg_str_value(cmd, sort_ARG, keys);
@ -841,19 +841,24 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
if (arg_count(cmd, select_ARG)) if (arg_count(cmd, select_ARG))
selection = arg_str_value(cmd, select_ARG, NULL); selection = arg_str_value(cmd, select_ARG, NULL);
if (!(handle = init_processing_handle(cmd)))
goto_out;
if (!(report_handle = report_init(cmd, options, keys, &report_type, if (!(report_handle = report_init(cmd, options, keys, &report_type,
separator, aligned, buffered, separator, aligned, buffered,
headings, field_prefixes, quoted, headings, field_prefixes, quoted,
columns_as_rows, selection))) columns_as_rows, selection)))
return_ECMD_FAILED; goto_out;
handle->internal_report_for_select = 0;
handle->include_historical_lvs = cmd->include_historical_lvs;
handle->custom_handle = report_handle;
if (!_get_final_report_type(args_are_pvs, if (!_get_final_report_type(args_are_pvs,
report_type, &lv_info_needed, report_type, &lv_info_needed,
&lv_segment_status_needed, &lv_segment_status_needed,
&report_type)) { &report_type))
dm_report_free(report_handle); goto_out;
return ECMD_FAILED;
}
/* /*
* We lock VG_GLOBAL to enable use of metadata cache. * We lock VG_GLOBAL to enable use of metadata cache.
@ -864,18 +869,13 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
lock_global = 1; lock_global = 1;
if (!lock_vol(cmd, VG_GLOBAL, LCK_VG_READ, NULL)) { if (!lock_vol(cmd, VG_GLOBAL, LCK_VG_READ, NULL)) {
log_error("Unable to obtain global lock."); log_error("Unable to obtain global lock.");
dm_report_free(report_handle); goto out;
return ECMD_FAILED;
} }
} }
handle.internal_report_for_select = 0;
handle.include_historical_lvs = cmd->include_historical_lvs;
handle.custom_handle = report_handle;
switch (report_type) { switch (report_type) {
case DEVTYPES: case DEVTYPES:
r = _process_each_devtype(cmd, argc, &handle); r = _process_each_devtype(cmd, argc, handle);
break; break;
case LVSINFO: case LVSINFO:
/* fall through */ /* fall through */
@ -884,7 +884,7 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
case LVSINFOSTATUS: case LVSINFOSTATUS:
/* fall through */ /* fall through */
case LVS: case LVS:
r = process_each_lv(cmd, argc, argv, 0, &handle, r = process_each_lv(cmd, argc, argv, 0, handle,
lv_info_needed && !lv_segment_status_needed ? &_lvs_with_info_single : lv_info_needed && !lv_segment_status_needed ? &_lvs_with_info_single :
!lv_info_needed && lv_segment_status_needed ? &_lvs_with_status_single : !lv_info_needed && lv_segment_status_needed ? &_lvs_with_status_single :
lv_info_needed && lv_segment_status_needed ? &_lvs_with_info_and_status_single : lv_info_needed && lv_segment_status_needed ? &_lvs_with_info_and_status_single :
@ -892,25 +892,25 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
break; break;
case VGS: case VGS:
r = process_each_vg(cmd, argc, argv, NULL, 0, r = process_each_vg(cmd, argc, argv, NULL, 0,
&handle, &_vgs_single); handle, &_vgs_single);
break; break;
case LABEL: case LABEL:
r = process_each_label(cmd, argc, argv, r = process_each_label(cmd, argc, argv,
&handle, &_label_single); handle, &_label_single);
break; break;
case PVS: case PVS:
if (args_are_pvs) if (args_are_pvs)
r = process_each_pv(cmd, argc, argv, NULL, r = process_each_pv(cmd, argc, argv, NULL,
arg_is_set(cmd, all_ARG), 0, arg_is_set(cmd, all_ARG), 0,
&handle, &_pvs_single); handle, &_pvs_single);
else else
r = process_each_vg(cmd, argc, argv, NULL, 0, r = process_each_vg(cmd, argc, argv, NULL, 0,
&handle, &_pvs_in_vg); handle, &_pvs_in_vg);
break; break;
case SEGSSTATUS: case SEGSSTATUS:
/* fall through */ /* fall through */
case SEGS: case SEGS:
r = process_each_lv(cmd, argc, argv, 0, &handle, r = process_each_lv(cmd, argc, argv, 0, handle,
lv_info_needed && !lv_segment_status_needed ? &_lvsegs_with_info_single : lv_info_needed && !lv_segment_status_needed ? &_lvsegs_with_info_single :
!lv_info_needed && lv_segment_status_needed ? &_lvsegs_with_status_single : !lv_info_needed && lv_segment_status_needed ? &_lvsegs_with_status_single :
lv_info_needed && lv_segment_status_needed ? &_lvsegs_with_info_and_status_single : lv_info_needed && lv_segment_status_needed ? &_lvsegs_with_info_and_status_single :
@ -920,14 +920,14 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
if (args_are_pvs) if (args_are_pvs)
r = process_each_pv(cmd, argc, argv, NULL, r = process_each_pv(cmd, argc, argv, NULL,
arg_is_set(cmd, all_ARG), 0, arg_is_set(cmd, all_ARG), 0,
&handle, handle,
lv_info_needed && !lv_segment_status_needed ? &_pvsegs_with_lv_info_single : lv_info_needed && !lv_segment_status_needed ? &_pvsegs_with_lv_info_single :
!lv_info_needed && lv_segment_status_needed ? &_pvsegs_with_lv_status_single : !lv_info_needed && lv_segment_status_needed ? &_pvsegs_with_lv_status_single :
lv_info_needed && lv_segment_status_needed ? &_pvsegs_with_lv_info_and_status_single : lv_info_needed && lv_segment_status_needed ? &_pvsegs_with_lv_info_and_status_single :
&_pvsegs_single); &_pvsegs_single);
else else
r = process_each_vg(cmd, argc, argv, NULL, 0, r = process_each_vg(cmd, argc, argv, NULL, 0,
&handle, &_pvsegs_in_vg); handle, &_pvsegs_in_vg);
break; break;
} }
@ -942,11 +942,13 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
dm_report_output(report_handle); dm_report_output(report_handle);
dm_report_free(report_handle);
if (lock_global) if (lock_global)
unlock_vg(cmd, VG_GLOBAL); unlock_vg(cmd, VG_GLOBAL);
out:
if (handle)
destroy_processing_handle(cmd, handle);
if (report_handle)
dm_report_free(report_handle);
return r; return r;
} }