ops_dentry.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 inum;
  43. unsigned int type;
  44. int error;
  45. if (inode && is_bad_inode(inode))
  46. goto invalid;
  47. if (sdp->sd_args.ar_localcaching)
  48. goto valid;
  49. error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
  50. if (error)
  51. goto fail;
  52. error = gfs2_dir_search(parent->d_inode, &dentry->d_name, &inum, &type);
  53. switch (error) {
  54. case 0:
  55. if (!inode)
  56. goto invalid_gunlock;
  57. break;
  58. case -ENOENT:
  59. if (!inode)
  60. goto valid_gunlock;
  61. goto invalid_gunlock;
  62. default:
  63. goto fail_gunlock;
  64. }
  65. ip = GFS2_I(inode);
  66. if (!gfs2_inum_equal(&ip->i_num, &inum))
  67. goto invalid_gunlock;
  68. if (IF2DT(ip->i_di.di_mode) != type) {
  69. gfs2_consist_inode(dip);
  70. goto fail_gunlock;
  71. }
  72. valid_gunlock:
  73. gfs2_glock_dq_uninit(&d_gh);
  74. valid:
  75. dput(parent);
  76. return 1;
  77. invalid_gunlock:
  78. gfs2_glock_dq_uninit(&d_gh);
  79. invalid:
  80. if (inode && S_ISDIR(inode->i_mode)) {
  81. if (have_submounts(dentry))
  82. goto valid;
  83. shrink_dcache_parent(dentry);
  84. }
  85. d_drop(dentry);
  86. dput(parent);
  87. return 0;
  88. fail_gunlock:
  89. gfs2_glock_dq_uninit(&d_gh);
  90. fail:
  91. dput(parent);
  92. return 0;
  93. }
  94. static int gfs2_dhash(struct dentry *dentry, struct qstr *str)
  95. {
  96. str->hash = gfs2_disk_hash(str->name, str->len);
  97. return 0;
  98. }
  99. struct dentry_operations gfs2_dops = {
  100. .d_revalidate = gfs2_drevalidate,
  101. .d_hash = gfs2_dhash,
  102. };