cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Steven Whitehouse <swhiteho@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 16/27] GFS2: Use rbm for gfs2_testbit()
Date: Wed, 26 Sep 2012 09:25:37 +0100	[thread overview]
Message-ID: <1348647948-3219-17-git-send-email-swhiteho@redhat.com> (raw)
In-Reply-To: <1348647948-3219-1-git-send-email-swhiteho@redhat.com>

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: Steven Whitehouse <swhiteho@redhat.com>

diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 47d2346..3a288ce 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -117,30 +117,21 @@ static inline void gfs2_setbit(struct gfs2_rgrpd *rgd, unsigned char *buf2,
 
 /**
  * gfs2_testbit - test a bit in the bitmaps
- * @rgd: the resource group descriptor
- * @buffer: the buffer that holds the bitmaps
- * @buflen: the length (in bytes) of the buffer
- * @block: the block to read
+ * @rbm: The bit to test
  *
+ * Returns: The two bit block state of the requested bit
  */
 
-static inline unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd,
-					 const unsigned char *buffer,
-					 unsigned int buflen, u32 block)
+static inline u8 gfs2_testbit(const struct gfs2_rbm *rbm)
 {
-	const unsigned char *byte, *end;
-	unsigned char cur_state;
+	const u8 *buffer = rbm->bi->bi_bh->b_data + rbm->bi->bi_offset;
+	const u8 *byte;
 	unsigned int bit;
 
-	byte = buffer + (block / GFS2_NBBY);
-	bit = (block % GFS2_NBBY) * GFS2_BIT_SIZE;
-	end = buffer + buflen;
-
-	gfs2_assert(rgd->rd_sbd, byte < end);
-
-	cur_state = (*byte >> bit) & GFS2_BIT_MASK;
+	byte = buffer + (rbm->offset / GFS2_NBBY);
+	bit = (rbm->offset % GFS2_NBBY) * GFS2_BIT_SIZE;
 
-	return cur_state;
+	return (*byte >> bit) & GFS2_BIT_MASK;
 }
 
 /**
@@ -1837,8 +1828,7 @@ static unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block)
 	ret = gfs2_rbm_from_block(&rbm, block);
 	WARN_ON_ONCE(ret != 0);
 
-	return gfs2_testbit(rgd, rbm.bi->bi_bh->b_data + rbm.bi->bi_offset,
-			    rbm.bi->bi_len, rbm.offset);
+	return gfs2_testbit(&rbm);
 }
 
 
@@ -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
  * @rbm: the resource group information
  * @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.
- * 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)
 {
-	struct gfs2_rgrpd *rgd = rbm->rgd;
-	struct gfs2_bitmap *bi = rbm->bi;
-	u32 blk = rbm->offset;
+	struct gfs2_rbm pos = { .rgd = rbm->rgd, };
 	const unsigned int elen = *n;
-	u32 goal;
-	const u8 *buffer = NULL;
+	u64 block;
+	int ret;
 
-	*n = 0;
-	buffer = bi->bi_bh->b_data + bi->bi_offset;
-	gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1);
-	gfs2_setbit(rgd, bi->bi_clone, bi, blk,
+	*n = 1;
+	block = gfs2_rbm_to_block(rbm);
+	gfs2_trans_add_bh(rbm->rgd->rd_gl, rbm->bi->bi_bh, 1);
+	gfs2_setbit(rbm->rgd, rbm->bi->bi_clone, rbm->bi, rbm->offset,
 		    dinode ? GFS2_BLKST_DINODE : GFS2_BLKST_USED);
-	(*n)++;
-	goal = blk;
+	block++;
 	while (*n < elen) {
-		goal++;
-		if (goal >= (bi->bi_len * GFS2_NBBY))
-			break;
-		if (gfs2_testbit(rgd, buffer, bi->bi_len, goal) !=
-		    GFS2_BLKST_FREE)
+		ret = gfs2_rbm_from_block(&pos, block);
+		WARN_ON(ret);
+		if (gfs2_testbit(&pos) != GFS2_BLKST_FREE)
 			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)++;
+		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,
 		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))
 		gfs2_adjust_reservation(ip, &rbm, *nblocks);
 	ndata = *nblocks;
-- 
1.7.4



  parent reply	other threads:[~2012-09-26  8:25 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-26  8:25 [Cluster-devel] GFS2: Pre-pull patch posting (merge window) Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 01/27] GFS2: Merge two nearly identical xattr functions Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 02/27] GFS2: Remove rs_requested field from reservations Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 03/27] GFS2: Add structure to contain rgrp, bitmap, offset tuple Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 04/27] GFS2: Replace rgblk_search with gfs2_rbm_find Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 05/27] GFS2: Update gfs2_get_block_type() to use rbm Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 06/27] GFS2: Update rgblk_free() " Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 07/27] GFS2: Use RB_CLEAR_NODE() rather than rb_init_node() Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 08/27] GFS2: Fix case where reservation finished at end of rgrp Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 09/27] GFS2: rbm code cleanup Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 10/27] GFS2: change function gfs2_direct_IO to use a normal gfs2_glock_dq Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 11/27] GFS2: inline __gfs2_glock_schedule_for_reclaim Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 12/27] GFS2: Combine functions gfs2_glock_wait and wait_on_holder Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 13/27] GFS2: Combine functions gfs2_glock_dq_wait and wait_on_demote Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 14/27] GFS2: Eliminate redundant calls to may_grant Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 15/27] GFS2: Eliminate unnecessary check for state > 3 in bitfit Steven Whitehouse
2012-09-26  8:25 ` Steven Whitehouse [this message]
2012-09-26  8:25 ` [Cluster-devel] [PATCH 17/27] GFS2: Use rbm for gfs2_setbit() Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 18/27] GFS2: Fix ->show_options() for statfs slow Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 19/27] GFS2: Fall back to ignoring reservations, if there are no other blocks left Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 20/27] GFS2: Improve block reservation tracing Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 21/27] GFS2: Fix unclaimed_blocks() wrapping bug and clean up Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 22/27] GFS2: Stop block extents at the end of bitmaps Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 23/27] GFS2: Get rid of I_MUTEX_QUOTA usage Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 24/27] GFS2: Consolidate free block searching functions Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 25/27] GFS2: Fix infinite loop in rbm_find Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 26/27] GFS2: fix s_writers.counter imbalance in gfs2_ail_empty_gl Steven Whitehouse
2012-09-26  8:25 ` [Cluster-devel] [PATCH 27/27] GFS2: Write out dirty inode metadata in delayed deletes Steven Whitehouse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1348647948-3219-17-git-send-email-swhiteho@redhat.com \
    --to=swhiteho@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).