Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=81839cc4ebf566ea9f3e6…
Commit: 81839cc4ebf566ea9f3e6d819c7338b98cdec374
Parent: ce58e9d5b37c3e408f2b41c8095980490a87f2a4
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Mon Aug 15 11:40:52 2022 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Aug 16 13:42:50 2022 +0200
report: report numeric values (not string synonyms) for NUM and BIN fields with json_std format
Internally, NUM and BIN fields are marked as DM_REPORT_FIELD_TYPE_NUM_NUMBER
through libdevmapper API. The new 'json_std' format mandates that the report
string representing such a value must be a number, not an arbitrary string.
This is because numeric values in 'json_std' format do not have double quotes
around them. This practically means, we can't use string synonyms
("named reserved values") for such values and the report string must always
represent a proper number.
With 'json' and 'basic' formats, this is not an issue because 'basic' format
doesn't have any structure or typing at all and 'json' format puts all values
in quotes, including numeric ones.
---
lib/commands/toolcontext.h | 1 +
lib/report/report.c | 7 ++++---
man/lvmreport.7_main | 4 ++++
tools/reporter.c | 10 ++++++++++
4 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index f16322d4e..7a4979b33 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -144,6 +144,7 @@ struct cmd_context {
unsigned degraded_activation:1;
unsigned auto_set_activation_skip:1;
unsigned si_unit_consistency:1;
+ unsigned report_strict_type_mode:1;
unsigned report_binary_values_as_numeric:1;
unsigned report_mark_hidden_devices:1;
unsigned metadata_read_only:1;
diff --git a/lib/report/report.c b/lib/report/report.c
index c06b22674..8a5122ff9 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -1256,7 +1256,7 @@ static int _binary_disp(struct dm_report *rh, struct dm_pool *mem __attribute__(
{
const struct cmd_context *cmd = (const struct cmd_context *) private;
- if (cmd->report_binary_values_as_numeric)
+ if (cmd->report_strict_type_mode || cmd->report_binary_values_as_numeric)
/* "0"/"1" */
return _field_set_value(field, bin_value ? _str_one : _str_zero, bin_value ? &_one64 : &_zero64);
@@ -1269,7 +1269,7 @@ static int _binary_undef_disp(struct dm_report *rh, struct dm_pool *mem __attrib
{
const struct cmd_context *cmd = (const struct cmd_context *) private;
- if (cmd->report_binary_values_as_numeric)
+ if (cmd->report_strict_type_mode || cmd->report_binary_values_as_numeric)
return _field_set_value(field, GET_FIRST_RESERVED_NAME(num_undef_64), &GET_TYPE_RESERVED_VALUE(num_undef_64));
return _field_set_value(field, _str_unknown, &GET_TYPE_RESERVED_VALUE(num_undef_64));
@@ -3041,10 +3041,11 @@ static int _vgmdacopies_disp(struct dm_report *rh, struct dm_pool *mem,
struct dm_report_field *field,
const void *data, void *private)
{
+ struct cmd_context *cmd = (struct cmd_context *) private;
const struct volume_group *vg = (const struct volume_group *) data;
uint32_t count = vg_mda_copies(vg);
- if (count == VGMETADATACOPIES_UNMANAGED)
+ if (count == VGMETADATACOPIES_UNMANAGED && !cmd->report_strict_type_mode)
return _field_set_value(field, GET_FIRST_RESERVED_NAME(vg_mda_copies_unmanaged),
GET_FIELD_RESERVED_VALUE(vg_mda_copies_unmanaged));
diff --git a/man/lvmreport.7_main b/man/lvmreport.7_main
index 1ef5d25db..0015cdce7 100644
--- a/man/lvmreport.7_main
+++ b/man/lvmreport.7_main
@@ -1335,6 +1335,10 @@ compared to the original \fBjson\fP format:
.RS
- it does not use double quotes around numeric values,
.br
+- numeric values are always expressed as numbers, not reserved strings
+ representing them (this also means that report/binary_values_as_numeric=1
+ setting is forced)
+.br
- it uses 'null' for undefined numeric values,
.br
- it prints string list as proper JSON array of strings instead of a single string.
diff --git a/tools/reporter.c b/tools/reporter.c
index b31f1891e..e62858f42 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -1495,6 +1495,16 @@ int report_format_init(struct cmd_context *cmd)
return 0;
}
+ /*
+ * JSON_STD requires strict type mode. That means all NUM and BIN
+ * fields are always reported as numeric values and not strings which
+ * are synonyms to these numeric values.
+ */
+ if (args.report_group_type == DM_REPORT_GROUP_JSON_STD)
+ cmd->report_strict_type_mode = 1;
+ else
+ cmd->report_strict_type_mode = 0;
+
if (report_command_log) {
single_args = &args.single_args[REPORT_IDX_LOG];
single_args->report_type = CMDLOG;
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=1ab6d0d8d8d043a99cb44…
Commit: 1ab6d0d8d8d043a99cb44531de563c7aeb1f0f75
Parent: ce58e9d5b37c3e408f2b41c8095980490a87f2a4
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Mon Aug 15 11:40:52 2022 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Aug 16 13:35:30 2022 +0200
report: report numeric values (not string synonyms) for NUM and BIN fields with json_std format
Internally, NUM and BIN fields are marked as DM_REPORT_FIELD_TYPE_NUM_NUMBER
through libdevmapper API. The new 'json_std' format mandates that the report
string representing such a value must be a number, not an arbitrary string.
This is because numeric values in 'json_std' format do not have double quotes
around them. This practically means, we can't use string synonyms
("named reserved values") for such values and the report string must always
represent a proper number.
With 'json' and 'basic' formats, this is not an issue because 'basic' format
doesn't have any structure or typing at all and 'json' format puts all values
in quotes, including numeric ones.
---
lib/commands/toolcontext.h | 1 +
lib/report/report.c | 7 ++++---
man/lvmreport.7_main | 6 +++++-
tools/reporter.c | 10 ++++++++++
4 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index f16322d4e..7a4979b33 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -144,6 +144,7 @@ struct cmd_context {
unsigned degraded_activation:1;
unsigned auto_set_activation_skip:1;
unsigned si_unit_consistency:1;
+ unsigned report_strict_type_mode:1;
unsigned report_binary_values_as_numeric:1;
unsigned report_mark_hidden_devices:1;
unsigned metadata_read_only:1;
diff --git a/lib/report/report.c b/lib/report/report.c
index c06b22674..8a5122ff9 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -1256,7 +1256,7 @@ static int _binary_disp(struct dm_report *rh, struct dm_pool *mem __attribute__(
{
const struct cmd_context *cmd = (const struct cmd_context *) private;
- if (cmd->report_binary_values_as_numeric)
+ if (cmd->report_strict_type_mode || cmd->report_binary_values_as_numeric)
/* "0"/"1" */
return _field_set_value(field, bin_value ? _str_one : _str_zero, bin_value ? &_one64 : &_zero64);
@@ -1269,7 +1269,7 @@ static int _binary_undef_disp(struct dm_report *rh, struct dm_pool *mem __attrib
{
const struct cmd_context *cmd = (const struct cmd_context *) private;
- if (cmd->report_binary_values_as_numeric)
+ if (cmd->report_strict_type_mode || cmd->report_binary_values_as_numeric)
return _field_set_value(field, GET_FIRST_RESERVED_NAME(num_undef_64), &GET_TYPE_RESERVED_VALUE(num_undef_64));
return _field_set_value(field, _str_unknown, &GET_TYPE_RESERVED_VALUE(num_undef_64));
@@ -3041,10 +3041,11 @@ static int _vgmdacopies_disp(struct dm_report *rh, struct dm_pool *mem,
struct dm_report_field *field,
const void *data, void *private)
{
+ struct cmd_context *cmd = (struct cmd_context *) private;
const struct volume_group *vg = (const struct volume_group *) data;
uint32_t count = vg_mda_copies(vg);
- if (count == VGMETADATACOPIES_UNMANAGED)
+ if (count == VGMETADATACOPIES_UNMANAGED && !cmd->report_strict_type_mode)
return _field_set_value(field, GET_FIRST_RESERVED_NAME(vg_mda_copies_unmanaged),
GET_FIELD_RESERVED_VALUE(vg_mda_copies_unmanaged));
diff --git a/man/lvmreport.7_main b/man/lvmreport.7_main
index 1ef5d25db..78c43664c 100644
--- a/man/lvmreport.7_main
+++ b/man/lvmreport.7_main
@@ -1335,9 +1335,13 @@ compared to the original \fBjson\fP format:
.RS
- it does not use double quotes around numeric values,
.br
+- numeric values are always expressed as numbers, not reserved strings
+ representing them (this also means that report/binary_values_as_numeric=1
+ setting is forced)
+.br
- it uses 'null' for undefined numeric values,
.br
-- it prints string list as proper JSON array of strings instead of a single string.
+- it prints string list as proper JSON array of strings instead of a single string.
.RE
.P
Note that some configuration settings and command line options have no
diff --git a/tools/reporter.c b/tools/reporter.c
index b31f1891e..e62858f42 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -1495,6 +1495,16 @@ int report_format_init(struct cmd_context *cmd)
return 0;
}
+ /*
+ * JSON_STD requires strict type mode. That means all NUM and BIN
+ * fields are always reported as numeric values and not strings which
+ * are synonyms to these numeric values.
+ */
+ if (args.report_group_type == DM_REPORT_GROUP_JSON_STD)
+ cmd->report_strict_type_mode = 1;
+ else
+ cmd->report_strict_type_mode = 0;
+
if (report_command_log) {
single_args = &args.single_args[REPORT_IDX_LOG];
single_args->report_type = CMDLOG;
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=fc8fda641781d0978ff22…
Commit: fc8fda641781d0978ff22ad0a59d5a19b5e450e1
Parent: b318c9c20f40be1583e7d0751a733f77be173012
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Fri Aug 5 11:02:25 2022 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Thu Aug 11 11:10:11 2022 +0200
report: fix pe_start column type from NUM to SIZ
The 'pe_start' column was incorrectly marked as being of type NUM.
This was not correct as pe_start is actually of type SIZ, which means
it can have a size suffix and hence it's not a pure numeric value.
Proper column type is important for selection to work correctly, so we
can also do comparisons while using suffixes.
This is also important for new "json_std" output format which does not
put double quotes around pure numeric values. With pe_start incorrectly
marked as NUM instead of SIZ, this produced invalid JSON output
like '"pe_start" = 1.00m' because it contained the 'm' (or other)
size suffix. If properly marked as SIZ, this is then put in double
quotes like '"pe_start" = "1.00m"'.
---
lib/report/columns.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/report/columns.h b/lib/report/columns.h
index 7e450dace..d702635d2 100644
--- a/lib/report/columns.h
+++ b/lib/report/columns.h
@@ -191,7 +191,7 @@ FIELD(LABEL, label, NUM, "PExtVsn", type, 0, pvextvsn, pv_ext_vsn, "PV header ex
/*
* PVS type fields
*/
-FIELD(PVS, pv, NUM, "1st PE", pe_start, 7, size64, pe_start, "Offset to the start of data on the underlying device.", 0)
+FIELD(PVS, pv, SIZ, "1st PE", pe_start, 7, size64, pe_start, "Offset to the start of data on the underlying device.", 0)
FIELD(PVS, pv, SIZ, "PSize", id, 0, pvsize, pv_size, "Size of PV in current units.", 0)
FIELD(PVS, pv, SIZ, "PFree", id, 0, pvfree, pv_free, "Total amount of unallocated space in current units.", 0)
FIELD(PVS, pv, SIZ, "Used", id, 0, pvused, pv_used, "Total amount of allocated space in current units.", 0)