Commit c04a2ef3 authored by Steven Whitehouse's avatar Steven Whitehouse

GFS2: Use rbm for gfs2_testbit()

Change the arguments to gfs2_testbit() so that it now just takes an
rbm specifying the position of the two bit entry to return.
Signed-off-by: default avatarSteven Whitehouse <swhiteho@redhat.com>
parent 29c05b20
...@@ -117,30 +117,21 @@ static inline void gfs2_setbit(struct gfs2_rgrpd *rgd, unsigned char *buf2, ...@@ -117,30 +117,21 @@ static inline void gfs2_setbit(struct gfs2_rgrpd *rgd, unsigned char *buf2,
/** /**
* gfs2_testbit - test a bit in the bitmaps * gfs2_testbit - test a bit in the bitmaps
* @rgd: the resource group descriptor * @rbm: The bit to test
* @buffer: the buffer that holds the bitmaps
* @buflen: the length (in bytes) of the buffer
* @block: the block to read
* *
* Returns: The two bit block state of the requested bit
*/ */
static inline unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd, static inline u8 gfs2_testbit(const struct gfs2_rbm *rbm)
const unsigned char *buffer,
unsigned int buflen, u32 block)
{ {
const unsigned char *byte, *end; const u8 *buffer = rbm->bi->bi_bh->b_data + rbm->bi->bi_offset;
unsigned char cur_state; const u8 *byte;
unsigned int bit; unsigned int bit;
byte = buffer + (block / GFS2_NBBY); byte = buffer + (rbm->offset / GFS2_NBBY);
bit = (block % GFS2_NBBY) * GFS2_BIT_SIZE; bit = (rbm->offset % GFS2_NBBY) * GFS2_BIT_SIZE;
end = buffer + buflen;
gfs2_assert(rgd->rd_sbd, byte < end);
cur_state = (*byte >> bit) & GFS2_BIT_MASK; return (*byte >> bit) & GFS2_BIT_MASK;
return cur_state;
} }
/** /**
...@@ -1837,8 +1828,7 @@ static unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block) ...@@ -1837,8 +1828,7 @@ static unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block)
ret = gfs2_rbm_from_block(&rbm, block); ret = gfs2_rbm_from_block(&rbm, block);
WARN_ON_ONCE(ret != 0); WARN_ON_ONCE(ret != 0);
return gfs2_testbit(rgd, rbm.bi->bi_bh->b_data + rbm.bi->bi_offset, return gfs2_testbit(&rbm);
rbm.bi->bi_len, rbm.offset);
} }
...@@ -1846,42 +1836,35 @@ static unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block) ...@@ -1846,42 +1836,35 @@ static unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block)
* gfs2_alloc_extent - allocate an extent from a given bitmap * gfs2_alloc_extent - allocate an extent from a given bitmap
* @rbm: the resource group information * @rbm: the resource group information
* @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 * @n: The extent length (value/result)
* *
* Add the found bitmap buffer to the transaction. * Add the bitmap buffer to the transaction.
* Set the found bits to @new_state to change block's allocation state. * 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(const struct gfs2_rbm *rbm, bool dinode, static void gfs2_alloc_extent(const struct gfs2_rbm *rbm, bool dinode,
unsigned int *n) unsigned int *n)
{ {
struct gfs2_rgrpd *rgd = rbm->rgd; struct gfs2_rbm pos = { .rgd = rbm->rgd, };
struct gfs2_bitmap *bi = rbm->bi;
u32 blk = rbm->offset;
const unsigned int elen = *n; const unsigned int elen = *n;
u32 goal; u64 block;
const u8 *buffer = NULL; int ret;
*n = 0; *n = 1;
buffer = bi->bi_bh->b_data + bi->bi_offset; block = gfs2_rbm_to_block(rbm);
gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1); gfs2_trans_add_bh(rbm->rgd->rd_gl, rbm->bi->bi_bh, 1);
gfs2_setbit(rgd, bi->bi_clone, bi, blk, gfs2_setbit(rbm->rgd, rbm->bi->bi_clone, rbm->bi, rbm->offset,
dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED); dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED);
(*n)++; block++;
goal = blk;
while (*n < elen) { while (*n < elen) {
goal++; ret = gfs2_rbm_from_block(&pos, block);
if (goal >= (bi->bi_len * GFS2_NBBY)) WARN_ON(ret);
break; if (gfs2_testbit(&pos) != GFS2_BLKST_FREE)
if (gfs2_testbit(rgd, buffer, bi->bi_len, goal) !=
GFS2_BLKST_FREE)
break; break;
gfs2_setbit(rgd, bi->bi_clone, bi, goal, GFS2_BLKST_USED); gfs2_trans_add_bh(pos.rgd->rd_gl, pos.bi->bi_bh, 1);
gfs2_setbit(pos.rgd, pos.bi->bi_clone, pos.bi, pos.offset, GFS2_BLKST_USED);
(*n)++; (*n)++;
block++;
} }
blk = gfs2_bi2rgd_blk(bi, blk);
rgd->rd_last_alloc = blk + *n - 1;
return rgd->rd_data0 + blk;
} }
/** /**
...@@ -2042,7 +2025,8 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *nblocks, ...@@ -2042,7 +2025,8 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *nblocks,
goto rgrp_error; goto rgrp_error;
} }
block = gfs2_alloc_extent(&rbm, dinode, nblocks); gfs2_alloc_extent(&rbm, dinode, nblocks);
block = gfs2_rbm_to_block(&rbm);
if (gfs2_rs_active(ip->i_res)) if (gfs2_rs_active(ip->i_res))
gfs2_adjust_reservation(ip, &rbm, *nblocks); gfs2_adjust_reservation(ip, &rbm, *nblocks);
ndata = *nblocks; ndata = *nblocks;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment