ops_dentry.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2005 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 v.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 <asm/semaphore.h>
  17. #include "gfs2.h"
  18. #include "lm_interface.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_inode *dip = parent->d_inode->u.generic_ip;
  38. struct inode *inode;
  39. struct gfs2_holder d_gh;
  40. struct gfs2_inode *ip;
  41. struct gfs2_inum inum;
  42. unsigned int type;
  43. int error;
  44. lock_kernel();
  45. inode = dentry->d_inode;
  46. if (inode && is_bad_inode(inode))
  47. goto invalid;
  48. error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
  49. if (error)
  50. goto fail;
  51. error = gfs2_dir_search(dip, &dentry->d_name, &inum, &type);
  52. switch (error) {
  53. case 0:
  54. if (!inode)
  55. goto invalid_gunlock;
  56. break;
  57. case -ENOENT:
  58. if (!inode)
  59. goto valid_gunlock;
  60. goto invalid_gunlock;
  61. default:
  62. goto fail_gunlock;
  63. }
  64. ip = inode->u.generic_ip;
  65. if (!gfs2_inum_equal(&ip->i_num, &inum))
  66. goto invalid_gunlock;
  67. if (IF2DT(ip->i_di.di_mode) != type) {
  68. gfs2_consist_inode(dip);
  69. goto fail_gunlock;
  70. }
  71. valid_gunlock:
  72. gfs2_glock_dq_uninit(&d_gh);
  73. valid:
  74. unlock_kernel();
  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. unlock_kernel();
  87. dput(parent);
  88. return 0;
  89. fail_gunlock:
  90. gfs2_glock_dq_uninit(&d_gh);
  91. fail:
  92. unlock_kernel();
  93. dput(parent);
  94. return 0;
  95. }
  96. struct dentry_operations gfs2_dops = {
  97. .d_revalidate = gfs2_drevalidate,
  98. };