/
storage_nvme.go
290 lines (250 loc) · 8.48 KB
/
storage_nvme.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
//
// (C) Copyright 2020-2024 Intel Corporation.
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
package pretty
import (
"fmt"
"io"
"sort"
"strings"
"time"
"github.com/dustin/go-humanize"
"github.com/daos-stack/daos/src/control/common"
"github.com/daos-stack/daos/src/control/lib/control"
"github.com/daos-stack/daos/src/control/lib/ranklist"
"github.com/daos-stack/daos/src/control/lib/txtfmt"
"github.com/daos-stack/daos/src/control/server/storage"
)
func printNvmeControllerSummary(nvme *storage.NvmeController, out io.Writer, opts ...PrintConfigOption) error {
w := txtfmt.NewErrWriter(out)
if _, err := fmt.Fprintf(out, "PCI:%s Model:%s FW:%s Socket:%d Capacity:%s\n",
nvme.PciAddr, nvme.Model, nvme.FwRev, nvme.SocketID, humanize.Bytes(nvme.Capacity())); err != nil {
return err
}
return w.Err
}
func getTimestampString(secs uint64) string {
if secs == 0 {
return "N/A"
}
return common.FormatTime(time.Unix(int64(secs), 0))
}
func printNvmeHealth(stat *storage.NvmeHealth, out io.Writer, opts ...PrintConfigOption) error {
w := txtfmt.NewErrWriter(out)
if stat == nil {
fmt.Fprintln(out, "Health Stats Unavailable")
return w.Err
}
fmt.Fprintln(out, "Health Stats:")
iw := txtfmt.NewIndentWriter(out)
if stat.Timestamp > 0 {
fmt.Fprintf(iw, "Timestamp:%s\n", getTimestampString(stat.Timestamp))
}
fmt.Fprintf(iw, "Temperature:%dK(%.02fC)\n", stat.TempK(), stat.TempC())
if stat.TempWarnTime > 0 {
fmt.Fprintf(iw, "Temperature Warning Duration:%s\n",
time.Duration(stat.TempWarnTime)*time.Minute)
}
if stat.TempCritTime > 0 {
fmt.Fprintf(iw, "Temperature Critical Duration:%s\n",
time.Duration(stat.TempCritTime)*time.Minute)
}
fmt.Fprintf(iw, "Controller Busy Time:%s\n", time.Duration(stat.CtrlBusyTime)*time.Minute)
fmt.Fprintf(iw, "Power Cycles:%d\n", uint64(stat.PowerCycles))
fmt.Fprintf(iw, "Power On Duration:%s\n", time.Duration(stat.PowerOnHours)*time.Hour)
fmt.Fprintf(iw, "Unsafe Shutdowns:%d\n", uint64(stat.UnsafeShutdowns))
fmt.Fprintf(iw, "Media Errors:%d\n", uint64(stat.MediaErrors))
if stat.Timestamp > 0 {
fmt.Fprintf(iw, "Read Errors:%d\n", uint64(stat.ReadErrors))
fmt.Fprintf(iw, "Write Errors:%d\n", uint64(stat.WriteErrors))
fmt.Fprintf(iw, "Unmap Errors:%d\n", uint64(stat.UnmapErrors))
fmt.Fprintf(iw, "Checksum Errors:%d\n", uint64(stat.ChecksumErrors))
}
fmt.Fprintf(iw, "Error Log Entries:%d\n", uint64(stat.ErrorLogEntries))
fmt.Fprintf(out, "Critical Warnings:\n")
fmt.Fprintf(iw, "Temperature: ")
if stat.TempWarn {
fmt.Fprintf(iw, "WARNING\n")
} else {
fmt.Fprintf(iw, "OK\n")
}
fmt.Fprintf(iw, "Available Spare: ")
if stat.AvailSpareWarn {
fmt.Fprintf(iw, "WARNING\n")
} else {
fmt.Fprintf(iw, "OK\n")
}
fmt.Fprintf(iw, "Device Reliability: ")
if stat.ReliabilityWarn {
fmt.Fprintf(iw, "WARNING\n")
} else {
fmt.Fprintf(iw, "OK\n")
}
fmt.Fprintf(iw, "Read Only: ")
if stat.ReadOnlyWarn {
fmt.Fprintf(iw, "WARNING\n")
} else {
fmt.Fprintf(iw, "OK\n")
}
fmt.Fprintf(iw, "Volatile Memory Backup: ")
if stat.VolatileWarn {
fmt.Fprintf(iw, "WARNING\n")
} else {
fmt.Fprintf(iw, "OK\n")
}
if stat.ProgFailCntNorm > 0 {
fmt.Fprintf(out, "Intel Vendor SMART Attributes:\n")
fmt.Fprintf(iw, "Program Fail Count:\n")
fmt.Fprintf(iw, " Normalized:%d%%\n",
uint8(stat.ProgFailCntNorm))
fmt.Fprintf(iw, " Raw:%d\n",
uint64(stat.ProgFailCntRaw))
fmt.Fprintf(iw, "Erase Fail Count:\n")
fmt.Fprintf(iw, " Normalized:%d%%\n",
uint8(stat.EraseFailCntNorm))
fmt.Fprintf(iw, " Raw:%d\n",
uint64(stat.EraseFailCntRaw))
fmt.Fprintf(iw, "Wear Leveling Count:\n")
fmt.Fprintf(iw, " Normalized:%d%%\n",
uint8(stat.WearLevelingCntNorm))
fmt.Fprintf(iw, " Min:%d\n",
uint16(stat.WearLevelingCntMin))
fmt.Fprintf(iw, " Max:%d\n",
uint16(stat.WearLevelingCntMax))
fmt.Fprintf(iw, " Avg:%d\n",
uint16(stat.WearLevelingCntAvg))
fmt.Fprintf(iw, "End-to-End Error Detection Count:%d\n",
uint64(stat.EndtoendErrCntRaw))
fmt.Fprintf(iw, "CRC Error Count:%d\n",
uint64(stat.CrcErrCntRaw))
fmt.Fprintf(iw, "Timed Workload, Media Wear:%d\n",
uint64(stat.MediaWearRaw))
fmt.Fprintf(iw, "Timed Workload, Host Read/Write Ratio:%d\n",
uint64(stat.HostReadsRaw))
fmt.Fprintf(iw, "Timed Workload, Timer:%d\n",
uint64(stat.WorkloadTimerRaw))
fmt.Fprintf(iw, "Thermal Throttle Status:%d%%\n",
uint8(stat.ThermalThrottleStatus))
fmt.Fprintf(iw, "Thermal Throttle Event Count:%d\n",
uint64(stat.ThermalThrottleEventCnt))
fmt.Fprintf(iw, "Retry Buffer Overflow Counter:%d\n",
uint64(stat.RetryBufferOverflowCnt))
fmt.Fprintf(iw, "PLL Lock Loss Count:%d\n",
uint64(stat.PllLockLossCnt))
fmt.Fprintf(iw, "NAND Bytes Written:%d\n",
uint64(stat.NandBytesWritten))
fmt.Fprintf(iw, "Host Bytes Written:%d\n",
uint64(stat.HostBytesWritten))
}
return w.Err
}
// Strip NVMe controller format results of skip entries.
func parseNvmeFormatResults(inResults storage.NvmeControllers) storage.NvmeControllers {
parsedResults := make(storage.NvmeControllers, 0, len(inResults))
for _, result := range inResults {
if result.PciAddr != storage.NilBdevAddress {
parsedResults = append(parsedResults, result)
}
}
return parsedResults
}
func printNvmeFormatResults(inCtrlrs storage.NvmeControllers, out io.Writer, opts ...PrintConfigOption) error {
ctrlrs := parseNvmeFormatResults(inCtrlrs)
iw := txtfmt.NewIndentWriter(out)
if len(ctrlrs) == 0 {
fmt.Fprintln(iw, "No NVMe devices were formatted")
return nil
}
pciTitle := "NVMe PCI"
resultTitle := "Format Result"
rolesTitle := "Role(s)"
formatter := txtfmt.NewTableFormatter(pciTitle, resultTitle, rolesTitle)
formatter.InitWriter(out)
var table []txtfmt.TableRow
sort.Slice(ctrlrs, func(i, j int) bool { return ctrlrs[i].PciAddr < ctrlrs[j].PciAddr })
for _, c := range ctrlrs {
row := txtfmt.TableRow{pciTitle: c.PciAddr}
row[resultTitle] = c.Info
roles := "NA"
// Assumes that all SMD devices on a controller have the same roles.
if len(c.SmdDevices) > 0 {
roles = fmt.Sprintf("%s", c.SmdDevices[0].Roles.String())
}
row[rolesTitle] = roles
table = append(table, row)
}
formatter.Format(table)
return nil
}
// PrintNvmeControllers displays controller details in a verbose table.
func PrintNvmeControllers(controllers storage.NvmeControllers, out io.Writer, opts ...PrintConfigOption) error {
w := txtfmt.NewErrWriter(out)
iw := txtfmt.NewIndentWriter(out)
if len(controllers) == 0 {
fmt.Fprintln(iw, "No NVMe devices found")
return w.Err
}
pciTitle := "NVMe PCI"
modelTitle := "Model"
fwTitle := "FW Revision"
socketTitle := "Socket"
capacityTitle := "Capacity"
rolesTitle := "Role(s)"
rankTitle := "Rank"
formatter := txtfmt.NewTableFormatter(
pciTitle, modelTitle, fwTitle, socketTitle, capacityTitle, rolesTitle, rankTitle,
)
formatter.InitWriter(out)
var table []txtfmt.TableRow
sort.Slice(controllers, func(i, j int) bool { return controllers[i].PciAddr < controllers[j].PciAddr })
for _, ctrlr := range controllers {
row := txtfmt.TableRow{pciTitle: ctrlr.PciAddr}
row[modelTitle] = ctrlr.Model
row[fwTitle] = ctrlr.FwRev
row[socketTitle] = fmt.Sprint(ctrlr.SocketID)
row[capacityTitle] = humanize.Bytes(ctrlr.Capacity())
roles := "NA"
rank := "None"
// Assumes that all SMD devices on a controller have the same roles and rank.
if len(ctrlr.SmdDevices) > 0 {
sd := ctrlr.SmdDevices[0]
roles = sd.Roles.String()
if sd.Rank != ranklist.NilRank {
rank = sd.Rank.String()
}
}
row[rolesTitle] = roles
row[rankTitle] = rank
table = append(table, row)
}
formatter.Format(table)
return w.Err
}
// PrintNvmeHealthMap generates a human-readable representation of the supplied
// HostStorageMap, with a focus on presenting the NVMe Device Health information.
func PrintNvmeHealthMap(hsm control.HostStorageMap, out io.Writer, opts ...PrintConfigOption) error {
w := txtfmt.NewErrWriter(out)
for _, key := range hsm.Keys() {
hss := hsm[key]
hosts := getPrintHosts(hss.HostSet.RangedString(), opts...)
lineBreak := strings.Repeat("-", len(hosts))
fmt.Fprintf(out, "%s\n%s\n%s\n", lineBreak, hosts, lineBreak)
if len(hss.HostStorage.NvmeDevices) == 0 {
fmt.Fprintln(out, " No NVMe devices detected")
continue
}
for _, controller := range hss.HostStorage.NvmeDevices {
if err := printNvmeControllerSummary(controller, out, opts...); err != nil {
return err
}
iw := txtfmt.NewIndentWriter(out)
if err := printNvmeHealth(controller.HealthStats, iw, opts...); err != nil {
return err
}
fmt.Fprintln(out)
}
}
return w.Err
}