ops_dentry.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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/smp_lock.h>
  14. #include <linux/gfs2_ondisk.h>
  15. #include <linux/crc32.h>
  16. #include <linux/lm_interface.h>
  17. #include "gfs2.h"
  18. #include "incore.h"
  19. #include "dir.h"
  20. #include "glock.h"
  21. #include "ops_dentry.h"
  22. #include "util.h"
  23. /**
  24. * gfs2_drevalidate - Check directory lookup consistency
  25. * @dentry: the mapping to check
  26. * @nd:
  27. *
  28. * Check to make sure the lookup necessary to arrive at this inode from its
  29. * parent is still good.
  30. *
  31. * Returns: 1 if the dentry is ok, 0 if it isn't
  32. */
  33. static int gfs2_drevalidate(struct dentry *dentry, struct nameidata *nd)
  34. {
  35. struct dentry *parent = dget_parent(dentry);
  36. struct gfs2_sbd *sdp = GFS2_SB(parent->d_inode);
  37. struct gfs2_inode *dip = GFS2_I(parent->d_inode);
  38. struct inode *inode = dentry->d_inode;
  39. struct gfs2_holder d_gh;
  40. struct gfs2_inode *ip;
  41. struct gfs2_inum_host inum;
  42. unsigned int type;
  43. int error;
  44. int had_lock=0;
  45. if (inode && is_bad_inode(inode))
  46. goto invalid;
  47. if (sdp->sd_args.ar_localcaching)
  48. goto valid;
  49. had_lock = gfs2_glock_is_locked_by_me(dip->i_gl);
  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_search(parent->d_inode, &dentry->d_name, &inum, &type);
  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. ip = GFS2_I(inode);
  69. if (!gfs2_inum_equal(&ip->i_num, &inum))
  70. goto invalid_gunlock;
  71. if (IF2DT(ip->i_inode.i_mode) != type) {
  72. gfs2_consist_inode(dip);
  73. goto fail_gunlock;
  74. }
  75. valid_gunlock:
  76. if (!had_lock)
  77. gfs2_glock_dq_uninit(&d_gh);
  78. valid:
  79. dput(parent);
  80. return 1;
  81. invalid_gunlock:
  82. if (!had_lock)
  83. gfs2_glock_dq_uninit(&d_gh);
  84. invalid:
  85. if (inode && S_ISDIR(inode->i_mode)) {
  86. if (have_submounts(dentry))
  87. goto valid;
  88. shrink_dcache_parent(dentry);
  89. }
  90. d_drop(dentry);
  91. dput(parent);
  92. return 0;
  93. fail_gunlock:
  94. gfs2_glock_dq_uninit(&d_gh);
  95. fail:
  96. dput(parent);
  97. return 0;
  98. }
  99. static int gfs2_dhash(struct dentry *dentry, struct qstr *str)
  100. {
  101. str->hash = gfs2_disk_hash(str->name, str->len);
  102. return 0;
  103. }
  104. struct dentry_operations gfs2_dops = {
  105. .d_revalidate = gfs2_drevalidate,
  106. .d_hash = gfs2_dhash,
  107. };