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.

117 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/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. }
  33. // detect current user
  34. uid, gid := uint32(0), uint32(0)
  35. if u, err := user.Current(); err == nil {
  36. if parsedId, pe := strconv.ParseUint(u.Uid, 10, 32); pe == nil {
  37. uid = uint32(parsedId)
  38. }
  39. if parsedId, pe := strconv.ParseUint(u.Gid, 10, 32); pe == nil {
  40. gid = uint32(parsedId)
  41. }
  42. }
  43. util.SetupProfiling(*mountCpuProfile, *mountMemProfile)
  44. c, err := fuse.Mount(
  45. *mountOptions.dir,
  46. fuse.VolumeName("SeaweedFS"),
  47. fuse.FSName("SeaweedFS"),
  48. fuse.Subtype("SeaweedFS"),
  49. fuse.NoAppleDouble(),
  50. fuse.NoAppleXattr(),
  51. fuse.NoBrowse(),
  52. fuse.AutoXattr(),
  53. fuse.ExclCreate(),
  54. fuse.DaemonTimeout("3600"),
  55. fuse.AllowOther(),
  56. fuse.AllowSUID(),
  57. fuse.DefaultPermissions(),
  58. fuse.MaxReadahead(1024*128),
  59. fuse.AsyncRead(),
  60. fuse.WritebackCache(),
  61. )
  62. if err != nil {
  63. glog.Fatal(err)
  64. return false
  65. }
  66. util.OnInterrupt(func() {
  67. fuse.Unmount(*mountOptions.dir)
  68. c.Close()
  69. })
  70. filerGrpcAddress, err := parseFilerGrpcAddress(*mountOptions.filer, *mountOptions.filerGrpcPort)
  71. if err != nil {
  72. glog.Fatal(err)
  73. return false
  74. }
  75. mountRoot := *mountOptions.filerMountRootPath
  76. if mountRoot != "/" && strings.HasSuffix(mountRoot, "/") {
  77. mountRoot = mountRoot[0 : len(mountRoot)-1]
  78. }
  79. err = fs.Serve(c, filesys.NewSeaweedFileSystem(&filesys.Option{
  80. FilerGrpcAddress: filerGrpcAddress,
  81. FilerMountRootPath: mountRoot,
  82. Collection: *mountOptions.collection,
  83. Replication: *mountOptions.replication,
  84. TtlSec: int32(*mountOptions.ttlSec),
  85. ChunkSizeLimit: int64(*mountOptions.chunkSizeLimitMB) * 1024 * 1024,
  86. DataCenter: *mountOptions.dataCenter,
  87. DirListingLimit: *mountOptions.dirListingLimit,
  88. EntryCacheTtl: 3 * time.Second,
  89. MountUid: uid,
  90. MountGid: gid,
  91. MountMode: mountMode,
  92. }))
  93. if err != nil {
  94. fuse.Unmount(*mountOptions.dir)
  95. }
  96. // check if the mount process has an error to report
  97. <-c.Ready
  98. if err := c.MountError; err != nil {
  99. glog.Fatal(err)
  100. }
  101. return true
  102. }