-
Notifications
You must be signed in to change notification settings - Fork 294
/
config.go
139 lines (122 loc) · 4.11 KB
/
config.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
//
// (C) Copyright 2019 Intel Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// GOVERNMENT LICENSE RIGHTS-OPEN SOURCE SOFTWARE
// The Government's rights to use, modify, reproduce, release, perform, display,
// or disclose this software are subject to the terms of the Apache License as
// provided in Contract No. 8F-30005.
// Any reproduction of computer software, computer software documentation, or
// portions thereof marked with this legend must also reproduce the markings.
//
package storage
import "github.com/pkg/errors"
const (
maxScmDeviceLen = 1
)
const (
ScmClassNone ScmClass = ""
ScmClassDCPM ScmClass = "dcpm"
ScmClassRAM ScmClass = "ram"
)
// ScmClass specifies device type for Storage Class Memory
type ScmClass string
// UnmarshalYAML implements yaml.Unmarshaler on ScmClass type
func (s *ScmClass) UnmarshalYAML(unmarshal func(interface{}) error) error {
var class string
if err := unmarshal(&class); err != nil {
return err
}
scmClass := ScmClass(class)
switch scmClass {
case ScmClassDCPM, ScmClassRAM:
*s = scmClass
default:
return errors.Errorf("scm_class value %q not supported in config (dcpm/ram)", scmClass)
}
return nil
}
func (s ScmClass) String() string {
return string(s)
}
// ScmConfig represents a SCM (Storage Class Memory) configuration entry.
type ScmConfig struct {
MountPoint string `yaml:"scm_mount,omitempty" cmdLongFlag:"--storage" cmdShortFlag:"-s"`
Class ScmClass `yaml:"scm_class,omitempty"`
RamdiskSize int `yaml:"scm_size,omitempty"`
DeviceList []string `yaml:"scm_list,omitempty"`
}
func (sc *ScmConfig) Validate() error {
if sc.MountPoint == "" {
return errors.New("no scm_mount set")
}
if sc.Class == "" {
return errors.New("no scm_class set")
}
if len(sc.DeviceList) > maxScmDeviceLen {
return errors.Errorf("scm_list may have at most %d devices", maxScmDeviceLen)
}
return nil
}
const (
BdevClassNone BdevClass = ""
BdevClassNvme BdevClass = "nvme"
BdevClassMalloc BdevClass = "malloc"
BdevClassKdev BdevClass = "kdev"
BdevClassFile BdevClass = "file"
)
// BdevClass specifies block device type for block device storage
type BdevClass string
// UnmarshalYAML implements yaml.Unmarshaler on BdevClass type
func (b *BdevClass) UnmarshalYAML(unmarshal func(interface{}) error) error {
var class string
if err := unmarshal(&class); err != nil {
return err
}
bdevClass := BdevClass(class)
switch bdevClass {
// NB: It seems as if this is a valid default; configs generated by the test
// harness have no bdev entries and are expected to work.
case BdevClassNone:
*b = BdevClassNvme
case BdevClassNvme, BdevClassMalloc, BdevClassKdev, BdevClassFile:
*b = bdevClass
default:
return errors.Errorf("bdev_class value %q not supported in config (nvme/malloc/kdev/file)", bdevClass)
}
return nil
}
func (b BdevClass) String() string {
return string(b)
}
// BdevConfig represents a Block Device (NVMe, etc.) configuration entry.
type BdevConfig struct {
ConfigPath string `yaml:"-" cmdLongFlag:"--nvme" cmdShortFlag:"-n"`
Class BdevClass `yaml:"bdev_class,omitempty"`
DeviceList []string `yaml:"bdev_list,omitempty"`
DeviceCount int `yaml:"bdev_number,omitempty"`
FileSize int `yaml:"bdev_size,omitempty"`
ShmID int `yaml:"-" cmdLongFlag:"--shm_id,nonzero" cmdShortFlag:"-i,nonzero"`
VosEnv string `yaml:"-" cmdEnv:"VOS_BDEV_CLASS"`
Hostname string `yaml:"-"` // used when generating templates
}
func (bc *BdevConfig) Validate() error {
return nil
}
func (bc *BdevConfig) GetNvmeDevs() []string {
if bc.Class == BdevClassNvme {
return bc.DeviceList
}
return []string{}
}