Skip to content

Commit aafc3c2

Browse files
Brian Fosterdchinner
authored andcommitted
xfs: support the XFS_BTNUM_FINOBT free inode btree type
Define the AGI fields for the finobt root/level and add magic numbers. Update the btree code to add support for the new XFS_BTNUM_FINOBT inode btree. The finobt root block is reserved immediately following the inobt root block in the AG. Update XFS_PREALLOC_BLOCKS() to determine the starting AG data block based on whether finobt support is enabled. Signed-off-by: Brian Foster <bfoster@redhat.com> Reviewed-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Dave Chinner <david@fromorbit.com>
1 parent 8e2c84d commit aafc3c2

10 files changed

Lines changed: 153 additions & 27 deletions

File tree

‎fs/xfs/xfs_ag.h‎

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,30 +160,38 @@ typedef struct xfs_agi {
160160
* still being referenced.
161161
*/
162162
__be32 agi_unlinked[XFS_AGI_UNLINKED_BUCKETS];
163-
163+
/*
164+
* This marks the end of logging region 1 and start of logging region 2.
165+
*/
164166
uuid_t agi_uuid; /* uuid of filesystem */
165167
__be32 agi_crc; /* crc of agi sector */
166168
__be32 agi_pad32;
167169
__be64 agi_lsn; /* last write sequence */
168170

171+
__be32 agi_free_root; /* root of the free inode btree */
172+
__be32 agi_free_level;/* levels in free inode btree */
173+
169174
/* structure must be padded to 64 bit alignment */
170175
} xfs_agi_t;
171176

172177
#define XFS_AGI_CRC_OFF offsetof(struct xfs_agi, agi_crc)
173178

174-
#define XFS_AGI_MAGICNUM 0x00000001
175-
#define XFS_AGI_VERSIONNUM 0x00000002
176-
#define XFS_AGI_SEQNO 0x00000004
177-
#define XFS_AGI_LENGTH 0x00000008
178-
#define XFS_AGI_COUNT 0x00000010
179-
#define XFS_AGI_ROOT 0x00000020
180-
#define XFS_AGI_LEVEL 0x00000040
181-
#define XFS_AGI_FREECOUNT 0x00000080
182-
#define XFS_AGI_NEWINO 0x00000100
183-
#define XFS_AGI_DIRINO 0x00000200
184-
#define XFS_AGI_UNLINKED 0x00000400
185-
#define XFS_AGI_NUM_BITS 11
186-
#define XFS_AGI_ALL_BITS ((1 << XFS_AGI_NUM_BITS) - 1)
179+
#define XFS_AGI_MAGICNUM (1 << 0)
180+
#define XFS_AGI_VERSIONNUM (1 << 1)
181+
#define XFS_AGI_SEQNO (1 << 2)
182+
#define XFS_AGI_LENGTH (1 << 3)
183+
#define XFS_AGI_COUNT (1 << 4)
184+
#define XFS_AGI_ROOT (1 << 5)
185+
#define XFS_AGI_LEVEL (1 << 6)
186+
#define XFS_AGI_FREECOUNT (1 << 7)
187+
#define XFS_AGI_NEWINO (1 << 8)
188+
#define XFS_AGI_DIRINO (1 << 9)
189+
#define XFS_AGI_UNLINKED (1 << 10)
190+
#define XFS_AGI_NUM_BITS_R1 11 /* end of the 1st agi logging region */
191+
#define XFS_AGI_ALL_BITS_R1 ((1 << XFS_AGI_NUM_BITS_R1) - 1)
192+
#define XFS_AGI_FREE_ROOT (1 << 11)
193+
#define XFS_AGI_FREE_LEVEL (1 << 12)
194+
#define XFS_AGI_NUM_BITS_R2 13
187195

188196
/* disk block (xfs_daddr_t) in the AG */
189197
#define XFS_AGI_DADDR(mp) ((xfs_daddr_t)(2 << (mp)->m_sectbb_log))

