dentry.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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/slab.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/completion.h>
  12. #include <linux/buffer_head.h>
  13. #include <linux/gfs2_ondisk.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 = dget_parent(dentry);
  35. struct gfs2_sbd *sdp = GFS2_SB(parent->d_inode);
  36. struct gfs2_inode *dip = GFS2_I(parent->d_inode);
  37. struct inode *inode = dentry->d_inode;
  38. struct gfs2_holder d_gh;
  39. struct gfs2_inode *ip = NULL;
  40. int error;
  41. int had_lock = 0;
  42. if (inode) {
  43. if (is_bad_inode(inode))
  44. goto invalid;
  45. ip = GFS2_I(inode);
  46. }
  47. if (sdp->sd_args.ar_localcaching)
  48. goto valid;
  49. had_lock = (gfs2_glock_is_locked_by_me(dip->i_gl) != NULL);
  50. if (!had_lock) {
  51. error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
  52. if (error)
  53. goto fail;
  54. }
  55. error = gfs2_dir_check(parent->d_inode, &dentry->d_name, ip);
  56. switch (error) {
  57. case 0:
  58. if (!inode)
  59. goto invalid_gunlock;
  60. break;
  61. case -ENOENT:
  62. if (!inode)
  63. goto valid_gunlock;
  64. goto invalid_gunlock;
  65. default:
  66. goto fail_gunlock;
  67. }
  68. valid_gunlock:
  69. if (!had_lock)
  70. gfs2_glock_dq_uninit(&d_gh);
  71. valid:
  72. dput(parent);
  73. return 1;
  74. invalid_gunlock:
  75. if (!had_lock)
  76. gfs2_glock_dq_uninit(&d_gh);
  77. invalid:
  78. if (inode && S_ISDIR(inode->i_mode)) {
  79. if (have_submounts(dentry))
  80. goto valid;
  81. shrink_dcache_parent(dentry);
  82. }
  83. d_drop(dentry);
  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(struct dentry *dentry, struct qstr *str)
  93. {
  94. str->hash = gfs2_disk_hash(str->name, str->len);
  95. return 0;
  96. }
  97. const struct dentry_operations gfs2_dops = {
  98. .d_revalidate = gfs2_drevalidate,
  99. .d_hash = gfs2_dhash,
  100. };