summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/commands/toolcontext.h1
-rw-r--r--lib/report/report.c7
-rw-r--r--man/lvmreport.7_main4
-rw-r--r--tools/reporter.c10
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;