cubefs

Форк
0
/
mount_options.go 
330 строк · 10.4 Кб
1
package proto
2

3
import (
4
	"flag"
5
	"fmt"
6
	"strconv"
7

8
	"github.com/cubefs/cubefs/util/auth"
9
	"github.com/cubefs/cubefs/util/config"
10
)
11

12
// For client
13
const (
14
	// Mandatory
15
	MountPoint int = iota
16
	VolName
17
	Owner
18
	Master
19
	// Optional
20
	LogDir
21
	WarnLogDir
22
	LogLevel
23
	ProfPort
24
	IcacheTimeout
25
	LookupValid
26
	AttrValid
27
	ReadRate
28
	WriteRate
29
	EnSyncWrite
30
	AutoInvalData
31
	Rdonly
32
	WriteCache
33
	KeepCache
34
	FollowerRead
35
	Authenticate
36
	ClientKey
37
	TicketHost
38
	EnableHTTPS
39
	CertFile
40
	AccessKey
41
	SecretKey
42
	DisableDcache
43
	SubDir
44
	FsyncOnClose
45
	MaxCPUs
46
	EnableXattr
47
	NearRead
48
	EnablePosixACL
49
	EnableSummary
50
	EnableUnixPermission
51
	RequestTimeout
52

53
	// adls
54
	VolType
55
	EbsEndpoint
56
	EbsServerPath
57
	CacheAction
58
	EbsBlockSize
59
	EnableBcache
60
	BcacheDir
61
	BcacheFilterFiles
62
	BcacheBatchCnt
63
	BcacheCheckIntervalS
64
	ReadThreads
65
	WriteThreads
66
	MetaSendTimeout
67
	BuffersTotalLimit
68
	MaxStreamerLimit
69
	EnableAudit
70

71
	LocallyProf
72
	MinWriteAbleDataPartitionCnt
73
	FileSystemName
74

75
	// snapshot
76
	SnapshotReadVerSeq
77

78
	MaxMountOption
79
)
80

81
// For server
82
const (
83
	MasterAddr       = "masterAddr"
84
	ListenPort       = "listen"
85
	ObjectNodeDomain = "objectNodeDomain"
86
	BindIpKey        = "bindIp"
87
)
88

89
type MountOption struct {
90
	keyword      string
91
	description  string
92
	cmdlineValue string
93
	value        interface{}
94
}
95

96
func (opt MountOption) String() string {
97
	return fmt.Sprintf("[%v] %T: %v", opt.keyword, opt.value, opt.value)
98
}
99

100
func NewMountOptions() []MountOption {
101
	opts := make([]MountOption, MaxMountOption)
102
	return opts
103
}
104

