xfs_alloc.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of version 2 of the GNU General Public License as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it would be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *
  12. * Further, this software is distributed without any warranty that it is
  13. * free of the rightful claim of any third person regarding infringement
  14. * or the like. Any license provided herein, whether implied or
  15. * otherwise, applies only to this software file. Patent licenses, if
  16. * any, provided herein do not apply to combinations of this program with
  17. * other software, or any other product whatsoever.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write the Free Software Foundation, Inc., 59
  21. * Temple Place - Suite 330, Boston MA 02111-1307, USA.
  22. *
  23. * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
  24. * Mountain View, CA 94043, or:
  25. *
  26. * http://www.sgi.com
  27. *
  28. * For further information regarding this notice, see:
  29. *
  30. * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
  31. */
  32. #ifndef __XFS_ALLOC_H__
  33. #define __XFS_ALLOC_H__
  34. struct xfs_buf;
  35. struct xfs_mount;
  36. struct xfs_perag;
  37. struct xfs_trans;
  38. /*
  39. * Freespace allocation types. Argument to xfs_alloc_[v]extent.
  40. */
  41. typedef enum xfs_alloctype
  42. {
  43. XFS_ALLOCTYPE_ANY_AG, /* allocate anywhere, use rotor */
  44. XFS_ALLOCTYPE_FIRST_AG, /* ... start at ag 0 */
  45. XFS_ALLOCTYPE_START_AG, /* anywhere, start in this a.g. */
  46. XFS_ALLOCTYPE_THIS_AG, /* anywhere in this a.g. */
  47. XFS_ALLOCTYPE_START_BNO, /* near this block else anywhere */
  48. XFS_ALLOCTYPE_NEAR_BNO, /* in this a.g. and near this block */
  49. XFS_ALLOCTYPE_THIS_BNO /* at exactly this block */
  50. } xfs_alloctype_t;
  51. /*
  52. * Flags for xfs_alloc_fix_freelist.
  53. */
  54. #define XFS_ALLOC_FLAG_TRYLOCK 0x00000001 /* use trylock for buffer locking */
  55. /*
  56. * Argument structure for xfs_alloc routines.
  57. * This is turned into a structure to avoid having 20 arguments passed
  58. * down several levels of the stack.
  59. */
  60. typedef struct xfs_alloc_arg {
  61. struct xfs_trans *tp; /* transaction pointer */
  62. struct xfs_mount *mp; /* file system mount point */
  63. struct xfs_buf *agbp; /* buffer for a.g. freelist header */
  64. struct xfs_perag *pag; /* per-ag struct for this agno */
  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_extlen_t len; /* output: actual size of extent */
  77. xfs_alloctype_t type; /* allocation type XFS_ALLOCTYPE_... */
  78. xfs_alloctype_t otype; /* original allocation type */
  79. char wasdel; /* set if allocation was prev delayed */
  80. char wasfromfl; /* set if allocation is from freelist */
  81. char isfl; /* set if is freelist blocks - !actg */
  82. char userdata; /* set if this is user data */
  83. } xfs_alloc_arg_t;
  84. /*
  85. * Defines for userdata
  86. */
  87. #define XFS_ALLOC_USERDATA 1 /* allocation is for user data*/
  88. #define XFS_ALLOC_INITIAL_USER_DATA 2 /* special case start of file */
  89. #ifdef __KERNEL__
  90. #if defined(XFS_ALLOC_TRACE)
  91. /*
  92. * Allocation tracing buffer size.
  93. */
  94. #define XFS_ALLOC_TRACE_SIZE 4096
  95. extern ktrace_t *xfs_alloc_trace_buf;
  96. /*
  97. * Types for alloc tracing.
  98. */
  99. #define XFS_ALLOC_KTRACE_ALLOC 1
  100. #define XFS_ALLOC_KTRACE_FREE 2
  101. #define XFS_ALLOC_KTRACE_MODAGF 3
  102. #define XFS_ALLOC_KTRACE_BUSY 4
  103. #define XFS_ALLOC_KTRACE_UNBUSY 5
  104. #define XFS_ALLOC_KTRACE_BUSYSEARCH 6
  105. #endif
  106. /*
  107. * Compute and fill in value of m_ag_maxlevels.
  108. */
  109. void
  110. xfs_alloc_compute_maxlevels(
  111. struct xfs_mount *mp); /* file system mount structure */
  112. /*
  113. * Get a block from the freelist.
  114. * Returns with the buffer for the block gotten.
  115. */
  116. int /* error */
  117. xfs_alloc_get_freelist(
  118. struct xfs_trans *tp, /* transaction pointer */
  119. struct xfs_buf *agbp, /* buffer containing the agf structure */
  120. xfs_agblock_t *bnop); /* block address retrieved from freelist */
  121. /*
  122. * Log the given fields from the agf structure.
  123. */
  124. void
  125. xfs_alloc_log_agf(
  126. struct xfs_trans *tp, /* transaction pointer */
  127. struct xfs_buf *bp, /* buffer for a.g. freelist header */
  128. int fields);/* mask of fields to be logged (XFS_AGF_...) */
  129. /*
  130. * Interface for inode allocation to force the pag data to be initialized.
  131. */
  132. int /* error */
  133. xfs_alloc_pagf_init(
  134. struct xfs_mount *mp, /* file system mount structure */
  135. struct xfs_trans *tp, /* transaction pointer */
  136. xfs_agnumber_t agno, /* allocation group number */
  137. int flags); /* XFS_ALLOC_FLAGS_... */
  138. /*
  139. * Put the block on the freelist for the allocation group.
  140. */
  141. int /* error */
  142. xfs_alloc_put_freelist(
  143. struct xfs_trans *tp, /* transaction pointer */
  144. struct xfs_buf *agbp, /* buffer for a.g. freelist header */
  145. struct xfs_buf *agflbp,/* buffer for a.g. free block array */
  146. xfs_agblock_t bno); /* block being freed */
  147. /*
  148. * Read in the allocation group header (free/alloc section).
  149. */
  150. int /* error */
  151. xfs_alloc_read_agf(
  152. struct xfs_mount *mp, /* mount point structure */
  153. struct xfs_trans *tp, /* transaction pointer */
  154. xfs_agnumber_t agno, /* allocation group number */
  155. int flags, /* XFS_ALLOC_FLAG_... */
  156. struct xfs_buf **bpp); /* buffer for the ag freelist header */
  157. /*
  158. * Allocate an extent (variable-size).
  159. */
  160. int /* error */
  161. xfs_alloc_vextent(
  162. xfs_alloc_arg_t *args); /* allocation argument structure */
  163. /*
  164. * Free an extent.
  165. */
  166. int /* error */
  167. xfs_free_extent(
  168. struct xfs_trans *tp, /* transaction pointer */
  169. xfs_fsblock_t bno, /* starting block number of extent */
  170. xfs_extlen_t len); /* length of extent */
  171. void
  172. xfs_alloc_mark_busy(xfs_trans_t *tp,
  173. xfs_agnumber_t agno,
  174. xfs_agblock_t bno,
  175. xfs_extlen_t len);
  176. void
  177. xfs_alloc_clear_busy(xfs_trans_t *tp,
  178. xfs_agnumber_t ag,
  179. int idx);
  180. #endif /* __KERNEL__ */
  181. #endif /* __XFS_ALLOC_H__ */