mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-11-29 05:49:03 +08:00
Merge pull request #2099 from danielflira/mount-helper
fix parameter multiple values
This commit is contained in:
commit
ae185b997f
@ -12,120 +12,174 @@ func init() {
|
|||||||
cmdFuse.Run = runFuse // break init cycle
|
cmdFuse.Run = runFuse // break init cycle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type parameter struct {
|
||||||
|
name string
|
||||||
|
value string
|
||||||
|
}
|
||||||
|
|
||||||
func runFuse(cmd *Command, args []string) bool {
|
func runFuse(cmd *Command, args []string) bool {
|
||||||
argsLen := len(args)
|
rawArgs := strings.Join(args, " ")
|
||||||
options := []string{}
|
rawArgsLen := len(rawArgs)
|
||||||
|
option := strings.Builder{}
|
||||||
|
options := []parameter{}
|
||||||
|
|
||||||
// at least target mount path should be passed
|
// first parameter
|
||||||
if argsLen < 1 {
|
i := 0
|
||||||
return false
|
for i = 0; i < rawArgsLen && rawArgs[i] != ' '; i++ {
|
||||||
|
option.WriteByte(rawArgs[i])
|
||||||
|
}
|
||||||
|
options = append(options, parameter{"arg0", option.String()})
|
||||||
|
option.Reset()
|
||||||
|
|
||||||
|
for i++; i < rawArgsLen; i++ {
|
||||||
|
|
||||||
|
// space separator check for filled option
|
||||||
|
if rawArgs[i] == ' ' {
|
||||||
|
if option.Len() > 0 {
|
||||||
|
options = append(options, parameter{option.String(), "true"})
|
||||||
|
option.Reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
// first option is always target mount path
|
// dash separator read option until next space
|
||||||
mountOptions.dir = &args[0]
|
} else if rawArgs[i] == '-' {
|
||||||
|
for i++; i < rawArgsLen && rawArgs[i] != ' '; i++ {
|
||||||
|
option.WriteByte(rawArgs[i])
|
||||||
|
}
|
||||||
|
options = append(options, parameter{option.String(), "true"})
|
||||||
|
option.Reset()
|
||||||
|
|
||||||
// scan parameters looking for one or more -o options
|
// equal separator start option with pending value
|
||||||
// -o options receive parameters on format key=value[,key=value]...
|
} else if rawArgs[i] == '=' {
|
||||||
for i := 0; i < argsLen; i++ {
|
name := option.String()
|
||||||
if args[i] == "-o" && i+1 <= argsLen {
|
option.Reset()
|
||||||
options = strings.Split(args[i+1], ",")
|
|
||||||
i++
|
for i++; i < rawArgsLen && rawArgs[i] != ','; i++ {
|
||||||
|
// double quote separator read option until next double quote
|
||||||
|
if rawArgs[i] == '"' {
|
||||||
|
for i++; i < rawArgsLen && rawArgs[i] != '"'; i++ {
|
||||||
|
option.WriteByte(rawArgs[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
// single quote separator read option until next single quote
|
||||||
|
} else if rawArgs[i] == '\'' {
|
||||||
|
for i++; i < rawArgsLen && rawArgs[i] != '\''; i++ {
|
||||||
|
option.WriteByte(rawArgs[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
// add chars before comma
|
||||||
|
} else if rawArgs[i] != ' ' {
|
||||||
|
option.WriteByte(rawArgs[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for each option passed with -o
|
options = append(options, parameter{name, option.String()})
|
||||||
for _, option := range options {
|
option.Reset()
|
||||||
// split just first = character
|
|
||||||
parts := strings.SplitN(option, "=", 2)
|
|
||||||
|
|
||||||
// if doesn't key and value skip
|
// comma separator just read current option
|
||||||
if len(parts) != 2 {
|
} else if rawArgs[i] == ',' {
|
||||||
continue
|
options = append(options, parameter{option.String(), "true"})
|
||||||
|
option.Reset()
|
||||||
|
|
||||||
|
// what is not a separator fill option buffer
|
||||||
|
} else {
|
||||||
|
option.WriteByte(rawArgs[i])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
key, value := parts[0], parts[1]
|
// get residual option data
|
||||||
|
if option.Len() > 0 {
|
||||||
|
// add value to pending option
|
||||||
|
options = append(options, parameter{option.String(), "true"})
|
||||||
|
option.Reset()
|
||||||
|
}
|
||||||
|
|
||||||
// switch key keeping "weed mount" parameters
|
// scan each parameter
|
||||||
switch key {
|
for i := 0; i < len(options); i++ {
|
||||||
|
parameter := options[i]
|
||||||
|
|
||||||
|
switch parameter.name {
|
||||||
|
case "arg0":
|
||||||
|
mountOptions.dir = ¶meter.value
|
||||||
case "filer":
|
case "filer":
|
||||||
mountOptions.filer = &value
|
mountOptions.filer = ¶meter.value
|
||||||
case "filer.path":
|
case "filer.path":
|
||||||
mountOptions.filerMountRootPath = &value
|
mountOptions.filerMountRootPath = ¶meter.value
|
||||||
case "dirAutoCreate":
|
case "dirAutoCreate":
|
||||||
if parsed, err := strconv.ParseBool(value); err != nil {
|
if parsed, err := strconv.ParseBool(parameter.value); err != nil {
|
||||||
mountOptions.dirAutoCreate = &parsed
|
mountOptions.dirAutoCreate = &parsed
|
||||||
} else {
|
} else {
|
||||||
panic(fmt.Errorf("dirAutoCreate: %s", err))
|
panic(fmt.Errorf("dirAutoCreate: %s", err))
|
||||||
}
|
}
|
||||||
case "collection":
|
case "collection":
|
||||||
mountOptions.collection = &value
|
mountOptions.collection = ¶meter.value
|
||||||
case "replication":
|
case "replication":
|
||||||
mountOptions.replication = &value
|
mountOptions.replication = ¶meter.value
|
||||||
case "disk":
|
case "disk":
|
||||||
mountOptions.diskType = &value
|
mountOptions.diskType = ¶meter.value
|
||||||
case "ttl":
|
case "ttl":
|
||||||
if parsed, err := strconv.ParseInt(value, 0, 32); err != nil {
|
if parsed, err := strconv.ParseInt(parameter.value, 0, 32); err != nil {
|
||||||
intValue := int(parsed)
|
intValue := int(parsed)
|
||||||
mountOptions.ttlSec = &intValue
|
mountOptions.ttlSec = &intValue
|
||||||
} else {
|
} else {
|
||||||
panic(fmt.Errorf("ttl: %s", err))
|
panic(fmt.Errorf("ttl: %s", err))
|
||||||
}
|
}
|
||||||
case "chunkSizeLimitMB":
|
case "chunkSizeLimitMB":
|
||||||
if parsed, err := strconv.ParseInt(value, 0, 32); err != nil {
|
if parsed, err := strconv.ParseInt(parameter.value, 0, 32); err != nil {
|
||||||
intValue := int(parsed)
|
intValue := int(parsed)
|
||||||
mountOptions.chunkSizeLimitMB = &intValue
|
mountOptions.chunkSizeLimitMB = &intValue
|
||||||
} else {
|
} else {
|
||||||
panic(fmt.Errorf("chunkSizeLimitMB: %s", err))
|
panic(fmt.Errorf("chunkSizeLimitMB: %s", err))
|
||||||
}
|
}
|
||||||
case "concurrentWriters":
|
case "concurrentWriters":
|
||||||
if parsed, err := strconv.ParseInt(value, 0, 32); err != nil {
|
i++
|
||||||
|
if parsed, err := strconv.ParseInt(parameter.value, 0, 32); err != nil {
|
||||||
intValue := int(parsed)
|
intValue := int(parsed)
|
||||||
mountOptions.concurrentWriters = &intValue
|
mountOptions.concurrentWriters = &intValue
|
||||||
} else {
|
} else {
|
||||||
panic(fmt.Errorf("concurrentWriters: %s", err))
|
panic(fmt.Errorf("concurrentWriters: %s", err))
|
||||||
}
|
}
|
||||||
case "cacheDir":
|
case "cacheDir":
|
||||||
mountOptions.cacheDir = &value
|
mountOptions.cacheDir = ¶meter.value
|
||||||
case "cacheCapacityMB":
|
case "cacheCapacityMB":
|
||||||
if parsed, err := strconv.ParseInt(value, 0, 64); err != nil {
|
if parsed, err := strconv.ParseInt(parameter.value, 0, 64); err != nil {
|
||||||
mountOptions.cacheSizeMB = &parsed
|
mountOptions.cacheSizeMB = &parsed
|
||||||
} else {
|
} else {
|
||||||
panic(fmt.Errorf("cacheCapacityMB: %s", err))
|
panic(fmt.Errorf("cacheCapacityMB: %s", err))
|
||||||
}
|
}
|
||||||
case "dataCenter":
|
case "dataCenter":
|
||||||
mountOptions.dataCenter = &value
|
mountOptions.dataCenter = ¶meter.value
|
||||||
case "allowOthers":
|
case "allowOthers":
|
||||||
if parsed, err := strconv.ParseBool(value); err != nil {
|
if parsed, err := strconv.ParseBool(parameter.value); err != nil {
|
||||||
mountOptions.allowOthers = &parsed
|
mountOptions.allowOthers = &parsed
|
||||||
} else {
|
} else {
|
||||||
panic(fmt.Errorf("allowOthers: %s", err))
|
panic(fmt.Errorf("allowOthers: %s", err))
|
||||||
}
|
}
|
||||||
case "umask":
|
case "umask":
|
||||||
mountOptions.umaskString = &value
|
mountOptions.umaskString = ¶meter.value
|
||||||
case "nonempty":
|
case "nonempty":
|
||||||
if parsed, err := strconv.ParseBool(value); err != nil {
|
if parsed, err := strconv.ParseBool(parameter.value); err != nil {
|
||||||
mountOptions.nonempty = &parsed
|
mountOptions.nonempty = &parsed
|
||||||
} else {
|
} else {
|
||||||
panic(fmt.Errorf("nonempty: %s", err))
|
panic(fmt.Errorf("nonempty: %s", err))
|
||||||
}
|
}
|
||||||
case "volumeServerAccess":
|
case "volumeServerAccess":
|
||||||
mountOptions.volumeServerAccess = &value
|
mountOptions.volumeServerAccess = ¶meter.value
|
||||||
case "map.uid":
|
case "map.uid":
|
||||||
mountOptions.uidMap = &value
|
mountOptions.uidMap = ¶meter.value
|
||||||
case "map.gid":
|
case "map.gid":
|
||||||
mountOptions.gidMap = &value
|
mountOptions.gidMap = ¶meter.value
|
||||||
case "readOnly":
|
case "readOnly":
|
||||||
if parsed, err := strconv.ParseBool(value); err != nil {
|
if parsed, err := strconv.ParseBool(parameter.value); err != nil {
|
||||||
mountOptions.readOnly = &parsed
|
mountOptions.readOnly = &parsed
|
||||||
} else {
|
} else {
|
||||||
panic(fmt.Errorf("readOnly: %s", err))
|
panic(fmt.Errorf("readOnly: %s", err))
|
||||||
}
|
}
|
||||||
case "cpuprofile":
|
case "cpuprofile":
|
||||||
mountCpuProfile = &value
|
mountCpuProfile = ¶meter.value
|
||||||
case "memprofile":
|
case "memprofile":
|
||||||
mountMemProfile = &value
|
mountMemProfile = ¶meter.value
|
||||||
case "readRetryTime":
|
case "readRetryTime":
|
||||||
if parsed, err := time.ParseDuration(value); err != nil {
|
if parsed, err := time.ParseDuration(parameter.value); err != nil {
|
||||||
mountReadRetryTime = &parsed
|
mountReadRetryTime = &parsed
|
||||||
} else {
|
} else {
|
||||||
panic(fmt.Errorf("readRetryTime: %s", err))
|
panic(fmt.Errorf("readRetryTime: %s", err))
|
||||||
@ -160,6 +214,9 @@ var cmdFuse = &Command{
|
|||||||
mount -t fuse./home/user/bin/weed fuse /mnt -o "filer=localhost:8888,filer.path=/"
|
mount -t fuse./home/user/bin/weed fuse /mnt -o "filer=localhost:8888,filer.path=/"
|
||||||
mount -t fuse "/home/user/bin/weed#fuse" /mnt -o "filer=localhost:8888,filer.path=/"
|
mount -t fuse "/home/user/bin/weed#fuse" /mnt -o "filer=localhost:8888,filer.path=/"
|
||||||
|
|
||||||
|
To pass more than one parameter use quotes, example:
|
||||||
|
mount -t weed fuse /mnt -o "filer='192.168.0.1:8888,192.168.0.2:8888',filer.path=/"
|
||||||
|
|
||||||
To check valid options look "weed mount --help"
|
To check valid options look "weed mount --help"
|
||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user