‎fs/xfs/xfs_btree.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ kmem_zone_t *xfs_btree_cur_zone;
4343
* Btree magic numbers.
4444
*/
4545
static const __uint32_t xfs_magics[2][XFS_BTNUM_MAX] = {
46-
{ XFS_ABTB_MAGIC, XFS_ABTC_MAGIC, XFS_BMAP_MAGIC, XFS_IBT_MAGIC },
46+
{ XFS_ABTB_MAGIC, XFS_ABTC_MAGIC, XFS_BMAP_MAGIC, XFS_IBT_MAGIC,
47+
XFS_FIBT_MAGIC },
4748
{ XFS_ABTB_CRC_MAGIC, XFS_ABTC_CRC_MAGIC,
48-
XFS_BMAP_CRC_MAGIC, XFS_IBT_CRC_MAGIC }
49+
XFS_BMAP_CRC_MAGIC, XFS_IBT_CRC_MAGIC, XFS_FIBT_CRC_MAGIC }
4950
};
5051
#define xfs_btree_magic(cur) \
5152
xfs_magics[!!((cur)->bc_flags & XFS_BTREE_CRC_BLOCKS)][cur->bc_btnum]
@@ -1115,6 +1116,7 @@ xfs_btree_set_refs(
11151116
xfs_buf_set_ref(bp, XFS_ALLOC_BTREE_REF);
11161117
break;
11171118
case XFS_BTNUM_INO:
1119+
case XFS_BTNUM_FINO:
11181120
xfs_buf_set_ref(bp, XFS_INO_BTREE_REF);
11191121
break;
11201122
case XFS_BTNUM_BMAP:

‎fs/xfs/xfs_btree.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ union xfs_btree_rec {
6262
#define XFS_BTNUM_CNT ((xfs_btnum_t)XFS_BTNUM_CNTi)
6363
#define XFS_BTNUM_BMAP ((xfs_btnum_t)XFS_BTNUM_BMAPi)
6464
#define XFS_BTNUM_INO ((xfs_btnum_t)XFS_BTNUM_INOi)
65+
#define XFS_BTNUM_FINO ((xfs_btnum_t)XFS_BTNUM_FINOi)
6566

6667
/*
6768
* For logging record fields.
@@ -92,6 +93,7 @@ do { \
9293
case XFS_BTNUM_CNT: __XFS_BTREE_STATS_INC(abtc, stat); break; \
9394
case XFS_BTNUM_BMAP: __XFS_BTREE_STATS_INC(bmbt, stat); break; \
9495
case XFS_BTNUM_INO: __XFS_BTREE_STATS_INC(ibt, stat); break; \
96+
case XFS_BTNUM_FINO: __XFS_BTREE_STATS_INC(fibt, stat); break; \
9597
case XFS_BTNUM_MAX: ASSERT(0); /* fucking gcc */ ; break; \
9698
} \
9799
} while (0)
@@ -105,6 +107,7 @@ do { \
105107
case XFS_BTNUM_CNT: __XFS_BTREE_STATS_ADD(abtc, stat, val); break; \
106108
case XFS_BTNUM_BMAP: __XFS_BTREE_STATS_ADD(bmbt, stat, val); break; \
107109
case XFS_BTNUM_INO: __XFS_BTREE_STATS_ADD(ibt, stat, val); break; \
110+
case XFS_BTNUM_FINO: __XFS_BTREE_STATS_ADD(fibt, stat, val); break; \
108111
case XFS_BTNUM_MAX: ASSERT(0); /* fucking gcc */ ; break; \
109112
} \
110113
} while (0)

‎fs/xfs/xfs_format.h‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ typedef __be32 xfs_alloc_ptr_t;
202202
*/
203203
#define XFS_IBT_MAGIC 0x49414254 /* 'IABT' */
204204
#define XFS_IBT_CRC_MAGIC 0x49414233 /* 'IAB3' */
205+
#define XFS_FIBT_MAGIC 0x46494254 /* 'FIBT' */
206+
#define XFS_FIBT_CRC_MAGIC 0x46494233 /* 'FIB3' */
205207

