1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00
lvm2/device_mapper
Peter Rajnoha 31cd8346ae libdm: report: enhance the way string list is stored internally
Before, we stored only the report string itself for a string list
in field->report_string. The field->report_string has either
sorted items or not, depending on what we need for a field -
some report fields have sorted output, some don't...

The field->sort_value.value then contains pointer to the exact
field->report_string. The field->sort_value.items ALWAYS keeps
sorted array of individual items, represented as '[position,length]'
pairs pointing to the field->sort_value.value string.

This approach was fine as far as we didn't need to apply further
formatting to field->report_string. However, if we need to apply
further formatting to field->report_string content, taking into
account individual items, we also need to know where each item
starts and what is its length. Before, we only knew this when
items in report string were sorted, but not in the unsorted version.

We can't rely on the delimiter (default ",") only to separate items
back out of report string, because that delimiter can be contained
in the item value itself.

So this patch enhances the field->report_string for a string list so
it also contains '[position,length]' pairs for each individual item
inside field->report_string. We store this array right beyond the
string itself and we encode it in the same manner we already did for
field->sort_value.items before.

If field->report_string has sorted items, the field->sort_value.items
just points to the array of items we store beyond the report string.
If field->report_string has unsorted items, we store separate array
of items for both field->report_string and field->sort_value.

This patch also cleans up the _report_field_string_list function a bit
so it's easier and more straightforward to follow than the original
version.

Example. If we have "abc", "xy", "defgh" as list on input with ","
as delimiter, then:

  - field->report_string will have:

    - if we need field->report_string unsorted:

        abc,xy,defgh\0{[3,12],[0,3],[4,2],[7,5]}
        |____________||________________________|
           string      array of [pos,len] pairs
                       |____||________________|
                       #items      items

    - if we need field->report_string sorted:

                 repstr_extra
                      |
                      V
        abc,defgh,xy\0{[3,12],[0,3],[4,5],[10,2]}
        |____________||________________________|
           string      array of [pos,len] pairs
                       |____||________________|
                       #items      items

  - field->sort_value will have:

    - if field->report_string is unsorted:

        field->sort_value.value = field->report_string
        field->sort_value.items = {[0,3],[0,3],[7,5],[4,2]}
                                    (that is 'abc,defgh,xy')

    - if field->report_string is sorted already:

        field->sort_value.value = field->report_string
        field->sort_value.items = repstr_extra
                                  (that is also 'abc,defgh,xy')
2022-08-11 11:10:11 +02:00
..
datastruct gcc: match types 2021-09-22 17:18:50 +02:00
ioctl devicemapper: add dm_task_get_device_list 2021-12-20 16:13:28 +01:00
misc devicemapper: in sync with libdm 2021-09-23 16:49:58 +02:00
mm gcc: use apropriate type for reading and printing values 2020-08-28 21:43:03 +02:00
regex build: get separate builddir working again 2018-06-04 13:22:14 +01:00
vdo vdo: report supported range in error path 2022-07-11 01:18:24 +02:00
all.h libdm: report: add DM_REPORT_GROUP_JSON_STD group 2022-08-11 11:10:11 +02:00
libdm-common.c devicemapper: in sync with libdm 2021-09-23 16:49:58 +02:00
libdm-common.h device_mapper: rename libdevmapper.h -> all.h 2018-06-08 12:31:45 +01:00
libdm-config.c libdm-config: replace check for 0 2021-03-08 15:43:27 +01:00
libdm-deptree.c vdo: support v4 kernel target line 2022-07-11 01:18:24 +02:00
libdm-file.c debug: change sys_error to sys_debug 2021-03-10 01:11:52 +01:00
libdm-report.c libdm: report: enhance the way string list is stored internally 2022-08-11 11:10:11 +02:00
libdm-string.c device_mapper: remove dbg_malloc. 2018-06-08 13:40:53 +01:00
libdm-targets.c Allow dm-integrity to be used for raid images 2020-04-15 12:10:32 -05:00
libdm-timestamp.c device_mapper: remove dbg_malloc. 2018-06-08 13:40:53 +01:00
Makefile makefiles: correcting login of makefile 2018-12-17 10:55:20 +01:00