dentry.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. * @dir: expected parent directory inode
  22. * @name: expexted name
  23. * @dentry: dentry to check
  24. * @flags: lookup flags
  25. *
  26. * Check to make sure the lookup necessary to arrive at this inode from its
  27. * parent is still good.
  28. *
  29. * Returns: 1 if the dentry is ok, 0 if it isn't
  30. */
  31. static int gfs2_drevalidate(struct inode *dir, const struct qstr *name,
  32. struct dentry *dentry, unsigned int flags)
  33. {
  34. struct gfs2_sbd *sdp = GFS2_SB(dir);
  35. struct gfs2_inode *dip = GFS2_I(dir);
  36. struct inode *inode;
  37. struct gfs2_holder d_gh;
  38. struct gfs2_inode *ip = NULL;
  39. int error, valid;
  40. int had_lock = 0;
  41. if (flags & LOOKUP_RCU)
  42. return -ECHILD;
  43. inode = d_inode(dentry);
  44. if (inode) {
  45. if (is_bad_inode(inode))
  46. return 0;
  47. ip = GFS2_I(inode);
  48. }
  49. if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL)
  50. return 1;
  51. had_lock = (gfs2_glock_is_locked_by_me(dip->i_gl) != NULL);
  52. if (!had_lock) {
  53. error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
  54. if (error)
  55. return 0;
  56. }
  57. error = gfs2_dir_check(dir, name, ip);
  58. valid = inode ? !error : (error == -ENOENT);
  59. if (!had_lock)
  60. gfs2_glock_dq_uninit(&d_gh);
  61. return valid;
  62. }
  63. static int gfs2_dhash(const struct dentry *dentry, struct qstr *str)
  64. {
  65. str->hash = gfs2_disk_hash(str->name, str->len);
  66. return 0;
  67. }
  68. static int gfs2_dentry_delete(const struct dentry *dentry)
  69. {
  70. struct gfs2_inode *ginode;
  71. if (d_really_is_negative(dentry))
  72. return 0;
  73. ginode = GFS2_I(d_inode(dentry));
  74. if (!gfs2_holder_initialized(&ginode->i_iopen_gh))
  75. return 0;
  76. if (test_bit(GLF_DEMOTE, &ginode->i_iopen_gh.gh_gl->gl_flags))
  77. return 1;
  78. return 0;
  79. }
  80. const struct dentry_operations gfs2_dops = {
  81. .d_revalidate = gfs2_drevalidate,
  82. .d_hash = gfs2_dhash,
  83. .d_delete = gfs2_dentry_delete,
  84. };