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.

118 lines
2.9 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/chrislusf/seaweedfs/weed/filesys"
  12. "github.com/chrislusf/seaweedfs/weed/glog"
  13. "github.com/chrislusf/seaweedfs/weed/util"
  14. "github.com/seaweedfs/fuse"
  15. "github.com/seaweedfs/fuse/fs"
  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.NoBrowse(),
  53. fuse.AutoXattr(),
  54. fuse.ExclCreate(),
  55. fuse.DaemonTimeout("3600"),
  56. fuse.AllowOther(),
  57. fuse.AllowSUID(),
  58. fuse.DefaultPermissions(),
  59. fuse.MaxReadahead(1024*128),
  60. fuse.AsyncRead(),
  61. fuse.WritebackCache(),
  62. )
  63. if err != nil {
  64. glog.Fatal(err)
  65. return false
  66. }
  67. util.OnInterrupt(func() {
  68. fuse.Unmount(*mountOptions.dir)
  69. c.Close()
  70. })
  71. filerGrpcAddress, err := parseFilerGrpcAddress(*mountOptions.filer, *mountOptions.filerGrpcPort)
  72. if err != nil {
  73. glog.Fatal(err)
  74. return false
  75. }
  76. mountRoot := *mountOptions.filerMountRootPath
  77. if mountRoot != "/" && strings.HasSuffix(mountRoot, "/") {
  78. mountRoot = mountRoot[0 : len(mountRoot)-1]
  79. }
  80. err = fs.Serve(c, filesys.NewSeaweedFileSystem(&filesys.Option{
  81. FilerGrpcAddress: filerGrpcAddress,
  82. FilerMountRootPath: mountRoot,
  83. Collection: *mountOptions.collection,
  84. Replication: *mountOptions.replication,
  85. TtlSec: int32(*mountOptions.ttlSec),
  86. ChunkSizeLimit: int64(*mountOptions.chunkSizeLimitMB) * 1024 * 1024,
  87. DataCenter: *mountOptions.dataCenter,
  88. DirListingLimit: *mountOptions.dirListingLimit,
  89. EntryCacheTtl: 3 * time.Second,
  90. MountUid: uid,
  91. MountGid: gid,
  92. MountMode: mountMode,
  93. }))
  94. if err != nil {
  95. fuse.Unmount(*mountOptions.dir)
  96. }
  97. // check if the mount process has an error to report
  98. <-c.Ready
  99. if err := c.MountError; err != nil {
  100. glog.Fatal(err)
  101. }
  102. return true
  103. }