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