xfs_alloc.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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_mount;
  22. struct xfs_perag;
  23. struct xfs_trans;
  24. /*
  25. * Freespace allocation types. Argument to xfs_alloc_[v]extent.
  26. */
  27. typedef enum xfs_alloctype
  28. {
  29. XFS_ALLOCTYPE_ANY_AG, /* allocate anywhere, use rotor */
  30. XFS_ALLOCTYPE_FIRST_AG, /* ... start at ag 0 */
  31. XFS_ALLOCTYPE_START_AG, /* anywhere, start in this a.g. */
  32. XFS_ALLOCTYPE_THIS_AG, /* anywhere in this a.g. */
  33. XFS_ALLOCTYPE_START_BNO, /* near this block else anywhere */
  34. XFS_ALLOCTYPE_NEAR_BNO, /* in this a.g. and near this block */
  35. XFS_ALLOCTYPE_THIS_BNO /* at exactly this block */
  36. } xfs_alloctype_t;
  37. /*
  38. * Flags for xfs_alloc_fix_freelist.
  39. */
  40. #define XFS_ALLOC_FLAG_TRYLOCK 0x00000001 /* use trylock for buffer locking */
  41. #define XFS_ALLOC_FLAG_FREEING 0x00000002 /* indicate caller is freeing extents*/
  42. /*
  43. * Argument structure for xfs_alloc routines.
  44. * This is turned into a structure to avoid having 20 arguments passed
  45. * down several levels of the stack.
  46. */
  47. typedef struct xfs_alloc_arg {
  48. struct xfs_trans *tp; /* transaction pointer */
  49. struct xfs_mount *mp; /* file system mount point */
  50. struct xfs_buf *agbp; /* buffer for a.g. freelist header */
  51. struct xfs_perag *pag; /* per-ag struct for this agno */
  52. xfs_fsblock_t fsbno; /* file system block number */
  53. xfs_agnumber_t agno; /* allocation group number */
  54. xfs_agblock_t agbno; /* allocation group-relative block # */
  55. xfs_extlen_t minlen; /* minimum size of extent */
  56. xfs_extlen_t maxlen; /* maximum size of extent */
  57. xfs_extlen_t mod; /* mod value for extent size */
  58. xfs_extlen_t prod; /* prod value for extent size */
  59. xfs_extlen_t minleft; /* min blocks must be left after us */
  60. xfs_extlen_t total; /* total blocks needed in xaction */
  61. xfs_extlen_t alignment; /* align answer to multiple of this */
  62. xfs_extlen_t minalignslop; /* slop for minlen+alignment calcs */
  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. char wasdel; /* set if allocation was prev delayed */
  67. char wasfromfl; /* set if allocation is from freelist */
  68. char isfl; /* set if is freelist blocks - !acctg */
  69. char userdata; /* set if this is user data */
  70. xfs_fsblock_t firstblock; /* io first block allocated */
  71. } xfs_alloc_arg_t;
  72. /*
  73. * Defines for userdata
  74. */
  75. #define XFS_ALLOC_USERDATA 1 /* allocation is for user data*/
  76. #define XFS_ALLOC_INITIAL_USER_DATA 2 /* special case start of file */
  77. #ifdef __KERNEL__
  78. #if defined(XFS_ALLOC_TRACE)
  79. /*
  80. * Allocation tracing buffer size.
  81. */
  82. #define XFS_ALLOC_TRACE_SIZE 4096
  83. extern ktrace_t *xfs_alloc_trace_buf;
  84. /*
  85. * Types for alloc tracing.
  86. */
  87. #define XFS_ALLOC_KTRACE_ALLOC 1
  88. #define XFS_ALLOC_KTRACE_FREE 2
  89. #define XFS_ALLOC_KTRACE_MODAGF 3
  90. #define XFS_ALLOC_KTRACE_BUSY 4
  91. #define XFS_ALLOC_KTRACE_UNBUSY 5
  92. #define XFS_ALLOC_KTRACE_BUSYSEARCH 6
  93. #endif
  94. /*
  95. * Compute and fill in value of m_ag_maxlevels.
  96. */
  97. void
  98. xfs_alloc_compute_maxlevels(
  99. struct xfs_mount *mp); /* file system mount structure */
  100. /*
  101. * Get a block from the freelist.
  102. * Returns with the buffer for the block gotten.
  103. */
  104. int /* error */
  105. xfs_alloc_get_freelist(
  106. struct xfs_trans *tp, /* transaction pointer */
  107. struct xfs_buf *agbp, /* buffer containing the agf structure */
  108. xfs_agblock_t *bnop); /* block address retrieved from freelist */
  109. /*
  110. * Log the given fields from the agf structure.
  111. */
  112. void
  113. xfs_alloc_log_agf(
  114. struct xfs_trans *tp, /* transaction pointer */
  115. struct xfs_buf *bp, /* buffer for a.g. freelist header */
  116. int fields);/* mask of fields to be logged (XFS_AGF_...) */
  117. /*
  118. * Interface for inode allocation to force the pag data to be initialized.
  119. */
  120. int /* error */
  121. xfs_alloc_pagf_init(
  122. struct xfs_mount *mp, /* file system mount structure */
  123. struct xfs_trans *tp, /* transaction pointer */
  124. xfs_agnumber_t agno, /* allocation group number */
  125. int flags); /* XFS_ALLOC_FLAGS_... */
  126. /*
  127. * Put the block on the freelist for the allocation group.
  128. */
  129. int /* error */
  130. xfs_alloc_put_freelist(
  131. struct xfs_trans *tp, /* transaction pointer */
  132. struct xfs_buf *agbp, /* buffer for a.g. freelist header */
  133. struct xfs_buf *agflbp,/* buffer for a.g. free block array */
  134. xfs_agblock_t bno); /* block being freed */
  135. /*
  136. * Read in the allocation group header (free/alloc section).
  137. */
  138. int /* error */
  139. xfs_alloc_read_agf(
  140. struct xfs_mount *mp, /* mount point structure */
  141. struct xfs_trans *tp, /* transaction pointer */
  142. xfs_agnumber_t agno, /* allocation group number */
  143. int flags, /* XFS_ALLOC_FLAG_... */
  144. struct xfs_buf **bpp); /* buffer for the ag freelist header */
  145. /*
  146. * Allocate an extent (variable-size).
  147. */
  148. int /* error */
  149. xfs_alloc_vextent(
  150. xfs_alloc_arg_t *args); /* allocation argument structure */
  151. /*
  152. * Free an extent.
  153. */
  154. int /* error */
  155. xfs_free_extent(
  156. struct xfs_trans *tp, /* transaction pointer */
  157. xfs_fsblock_t bno, /* starting block number of extent */
  158. xfs_extlen_t len); /* length of extent */
  159. void
  160. xfs_alloc_mark_busy(xfs_trans_t *tp,
  161. xfs_agnumber_t agno,
  162. xfs_agblock_t bno,
  163. xfs_extlen_t len);
  164. void
  165. xfs_alloc_clear_busy(xfs_trans_t *tp,
  166. xfs_agnumber_t ag,
  167. int idx);
  168. #endif /* __KERNEL__ */
  169. #endif /* __XFS_ALLOC_H__ */