-
Notifications
You must be signed in to change notification settings - Fork 291
/
storage.go
328 lines (283 loc) · 9.63 KB
/
storage.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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
//
// (C) Copyright 2020-2024 Intel Corporation.
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
package pretty
import (
"fmt"
"io"
"strings"
"github.com/dustin/go-humanize"
"github.com/pkg/errors"
"github.com/daos-stack/daos/src/control/lib/control"
"github.com/daos-stack/daos/src/control/lib/txtfmt"
"github.com/daos-stack/daos/src/control/server/storage"
)
// printHostStorageMapVerbose generates a human-readable representation of the supplied
// HostStorageMap struct and writes it to the supplied io.Writer.
func printHostStorageMapVerbose(hsm control.HostStorageMap, out io.Writer, opts ...PrintConfigOption) error {
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)
fmt.Fprintf(out, "HugePage Size: %d KB\n\n",
hss.HostStorage.MemInfo.HugepageSizeKiB)
if len(hss.HostStorage.ScmNamespaces) == 0 {
if err := PrintScmModules(hss.HostStorage.ScmModules, out, opts...); err != nil {
return err
}
} else {
if err := PrintScmNamespaces(hss.HostStorage.ScmNamespaces, out, opts...); err != nil {
return err
}
}
fmt.Fprintln(out)
if err := PrintNvmeControllers(hss.HostStorage.NvmeDevices, out, opts...); err != nil {
return err
}
fmt.Fprintln(out)
}
return nil
}
// PrintHostStorageMap generates a human-readable representation of the supplied
// HostStorageMap struct and writes it to the supplied io.Writer.
func PrintHostStorageMap(hsm control.HostStorageMap, out io.Writer, opts ...PrintConfigOption) error {
if len(hsm) == 0 {
return nil
}
fc := getPrintConfig(opts...)
if fc.Verbose {
return printHostStorageMapVerbose(hsm, out, opts...)
}
hostsTitle := "Hosts"
scmTitle := "SCM Total"
nvmeTitle := "NVMe Total"
tablePrint := txtfmt.NewTableFormatter(hostsTitle, scmTitle, nvmeTitle)
tablePrint.InitWriter(out)
table := []txtfmt.TableRow{}
for _, key := range hsm.Keys() {
hss := hsm[key]
hosts := getPrintHosts(hss.HostSet.RangedString(), opts...)
row := txtfmt.TableRow{hostsTitle: hosts}
if len(hss.HostStorage.ScmNamespaces) == 0 {
row[scmTitle] = hss.HostStorage.ScmModules.Summary()
} else {
row[scmTitle] = hss.HostStorage.ScmNamespaces.Summary()
}
row[nvmeTitle] = hss.HostStorage.NvmeDevices.Summary()
table = append(table, row)
}
tablePrint.Format(table)
return nil
}
// PrintHostStorageUsageMap generates a human-readable representation of the supplied
// HostStorageMap struct and writes utilization info to the supplied io.Writer.
func PrintHostStorageUsageMap(hsm control.HostStorageMap, out io.Writer) error {
if len(hsm) == 0 {
return nil
}
hostsTitle := "Hosts"
scmTitle := "SCM-Total"
scmFreeTitle := "SCM-Free"
scmUsageTitle := "SCM-Used"
nvmeTitle := "NVMe-Total"
nvmeFreeTitle := "NVMe-Free"
nvmeUsageTitle := "NVMe-Used"
tablePrint := txtfmt.NewTableFormatter(hostsTitle, scmTitle, scmFreeTitle,
scmUsageTitle, nvmeTitle, nvmeFreeTitle, nvmeUsageTitle)
tablePrint.InitWriter(out)
table := []txtfmt.TableRow{}
for _, key := range hsm.Keys() {
hss := hsm[key]
hosts := getPrintHosts(hss.HostSet.RangedString())
row := txtfmt.TableRow{hostsTitle: hosts}
storage := hss.HostStorage
row[scmTitle] = humanize.Bytes(storage.ScmNamespaces.Total())
row[scmFreeTitle] = humanize.Bytes(storage.ScmNamespaces.Free())
row[scmUsageTitle] = storage.ScmNamespaces.PercentUsage()
row[nvmeTitle] = humanize.Bytes(storage.NvmeDevices.Total())
row[nvmeFreeTitle] = humanize.Bytes(storage.NvmeDevices.Free())
row[nvmeUsageTitle] = storage.NvmeDevices.PercentUsage()
table = append(table, row)
}
tablePrint.Format(table)
return nil
}
func printStorageFormatMapVerbose(hsm control.HostStorageMap, out io.Writer, opts ...PrintConfigOption) error {
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 err := printScmMountPoints(hss.HostStorage.ScmMountPoints, out, opts...); err != nil {
return err
}
fmt.Fprintln(out)
if err := printNvmeFormatResults(hss.HostStorage.NvmeDevices, out, opts...); err != nil {
return err
}
fmt.Fprintln(out)
}
return nil
}
// PrintStorageFormatMap generates a human-readable representation of the supplied
// HostStorageMap which is populated in response to a StorageFormat operation.
func PrintStorageFormatMap(hsm control.HostStorageMap, out io.Writer, opts ...PrintConfigOption) error {
if len(hsm) == 0 {
return nil
}
fc := getPrintConfig(opts...)
if fc.Verbose {
return printStorageFormatMapVerbose(hsm, out, opts...)
}
hostsTitle := "Hosts"
scmTitle := "SCM Devices"
nvmeTitle := "NVMe Devices"
fmt.Fprintln(out, "Format Summary:")
tablePrint := txtfmt.NewTableFormatter(hostsTitle, scmTitle, nvmeTitle)
tablePrint.InitWriter(txtfmt.NewIndentWriter(out))
table := []txtfmt.TableRow{}
for _, key := range hsm.Keys() {
hss := hsm[key]
hosts := getPrintHosts(hss.HostSet.RangedString(), opts...)
row := txtfmt.TableRow{hostsTitle: hosts}
row[scmTitle] = fmt.Sprintf("%d", len(hss.HostStorage.ScmMountPoints))
row[nvmeTitle] = fmt.Sprintf("%d",
len(parseNvmeFormatResults(hss.HostStorage.NvmeDevices)))
table = append(table, row)
}
tablePrint.Format(table)
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 {
out := trAddr
if dev.CtrlrNamespaceID > 0 {
out = fmt.Sprintf("%s %s", out, nsID)
}
if dev.UUID != "" {
out = fmt.Sprintf("%s [%s]", out, uid)
}
_, err := fmt.Fprintf(iw, "%s %s\n", out, led)
return err
}
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
}
var hasSysXS string
if dev.HasSysXS {
hasSysXS = "SysXS "
}
if _, err := fmt.Fprintf(txtfmt.NewIndentWriter(iw),
"Roles:%s %sTargets:%+v Rank:%d State:%s LED:%s\n", &dev.Roles, hasSysXS,
dev.TargetIDs, dev.Rank, dev.Ctrlr.NvmeState, dev.Ctrlr.LedState); err != nil {
return err
}
return nil
}
func printSmdPool(pool *control.SmdPool, out io.Writer, opts ...PrintConfigOption) error {
ew := txtfmt.NewErrWriter(out)
fmt.Fprintf(ew, "Rank:%d Targets:%+v", pool.Rank, pool.TargetIDs)
cfg := getPrintConfig(opts...)
if cfg.Verbose {
fmt.Fprintf(ew, " Blobs:%+v", pool.Blobs)
}
fmt.Fprintln(ew)
return ew.Err
}
// PrintSmdInfoMap generates a human-readable representation of the supplied
// HostStorageMap, with a focus on presenting the per-server metadata (SMD) information.
func PrintSmdInfoMap(omitDevs, omitPools bool, 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)
iw := txtfmt.NewIndentWriter(out)
if hss.HostStorage.SmdInfo == nil {
fmt.Fprintln(iw, "No SMD info returned")
continue
}
if !omitDevs {
if len(hss.HostStorage.SmdInfo.Devices) > 0 {
fmt.Fprintln(iw, "Devices")
for _, device := range hss.HostStorage.SmdInfo.Devices {
iw1 := txtfmt.NewIndentWriter(iw)
if err := printSmdDevice(device, iw1, opts...); err != nil {
return err
}
if device.Ctrlr.HealthStats == nil {
continue
}
if err := printNvmeHealth(device.Ctrlr.HealthStats,
txtfmt.NewIndentWriter(iw1), opts...); err != nil {
return err
}
fmt.Fprintln(out)
}
} else {
fmt.Fprintln(iw, "No devices found")
}
}
if !omitPools {
if len(hss.HostStorage.SmdInfo.Pools) > 0 {
fmt.Fprintln(iw, "Pools")
for uuid, poolSet := range hss.HostStorage.SmdInfo.Pools {
iw1 := txtfmt.NewIndentWriter(iw)
fmt.Fprintf(iw1, "UUID:%s\n", uuid)
iw2 := txtfmt.NewIndentWriter(iw1)
for _, pool := range poolSet {
if err := printSmdPool(pool, iw2, opts...); err != nil {
return err
}
}
fmt.Fprintln(out)
}
} else {
fmt.Fprintln(iw, "No pools with NVMe found")
}
}
}
return w.Err
}
// PrintSmdManageResp generates a human-readable representation of the supplied response.
func PrintSmdManageResp(op control.SmdManageOpcode, resp *control.SmdResp, out, outErr io.Writer, opts ...PrintConfigOption) error {
switch op {
case control.SetFaultyOp, control.DevReplaceOp:
if resp.ResultCount() > 1 {
return errors.Errorf("smd-manage %s: unexpected number of results, "+
"want %d got %d", op, 1, resp.ResultCount())
}
hem := resp.GetHostErrors()
if len(hem) > 0 {
for errStr, hostSet := range hem {
fmt.Fprintln(outErr, fmt.Sprintf("%s operation failed on %s: %s",
op, hostSet.HostSet, errStr))
}
return nil
}
return PrintHostStorageSuccesses(fmt.Sprintf("%s operation performed", op),
resp.HostStorage, out)
case control.LedCheckOp, control.LedBlinkOp, control.LedResetOp:
if err := PrintResponseErrors(resp, outErr, opts...); err != nil {
return err
}
return PrintSmdInfoMap(false, true, resp.HostStorage, out, opts...)
default:
return errors.Errorf("unsupported opcode %d", op)
}
}