xfs_alloc.h 9.4 KB

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