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.

92 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.Subtype("SeaweedFS"),
  31. fuse.NoAppleDouble(),
  32. fuse.NoAppleXattr(),
  33. fuse.ExclCreate(),
  34. fuse.DaemonTimeout("3600"),
  35. fuse.AllowOther(),
  36. fuse.AllowSUID(),
  37. fuse.DefaultPermissions(),
  38. fuse.MaxReadahead(1024*128),
  39. fuse.AsyncRead(),
  40. fuse.WritebackCache(),
  41. )
  42. if err != nil {
  43. glog.Fatal(err)
  44. return false
  45. }
  46. util.OnInterrupt(func() {
  47. fuse.Unmount(*mountOptions.dir)
  48. c.Close()
  49. })
  50. filerGrpcAddress, err := parseFilerGrpcAddress(*mountOptions.filer, *mountOptions.filerGrpcPort)
  51. if err != nil {
  52. glog.Fatal(err)
  53. return false
  54. }
  55. mountRoot := *mountOptions.filerMountRootPath
  56. if mountRoot != "/" && strings.HasSuffix(mountRoot, "/") {
  57. mountRoot = mountRoot[0 : len(mountRoot)-1]
  58. }
  59. err = fs.Serve(c, filesys.NewSeaweedFileSystem(&filesys.Option{
  60. FilerGrpcAddress: filerGrpcAddress,
  61. FilerMountRootPath: mountRoot,
  62. Collection: *mountOptions.collection,
  63. Replication: *mountOptions.replication,
  64. TtlSec: int32(*mountOptions.ttlSec),
  65. ChunkSizeLimit: int64(*mountOptions.chunkSizeLimitMB) * 1024 * 1024,
  66. DataCenter: *mountOptions.dataCenter,
  67. DirListingLimit: *mountOptions.dirListingLimit,
  68. EntryCacheTtl: 3 * time.Second,
  69. }))
  70. if err != nil {
  71. fuse.Unmount(*mountOptions.dir)
  72. }
  73. // check if the mount process has an error to report
  74. <-c.Ready
  75. if err := c.MountError; err != nil {
  76. glog.Fatal(err)
  77. }
  78. return true
  79. }