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.

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