xfs_ag.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /*
  2. * Copyright (c) 2000-2003,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_AG_H__
  19. #define __XFS_AG_H__
  20. /*
  21. * Allocation group header
  22. * This is divided into three structures, placed in sequential 512-byte
  23. * buffers after a copy of the superblock (also in a 512-byte buffer).
  24. */
  25. struct xfs_buf;
  26. struct xfs_mount;
  27. struct xfs_trans;
  28. #define XFS_AGF_MAGIC 0x58414746 /* 'XAGF' */
  29. #define XFS_AGI_MAGIC 0x58414749 /* 'XAGI' */
  30. #define XFS_AGFL_MAGIC 0x5841464c /* 'XAFL' */
  31. #define XFS_AGF_VERSION 1
  32. #define XFS_AGI_VERSION 1
  33. #define XFS_AGF_GOOD_VERSION(v) ((v) == XFS_AGF_VERSION)
  34. #define XFS_AGI_GOOD_VERSION(v) ((v) == XFS_AGI_VERSION)
  35. /*
  36. * Btree number 0 is bno, 1 is cnt. This value gives the size of the
  37. * arrays below.
  38. */
  39. #define XFS_BTNUM_AGF ((int)XFS_BTNUM_CNTi + 1)
  40. /*
  41. * The second word of agf_levels in the first a.g. overlaps the EFS
  42. * superblock's magic number. Since the magic numbers valid for EFS
  43. * are > 64k, our value cannot be confused for an EFS superblock's.
  44. */
  45. typedef struct xfs_agf {
  46. /*
  47. * Common allocation group header information
  48. */
  49. __be32 agf_magicnum; /* magic number == XFS_AGF_MAGIC */
  50. __be32 agf_versionnum; /* header version == XFS_AGF_VERSION */
  51. __be32 agf_seqno; /* sequence # starting from 0 */
  52. __be32 agf_length; /* size in blocks of a.g. */
  53. /*
  54. * Freespace information
  55. */
  56. __be32 agf_roots[XFS_BTNUM_AGF]; /* root blocks */
  57. __be32 agf_spare0; /* spare field */
  58. __be32 agf_levels[XFS_BTNUM_AGF]; /* btree levels */
  59. __be32 agf_spare1; /* spare field */
  60. __be32 agf_flfirst; /* first freelist block's index */
  61. __be32 agf_fllast; /* last freelist block's index */
  62. __be32 agf_flcount; /* count of blocks in freelist */
  63. __be32 agf_freeblks; /* total free blocks */
  64. __be32 agf_longest; /* longest free space */
  65. __be32 agf_btreeblks; /* # of blocks held in AGF btrees */
  66. uuid_t agf_uuid; /* uuid of filesystem */
  67. /*
  68. * reserve some contiguous space for future logged fields before we add
  69. * the unlogged fields. This makes the range logging via flags and
  70. * structure offsets much simpler.
  71. */
  72. __be64 agf_spare64[16];
  73. /* unlogged fields, written during buffer writeback. */
  74. __be64 agf_lsn; /* last write sequence */
  75. __be32 agf_crc; /* crc of agf sector */
  76. __be32 agf_spare2;
  77. /* structure must be padded to 64 bit alignment */
  78. } xfs_agf_t;
  79. #define XFS_AGF_MAGICNUM 0x00000001
  80. #define XFS_AGF_VERSIONNUM 0x00000002
  81. #define XFS_AGF_SEQNO 0x00000004
  82. #define XFS_AGF_LENGTH 0x00000008
  83. #define XFS_AGF_ROOTS 0x00000010
  84. #define XFS_AGF_LEVELS 0x00000020
  85. #define XFS_AGF_FLFIRST 0x00000040
  86. #define XFS_AGF_FLLAST 0x00000080
  87. #define XFS_AGF_FLCOUNT 0x00000100
  88. #define XFS_AGF_FREEBLKS 0x00000200
  89. #define XFS_AGF_LONGEST 0x00000400
  90. #define XFS_AGF_BTREEBLKS 0x00000800
  91. #define XFS_AGF_UUID 0x00001000
  92. #define XFS_AGF_NUM_BITS 13
  93. #define XFS_AGF_ALL_BITS ((1 << XFS_AGF_NUM_BITS) - 1)
  94. #define XFS_AGF_FLAGS \
  95. { XFS_AGF_MAGICNUM, "MAGICNUM" }, \
  96. { XFS_AGF_VERSIONNUM, "VERSIONNUM" }, \
  97. { XFS_AGF_SEQNO, "SEQNO" }, \
  98. { XFS_AGF_LENGTH, "LENGTH" }, \
  99. { XFS_AGF_ROOTS, "ROOTS" }, \
  100. { XFS_AGF_LEVELS, "LEVELS" }, \
  101. { XFS_AGF_FLFIRST, "FLFIRST" }, \
  102. { XFS_AGF_FLLAST, "FLLAST" }, \
  103. { XFS_AGF_FLCOUNT, "FLCOUNT" }, \
  104. { XFS_AGF_FREEBLKS, "FREEBLKS" }, \
  105. { XFS_AGF_LONGEST, "LONGEST" }, \
  106. { XFS_AGF_BTREEBLKS, "BTREEBLKS" }, \
  107. { XFS_AGF_UUID, "UUID" }
  108. /* disk block (xfs_daddr_t) in the AG */
  109. #define XFS_AGF_DADDR(mp) ((xfs_daddr_t)(1 << (mp)->m_sectbb_log))
  110. #define XFS_AGF_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGF_DADDR(mp))
  111. #define XFS_BUF_TO_AGF(bp) ((xfs_agf_t *)((bp)->b_addr))
  112. extern int xfs_read_agf(struct xfs_mount *mp, struct xfs_trans *tp,
  113. xfs_agnumber_t agno, int flags, struct xfs_buf **bpp);
  114. extern const struct xfs_buf_ops xfs_agf_buf_ops;
  115. /*
  116. * Size of the unlinked inode hash table in the agi.
  117. */
  118. #define XFS_AGI_UNLINKED_BUCKETS 64
  119. typedef struct xfs_agi {
  120. /*
  121. * Common allocation group header information
  122. */
  123. __be32 agi_magicnum; /* magic number == XFS_AGI_MAGIC */
  124. __be32 agi_versionnum; /* header version == XFS_AGI_VERSION */
  125. __be32 agi_seqno; /* sequence # starting from 0 */
  126. __be32 agi_length; /* size in blocks of a.g. */
  127. /*
  128. * Inode information
  129. * Inodes are mapped by interpreting the inode number, so no
  130. * mapping data is needed here.
  131. */
  132. __be32 agi_count; /* count of allocated inodes */
  133. __be32 agi_root; /* root of inode btree */
  134. __be32 agi_level; /* levels in inode btree */
  135. __be32 agi_freecount; /* number of free inodes */
  136. __be32 agi_newino; /* new inode just allocated */
  137. __be32 agi_dirino; /* last directory inode chunk */
  138. /*
  139. * Hash table of inodes which have been unlinked but are
  140. * still being referenced.
  141. */
  142. __be32 agi_unlinked[XFS_AGI_UNLINKED_BUCKETS];
  143. uuid_t agi_uuid; /* uuid of filesystem */
  144. __be32 agi_crc; /* crc of agi sector */
  145. __be32 agi_pad32;
  146. __be64 agi_lsn; /* last write sequence */
  147. /* structure must be padded to 64 bit alignment */
  148. } xfs_agi_t;
  149. #define XFS_AGI_MAGICNUM 0x00000001
  150. #define XFS_AGI_VERSIONNUM 0x00000002
  151. #define XFS_AGI_SEQNO 0x00000004
  152. #define XFS_AGI_LENGTH 0x00000008
  153. #define XFS_AGI_COUNT 0x00000010
  154. #define XFS_AGI_ROOT 0x00000020
  155. #define XFS_AGI_LEVEL 0x00000040
  156. #define XFS_AGI_FREECOUNT 0x00000080
  157. #define XFS_AGI_NEWINO 0x00000100
  158. #define XFS_AGI_DIRINO 0x00000200
  159. #define XFS_AGI_UNLINKED 0x00000400
  160. #define XFS_AGI_NUM_BITS 11
  161. #define XFS_AGI_ALL_BITS ((1 << XFS_AGI_NUM_BITS) - 1)
  162. /* disk block (xfs_daddr_t) in the AG */
  163. #define XFS_AGI_DADDR(mp) ((xfs_daddr_t)(2 << (mp)->m_sectbb_log))
  164. #define XFS_AGI_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGI_DADDR(mp))
  165. #define XFS_BUF_TO_AGI(bp) ((xfs_agi_t *)((bp)->b_addr))
  166. extern int xfs_read_agi(struct xfs_mount *mp, struct xfs_trans *tp,
  167. xfs_agnumber_t agno, struct xfs_buf **bpp);
  168. extern const struct xfs_buf_ops xfs_agi_buf_ops;
  169. /*
  170. * The third a.g. block contains the a.g. freelist, an array
  171. * of block pointers to blocks owned by the allocation btree code.
  172. */
  173. #define XFS_AGFL_DADDR(mp) ((xfs_daddr_t)(3 << (mp)->m_sectbb_log))
  174. #define XFS_AGFL_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGFL_DADDR(mp))
  175. #define XFS_BUF_TO_AGFL(bp) ((xfs_agfl_t *)((bp)->b_addr))
  176. #define XFS_BUF_TO_AGFL_BNO(mp, bp) \
  177. (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \
  178. &(XFS_BUF_TO_AGFL(bp)->agfl_bno[0]) : \
  179. (__be32 *)(bp)->b_addr)
  180. /*
  181. * Size of the AGFL. For CRC-enabled filesystes we steal a couple of
  182. * slots in the beginning of the block for a proper header with the
  183. * location information and CRC.
  184. */
  185. #define XFS_AGFL_SIZE(mp) \
  186. (((mp)->m_sb.sb_sectsize - \
  187. (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \
  188. sizeof(struct xfs_agfl) : 0)) / \
  189. sizeof(xfs_agblock_t))
  190. typedef struct xfs_agfl {
  191. __be32 agfl_magicnum;
  192. __be32 agfl_seqno;
  193. uuid_t agfl_uuid;
  194. __be64 agfl_lsn;
  195. __be32 agfl_crc;
  196. __be32 agfl_bno[]; /* actually XFS_AGFL_SIZE(mp) */
  197. } xfs_agfl_t;
  198. /*
  199. * Per-ag incore structure, copies of information in agf and agi,
  200. * to improve the performance of allocation group selection.
  201. */
  202. #define XFS_PAGB_NUM_SLOTS 128
  203. typedef struct xfs_perag {
  204. struct xfs_mount *pag_mount; /* owner filesystem */
  205. xfs_agnumber_t pag_agno; /* AG this structure belongs to */
  206. atomic_t pag_ref; /* perag reference count */
  207. char pagf_init; /* this agf's entry is initialized */
  208. char pagi_init; /* this agi's entry is initialized */
  209. char pagf_metadata; /* the agf is preferred to be metadata */
  210. char pagi_inodeok; /* The agi is ok for inodes */
  211. __uint8_t pagf_levels[XFS_BTNUM_AGF];
  212. /* # of levels in bno & cnt btree */
  213. __uint32_t pagf_flcount; /* count of blocks in freelist */
  214. xfs_extlen_t pagf_freeblks; /* total free blocks */
  215. xfs_extlen_t pagf_longest; /* longest free space */
  216. __uint32_t pagf_btreeblks; /* # of blocks held in AGF btrees */
  217. xfs_agino_t pagi_freecount; /* number of free inodes */
  218. xfs_agino_t pagi_count; /* number of allocated inodes */
  219. /*
  220. * Inode allocation search lookup optimisation.
  221. * If the pagino matches, the search for new inodes
  222. * doesn't need to search the near ones again straight away
  223. */
  224. xfs_agino_t pagl_pagino;
  225. xfs_agino_t pagl_leftrec;
  226. xfs_agino_t pagl_rightrec;
  227. #ifdef __KERNEL__
  228. spinlock_t pagb_lock; /* lock for pagb_tree */
  229. struct rb_root pagb_tree; /* ordered tree of busy extents */
  230. atomic_t pagf_fstrms; /* # of filestreams active in this AG */
  231. spinlock_t pag_ici_lock; /* incore inode cache lock */
  232. struct radix_tree_root pag_ici_root; /* incore inode cache root */
  233. int pag_ici_reclaimable; /* reclaimable inodes */
  234. struct mutex pag_ici_reclaim_lock; /* serialisation point */
  235. unsigned long pag_ici_reclaim_cursor; /* reclaim restart point */
  236. /* buffer cache index */
  237. spinlock_t pag_buf_lock; /* lock for pag_buf_tree */
  238. struct rb_root pag_buf_tree; /* ordered tree of active buffers */
  239. /* for rcu-safe freeing */
  240. struct rcu_head rcu_head;
  241. #endif
  242. int pagb_count; /* pagb slots in use */
  243. } xfs_perag_t;
  244. /*
  245. * tags for inode radix tree
  246. */
  247. #define XFS_ICI_NO_TAG (-1) /* special flag for an untagged lookup
  248. in xfs_inode_ag_iterator */
  249. #define XFS_ICI_RECLAIM_TAG 0 /* inode is to be reclaimed */
  250. #define XFS_ICI_EOFBLOCKS_TAG 1 /* inode has blocks beyond EOF */
  251. #define XFS_AG_MAXLEVELS(mp) ((mp)->m_ag_maxlevels)
  252. #define XFS_MIN_FREELIST_RAW(bl,cl,mp) \
  253. (MIN(bl + 1, XFS_AG_MAXLEVELS(mp)) + MIN(cl + 1, XFS_AG_MAXLEVELS(mp)))
  254. #define XFS_MIN_FREELIST(a,mp) \
  255. (XFS_MIN_FREELIST_RAW( \
  256. be32_to_cpu((a)->agf_levels[XFS_BTNUM_BNOi]), \
  257. be32_to_cpu((a)->agf_levels[XFS_BTNUM_CNTi]), mp))
  258. #define XFS_MIN_FREELIST_PAG(pag,mp) \
  259. (XFS_MIN_FREELIST_RAW( \
  260. (unsigned int)(pag)->pagf_levels[XFS_BTNUM_BNOi], \
  261. (unsigned int)(pag)->pagf_levels[XFS_BTNUM_CNTi], mp))
  262. #define XFS_AGB_TO_FSB(mp,agno,agbno) \
  263. (((xfs_fsblock_t)(agno) << (mp)->m_sb.sb_agblklog) | (agbno))
  264. #define XFS_FSB_TO_AGNO(mp,fsbno) \
  265. ((xfs_agnumber_t)((fsbno) >> (mp)->m_sb.sb_agblklog))
  266. #define XFS_FSB_TO_AGBNO(mp,fsbno) \
  267. ((xfs_agblock_t)((fsbno) & xfs_mask32lo((mp)->m_sb.sb_agblklog)))
  268. #define XFS_AGB_TO_DADDR(mp,agno,agbno) \
  269. ((xfs_daddr_t)XFS_FSB_TO_BB(mp, \
  270. (xfs_fsblock_t)(agno) * (mp)->m_sb.sb_agblocks + (agbno)))
  271. #define XFS_AG_DADDR(mp,agno,d) (XFS_AGB_TO_DADDR(mp, agno, 0) + (d))
  272. /*
  273. * For checking for bad ranges of xfs_daddr_t's, covering multiple
  274. * allocation groups or a single xfs_daddr_t that's a superblock copy.
  275. */
  276. #define XFS_AG_CHECK_DADDR(mp,d,len) \
  277. ((len) == 1 ? \
  278. ASSERT((d) == XFS_SB_DADDR || \
  279. xfs_daddr_to_agbno(mp, d) != XFS_SB_DADDR) : \
  280. ASSERT(xfs_daddr_to_agno(mp, d) == \
  281. xfs_daddr_to_agno(mp, (d) + (len) - 1)))
  282. #endif /* __XFS_AG_H__ */