2021-05-26 02:32:35 +00:00
|
|
|
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 15:07:36 +00:00
|
|
|
key, value := parts[0], parts[1]
|
|
|
|
|
2021-05-26 02:32:35 +00:00
|
|
|
// switch key keeping "weed mount" parameters
|
2021-05-26 15:07:36 +00:00
|
|
|
switch key {
|
2021-05-26 02:32:35 +00:00
|
|
|
case "filer":
|
2021-05-26 15:07:36 +00:00
|
|
|
mountOptions.filer = &value
|
2021-05-26 02:32:35 +00:00
|
|
|
case "filer.path":
|
2021-05-26 15:07:36 +00:00
|
|
|
mountOptions.filerMountRootPath = &value
|
2021-05-26 02:32:35 +00:00
|
|
|
case "dirAutoCreate":
|
2021-05-26 15:07:36 +00:00
|
|
|
if parsed, err := strconv.ParseBool(value); err != nil {
|
|
|
|
mountOptions.dirAutoCreate = &parsed
|
2021-05-26 02:32:35 +00:00
|
|
|
} else {
|
|
|
|
panic(fmt.Errorf("dirAutoCreate: %s", err))
|
|
|
|
}
|
|
|
|
case "collection":
|
2021-05-26 15:07:36 +00:00
|
|
|
mountOptions.collection = &value
|
2021-05-26 02:32:35 +00:00
|
|
|
case "replication":
|
2021-05-26 15:07:36 +00:00
|
|
|
mountOptions.replication = &value
|
2021-05-26 02:32:35 +00:00
|
|
|
case "disk":
|
2021-05-26 15:07:36 +00:00
|
|
|
mountOptions.diskType = &value
|
2021-05-26 02:32:35 +00:00
|
|
|
case "ttl":
|
2021-05-26 15:07:36 +00:00
|
|
|
if parsed, err := strconv.ParseInt(value, 0, 32); err != nil {
|
|
|
|
intValue := int(parsed)
|
2021-05-26 02:32:35 +00:00
|
|
|
mountOptions.ttlSec = &intValue
|
|
|
|
} else {
|
|
|
|
panic(fmt.Errorf("ttl: %s", err))
|
|
|
|
}
|
|
|
|
case "chunkSizeLimitMB":
|
2021-05-26 15:07:36 +00:00
|
|
|
if parsed, err := strconv.ParseInt(value, 0, 32); err != nil {
|
|
|
|
intValue := int(parsed)
|
2021-05-26 02:32:35 +00:00
|
|
|
mountOptions.chunkSizeLimitMB = &intValue
|
|
|
|
} else {
|
|
|
|
panic(fmt.Errorf("chunkSizeLimitMB: %s", err))
|
|
|
|
}
|
|
|
|
case "concurrentWriters":
|
2021-05-26 15:07:36 +00:00
|
|
|
if parsed, err := strconv.ParseInt(value, 0, 32); err != nil {
|
|
|
|
intValue := int(parsed)
|
2021-05-26 02:32:35 +00:00
|
|
|
mountOptions.concurrentWriters = &intValue
|
|
|
|
} else {
|
|
|
|
panic(fmt.Errorf("concurrentWriters: %s", err))
|
|
|
|
}
|
|
|
|
case "cacheDir":
|
2021-05-26 15:07:36 +00:00
|
|
|
mountOptions.cacheDir = &value
|
2021-05-26 02:32:35 +00:00
|
|
|
case "cacheCapacityMB":
|
2021-05-26 15:07:36 +00:00
|
|
|
if parsed, err := strconv.ParseInt(value, 0, 64); err != nil {
|
|
|
|
mountOptions.cacheSizeMB = &parsed
|
2021-05-26 02:32:35 +00:00
|
|
|
} else {
|
|
|
|
panic(fmt.Errorf("cacheCapacityMB: %s", err))
|
|
|
|
}
|
|
|
|
case "dataCenter":
|
2021-05-26 15:07:36 +00:00
|
|
|
mountOptions.dataCenter = &value
|
2021-05-26 02:32:35 +00:00
|
|
|
case "allowOthers":
|
2021-05-26 15:07:36 +00:00
|
|
|
if parsed, err := strconv.ParseBool(value); err != nil {
|
|
|
|
mountOptions.allowOthers = &parsed
|
2021-05-26 02:32:35 +00:00
|
|
|
} else {
|
|
|
|
panic(fmt.Errorf("allowOthers: %s", err))
|
|
|
|
}
|
|
|
|
case "umask":
|
2021-05-26 15:07:36 +00:00
|
|
|
mountOptions.umaskString = &value
|
2021-05-26 02:32:35 +00:00
|
|
|
case "nonempty":
|
2021-05-26 15:07:36 +00:00
|
|
|
if parsed, err := strconv.ParseBool(value); err != nil {
|
|
|
|
mountOptions.nonempty = &parsed
|
2021-05-26 02:32:35 +00:00
|
|
|
} else {
|
|
|
|
panic(fmt.Errorf("nonempty: %s", err))
|
|
|
|
}
|
|
|
|
case "volumeServerAccess":
|
2021-05-26 15:07:36 +00:00
|
|
|
mountOptions.volumeServerAccess = &value
|
2021-05-26 02:32:35 +00:00
|
|
|
case "map.uid":
|
2021-05-26 15:07:36 +00:00
|
|
|
mountOptions.uidMap = &value
|
2021-05-26 02:32:35 +00:00
|
|
|
case "map.gid":
|
2021-05-26 15:07:36 +00:00
|
|
|
mountOptions.gidMap = &value
|
2021-05-26 02:32:35 +00:00
|
|
|
case "readOnly":
|
2021-05-26 15:07:36 +00:00
|
|
|
if parsed, err := strconv.ParseBool(value); err != nil {
|
|
|
|
mountOptions.readOnly = &parsed
|
2021-05-26 02:32:35 +00:00
|
|
|
} else {
|
|
|
|
panic(fmt.Errorf("readOnly: %s", err))
|
|
|
|
}
|
|
|
|
case "cpuprofile":
|
2021-05-26 15:07:36 +00:00
|
|
|
mountCpuProfile = &value
|
2021-05-26 02:32:35 +00:00
|
|
|
case "memprofile":
|
2021-05-26 15:07:36 +00:00
|
|
|
mountMemProfile = &value
|
2021-05-26 02:32:35 +00:00
|
|
|
case "readRetryTime":
|
2021-05-26 15:07:36 +00:00
|
|
|
if parsed, err := time.ParseDuration(value); err != nil {
|
|
|
|
mountReadRetryTime = &parsed
|
2021-05-26 02:32:35 +00:00
|
|
|
} 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 15:07:36 +00:00
|
|
|
}
|
2021-05-26 02:32:35 +00:00
|
|
|
|
|
|
|
// just call "weed mount" command
|
|
|
|
return runMount(cmdMount, []string{})
|
|
|
|
}
|
|
|
|
|
|
|
|
var cmdFuse = &Command{
|
2021-05-26 15:07:36 +00:00
|
|
|
UsageLine: "fuse /mnt/mount/point -o \"filer=localhost:8888,filer.path=/\"",
|
2021-05-26 02:32:35 +00:00
|
|
|
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 15:07:36 +00:00
|
|
|
mount -t weed fuse /mnt -o "filer=localhost:8888,filer.path=/"
|
2021-05-26 02:32:35 +00:00
|
|
|
|
|
|
|
Or you can use -t fuse on mount command:
|
|
|
|
mv weed /sbin/weed
|
2021-05-26 15:07:36 +00: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=/"
|
2021-05-26 02:32:35 +00:00
|
|
|
|
|
|
|
To use without mess with your /sbin:
|
2021-05-26 15:07:36 +00: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=/"
|
2021-05-26 02:32:35 +00:00
|
|
|
|
|
|
|
To check valid options look "weed mount --help"
|
|
|
|
`,
|
|
|
|
}
|