You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
nvme-list: fix verbose JSON output for 'nvme list' command
The verbose JSON output of the nvme list command is currently incorrect in
both multipath and non-multipath configurations. Specifically, it prints
empty Namespaces[] and Paths[] arrays in the wrong places, leading to
confusion and invalid output. For example, on a system with single NVMe
disk, signle controller and one namepsace created, 'nvme list --verbose
--output json' prints the following output:
With multipath disabled:
{
"Devices":[
{
...
"Subsystems":[
{
...
"Controllers":[
{
"Controller":"nvme0",
...
"Namespaces":[
{
"NameSpace":"nvme0n1",
...
}
],
"Paths":[] <---- Incorrct: Path should not be present
}
],
"Namespaces":[] <-----Incorrect: Namespaces should not be here
}
]
}
]
}
With multipath enabled, the output changes, but still has misplaced or
empty fields:
{
"Devices":[
{
...
"Subsystems":[
{
...
"Controllers":[
{
"Controller":"nvme0",
...
"Namespaces":[] <-----Incorrect: Namespaces should not be here
"Paths":[
{
"Path":"nvme0c0n1",
"ANAState":"optimized"
}
]
}
],
"Namespaces":[
{
"NameSpace":"nvme0n1",
...
}
]
}
]
}
]
}
So as we could see above in both multipath and non-multipath scenarios,
the JSON formatted output is incorrect.
The existing JSON formatting logic doesn't differentiate between multipath
and non-multipath configurations. As a result:
- "Paths" is printed even when multipath is disabled.
- "Namespaces" appear at incorrect levels in the output tree.
This patch updates the logic for verbose JSON output in nvme list to
properly reflect the system configuration:
- When multipath is enabled, each namespace entry includes its associated
paths and controller attributes.
- When multipath is disabled, namespaces are shown directly under the
controller, and the "Paths" array is omitted.
After this fix, JSON formatted output looks as below:
Scenario1: multipath is enabled
{
Devices: [
{
...
Subsystems: [
{
...
Namespaces: [
{
"NameSpace":"nvme0n1",
...
Paths: [
{
"Path":"nvme0c0n1",
"ANAState":"optimized",
"Controller":"nvme0",
...
}
]
}
]
}
]
}
]
}
Scenario2: multipath is disabled
{
Devices: [
{
...
Subsystems: [
{
...
Controllers: [
{
"Controller":"nvme0",
...
"Namespaces":[
{
"NameSpace":"nvme0n1",
...
}
]
}
]
}
]
}
]
}
This fix ensures the JSON output is semantically accurate and easier to
consume by tools that parse nvme list --verbose --output json.
Reported-by: Maram Srimannarayana Murthy <[email protected]>
Signed-off-by: Nilay Shroff <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Daniel Wagner <[email protected]>
0 commit comments