105
func InitMountOptions(opts []MountOption) {
106
	opts[MountPoint] = MountOption{"mountPoint", "Mount Point", "", ""}
107
	opts[VolName] = MountOption{"volName", "Volume Name", "", ""}
108
	opts[Owner] = MountOption{"owner", "Owner", "", ""}
109
	opts[Master] = MountOption{MasterAddr, "Master Address", "", ""}
110
	opts[LogDir] = MountOption{"logDir", "Log Path", "", ""}
111
	opts[WarnLogDir] = MountOption{"warnLogDir", "Warn Log Path", "", ""}
112
	opts[LogLevel] = MountOption{"logLevel", "Log Level", "", ""}
113
	opts[ProfPort] = MountOption{"profPort", "PProf Port", "", ""}
114
	opts[LocallyProf] = MountOption{"locallyProf", "Locally PProf", "", false}
115
	opts[IcacheTimeout] = MountOption{"icacheTimeout", "Inode Cache Expiration Time", "", int64(-1)}
116
	opts[LookupValid] = MountOption{"lookupValid", "Lookup Valid Duration", "", int64(-1)}
117
	opts[AttrValid] = MountOption{"attrValid", "Attr Valid Duration", "", int64(-1)}
118
	opts[ReadRate] = MountOption{"readRate", "Read Rate Limit", "", int64(-1)}
119
	opts[WriteRate] = MountOption{"writeRate", "Write Rate Limit", "", int64(-1)}
120
	opts[EnSyncWrite] = MountOption{"enSyncWrite", "Enable Sync Write", "", int64(-1)}
121
	opts[AutoInvalData] = MountOption{"autoInvalData", "Auto Invalidate Data", "", int64(-1)}
122
	opts[Rdonly] = MountOption{"rdonly", "Mount as readonly", "", false}
123
	opts[WriteCache] = MountOption{"writecache", "Enable FUSE writecache feature", "", false}
124
	opts[KeepCache] = MountOption{"keepcache", "Enable FUSE keepcache feature", "", false}
125
	opts[FollowerRead] = MountOption{"followerRead", "Enable read from follower", "", false}
126
	opts[NearRead] = MountOption{"nearRead", "Enable read from nearest node", "", true}
127

128
	opts[Authenticate] = MountOption{"authenticate", "Enable Authenticate", "", false}
129
	opts[ClientKey] = MountOption{"clientKey", "Client Key", "", ""}
130
	opts[TicketHost] = MountOption{"ticketHost", "Ticket Host", "", ""}
131
	opts[EnableHTTPS] = MountOption{"enableHTTPS", "Enable HTTPS", "", false}
132
	opts[CertFile] = MountOption{"certFile", "Cert File", "", ""}
133

134
	opts[AccessKey] = MountOption{"accessKey", "Access Key", "", ""}
135
	opts[SecretKey] = MountOption{"secretKey", "Secret Key", "", ""}
136

137
	opts[DisableDcache] = MountOption{"disableDcache", "Disable Dentry Cache", "", false}
138
	opts[SubDir] = MountOption{"subdir", "Mount sub directory", "", ""}
139
	opts[FsyncOnClose] = MountOption{"fsyncOnClose", "Perform fsync upon file close", "", true}
140
	opts[MaxCPUs] = MountOption{"maxcpus", "The maximum number of CPUs that can be executing", "", int64(-1)}
141
	opts[EnableXattr] = MountOption{"enableXattr", "Enable xattr support", "", false}
142
	opts[EnablePosixACL] = MountOption{"enablePosixACL", "Enable posix ACL support", "", false}
143
	opts[EnableSummary] = MountOption{"enableSummary", "Enable content summary", "", false}
144
	opts[EnableUnixPermission] = MountOption{"enableUnixPermission", "Enable unix permission check(e.g: 777/755)", "", false}
145

146
	opts[VolType] = MountOption{"volType", "volume type", "", int64(0)}
147
	opts[EbsEndpoint] = MountOption{"ebsEndpoint", "Ebs service address", "", ""}
148
	opts[EbsServerPath] = MountOption{"ebsServerPath", "Ebs service path", "", ""}
149
	opts[CacheAction] = MountOption{"cacheAction", "Cold cache action", "", int64(0)}
150
	opts[EbsBlockSize] = MountOption{"ebsBlockSize", "Ebs object size", "", ""}
151
	// opts[EnableBcache] = MountOption{"enableBcache", "Enable block cache", "", false}
152
	opts[BcacheDir] = MountOption{"bcacheDir", "block cache dir", "", ""}
153
	opts[ReadThreads] = MountOption{"readThreads", "Cold volume read threads", "", int64(10)}
154
	opts[WriteThreads] = MountOption{"writeThreads", "Cold volume write threads", "", int64(10)}
155
	opts[MetaSendTimeout] = MountOption{"metaSendTimeout", "Meta send timeout", "", int64(600)}
156
	opts[BuffersTotalLimit] = MountOption{"buffersTotalLimit", "Send/Receive packets memory limit", "", int64(32768)} // default 4G
157
	opts[MaxStreamerLimit] = MountOption{"maxStreamerLimit", "The maximum number of streamers", "", int64(0)}         // default 0
158
	opts[BcacheFilterFiles] = MountOption{"bcacheFilterFiles", "The block cache filter files suffix", "", "py;pyx;sh;yaml;conf;pt;pth;log;out"}
159
	opts[BcacheBatchCnt] = MountOption{"bcacheBatchCnt", "The block cache get meta count", "", int64(100000)}
160
	opts[BcacheCheckIntervalS] = MountOption{"bcacheCheckIntervalS", "The block cache check interval", "", int64(300)}
161
	opts[EnableAudit] = MountOption{"enableAudit", "enable client audit logging", "", false}
162
	opts[RequestTimeout] = MountOption{"requestTimeout", "The Request Expiration Time", "", int64(0)}
163
	opts[MinWriteAbleDataPartitionCnt] = MountOption{
164
		"minWriteAbleDataPartitionCnt",
165
		"Min writeable data partition count retained int dpSelector when update DataPartitionsView from master",
166
		"", int64(10),
167
	}
168

169
	opts[FileSystemName] = MountOption{"fileSystemName", "The explicit name of the filesystem", "", ""}
170
	opts[SnapshotReadVerSeq] = MountOption{"snapshotReadSeq", "Snapshot read seq", "", int64(0)} // default false
171

172
	for i := 0; i < MaxMountOption; i++ {
173
		flag.StringVar(&opts[i].cmdlineValue, opts[i].keyword, "", opts[i].description)
174
	}
175
}
176

