aboutsummaryrefslogtreecommitdiff
path: root/weed/command
diff options
context:
space:
mode:
Diffstat (limited to 'weed/command')
-rw-r--r--weed/command/mount_std.go86
-rw-r--r--weed/command/weedfuse/weedfuse.go49
2 files changed, 105 insertions, 30 deletions
diff --git a/weed/command/mount_std.go b/weed/command/mount_std.go
index 33d0332cf..66aa613d5 100644
--- a/weed/command/mount_std.go
+++ b/weed/command/mount_std.go
@@ -4,9 +4,6 @@ package command
import (
"fmt"
- "github.com/chrislusf/seaweedfs/weed/security"
- "github.com/chrislusf/seaweedfs/weed/server"
- "github.com/spf13/viper"
"os"
"os/user"
"path"
@@ -15,6 +12,10 @@ import (
"strings"
"time"
+ "github.com/chrislusf/seaweedfs/weed/security"
+ "github.com/chrislusf/seaweedfs/weed/server"
+ "github.com/spf13/viper"
+
"github.com/chrislusf/seaweedfs/weed/filesys"
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/util"
@@ -24,40 +25,63 @@ import (
func runMount(cmd *Command, args []string) bool {
+ util.SetupProfiling(*mountCpuProfile, *mountMemProfile)
+
+ return RunMount(
+ *mountOptions.filer,
+ *mountOptions.filerMountRootPath,
+ *mountOptions.dir,
+ *mountOptions.collection,
+ *mountOptions.replication,
+ *mountOptions.dataCenter,
+ *mountOptions.chunkSizeLimitMB,
+ *mountOptions.allowOthers,
+ *mountOptions.ttlSec,
+ *mountOptions.dirListingLimit,
+ )
+}
+
+func RunMount(filer, filerMountRootPath, dir, collection, replication, dataCenter string, chunkSizeLimitMB int,
+ allowOthers bool, ttlSec int, dirListingLimit int) bool {
+
weed_server.LoadConfiguration("security", false)
fmt.Printf("This is SeaweedFS version %s %s %s\n", util.VERSION, runtime.GOOS, runtime.GOARCH)
- if *mountOptions.dir == "" {
+ if dir == "" {
fmt.Printf("Please specify the mount directory via \"-dir\"")
return false
}
- if *mountOptions.chunkSizeLimitMB <= 0 {
+ if chunkSizeLimitMB <= 0 {
fmt.Printf("Please specify a reasonable buffer size.")
return false
}
- fuse.Unmount(*mountOptions.dir)
+ fuse.Unmount(dir)
+
+ uid, gid := uint32(0), uint32(0)
// detect mount folder mode
mountMode := os.ModeDir | 0755
- if fileInfo, err := os.Stat(*mountOptions.dir); err == nil {
+ fileInfo, err := os.Stat(dir)
+ if err == nil {
mountMode = os.ModeDir | fileInfo.Mode()
+ uid, gid = util.GetFileUidGid(fileInfo)
+ fmt.Printf("mount point owner uid=%d gid=%d mode=%s\n", uid, gid, fileInfo.Mode())
}
- mountName := path.Base(*mountOptions.dir)
-
- // detect current user
- uid, gid := uint32(0), uint32(0)
- if u, err := user.Current(); err == nil {
- if parsedId, pe := strconv.ParseUint(u.Uid, 10, 32); pe == nil {
- uid = uint32(parsedId)
- }
- if parsedId, pe := strconv.ParseUint(u.Gid, 10, 32); pe == nil {
- gid = uint32(parsedId)
+ if uid == 0 {
+ if u, err := user.Current(); err == nil {
+ if parsedId, pe := strconv.ParseUint(u.Uid, 10, 32); pe == nil {
+ uid = uint32(parsedId)
+ }
+ if parsedId, pe := strconv.ParseUint(u.Gid, 10, 32); pe == nil {
+ gid = uint32(parsedId)
+ }
+ fmt.Printf("current uid=%d gid=%d\n", uid, gid)
}
}
- util.SetupProfiling(*mountCpuProfile, *mountMemProfile)
+ mountName := path.Base(dir)
options := []fuse.MountOption{
fuse.VolumeName(mountName),
@@ -76,28 +100,28 @@ func runMount(cmd *Command, args []string) bool {
fuse.WritebackCache(),
fuse.AllowNonEmptyMount(),
}
- if *mountOptions.allowOthers {
+ if allowOthers {
options = append(options, fuse.AllowOther())
}
- c, err := fuse.Mount(*mountOptions.dir, options...)
+ c, err := fuse.Mount(dir, options...)
if err != nil {
glog.Fatal(err)
return false
}
util.OnInterrupt(func() {
- fuse.Unmount(*mountOptions.dir)
+ fuse.Unmount(dir)
c.Close()
})
- filerGrpcAddress, err := parseFilerGrpcAddress(*mountOptions.filer)
+ filerGrpcAddress, err := parseFilerGrpcAddress(filer)
if err != nil {
glog.Fatal(err)
return false
}
- mountRoot := *mountOptions.filerMountRootPath
+ mountRoot := filerMountRootPath
if mountRoot != "/" && strings.HasSuffix(mountRoot, "/") {
mountRoot = mountRoot[0 : len(mountRoot)-1]
}
@@ -106,19 +130,21 @@ func runMount(cmd *Command, args []string) bool {
FilerGrpcAddress: filerGrpcAddress,
GrpcDialOption: security.LoadClientTLS(viper.Sub("grpc"), "client"),
FilerMountRootPath: mountRoot,
- Collection: *mountOptions.collection,
- Replication: *mountOptions.replication,
- TtlSec: int32(*mountOptions.ttlSec),
- ChunkSizeLimit: int64(*mountOptions.chunkSizeLimitMB) * 1024 * 1024,
- DataCenter: *mountOptions.dataCenter,
- DirListingLimit: *mountOptions.dirListingLimit,
+ Collection: collection,
+ Replication: replication,
+ TtlSec: int32(ttlSec),
+ ChunkSizeLimit: int64(chunkSizeLimitMB) * 1024 * 1024,
+ DataCenter: dataCenter,
+ DirListingLimit: dirListingLimit,
EntryCacheTtl: 3 * time.Second,
MountUid: uid,
MountGid: gid,
MountMode: mountMode,
+ MountCtime: fileInfo.ModTime(),
+ MountMtime: time.Now(),
}))
if err != nil {
- fuse.Unmount(*mountOptions.dir)
+ fuse.Unmount(dir)
}
// check if the mount process has an error to report
diff --git a/weed/command/weedfuse/weedfuse.go b/weed/command/weedfuse/weedfuse.go
new file mode 100644
index 000000000..3b7789eb1
--- /dev/null
+++ b/weed/command/weedfuse/weedfuse.go
@@ -0,0 +1,49 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "os"
+ "strings"
+
+ "github.com/chrislusf/seaweedfs/weed/command"
+)
+
+var (
+ options = flag.String("o", "", "comma separated options rw,uid=xxx,gid=xxx")
+)
+
+func main() {
+
+ flag.Parse()
+
+ device := flag.Arg(0)
+ mountPoint := flag.Arg(1)
+
+ fmt.Printf("source: %v\n", device)
+ fmt.Printf("target: %v\n", mountPoint)
+
+ maybeSetupPath()
+
+ parts := strings.SplitN(device, "/", 2)
+ filer, filerPath := parts[0], parts[1]
+
+ command.RunMount(
+ filer, "/"+filerPath, mountPoint, "", "000", "",
+ 4, true, 0, 1000000)
+
+}
+
+func maybeSetupPath() {
+ // sudo mount -av may not include PATH in some linux, e.g., Ubuntu
+ hasPathEnv := false
+ for _, e := range os.Environ() {
+ if strings.HasPrefix(e, "PATH=") {
+ hasPathEnv = true
+ }
+ fmt.Println(e)
+ }
+ if !hasPathEnv {
+ os.Setenv("PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin")
+ }
+}