/
ctl_storage.go
159 lines (136 loc) · 4.53 KB
/
ctl_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
//
// (C) Copyright 2019-2023 Intel Corporation.
//
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
package server
import (
"path/filepath"
"strings"
"github.com/dustin/go-humanize"
"github.com/pkg/errors"
"github.com/daos-stack/daos/src/control/common"
"github.com/daos-stack/daos/src/control/logging"
"github.com/daos-stack/daos/src/control/server/engine"
"github.com/daos-stack/daos/src/control/server/storage"
)
// StorageControlService encapsulates the storage part of the control service
type StorageControlService struct {
log logging.Logger
storage *storage.Provider
instanceStorage map[uint32]*storage.Config
getMemInfo common.GetMemInfoFn
}
// ScmPrepare preps locally attached modules.
func (scs *StorageControlService) ScmPrepare(req storage.ScmPrepareRequest) (*storage.ScmPrepareResponse, error) {
return scs.storage.PrepareScm(req)
}
// ScmScan scans locally attached modules and namespaces.
func (scs *StorageControlService) ScmScan(req storage.ScmScanRequest) (*storage.ScmScanResponse, error) {
return scs.storage.ScanScm(req)
}
// NvmePrepare preps locally attached SSDs.
func (scs *StorageControlService) NvmePrepare(req storage.BdevPrepareRequest) (*storage.BdevPrepareResponse, error) {
return scs.storage.PrepareBdevs(req)
}
// NvmeScan scans locally attached SSDs.
func (scs *StorageControlService) NvmeScan(req storage.BdevScanRequest) (*storage.BdevScanResponse, error) {
return scs.storage.ScanBdevs(req)
}
// WithVMDEnabled enables VMD support in storage provider.
func (scs *StorageControlService) WithVMDEnabled() *StorageControlService {
scs.storage.WithVMDEnabled(true)
return scs
}
// NewStorageControlService returns an initialized *StorageControlService
func NewStorageControlService(log logging.Logger, ecs []*engine.Config) *StorageControlService {
topCfg := &storage.Config{
Tiers: nil,
}
if len(ecs) > 0 {
topCfg.ControlMetadata = ecs[0].Storage.ControlMetadata
}
instanceStorage := make(map[uint32]*storage.Config)
for i, c := range ecs {
instanceStorage[uint32(i)] = &c.Storage
}
return &StorageControlService{
log: log,
instanceStorage: instanceStorage,
storage: storage.DefaultProvider(log, 0, topCfg),
getMemInfo: common.GetMemInfo,
}
}
func findPMemInScan(ssr *storage.ScmScanResponse, pmemDevs []string) *storage.ScmNamespace {
for _, scanned := range ssr.Namespaces {
for _, path := range pmemDevs {
if strings.TrimSpace(path) == "" {
continue
}
if filepath.Base(path) == scanned.BlockDevice {
return scanned
}
}
}
return nil
}
// getScmUsage will retrieve usage statistics (how much space is available for
// new DAOS pools) for either PMem namespaces or SCM emulation with ramdisk.
//
// Usage is only retrieved for active mountpoints being used by online DAOS I/O
// Server instances.
func (cs *ControlService) getScmUsage(ssr *storage.ScmScanResponse) (*storage.ScmScanResponse, error) {
if ssr == nil {
return nil, errors.New("input scm scan response is nil")
}
instances := cs.harness.Instances()
nss := make(storage.ScmNamespaces, 0, len(instances))
for _, engine := range instances {
if !engine.IsReady() {
continue // skip if not running
}
cfg, err := engine.GetStorage().GetScmConfig()
if err != nil {
return nil, err
}
mount, err := engine.GetStorage().GetScmUsage()
if err != nil {
return nil, err
}
var ns *storage.ScmNamespace
switch mount.Class {
case storage.ClassRam: // generate fake namespace for emulated ramdisk mounts
ns = &storage.ScmNamespace{
Mount: mount,
BlockDevice: "ramdisk",
Size: uint64(humanize.GiByte * cfg.Scm.RamdiskSize),
}
case storage.ClassDcpm: // update namespace mount info for online storage
if ssr.Namespaces == nil {
return nil, errors.Errorf("instance %d: input scm scan response missing namespaces",
engine.Index())
}
ns = findPMemInScan(ssr, mount.DeviceList)
if ns == nil {
return nil, errors.Errorf("instance %d: no pmem namespace for mount %s",
engine.Index(), mount.Path)
}
ns.Mount = mount
}
if ns.Mount != nil {
rank, err := engine.GetRank()
if err != nil {
return nil, errors.Wrapf(err, "instance %d: no rank associated for mount %s",
engine.Index(), mount.Path)
}
ns.Mount.Rank = rank
}
cs.log.Debugf("updated scm fs usage on device %s mounted at %s: %+v", ns.BlockDevice,
mount.Path, ns.Mount)
nss = append(nss, ns)
}
if len(nss) == 0 {
return nil, errors.New("no scm details found")
}
return &storage.ScmScanResponse{Namespaces: nss}, nil
}