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.

87 lines
2.1 KiB

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