xfs_alloc.h 5.7 KB

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