1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#ifndef __XFS_AG_H__
19#define __XFS_AG_H__
20
21
22
23
24
25
26
27struct xfs_buf;
28struct xfs_mount;
29struct xfs_trans;
30
31#define XFS_AGF_MAGIC 0x58414746
32#define XFS_AGI_MAGIC 0x58414749
33#define XFS_AGF_VERSION 1
34#define XFS_AGI_VERSION 1
35
36#define XFS_AGF_GOOD_VERSION(v) ((v) == XFS_AGF_VERSION)
37#define XFS_AGI_GOOD_VERSION(v) ((v) == XFS_AGI_VERSION)
38
39
40
41
42
43#define XFS_BTNUM_AGF ((int)XFS_BTNUM_CNTi + 1)
44
45
46
47
48
49
50
51typedef struct xfs_agf {
52
53
54
55 __be32 agf_magicnum;
56 __be32 agf_versionnum;
57 __be32 agf_seqno;
58 __be32 agf_length;
59
60
61
62 __be32 agf_roots[XFS_BTNUM_AGF];
63 __be32 agf_spare0;
64 __be32 agf_levels[XFS_BTNUM_AGF];
65 __be32 agf_spare1;
66 __be32 agf_flfirst;
67 __be32 agf_fllast;
68 __be32 agf_flcount;
69 __be32 agf_freeblks;
70 __be32 agf_longest;
71 __be32 agf_btreeblks;
72} xfs_agf_t;
73
74#define XFS_AGF_MAGICNUM 0x00000001
75#define XFS_AGF_VERSIONNUM 0x00000002
76#define XFS_AGF_SEQNO 0x00000004
77#define XFS_AGF_LENGTH 0x00000008
78#define XFS_AGF_ROOTS 0x00000010
79#define XFS_AGF_LEVELS 0x00000020
80#define XFS_AGF_FLFIRST 0x00000040
81#define XFS_AGF_FLLAST 0x00000080
82#define XFS_AGF_FLCOUNT 0x00000100
83#define XFS_AGF_FREEBLKS 0x00000200
84#define XFS_AGF_LONGEST 0x00000400
85#define XFS_AGF_BTREEBLKS 0x00000800
86#define XFS_AGF_NUM_BITS 12
87#define XFS_AGF_ALL_BITS ((1 << XFS_AGF_NUM_BITS) - 1)
88
89
90#define XFS_AGF_DADDR(mp) ((xfs_daddr_t)(1 << (mp)->m_sectbb_log))
91#define XFS_AGF_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGF_DADDR(mp))
92#define XFS_BUF_TO_AGF(bp) ((xfs_agf_t *)XFS_BUF_PTR(bp))
93
94extern int xfs_read_agf(struct xfs_mount *mp, struct xfs_trans *tp,
95 xfs_agnumber_t agno, int flags, struct xfs_buf **bpp);
96
97
98
99
100#define XFS_AGI_UNLINKED_BUCKETS 64
101
102typedef struct xfs_agi {
103
104
105
106 __be32 agi_magicnum;
107 __be32 agi_versionnum;
108 __be32 agi_seqno;
109 __be32 agi_length;
110
111
112
113
114
115 __be32 agi_count;
116 __be32 agi_root;
117 __be32 agi_level;
118 __be32 agi_freecount;
119 __be32 agi_newino;
120 __be32 agi_dirino;
121
122
123
124
125 __be32 agi_unlinked[XFS_AGI_UNLINKED_BUCKETS];
126} xfs_agi_t;
127
128#define XFS_AGI_MAGICNUM 0x00000001
129#define XFS_AGI_VERSIONNUM 0x00000002
130#define XFS_AGI_SEQNO 0x00000004
131#define XFS_AGI_LENGTH 0x00000008
132#define XFS_AGI_COUNT 0x00000010
133#define XFS_AGI_ROOT 0x00000020
134#define XFS_AGI_LEVEL 0x00000040
135#define XFS_AGI_FREECOUNT 0x00000080
136#define XFS_AGI_NEWINO 0x00000100
137#define XFS_AGI_DIRINO 0x00000200
138#define XFS_AGI_UNLINKED 0x00000400
139#define XFS_AGI_NUM_BITS 11
140#define XFS_AGI_ALL_BITS ((1 << XFS_AGI_NUM_BITS) - 1)
141
142
143#define XFS_AGI_DADDR(mp) ((xfs_daddr_t)(2 << (mp)->m_sectbb_log))
144#define XFS_AGI_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGI_DADDR(mp))
145#define XFS_BUF_TO_AGI(bp) ((xfs_agi_t *)XFS_BUF_PTR(bp))
146
147extern int xfs_read_agi(struct xfs_mount *mp, struct xfs_trans *tp,
148 xfs_agnumber_t agno, struct xfs_buf **bpp);
149
150
151
152
153
154#define XFS_AGFL_DADDR(mp) ((xfs_daddr_t)(3 << (mp)->m_sectbb_log))
155#define XFS_AGFL_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGFL_DADDR(mp))
156#define XFS_AGFL_SIZE(mp) ((mp)->m_sb.sb_sectsize / sizeof(xfs_agblock_t))
157#define XFS_BUF_TO_AGFL(bp) ((xfs_agfl_t *)XFS_BUF_PTR(bp))
158
159typedef struct xfs_agfl {
160 __be32 agfl_bno[1];
161} xfs_agfl_t;
162
163
164
165
166
167typedef struct xfs_perag_busy {
168 xfs_agblock_t busy_start;
169 xfs_extlen_t busy_length;
170 struct xfs_trans *busy_tp;
171} xfs_perag_busy_t;
172
173
174
175
176
177
178
179#if (BITS_PER_LONG == 32)
180#define XFS_PAGB_NUM_SLOTS 84
181#elif (BITS_PER_LONG == 64)
182#define XFS_PAGB_NUM_SLOTS 128
183#endif
184
185typedef struct xfs_perag
186{
187 char pagf_init;
188 char pagi_init;
189 char pagf_metadata;
190 char pagi_inodeok;
191 __uint8_t pagf_levels[XFS_BTNUM_AGF];
192
193 __uint32_t pagf_flcount;
194 xfs_extlen_t pagf_freeblks;
195 xfs_extlen_t pagf_longest;
196 __uint32_t pagf_btreeblks;
197 xfs_agino_t pagi_freecount;
198 xfs_agino_t pagi_count;
199 int pagb_count;
200 xfs_perag_busy_t *pagb_list;
201
202
203
204
205
206
207 xfs_agino_t pagl_pagino;
208 xfs_agino_t pagl_leftrec;
209 xfs_agino_t pagl_rightrec;
210#ifdef __KERNEL__
211 spinlock_t pagb_lock;
212
213 atomic_t pagf_fstrms;
214
215 int pag_ici_init;
216 rwlock_t pag_ici_lock;
217 struct radix_tree_root pag_ici_root;
218#endif
219} xfs_perag_t;
220
221
222
223
224#define XFS_ICI_NO_TAG (-1)
225
226#define XFS_ICI_RECLAIM_TAG 0
227
228#define XFS_AG_MAXLEVELS(mp) ((mp)->m_ag_maxlevels)
229#define XFS_MIN_FREELIST_RAW(bl,cl,mp) \
230 (MIN(bl + 1, XFS_AG_MAXLEVELS(mp)) + MIN(cl + 1, XFS_AG_MAXLEVELS(mp)))
231#define XFS_MIN_FREELIST(a,mp) \
232 (XFS_MIN_FREELIST_RAW( \
233 be32_to_cpu((a)->agf_levels[XFS_BTNUM_BNOi]), \
234 be32_to_cpu((a)->agf_levels[XFS_BTNUM_CNTi]), mp))
235#define XFS_MIN_FREELIST_PAG(pag,mp) \
236 (XFS_MIN_FREELIST_RAW( \
237 (unsigned int)(pag)->pagf_levels[XFS_BTNUM_BNOi], \
238 (unsigned int)(pag)->pagf_levels[XFS_BTNUM_CNTi], mp))
239
240#define XFS_AGB_TO_FSB(mp,agno,agbno) \
241 (((xfs_fsblock_t)(agno) << (mp)->m_sb.sb_agblklog) | (agbno))
242#define XFS_FSB_TO_AGNO(mp,fsbno) \
243 ((xfs_agnumber_t)((fsbno) >> (mp)->m_sb.sb_agblklog))
244#define XFS_FSB_TO_AGBNO(mp,fsbno) \
245 ((xfs_agblock_t)((fsbno) & xfs_mask32lo((mp)->m_sb.sb_agblklog)))
246#define XFS_AGB_TO_DADDR(mp,agno,agbno) \
247 ((xfs_daddr_t)XFS_FSB_TO_BB(mp, \
248 (xfs_fsblock_t)(agno) * (mp)->m_sb.sb_agblocks + (agbno)))
249#define XFS_AG_DADDR(mp,agno,d) (XFS_AGB_TO_DADDR(mp, agno, 0) + (d))
250
251
252
253
254
255#define XFS_AG_CHECK_DADDR(mp,d,len) \
256 ((len) == 1 ? \
257 ASSERT((d) == XFS_SB_DADDR || \
258 xfs_daddr_to_agbno(mp, d) != XFS_SB_DADDR) : \
259 ASSERT(xfs_daddr_to_agno(mp, d) == \
260 xfs_daddr_to_agno(mp, (d) + (len) - 1)))
261
262#endif
263