diff --git a/src/control/cmd/dmg/pretty/storage.go b/src/control/cmd/dmg/pretty/storage.go index eba4dfc58b6..8fda5b158e1 100644 --- a/src/control/cmd/dmg/pretty/storage.go +++ b/src/control/cmd/dmg/pretty/storage.go @@ -176,27 +176,34 @@ func PrintStorageFormatMap(hsm control.HostStorageMap, out io.Writer, opts ...Pr return nil } +// NVMe controller namespace ID (NSID) should only be displayed if >= 1. Zero value should be +// ignored in display output. func printSmdDevice(dev *storage.SmdDevice, iw io.Writer, opts ...PrintConfigOption) error { fc := getPrintConfig(opts...) + trAddr := fmt.Sprintf("TrAddr:%s", dev.Ctrlr.PciAddr) + nsID := fmt.Sprintf("NSID:%d", dev.CtrlrNamespaceID) + uid := fmt.Sprintf("UUID:%s", dev.UUID) + led := fmt.Sprintf("LED:%s", dev.Ctrlr.LedState) + if fc.LEDInfoOnly { - if _, err := fmt.Fprintf(iw, "TrAddr:%s NSID:%d", dev.Ctrlr.PciAddr, - dev.CtrlrNamespaceID); err != nil { - return err + out := trAddr + if dev.CtrlrNamespaceID > 0 { + out = fmt.Sprintf("%s %s", out, nsID) } if dev.UUID != "" { - if _, err := fmt.Fprintf(iw, " [UUID:%s]", dev.UUID); err != nil { - return err - } - } - if _, err := fmt.Fprintf(iw, " LED:%s\n", dev.Ctrlr.LedState); err != nil { - return err + out = fmt.Sprintf("%s [%s]", out, uid) } - return nil + + _, err := fmt.Fprintf(iw, "%s %s\n", out, led) + return err } - if _, err := fmt.Fprintf(iw, "UUID:%s [TrAddr:%s NSID:%d]\n", dev.UUID, dev.Ctrlr.PciAddr, - dev.CtrlrNamespaceID); err != nil { + out := fmt.Sprintf("%s [%s", uid, trAddr) + if dev.CtrlrNamespaceID > 0 { + out = fmt.Sprintf("%s %s", out, nsID) + } + if _, err := fmt.Fprintf(iw, "%s]\n", out); err != nil { return err } diff --git a/src/control/cmd/dmg/pretty/storage_test.go b/src/control/cmd/dmg/pretty/storage_test.go index 4648731dccf..f3d692bca67 100644 --- a/src/control/cmd/dmg/pretty/storage_test.go +++ b/src/control/cmd/dmg/pretty/storage_test.go @@ -1518,25 +1518,28 @@ host1 SmdInfo: &control.SmdInfo{ Devices: []*storage.SmdDevice{ { - UUID: test.MockUUID(0), - TargetIDs: []int32{0, 1, 2}, - HasSysXS: true, - Roles: storage.BdevRoles{storage.BdevRoleWAL}, - Ctrlr: newCtrlr, + UUID: test.MockUUID(0), + TargetIDs: []int32{0, 1, 2}, + HasSysXS: true, + Roles: storage.BdevRoles{storage.BdevRoleWAL}, + Ctrlr: newCtrlr, + CtrlrNamespaceID: 1, }, { - UUID: test.MockUUID(1), - TargetIDs: []int32{3, 4, 5}, - Roles: storage.BdevRoles{storage.BdevRoleMeta | storage.BdevRoleData}, - Ctrlr: faultCtrlr, + UUID: test.MockUUID(1), + TargetIDs: []int32{3, 4, 5}, + Roles: storage.BdevRoles{storage.BdevRoleMeta | storage.BdevRoleData}, + Ctrlr: faultCtrlr, + CtrlrNamespaceID: 1, }, { - UUID: test.MockUUID(2), - TargetIDs: []int32{0, 1, 2}, - Rank: 1, - HasSysXS: true, - Roles: storage.BdevRoles{storage.BdevRoleWAL}, - Ctrlr: unknoCtrlr, + UUID: test.MockUUID(2), + TargetIDs: []int32{0, 1, 2}, + Rank: 1, + HasSysXS: true, + Roles: storage.BdevRoles{storage.BdevRoleWAL}, + Ctrlr: unknoCtrlr, + CtrlrNamespaceID: 1, }, { UUID: test.MockUUID(3), @@ -1555,13 +1558,13 @@ host1 host1 ----- Devices - UUID:00000000-0000-0000-0000-000000000000 [TrAddr:0000:8a:00.0 NSID:0] + UUID:00000000-0000-0000-0000-000000000000 [TrAddr:0000:8a:00.0 NSID:1] Roles:wal SysXS Targets:[0 1 2] Rank:0 State:NEW LED:OFF - UUID:00000001-0001-0001-0001-000000000001 [TrAddr:0000:8b:00.0 NSID:0] + UUID:00000001-0001-0001-0001-000000000001 [TrAddr:0000:8b:00.0 NSID:1] Roles:data,meta Targets:[3 4 5] Rank:0 State:EVICTED LED:ON - UUID:00000002-0002-0002-0002-000000000002 [TrAddr:0000:da:00.0 NSID:0] + UUID:00000002-0002-0002-0002-000000000002 [TrAddr:0000:da:00.0 NSID:1] Roles:wal SysXS Targets:[0 1 2] Rank:1 State:UNKNOWN LED:NA - UUID:00000003-0003-0003-0003-000000000003 [TrAddr:0000:db:00.0 NSID:0] + UUID:00000003-0003-0003-0003-000000000003 [TrAddr:0000:db:00.0] Roles:data,meta Targets:[3 4 5] Rank:1 State:NORMAL LED:QUICK_BLINK `, }, @@ -1693,7 +1696,7 @@ host1 host1 ----- Devices - TrAddr:0000:db:00.0 NSID:0 [UUID:842c739b-86b5-462f-a7ba-b4a91b674f3d] LED:QUICK_BLINK + TrAddr:0000:db:00.0 [UUID:842c739b-86b5-462f-a7ba-b4a91b674f3d] LED:QUICK_BLINK `, }, "identify led; no uuid specified": {