xfs_shared.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  4. * Copyright (c) 2013 Red Hat, Inc.
  5. * All Rights Reserved.
  6. */
  7. #ifndef __XFS_SHARED_H__
  8. #define __XFS_SHARED_H__
  9. /*
  10. * Definitions shared between kernel and userspace that don't fit into any other
  11. * header file that is shared with userspace.
  12. */
  13. struct xfs_ifork;
  14. struct xfs_buf;
  15. struct xfs_buf_ops;
  16. struct xfs_mount;
  17. struct xfs_trans;
  18. struct xfs_inode;
  19. /*
  20. * Buffer verifier operations are widely used, including userspace tools
  21. */
  22. extern const struct xfs_buf_ops xfs_agf_buf_ops;
  23. extern const struct xfs_buf_ops xfs_agfl_buf_ops;
  24. extern const struct xfs_buf_ops xfs_agi_buf_ops;
  25. extern const struct xfs_buf_ops xfs_attr3_leaf_buf_ops;
  26. extern const struct xfs_buf_ops xfs_attr3_rmt_buf_ops;
  27. extern const struct xfs_buf_ops xfs_bmbt_buf_ops;
  28. extern const struct xfs_buf_ops xfs_bnobt_buf_ops;
  29. extern const struct xfs_buf_ops xfs_cntbt_buf_ops;
  30. extern const struct xfs_buf_ops xfs_da3_node_buf_ops;
  31. extern const struct xfs_buf_ops xfs_dquot_buf_ops;
  32. extern const struct xfs_buf_ops xfs_dquot_buf_ra_ops;
  33. extern const struct xfs_buf_ops xfs_finobt_buf_ops;
  34. extern const struct xfs_buf_ops xfs_inobt_buf_ops;
  35. extern const struct xfs_buf_ops xfs_inode_buf_ops;
  36. extern const struct xfs_buf_ops xfs_inode_buf_ra_ops;
  37. extern const struct xfs_buf_ops xfs_refcountbt_buf_ops;
  38. extern const struct xfs_buf_ops xfs_rmapbt_buf_ops;
  39. extern const struct xfs_buf_ops xfs_rtbuf_ops;
  40. extern const struct xfs_buf_ops xfs_sb_buf_ops;
  41. extern const struct xfs_buf_ops xfs_sb_quiet_buf_ops;
  42. extern const struct xfs_buf_ops xfs_symlink_buf_ops;
  43. /* btree ops */
  44. extern const struct xfs_btree_ops xfs_bnobt_ops;
  45. extern const struct xfs_btree_ops xfs_cntbt_ops;
  46. extern const struct xfs_btree_ops xfs_inobt_ops;
  47. extern const struct xfs_btree_ops xfs_finobt_ops;
  48. extern const struct xfs_btree_ops xfs_bmbt_ops;
  49. extern const struct xfs_btree_ops xfs_refcountbt_ops;
  50. extern const struct xfs_btree_ops xfs_rmapbt_ops;
  51. extern const struct xfs_btree_ops xfs_rmapbt_mem_ops;
  52. static inline bool xfs_btree_is_bno(const struct xfs_btree_ops *ops)
  53. {
  54. return ops == &xfs_bnobt_ops;
  55. }
  56. static inline bool xfs_btree_is_cnt(const struct xfs_btree_ops *ops)
  57. {
  58. return ops == &xfs_cntbt_ops;
  59. }
  60. static inline bool xfs_btree_is_bmap(const struct xfs_btree_ops *ops)
  61. {
  62. return ops == &xfs_bmbt_ops;
  63. }
  64. static inline bool xfs_btree_is_ino(const struct xfs_btree_ops *ops)
  65. {
  66. return ops == &xfs_inobt_ops;
  67. }
  68. static inline bool xfs_btree_is_fino(const struct xfs_btree_ops *ops)
  69. {
  70. return ops == &xfs_finobt_ops;
  71. }
  72. static inline bool xfs_btree_is_refcount(const struct xfs_btree_ops *ops)
  73. {
  74. return ops == &xfs_refcountbt_ops;
  75. }
  76. static inline bool xfs_btree_is_rmap(const struct xfs_btree_ops *ops)
  77. {
  78. return ops == &xfs_rmapbt_ops;
  79. }
  80. #ifdef CONFIG_XFS_BTREE_IN_MEM
  81. static inline bool xfs_btree_is_mem_rmap(const struct xfs_btree_ops *ops)
  82. {
  83. return ops == &xfs_rmapbt_mem_ops;
  84. }
  85. #else
  86. # define xfs_btree_is_mem_rmap(...) (false)
  87. #endif
  88. /* log size calculation functions */
  89. int xfs_log_calc_unit_res(struct xfs_mount *mp, int unit_bytes);
  90. int xfs_log_calc_minimum_size(struct xfs_mount *);
  91. struct xfs_trans_res;
  92. void xfs_log_get_max_trans_res(struct xfs_mount *mp,
  93. struct xfs_trans_res *max_resp);
  94. /*
  95. * Values for t_flags.
  96. */
  97. /* Transaction needs to be logged */
  98. #define XFS_TRANS_DIRTY (1u << 0)
  99. /* Superblock is dirty and needs to be logged */
  100. #define XFS_TRANS_SB_DIRTY (1u << 1)
  101. /* Transaction took a permanent log reservation */
  102. #define XFS_TRANS_PERM_LOG_RES (1u << 2)
  103. /* Synchronous transaction commit needed */
  104. #define XFS_TRANS_SYNC (1u << 3)
  105. /* Transaction can use reserve block pool */
  106. #define XFS_TRANS_RESERVE (1u << 4)
  107. /* Transaction should avoid VFS level superblock write accounting */
  108. #define XFS_TRANS_NO_WRITECOUNT (1u << 5)
  109. /* Transaction has freed blocks returned to it's reservation */
  110. #define XFS_TRANS_RES_FDBLKS (1u << 6)
  111. /* Transaction contains an intent done log item */
  112. #define XFS_TRANS_HAS_INTENT_DONE (1u << 7)
  113. /*
  114. * LOWMODE is used by the allocator to activate the lowspace algorithm - when
  115. * free space is running low the extent allocator may choose to allocate an
  116. * extent from an AG without leaving sufficient space for a btree split when
  117. * inserting the new extent. In this case the allocator will enable the
  118. * lowspace algorithm which is supposed to allow further allocations (such as
  119. * btree splits and newroots) to allocate from sequential AGs. In order to
  120. * avoid locking AGs out of order the lowspace algorithm will start searching
  121. * for free space from AG 0. If the correct transaction reservations have been
  122. * made then this algorithm will eventually find all the space it needs.
  123. */
  124. #define XFS_TRANS_LOWMODE (1u << 8)
  125. /* Transaction has locked the rtbitmap and rtsum inodes */
  126. #define XFS_TRANS_RTBITMAP_LOCKED (1u << 9)
  127. /*
  128. * Field values for xfs_trans_mod_sb.
  129. */
  130. #define XFS_TRANS_SB_ICOUNT 0x00000001
  131. #define XFS_TRANS_SB_IFREE 0x00000002
  132. #define XFS_TRANS_SB_FDBLOCKS 0x00000004
  133. #define XFS_TRANS_SB_RES_FDBLOCKS 0x00000008
  134. #define XFS_TRANS_SB_FREXTENTS 0x00000010
  135. #define XFS_TRANS_SB_RES_FREXTENTS 0x00000020
  136. #define XFS_TRANS_SB_DBLOCKS 0x00000040
  137. #define XFS_TRANS_SB_AGCOUNT 0x00000080
  138. #define XFS_TRANS_SB_IMAXPCT 0x00000100
  139. #define XFS_TRANS_SB_REXTSIZE 0x00000200
  140. #define XFS_TRANS_SB_RBMBLOCKS 0x00000400
  141. #define XFS_TRANS_SB_RBLOCKS 0x00000800
  142. #define XFS_TRANS_SB_REXTENTS 0x00001000
  143. #define XFS_TRANS_SB_REXTSLOG 0x00002000
  144. /*
  145. * Here we centralize the specification of XFS meta-data buffer reference count
  146. * values. This determines how hard the buffer cache tries to hold onto the
  147. * buffer.
  148. */
  149. #define XFS_AGF_REF 4
  150. #define XFS_AGI_REF 4
  151. #define XFS_AGFL_REF 3
  152. #define XFS_INO_BTREE_REF 3
  153. #define XFS_ALLOC_BTREE_REF 2
  154. #define XFS_BMAP_BTREE_REF 2
  155. #define XFS_RMAP_BTREE_REF 2
  156. #define XFS_DIR_BTREE_REF 2
  157. #define XFS_INO_REF 2
  158. #define XFS_ATTR_BTREE_REF 1
  159. #define XFS_DQUOT_REF 1
  160. #define XFS_REFC_BTREE_REF 1
  161. #define XFS_SSB_REF 0
  162. /* Computed inode geometry for the filesystem. */
  163. struct xfs_ino_geometry {
  164. /* Maximum inode count in this filesystem. */
  165. uint64_t maxicount;
  166. /* Actual inode cluster buffer size, in bytes. */
  167. unsigned int inode_cluster_size;
  168. /*
  169. * Desired inode cluster buffer size, in bytes. This value is not
  170. * rounded up to at least one filesystem block, which is necessary for
  171. * the sole purpose of validating sb_spino_align. Runtime code must
  172. * only ever use inode_cluster_size.
  173. */
  174. unsigned int inode_cluster_size_raw;
  175. /* Inode cluster sizes, adjusted to be at least 1 fsb. */
  176. unsigned int inodes_per_cluster;
  177. unsigned int blocks_per_cluster;
  178. /* Inode cluster alignment. */
  179. unsigned int cluster_align;
  180. unsigned int cluster_align_inodes;
  181. unsigned int inoalign_mask; /* mask sb_inoalignmt if used */
  182. unsigned int inobt_mxr[2]; /* max inobt btree records */
  183. unsigned int inobt_mnr[2]; /* min inobt btree records */
  184. unsigned int inobt_maxlevels; /* max inobt btree levels. */
  185. /* Size of inode allocations under normal operation. */
  186. unsigned int ialloc_inos;
  187. unsigned int ialloc_blks;
  188. /* Minimum inode blocks for a sparse allocation. */
  189. unsigned int ialloc_min_blks;
  190. /* stripe unit inode alignment */
  191. unsigned int ialloc_align;
  192. unsigned int agino_log; /* #bits for agino in inum */
  193. /* precomputed default inode attribute fork offset */
  194. unsigned int attr_fork_offset;
  195. /* precomputed value for di_flags2 */
  196. uint64_t new_diflags2;
  197. /* minimum folio order of a page cache allocation */
  198. unsigned int min_folio_order;
  199. };
  200. #endif /* __XFS_SHARED_H__ */