diff options
author | Dave Chinner <dchinner@redhat.com> | 2012-11-13 17:40:27 -0500 |
---|---|---|
committer | Ben Myers <bpm@sgi.com> | 2012-11-13 17:40:27 -0500 |
commit | b64f3a390d3477517cbff7d613e551705540769b (patch) | |
tree | 1e82fffaf55236f3eda42f55b7a772c4baaa5d98 | |
parent | ee73259b401317117e7f5d4834c270b10b12bc8e (diff) |
xfs: use btree block initialisation functions in growfs
Factor xfs_btree_init_block() to be independent of the btree cursor,
and use the function to initialise btree blocks in the growfs code.
This makes adding support for different format btree blocks simple.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by Rich Johnston <rjohnston@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
-rw-r--r-- | fs/xfs/xfs_btree.c | 33 | ||||
-rw-r--r-- | fs/xfs/xfs_btree.h | 11 | ||||
-rw-r--r-- | fs/xfs/xfs_fsops.c | 37 |
3 files changed, 48 insertions, 33 deletions
diff --git a/fs/xfs/xfs_btree.c b/fs/xfs/xfs_btree.c index e53e317b1582..121ea99e615a 100644 --- a/fs/xfs/xfs_btree.c +++ b/fs/xfs/xfs_btree.c | |||
@@ -853,18 +853,22 @@ xfs_btree_set_sibling( | |||
853 | } | 853 | } |
854 | } | 854 | } |
855 | 855 | ||
856 | STATIC void | 856 | void |
857 | xfs_btree_init_block( | 857 | xfs_btree_init_block( |
858 | struct xfs_btree_cur *cur, | 858 | struct xfs_mount *mp, |
859 | int level, | 859 | struct xfs_buf *bp, |
860 | int numrecs, | 860 | __u32 magic, |
861 | struct xfs_btree_block *new) /* new block */ | 861 | __u16 level, |
862 | __u16 numrecs, | ||
863 | unsigned int flags) | ||
862 | { | 864 | { |
863 | new->bb_magic = cpu_to_be32(xfs_magics[cur->bc_btnum]); | 865 | struct xfs_btree_block *new = XFS_BUF_TO_BLOCK(bp); |
866 | |||
867 | new->bb_magic = cpu_to_be32(magic); | ||
864 | new->bb_level = cpu_to_be16(level); | 868 | new->bb_level = cpu_to_be16(level); |
865 | new->bb_numrecs = cpu_to_be16(numrecs); | 869 | new->bb_numrecs = cpu_to_be16(numrecs); |
866 | 870 | ||
867 | if (cur->bc_flags & XFS_BTREE_LONG_PTRS) { | 871 | if (flags & XFS_BTREE_LONG_PTRS) { |
868 | new->bb_u.l.bb_leftsib = cpu_to_be64(NULLDFSBNO); | 872 | new->bb_u.l.bb_leftsib = cpu_to_be64(NULLDFSBNO); |
869 | new->bb_u.l.bb_rightsib = cpu_to_be64(NULLDFSBNO); | 873 | new->bb_u.l.bb_rightsib = cpu_to_be64(NULLDFSBNO); |
870 | } else { | 874 | } else { |
@@ -873,6 +877,17 @@ xfs_btree_init_block( | |||
873 | } | 877 | } |
874 | } | 878 | } |
875 | 879 | ||
880 | STATIC void | ||
881 | xfs_btree_init_block_cur( | ||
882 | struct xfs_btree_cur *cur, | ||
883 | int level, | ||
884 | int numrecs, | ||
885 | struct xfs_buf *bp) | ||
886 | { | ||
887 | xfs_btree_init_block(cur->bc_mp, bp, xfs_magics[cur->bc_btnum], | ||
888 | level, numrecs, cur->bc_flags); | ||
889 | } | ||
890 | |||
876 | /* | 891 | /* |
877 | * Return true if ptr is the last record in the btree and | 892 | * Return true if ptr is the last record in the btree and |
878 | * we need to track updateѕ to this record. The decision | 893 | * we need to track updateѕ to this record. The decision |
@@ -2183,7 +2198,7 @@ xfs_btree_split( | |||
2183 | goto error0; | 2198 | goto error0; |
2184 | 2199 | ||
2185 | /* Fill in the btree header for the new right block. */ | 2200 | /* Fill in the btree header for the new right block. */ |
2186 | xfs_btree_init_block(cur, xfs_btree_get_level(left), 0, right); | 2201 | xfs_btree_init_block_cur(cur, xfs_btree_get_level(left), 0, rbp); |
2187 | 2202 | ||
2188 | /* | 2203 | /* |
2189 | * Split the entries between the old and the new block evenly. | 2204 | * Split the entries between the old and the new block evenly. |
@@ -2492,7 +2507,7 @@ xfs_btree_new_root( | |||
2492 | nptr = 2; | 2507 | nptr = 2; |
2493 | } | 2508 | } |
2494 | /* Fill in the new block's btree header and log it. */ | 2509 | /* Fill in the new block's btree header and log it. */ |
2495 | xfs_btree_init_block(cur, cur->bc_nlevels, 2, new); | 2510 | xfs_btree_init_block_cur(cur, cur->bc_nlevels, 2, nbp); |
2496 | xfs_btree_log_block(cur, nbp, XFS_BB_ALL_BITS); | 2511 | xfs_btree_log_block(cur, nbp, XFS_BB_ALL_BITS); |
2497 | ASSERT(!xfs_btree_ptr_is_null(cur, &lptr) && | 2512 | ASSERT(!xfs_btree_ptr_is_null(cur, &lptr) && |
2498 | !xfs_btree_ptr_is_null(cur, &rptr)); | 2513 | !xfs_btree_ptr_is_null(cur, &rptr)); |
diff --git a/fs/xfs/xfs_btree.h b/fs/xfs/xfs_btree.h index 5b240de104c0..c9cf2d00e236 100644 --- a/fs/xfs/xfs_btree.h +++ b/fs/xfs/xfs_btree.h | |||
@@ -378,6 +378,17 @@ xfs_btree_reada_bufs( | |||
378 | xfs_agblock_t agbno, /* allocation group block number */ | 378 | xfs_agblock_t agbno, /* allocation group block number */ |
379 | xfs_extlen_t count); /* count of filesystem blocks */ | 379 | xfs_extlen_t count); /* count of filesystem blocks */ |
380 | 380 | ||
381 | /* | ||
382 | * Initialise a new btree block header | ||
383 | */ | ||
384 | void | ||
385 | xfs_btree_init_block( | ||
386 | struct xfs_mount *mp, | ||
387 | struct xfs_buf *bp, | ||
388 | __u32 magic, | ||
389 | __u16 level, | ||
390 | __u16 numrecs, | ||
391 | unsigned int flags); | ||
381 | 392 | ||
382 | /* | 393 | /* |
383 | * Common btree core entry points. | 394 | * Common btree core entry points. |
diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c index 7b0a997cf62b..a5034af35db7 100644 --- a/fs/xfs/xfs_fsops.c +++ b/fs/xfs/xfs_fsops.c | |||
@@ -125,7 +125,6 @@ xfs_growfs_data_private( | |||
125 | xfs_extlen_t agsize; | 125 | xfs_extlen_t agsize; |
126 | xfs_extlen_t tmpsize; | 126 | xfs_extlen_t tmpsize; |
127 | xfs_alloc_rec_t *arec; | 127 | xfs_alloc_rec_t *arec; |
128 | struct xfs_btree_block *block; | ||
129 | xfs_buf_t *bp; | 128 | xfs_buf_t *bp; |
130 | int bucket; | 129 | int bucket; |
131 | int dpct; | 130 | int dpct; |
@@ -263,17 +262,14 @@ xfs_growfs_data_private( | |||
263 | error = ENOMEM; | 262 | error = ENOMEM; |
264 | goto error0; | 263 | goto error0; |
265 | } | 264 | } |
266 | block = XFS_BUF_TO_BLOCK(bp); | 265 | xfs_buf_zero(bp, 0, BBTOB(bp->b_length)); |
267 | memset(block, 0, mp->m_sb.sb_blocksize); | 266 | xfs_btree_init_block(mp, bp, XFS_ABTB_MAGIC, 0, 1, 0); |
268 | block->bb_magic = cpu_to_be32(XFS_ABTB_MAGIC); | 267 | |
269 | block->bb_level = 0; | 268 | arec = XFS_ALLOC_REC_ADDR(mp, XFS_BUF_TO_BLOCK(bp), 1); |
270 | block->bb_numrecs = cpu_to_be16(1); | ||
271 | block->bb_u.s.bb_leftsib = cpu_to_be32(NULLAGBLOCK); | ||
272 | block->bb_u.s.bb_rightsib = cpu_to_be32(NULLAGBLOCK); | ||
273 | arec = XFS_ALLOC_REC_ADDR(mp, block, 1); | ||
274 | arec->ar_startblock = cpu_to_be32(XFS_PREALLOC_BLOCKS(mp)); | 269 | arec->ar_startblock = cpu_to_be32(XFS_PREALLOC_BLOCKS(mp)); |
275 | arec->ar_blockcount = cpu_to_be32( | 270 | arec->ar_blockcount = cpu_to_be32( |
276 | agsize - be32_to_cpu(arec->ar_startblock)); | 271 | agsize - be32_to_cpu(arec->ar_startblock)); |
272 | |||
277 | error = xfs_bwrite(bp); | 273 | error = xfs_bwrite(bp); |
278 | xfs_buf_relse(bp); | 274 | xfs_buf_relse(bp); |
279 | if (error) | 275 | if (error) |
@@ -289,18 +285,15 @@ xfs_growfs_data_private( | |||
289 | error = ENOMEM; | 285 | error = ENOMEM; |
290 | goto error0; | 286 | goto error0; |
291 | } | 287 | } |
292 | block = XFS_BUF_TO_BLOCK(bp); | 288 | xfs_buf_zero(bp, 0, BBTOB(bp->b_length)); |
293 | memset(block, 0, mp->m_sb.sb_blocksize); | 289 | xfs_btree_init_block(mp, bp, XFS_ABTC_MAGIC, 0, 1, 0); |
294 | block->bb_magic = cpu_to_be32(XFS_ABTC_MAGIC); | 290 | |
295 | block->bb_level = 0; | 291 | arec = XFS_ALLOC_REC_ADDR(mp, XFS_BUF_TO_BLOCK(bp), 1); |
296 | block->bb_numrecs = cpu_to_be16(1); | ||
297 | block->bb_u.s.bb_leftsib = cpu_to_be32(NULLAGBLOCK); | ||
298 | block->bb_u.s.bb_rightsib = cpu_to_be32(NULLAGBLOCK); | ||
299 | arec = XFS_ALLOC_REC_ADDR(mp, block, 1); | ||
300 | arec->ar_startblock = cpu_to_be32(XFS_PREALLOC_BLOCKS(mp)); | 292 | arec->ar_startblock = cpu_to_be32(XFS_PREALLOC_BLOCKS(mp)); |
301 | arec->ar_blockcount = cpu_to_be32( | 293 | arec->ar_blockcount = cpu_to_be32( |
302 | agsize - be32_to_cpu(arec->ar_startblock)); | 294 | agsize - be32_to_cpu(arec->ar_startblock)); |
303 | nfree += be32_to_cpu(arec->ar_blockcount); | 295 | nfree += be32_to_cpu(arec->ar_blockcount); |
296 | |||
304 | error = xfs_bwrite(bp); | 297 | error = xfs_bwrite(bp); |
305 | xfs_buf_relse(bp); | 298 | xfs_buf_relse(bp); |
306 | if (error) | 299 | if (error) |
@@ -316,13 +309,9 @@ xfs_growfs_data_private( | |||
316 | error = ENOMEM; | 309 | error = ENOMEM; |
317 | goto error0; | 310 | goto error0; |
318 | } | 311 | } |
319 | block = XFS_BUF_TO_BLOCK(bp); | 312 | xfs_buf_zero(bp, 0, BBTOB(bp->b_length)); |
320 | memset(block, 0, mp->m_sb.sb_blocksize); | 313 | xfs_btree_init_block(mp, bp, XFS_IBT_MAGIC, 0, 0, 0); |
321 | block->bb_magic = cpu_to_be32(XFS_IBT_MAGIC); | 314 | |
322 | block->bb_level = 0; | ||
323 | block->bb_numrecs = 0; | ||
324 | block->bb_u.s.bb_leftsib = cpu_to_be32(NULLAGBLOCK); | ||
325 | block->bb_u.s.bb_rightsib = cpu_to_be32(NULLAGBLOCK); | ||
326 | error = xfs_bwrite(bp); | 315 | error = xfs_bwrite(bp); |
327 | xfs_buf_relse(bp); | 316 | xfs_buf_relse(bp); |
328 | if (error) | 317 | if (error) |