diff --git a/lib/report/report.c b/lib/report/report.c index 53de714ad..cf3d9b652 100644 --- a/lib/report/report.c +++ b/lib/report/report.c @@ -2009,15 +2009,28 @@ void *report_init(struct cmd_context *cmd, const char *format, const char *keys, return rh; } +void *report_init_for_selection(struct cmd_context *cmd, + report_type_t *report_type, + const char *selection_criteria) +{ + return dm_report_init_with_selection(report_type, _report_types, _fields, + "", DEFAULT_REP_SEPARATOR, + DM_REPORT_OUTPUT_FIELD_UNQUOTED, + "", selection_criteria, + _report_reserved_values, + cmd); +} + /* * Create a row of data for an object */ -int report_object(void *handle, const struct volume_group *vg, +int report_object(void *handle, int selection_only, const struct volume_group *vg, const struct logical_volume *lv, const struct physical_volume *pv, const struct lv_segment *seg, const struct pv_segment *pvseg, const struct lv_with_info_and_seg_status *lvdm, const struct label *label) { + struct selection_handle *sh = selection_only ? (struct selection_handle *) handle : NULL; struct device dummy_device = { .dev = 0 }; struct label dummy_label = { .dev = &dummy_device }; struct lvm_report_object obj = { @@ -2051,7 +2064,8 @@ int report_object(void *handle, const struct volume_group *vg, if (!obj.vg && pv) _dummy_fid.fmt = pv->fmt; - return dm_report_object(handle, &obj); + return sh ? dm_report_object_is_selected(sh->selection_rh, &obj, 0, &sh->selected) + : dm_report_object(handle, &obj); } static int _report_devtype_single(void *handle, const dev_known_type_t *devtype) diff --git a/lib/report/report.h b/lib/report/report.h index aef6d7258..80a75fd7a 100644 --- a/lib/report/report.h +++ b/lib/report/report.h @@ -69,8 +69,10 @@ void *report_init(struct cmd_context *cmd, const char *format, const char *keys, report_type_t *report_type, const char *separator, int aligned, int buffered, int headings, int field_prefixes, int quoted, int columns_as_rows, const char *selection); +void *report_init_for_selection(struct cmd_context *cmd, report_type_t *report_type, + const char *selection); void report_free(void *handle); -int report_object(void *handle, const struct volume_group *vg, +int report_object(void *handle, int selection_only, const struct volume_group *vg, const struct logical_volume *lv, const struct physical_volume *pv, const struct lv_segment *seg, const struct pv_segment *pvseg, const struct lv_with_info_and_seg_status *lvdm, diff --git a/tools/reporter.c b/tools/reporter.c index 3d7e5ddd6..3cba020c6 100644 --- a/tools/reporter.c +++ b/tools/reporter.c @@ -32,7 +32,10 @@ static int _vgs_single(struct cmd_context *cmd __attribute__((unused)), const char *vg_name, struct volume_group *vg, struct processing_handle *handle) { - if (!report_object(handle->custom_handle, vg, NULL, NULL, NULL, NULL, NULL, NULL)) + struct selection_handle *sh = handle->selection_handle; + + if (!report_object(sh ? : handle->custom_handle, sh != NULL, + vg, NULL, NULL, NULL, NULL, NULL, NULL)) return_ECMD_FAILED; check_current_backup(vg); @@ -88,6 +91,7 @@ static int _do_lvs_with_info_and_status_single(struct cmd_context *cmd, int do_info, int do_status, struct processing_handle *handle) { + struct selection_handle *sh = handle->selection_handle; struct lv_with_info_and_seg_status status = { .seg_status.type = SEG_STATUS_NONE }; @@ -96,8 +100,8 @@ static int _do_lvs_with_info_and_status_single(struct cmd_context *cmd, if (!_do_info_and_status(cmd, lv, NULL, &status, do_info, do_status)) goto_out; - if (!report_object(handle->custom_handle, lv->vg, lv, - NULL, NULL, NULL, &status, NULL)) + if (!report_object(sh ? : handle->custom_handle, sh != NULL, + lv->vg, lv, NULL, NULL, NULL, &status, NULL)) goto out; r = ECMD_PROCESSED; @@ -137,6 +141,7 @@ static int _do_segs_with_info_and_status_single(struct cmd_context *cmd, int do_info, int do_status, struct processing_handle *handle) { + struct selection_handle *sh = handle->selection_handle; struct lv_with_info_and_seg_status status = { .seg_status.type = SEG_STATUS_NONE }; @@ -145,9 +150,9 @@ static int _do_segs_with_info_and_status_single(struct cmd_context *cmd, if (!_do_info_and_status(cmd, seg->lv, seg, &status, do_info, do_status)) goto_out; - if (!report_object(handle->custom_handle, seg->lv->vg, seg->lv, NULL, seg, NULL, - &status, NULL)) - goto_out; + if (!report_object(sh ? : handle->custom_handle, sh != NULL, + seg->lv->vg, seg->lv, NULL, seg, NULL, &status, NULL)) + goto_out; r = ECMD_PROCESSED; out: @@ -224,6 +229,7 @@ static int _do_pvsegs_sub_single(struct cmd_context *cmd, int do_status, struct processing_handle *handle) { + struct selection_handle *sh = handle->selection_handle; int ret = ECMD_PROCESSED; struct lv_segment *seg = pvseg->lvseg; @@ -268,9 +274,10 @@ static int _do_pvsegs_sub_single(struct cmd_context *cmd, if (seg && !_do_info_and_status(cmd, seg->lv, seg, &status, do_info, do_status)) goto_out; - if (!report_object(handle->custom_handle, vg, seg ? seg->lv : &_free_logical_volume, - pvseg->pv, seg ? : &_free_lv_segment, pvseg, &status, - pv_label(pvseg->pv))) { + if (!report_object(sh ? : handle->custom_handle, sh != NULL, + vg, seg ? seg->lv : &_free_logical_volume, + pvseg->pv, seg ? : &_free_lv_segment, pvseg, + &status, pv_label(pvseg->pv))) { ret = ECMD_FAILED; goto_out; } @@ -350,7 +357,10 @@ static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg, struct physical_volume *pv, struct processing_handle *handle) { - if (!report_object(handle->custom_handle, vg, NULL, pv, NULL, NULL, NULL, NULL)) + struct selection_handle *sh = handle->selection_handle; + + if (!report_object(sh ? : handle->custom_handle, sh != NULL, + vg, NULL, pv, NULL, NULL, NULL, NULL)) return_ECMD_FAILED; return ECMD_PROCESSED; @@ -359,7 +369,10 @@ static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg, static int _label_single(struct cmd_context *cmd, struct label *label, struct processing_handle *handle) { - if (!report_object(handle->custom_handle, NULL, NULL, NULL, NULL, NULL, NULL, label)) + struct selection_handle *sh = handle->selection_handle; + + if (!report_object(sh ? : handle->custom_handle, sh != NULL, + NULL, NULL, NULL, NULL, NULL, NULL, label)) return_ECMD_FAILED; return ECMD_PROCESSED;