vfs_dentry.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/fs/9p/vfs_dentry.c
  4. *
  5. * This file contians vfs dentry ops for the 9P2000 protocol.
  6. *
  7. * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
  8. * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
  9. */
  10. #include <linux/module.h>
  11. #include <linux/errno.h>
  12. #include <linux/fs.h>
  13. #include <linux/file.h>
  14. #include <linux/pagemap.h>
  15. #include <linux/stat.h>
  16. #include <linux/string.h>
  17. #include <linux/inet.h>
  18. #include <linux/namei.h>
  19. #include <linux/idr.h>
  20. #include <linux/sched.h>
  21. #include <linux/slab.h>
  22. #include <net/9p/9p.h>
  23. #include <net/9p/client.h>
  24. #include "v9fs.h"
  25. #include "v9fs_vfs.h"
  26. #include "fid.h"
  27. /**
  28. * v9fs_cached_dentry_delete - called when dentry refcount equals 0
  29. * @dentry: dentry in question
  30. *
  31. */
  32. static int v9fs_cached_dentry_delete(const struct dentry *dentry)
  33. {
  34. p9_debug(P9_DEBUG_VFS, " dentry: %pd (%p)\n",
  35. dentry, dentry);
  36. /* Don't cache negative dentries */
  37. if (d_really_is_negative(dentry))
  38. return 1;
  39. return 0;
  40. }
  41. /**
  42. * v9fs_dentry_release - called when dentry is going to be freed
  43. * @dentry: dentry that is being release
  44. *
  45. */
  46. static void v9fs_dentry_release(struct dentry *dentry)
  47. {
  48. struct hlist_node *p, *n;
  49. p9_debug(P9_DEBUG_VFS, " dentry: %pd (%p)\n",
  50. dentry, dentry);
  51. hlist_for_each_safe(p, n, (struct hlist_head *)&dentry->d_fsdata)
  52. p9_client_clunk(hlist_entry(p, struct p9_fid, dlist));
  53. dentry->d_fsdata = NULL;
  54. }
  55. static int v9fs_lookup_revalidate(struct dentry *dentry, unsigned int flags)
  56. {
  57. struct p9_fid *fid;
  58. struct inode *inode;
  59. struct v9fs_inode *v9inode;
  60. if (flags & LOOKUP_RCU)
  61. return -ECHILD;
  62. inode = d_inode(dentry);
  63. if (!inode)
  64. goto out_valid;
  65. v9inode = V9FS_I(inode);
  66. if (v9inode->cache_validity & V9FS_INO_INVALID_ATTR) {
  67. int retval;
  68. struct v9fs_session_info *v9ses;
  69. fid = v9fs_fid_lookup(dentry);
  70. if (IS_ERR(fid))
  71. return PTR_ERR(fid);
  72. v9ses = v9fs_inode2v9ses(inode);
  73. if (v9fs_proto_dotl(v9ses))
  74. retval = v9fs_refresh_inode_dotl(fid, inode);
  75. else
  76. retval = v9fs_refresh_inode(fid, inode);
  77. if (retval == -ENOENT)
  78. return 0;
  79. if (retval < 0)
  80. return retval;
  81. }
  82. out_valid:
  83. return 1;
  84. }
  85. const struct dentry_operations v9fs_cached_dentry_operations = {
  86. .d_revalidate = v9fs_lookup_revalidate,
  87. .d_weak_revalidate = v9fs_lookup_revalidate,
  88. .d_delete = v9fs_cached_dentry_delete,
  89. .d_release = v9fs_dentry_release,
  90. };
  91. const struct dentry_operations v9fs_dentry_operations = {
  92. .d_delete = always_delete_dentry,
  93. .d_release = v9fs_dentry_release,
  94. };