dentry.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. * @flags: lookup flags
  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, unsigned int flags)
  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 (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 (check_submounts_and_drop(dentry) != 0)
  85. goto valid;
  86. dput(parent);
  87. return 0;
  88. fail_gunlock:
  89. gfs2_glock_dq_uninit(&d_gh);
  90. fail:
  91. dput(parent);
  92. return 0;
  93. }
  94. static int gfs2_dhash(const struct dentry *dentry, struct qstr *str)
  95. {
  96. str->hash = gfs2_disk_hash(str->name, str->len);
  97. return 0;
  98. }
  99. static int gfs2_dentry_delete(const struct dentry *dentry)
  100. {
  101. struct gfs2_inode *ginode;
  102. if (!dentry->d_inode)
  103. return 0;
  104. ginode = GFS2_I(dentry->d_inode);
  105. if (!ginode->i_iopen_gh.gh_gl)
  106. return 0;
  107. if (test_bit(GLF_DEMOTE, &ginode->i_iopen_gh.gh_gl->gl_flags))
  108. return 1;
  109. return 0;
  110. }
  111. const struct dentry_operations gfs2_dops = {
  112. .d_revalidate = gfs2_drevalidate,
  113. .d_hash = gfs2_dhash,
  114. .d_delete = gfs2_dentry_delete,
  115. };