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
  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. "strconv"
  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. hostnameAndPort := strings.Split(*mountOptions.filer, ":")
  49. if len(hostnameAndPort) != 2 {
  50. fmt.Printf("The filer should have hostname:port format: %v\n", hostnameAndPort)
  51. return false
  52. }
  53. filerPort, parseErr := strconv.ParseUint(hostnameAndPort[1], 10, 64)
  54. if parseErr != nil {
  55. fmt.Printf("The filer filer port parse error: %v\n", parseErr)
  56. return false
  57. }
  58. filerGrpcPort := filerPort + 10000
  59. if *mountOptions.filerGrpcPort != 0 {
  60. filerGrpcPort = uint64(*copy.filerGrpcPort)
  61. }
  62. filerAddress := fmt.Sprintf("%s:%d", hostnameAndPort[0], filerGrpcPort)
  63. err = fs.Serve(c, filesys.NewSeaweedFileSystem(
  64. filerAddress, *mountOptions.filerMountRootPath, *mountOptions.collection, *mountOptions.replication, int32(*mountOptions.ttlSec),
  65. *mountOptions.chunkSizeLimitMB, *mountOptions.dataCenter))
  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. }