dentry.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
  4. *
  5. * This copyrighted material is made available to anyone wishing to use,
  6. * modify, copy, or redistribute it subject to the terms and conditions
  7. * of the GNU General Public License version 2.
  8. */
  9. #include <linux/spinlock.h>
  10. #include <linux/completion.h>
  11. #include <linux/buffer_head.h>
  12. #include <linux/gfs2_ondisk.h>
  13. #include <linux/namei.h>
  14. #include <linux/crc32.h>
  15. #include "gfs2.h"
  16. #include "incore.h"
  17. #include "dir.h"
  18. #include "glock.h"
  19. #include "super.h"
  20. #include "util.h"
  21. #include "inode.h"
  22. /**
  23. * gfs2_drevalidate - Check directory lookup consistency
  24. * @dentry: the mapping to check
  25. * @nd:
  26. *
  27. * Check to make sure the lookup necessary to arrive at this inode from its
  28. * parent is still good.
  29. *
  30. * Returns: 1 if the dentry is ok, 0 if it isn't
  31. */
  32. static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd)
  33. {
  34. struct dentry *parent;
  35. struct gfs2_sbd *sdp;
  36. struct gfs2_inode *dip;
  37. struct inode *inode;
  38. struct gfs2_holder d_gh;
  39. struct gfs2_inode *ip = NULL;
  40. int error;
  41. int had_lock = 0;
  42. if (nd && nd->flags & LOOKUP_RCU)
  43. return -ECHILD;
  44. parent = dget_parent(dentry);
  45. sdp = GFS2_SB(parent->d_inode);
  46. dip = GFS2_I(parent->d_inode);
  47. inode = dentry->d_inode;
  48. if (inode) {
  49. if (is_bad_inode(inode))
  50. goto invalid;
  51. ip = GFS2_I(inode);
  52. }
  53. if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL)
  54. goto valid;
  55. had_lock = (gfs2_glock_is_locked_by_me(dip->i_gl) != NULL);
  56. if (!had_lock) {
  57. error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
  58. if (error)
  59. goto fail;
  60. }
  61. error = gfs2_dir_check(parent->d_inode, &dentry->d_name, ip);
  62. switch (error) {
  63. case 0:
  64. if (!inode)
  65. goto invalid_gunlock;
  66. break;
  67. case -ENOENT:
  68. if (!inode)
  69. goto valid_gunlock;
  70. goto invalid_gunlock;
  71. default:
  72. goto fail_gunlock;
  73. }
  74. valid_gunlock:
  75. if (!had_lock)
  76. gfs2_glock_dq_uninit(&d_gh);
  77. valid:
  78. dput(parent);
  79. return 1;
  80. invalid_gunlock:
  81. if (!had_lock)
  82. gfs2_glock_dq_uninit(&d_gh);
  83. invalid:
  84. if (inode && S_ISDIR(inode->i_mode)) {
  85. if (have_submounts(dentry))
  86. goto valid;
  87. shrink_dcache_parent(dentry);
  88. }
  89. d_drop(dentry);
  90. dput(parent);
  91. return 0;
  92. fail_gunlock:
  93. gfs2_glock_dq_uninit(&d_gh);
  94. fail:
  95. dput(parent);
  96. return 0;
  97. }
  98. static int gfs2_dhash(const struct dentry *dentry, const struct inode *inode,
  99. struct qstr *str)
  100. {
  101. str->hash = gfs2_disk_hash(str->name, str->len);
  102. return 0;
  103. }
  104. static int gfs2_dentry_delete(const struct dentry *dentry)
  105. {
  106. struct gfs2_inode *ginode;
  107. if (!dentry->d_inode)
  108. return 0;
  109. ginode = GFS2_I(dentry->d_inode);
  110. if (!ginode->i_iopen_gh.gh_gl)
  111. return 0;
  112. if (test_bit(GLF_DEMOTE, &ginode->i_iopen_gh.gh_gl->gl_flags))
  113. return 1;
  114. return 0;
  115. }
  116. const struct dentry_operations gfs2_dops = {
  117. .d_revalidate = gfs2_drevalidate,
  118. .d_hash = gfs2_dhash,
  119. .d_delete = gfs2_dentry_delete,
  120. };