ops_dentry.c 2.7 KB

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