weedfs_forget.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package mount
  2. import (
  3. "context"
  4. "github.com/seaweedfs/seaweedfs/weed/util"
  5. )
  6. // Forget is called when the kernel discards entries from its
  7. // dentry cache. This happens on unmount, and when the kernel
  8. // is short on memory. Since it is not guaranteed to occur at
  9. // any moment, and since there is no return value, Forget
  10. // should not do I/O, as there is no channel to report back
  11. // I/O errors.
  12. // from https://github.com/libfuse/libfuse/blob/master/include/fuse_lowlevel.h
  13. /**
  14. * Forget about an inode
  15. *
  16. * This function is called when the kernel removes an inode
  17. * from its internal caches.
  18. *
  19. * The inode's lookup count increases by one for every call to
  20. * fuse_reply_entry and fuse_reply_create. The nlookup parameter
  21. * indicates by how much the lookup count should be decreased.
  22. *
  23. * Inodes with a non-zero lookup count may receive request from
  24. * the kernel even after calls to unlink, rmdir or (when
  25. * overwriting an existing file) rename. Filesystems must handle
  26. * such requests properly and it is recommended to defer removal
  27. * of the inode until the lookup count reaches zero. Calls to
  28. * unlink, rmdir or rename will be followed closely by forget
  29. * unless the file or directory is open, in which case the
  30. * kernel issues forget only after the release or releasedir
  31. * calls.
  32. *
  33. * Note that if a file system will be exported over NFS the
  34. * inodes lifetime must extend even beyond forget. See the
  35. * generation field in struct fuse_entry_param above.
  36. *
  37. * On unmount the lookup count for all inodes implicitly drops
  38. * to zero. It is not guaranteed that the file system will
  39. * receive corresponding forget messages for the affected
  40. * inodes.
  41. *
  42. * Valid replies:
  43. * fuse_reply_none
  44. *
  45. * @param req request handle
  46. * @param ino the inode number
  47. * @param nlookup the number of lookups to forget
  48. */
  49. /*
  50. https://libfuse.github.io/doxygen/include_2fuse__lowlevel_8h.html
  51. int fuse_reply_entry ( fuse_req_t req,
  52. const struct fuse_entry_param * e
  53. )
  54. Reply with a directory entry
  55. Possible requests: lookup, mknod, mkdir, symlink, link
  56. Side effects: increments the lookup count on success
  57. */
  58. func (wfs *WFS) Forget(nodeid, nlookup uint64) {
  59. wfs.inodeToPath.Forget(nodeid, nlookup, func(dir util.FullPath) {
  60. wfs.metaCache.DeleteFolderChildren(context.Background(), dir)
  61. })
  62. wfs.fhmap.ReleaseByInode(nodeid)
  63. }