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.

73 lines
2.5 KiB

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