mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-03 05:18:29 +03:00
refactor: factor out vg/lv/pv handling part from report_for_selection fn
Functionality will be reused by future patches. Also, it makes the code more readable.
This commit is contained in:
parent
9a299d2d7a
commit
3f6e7f90ca
160
tools/reporter.c
160
tools/reporter.c
@ -438,13 +438,104 @@ static int _get_final_report_type(int args_are_pvs,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _report_all_in_vg(struct cmd_context *cmd, struct processing_handle *handle,
|
||||
struct volume_group *vg, report_type_t type,
|
||||
int do_lv_info, int do_lv_seg_status)
|
||||
{
|
||||
int r = 0;
|
||||
|
||||
switch (type) {
|
||||
case VGS:
|
||||
r = _vgs_single(cmd, vg->name, vg, handle);
|
||||
break;
|
||||
case LVS:
|
||||
r = process_each_lv_in_vg(cmd, vg, NULL, NULL, 0, handle,
|
||||
do_lv_info && !do_lv_seg_status ? &_lvs_with_info_single :
|
||||
!do_lv_info && do_lv_seg_status ? &_lvs_with_status_single :
|
||||
do_lv_info && do_lv_seg_status ? &_lvs_with_info_and_status_single :
|
||||
&_lvs_single);
|
||||
break;
|
||||
case SEGS:
|
||||
r = process_each_lv_in_vg(cmd, vg, NULL, NULL, 0, handle,
|
||||
do_lv_info && !do_lv_seg_status ? &_lvsegs_with_info_single :
|
||||
!do_lv_info && do_lv_seg_status ? &_lvsegs_with_status_single :
|
||||
do_lv_info && do_lv_seg_status ? &_lvsegs_with_info_and_status_single :
|
||||
&_lvsegs_single);
|
||||
break;
|
||||
case PVS:
|
||||
r = process_each_pv_in_vg(cmd, vg, handle, &_pvs_single);
|
||||
break;
|
||||
case PVSEGS:
|
||||
r = process_each_pv_in_vg(cmd, vg, handle,
|
||||
do_lv_info && !do_lv_seg_status ? &_pvsegs_with_lv_info_single :
|
||||
!do_lv_info && do_lv_seg_status ? &_pvsegs_with_lv_status_single :
|
||||
do_lv_info && do_lv_seg_status ? &_pvsegs_with_lv_info_and_status_single :
|
||||
&_pvsegs_single);
|
||||
break;
|
||||
default:
|
||||
log_error(INTERNAL_ERROR "_report_all_in_vg: incorrect report type");
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _report_all_in_lv(struct cmd_context *cmd, struct processing_handle *handle,
|
||||
struct logical_volume *lv, report_type_t type,
|
||||
int do_lv_info, int do_lv_seg_status)
|
||||
{
|
||||
int r = 0;
|
||||
|
||||
switch (type) {
|
||||
case LVS:
|
||||
r = _do_lvs_with_info_and_status_single(cmd, lv, do_lv_info, do_lv_seg_status, handle);
|
||||
break;
|
||||
case SEGS:
|
||||
r = process_each_segment_in_lv(cmd, lv, handle,
|
||||
do_lv_info && !do_lv_seg_status ? &_segs_with_info_single :
|
||||
!do_lv_info && do_lv_seg_status ? &_segs_with_status_single :
|
||||
do_lv_info && do_lv_seg_status ? &_segs_with_info_and_status_single :
|
||||
&_segs_single);
|
||||
break;
|
||||
default:
|
||||
log_error(INTERNAL_ERROR "_report_all_in_lv: incorrect report type");
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _report_all_in_pv(struct cmd_context *cmd, struct processing_handle *handle,
|
||||
struct physical_volume *pv, report_type_t type,
|
||||
int do_lv_info, int do_lv_seg_status)
|
||||
{
|
||||
int r = 0;
|
||||
|
||||
switch (type) {
|
||||
case PVS:
|
||||
r = _pvs_single(cmd, pv->vg, pv, handle);
|
||||
break;
|
||||
case PVSEGS:
|
||||
r = process_each_segment_in_pv(cmd, pv->vg, pv, handle,
|
||||
do_lv_info && !do_lv_seg_status ? &_pvsegs_with_lv_info_sub_single :
|
||||
!do_lv_info && do_lv_seg_status ? &_pvsegs_with_lv_status_sub_single :
|
||||
do_lv_info && do_lv_seg_status ? &_pvsegs_with_lv_info_and_status_sub_single :
|
||||
&_pvsegs_sub_single);
|
||||
break;
|
||||
default:
|
||||
log_error(INTERNAL_ERROR "_report_all_in_pv: incorrect report type");
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int report_for_selection(struct cmd_context *cmd,
|
||||
struct selection_handle *sh,
|
||||
struct physical_volume *pv,
|
||||
struct volume_group *vg,
|
||||
struct logical_volume *lv)
|
||||
{
|
||||
static const char *incorrect_report_type_msg = "report_for_selection: incorrect report type";
|
||||
int args_are_pvs = sh->orig_report_type == PVS;
|
||||
int do_lv_info, do_lv_seg_status;
|
||||
struct processing_handle *handle;
|
||||
@ -491,75 +582,16 @@ int report_for_selection(struct cmd_context *cmd,
|
||||
*/
|
||||
switch (sh->orig_report_type) {
|
||||
case LVS:
|
||||
switch (sh->report_type) {
|
||||
case LVS:
|
||||
r = _do_lvs_with_info_and_status_single(vg->cmd, lv, do_lv_info, do_lv_seg_status, handle);
|
||||
break;
|
||||
case SEGS:
|
||||
r = process_each_segment_in_lv(vg->cmd, lv, handle,
|
||||
do_lv_info && !do_lv_seg_status ? &_segs_with_info_single :
|
||||
!do_lv_info && do_lv_seg_status ? &_segs_with_status_single :
|
||||
do_lv_info && do_lv_seg_status ? &_segs_with_info_and_status_single :
|
||||
&_segs_single);
|
||||
break;
|
||||
default:
|
||||
log_error(INTERNAL_ERROR "%s for LVS", incorrect_report_type_msg);
|
||||
break;
|
||||
}
|
||||
r = _report_all_in_lv(cmd, handle, lv, sh->report_type, do_lv_info, do_lv_seg_status);
|
||||
break;
|
||||
case VGS:
|
||||
switch (sh->report_type) {
|
||||
case VGS:
|
||||
r = _vgs_single(vg->cmd, vg->name, vg, handle);
|
||||
break;
|
||||
case LVS:
|
||||
r = process_each_lv_in_vg(vg->cmd, vg, NULL, NULL, 0, handle,
|
||||
do_lv_info && !do_lv_seg_status ? &_lvs_with_info_single :
|
||||
!do_lv_info && do_lv_seg_status ? &_lvs_with_status_single :
|
||||
do_lv_info && do_lv_seg_status ? &_lvs_with_info_and_status_single :
|
||||
&_lvs_single);
|
||||
break;
|
||||
case SEGS:
|
||||
r = process_each_lv_in_vg(vg->cmd, vg, NULL, NULL, 0, handle,
|
||||
do_lv_info && !do_lv_seg_status ? &_lvsegs_with_info_single :
|
||||
!do_lv_info && do_lv_seg_status ? &_lvsegs_with_status_single :
|
||||
do_lv_info && do_lv_seg_status ? &_lvsegs_with_info_and_status_single :
|
||||
&_lvsegs_single);
|
||||
r = _report_all_in_vg(cmd, handle, vg, sh->report_type, do_lv_info, do_lv_seg_status);
|
||||
break;
|
||||
case PVS:
|
||||
r = process_each_pv_in_vg(vg->cmd, vg, handle, &_pvs_single);
|
||||
break;
|
||||
case PVSEGS:
|
||||
r = process_each_pv_in_vg(vg->cmd, vg, handle,
|
||||
do_lv_info && !do_lv_seg_status ? &_pvsegs_with_lv_info_single :
|
||||
!do_lv_info && do_lv_seg_status ? &_pvsegs_with_lv_status_single :
|
||||
do_lv_info && do_lv_seg_status ? &_pvsegs_with_lv_info_and_status_single :
|
||||
&_pvsegs_single);
|
||||
r = _report_all_in_pv(cmd, handle, pv, sh->report_type, do_lv_info, do_lv_seg_status);
|
||||
break;
|
||||
default:
|
||||
log_error(INTERNAL_ERROR "%s for VGS", incorrect_report_type_msg);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case PVS:
|
||||
switch (sh->report_type) {
|
||||
case PVS:
|
||||
r = _pvs_single(vg->cmd, vg, pv, handle);
|
||||
break;
|
||||
case PVSEGS:
|
||||
r = process_each_segment_in_pv(vg->cmd, vg, pv, handle,
|
||||
do_lv_info && !do_lv_seg_status ? &_pvsegs_with_lv_info_sub_single :
|
||||
!do_lv_info && do_lv_seg_status ? &_pvsegs_with_lv_status_sub_single :
|
||||
do_lv_info && do_lv_seg_status ? &_pvsegs_with_lv_info_and_status_sub_single :
|
||||
&_pvsegs_sub_single);
|
||||
break;
|
||||
default:
|
||||
log_error(INTERNAL_ERROR "%s for PVS", incorrect_report_type_msg);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
log_error(INTERNAL_ERROR "%s", incorrect_report_type_msg);
|
||||
log_error(INTERNAL_ERROR "report_for_selection: incorrect report type");
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user