177
func ParseMountOptions(opts []MountOption, cfg *config.Config) {
178
	for i := 0; i < MaxMountOption; i++ {
179
		switch v := opts[i].value.(type) {
180
		case string:
181
			if opts[i].cmdlineValue != "" {
182
				opts[i].value = opts[i].cmdlineValue
183
			} else {
184
				if value, present := cfg.CheckAndGetString(opts[i].keyword); present {
185
					opts[i].value = value
186
				} else {
187
					opts[i].value = v
188
				}
189
			}
190
			fmt.Printf("keyword[%v] value[%v] type[%T]\n", opts[i].keyword, opts[i].value, v)
191

192
		case int64:
193
			if opts[i].cmdlineValue != "" {
194
				opts[i].value = parseInt64(opts[i].cmdlineValue)
195
			} else {
196
				if present := cfg.HasKey(opts[i].keyword); present {
197
					opts[i].value = cfg.GetInt64(opts[i].keyword)
198
				} else {
199
					opts[i].value = v
200
				}
201
			}
202
			fmt.Printf("keyword[%v] value[%v] type[%T]\n", opts[i].keyword, opts[i].value, v)
203

204
		case bool:
205
			if opts[i].cmdlineValue != "" {
206
				opts[i].value = parseBool(opts[i].cmdlineValue)
207
			} else {
208
				if value, present := cfg.CheckAndGetBool(opts[i].keyword); present {
209
					opts[i].value = value
210
				} else {
211
					opts[i].value = v
212
				}
213
			}
214
			fmt.Printf("keyword[%v] value[%v] type[%T]\n", opts[i].keyword, opts[i].value, v)
215

216
		default:
217
			fmt.Printf("keyword[%v] unknown type[%T]\n", opts[i].keyword, v)
218
		}
219
	}
220
}
221

222
func parseInt64(s string) int64 {
223
	var ret int64 = -1
224

225
	if s != "" {
226
		val, err := strconv.Atoi(s)
227
		if err == nil {
228
			ret = int64(val)
229
		}
230
	}
231
	return ret
232
}
233

234
func parseBool(s string) bool {
235
	var ret bool = false
236

237
	if s == "true" {
238
		ret = true
239
	}
240
	return ret
241
}
242

243
func (opt *MountOption) GetString() string {
244
	val, ok := opt.value.(string)
245
	if !ok {
246
		return ""
247
	}
248
	return val
249
}
250

251
func (opt *MountOption) GetBool() bool {
252
	val, ok := opt.value.(bool)
253
	if !ok {
254
		return false
255
	}
256
	return val
257
}
258

259
func (opt *MountOption) GetInt64() int64 {
260
	val, ok := opt.value.(int64)
261
	if !ok {
262
		return int64(-1)
263
	}
264
	return val
265
}
266

267
type MountOptions struct {
268
	Config                       *config.Config
269
	MountPoint                   string
270
	Volname                      string
271
	Owner                        string
272
	Master                       string
273
	Logpath                      string
274
	Loglvl                       string
275
	Profport                     string
276
	LocallyProf                  bool
277
	IcacheTimeout                int64
278
	LookupValid                  int64
279
	AttrValid                    int64
280
	ReadRate                     int64
281
	WriteRate                    int64
282
	EnSyncWrite                  int64
283
	AutoInvalData                int64
284
	UmpDatadir                   string
285
	Rdonly                       bool
286
	WriteCache                   bool
287
	KeepCache                    bool
288
	FollowerRead                 bool
289
	Authenticate                 bool
290
	TicketMess                   auth.TicketMess
291
	TokenKey                     string
292
	AccessKey                    string
293
	SecretKey                    string
294
	DisableDcache                bool
295
	SubDir                       string
296
	FsyncOnClose                 bool
297
	MaxCPUs                      int64
298
	EnableXattr                  bool
299
	NearRead                     bool
300
	EnablePosixACL               bool
301
	EnableQuota                  bool
302
	EnableTransaction            string
303
	TxTimeout                    int64
304
	TxConflictRetryNum           int64
305
	TxConflictRetryInterval      int64
306
	VolType                      int
307
	EbsEndpoint                  string
308
	EbsServicePath               string
309
	CacheAction                  int
310
	CacheThreshold               int
311
	EbsBlockSize                 int
312
	EnableBcache                 bool
313
	BcacheDir                    string
314
	BcacheFilterFiles            string
315
	BcacheCheckIntervalS         int64
316
	BcacheBatchCnt               int64
317
	ReadThreads                  int64
318
	WriteThreads                 int64
319
	EnableSummary                bool
320
	EnableUnixPermission         bool
321
	NeedRestoreFuse              bool
322
	MetaSendTimeout              int64
323
	BuffersTotalLimit            int64
324
	MaxStreamerLimit             int64
325
	EnableAudit                  bool
326
	RequestTimeout               int64
327
	MinWriteAbleDataPartitionCnt int
328
	FileSystemName               string
329
	VerReadSeq                   uint64
330
}
331

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.