/
server_meta.go
401 lines (347 loc) · 10.6 KB
/
server_meta.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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
//
// (C) Copyright 2020-2024 Intel Corporation.
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
package control
import (
"context"
"fmt"
"strings"
"github.com/pkg/errors"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"
"github.com/daos-stack/daos/src/control/common/proto/convert"
ctlpb "github.com/daos-stack/daos/src/control/common/proto/ctl"
"github.com/daos-stack/daos/src/control/lib/daos"
"github.com/daos-stack/daos/src/control/lib/ranklist"
"github.com/daos-stack/daos/src/control/server/storage"
)
// SmdManageOpcode defines an SmdManage operation.
type SmdManageOpcode uint8
// SmdManageOpcode definitions
const (
_ SmdManageOpcode = iota
SetFaultyOp
DevReplaceOp
LedCheckOp
LedBlinkOp
LedResetOp
)
func (smo SmdManageOpcode) String() string {
return map[SmdManageOpcode]string{
SetFaultyOp: "set-faulty",
DevReplaceOp: "dev-replace",
LedCheckOp: "led-check",
LedBlinkOp: "led-blink",
LedResetOp: "led-reset",
}[smo]
}
type (
// SmdPool contains the per-server components of a DAOS pool.
SmdPool struct {
UUID string `json:"uuid"`
TargetIDs []int32 `hash:"set" json:"tgt_ids"`
Blobs []uint64 `hash:"set" json:"blobs"`
Rank ranklist.Rank `hash:"set" json:"rank"`
}
// SmdPoolMap provides a map from pool UUIDs to per-rank pool info.
SmdPoolMap map[string][]*SmdPool
// SmdInfo encapsulates SMD-specific information.
SmdInfo struct {
Devices []*storage.SmdDevice `hash:"set" json:"devices"`
Pools SmdPoolMap `json:"pools"`
}
// SmdQueryReq contains the request parameters for a SMD query operation.
SmdQueryReq struct {
unaryRequest
OmitDevices bool `json:"omit_devices"`
OmitPools bool `json:"omit_pools"`
IncludeBioHealth bool `json:"include_bio_health"`
UUID string `json:"uuid"`
Rank ranklist.Rank `json:"rank"`
FaultyDevsOnly bool `json:"-"` // only show faulty devices
}
// SmdManageReq contains the request parameters for a SMD query operation.
SmdManageReq struct {
unaryRequest
IDs string // comma separated list of IDs
Rank ranklist.Rank
ReplaceUUID string // For device replacement, UUID of new device
ReplaceNoReint bool // For device replacement, indicate no reintegration
IdentifyTimeout uint32 // For LED identify, blink duration in minutes
Operation SmdManageOpcode
}
// SmdResp represents the results of performing SMD query or manage operations across
// a set of hosts.
SmdResp struct {
HostErrorsResp
HostStorage HostStorageMap `json:"host_storage_map"`
}
)
func (si *SmdInfo) addRankPools(rank ranklist.Rank, pools []*SmdPool) {
for _, pool := range pools {
if _, found := si.Pools[pool.UUID]; !found {
si.Pools[pool.UUID] = make([]*SmdPool, 0, 1)
}
pool.Rank = rank
si.Pools[pool.UUID] = append(si.Pools[pool.UUID], pool)
}
}
func (si *SmdInfo) String() string {
return fmt.Sprintf("[Devices: %v, Pools: %v]", si.Devices, si.Pools)
}
func (sr *SmdResp) addHostQueryResponse(hr *HostResponse, faultyOnly bool) error {
pbResp, ok := hr.Message.(*ctlpb.SmdQueryResp)
if !ok {
return errors.Errorf("unable to unpack message: %+v", hr.Message)
}
hs := &HostStorage{
SmdInfo: &SmdInfo{
Pools: make(SmdPoolMap),
},
}
for _, rResp := range pbResp.GetRanks() {
rank := ranklist.Rank(rResp.Rank)
for _, pbDev := range rResp.GetDevices() {
isEvicted := pbDev.Ctrlr.DevState == ctlpb.NvmeDevState_EVICTED
if faultyOnly && !isEvicted {
continue
}
sd := new(storage.SmdDevice)
if err := convert.Types(pbDev, sd); err != nil {
return errors.Wrapf(err, "converting %T to %T", pbDev, sd)
}
sd.Rank = rank
hs.SmdInfo.Devices = append(hs.SmdInfo.Devices, sd)
}
rPools := make([]*SmdPool, len(rResp.GetPools()))
if err := convert.Types(rResp.GetPools(), &rPools); err != nil {
return errors.Wrapf(err, "converting %T to %T", rResp.Pools, &rPools)
}
hs.SmdInfo.addRankPools(rank, rPools)
}
if sr.HostStorage == nil {
sr.HostStorage = make(HostStorageMap)
}
if err := sr.HostStorage.Add(hr.Addr, hs); err != nil {
return err
}
return nil
}
func (sr *SmdResp) ResultCount() int {
if sr == nil {
return 0
}
nrErrs := sr.HostErrorsResp.GetHostErrors().ErrorCount()
nrHS := sr.HostStorage.HostCount()
return nrErrs + nrHS
}
// SmdQuery concurrently performs per-server metadata operations across all
// hosts supplied in the request's hostlist, or all configured hosts if not
// explicitly specified. The function blocks until all results (successful
// or otherwise) are received, and returns a single response structure
// containing results for all SMD operations.
func SmdQuery(ctx context.Context, rpcClient UnaryInvoker, req *SmdQueryReq) (*SmdResp, error) {
rpcClient.Debugf("SmdQuery() called with request %+v", req)
if req == nil {
return nil, errors.New("nil request")
}
if req.UUID != "" {
if err := checkUUID(req.UUID); err != nil {
return nil, errors.Wrap(err, "invalid UUID")
}
}
pbReq := new(ctlpb.SmdQueryReq)
if err := convert.Types(req, pbReq); err != nil {
return nil, errors.Wrap(err, "unable to convert request to protobuf")
}
req.setRPC(func(ctx context.Context, conn *grpc.ClientConn) (proto.Message, error) {
return ctlpb.NewCtlSvcClient(conn).SmdQuery(ctx, pbReq)
})
ur, err := rpcClient.InvokeUnaryRPC(ctx, req)
if err != nil {
return nil, err
}
sr := new(SmdResp)
for _, hostResp := range ur.Responses {
if hostResp.Error != nil {
if err := sr.addHostError(hostResp.Addr, hostResp.Error); err != nil {
return nil, err
}
continue
}
if err := sr.addHostQueryResponse(hostResp, req.FaultyDevsOnly); err != nil {
return nil, err
}
}
return sr, nil
}
func (sr *SmdResp) addHostManageResponse(hr *HostResponse) error {
pbResp, ok := hr.Message.(*ctlpb.SmdManageResp)
if !ok {
return errors.Errorf("unable to unpack message: %+v", hr.Message)
}
var sds []*storage.SmdDevice
for _, rResp := range pbResp.GetRanks() {
rank := ranklist.Rank(rResp.Rank)
for _, pbResult := range rResp.GetResults() {
if pbResult.Device == nil {
continue
}
sd := new(storage.SmdDevice)
if err := convert.Types(pbResult.Device, sd); err != nil {
return errors.Wrapf(err, "converting %T to %T", pbResult.Device, sd)
}
sd.Rank = rank
sds = append(sds, sd)
}
}
hs := &HostStorage{}
if len(sds) != 0 {
hs.SmdInfo = &SmdInfo{Devices: sds}
}
if sr.HostStorage == nil {
sr.HostStorage = make(HostStorageMap)
}
if err := sr.HostStorage.Add(hr.Addr, hs); err != nil {
return err
}
return nil
}
func (sr *SmdResp) getHostManageRespErr(hr *HostResponse) error {
pbResp, ok := hr.Message.(*ctlpb.SmdManageResp)
if !ok {
return errors.Errorf("unable to unpack message: %+v", hr.Message)
}
var errMsgs []string
for _, rResp := range pbResp.GetRanks() {
for _, pbResult := range rResp.GetResults() {
if pbResult.Status == 0 {
continue
}
var id string
if pbResult.Device != nil {
id = pbResult.Device.Uuid
if id == "" {
id = pbResult.Device.Ctrlr.PciAddr
}
id += " "
}
errMsgs = append(errMsgs, fmt.Sprintf("rank %d: %s%s", rResp.Rank, id,
daos.Status(pbResult.Status)))
}
}
if len(errMsgs) > 0 {
return errors.New(strings.Join(errMsgs, ", "))
}
return nil
}
// Pack SmdManage proto request oneof field.
func packPBSmdManageReq(req *SmdManageReq, pbReq *ctlpb.SmdManageReq) error {
switch req.Operation {
case SetFaultyOp:
// Expect single UUID in request IDs field.
if err := checkUUID(req.IDs); err != nil {
return errors.Wrap(err, "bad device UUID to set-faulty")
}
pbReq.Op = &ctlpb.SmdManageReq_Faulty{
Faulty: &ctlpb.SetFaultyReq{
Uuid: req.IDs,
},
}
case DevReplaceOp:
// Expect single UUID in request IDs field.
if err := checkUUID(req.IDs); err != nil {
return errors.Wrap(err, "bad old device UUID for replacement")
}
if err := checkUUID(req.ReplaceUUID); err != nil {
return errors.Wrap(err, "bad new device UUID for replacement")
}
pbReq.Op = &ctlpb.SmdManageReq_Replace{
Replace: &ctlpb.DevReplaceReq{
OldDevUuid: req.IDs,
NewDevUuid: req.ReplaceUUID,
NoReint: req.ReplaceNoReint,
},
}
case LedCheckOp:
pbReq.Op = &ctlpb.SmdManageReq_Led{
Led: &ctlpb.LedManageReq{
Ids: req.IDs,
LedState: ctlpb.LedState_NA,
LedAction: ctlpb.LedAction_GET,
},
}
case LedBlinkOp:
pbReq.Op = &ctlpb.SmdManageReq_Led{
Led: &ctlpb.LedManageReq{
Ids: req.IDs,
LedState: ctlpb.LedState_QUICK_BLINK,
LedAction: ctlpb.LedAction_SET,
LedDurationMins: req.IdentifyTimeout,
},
}
case LedResetOp:
pbReq.Op = &ctlpb.SmdManageReq_Led{
Led: &ctlpb.LedManageReq{
Ids: req.IDs,
LedState: ctlpb.LedState_NA,
LedAction: ctlpb.LedAction_RESET,
},
}
default:
return errors.New("smd manage called but unrecognized operation requested")
}
return nil
}
// SmdManage concurrently performs per-server metadata operations across all
// hosts supplied in the request's hostlist, or all configured hosts if not
// explicitly specified. The function blocks until all results (successful
// or otherwise) are received, and returns a single response structure
// containing results for all SMD operations.
func SmdManage(ctx context.Context, rpcClient UnaryInvoker, req *SmdManageReq) (*SmdResp, error) {
rpcClient.Debugf("SmdManage() called with request %+v", req)
if req == nil {
return nil, errors.New("nil request")
}
pbReq := new(ctlpb.SmdManageReq)
if err := packPBSmdManageReq(req, pbReq); err != nil {
return nil, errors.Wrap(err, "packing proto manage request")
}
req.setRPC(func(ctx context.Context, conn *grpc.ClientConn) (proto.Message, error) {
return ctlpb.NewCtlSvcClient(conn).SmdManage(ctx, pbReq)
})
if req.Operation == SetFaultyOp || req.Operation == DevReplaceOp {
reqHosts, err := getRequestHosts(DefaultConfig(), req)
if err != nil {
return nil, err
}
if len(reqHosts) > 1 {
return nil, errors.Errorf("cannot perform %s operation on > 1 host",
req.Operation)
}
}
ur, err := rpcClient.InvokeUnaryRPC(ctx, req)
if err != nil {
return nil, err
}
sr := new(SmdResp)
for _, hostResp := range ur.Responses {
if hostResp.Error != nil {
if err := sr.addHostError(hostResp.Addr, hostResp.Error); err != nil {
return nil, err
}
continue
}
if respError := sr.getHostManageRespErr(hostResp); respError != nil {
if err := sr.addHostError(hostResp.Addr, respError); err != nil {
return nil, err
}
}
if err := sr.addHostManageResponse(hostResp); err != nil {
return nil, err
}
}
return sr, nil
}