206208
typedef __uint64_t xfs_inofree_t;
207209
#define XFS_INODES_PER_CHUNK (NBBY * sizeof(xfs_inofree_t))
@@ -244,7 +246,17 @@ typedef __be32 xfs_inobt_ptr_t;
244246
* block numbers in the AG.
245247
*/
246248
#define XFS_IBT_BLOCK(mp) ((xfs_agblock_t)(XFS_CNT_BLOCK(mp) + 1))
247-
#define XFS_PREALLOC_BLOCKS(mp) ((xfs_agblock_t)(XFS_IBT_BLOCK(mp) + 1))
249+
#define XFS_FIBT_BLOCK(mp) ((xfs_agblock_t)(XFS_IBT_BLOCK(mp) + 1))
250+
251+
/*
252+
* The first data block of an AG depends on whether the filesystem was formatted
253+
* with the finobt feature. If so, account for the finobt reserved root btree
254+
* block.
255+
*/
256+
#define XFS_PREALLOC_BLOCKS(mp) \
257+
(xfs_sb_version_hasfinobt(&((mp)->m_sb)) ? \
258+
XFS_FIBT_BLOCK(mp) + 1 : \
259+
XFS_IBT_BLOCK(mp) + 1)
248260

249261

250262

‎fs/xfs/xfs_ialloc.c‎

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,16 @@ xfs_ialloc_compute_maxlevels(
14881488
}
14891489

