dentry.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  4. * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
  5. */
  6. #include <linux/spinlock.h>
  7. #include <linux/completion.h>
  8. #include <linux/buffer_head.h>
  9. #include <linux/gfs2_ondisk.h>
  10. #include <linux/namei.h>
  11. #include <linux/crc32.h>
  12. #include "gfs2.h"
  13. #include "incore.h"
  14. #include "dir.h"
  15. #include "glock.h"
  16. #include "super.h"
  17. #include "util.h"
  18. #include "inode.h"
  19. /**
  20. * gfs2_drevalidate - Check directory lookup consistency
  21. * @dentry: the mapping to check
  22. * @flags: lookup flags
  23. *
  24. * Check to make sure the lookup necessary to arrive at this inode from its
  25. * parent is still good.
  26. *
  27. * Returns: 1 if the dentry is ok, 0 if it isn't
  28. */
  29. static int gfs2_drevalidate(struct dentry *dentry, unsigned int flags)
  30. {
  31. struct dentry *parent;
  32. struct gfs2_sbd *sdp;
  33. struct gfs2_inode *dip;
  34. struct inode *inode;
  35. struct gfs2_holder d_gh;
  36. struct gfs2_inode *ip = NULL;
  37. int error, valid = 0;
  38. int had_lock = 0;
  39. if (flags & LOOKUP_RCU)
  40. return -ECHILD;
  41. parent = dget_parent(dentry);
  42. sdp = GFS2_SB(d_inode(parent));
  43. dip = GFS2_I(d_inode(parent));
  44. inode = d_inode(dentry);
  45. if (inode) {
  46. if (is_bad_inode(inode))
  47. goto out;
  48. ip = GFS2_I(inode);
  49. }
  50. if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL) {
  51. valid = 1;
  52. goto out;
  53. }
  54. had_lock = (gfs2_glock_is_locked_by_me(dip->i_gl) != NULL);
  55. if (!had_lock) {
  56. error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
  57. if (error)
  58. goto out;
  59. }
  60. error = gfs2_dir_check(d_inode(parent), &dentry->d_name, ip);
  61. valid = inode ? !error : (error == -ENOENT);
  62. if (!had_lock)
  63. gfs2_glock_dq_uninit(&d_gh);
  64. out:
  65. dput(parent);
  66. return valid;
  67. }
  68. static int gfs2_dhash(const struct dentry *dentry, struct qstr *str)
  69. {
  70. str->hash = gfs2_disk_hash(str->name, str->len);
  71. return 0;
  72. }
  73. static int gfs2_dentry_delete(const struct dentry *dentry)
  74. {
  75. struct gfs2_inode *ginode;
  76. if (d_really_is_negative(dentry))
  77. return 0;
  78. ginode = GFS2_I(d_inode(dentry));
  79. if (!gfs2_holder_initialized(&ginode->i_iopen_gh))
  80. return 0;
  81. if (test_bit(GLF_DEMOTE, &ginode->i_iopen_gh.gh_gl->gl_flags))
  82. return 1;
  83. return 0;
  84. }
  85. const struct dentry_operations gfs2_dops = {
  86. .d_revalidate = gfs2_drevalidate,
  87. .d_hash = gfs2_dhash,
  88. .d_delete = gfs2_dentry_delete,
  89. };