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.

107 lines
2.8 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. package mount
  2. import (
  3. "context"
  4. "github.com/chrislusf/seaweedfs/weed/filesys/meta_cache"
  5. "github.com/chrislusf/seaweedfs/weed/pb"
  6. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  7. "github.com/chrislusf/seaweedfs/weed/storage/types"
  8. "github.com/chrislusf/seaweedfs/weed/util"
  9. "github.com/chrislusf/seaweedfs/weed/util/grace"
  10. "google.golang.org/grpc"
  11. "os"
  12. "path"
  13. "path/filepath"
  14. "syscall"
  15. "time"
  16. "github.com/hanwen/go-fuse/v2/fs"
  17. "github.com/hanwen/go-fuse/v2/fuse"
  18. )
  19. type Option struct {
  20. MountDirectory string
  21. FilerAddresses []pb.ServerAddress
  22. filerIndex int
  23. GrpcDialOption grpc.DialOption
  24. FilerMountRootPath string
  25. Collection string
  26. Replication string
  27. TtlSec int32
  28. DiskType types.DiskType
  29. ChunkSizeLimit int64
  30. ConcurrentWriters int
  31. CacheDir string
  32. CacheSizeMB int64
  33. DataCenter string
  34. Umask os.FileMode
  35. MountUid uint32
  36. MountGid uint32
  37. MountMode os.FileMode
  38. MountCtime time.Time
  39. MountMtime time.Time
  40. MountParentInode uint64
  41. VolumeServerAccess string // how to access volume servers
  42. Cipher bool // whether encrypt data on volume server
  43. UidGidMapper *meta_cache.UidGidMapper
  44. uniqueCacheDir string
  45. uniqueCacheTempPageDir string
  46. }
  47. type WFS struct {
  48. fs.Inode
  49. option *Option
  50. metaCache *meta_cache.MetaCache
  51. signature int32
  52. }
  53. func NewSeaweedFileSystem(option *Option) *WFS {
  54. wfs := &WFS{
  55. option: option,
  56. signature: util.RandomInt32(),
  57. }
  58. wfs.metaCache = meta_cache.NewMetaCache(path.Join(option.getUniqueCacheDir(), "meta"), util.FullPath(option.FilerMountRootPath), option.UidGidMapper, func(filePath util.FullPath, entry *filer_pb.Entry) {
  59. })
  60. grace.OnInterrupt(func() {
  61. wfs.metaCache.Shutdown()
  62. })
  63. return wfs
  64. }
  65. func (option *Option) setupUniqueCacheDirectory() {
  66. cacheUniqueId := util.Md5String([]byte(option.MountDirectory + string(option.FilerAddresses[0]) + option.FilerMountRootPath + util.Version()))[0:8]
  67. option.uniqueCacheDir = path.Join(option.CacheDir, cacheUniqueId)
  68. option.uniqueCacheTempPageDir = filepath.Join(option.uniqueCacheDir, "sw")
  69. os.MkdirAll(option.uniqueCacheTempPageDir, os.FileMode(0777)&^option.Umask)
  70. }
  71. func (option *Option) getTempFilePageDir() string {
  72. return option.uniqueCacheTempPageDir
  73. }
  74. func (option *Option) getUniqueCacheDir() string {
  75. return option.uniqueCacheDir
  76. }
  77. func (r *WFS) OnAdd(ctx context.Context) {
  78. ch := r.NewPersistentInode(
  79. ctx, &fs.MemRegularFile{
  80. Data: []byte("file.txt"),
  81. Attr: fuse.Attr{
  82. Mode: 0644,
  83. },
  84. }, fs.StableAttr{Ino: 2})
  85. r.AddChild("file.txt", ch, false)
  86. }
  87. func (r *WFS) Getattr(ctx context.Context, fh fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
  88. out.Mode = 0755
  89. return 0
  90. }
  91. var _ = (fs.NodeGetattrer)((*WFS)(nil))
  92. var _ = (fs.NodeOnAdder)((*WFS)(nil))