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.

108 lines
2.8 KiB

  1. package mount
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/chrislusf/seaweedfs/weed/filer"
  6. "github.com/chrislusf/seaweedfs/weed/glog"
  7. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  8. "github.com/hanwen/go-fuse/v2/fuse"
  9. "time"
  10. )
  11. func (wfs *WFS) Mknod(cancel <-chan struct{}, in *fuse.MknodIn, name string, out *fuse.EntryOut) (code fuse.Status) {
  12. if s := checkName(name); s != fuse.OK {
  13. return s
  14. }
  15. newEntry := &filer_pb.Entry{
  16. Name: name,
  17. IsDirectory: false,
  18. Attributes: &filer_pb.FuseAttributes{
  19. Mtime: time.Now().Unix(),
  20. Crtime: time.Now().Unix(),
  21. FileMode: uint32(toFileMode(in.Mode) &^ wfs.option.Umask),
  22. Uid: in.Uid,
  23. Gid: in.Gid,
  24. Collection: wfs.option.Collection,
  25. Replication: wfs.option.Replication,
  26. TtlSec: wfs.option.TtlSec,
  27. },
  28. }
  29. dirFullPath := wfs.inodeToPath.GetPath(in.NodeId)
  30. entryFullPath := dirFullPath.Child(name)
  31. err := wfs.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
  32. wfs.mapPbIdFromLocalToFiler(newEntry)
  33. defer wfs.mapPbIdFromFilerToLocal(newEntry)
  34. request := &filer_pb.CreateEntryRequest{
  35. Directory: string(dirFullPath),
  36. Entry: newEntry,
  37. Signatures: []int32{wfs.signature},
  38. }
  39. glog.V(1).Infof("mknod: %v", request)
  40. if err := filer_pb.CreateEntry(client, request); err != nil {
  41. glog.V(0).Infof("mknod %s: %v", entryFullPath, err)
  42. return err
  43. }
  44. if err := wfs.metaCache.InsertEntry(context.Background(), filer.FromPbEntry(request.Directory, request.Entry)); err != nil {
  45. return fmt.Errorf("local mknod %s: %v", entryFullPath, err)
  46. }
  47. return nil
  48. })
  49. glog.V(0).Infof("mknod %s: %v", entryFullPath, err)
  50. if err != nil {
  51. return fuse.EIO
  52. }
  53. inode := wfs.inodeToPath.GetInode(entryFullPath)
  54. wfs.outputPbEntry(out, inode, newEntry)
  55. return fuse.OK
  56. }
  57. func (wfs *WFS) Unlink(cancel <-chan struct{}, header *fuse.InHeader, name string) (code fuse.Status) {
  58. dirFullPath := wfs.inodeToPath.GetPath(header.NodeId)
  59. entryFullPath := dirFullPath.Child(name)
  60. entry, status := wfs.maybeLoadEntry(entryFullPath)
  61. if status != fuse.OK {
  62. return status
  63. }
  64. // first, ensure the filer store can correctly delete
  65. glog.V(3).Infof("remove file: %v", entryFullPath)
  66. isDeleteData := entry != nil && entry.HardLinkCounter <= 1
  67. err := filer_pb.Remove(wfs, string(dirFullPath), name, isDeleteData, false, false, false, []int32{wfs.signature})
  68. if err != nil {
  69. glog.V(0).Infof("remove %s: %v", entryFullPath, err)
  70. return fuse.ENOENT
  71. }
  72. // then, delete meta cache
  73. if err = wfs.metaCache.DeleteEntry(context.Background(), entryFullPath); err != nil {
  74. glog.V(3).Infof("local DeleteEntry %s: %v", entryFullPath, err)
  75. return fuse.EIO
  76. }
  77. wfs.metaCache.DeleteEntry(context.Background(), entryFullPath)
  78. wfs.inodeToPath.RemovePath(entryFullPath)
  79. // TODO handle open files, hardlink
  80. return fuse.OK
  81. }