Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3e0ed83bc8103d36…
Commit: 3e0ed83bc8103d36efe0e2dcdfd4b5ad5fd822a8
Parent: 57af48d734f1f7aa985424a1e11287a0975077b9
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Fri Dec 19 09:17:16 2014 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Fri Dec 19 09:23:05 2014 +0100
libdm: report: add more comments about helper macros to get reserved values
Since GET_FIELD_RESERVED_VALUE always returns a pointer, don't reference
it with "&" when used - we already have that pointer value (this is an
addendum to recent commit 028ff309472834e82fe4b849ea4c243feb5098b9).
Only GET_TYPE_RESERVED_VALUE needs to be referenced with "&" as it
returns directly the value of that type.
---
lib/report/report.c | 25 +++++++++++++++++++------
1 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/lib/report/report.c b/lib/report/report.c
index 818e3fd..d0351f7 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -63,6 +63,23 @@ static const char _str_unknown[] = "unknown";
static const int32_t _reserved_num_undef_32 = INT32_C(-1);
/*
+ * Get type reserved value - the value returned is the direct value of that type.
+ */
+#define GET_TYPE_RESERVED_VALUE(id) _reserved_ ## id
+
+/*
+ * Get field reserved value - the value returned is always a pointer (const void *).
+ */
+#define GET_FIELD_RESERVED_VALUE(id) _reserved_ ## id.value
+
+/*
+ * Get first name assigned to the reserved value - this is the one that
+ * should be reported/displayed. All the other names assigned for the reserved
+ * value are synonyms recognized in selection criteria.
+ */
+#define GET_FIRST_RESERVED_NAME(id) _reserved_ ## id ## _names[0]
+
+/*
* Reserved values and their assigned names.
* The first name is the one that is also used for reporting.
* All names listed are synonyms recognized in selection criteria.
@@ -76,10 +93,6 @@ static const int32_t _reserved_num_undef_32 = INT32_C(-1);
* - 'reserved_value_id_y' (for 1)
* - 'reserved_value_id_n' (for 0)
*/
-#define GET_TYPE_RESERVED_VALUE(id) _reserved_ ## id
-#define GET_FIELD_RESERVED_VALUE(id) _reserved_ ## id.value
-#define GET_FIRST_RESERVED_NAME(id) _reserved_ ## id ## _names[0]
-
#define NUM uint64_t
#define TYPE_RESERVED_VALUE(type, id, desc, value, ...) \
@@ -721,7 +734,7 @@ static int _lvreadahead_disp(struct dm_report *rh, struct dm_pool *mem,
if (lv->read_ahead == DM_READ_AHEAD_AUTO)
return _field_set_value(field, GET_FIRST_RESERVED_NAME(lv_read_ahead_auto),
- &GET_FIELD_RESERVED_VALUE(lv_read_ahead_auto));
+ GET_FIELD_RESERVED_VALUE(lv_read_ahead_auto));
return _size32_disp(rh, mem, field, &lv->read_ahead, private);
}
@@ -1021,7 +1034,7 @@ static int _vgmdacopies_disp(struct dm_report *rh, struct dm_pool *mem,
if (count == VGMETADATACOPIES_UNMANAGED)
return _field_set_value(field, GET_FIRST_RESERVED_NAME(vg_mda_copies_unmanaged),
- &GET_FIELD_RESERVED_VALUE(vg_mda_copies_unmanaged));
+ GET_FIELD_RESERVED_VALUE(vg_mda_copies_unmanaged));
return _uint32_disp(rh, mem, field, &count, private);
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=da9da0d8c2201c24…
Commit: da9da0d8c2201c244d06a713134e96d2a26a0db5
Parent: 028ff309472834e82fe4b849ea4c243feb5098b9
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Thu Dec 18 15:11:25 2014 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Thu Dec 18 15:21:21 2014 +0100
report: properly set "undefined" reserved value for cache_policy field
Use helper macros to handle reserved values and also define "undefined"
reserved value as:
FIELD_RESERVED_VALUE(cache_policy, cache_policy_undef, "", "", "undefined")
Which means:
- print "" if the cache_policy value is undefined (the first name for this reserved value is "")
- recognize "undefined" reserved name as synonym to ""
(so statements like "lvs -S cache_policy=undefined" are still recognized)
---
lib/report/report.c | 3 ++-
lib/report/values.h | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/lib/report/report.c b/lib/report/report.c
index 5397d45..417396c 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -291,7 +291,8 @@ static int _cache_policy_disp(struct dm_report *rh, struct dm_pool *mem,
if (seg_is_cache(seg))
seg = first_seg(seg->pool_lv);
else
- return _field_set_value(field, "", GET_FIRST_RESERVED_NAME(cache_policy_undef));
+ return _field_set_value(field, GET_FIRST_RESERVED_NAME(cache_policy_undef),
+ GET_FIELD_RESERVED_VALUE(cache_policy_undef));
if (seg->policy_name) {
if (!(cache_policy_name = dm_pool_strdup(mem, seg->policy_name))) {
diff --git a/lib/report/values.h b/lib/report/values.h
index 4e12294..4ea92bd 100644
--- a/lib/report/values.h
+++ b/lib/report/values.h
@@ -86,7 +86,7 @@ FIELD_RESERVED_VALUE(lv_permissions, lv_permissions_r_override, "", "read-only-o
FIELD_RESERVED_VALUE(lv_read_ahead, lv_read_ahead_auto, "", &GET_TYPE_RESERVED_VALUE(num_undef_64), "auto")
/* Reserved values for SEG fields */
-FIELD_RESERVED_VALUE(cache_policy, cache_policy_undef, "", "undefined", "undefined")
+FIELD_RESERVED_VALUE(cache_policy, cache_policy_undef, "", "", "", "undefined")
/* TODO the following 2 need STR_LIST support for reserved values
FIELD_RESERVED_VALUE(cache_settings, cache_settings_default, "", "default", "default")
FIELD_RESERVED_VALUE(cache_settings, cache_settings_undef, "", "undefined", "undefined") */
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=aaf25ec6bd2201d4…
Commit: aaf25ec6bd2201d4219765d7bfca05636b554145
Parent: e471ea7890cf555ad920ca67a38254dd2504dabe
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Thu Dec 18 11:29:48 2014 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Thu Dec 18 11:29:48 2014 +0100
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.
---
libdm/libdm-report.c | 29 ++++++++++++++++++++++++-----
1 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c
index e3c3d2f..5ff6cda 100644
--- a/libdm/libdm-report.c
+++ b/libdm/libdm-report.c
@@ -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");