seaweedfs/weed/command/fuse.go

166 lines
4.5 KiB
Go
Raw Normal View History

package command
import (
"fmt"
"strings"
"strconv"
"time"
"os"
)
func init() {
cmdFuse.Run = runFuse // break init cycle
}
func runFuse(cmd *Command, args []string) bool {
argsLen := len(args)
options := []string{}
// at least target mount path should be passed
if argsLen < 1 {
return false
}
// first option is always target mount path
mountOptions.dir = &args[0]
// scan parameters looking for one or more -o options
// -o options receive parameters on format key=value[,key=value]...
for i := 0; i < argsLen; i++ {
if args[i] == "-o" && i+1 <= argsLen {
options = strings.Split(args[i+1], ",")
i++
}
}
// for each option passed with -o
for _, option := range options {
// split just first = character
parts := strings.SplitN(option, "=", 2)
// if doesn't key and value skip
if len(parts) != 2 {
continue
}
2021-05-26 23:07:36 +08:00
key, value := parts[0], parts[1]
// switch key keeping "weed mount" parameters
2021-05-26 23:07:36 +08:00
switch key {
case "filer":
2021-05-26 23:07:36 +08:00
mountOptions.filer = &value
case "filer.path":
2021-05-26 23:07:36 +08:00
mountOptions.filerMountRootPath = &value
case "dirAutoCreate":
2021-05-26 23:07:36 +08:00
if parsed, err := strconv.ParseBool(value); err != nil {
mountOptions.dirAutoCreate = &parsed
} else {
panic(fmt.Errorf("dirAutoCreate: %s", err))
}
case "collection":
2021-05-26 23:07:36 +08:00
mountOptions.collection = &value
case "replication":
2021-05-26 23:07:36 +08:00
mountOptions.replication = &value
case "disk":
2021-05-26 23:07:36 +08:00
mountOptions.diskType = &value
case "ttl":
2021-05-26 23:07:36 +08:00
if parsed, err := strconv.ParseInt(value, 0, 32); err != nil {
intValue := int(parsed)
mountOptions.ttlSec = &intValue
} else {
panic(fmt.Errorf("ttl: %s", err))
}
case "chunkSizeLimitMB":
2021-05-26 23:07:36 +08:00
if parsed, err := strconv.ParseInt(value, 0, 32); err != nil {
intValue := int(parsed)
mountOptions.chunkSizeLimitMB = &intValue
} else {
panic(fmt.Errorf("chunkSizeLimitMB: %s", err))
}
case "concurrentWriters":
2021-05-26 23:07:36 +08:00
if parsed, err := strconv.ParseInt(value, 0, 32); err != nil {
intValue := int(parsed)
mountOptions.concurrentWriters = &intValue
} else {
panic(fmt.Errorf("concurrentWriters: %s", err))
}
case "cacheDir":
2021-05-26 23:07:36 +08:00
mountOptions.cacheDir = &value
case "cacheCapacityMB":
2021-05-26 23:07:36 +08:00
if parsed, err := strconv.ParseInt(value, 0, 64); err != nil {
mountOptions.cacheSizeMB = &parsed
} else {
panic(fmt.Errorf("cacheCapacityMB: %s", err))
}
case "dataCenter":
2021-05-26 23:07:36 +08:00
mountOptions.dataCenter = &value
case "allowOthers":
2021-05-26 23:07:36 +08:00
if parsed, err := strconv.ParseBool(value); err != nil {
mountOptions.allowOthers = &parsed
} else {
panic(fmt.Errorf("allowOthers: %s", err))
}
case "umask":
2021-05-26 23:07:36 +08:00
mountOptions.umaskString = &value
case "nonempty":
2021-05-26 23:07:36 +08:00
if parsed, err := strconv.ParseBool(value); err != nil {
mountOptions.nonempty = &parsed
} else {
panic(fmt.Errorf("nonempty: %s", err))
}
case "volumeServerAccess":
2021-05-26 23:07:36 +08:00
mountOptions.volumeServerAccess = &value
case "map.uid":
2021-05-26 23:07:36 +08:00
mountOptions.uidMap = &value
case "map.gid":
2021-05-26 23:07:36 +08:00
mountOptions.gidMap = &value
case "readOnly":
2021-05-26 23:07:36 +08:00
if parsed, err := strconv.ParseBool(value); err != nil {
mountOptions.readOnly = &parsed
} else {
panic(fmt.Errorf("readOnly: %s", err))
}
case "cpuprofile":
2021-05-26 23:07:36 +08:00
mountCpuProfile = &value
case "memprofile":
2021-05-26 23:07:36 +08:00
mountMemProfile = &value
case "readRetryTime":
2021-05-26 23:07:36 +08:00
if parsed, err := time.ParseDuration(value); err != nil {
mountReadRetryTime = &parsed
} else {
panic(fmt.Errorf("readRetryTime: %s", err))
}
}
}
// I don't know why PATH environment variable is lost
if err := os.Setenv("PATH", "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"); err != nil {
panic(fmt.Errorf("setenv: %s", err))
2021-05-26 23:07:36 +08:00
}
// just call "weed mount" command
return runMount(cmdMount, []string{})
}
var cmdFuse = &Command{
2021-05-26 23:07:36 +08:00
UsageLine: "fuse /mnt/mount/point -o \"filer=localhost:8888,filer.path=/\"",
Short: "Allow use weed with linux's mount command",
Long: `Allow use weed with linux's mount command
You can use -t weed on mount command:
mv weed /sbin/mount.weed
2021-05-26 23:07:36 +08:00
mount -t weed fuse /mnt -o "filer=localhost:8888,filer.path=/"
Or you can use -t fuse on mount command:
mv weed /sbin/weed
2021-05-26 23:07:36 +08:00
mount -t fuse.weed fuse /mnt -o "filer=localhost:8888,filer.path=/"
mount -t fuse "weed#fuse" /mnt -o "filer=localhost:8888,filer.path=/"
To use without mess with your /sbin:
2021-05-26 23:07:36 +08:00
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 check valid options look "weed mount --help"
`,
}