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.

95 lines
2.4 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. "strconv"
  12. "strings"
  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. err = fs.Serve(c, filesys.NewSeaweedFileSystem(
  54. filerGrpcAddress, *mountOptions.filerMountRootPath, *mountOptions.collection, *mountOptions.replication, int32(*mountOptions.ttlSec),
  55. *mountOptions.chunkSizeLimitMB, *mountOptions.dataCenter))
  56. if err != nil {
  57. fuse.Unmount(*mountOptions.dir)
  58. }
  59. // check if the mount process has an error to report
  60. <-c.Ready
  61. if err := c.MountError; err != nil {
  62. glog.Fatal(err)
  63. }
  64. return true
  65. }
  66. func parseFilerGrpcAddress(filer string, optionalGrpcPort int) (filerGrpcAddress string, err error) {
  67. hostnameAndPort := strings.Split(filer, ":")
  68. if len(hostnameAndPort) != 2 {
  69. return "", fmt.Errorf("The filer should have hostname:port format: %v", hostnameAndPort)
  70. }
  71. filerPort, parseErr := strconv.ParseUint(hostnameAndPort[1], 10, 64)
  72. if parseErr != nil {
  73. return "", fmt.Errorf("The filer filer port parse error: %v", parseErr)
  74. }
  75. filerGrpcPort := int(filerPort) + 10000
  76. if optionalGrpcPort != 0 {
  77. filerGrpcPort = optionalGrpcPort
  78. }
  79. return fmt.Sprintf("%s:%d", hostnameAndPort[0], filerGrpcPort), nil
  80. }