ops_dentry.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 <linux/lm_interface.h>
  16. #include "gfs2.h"
  17. #include "incore.h"
  18. #include "dir.h"
  19. #include "glock.h"
  20. #include "ops_dentry.h"
  21. #include "util.h"
  22. #include "inode.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 = NULL;
  41. int error;
  42. int had_lock=0;
  43. if (inode) {
  44. if (is_bad_inode(inode))
  45. goto invalid;
  46. ip = GFS2_I(inode);
  47. }
  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_check(parent->d_inode, &dentry->d_name, ip);
  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. valid_gunlock:
  70. if (!had_lock)
  71. gfs2_glock_dq_uninit(&d_gh);
  72. valid:
  73. dput(parent);
  74. return 1;
  75. invalid_gunlock:
  76. if (!had_lock)
  77. gfs2_glock_dq_uninit(&d_gh);
  78. invalid:
  79. if (inode && S_ISDIR(inode->i_mode)) {
  80. if (have_submounts(dentry))
  81. goto valid;
  82. shrink_dcache_parent(dentry);
  83. }
  84. d_drop(dentry);
  85. dput(parent);
  86. return 0;
  87. fail_gunlock:
  88. gfs2_glock_dq_uninit(&d_gh);
  89. fail:
  90. dput(parent);
  91. return 0;
  92. }
  93. static int gfs2_dhash(struct dentry *dentry, struct qstr *str)
  94. {
  95. str->hash = gfs2_disk_hash(str->name, str->len);
  96. return 0;
  97. }
  98. struct dentry_operations gfs2_dops = {
  99. .d_revalidate = gfs2_drevalidate,
  100. .d_hash = gfs2_dhash,
  101. };