Pass the resource group and starting position to gfs2_adjust_reservation directly instead of passing an rbm. With this change, gfs2_alloc_blocks no longer needs the rbm after calling gfs2_alloc_extent, so gfs2_alloc_extent can modify the rbm instead of creating a copy.
Signed-off-by: Andreas Gruenbacher <agrue...@redhat.com> --- fs/gfs2/rgrp.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c index 14ffa86b6b1c5..7a93568fdc709 100644 --- a/fs/gfs2/rgrp.c +++ b/fs/gfs2/rgrp.c @@ -2207,34 +2207,32 @@ void gfs2_inplace_release(struct gfs2_inode *ip) /** * gfs2_alloc_extent - allocate an extent from a given bitmap - * @rbm: the resource group information + * @rbm: The position in the resource group * @dinode: TRUE if the first block we allocate is for a dinode * @n: The extent length (value/result) * + * Side effects: + * - Modifies rbm. + * * Add the bitmap buffer to the transaction. * Set the found bits to @new_state to change block's allocation state. */ -static void gfs2_alloc_extent(const struct gfs2_rbm *rbm, bool dinode, +static void gfs2_alloc_extent(struct gfs2_rbm *rbm, bool dinode, unsigned int *n) { - struct gfs2_rbm pos = { .rgd = rbm->rgd, }; const unsigned int elen = *n; - u64 block; int ret; *n = 1; - block = gfs2_rbm_to_block(rbm); gfs2_trans_add_meta(rbm->rgd->rd_gl, rbm_bi(rbm)->bi_bh); gfs2_setbit(rbm, true, dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED); - block++; while (*n < elen) { - ret = gfs2_rbm_from_block(&pos, block); - if (ret || gfs2_testbit(&pos, true) != GFS2_BLKST_FREE) + ret = gfs2_rbm_incr(rbm); + if (ret || gfs2_testbit(rbm, true) != GFS2_BLKST_FREE) break; - gfs2_trans_add_meta(pos.rgd->rd_gl, rbm_bi(&pos)->bi_bh); - gfs2_setbit(&pos, true, GFS2_BLKST_USED); + gfs2_trans_add_meta(rbm->rgd->rd_gl, rbm_bi(rbm)->bi_bh); + gfs2_setbit(rbm, true, GFS2_BLKST_USED); (*n)++; - block++; } } @@ -2322,7 +2320,8 @@ static void gfs2_rgrp_error(struct gfs2_rgrpd *rgd) /** * gfs2_adjust_reservation - Adjust (or remove) a reservation after allocation * @ip: The inode we have just allocated blocks for - * @rbm: The start of the allocated blocks + * @rgd: The resource group + * @start: The start of the reservation * @len: The extent length * * Adjusts a reservation after an allocation has taken place. If the @@ -2331,15 +2330,13 @@ static void gfs2_rgrp_error(struct gfs2_rgrpd *rgd) */ static void gfs2_adjust_reservation(struct gfs2_inode *ip, - const struct gfs2_rbm *rbm, unsigned len) + struct gfs2_rgrpd *rgd, + u64 start, unsigned len) { struct gfs2_blkreserv *rs = &ip->i_res; - struct gfs2_rgrpd *rgd = rbm->rgd; spin_lock(&rgd->rd_rsspin); if (gfs2_rs_active(rs)) { - u64 start = gfs2_rbm_to_block(rbm); - if (rs->rs_start == start) { unsigned int rlen; @@ -2429,11 +2426,11 @@ int gfs2_alloc_blocks(struct gfs2_inode *ip, u64 *bn, unsigned int *nblocks, goto rgrp_error; } - gfs2_alloc_extent(&rbm, dinode, nblocks); block = gfs2_rbm_to_block(&rbm); + gfs2_alloc_extent(&rbm, dinode, nblocks); rbm.rgd->rd_last_alloc = block - rbm.rgd->rd_data0; if (gfs2_rs_active(&ip->i_res)) - gfs2_adjust_reservation(ip, &rbm, *nblocks); + gfs2_adjust_reservation(ip, rbm.rgd, block, *nblocks); ndata = *nblocks; if (dinode) ndata--; -- 2.20.1