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.

75 lines
2.7 KiB

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