/
mount_options.go
247 lines (222 loc) · 6.77 KB
/
mount_options.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
package proto
import (
"flag"
"fmt"
"strconv"
"github.com/chubaofs/chubaofs/util/auth"
"github.com/chubaofs/chubaofs/util/config"
)
// For client
const (
// Mandatory
MountPoint int = iota
VolName
Owner
Master
// Optional
LogDir
WarnLogDir
LogLevel
ProfPort
IcacheTimeout
LookupValid
AttrValid
ReadRate
WriteRate
EnSyncWrite
AutoInvalData
Rdonly
WriteCache
KeepCache
FollowerRead
Authenticate
ClientKey
TicketHost
EnableHTTPS
CertFile
AccessKey
SecretKey
DisableDcache
SubDir
FsyncOnClose
MaxCPUs
EnableXattr
NearRead
EnablePosixACL
EnableSummary
EnableUnixPermission
MaxMountOption
)
// For server
const (
MasterAddr = "masterAddr"
ListenPort = "listen"
ObjectNodeDomain = "objectNodeDomain"
)
type MountOption struct {
keyword string
description string
cmdlineValue string
value interface{}
}
func (opt MountOption) String() string {
return fmt.Sprintf("[%v] %T: %v", opt.keyword, opt.value, opt.value)
}
func NewMountOptions() []MountOption {
opts := make([]MountOption, MaxMountOption)
return opts
}
func InitMountOptions(opts []MountOption) {
opts[MountPoint] = MountOption{"mountPoint", "Mount Point", "", ""}
opts[VolName] = MountOption{"volName", "Volume Name", "", ""}
opts[Owner] = MountOption{"owner", "Owner", "", ""}
opts[Master] = MountOption{MasterAddr, "Master Address", "", ""}
opts[LogDir] = MountOption{"logDir", "Log Path", "", ""}
opts[WarnLogDir] = MountOption{"warnLogDir", "Warn Log Path", "", ""}
opts[LogLevel] = MountOption{"logLevel", "Log Level", "", ""}
opts[ProfPort] = MountOption{"profPort", "PProf Port", "", ""}
opts[IcacheTimeout] = MountOption{"icacheTimeout", "Inode Cache Expiration Time", "", int64(-1)}
opts[LookupValid] = MountOption{"lookupValid", "Lookup Valid Duration", "", int64(-1)}
opts[AttrValid] = MountOption{"attrValid", "Attr Valid Duration", "", int64(-1)}
opts[ReadRate] = MountOption{"readRate", "Read Rate Limit", "", int64(-1)}
opts[WriteRate] = MountOption{"writeRate", "Write Rate Limit", "", int64(-1)}
opts[EnSyncWrite] = MountOption{"enSyncWrite", "Enable Sync Write", "", int64(-1)}
opts[AutoInvalData] = MountOption{"autoInvalData", "Auto Invalidate Data", "", int64(-1)}
opts[Rdonly] = MountOption{"rdonly", "Mount as readonly", "", false}
opts[WriteCache] = MountOption{"writecache", "Enable FUSE writecache feature", "", false}
opts[KeepCache] = MountOption{"keepcache", "Enable FUSE keepcache feature", "", false}
opts[FollowerRead] = MountOption{"followerRead", "Enable read from follower", "", false}
opts[NearRead] = MountOption{"nearRead", "Enable read from nearest node", "", true}
opts[Authenticate] = MountOption{"authenticate", "Enable Authenticate", "", false}
opts[ClientKey] = MountOption{"clientKey", "Client Key", "", ""}
opts[TicketHost] = MountOption{"ticketHost", "Ticket Host", "", ""}
opts[EnableHTTPS] = MountOption{"enableHTTPS", "Enable HTTPS", "", false}
opts[CertFile] = MountOption{"certFile", "Cert File", "", ""}
opts[AccessKey] = MountOption{"accessKey", "Access Key", "", ""}
opts[SecretKey] = MountOption{"secretKey", "Secret Key", "", ""}
opts[DisableDcache] = MountOption{"disableDcache", "Disable Dentry Cache", "", false}
opts[SubDir] = MountOption{"subdir", "Mount sub directory", "", ""}
opts[FsyncOnClose] = MountOption{"fsyncOnClose", "Perform fsync upon file close", "", true}
opts[MaxCPUs] = MountOption{"maxcpus", "The maximum number of CPUs that can be executing", "", int64(-1)}
opts[EnableXattr] = MountOption{"enableXattr", "Enable xattr support", "", false}
opts[EnablePosixACL] = MountOption{"enablePosixACL", "Enable posix ACL support", "", false}
opts[EnableSummary] = MountOption{"enableSummary", "Enable content summary", "", false}
opts[EnableUnixPermission] = MountOption{"enableUnixPermission", "Enable unix permission check(e.g: 777/755)", "", false}
for i := 0; i < MaxMountOption; i++ {
flag.StringVar(&opts[i].cmdlineValue, opts[i].keyword, "", opts[i].description)
}
}
func ParseMountOptions(opts []MountOption, cfg *config.Config) {
for i := 0; i < MaxMountOption; i++ {
switch v := opts[i].value.(type) {
case string:
if opts[i].cmdlineValue != "" {
opts[i].value = opts[i].cmdlineValue
} else {
if value, present := cfg.CheckAndGetString(opts[i].keyword); present {
opts[i].value = value
} else {
opts[i].value = v
}
}
fmt.Println(fmt.Sprintf("keyword[%v] value[%v] type[%T]", opts[i].keyword, opts[i].value, v))
case int64:
if opts[i].cmdlineValue != "" {
opts[i].value = parseInt64(opts[i].cmdlineValue)
} else {
if value, present := cfg.CheckAndGetString(opts[i].keyword); present {
opts[i].value = parseInt64(value)
} else {
opts[i].value = v
}
}
fmt.Println(fmt.Sprintf("keyword[%v] value[%v] type[%T]", opts[i].keyword, opts[i].value, v))
case bool:
if opts[i].cmdlineValue != "" {
opts[i].value = parseBool(opts[i].cmdlineValue)
} else {
if value, present := cfg.CheckAndGetBool(opts[i].keyword); present {
opts[i].value = value
} else {
opts[i].value = v
}
}
fmt.Println(fmt.Sprintf("keyword[%v] value[%v] type[%T]", opts[i].keyword, opts[i].value, v))
default:
fmt.Println(fmt.Sprintf("keyword[%v] unknown type[%T]", opts[i].keyword, v))
}
}
}
func parseInt64(s string) int64 {
var ret int64 = -1
if s != "" {
val, err := strconv.Atoi(s)
if err == nil {
ret = int64(val)
}
}
return ret
}
func parseBool(s string) bool {
var ret bool = false
if s == "true" {
ret = true
}
return ret
}
func (opt *MountOption) GetString() string {
val, ok := opt.value.(string)
if !ok {
return ""
}
return val
}
func (opt *MountOption) GetBool() bool {
val, ok := opt.value.(bool)
if !ok {
return false
}
return val
}
func (opt *MountOption) GetInt64() int64 {
val, ok := opt.value.(int64)
if !ok {
return int64(-1)
}
return val
}
type MountOptions struct {
Config *config.Config
MountPoint string
Volname string
Owner string
Master string
Logpath string
Loglvl string
Profport string
IcacheTimeout int64
LookupValid int64
AttrValid int64
ReadRate int64
WriteRate int64
EnSyncWrite int64
AutoInvalData int64
UmpDatadir string
Rdonly bool
WriteCache bool
KeepCache bool
FollowerRead bool
Authenticate bool
TicketMess auth.TicketMess
AccessKey string
SecretKey string
DisableDcache bool
SubDir string
FsyncOnClose bool
MaxCPUs int64
EnableXattr bool
NearRead bool
EnablePosixACL bool
EnableSummary bool
EnableUnixPermission bool
}