/
storage_scm.go
126 lines (101 loc) · 3.42 KB
/
storage_scm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//
// (C) Copyright 2020-2024 Intel Corporation.
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
package pretty
import (
"fmt"
"io"
"sort"
"github.com/dustin/go-humanize"
"github.com/daos-stack/daos/src/control/lib/txtfmt"
"github.com/daos-stack/daos/src/control/server/storage"
)
func printScmMountPoints(mountpoints storage.ScmMountPoints, out io.Writer, opts ...PrintConfigOption) error {
iw := txtfmt.NewIndentWriter(out)
if len(mountpoints) == 0 {
fmt.Fprintln(iw, "No SCM mount results")
return nil
}
mntTitle := "SCM Mount"
resultTitle := "Format Result"
formatter := txtfmt.NewTableFormatter(mntTitle, resultTitle)
formatter.InitWriter(out)
var table []txtfmt.TableRow
sort.Slice(mountpoints, func(i, j int) bool { return mountpoints[i].Path < mountpoints[j].Path })
for _, mountpoint := range mountpoints {
row := txtfmt.TableRow{mntTitle: mountpoint.Path}
row[resultTitle] = mountpoint.Info
table = append(table, row)
}
formatter.Format(table)
return nil
}
// PrintScmModules displays PMem module details in a verbose table.
//
// TODO: un-export function when not needed in cmd/daos_server/storage.go
func PrintScmModules(modules storage.ScmModules, out io.Writer, opts ...PrintConfigOption) error {
w := txtfmt.NewErrWriter(out)
iw := txtfmt.NewIndentWriter(out)
if len(modules) == 0 {
fmt.Fprintln(iw, "No SCM modules found")
return w.Err
}
physicalIdTitle := "SCM Module"
socketTitle := "Socket"
memCtrlrTitle := "Memory Ctrlr"
channelTitle := "Channel"
slotTitle := "Channel Slot"
capacityTitle := "Capacity"
uidTitle := "UID"
partNumTitle := "Part Number"
healthTitle := "Health"
formatter := txtfmt.NewTableFormatter(
physicalIdTitle, socketTitle, memCtrlrTitle, channelTitle, slotTitle, capacityTitle,
uidTitle, partNumTitle, healthTitle,
)
formatter.InitWriter(out)
var table []txtfmt.TableRow
sort.Slice(modules, func(i, j int) bool { return modules[i].PhysicalID < modules[j].PhysicalID })
for _, m := range modules {
row := txtfmt.TableRow{physicalIdTitle: fmt.Sprint(m.PhysicalID)}
row[socketTitle] = fmt.Sprint(m.SocketID)
row[memCtrlrTitle] = fmt.Sprint(m.ControllerID)
row[channelTitle] = fmt.Sprint(m.ChannelID)
row[slotTitle] = fmt.Sprint(m.ChannelPosition)
row[capacityTitle] = humanize.IBytes(m.Capacity)
row[uidTitle] = m.UID
row[partNumTitle] = m.PartNumber
row[healthTitle] = m.HealthState
table = append(table, row)
}
formatter.Format(table)
return w.Err
}
// PrintScmNamespaces displays pmem block device details in a verbose table.
//
// TODO: un-export function when not needed in cmd/daos_server/storage.go
func PrintScmNamespaces(namespaces storage.ScmNamespaces, out io.Writer, opts ...PrintConfigOption) error {
w := txtfmt.NewErrWriter(out)
iw := txtfmt.NewIndentWriter(out)
if len(namespaces) == 0 {
fmt.Fprintln(iw, "No SCM namespaces found")
return w.Err
}
deviceTitle := "SCM Namespace"
socketTitle := "Socket"
capacityTitle := "Capacity"
formatter := txtfmt.NewTableFormatter(deviceTitle, socketTitle, capacityTitle)
formatter.InitWriter(out)
var table []txtfmt.TableRow
sort.Slice(namespaces, func(i, j int) bool { return namespaces[i].BlockDevice < namespaces[j].BlockDevice })
for _, ns := range namespaces {
row := txtfmt.TableRow{deviceTitle: ns.BlockDevice}
row[socketTitle] = fmt.Sprint(ns.NumaNode)
row[capacityTitle] = humanize.Bytes(ns.Size)
table = append(table, row)
}
formatter.Format(table)
return w.Err
}