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.

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