xfs_alloc.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
  4. * All Rights Reserved.
  5. */
  6. #ifndef __XFS_ALLOC_H__
  7. #define __XFS_ALLOC_H__
  8. struct xfs_buf;
  9. struct xfs_btree_cur;
  10. struct xfs_mount;
  11. struct xfs_perag;
  12. struct xfs_trans;
  13. extern struct workqueue_struct *xfs_alloc_wq;
  14. unsigned int xfs_agfl_size(struct xfs_mount *mp);
  15. /*
  16. * Freespace allocation types. Argument to xfs_alloc_[v]extent.
  17. */
  18. #define XFS_ALLOCTYPE_FIRST_AG 0x02 /* ... start at ag 0 */
  19. #define XFS_ALLOCTYPE_THIS_AG 0x08 /* anywhere in this a.g. */
  20. #define XFS_ALLOCTYPE_START_BNO 0x10 /* near this block else anywhere */
  21. #define XFS_ALLOCTYPE_NEAR_BNO 0x20 /* in this a.g. and near this block */
  22. #define XFS_ALLOCTYPE_THIS_BNO 0x40 /* at exactly this block */
  23. /* this should become an enum again when the tracing code is fixed */
  24. typedef unsigned int xfs_alloctype_t;
  25. #define XFS_ALLOC_TYPES \
  26. { XFS_ALLOCTYPE_FIRST_AG, "FIRST_AG" }, \
  27. { XFS_ALLOCTYPE_THIS_AG, "THIS_AG" }, \
  28. { XFS_ALLOCTYPE_START_BNO, "START_BNO" }, \
  29. { XFS_ALLOCTYPE_NEAR_BNO, "NEAR_BNO" }, \
  30. { XFS_ALLOCTYPE_THIS_BNO, "THIS_BNO" }
  31. /*
  32. * Flags for xfs_alloc_fix_freelist.
  33. */
  34. #define XFS_ALLOC_FLAG_TRYLOCK 0x00000001 /* use trylock for buffer locking */
  35. #define XFS_ALLOC_FLAG_FREEING 0x00000002 /* indicate caller is freeing extents*/
  36. #define XFS_ALLOC_FLAG_NORMAP 0x00000004 /* don't modify the rmapbt */
  37. #define XFS_ALLOC_FLAG_NOSHRINK 0x00000008 /* don't shrink the freelist */
  38. #define XFS_ALLOC_FLAG_CHECK 0x00000010 /* test only, don't modify args */
  39. /*
  40. * Argument structure for xfs_alloc routines.
  41. * This is turned into a structure to avoid having 20 arguments passed
  42. * down several levels of the stack.
  43. */
  44. typedef struct xfs_alloc_arg {
  45. struct xfs_trans *tp; /* transaction pointer */
  46. struct xfs_mount *mp; /* file system mount point */
  47. struct xfs_buf *agbp; /* buffer for a.g. freelist header */
  48. struct xfs_perag *pag; /* per-ag struct for this agno */
  49. struct xfs_inode *ip; /* for userdata zeroing method */
  50. xfs_fsblock_t fsbno; /* file system block number */
  51. xfs_agnumber_t agno; /* allocation group number */
  52. xfs_agblock_t agbno; /* allocation group-relative block # */
  53. xfs_extlen_t minlen; /* minimum size of extent */
  54. xfs_extlen_t maxlen; /* maximum size of extent */
  55. xfs_extlen_t mod; /* mod value for extent size */
  56. xfs_extlen_t prod; /* prod value for extent size */
  57. xfs_extlen_t minleft; /* min blocks must be left after us */
  58. xfs_extlen_t total; /* total blocks needed in xaction */
  59. xfs_extlen_t alignment; /* align answer to multiple of this */
  60. xfs_extlen_t minalignslop; /* slop for minlen+alignment calcs */
  61. xfs_agblock_t min_agbno; /* set an agbno range for NEAR allocs */
  62. xfs_agblock_t max_agbno; /* ... */
  63. xfs_extlen_t len; /* output: actual size of extent */
  64. xfs_alloctype_t type; /* allocation type XFS_ALLOCTYPE_... */
  65. xfs_alloctype_t otype; /* original allocation type */
  66. int datatype; /* mask defining data type treatment */
  67. char wasdel; /* set if allocation was prev delayed */
  68. char wasfromfl; /* set if allocation is from freelist */
  69. xfs_fsblock_t firstblock; /* io first block allocated */
  70. struct xfs_owner_info oinfo; /* owner of blocks being allocated */
  71. enum xfs_ag_resv_type resv; /* block reservation to use */
  72. } xfs_alloc_arg_t;
  73. /*
  74. * Defines for datatype
  75. */
  76. #define XFS_ALLOC_USERDATA (1 << 0)/* allocation is for user data*/
  77. #define XFS_ALLOC_INITIAL_USER_DATA (1 << 1)/* special case start of file */
  78. #define XFS_ALLOC_USERDATA_ZERO (1 << 2)/* zero extent on allocation */
  79. #define XFS_ALLOC_NOBUSY (1 << 3)/* Busy extents not allowed */
  80. static inline bool
  81. xfs_alloc_is_userdata(int datatype)
  82. {
  83. return (datatype & ~XFS_ALLOC_NOBUSY) != 0;
  84. }
  85. static inline bool
  86. xfs_alloc_allow_busy_reuse(int datatype)
  87. {
  88. return (datatype & XFS_ALLOC_NOBUSY) == 0;
  89. }
  90. /* freespace limit calculations */
  91. #define XFS_ALLOC_AGFL_RESERVE 4
  92. unsigned int xfs_alloc_set_aside(struct xfs_mount *mp);
  93. unsigned int xfs_alloc_ag_max_usable(struct xfs_mount *mp);
  94. xfs_extlen_t xfs_alloc_longest_free_extent(struct xfs_perag *pag,
  95. xfs_extlen_t need, xfs_extlen_t reserved);
  96. unsigned int xfs_alloc_min_freelist(struct xfs_mount *mp,
  97. struct xfs_perag *pag);
  98. /*
  99. * Compute and fill in value of m_ag_maxlevels.
  100. */
  101. void
  102. xfs_alloc_compute_maxlevels(
  103. struct xfs_mount *mp); /* file system mount structure */
  104. /*
  105. * Get a block from the freelist.
  106. * Returns with the buffer for the block gotten.
  107. */
  108. int /* error */
  109. xfs_alloc_get_freelist(
  110. struct xfs_trans *tp, /* transaction pointer */
  111. struct xfs_buf *agbp, /* buffer containing the agf structure */
  112. xfs_agblock_t *bnop, /* block address retrieved from freelist */
  113. int btreeblk); /* destination is a AGF btree */
  114. /*
  115. * Log the given fields from the agf structure.
  116. */
  117. void
  118. xfs_alloc_log_agf(
  119. struct xfs_trans *tp, /* transaction pointer */
  120. struct xfs_buf *bp, /* buffer for a.g. freelist header */
  121. int fields);/* mask of fields to be logged (XFS_AGF_...) */
  122. /*
  123. * Interface for inode allocation to force the pag data to be initialized.
  124. */
  125. int /* error */
  126. xfs_alloc_pagf_init(
  127. struct xfs_mount *mp, /* file system mount structure */
  128. struct xfs_trans *tp, /* transaction pointer */
  129. xfs_agnumber_t agno, /* allocation group number */
  130. int flags); /* XFS_ALLOC_FLAGS_... */
  131. /*
  132. * Put the block on the freelist for the allocation group.
  133. */
  134. int /* error */
  135. xfs_alloc_put_freelist(
  136. struct xfs_trans *tp, /* transaction pointer */
  137. struct xfs_buf *agbp, /* buffer for a.g. freelist header */
  138. struct xfs_buf *agflbp,/* buffer for a.g. free block array */
  139. xfs_agblock_t bno, /* block being freed */
  140. int btreeblk); /* owner was a AGF btree */
  141. /*
  142. * Read in the allocation group header (free/alloc section).
  143. */
  144. int /* error */
  145. xfs_alloc_read_agf(
  146. struct xfs_mount *mp, /* mount point structure */
  147. struct xfs_trans *tp, /* transaction pointer */
  148. xfs_agnumber_t agno, /* allocation group number */
  149. int flags, /* XFS_ALLOC_FLAG_... */
  150. struct xfs_buf **bpp); /* buffer for the ag freelist header */
  151. /*
  152. * Allocate an extent (variable-size).
  153. */
  154. int /* error */
  155. xfs_alloc_vextent(
  156. xfs_alloc_arg_t *args); /* allocation argument structure */
  157. /*
  158. * Free an extent.
  159. */
  160. int /* error */
  161. __xfs_free_extent(
  162. struct xfs_trans *tp, /* transaction pointer */
  163. xfs_fsblock_t bno, /* starting block number of extent */
  164. xfs_extlen_t len, /* length of extent */
  165. struct xfs_owner_info *oinfo, /* extent owner */
  166. enum xfs_ag_resv_type type, /* block reservation type */
  167. bool skip_discard);
  168. static inline int
  169. xfs_free_extent(
  170. struct xfs_trans *tp,
  171. xfs_fsblock_t bno,
  172. xfs_extlen_t len,
  173. struct xfs_owner_info *oinfo,
  174. enum xfs_ag_resv_type type)
  175. {
  176. return __xfs_free_extent(tp, bno, len, oinfo, type, false);
  177. }
  178. int /* error */
  179. xfs_alloc_lookup_le(
  180. struct xfs_btree_cur *cur, /* btree cursor */
  181. xfs_agblock_t bno, /* starting block of extent */
  182. xfs_extlen_t len, /* length of extent */
  183. int *stat); /* success/failure */
  184. int /* error */
  185. xfs_alloc_lookup_ge(
  186. struct xfs_btree_cur *cur, /* btree cursor */
  187. xfs_agblock_t bno, /* starting block of extent */
  188. xfs_extlen_t len, /* length of extent */
  189. int *stat); /* success/failure */
  190. int /* error */
  191. xfs_alloc_get_rec(
  192. struct xfs_btree_cur *cur, /* btree cursor */
  193. xfs_agblock_t *bno, /* output: starting block of extent */
  194. xfs_extlen_t *len, /* output: length of extent */
  195. int *stat); /* output: success/failure */
  196. int xfs_read_agf(struct xfs_mount *mp, struct xfs_trans *tp,
  197. xfs_agnumber_t agno, int flags, struct xfs_buf **bpp);
  198. int xfs_alloc_read_agfl(struct xfs_mount *mp, struct xfs_trans *tp,
  199. xfs_agnumber_t agno, struct xfs_buf **bpp);
  200. int xfs_free_agfl_block(struct xfs_trans *, xfs_agnumber_t, xfs_agblock_t,
  201. struct xfs_buf *, struct xfs_owner_info *);
  202. int xfs_alloc_fix_freelist(struct xfs_alloc_arg *args, int flags);
  203. int xfs_free_extent_fix_freelist(struct xfs_trans *tp, xfs_agnumber_t agno,
  204. struct xfs_buf **agbp);
  205. xfs_extlen_t xfs_prealloc_blocks(struct xfs_mount *mp);
  206. typedef int (*xfs_alloc_query_range_fn)(
  207. struct xfs_btree_cur *cur,
  208. struct xfs_alloc_rec_incore *rec,
  209. void *priv);
  210. int xfs_alloc_query_range(struct xfs_btree_cur *cur,
  211. struct xfs_alloc_rec_incore *low_rec,
  212. struct xfs_alloc_rec_incore *high_rec,
  213. xfs_alloc_query_range_fn fn, void *priv);
  214. int xfs_alloc_query_all(struct xfs_btree_cur *cur, xfs_alloc_query_range_fn fn,
  215. void *priv);
  216. int xfs_alloc_has_record(struct xfs_btree_cur *cur, xfs_agblock_t bno,
  217. xfs_extlen_t len, bool *exist);
  218. typedef int (*xfs_agfl_walk_fn)(struct xfs_mount *mp, xfs_agblock_t bno,
  219. void *priv);
  220. int xfs_agfl_walk(struct xfs_mount *mp, struct xfs_agf *agf,
  221. struct xfs_buf *agflbp, xfs_agfl_walk_fn walk_fn, void *priv);
  222. #endif /* __XFS_ALLOC_H__ */