Commit feba6aa
committed
utils/nvme: enhance get_ns_status with show-topology fallback
The 'nvme show-topology /dev/<controller>' form fails on some nvme-cli
builds, returning {"error": "Invalid device name"} instead of a valid
JSON topology. Additionally, in multi-path subsystems where two
controllers (e.g. nvme0 and nvme3) share a namespace (e.g. nvme3n1),
the namespace block device is named after only one of the controllers,
making a namespace name constructed from controller_name unreliable.
Enhance get_ns_status with a two-stage approach and unified parsing:
- Introduce _iter_topology_paths() generator helper to normalize and
flatten the topology traversal across differing JSON schemas:
- Targeted schema: where Name and State reside directly on Path
- Whole-system schema: where Name and State are nested under Controller[]
- Primary path:
nvme show-topology /dev/<controller_name> -o json
Queries targeted controller and extracts state using the helper.
Returns immediately on match.
- Fallback path:
nvme show-topology -o json (whole-system, no device argument)
Triggered when primary path returns an error payload, raises
JSONDecodeError, or yields no match. Uses the same helper to match
NSID and Controller.Name unambiguously across multi-controller subsystems.
Both paths return [State, ANAState], preserving existing API and behavior.
Signed-off-by: Maram Srimannarayana Murthy <msmurthy@linux.vnet.ibm.com>1 parent 2454cd2 commit feba6aa
2 files changed
Lines changed: 75 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
| |||
650 | 649 | | |
651 | 650 | | |
652 | 651 | | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
653 | 681 | | |
654 | 682 | | |
655 | | - | |
| 683 | + | |
656 | 684 | | |
657 | | - | |
658 | | - | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
659 | 689 | | |
660 | | - | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
661 | 694 | | |
662 | 695 | | |
| 696 | + | |
663 | 697 | | |
664 | 698 | | |
665 | | - | |
666 | | - | |
667 | | - | |
668 | | - | |
669 | | - | |
670 | | - | |
671 | | - | |
672 | | - | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
673 | 729 | | |
674 | 730 | | |
675 | 731 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
26 | 32 | | |
27 | 33 | | |
28 | 34 | | |
| |||
0 commit comments