mount.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package command
  2. import (
  3. "fmt"
  4. "strconv"
  5. "strings"
  6. )
  7. type MountOptions struct {
  8. filer *string
  9. filerMountRootPath *string
  10. dir *string
  11. dirListCacheLimit *int64
  12. collection *string
  13. replication *string
  14. ttlSec *int
  15. chunkSizeLimitMB *int
  16. dataCenter *string
  17. allowOthers *bool
  18. umaskString *string
  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.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.dirListCacheLimit = cmdMount.Flag.Int64("dirListCacheLimit", 1000000, "limit cache size to speed up directory long format listing")
  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. mountOptions.allowOthers = cmdMount.Flag.Bool("allowOthers", true, "allows other users to access the file system")
  37. mountOptions.umaskString = cmdMount.Flag.String("umask", "022", "octal umask, e.g., 022, 0111")
  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) (filerGrpcAddress string, err error) {
  55. hostnameAndPort := strings.Split(filer, ":")
  56. if len(hostnameAndPort) != 2 {
  57. return "", fmt.Errorf("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("filer port parse error: %v", parseErr)
  62. }
  63. filerGrpcPort := int(filerPort) + 10000
  64. return fmt.Sprintf("%s:%d", hostnameAndPort[0], filerGrpcPort), nil
  65. }