xfs_alloc.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. /*
  52. * In order to avoid ENOSPC-related deadlock caused by
  53. * out-of-order locking of AGF buffer (PV 947395), we place
  54. * constraints on the relationship among actual allocations for
  55. * data blocks, freelist blocks, and potential file data bmap
  56. * btree blocks. However, these restrictions may result in no
  57. * actual space allocated for a delayed extent, for example, a data
  58. * block in a certain AG is allocated but there is no additional
  59. * block for the additional bmap btree block due to a split of the
  60. * bmap btree of the file. The result of this may lead to an
  61. * infinite loop in xfssyncd when the file gets flushed to disk and
  62. * all delayed extents need to be actually allocated. To get around
  63. * this, we explicitly set aside a few blocks which will not be
  64. * reserved in delayed allocation. Considering the minimum number of
  65. * needed freelist blocks is 4 fsbs _per AG_, a potential split of file's bmap
  66. * btree requires 1 fsb, so we set the number of set-aside blocks
  67. * to 4 + 4*agcount.
  68. */
  69. #define XFS_ALLOC_SET_ASIDE(mp) (4 + ((mp)->m_sb.sb_agcount * 4))
  70. /*
  71. * When deciding how much space to allocate out of an AG, we limit the
  72. * allocation maximum size to the size the AG. However, we cannot use all the
  73. * blocks in the AG - some are permanently used by metadata. These
  74. * blocks are generally:
  75. * - the AG superblock, AGF, AGI and AGFL
  76. * - the AGF (bno and cnt) and AGI btree root blocks
  77. * - 4 blocks on the AGFL according to XFS_ALLOC_SET_ASIDE() limits
  78. *
  79. * The AG headers are sector sized, so the amount of space they take up is
  80. * dependent on filesystem geometry. The others are all single blocks.
  81. */
  82. #define XFS_ALLOC_AG_MAX_USABLE(mp) \
  83. ((mp)->m_sb.sb_agblocks - XFS_BB_TO_FSB(mp, XFS_FSS_TO_BB(mp, 4)) - 7)
  84. /*
  85. * Argument structure for xfs_alloc routines.
  86. * This is turned into a structure to avoid having 20 arguments passed
  87. * down several levels of the stack.
  88. */
  89. typedef struct xfs_alloc_arg {
  90. struct xfs_trans *tp; /* transaction pointer */
  91. struct xfs_mount *mp; /* file system mount point */
  92. struct xfs_buf *agbp; /* buffer for a.g. freelist header */
  93. struct xfs_perag *pag; /* per-ag struct for this agno */
  94. struct xfs_inode *ip; /* for userdata zeroing method */
  95. xfs_fsblock_t fsbno; /* file system block number */
  96. xfs_agnumber_t agno; /* allocation group number */
  97. xfs_agblock_t agbno; /* allocation group-relative block # */
  98. xfs_extlen_t minlen; /* minimum size of extent */
  99. xfs_extlen_t maxlen; /* maximum size of extent */
  100. xfs_extlen_t mod; /* mod value for extent size */
  101. xfs_extlen_t prod; /* prod value for extent size */
  102. xfs_extlen_t minleft; /* min blocks must be left after us */
  103. xfs_extlen_t total; /* total blocks needed in xaction */
  104. xfs_extlen_t alignment; /* align answer to multiple of this */
  105. xfs_extlen_t minalignslop; /* slop for minlen+alignment calcs */
  106. xfs_agblock_t min_agbno; /* set an agbno range for NEAR allocs */
  107. xfs_agblock_t max_agbno; /* ... */
  108. xfs_extlen_t len; /* output: actual size of extent */
  109. xfs_alloctype_t type; /* allocation type XFS_ALLOCTYPE_... */
  110. xfs_alloctype_t otype; /* original allocation type */
  111. char wasdel; /* set if allocation was prev delayed */
  112. char wasfromfl; /* set if allocation is from freelist */
  113. char isfl; /* set if is freelist blocks - !acctg */
  114. char userdata; /* mask defining userdata treatment */
  115. xfs_fsblock_t firstblock; /* io first block allocated */
  116. } xfs_alloc_arg_t;
  117. /*
  118. * Defines for userdata
  119. */
  120. #define XFS_ALLOC_USERDATA (1 << 0)/* allocation is for user data*/
  121. #define XFS_ALLOC_INITIAL_USER_DATA (1 << 1)/* special case start of file */
  122. #define XFS_ALLOC_USERDATA_ZERO (1 << 2)/* zero extent on allocation */
  123. xfs_extlen_t xfs_alloc_longest_free_extent(struct xfs_mount *mp,
  124. struct xfs_perag *pag, xfs_extlen_t need);
  125. unsigned int xfs_alloc_min_freelist(struct xfs_mount *mp,
  126. struct xfs_perag *pag);
  127. /*
  128. * Compute and fill in value of m_ag_maxlevels.
  129. */
  130. void
  131. xfs_alloc_compute_maxlevels(
  132. struct xfs_mount *mp); /* file system mount structure */
  133. /*
  134. * Get a block from the freelist.
  135. * Returns with the buffer for the block gotten.
  136. */
  137. int /* error */
  138. xfs_alloc_get_freelist(
  139. struct xfs_trans *tp, /* transaction pointer */
  140. struct xfs_buf *agbp, /* buffer containing the agf structure */
  141. xfs_agblock_t *bnop, /* block address retrieved from freelist */
  142. int btreeblk); /* destination is a AGF btree */
  143. /*
  144. * Log the given fields from the agf structure.
  145. */
  146. void
  147. xfs_alloc_log_agf(
  148. struct xfs_trans *tp, /* transaction pointer */
  149. struct xfs_buf *bp, /* buffer for a.g. freelist header */
  150. int fields);/* mask of fields to be logged (XFS_AGF_...) */
  151. /*
  152. * Interface for inode allocation to force the pag data to be initialized.
  153. */
  154. int /* error */
  155. xfs_alloc_pagf_init(
  156. struct xfs_mount *mp, /* file system mount structure */
  157. struct xfs_trans *tp, /* transaction pointer */
  158. xfs_agnumber_t agno, /* allocation group number */
  159. int flags); /* XFS_ALLOC_FLAGS_... */
  160. /*
  161. * Put the block on the freelist for the allocation group.
  162. */
  163. int /* error */
  164. xfs_alloc_put_freelist(
  165. struct xfs_trans *tp, /* transaction pointer */
  166. struct xfs_buf *agbp, /* buffer for a.g. freelist header */
  167. struct xfs_buf *agflbp,/* buffer for a.g. free block array */
  168. xfs_agblock_t bno, /* block being freed */
  169. int btreeblk); /* owner was a AGF btree */
  170. /*
  171. * Read in the allocation group header (free/alloc section).
  172. */
  173. int /* error */
  174. xfs_alloc_read_agf(
  175. struct xfs_mount *mp, /* mount point structure */
  176. struct xfs_trans *tp, /* transaction pointer */
  177. xfs_agnumber_t agno, /* allocation group number */
  178. int flags, /* XFS_ALLOC_FLAG_... */
  179. struct xfs_buf **bpp); /* buffer for the ag freelist header */
  180. /*
  181. * Allocate an extent (variable-size).
  182. */
  183. int /* error */
  184. xfs_alloc_vextent(
  185. xfs_alloc_arg_t *args); /* allocation argument structure */
  186. /*
  187. * Free an extent.
  188. */
  189. int /* error */
  190. xfs_free_extent(
  191. struct xfs_trans *tp, /* transaction pointer */
  192. xfs_fsblock_t bno, /* starting block number of extent */
  193. xfs_extlen_t len); /* length of extent */
  194. int /* error */
  195. xfs_alloc_lookup_le(
  196. struct xfs_btree_cur *cur, /* btree cursor */
  197. xfs_agblock_t bno, /* starting block of extent */
  198. xfs_extlen_t len, /* length of extent */
  199. int *stat); /* success/failure */
  200. int /* error */
  201. xfs_alloc_lookup_ge(
  202. struct xfs_btree_cur *cur, /* btree cursor */
  203. xfs_agblock_t bno, /* starting block of extent */
  204. xfs_extlen_t len, /* length of extent */
  205. int *stat); /* success/failure */
  206. int /* error */
  207. xfs_alloc_get_rec(
  208. struct xfs_btree_cur *cur, /* btree cursor */
  209. xfs_agblock_t *bno, /* output: starting block of extent */
  210. xfs_extlen_t *len, /* output: length of extent */
  211. int *stat); /* output: success/failure */
  212. int xfs_read_agf(struct xfs_mount *mp, struct xfs_trans *tp,
  213. xfs_agnumber_t agno, int flags, struct xfs_buf **bpp);
  214. #endif /* __XFS_ALLOC_H__ */