Commit 64bed0a
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]>1 parent 089c63d commit 64bed0a
3 files changed
+113
-81
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4423 | 4423 | | |
4424 | 4424 | | |
4425 | 4425 | | |
| 4426 | + | |
| 4427 | + | |
| 4428 | + | |
| 4429 | + | |
| 4430 | + | |
| 4431 | + | |
| 4432 | + | |
| 4433 | + | |
| 4434 | + | |
| 4435 | + | |
| 4436 | + | |
| 4437 | + | |
| 4438 | + | |
| 4439 | + | |
| 4440 | + | |
| 4441 | + | |
| 4442 | + | |
| 4443 | + | |
| 4444 | + | |
| 4445 | + | |
| 4446 | + | |
| 4447 | + | |
| 4448 | + | |
| 4449 | + | |
| 4450 | + | |
| 4451 | + | |
| 4452 | + | |
| 4453 | + | |
| 4454 | + | |
| 4455 | + | |
| 4456 | + | |
| 4457 | + | |
| 4458 | + | |
| 4459 | + | |
| 4460 | + | |
| 4461 | + | |
| 4462 | + | |
| 4463 | + | |
| 4464 | + | |
| 4465 | + | |
| 4466 | + | |
| 4467 | + | |
| 4468 | + | |
| 4469 | + | |
| 4470 | + | |
| 4471 | + | |
| 4472 | + | |
| 4473 | + | |
| 4474 | + | |
| 4475 | + | |
| 4476 | + | |
| 4477 | + | |
| 4478 | + | |
| 4479 | + | |
| 4480 | + | |
| 4481 | + | |
| 4482 | + | |
| 4483 | + | |
| 4484 | + | |
| 4485 | + | |
| 4486 | + | |
| 4487 | + | |
| 4488 | + | |
| 4489 | + | |
| 4490 | + | |
| 4491 | + | |
| 4492 | + | |
| 4493 | + | |
| 4494 | + | |
| 4495 | + | |
| 4496 | + | |
| 4497 | + | |
| 4498 | + | |
| 4499 | + | |
| 4500 | + | |
| 4501 | + | |
| 4502 | + | |
| 4503 | + | |
| 4504 | + | |
| 4505 | + | |
| 4506 | + | |
| 4507 | + | |
| 4508 | + | |
| 4509 | + | |
| 4510 | + | |
| 4511 | + | |
| 4512 | + | |
| 4513 | + | |
| 4514 | + | |
| 4515 | + | |
| 4516 | + | |
| 4517 | + | |
| 4518 | + | |
| 4519 | + | |
| 4520 | + | |
| 4521 | + | |
| 4522 | + | |
4426 | 4523 | | |
4427 | 4524 | | |
4428 | 4525 | | |
4429 | 4526 | | |
4430 | 4527 | | |
4431 | 4528 | | |
4432 | 4529 | | |
4433 | | - | |
4434 | | - | |
4435 | | - | |
4436 | 4530 | | |
4437 | 4531 | | |
4438 | 4532 | | |
| |||
4446 | 4540 | | |
4447 | 4541 | | |
4448 | 4542 | | |
4449 | | - | |
4450 | | - | |
4451 | 4543 | | |
4452 | 4544 | | |
4453 | 4545 | | |
4454 | 4546 | | |
4455 | | - | |
4456 | | - | |
4457 | | - | |
4458 | | - | |
4459 | | - | |
4460 | | - | |
4461 | | - | |
4462 | | - | |
4463 | | - | |
4464 | | - | |
4465 | | - | |
4466 | | - | |
4467 | | - | |
4468 | | - | |
4469 | | - | |
4470 | | - | |
4471 | | - | |
4472 | | - | |
4473 | | - | |
4474 | | - | |
4475 | | - | |
4476 | | - | |
4477 | | - | |
4478 | | - | |
4479 | | - | |
4480 | | - | |
4481 | | - | |
4482 | | - | |
4483 | | - | |
4484 | | - | |
4485 | | - | |
4486 | | - | |
4487 | | - | |
4488 | | - | |
4489 | | - | |
4490 | | - | |
4491 | | - | |
4492 | | - | |
4493 | | - | |
4494 | | - | |
4495 | | - | |
4496 | | - | |
4497 | | - | |
4498 | | - | |
4499 | | - | |
4500 | | - | |
4501 | | - | |
4502 | | - | |
4503 | | - | |
4504 | | - | |
4505 | | - | |
4506 | | - | |
4507 | | - | |
4508 | | - | |
4509 | | - | |
4510 | | - | |
4511 | | - | |
4512 | | - | |
4513 | | - | |
4514 | | - | |
4515 | | - | |
4516 | | - | |
4517 | | - | |
4518 | | - | |
| 4547 | + | |
| 4548 | + | |
| 4549 | + | |
| 4550 | + | |
4519 | 4551 | | |
4520 | 4552 | | |
4521 | 4553 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5589 | 5589 | | |
5590 | 5590 | | |
5591 | 5591 | | |
5592 | | - | |
5593 | | - | |
5594 | | - | |
5595 | | - | |
5596 | | - | |
5597 | | - | |
5598 | | - | |
5599 | | - | |
5600 | | - | |
5601 | | - | |
5602 | | - | |
5603 | | - | |
5604 | 5592 | | |
5605 | 5593 | | |
5606 | 5594 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
125 | 137 | | |
126 | 138 | | |
127 | 139 | | |
| |||
0 commit comments