xfs_parent.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2022-2024 Oracle.
  4. * All Rights Reserved.
  5. */
  6. #ifndef __XFS_PARENT_H__
  7. #define __XFS_PARENT_H__
  8. /* Metadata validators */
  9. bool xfs_parent_namecheck(unsigned int attr_flags, const void *name,
  10. size_t length);
  11. bool xfs_parent_valuecheck(struct xfs_mount *mp, const void *value,
  12. size_t valuelen);
  13. xfs_dahash_t xfs_parent_hashval(struct xfs_mount *mp, const uint8_t *name,
  14. int namelen, xfs_ino_t parent_ino);
  15. xfs_dahash_t xfs_parent_hashattr(struct xfs_mount *mp, const uint8_t *name,
  16. int namelen, const void *value, int valuelen);
  17. /* Initializes a xfs_parent_rec to be stored as an attribute name. */
  18. static inline void
  19. xfs_parent_rec_init(
  20. struct xfs_parent_rec *rec,
  21. xfs_ino_t ino,
  22. uint32_t gen)
  23. {
  24. rec->p_ino = cpu_to_be64(ino);
  25. rec->p_gen = cpu_to_be32(gen);
  26. }
  27. /* Initializes a xfs_parent_rec to be stored as an attribute name. */
  28. static inline void
  29. xfs_inode_to_parent_rec(
  30. struct xfs_parent_rec *rec,
  31. const struct xfs_inode *dp)
  32. {
  33. xfs_parent_rec_init(rec, dp->i_ino, VFS_IC(dp)->i_generation);
  34. }
  35. extern struct kmem_cache *xfs_parent_args_cache;
  36. /*
  37. * Parent pointer information needed to pass around the deferred xattr update
  38. * machinery.
  39. */
  40. struct xfs_parent_args {
  41. struct xfs_parent_rec rec;
  42. struct xfs_parent_rec new_rec;
  43. struct xfs_da_args args;
  44. };
  45. /*
  46. * Start a parent pointer update by allocating the context object we need to
  47. * perform a parent pointer update.
  48. */
  49. static inline int
  50. xfs_parent_start(
  51. struct xfs_mount *mp,
  52. struct xfs_parent_args **ppargsp)
  53. {
  54. if (!xfs_has_parent(mp)) {
  55. *ppargsp = NULL;
  56. return 0;
  57. }
  58. *ppargsp = kmem_cache_zalloc(xfs_parent_args_cache, GFP_KERNEL);
  59. if (!*ppargsp)
  60. return -ENOMEM;
  61. return 0;
  62. }
  63. /* Finish a parent pointer update by freeing the context object. */
  64. static inline void
  65. xfs_parent_finish(
  66. struct xfs_mount *mp,
  67. struct xfs_parent_args *ppargs)
  68. {
  69. if (ppargs)
  70. kmem_cache_free(xfs_parent_args_cache, ppargs);
  71. }
  72. int xfs_parent_addname(struct xfs_trans *tp, struct xfs_parent_args *ppargs,
  73. struct xfs_inode *dp, const struct xfs_name *parent_name,
  74. struct xfs_inode *child);
  75. int xfs_parent_removename(struct xfs_trans *tp, struct xfs_parent_args *ppargs,
  76. struct xfs_inode *dp, const struct xfs_name *parent_name,
  77. struct xfs_inode *child);
  78. int xfs_parent_replacename(struct xfs_trans *tp,
  79. struct xfs_parent_args *ppargs,
  80. struct xfs_inode *old_dp, const struct xfs_name *old_name,
  81. struct xfs_inode *new_dp, const struct xfs_name *new_name,
  82. struct xfs_inode *child);
  83. int xfs_parent_from_attr(struct xfs_mount *mp, unsigned int attr_flags,
  84. const unsigned char *name, unsigned int namelen,
  85. const void *value, unsigned int valuelen,
  86. xfs_ino_t *parent_ino, uint32_t *parent_gen);
  87. /* Repair functions */
  88. int xfs_parent_lookup(struct xfs_trans *tp, struct xfs_inode *ip,
  89. const struct xfs_name *name, struct xfs_parent_rec *pptr,
  90. struct xfs_da_args *scratch);
  91. int xfs_parent_set(struct xfs_inode *ip, xfs_ino_t owner,
  92. const struct xfs_name *name, struct xfs_parent_rec *pptr,
  93. struct xfs_da_args *scratch);
  94. int xfs_parent_unset(struct xfs_inode *ip, xfs_ino_t owner,
  95. const struct xfs_name *name, struct xfs_parent_rec *pptr,
  96. struct xfs_da_args *scratch);
  97. #endif /* __XFS_PARENT_H__ */