dentry.c 2.7 KB

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