14901490
/*
1491-
* Log specified fields for the ag hdr (inode section)
1491+
* Log specified fields for the ag hdr (inode section). The growth of the agi
1492+
* structure over time requires that we interpret the buffer as two logical
1493+
* regions delineated by the end of the unlinked list. This is due to the size
1494+
* of the hash table and its location in the middle of the agi.
1495+
*
1496+
* For example, a request to log a field before agi_unlinked and a field after
1497+
* agi_unlinked could cause us to log the entire hash table and use an excessive
1498+
* amount of log space. To avoid this behavior, log the region up through
1499+
* agi_unlinked in one call and the region after agi_unlinked through the end of
1500+
* the structure in another.
14921501
*/
14931502
void
14941503
xfs_ialloc_log_agi(
@@ -1511,6 +1520,8 @@ xfs_ialloc_log_agi(
15111520
offsetof(xfs_agi_t, agi_newino),
15121521
offsetof(xfs_agi_t, agi_dirino),
15131522
offsetof(xfs_agi_t, agi_unlinked),
1523+
offsetof(xfs_agi_t, agi_free_root),
1524+
offsetof(xfs_agi_t, agi_free_level),
15141525
sizeof(xfs_agi_t)
15151526
};
15161527
#ifdef DEBUG
@@ -1519,15 +1530,30 @@ xfs_ialloc_log_agi(
15191530
agi = XFS_BUF_TO_AGI(bp);
15201531
ASSERT(agi->agi_magicnum == cpu_to_be32(XFS_AGI_MAGIC));
15211532
#endif
1533+
1534+
xfs_trans_buf_set_type(tp, bp, XFS_BLFT_AGI_BUF);
1535+
15221536
/*
1523-
* Compute byte offsets for the first and last fields.
1537+
* Compute byte offsets for the first and last fields in the first
1538+
* region and log the agi buffer. This only logs up through
1539+
* agi_unlinked.
15241540
*/
1525-
xfs_btree_offsets(fields, offsets, XFS_AGI_NUM_BITS, &first, &last);
1541+
if (fields & XFS_AGI_ALL_BITS_R1) {
1542+
xfs_btree_offsets(fields, offsets, XFS_AGI_NUM_BITS_R1,
1543+
&first, &last);
1544+
xfs_trans_log_buf(tp, bp, first, last);
1545+
}
1546+
15261547
/*
1527-
* Log the allocation group inode header buffer.
1548+
* Mask off the bits in the first region and calculate the first and
1549+
* last field offsets for any bits in the second region.
15281550
*/
1529-
xfs_trans_buf_set_type(tp, bp, XFS_BLFT_AGI_BUF);
1530-
xfs_trans_log_buf(tp, bp, first, last);
1551+
fields &= ~XFS_AGI_ALL_BITS_R1;
1552+
if (fields) {
1553+
xfs_btree_offsets(fields, offsets, XFS_AGI_NUM_BITS_R2,
1554+
&first, &last);
1555+
xfs_trans_log_buf(tp, bp, first, last);
1556+
}
15311557
}
15321558

15331559
#ifdef DEBUG

‎fs/xfs/xfs_ialloc_btree.c‎

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ xfs_inobt_set_root(
6767
xfs_ialloc_log_agi(cur->bc_tp, agbp, XFS_AGI_ROOT | XFS_AGI_LEVEL);
6868
}
6969

70+
STATIC void
71+
xfs_finobt_set_root(
72+
struct xfs_btree_cur *cur,
73+
union xfs_btree_ptr *nptr,
74+
int inc) /* level change */
75+
{
76+
struct xfs_buf *agbp = cur->bc_private.a.agbp;
77+
struct xfs_agi *agi = XFS_BUF_TO_AGI(agbp);
78+
79+
agi->agi_free_root = nptr->s;
80+
be32_add_cpu(&agi->agi_free_level, inc);
81+
xfs_ialloc_log_agi(cur->bc_tp, agbp,
82+
XFS_AGI_FREE_ROOT | XFS_AGI_FREE_LEVEL);
83+
}
84+
7085
STATIC int
7186
xfs_inobt_alloc_block(
7287
struct xfs_btree_cur *cur,
@@ -174,6 +189,17 @@ xfs_inobt_init_ptr_from_cur(
174189
ptr->s = agi->agi_root;
175190
}
176191

192+
STATIC void
193+
xfs_finobt_init_ptr_from_cur(
194+
struct xfs_btree_cur *cur,
195+
union xfs_btree_ptr *ptr)
196+
{
197+
struct xfs_agi *agi = XFS_BUF_TO_AGI(cur->bc_private.a.agbp);
198+
199+
ASSERT(cur->bc_private.a.agno == be32_to_cpu(agi->agi_seqno));
200+
ptr->s = agi->agi_free_root;
201+
}
202+
177203
STATIC __int64_t
178204
xfs_inobt_key_diff(
179205
struct xfs_btree_cur *cur,
@@ -204,6 +230,7 @@ xfs_inobt_verify(
204230
*/
205231
switch (block->bb_magic) {
206232
case cpu_to_be32(XFS_IBT_CRC_MAGIC):
233+
case cpu_to_be32(XFS_FIBT_CRC_MAGIC):
207234
if (!xfs_sb_version_hascrc(&mp->m_sb))
208235
return false;
209236
if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_uuid))
@@ -215,6 +242,7 @@ xfs_inobt_verify(
215242
return false;
216243
/* fall through */
217244
case cpu_to_be32(XFS_IBT_MAGIC):
245+
case cpu_to_be32(XFS_FIBT_MAGIC):
218246
break;
219247
default:
220248
return 0;
@@ -318,6 +346,28 @@ static const struct xfs_btree_ops xfs_inobt_ops = {
318346
#endif
319347
};
320348

349+
static const struct xfs_btree_ops xfs_finobt_ops = {
350+
.rec_len = sizeof(xfs_inobt_rec_t),
351+
.key_len = sizeof(xfs_inobt_key_t),
352+
353+
.dup_cursor = xfs_inobt_dup_cursor,
354+
.set_root = xfs_finobt_set_root,
355+
.alloc_block = xfs_inobt_alloc_block,
356+
.free_block = xfs_inobt_free_block,
357+
.get_minrecs = xfs_inobt_get_minrecs,
358+
.get_maxrecs = xfs_inobt_get_maxrecs,
359+
.init_key_from_rec = xfs_inobt_init_key_from_rec,
360+
.init_rec_from_key = xfs_inobt_init_rec_from_key,
361+
.init_rec_from_cur = xfs_inobt_init_rec_from_cur,
362+
.init_ptr_from_cur = xfs_finobt_init_ptr_from_cur,
363+
.key_diff = xfs_inobt_key_diff,
364+
.buf_ops = &xfs_inobt_buf_ops,
365+
#if defined(DEBUG) || defined(XFS_WARN)
366+
.keys_inorder = xfs_inobt_keys_inorder,
367+
.recs_inorder = xfs_inobt_recs_inorder,
368+
#endif
369+
};
370+
321371
/*
322372
* Allocate a new inode btree cursor.
323373
*/
@@ -336,11 +386,17 @@ xfs_inobt_init_cursor(
336386

337387
cur->bc_tp = tp;
338388
cur->bc_mp = mp;
339-
cur->bc_nlevels = be32_to_cpu(agi->agi_level);
340389
cur->bc_btnum = btnum;
390+
if (btnum == XFS_BTNUM_INO) {
391+
cur->bc_nlevels = be32_to_cpu(agi->agi_level);
392+
cur->bc_ops = &xfs_inobt_ops;
393+
} else {
394+
cur->bc_nlevels = be32_to_cpu(agi->agi_free_level);
395+
cur->bc_ops = &xfs_finobt_ops;
396+
}
397+
341398
cur->bc_blocklog = mp->m_sb.sb_blocklog;
342399

343-
cur->bc_ops = &xfs_inobt_ops;
344400
if (xfs_sb_version_hascrc(&mp->m_sb))
345401
cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;
346402

‎fs/xfs/xfs_log_recover.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2138,7 +2138,9 @@ xlog_recover_validate_buf_type(
21382138
bp->b_ops = &xfs_allocbt_buf_ops;
21392139
break;
21402140
case XFS_IBT_CRC_MAGIC:
2141+
case XFS_FIBT_CRC_MAGIC:
21412142
case XFS_IBT_MAGIC:
2143+
case XFS_FIBT_MAGIC:
21422144
bp->b_ops = &xfs_inobt_buf_ops;
21432145
break;
21442146
case XFS_BMAP_CRC_MAGIC:

‎fs/xfs/xfs_stats.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ static int xfs_stat_proc_show(struct seq_file *m, void *v)
5959
{ "abtc2", XFSSTAT_END_ABTC_V2 },
6060
{ "bmbt2", XFSSTAT_END_BMBT_V2 },
6161
{ "ibt2", XFSSTAT_END_IBT_V2 },
62+
{ "fibt2", XFSSTAT_END_FIBT_V2 },
6263
/* we print both series of quota information together */
6364
{ "qm", XFSSTAT_END_QM },
6465
};

‎fs/xfs/xfs_stats.h‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,23 @@ struct xfsstats {
183183
__uint32_t xs_ibt_2_alloc;
184184
__uint32_t xs_ibt_2_free;
185185
__uint32_t xs_ibt_2_moves;
186-
#define XFSSTAT_END_XQMSTAT (XFSSTAT_END_IBT_V2+6)
186+
#define XFSSTAT_END_FIBT_V2 (XFSSTAT_END_IBT_V2+15)
187+
__uint32_t xs_fibt_2_lookup;
188+
__uint32_t xs_fibt_2_compare;
189+
__uint32_t xs_fibt_2_insrec;
190+
__uint32_t xs_fibt_2_delrec;
191+
__uint32_t xs_fibt_2_newroot;
192+
__uint32_t xs_fibt_2_killroot;
193+
__uint32_t xs_fibt_2_increment;
194+
__uint32_t xs_fibt_2_decrement;
195+
__uint32_t xs_fibt_2_lshift;
196+
__uint32_t xs_fibt_2_rshift;
197+
__uint32_t xs_fibt_2_split;
198+
__uint32_t xs_fibt_2_join;
199+
__uint32_t xs_fibt_2_alloc;
200+
__uint32_t xs_fibt_2_free;
201+
__uint32_t xs_fibt_2_moves;
202+
#define XFSSTAT_END_XQMSTAT (XFSSTAT_END_FIBT_V2+6)
187203
__uint32_t xs_qm_dqreclaims;
188204
__uint32_t xs_qm_dqreclaim_misses;
189205
__uint32_t xs_qm_dquot_dups;

‎fs/xfs/xfs_types.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ typedef enum {
134134

135135
typedef enum {
136136
XFS_BTNUM_BNOi, XFS_BTNUM_CNTi, XFS_BTNUM_BMAPi, XFS_BTNUM_INOi,
137-
XFS_BTNUM_MAX
137+
XFS_BTNUM_FINOi, XFS_BTNUM_MAX
138138
} xfs_btnum_t;
139139

140140
struct xfs_name {

0 commit comments

Comments
 (0)