This patch eliminates height parameters from function gfs2_bmap_alloc. Function find_metapath determines the metapath's "find height", also known as the desired height. Function lookup_metapath determines the metapath's "actual height", previously known as starting height or sheight. Function gfs2_bmap_alloc now gets both height values from the metapath. This simplification was done as a step toward switching the block_map functions to using iomap.
Signed-off-by: Bob Peterson <[email protected]> --- fs/gfs2/bmap.c | 65 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index f50933a..774bdb8 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c @@ -36,6 +36,8 @@ struct metapath { struct buffer_head *mp_bh[GFS2_MAX_META_HEIGHT]; __u16 mp_list[GFS2_MAX_META_HEIGHT]; + int mp_fheight; /* find_metapath height */ + int mp_aheight; /* actual height (lookup height) */ }; struct strip_mine { @@ -240,9 +242,9 @@ static void find_metapath(const struct gfs2_sbd *sdp, u64 block, { unsigned int i; + mp->mp_fheight = height; for (i = height; i--;) mp->mp_list[i] = do_div(block, sdp->sd_inptrs); - } static inline unsigned int metapath_branch_start(const struct metapath *mp) @@ -323,15 +325,20 @@ static int lookup_metapath(struct gfs2_inode *ip, struct metapath *mp) for (x = 0; x < end_of_metadata; x++) { ptr = metapointer(x, mp); dblock = be64_to_cpu(*ptr); - if (!dblock) - return x + 1; + if (!dblock) { + ret = x + 1; + goto out; + } ret = gfs2_meta_indirect_buffer(ip, x+1, dblock, &mp->mp_bh[x+1]); if (ret) - return ret; + goto out; } - return ip->i_height; + ret = ip->i_height; +out: + mp->mp_aheight = ret; + return ret; } static inline void release_metapath(struct metapath *mp) @@ -427,9 +434,7 @@ enum alloc_state { * @inode: The GFS2 inode * @lblock: The logical starting block of the extent * @zero_new: True if newly allocated blocks should be zeroed - * @mp: The metapath - * @sheight: The starting height (i.e. whats already mapped) - * @height: The height to build to + * @mp: The metapath, with proper height information calculated * @maxlen: The max number of data blocks to alloc * @dblock: Pointer to the physical block allocated * @dblks: Pointer to an int number of data blocks in the span @@ -450,8 +455,6 @@ enum alloc_state { static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock, bool zero_new, struct metapath *mp, - const unsigned int sheight, - const unsigned int height, const size_t maxlen, sector_t *dblock, unsigned int *dblks) { @@ -462,21 +465,21 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock, u64 bn; unsigned n, i, blks, alloced = 0, iblks = 0, branch_start = 0; unsigned ptrs_per_blk; - const unsigned end_of_metadata = height - 1; + const unsigned end_of_metadata = mp->mp_fheight - 1; int ret; int eob = 0; enum alloc_state state; __be64 *ptr; __be64 zero_bn = 0; - BUG_ON(sheight < 1); + BUG_ON(mp->mp_aheight < 1); BUG_ON(dibh == NULL); *dblock = 0; *dblks = 0; gfs2_trans_add_meta(ip->i_gl, dibh); - if (height == sheight) { + if (mp->mp_fheight == mp->mp_aheight) { struct buffer_head *bh; /* Bottom indirect block exists, find unalloced extent size */ ptr = metapointer(end_of_metadata, mp); @@ -487,26 +490,27 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock, state = ALLOC_DATA; } else { /* Need to allocate indirect blocks */ - ptrs_per_blk = height > 1 ? sdp->sd_inptrs : sdp->sd_diptrs; + ptrs_per_blk = mp->mp_fheight > 1 ? sdp->sd_inptrs : + sdp->sd_diptrs; *dblks = min(maxlen, (size_t)(ptrs_per_blk - mp->mp_list[end_of_metadata])); - if (height == ip->i_height) { + if (mp->mp_fheight == ip->i_height) { /* Writing into existing tree, extend tree down */ - iblks = height - sheight; + iblks = mp->mp_fheight - mp->mp_aheight; state = ALLOC_GROW_DEPTH; } else { /* Building up tree height */ state = ALLOC_GROW_HEIGHT; - iblks = height - ip->i_height; + iblks = mp->mp_fheight - ip->i_height; branch_start = metapath_branch_start(mp); - iblks += (height - branch_start); + iblks += (mp->mp_fheight - branch_start); } } /* start of the second part of the function (state machine) */ blks = *dblks + iblks; - i = sheight; + i = mp->mp_aheight; do { int error; n = blks - alloced; @@ -524,9 +528,10 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock, sizeof(struct gfs2_dinode)); zero_bn = *ptr; } - for (; i - 1 < height - ip->i_height && n > 0; i++, n--) + for (; i - 1 < mp->mp_fheight - ip->i_height && n > 0; + i++, n--) gfs2_indirect_init(mp, ip->i_gl, i, 0, bn++); - if (i - 1 == height - ip->i_height) { + if (i - 1 == mp->mp_fheight - ip->i_height) { i--; gfs2_buffer_copy_tail(mp->mp_bh[i], sizeof(struct gfs2_meta_header), @@ -538,7 +543,7 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock, sizeof(struct gfs2_meta_header)); *ptr = zero_bn; state = ALLOC_GROW_DEPTH; - for(i = branch_start; i < height; i++) { + for(i = branch_start; i < mp->mp_fheight; i++) { if (mp->mp_bh[i] == NULL) break; brelse(mp->mp_bh[i]); @@ -550,12 +555,12 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock, break; /* Branching from existing tree */ case ALLOC_GROW_DEPTH: - if (i > 1 && i < height) + if (i > 1 && i < mp->mp_fheight) gfs2_trans_add_meta(ip->i_gl, mp->mp_bh[i-1]); - for (; i < height && n > 0; i++, n--) + for (; i < mp->mp_fheight && n > 0; i++, n--) gfs2_indirect_init(mp, ip->i_gl, i, mp->mp_list[i-1], bn++); - if (i == height) + if (i == mp->mp_fheight) state = ALLOC_DATA; if (n == 0) break; @@ -582,7 +587,7 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock, } } while ((state != ALLOC_DATA) || !(*dblock)); - ip->i_height = height; + ip->i_height = mp->mp_fheight; gfs2_add_inode_blocks(&ip->i_inode, alloced); gfs2_dinode_out(ip, mp->mp_bh[0]->b_data); return 0; @@ -644,13 +649,13 @@ int gfs2_block_map(struct inode *inode, sector_t lblock, while (size > arr[height]) height++; find_metapath(sdp, lblock, &mp, height); - ret = 1; + mp.mp_aheight = 1; if (height > ip->i_height || gfs2_is_stuffed(ip)) goto do_alloc; ret = lookup_metapath(ip, &mp); if (ret < 0) goto out; - if (ret != ip->i_height) + if (mp.mp_aheight != ip->i_height) goto do_alloc; ptr = metapointer(ip->i_height - 1, &mp); if (*ptr == 0) @@ -679,8 +684,8 @@ int gfs2_block_map(struct inode *inode, sector_t lblock, /* At this point ret is the tree depth of already allocated blocks */ if (buffer_zeronew(bh_map)) zero_new = true; - ret = gfs2_bmap_alloc(inode, lblock, zero_new, &mp, ret, height, - maxlen, &dblock, &dblks); + ret = gfs2_bmap_alloc(inode, lblock, zero_new, &mp, maxlen, &dblock, + &dblks); if (ret == 0) { map_bh(bh_map, inode->i_sb, dblock); bh_map->b_size = dblks << inode->i_blkbits; -- 2.7.4
