提交 b3e47ca0 编写于 作者: B Bob Peterson 提交者: Steven Whitehouse

GFS2: split function rgblk_search

This patch splits function rgblk_search into a function that finds
blocks to allocate (rgblk_search) and a function that assigns those
blocks (gfs2_alloc_extent).
Signed-off-by: NBob Peterson <rpeterso@redhat.com>
Signed-off-by: NSteven Whitehouse <swhiteho@rehat.com>
上级 465f0a76
...@@ -65,8 +65,8 @@ static const char valid_change[16] = { ...@@ -65,8 +65,8 @@ static const char valid_change[16] = {
}; };
static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal, static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal,
unsigned char old_state, bool dinode, unsigned char old_state, bool dinode,
unsigned int *ndata); struct gfs2_bitmap **rbi);
/** /**
* gfs2_setbit - Set a bit in the bitmaps * gfs2_setbit - Set a bit in the bitmaps
...@@ -899,6 +899,11 @@ static int try_rgrp_fit(const struct gfs2_rgrpd *rgd, const struct gfs2_inode *i ...@@ -899,6 +899,11 @@ static int try_rgrp_fit(const struct gfs2_rgrpd *rgd, const struct gfs2_inode *i
return 0; return 0;
} }
static inline u32 gfs2_bi2rgd_blk(struct gfs2_bitmap *bi, u32 blk)
{
return (bi->bi_start * GFS2_NBBY) + blk;
}
/** /**
* try_rgrp_unlink - Look for any unlinked, allocated, but unused inodes * try_rgrp_unlink - Look for any unlinked, allocated, but unused inodes
* @rgd: The rgrp * @rgd: The rgrp
...@@ -912,19 +917,20 @@ static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip ...@@ -912,19 +917,20 @@ static void try_rgrp_unlink(struct gfs2_rgrpd *rgd, u64 *last_unlinked, u64 skip
u32 goal = 0, block; u32 goal = 0, block;
u64 no_addr; u64 no_addr;
struct gfs2_sbd *sdp = rgd->rd_sbd; struct gfs2_sbd *sdp = rgd->rd_sbd;
unsigned int n;
struct gfs2_glock *gl; struct gfs2_glock *gl;
struct gfs2_inode *ip; struct gfs2_inode *ip;
int error; int error;
int found = 0; int found = 0;
struct gfs2_bitmap *bi;
while (goal < rgd->rd_data) { while (goal < rgd->rd_data) {
down_write(&sdp->sd_log_flush_lock); down_write(&sdp->sd_log_flush_lock);
n = 1; block = rgblk_search(rgd, goal, GFS2_BLKST_UNLINKED, 0, &bi);
block = rgblk_search(rgd, goal, GFS2_BLKST_UNLINKED, 0, &n);
up_write(&sdp->sd_log_flush_lock); up_write(&sdp->sd_log_flush_lock);
if (block == BFITNOENT) if (block == BFITNOENT)
break; break;
block = gfs2_bi2rgd_blk(bi, block);
/* rgblk_search can return a block < goal, so we need to /* rgblk_search can return a block < goal, so we need to
keep it marching forward. */ keep it marching forward. */
no_addr = block + rgd->rd_data0; no_addr = block + rgd->rd_data0;
...@@ -1109,38 +1115,35 @@ static unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block) ...@@ -1109,38 +1115,35 @@ static unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block)
} }
/** /**
* rgblk_search - find a block in @old_state, change allocation * rgblk_search - find a block in @old_state
* state to @new_state
* @rgd: the resource group descriptor * @rgd: the resource group descriptor
* @goal: the goal block within the RG (start here to search for avail block) * @goal: the goal block within the RG (start here to search for avail block)
* @old_state: GFS2_BLKST_XXX the before-allocation state to find * @old_state: GFS2_BLKST_XXX the before-allocation state to find
* @dinode: TRUE if the first block we allocate is for a dinode * @dinode: TRUE if the first block we allocate is for a dinode
* @n: The extent length * @rbi: address of the pointer to the bitmap containing the block found
* *
* Walk rgrp's bitmap to find bits that represent a block in @old_state. * Walk rgrp's bitmap to find bits that represent a block in @old_state.
* Add the found bitmap buffer to the transaction.
* Set the found bits to @new_state to change block's allocation state.
* *
* This function never fails, because we wouldn't call it unless we * This function never fails, because we wouldn't call it unless we
* know (from reservation results, etc.) that a block is available. * know (from reservation results, etc.) that a block is available.
* *
* Scope of @goal and returned block is just within rgrp, not the whole * Scope of @goal is just within rgrp, not the whole filesystem.
* filesystem. * Scope of @returned block is just within bitmap, not the whole filesystem.
* *
* Returns: the block number allocated * Returns: the block number found relative to the bitmap rbi
*/ */
static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal, static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal,
unsigned char old_state, bool dinode, unsigned int *n) unsigned char old_state, bool dinode,
struct gfs2_bitmap **rbi)
{ {
struct gfs2_bitmap *bi = NULL; struct gfs2_bitmap *bi = NULL;
const u32 length = rgd->rd_length; const u32 length = rgd->rd_length;
u32 blk = BFITNOENT; u32 blk = BFITNOENT;
unsigned int buf, x; unsigned int buf, x;
const unsigned int elen = *n;
const u8 *buffer = NULL; const u8 *buffer = NULL;
*n = 0; *rbi = NULL;
/* Find bitmap block that contains bits for goal block */ /* Find bitmap block that contains bits for goal block */
for (buf = 0; buf < length; buf++) { for (buf = 0; buf < length; buf++) {
bi = rgd->rd_bits + buf; bi = rgd->rd_bits + buf;
...@@ -1187,12 +1190,32 @@ static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal, ...@@ -1187,12 +1190,32 @@ static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal,
goal = 0; goal = 0;
} }
if (blk == BFITNOENT) if (blk != BFITNOENT)
return blk; *rbi = bi;
if (old_state == GFS2_BLKST_UNLINKED) return blk;
goto out; }
/**
* gfs2_alloc_extent - allocate an extent from a given bitmap
* @rgd: the resource group descriptor
* @bi: the bitmap within the rgrp
* @blk: the block within the bitmap
* @dinode: TRUE if the first block we allocate is for a dinode
* @n: The extent length
*
* Add the found bitmap buffer to the transaction.
* Set the found bits to @new_state to change block's allocation state.
* Returns: starting block number of the extent (fs scope)
*/
static u64 gfs2_alloc_extent(struct gfs2_rgrpd *rgd, struct gfs2_bitmap *bi,
u32 blk, bool dinode, unsigned int *n)
{
const unsigned int elen = *n;
u32 goal;
const u8 *buffer = NULL;
buffer = bi->bi_bh->b_data + bi->bi_offset;
gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1); gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1);
gfs2_setbit(rgd, bi->bi_bh->b_data, bi->bi_clone, bi->bi_offset, gfs2_setbit(rgd, bi->bi_bh->b_data, bi->bi_clone, bi->bi_offset,
bi, blk, dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED); bi, blk, dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED);
...@@ -1210,8 +1233,9 @@ static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal, ...@@ -1210,8 +1233,9 @@ static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal,
bi, goal, GFS2_BLKST_USED); bi, goal, GFS2_BLKST_USED);
(*n)++; (*n)++;
} }
out: blk = gfs2_bi2rgd_blk(bi, blk);
return (bi->bi_start * GFS2_NBBY) + blk; rgd->rd_last_alloc = blk;
return rgd->rd_data0 + blk;
} }
/** /**
...@@ -1319,6 +1343,7 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *ndata, ...@@ -1319,6 +1343,7 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *ndata,
u32 goal, extlen, blk; /* block, within the rgrp scope */ u32 goal, extlen, blk; /* block, within the rgrp scope */
u64 block; /* block, within the file system scope */ u64 block; /* block, within the file system scope */
int error; int error;
struct gfs2_bitmap *bi;
/* Only happens if there is a bug in gfs2, return something distinctive /* Only happens if there is a bug in gfs2, return something distinctive
* to ensure that it is noticed. * to ensure that it is noticed.
...@@ -1333,14 +1358,15 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *ndata, ...@@ -1333,14 +1358,15 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *ndata,
else else
goal = rgd->rd_last_alloc; goal = rgd->rd_last_alloc;
blk = rgblk_search(rgd, goal, GFS2_BLKST_FREE, dinode, ndata); blk = rgblk_search(rgd, goal, GFS2_BLKST_FREE, dinode, &bi);
*ndata = 0;
/* Since all blocks are reserved in advance, this shouldn't happen */ /* Since all blocks are reserved in advance, this shouldn't happen */
if (blk == BFITNOENT) if (blk == BFITNOENT)
goto rgrp_error; goto rgrp_error;
rgd->rd_last_alloc = blk; block = gfs2_alloc_extent(rgd, bi, blk, dinode, ndata);
block = rgd->rd_data0 + blk;
if (!dinode) { if (!dinode) {
ip->i_goal = block + *ndata - 1; ip->i_goal = block + *ndata - 1;
error = gfs2_meta_inode_buffer(ip, &dibh); error = gfs2_meta_inode_buffer(ip, &dibh);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册