[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20251024-fix-module-info-json-v3-2-36862ce701ae@a-eberle.de>
Date: Fri, 24 Oct 2025 12:32:52 +0200
From: Johannes Eigner <johannes.eigner@...berle.de>
To: netdev@...r.kernel.org
Cc: Michal Kubecek <mkubecek@...e.cz>,
Danielle Ratson <danieller@...dia.com>,
Stephan Wurm <stephan.wurm@...berle.de>, Andrew Lunn <andrew@...n.ch>,
Johannes Eigner <johannes.eigner@...berle.de>
Subject: [PATCH ethtool v3 2/2] module info: Fix duplicated JSON keys
Fix duplicated JSON keys in the module diagnostics output.
This changes the JSON API in an incompatible way, but leaving it as it
is is not an option either. The API change is limited to the following
keys for measured values on QSFP and CMIS modules:
* "module_temperature" renamed to "module_temperature_measurement"
* "module_voltage" renamed to "module_voltage_measurement"
Keys with the same names for threshold values are kept unchanged to
maximize backward compatibility. Keys for SFP modules are changed as
well, but since it was never possible to get the diagnostics in JSON
format for SFP modules, this does not introduce any backward
compatibility issues for SFP modules. Used key names for SFP modules are
aligned with QSFP and CMIS modules.
Duplicated JSON keys result in undefined behavior which is handled
differently by different JSON parsers. From RFC 8259:
Many implementations report the last name/value pair
only. Other implementations report an error or fail to parse the
object, and some implementations report all of the name/value pairs,
including duplicates.
First behavior can be confirmed for Boost.JSON, nlohmann json,
javascript (running in Firefox and Chromium), jq, php, python and ruby.
With these parsers it was not possible to get the measured module
temperature and voltage, since they were silently overwritten by the
threshold values.
Shortened example output for module temperature.
Without patch:
$ ethtool -j -m sfp1
[ {
...
"module_temperature": 26.5898,
...
"module_temperature": {
"high_alarm_threshold": 110,
"low_alarm_threshold": -45,
"high_warning_threshold": 95,
"low_warning_threshold": -42
},
...
} ]
With patch:
$ ethtool -j -m sfp1
[ {
...
"module_temperature_measurement": 35.793,
...
"module_temperature": {
"high_alarm_threshold": 110,
"low_alarm_threshold": -45,
"high_warning_threshold": 95,
"low_warning_threshold": -42
},
...
} ]
Fixes: 3448a2f73e77 (cmis: Add JSON output handling to --module-info in CMIS modules)
Fixes: 008167804e54 (module_common: Add helpers to support JSON printing for common value types)
Signed-off-by: Johannes Eigner <johannes.eigner@...berle.de>
---
module-common.c | 4 ++--
module_info.json | 4 ++--
sfpdiag.c | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/module-common.c b/module-common.c
index 11b71bd..4e9a0a7 100644
--- a/module-common.c
+++ b/module-common.c
@@ -651,8 +651,8 @@ void module_show_mit_compliance(u16 value)
void module_show_dom_mod_lvl_monitors(const struct sff_diags *sd)
{
- PRINT_TEMP_ALL("Module temperature", "module_temperature",
+ PRINT_TEMP_ALL("Module temperature", "module_temperature_measurement",
sd->sfp_temp[MCURR]);
- PRINT_VCC_ALL("Module voltage", "module_voltage",
+ PRINT_VCC_ALL("Module voltage", "module_voltage_measurement",
sd->sfp_voltage[MCURR]);
}
diff --git a/module_info.json b/module_info.json
index 1ef214b..049250b 100644
--- a/module_info.json
+++ b/module_info.json
@@ -47,11 +47,11 @@
"type": "integer",
"description": "Unit: nm"
},
- "module_temperature": {
+ "module_temperature_measurement": {
"type": "number",
"description": "Unit: degrees C"
},
- "module_voltage": {
+ "module_voltage_measurement": {
"type": "number",
"description": "Unit: V"
},
diff --git a/sfpdiag.c b/sfpdiag.c
index a32f72c..137a109 100644
--- a/sfpdiag.c
+++ b/sfpdiag.c
@@ -254,9 +254,9 @@ void sff8472_show_all(const __u8 *id)
if (!sd.supports_dom)
return;
- PRINT_BIAS_ALL("Laser bias current", "laser_bias_current",
+ PRINT_BIAS_ALL("Laser bias current", "laser_tx_bias_current",
sd.bias_cur[MCURR]);
- PRINT_xX_PWR_ALL("Laser output power", "laser_output_power",
+ PRINT_xX_PWR_ALL("Laser output power", "transmit_avg_optical_power",
sd.tx_power[MCURR]);
if (!sd.rx_power_type)
--
2.43.0
Download attachment "smime.p7s" of type "application/x-pkcs7-signature" (4153 bytes)
Powered by blists - more mailing lists