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.

89 lines
2.2 KiB

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