xfs_ag.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /*
  2. * Copyright (c) 2000-2003 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_AG_H__
  33. #define __XFS_AG_H__
  34. /*
  35. * Allocation group header
  36. * This is divided into three structures, placed in sequential 512-byte
  37. * buffers after a copy of the superblock (also in a 512-byte buffer).
  38. */
  39. struct xfs_buf;
  40. struct xfs_mount;
  41. struct xfs_trans;
  42. #define XFS_AGF_MAGIC 0x58414746 /* 'XAGF' */
  43. #define XFS_AGI_MAGIC 0x58414749 /* 'XAGI' */
  44. #define XFS_AGF_VERSION 1
  45. #define XFS_AGI_VERSION 1
  46. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGF_GOOD_VERSION)
  47. int xfs_agf_good_version(unsigned v);
  48. #define XFS_AGF_GOOD_VERSION(v) xfs_agf_good_version(v)
  49. #else
  50. #define XFS_AGF_GOOD_VERSION(v) ((v) == XFS_AGF_VERSION)
  51. #endif
  52. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGI_GOOD_VERSION)
  53. int xfs_agi_good_version(unsigned v);
  54. #define XFS_AGI_GOOD_VERSION(v) xfs_agi_good_version(v)
  55. #else
  56. #define XFS_AGI_GOOD_VERSION(v) ((v) == XFS_AGI_VERSION)
  57. #endif
  58. /*
  59. * Btree number 0 is bno, 1 is cnt. This value gives the size of the
  60. * arrays below.
  61. */
  62. #define XFS_BTNUM_AGF ((int)XFS_BTNUM_CNTi + 1)
  63. /*
  64. * The second word of agf_levels in the first a.g. overlaps the EFS
  65. * superblock's magic number. Since the magic numbers valid for EFS
  66. * are > 64k, our value cannot be confused for an EFS superblock's.
  67. */
  68. typedef struct xfs_agf
  69. {
  70. /*
  71. * Common allocation group header information
  72. */
  73. __uint32_t agf_magicnum; /* magic number == XFS_AGF_MAGIC */
  74. __uint32_t agf_versionnum; /* header version == XFS_AGF_VERSION */
  75. xfs_agnumber_t agf_seqno; /* sequence # starting from 0 */
  76. xfs_agblock_t agf_length; /* size in blocks of a.g. */
  77. /*
  78. * Freespace information
  79. */
  80. xfs_agblock_t agf_roots[XFS_BTNUM_AGF]; /* root blocks */
  81. __uint32_t agf_spare0; /* spare field */
  82. __uint32_t agf_levels[XFS_BTNUM_AGF]; /* btree levels */
  83. __uint32_t agf_spare1; /* spare field */
  84. __uint32_t agf_flfirst; /* first freelist block's index */
  85. __uint32_t agf_fllast; /* last freelist block's index */
  86. __uint32_t agf_flcount; /* count of blocks in freelist */
  87. xfs_extlen_t agf_freeblks; /* total free blocks */
  88. xfs_extlen_t agf_longest; /* longest free space */
  89. } xfs_agf_t;
  90. #define XFS_AGF_MAGICNUM 0x00000001
  91. #define XFS_AGF_VERSIONNUM 0x00000002
  92. #define XFS_AGF_SEQNO 0x00000004
  93. #define XFS_AGF_LENGTH 0x00000008
  94. #define XFS_AGF_ROOTS 0x00000010
  95. #define XFS_AGF_LEVELS 0x00000020
  96. #define XFS_AGF_FLFIRST 0x00000040
  97. #define XFS_AGF_FLLAST 0x00000080
  98. #define XFS_AGF_FLCOUNT 0x00000100
  99. #define XFS_AGF_FREEBLKS 0x00000200
  100. #define XFS_AGF_LONGEST 0x00000400
  101. #define XFS_AGF_NUM_BITS 11
  102. #define XFS_AGF_ALL_BITS ((1 << XFS_AGF_NUM_BITS) - 1)
  103. /* disk block (xfs_daddr_t) in the AG */
  104. #define XFS_AGF_DADDR(mp) ((xfs_daddr_t)(1 << (mp)->m_sectbb_log))
  105. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGF_BLOCK)
  106. xfs_agblock_t xfs_agf_block(struct xfs_mount *mp);
  107. #define XFS_AGF_BLOCK(mp) xfs_agf_block(mp)
  108. #else
  109. #define XFS_AGF_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGF_DADDR(mp))
  110. #endif
  111. /*
  112. * Size of the unlinked inode hash table in the agi.
  113. */
  114. #define XFS_AGI_UNLINKED_BUCKETS 64
  115. typedef struct xfs_agi
  116. {
  117. /*
  118. * Common allocation group header information
  119. */
  120. __uint32_t agi_magicnum; /* magic number == XFS_AGI_MAGIC */
  121. __uint32_t agi_versionnum; /* header version == XFS_AGI_VERSION */
  122. xfs_agnumber_t agi_seqno; /* sequence # starting from 0 */
  123. xfs_agblock_t agi_length; /* size in blocks of a.g. */
  124. /*
  125. * Inode information
  126. * Inodes are mapped by interpreting the inode number, so no
  127. * mapping data is needed here.
  128. */
  129. xfs_agino_t agi_count; /* count of allocated inodes */
  130. xfs_agblock_t agi_root; /* root of inode btree */
  131. __uint32_t agi_level; /* levels in inode btree */
  132. xfs_agino_t agi_freecount; /* number of free inodes */
  133. xfs_agino_t agi_newino; /* new inode just allocated */
  134. xfs_agino_t agi_dirino; /* last directory inode chunk */
  135. /*
  136. * Hash table of inodes which have been unlinked but are
  137. * still being referenced.
  138. */
  139. xfs_agino_t agi_unlinked[XFS_AGI_UNLINKED_BUCKETS];
  140. } xfs_agi_t;
  141. #define XFS_AGI_MAGICNUM 0x00000001
  142. #define XFS_AGI_VERSIONNUM 0x00000002
  143. #define XFS_AGI_SEQNO 0x00000004
  144. #define XFS_AGI_LENGTH 0x00000008
  145. #define XFS_AGI_COUNT 0x00000010
  146. #define XFS_AGI_ROOT 0x00000020
  147. #define XFS_AGI_LEVEL 0x00000040
  148. #define XFS_AGI_FREECOUNT 0x00000080
  149. #define XFS_AGI_NEWINO 0x00000100
  150. #define XFS_AGI_DIRINO 0x00000200
  151. #define XFS_AGI_UNLINKED 0x00000400
  152. #define XFS_AGI_NUM_BITS 11
  153. #define XFS_AGI_ALL_BITS ((1 << XFS_AGI_NUM_BITS) - 1)
  154. /* disk block (xfs_daddr_t) in the AG */
  155. #define XFS_AGI_DADDR(mp) ((xfs_daddr_t)(2 << (mp)->m_sectbb_log))
  156. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGI_BLOCK)
  157. xfs_agblock_t xfs_agi_block(struct xfs_mount *mp);
  158. #define XFS_AGI_BLOCK(mp) xfs_agi_block(mp)
  159. #else
  160. #define XFS_AGI_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGI_DADDR(mp))
  161. #endif
  162. /*
  163. * The third a.g. block contains the a.g. freelist, an array
  164. * of block pointers to blocks owned by the allocation btree code.
  165. */
  166. #define XFS_AGFL_DADDR(mp) ((xfs_daddr_t)(3 << (mp)->m_sectbb_log))
  167. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGFL_BLOCK)
  168. xfs_agblock_t xfs_agfl_block(struct xfs_mount *mp);
  169. #define XFS_AGFL_BLOCK(mp) xfs_agfl_block(mp)
  170. #else
  171. #define XFS_AGFL_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGFL_DADDR(mp))
  172. #endif
  173. #define XFS_AGFL_SIZE(mp) ((mp)->m_sb.sb_sectsize / sizeof(xfs_agblock_t))
  174. typedef struct xfs_agfl {
  175. xfs_agblock_t agfl_bno[1]; /* actually XFS_AGFL_SIZE(mp) */
  176. } xfs_agfl_t;
  177. /*
  178. * Busy block/extent entry. Used in perag to mark blocks that have been freed
  179. * but whose transactions aren't committed to disk yet.
  180. */
  181. typedef struct xfs_perag_busy {
  182. xfs_agblock_t busy_start;
  183. xfs_extlen_t busy_length;
  184. struct xfs_trans *busy_tp; /* transaction that did the free */
  185. } xfs_perag_busy_t;
  186. /*
  187. * Per-ag incore structure, copies of information in agf and agi,
  188. * to improve the performance of allocation group selection.
  189. *
  190. * pick sizes which fit in allocation buckets well
  191. */
  192. #if (BITS_PER_LONG == 32)
  193. #define XFS_PAGB_NUM_SLOTS 84
  194. #elif (BITS_PER_LONG == 64)
  195. #define XFS_PAGB_NUM_SLOTS 128
  196. #endif
  197. typedef struct xfs_perag
  198. {
  199. char pagf_init; /* this agf's entry is initialized */
  200. char pagi_init; /* this agi's entry is initialized */
  201. char pagf_metadata; /* the agf is prefered to be metadata */
  202. char pagi_inodeok; /* The agi is ok for inodes */
  203. __uint8_t pagf_levels[XFS_BTNUM_AGF];
  204. /* # of levels in bno & cnt btree */
  205. __uint32_t pagf_flcount; /* count of blocks in freelist */
  206. xfs_extlen_t pagf_freeblks; /* total free blocks */
  207. xfs_extlen_t pagf_longest; /* longest free space */
  208. xfs_agino_t pagi_freecount; /* number of free inodes */
  209. #ifdef __KERNEL__
  210. lock_t pagb_lock; /* lock for pagb_list */
  211. #endif
  212. int pagb_count; /* pagb slots in use */
  213. xfs_perag_busy_t *pagb_list; /* unstable blocks */
  214. } xfs_perag_t;
  215. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AG_MAXLEVELS)
  216. int xfs_ag_maxlevels(struct xfs_mount *mp);
  217. #define XFS_AG_MAXLEVELS(mp) xfs_ag_maxlevels(mp)
  218. #else
  219. #define XFS_AG_MAXLEVELS(mp) ((mp)->m_ag_maxlevels)
  220. #endif
  221. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_MIN_FREELIST)
  222. int xfs_min_freelist(xfs_agf_t *a, struct xfs_mount *mp);
  223. #define XFS_MIN_FREELIST(a,mp) xfs_min_freelist(a,mp)
  224. #else
  225. #define XFS_MIN_FREELIST(a,mp) \
  226. XFS_MIN_FREELIST_RAW( \
  227. INT_GET((a)->agf_levels[XFS_BTNUM_BNOi], ARCH_CONVERT), \
  228. INT_GET((a)->agf_levels[XFS_BTNUM_CNTi], ARCH_CONVERT), mp)
  229. #endif
  230. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_MIN_FREELIST_PAG)
  231. int xfs_min_freelist_pag(xfs_perag_t *pag, struct xfs_mount *mp);
  232. #define XFS_MIN_FREELIST_PAG(pag,mp) xfs_min_freelist_pag(pag,mp)
  233. #else
  234. #define XFS_MIN_FREELIST_PAG(pag,mp) \
  235. XFS_MIN_FREELIST_RAW((uint_t)(pag)->pagf_levels[XFS_BTNUM_BNOi], \
  236. (uint_t)(pag)->pagf_levels[XFS_BTNUM_CNTi], mp)
  237. #endif
  238. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_MIN_FREELIST_RAW)
  239. int xfs_min_freelist_raw(int bl, int cl, struct xfs_mount *mp);
  240. #define XFS_MIN_FREELIST_RAW(bl,cl,mp) xfs_min_freelist_raw(bl,cl,mp)
  241. #else
  242. #define XFS_MIN_FREELIST_RAW(bl,cl,mp) \
  243. (MIN(bl + 1, XFS_AG_MAXLEVELS(mp)) + \
  244. MIN(cl + 1, XFS_AG_MAXLEVELS(mp)))
  245. #endif
  246. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGB_TO_FSB)
  247. xfs_fsblock_t xfs_agb_to_fsb(struct xfs_mount *mp, xfs_agnumber_t agno,
  248. xfs_agblock_t agbno);
  249. #define XFS_AGB_TO_FSB(mp,agno,agbno) xfs_agb_to_fsb(mp,agno,agbno)
  250. #else
  251. #define XFS_AGB_TO_FSB(mp,agno,agbno) \
  252. (((xfs_fsblock_t)(agno) << (mp)->m_sb.sb_agblklog) | (agbno))
  253. #endif
  254. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FSB_TO_AGNO)
  255. xfs_agnumber_t xfs_fsb_to_agno(struct xfs_mount *mp, xfs_fsblock_t fsbno);
  256. #define XFS_FSB_TO_AGNO(mp,fsbno) xfs_fsb_to_agno(mp,fsbno)
  257. #else
  258. #define XFS_FSB_TO_AGNO(mp,fsbno) \
  259. ((xfs_agnumber_t)((fsbno) >> (mp)->m_sb.sb_agblklog))
  260. #endif
  261. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_FSB_TO_AGBNO)
  262. xfs_agblock_t xfs_fsb_to_agbno(struct xfs_mount *mp, xfs_fsblock_t fsbno);
  263. #define XFS_FSB_TO_AGBNO(mp,fsbno) xfs_fsb_to_agbno(mp,fsbno)
  264. #else
  265. #define XFS_FSB_TO_AGBNO(mp,fsbno) \
  266. ((xfs_agblock_t)((fsbno) & XFS_MASK32LO((mp)->m_sb.sb_agblklog)))
  267. #endif
  268. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AGB_TO_DADDR)
  269. xfs_daddr_t xfs_agb_to_daddr(struct xfs_mount *mp, xfs_agnumber_t agno,
  270. xfs_agblock_t agbno);
  271. #define XFS_AGB_TO_DADDR(mp,agno,agbno) xfs_agb_to_daddr(mp,agno,agbno)
  272. #else
  273. #define XFS_AGB_TO_DADDR(mp,agno,agbno) \
  274. ((xfs_daddr_t)(XFS_FSB_TO_BB(mp, \
  275. (xfs_fsblock_t)(agno) * (mp)->m_sb.sb_agblocks + (agbno))))
  276. #endif
  277. /*
  278. * XFS_DADDR_TO_AGNO and XFS_DADDR_TO_AGBNO moved to xfs_mount.h
  279. * to avoid header file ordering change
  280. */
  281. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AG_DADDR)
  282. xfs_daddr_t xfs_ag_daddr(struct xfs_mount *mp, xfs_agnumber_t agno,
  283. xfs_daddr_t d);
  284. #define XFS_AG_DADDR(mp,agno,d) xfs_ag_daddr(mp,agno,d)
  285. #else
  286. #define XFS_AG_DADDR(mp,agno,d) (XFS_AGB_TO_DADDR(mp, agno, 0) + (d))
  287. #endif
  288. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_AGF)
  289. xfs_agf_t *xfs_buf_to_agf(struct xfs_buf *bp);
  290. #define XFS_BUF_TO_AGF(bp) xfs_buf_to_agf(bp)
  291. #else
  292. #define XFS_BUF_TO_AGF(bp) ((xfs_agf_t *)XFS_BUF_PTR(bp))
  293. #endif
  294. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_AGI)
  295. xfs_agi_t *xfs_buf_to_agi(struct xfs_buf *bp);
  296. #define XFS_BUF_TO_AGI(bp) xfs_buf_to_agi(bp)
  297. #else
  298. #define XFS_BUF_TO_AGI(bp) ((xfs_agi_t *)XFS_BUF_PTR(bp))
  299. #endif
  300. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_BUF_TO_AGFL)
  301. xfs_agfl_t *xfs_buf_to_agfl(struct xfs_buf *bp);
  302. #define XFS_BUF_TO_AGFL(bp) xfs_buf_to_agfl(bp)
  303. #else
  304. #define XFS_BUF_TO_AGFL(bp) ((xfs_agfl_t *)XFS_BUF_PTR(bp))
  305. #endif
  306. /*
  307. * For checking for bad ranges of xfs_daddr_t's, covering multiple
  308. * allocation groups or a single xfs_daddr_t that's a superblock copy.
  309. */
  310. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_AG_CHECK_DADDR)
  311. void xfs_ag_check_daddr(struct xfs_mount *mp, xfs_daddr_t d, xfs_extlen_t len);
  312. #define XFS_AG_CHECK_DADDR(mp,d,len) xfs_ag_check_daddr(mp,d,len)
  313. #else
  314. #define XFS_AG_CHECK_DADDR(mp,d,len) \
  315. ((len) == 1 ? \
  316. ASSERT((d) == XFS_SB_DADDR || \
  317. XFS_DADDR_TO_AGBNO(mp, d) != XFS_SB_DADDR) : \
  318. ASSERT(XFS_DADDR_TO_AGNO(mp, d) == \
  319. XFS_DADDR_TO_AGNO(mp, (d) + (len) - 1)))
  320. #endif
  321. #endif /* __XFS_AG_H__ */