You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
2.8 KiB

7 years ago
6 years ago
6 years ago
7 years ago
  1. // +build linux darwin
  2. package command
  3. import (
  4. "fmt"
  5. "os"
  6. "os/user"
  7. "runtime"
  8. "strconv"
  9. "strings"
  10. "time"
  11. "github.com/seaweedfs/fuse"
  12. "github.com/seaweedfs/fuse/fs"
  13. "github.com/chrislusf/seaweedfs/weed/filesys"
  14. "github.com/chrislusf/seaweedfs/weed/glog"
  15. "github.com/chrislusf/seaweedfs/weed/util"
  16. )
  17. func runMount(cmd *Command, args []string) bool {
  18. fmt.Printf("This is SeaweedFS version %s %s %s\n", util.VERSION, runtime.GOOS, runtime.GOARCH)
  19. if *mountOptions.dir == "" {
  20. fmt.Printf("Please specify the mount directory via \"-dir\"")
  21. return false
  22. }
  23. if *mountOptions.chunkSizeLimitMB <= 0 {
  24. fmt.Printf("Please specify a reasonable buffer size.")
  25. return false
  26. }
  27. fuse.Unmount(*mountOptions.dir)
  28. // detect mount folder mode
  29. mountMode := os.ModeDir | 0755
  30. if fileInfo, err := os.Stat(*mountOptions.dir); err == nil {
  31. mountMode = os.ModeDir | fileInfo.Mode()
  32. println(*mountOptions.dir, "mount mode", mountMode)
  33. }
  34. // detect current user
  35. uid, gid := uint32(0), uint32(0)
  36. if u, err := user.Current(); err == nil {
  37. if parsedId, pe := strconv.ParseUint(u.Uid, 10, 32); pe == nil {
  38. uid = uint32(parsedId)
  39. }
  40. if parsedId, pe := strconv.ParseUint(u.Gid, 10, 32); pe == nil {
  41. gid = uint32(parsedId)
  42. }
  43. }
  44. util.SetupProfiling(*mountCpuProfile, *mountMemProfile)
  45. c, err := fuse.Mount(
  46. *mountOptions.dir,
  47. fuse.VolumeName("SeaweedFS"),
  48. fuse.FSName("SeaweedFS"),
  49. fuse.Subtype("SeaweedFS"),
  50. fuse.NoAppleDouble(),
  51. fuse.NoAppleXattr(),
  52. fuse.ExclCreate(),
  53. fuse.DaemonTimeout("3600"),
  54. fuse.AllowOther(),
  55. fuse.AllowSUID(),
  56. fuse.DefaultPermissions(),
  57. fuse.MaxReadahead(1024*128),
  58. fuse.AsyncRead(),
  59. fuse.WritebackCache(),
  60. )
  61. if err != nil {
  62. glog.Fatal(err)
  63. return false
  64. }
  65. util.OnInterrupt(func() {
  66. fuse.Unmount(*mountOptions.dir)
  67. c.Close()
  68. })
  69. filerGrpcAddress, err := parseFilerGrpcAddress(*mountOptions.filer, *mountOptions.filerGrpcPort)
  70. if err != nil {
  71. glog.Fatal(err)
  72. return false
  73. }
  74. mountRoot := *mountOptions.filerMountRootPath
  75. if mountRoot != "/" && strings.HasSuffix(mountRoot, "/") {
  76. mountRoot = mountRoot[0 : len(mountRoot)-1]
  77. }
  78. err = fs.Serve(c, filesys.NewSeaweedFileSystem(&filesys.Option{
  79. FilerGrpcAddress: filerGrpcAddress,
  80. FilerMountRootPath: mountRoot,
  81. Collection: *mountOptions.collection,
  82. Replication: *mountOptions.replication,
  83. TtlSec: int32(*mountOptions.ttlSec),
  84. ChunkSizeLimit: int64(*mountOptions.chunkSizeLimitMB) * 1024 * 1024,
  85. DataCenter: *mountOptions.dataCenter,
  86. DirListingLimit: *mountOptions.dirListingLimit,
  87. EntryCacheTtl: 3 * time.Second,
  88. MountUid: uid,
  89. MountGid: gid,
  90. MountMode: mountMode,
  91. }))
  92. if err != nil {
  93. fuse.Unmount(*mountOptions.dir)
  94. }
  95. // check if the mount process has an error to report
  96. <-c.Ready
  97. if err := c.MountError; err != nil {
  98. glog.Fatal(err)
  99. }
  100. return true
  101. }