1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-30 17:18:21 +03:00

libdm: report: also check whether field type is supported for field-specific reserved value

We only checked global per-report-type reserved values for compatibility
with selection code. This patch also adds a check for per-report-field
reserved values. This avoids problems where unsupported report type is
used as reserved value which could cause hard to debug problems
otherwise. So this additional check stops from registering unsupported
and unhandled per-field reserved values.

Registerting such unsupported reserved value is a programmatic error,
so report internal error in this case to stop us from making a mistake
here in the future or even today where STR_LIST fields can't have
reserved values yet.
This commit is contained in:
Peter Rajnoha 2014-12-18 11:29:48 +01:00
parent e471ea7890
commit aaf25ec6bd

View File

@ -1995,9 +1995,12 @@ dm_percent_t dm_make_percent(uint64_t numerator, uint64_t denominator)
* Used to check whether the reserved_values definition passed to
* dm_report_init_with_selection contains only supported reserved value types.
*/
static int _check_reserved_values_supported(const struct dm_report_reserved_value reserved_values[])
static int _check_reserved_values_supported(const struct dm_report_field_type fields[],
const struct dm_report_reserved_value reserved_values[])
{
const struct dm_report_reserved_value *iter;
const struct dm_report_field_reserved_value *field_res;
const struct dm_report_field_type *field;
static uint32_t supported_reserved_types = DM_REPORT_FIELD_TYPE_NUMBER |
DM_REPORT_FIELD_TYPE_SIZE |
DM_REPORT_FIELD_TYPE_PERCENT |
@ -2008,9 +2011,25 @@ static int _check_reserved_values_supported(const struct dm_report_reserved_valu
iter = reserved_values;
while (iter->type) {
if (!(iter->type & supported_reserved_types))
return 0;
while (iter->value) {
if (iter->type) {
if (!(iter->type & supported_reserved_types)) {
log_error(INTERNAL_ERROR "_check_reserved_values_supported: "
"global reserved value for type 0x%x not supported",
iter->type);
return 0;
}
} else {
field_res = (const struct dm_report_field_reserved_value *) iter->value;
field = &fields[field_res->field_num];
if (!(field->flags & supported_reserved_types)) {
log_error(INTERNAL_ERROR "_check_reserved_values_supported: "
"field-specific reserved value of type 0x%x for "
"field %s not supported",
field->flags & DM_REPORT_FIELD_TYPE_MASK, field->id);
return 0;
}
}
iter++;
}
@ -2906,7 +2925,7 @@ struct dm_report *dm_report_init_with_selection(uint32_t *report_types,
return rh;
}
if (!_check_reserved_values_supported(reserved_values)) {
if (!_check_reserved_values_supported(fields, reserved_values)) {
log_error(INTERNAL_ERROR "dm_report_init_with_selection: "
"trying to register unsupported reserved value type, "
"skipping report selection");