dentry.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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/crc32.h>
  14. #include "gfs2.h"
  15. #include "incore.h"
  16. #include "dir.h"
  17. #include "glock.h"
  18. #include "super.h"
  19. #include "util.h"
  20. #include "inode.h"
  21. /**
  22. * gfs2_drevalidate - Check directory lookup consistency
  23. * @dentry: the mapping to check
  24. * @nd:
  25. *
  26. * Check to make sure the lookup necessary to arrive at this inode from its
  27. * parent is still good.
  28. *
  29. * Returns: 1 if the dentry is ok, 0 if it isn't
  30. */
  31. static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd)
  32. {
  33. struct dentry *parent = dget_parent(dentry);
  34. struct gfs2_sbd *sdp = GFS2_SB(parent->d_inode);
  35. struct gfs2_inode *dip = GFS2_I(parent->d_inode);
  36. struct inode *inode = dentry->d_inode;
  37. struct gfs2_holder d_gh;
  38. struct gfs2_inode *ip = NULL;
  39. int error;
  40. int had_lock = 0;
  41. if (inode) {
  42. if (is_bad_inode(inode))
  43. goto invalid;
  44. ip = GFS2_I(inode);
  45. }
  46. if (sdp->sd_args.ar_localcaching)
  47. goto valid;
  48. had_lock = (gfs2_glock_is_locked_by_me(dip->i_gl) != NULL);
  49. if (!had_lock) {
  50. error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
  51. if (error)
  52. goto fail;
  53. }
  54. error = gfs2_dir_check(parent->d_inode, &dentry->d_name, ip);
  55. switch (error) {
  56. case 0:
  57. if (!inode)
  58. goto invalid_gunlock;
  59. break;
  60. case -ENOENT:
  61. if (!inode)
  62. goto valid_gunlock;
  63. goto invalid_gunlock;
  64. default:
  65. goto fail_gunlock;
  66. }
  67. valid_gunlock:
  68. if (!had_lock)
  69. gfs2_glock_dq_uninit(&d_gh);
  70. valid:
  71. dput(parent);
  72. return 1;
  73. invalid_gunlock:
  74. if (!had_lock)
  75. gfs2_glock_dq_uninit(&d_gh);
  76. invalid:
  77. if (inode && S_ISDIR(inode->i_mode)) {
  78. if (have_submounts(dentry))
  79. goto valid;
  80. shrink_dcache_parent(dentry);
  81. }
  82. d_drop(dentry);
  83. dput(parent);
  84. return 0;
  85. fail_gunlock:
  86. gfs2_glock_dq_uninit(&d_gh);
  87. fail:
  88. dput(parent);
  89. return 0;
  90. }
  91. static int gfs2_dhash(struct dentry *dentry, struct qstr *str)
  92. {
  93. str->hash = gfs2_disk_hash(str->name, str->len);
  94. return 0;
  95. }
  96. static int gfs2_dentry_delete(struct dentry *dentry)
  97. {
  98. struct gfs2_inode *ginode;
  99. if (!dentry->d_inode)
  100. return 0;
  101. ginode = GFS2_I(dentry->d_inode);
  102. if (!ginode->i_iopen_gh.gh_gl)
  103. return 0;
  104. if (test_bit(GLF_DEMOTE, &ginode->i_iopen_gh.gh_gl->gl_flags))
  105. return 1;
  106. return 0;
  107. }
  108. const struct dentry_operations gfs2_dops = {
  109. .d_revalidate = gfs2_drevalidate,
  110. .d_hash = gfs2_dhash,
  111. .d_delete = gfs2_dentry_delete,
  112. };