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.

74 lines
1.8 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. )
  12. func runMount(cmd *Command, args []string) bool {
  13. fmt.Printf("This is SeaweedFS version %s %s %s\n", util.VERSION, runtime.GOOS, runtime.GOARCH)
  14. if *mountOptions.dir == "" {
  15. fmt.Printf("Please specify the mount directory via \"-dir\"")
  16. return false
  17. }
  18. if *mountOptions.chunkSizeLimitMB <= 0 {
  19. fmt.Printf("Please specify a reasonable buffer size.")
  20. return false
  21. }
  22. fuse.Unmount(*mountOptions.dir)
  23. c, err := fuse.Mount(
  24. *mountOptions.dir,
  25. fuse.VolumeName("SeaweedFS"),
  26. fuse.FSName("SeaweedFS"),
  27. fuse.NoAppleDouble(),
  28. fuse.NoAppleXattr(),
  29. fuse.ExclCreate(),
  30. fuse.DaemonTimeout("3600"),
  31. fuse.AllowOther(),
  32. fuse.AllowSUID(),
  33. fuse.DefaultPermissions(),
  34. // fuse.MaxReadahead(1024*128), // TODO: not tested yet, possibly improving read performance
  35. fuse.AsyncRead(),
  36. fuse.WritebackCache(),
  37. )
  38. if err != nil {
  39. glog.Fatal(err)
  40. return false
  41. }
  42. util.OnInterrupt(func() {
  43. fuse.Unmount(*mountOptions.dir)
  44. c.Close()
  45. })
  46. filerGrpcAddress, err := parseFilerGrpcAddress(*mountOptions.filer, *mountOptions.filerGrpcPort)
  47. if err != nil {
  48. glog.Fatal(err)
  49. return false
  50. }
  51. err = fs.Serve(c, filesys.NewSeaweedFileSystem(
  52. filerGrpcAddress, *mountOptions.filerMountRootPath, *mountOptions.collection, *mountOptions.replication, int32(*mountOptions.ttlSec),
  53. *mountOptions.chunkSizeLimitMB, *mountOptions.dataCenter))
  54. if err != nil {
  55. fuse.Unmount(*mountOptions.dir)
  56. }
  57. // check if the mount process has an error to report
  58. <-c.Ready
  59. if err := c.MountError; err != nil {
  60. glog.Fatal(err)
  61. }
  62. return true
  63. }