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.

91 lines
2.2 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. "runtime"
  6. "strings"
  7. "time"
  8. "bazil.org/fuse"
  9. "bazil.org/fuse/fs"
  10. "github.com/chrislusf/seaweedfs/weed/filesys"
  11. "github.com/chrislusf/seaweedfs/weed/glog"
  12. "github.com/chrislusf/seaweedfs/weed/util"
  13. )
  14. func runMount(cmd *Command, args []string) bool {
  15. fmt.Printf("This is SeaweedFS version %s %s %s\n", util.VERSION, runtime.GOOS, runtime.GOARCH)
  16. if *mountOptions.dir == "" {
  17. fmt.Printf("Please specify the mount directory via \"-dir\"")
  18. return false
  19. }
  20. if *mountOptions.chunkSizeLimitMB <= 0 {
  21. fmt.Printf("Please specify a reasonable buffer size.")
  22. return false
  23. }
  24. fuse.Unmount(*mountOptions.dir)
  25. util.SetupProfiling(*mountCpuProfile, *mountMemProfile)
  26. c, err := fuse.Mount(
  27. *mountOptions.dir,
  28. fuse.VolumeName("SeaweedFS"),
  29. fuse.FSName("SeaweedFS"),
  30. fuse.NoAppleDouble(),
  31. fuse.NoAppleXattr(),
  32. fuse.ExclCreate(),
  33. fuse.DaemonTimeout("3600"),
  34. fuse.AllowOther(),
  35. fuse.AllowSUID(),
  36. fuse.DefaultPermissions(),
  37. fuse.MaxReadahead(1024*128),
  38. fuse.AsyncRead(),
  39. fuse.WritebackCache(),
  40. )
  41. if err != nil {
  42. glog.Fatal(err)
  43. return false
  44. }
  45. util.OnInterrupt(func() {
  46. fuse.Unmount(*mountOptions.dir)
  47. c.Close()
  48. })
  49. filerGrpcAddress, err := parseFilerGrpcAddress(*mountOptions.filer, *mountOptions.filerGrpcPort)
  50. if err != nil {
  51. glog.Fatal(err)
  52. return false
  53. }
  54. mountRoot := *mountOptions.filerMountRootPath
  55. if mountRoot != "/" && strings.HasSuffix(mountRoot, "/") {
  56. mountRoot = mountRoot[0 : len(mountRoot)-1]
  57. }
  58. err = fs.Serve(c, filesys.NewSeaweedFileSystem(&filesys.Option{
  59. FilerGrpcAddress: filerGrpcAddress,
  60. FilerMountRootPath: mountRoot,
  61. Collection: *mountOptions.collection,
  62. Replication: *mountOptions.replication,
  63. TtlSec: int32(*mountOptions.ttlSec),
  64. ChunkSizeLimit: int64(*mountOptions.chunkSizeLimitMB) * 1024 * 1024,
  65. DataCenter: *mountOptions.dataCenter,
  66. DirListingLimit: *mountOptions.dirListingLimit,
  67. EntryCacheTtl: 3 * time.Second,
  68. }))
  69. if err != nil {
  70. fuse.Unmount(*mountOptions.dir)
  71. }
  72. // check if the mount process has an error to report
  73. <-c.Ready
  74. if err := c.MountError; err != nil {
  75. glog.Fatal(err)
  76. }
  77. return true
  78. }