xfs_alloc.h 8.0 KB

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