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.

79 lines
2.9 KiB

7 years ago
  1. package command
  2. import (
  3. "fmt"
  4. "strconv"
  5. "strings"
  6. )
  7. type MountOptions struct {
  8. filer *string
  9. filerGrpcPort *int
  10. filerMountRootPath *string
  11. dir *string
  12. dirListingLimit *int
  13. collection *string
  14. replication *string
  15. ttlSec *int
  16. chunkSizeLimitMB *int
  17. dataCenter *string
  18. }
  19. var (
  20. mountOptions MountOptions
  21. mountCpuProfile *string
  22. mountMemProfile *string
  23. )
  24. func init() {
  25. cmdMount.Run = runMount // break init cycle
  26. mountOptions.filer = cmdMount.Flag.String("filer", "localhost:8888", "weed filer location")
  27. mountOptions.filerGrpcPort = cmdMount.Flag.Int("filer.grpc.port", 0, "filer grpc server listen port, default to http port + 10000")
  28. mountOptions.filerMountRootPath = cmdMount.Flag.String("filer.path", "/", "mount this remote path from filer server")
  29. mountOptions.dir = cmdMount.Flag.String("dir", ".", "mount weed filer to this directory")
  30. mountOptions.dirListingLimit = cmdMount.Flag.Int("dirListLimit", 100000, "limit directory listing size")
  31. mountOptions.collection = cmdMount.Flag.String("collection", "", "collection to create the files")
  32. mountOptions.replication = cmdMount.Flag.String("replication", "", "replication(e.g. 000, 001) to create to files. If empty, let filer decide.")
  33. mountOptions.ttlSec = cmdMount.Flag.Int("ttl", 0, "file ttl in seconds")
  34. mountOptions.chunkSizeLimitMB = cmdMount.Flag.Int("chunkSizeLimitMB", 4, "local write buffer size, also chunk large files")
  35. mountOptions.dataCenter = cmdMount.Flag.String("dataCenter", "", "prefer to write to the data center")
  36. mountCpuProfile = cmdMount.Flag.String("cpuprofile", "", "cpu profile output file")
  37. mountMemProfile = cmdMount.Flag.String("memprofile", "", "memory profile output file")
  38. }
  39. var cmdMount = &Command{
  40. UsageLine: "mount -filer=localhost:8888 -dir=/some/dir",
  41. Short: "mount weed filer to a directory as file system in userspace(FUSE)",
  42. Long: `mount weed filer to userspace.
  43. Pre-requisites:
  44. 1) have SeaweedFS master and volume servers running
  45. 2) have a "weed filer" running
  46. These 2 requirements can be achieved with one command "weed server -filer=true"
  47. This uses github.com/seaweedfs/fuse, which enables writing FUSE file systems on
  48. Linux, and OS X.
  49. On OS X, it requires OSXFUSE (http://osxfuse.github.com/).
  50. `,
  51. }
  52. func parseFilerGrpcAddress(filer string, optionalGrpcPort int) (filerGrpcAddress string, err error) {
  53. hostnameAndPort := strings.Split(filer, ":")
  54. if len(hostnameAndPort) != 2 {
  55. return "", fmt.Errorf("The filer should have hostname:port format: %v", hostnameAndPort)
  56. }
  57. filerPort, parseErr := strconv.ParseUint(hostnameAndPort[1], 10, 64)
  58. if parseErr != nil {
  59. return "", fmt.Errorf("The filer filer port parse error: %v", parseErr)
  60. }
  61. filerGrpcPort := int(filerPort) + 10000
  62. if optionalGrpcPort != 0 {
  63. filerGrpcPort = optionalGrpcPort
  64. }
  65. return fmt.Sprintf("%s:%d", hostnameAndPort[0], filerGrpcPort), nil
  66. }