Skip to contentSkip to conversation

dev-prajnoha-report-select - report: select: add dm_report_field_string_list to libdm

PATCH Peter Rajnoha 1 participant 1 message Jun 6, 2014

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3bcf26dcbe3871c52448e283e39b4e1d5f0fd6ad
Commit:        3bcf26dcbe3871c52448e283e39b4e1d5f0fd6ad
Parent:        433fd6abc3a59e6030e163c9611b296348a442e1
Author:        Peter Rajnoha <[email protected]>
AuthorDate:    Thu May 29 09:41:18 2014 +0200
Committer:     Peter Rajnoha <[email protected]>
CommitterDate: Fri Jun 6 11:35:24 2014 +0200

report: select: add dm_report_field_string_list to libdm

Add a separate dm_report_field_string_list fn to libdevmapper to support reporting string lists. Before, the code used libdevmappers's dm_report_field_string fn which required formatting the list to a single string. This functionality is now moved to libdevmapper and the code that needs to report the string list just needs to pass the list itself and libdevmapper will take care of this. This also enhances code reuse.

The dm_report_field_string_list also accepts an argument to define custom delimiter to use. If not defined, a default "," (comma) is used as item delimiter in the string list reported.

The dm_report_field_string_list automatically sorts the items in the list before formatting it to a final string. It also encodes the position and length within the final string where each element can be found. This can be used to support checking against each list item reported since since when formatted as a single string for the actual report, we would lose this information otherwise (we don't want to copy each item, the position and length within the final string is enough for us to get the original items back).

When such lists are checked against the selection tree, we can check each item individually this way and we can support operators like "match any" and "match all".

---
 libdm/libdevmapper.h |    2 +
 libdm/libdm-report.c |  127 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 129 insertions(+), 0 deletions(-)
libdm/libdevmapper.h +2 -0
index f3e2b92..e007b9b 100644
@@ -1676,6 +1676,8 @@ int dm_report_set_output_field_name_prefix(struct dm_report *rh,
  */
 int dm_report_field_string(struct dm_report *rh, struct dm_report_field *field,
 			   const char *const *data);
+int dm_report_field_string_list(struct dm_report *rh, struct dm_report_field *field,
+				const struct dm_list *data, const char *delimiter);
 int dm_report_field_int32(struct dm_report *rh, struct dm_report_field *field,
 			  const int32_t *data);
 int dm_report_field_uint32(struct dm_report *rh, struct dm_report_field *field,
libdm/libdm-report.c +127 -0

133 lines not on this page · raw message