cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: swhiteho@redhat.com <swhiteho@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 14/48] [GFS2] Introduce array of buffers to struct metapath
Date: Thu, 17 Apr 2008 09:38:50 +0100	[thread overview]
Message-ID: <1208421597980-git-send-email-swhiteho@redhat.com> (raw)
In-Reply-To: <12084215961690-git-send-email-swhiteho@redhat.com>

From: Steven Whitehouse <swhiteho@redhat.com>

The reason for doing this is to allow all the block mapping code
to share the same array. As a result we can remove two arguments
from lookup_metapath since they are now returned via the array.

We also add a function to drop all refs to buffer heads when we
are done with the metapath. The build_height function shares the
struct metapath, but currently still frees its own buffers, and
this will change in a future patch.

Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>

diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index 08d1be4..2011dd2 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -33,6 +33,7 @@
  * keep it small.
  */
 struct metapath {
+	struct buffer_head *mp_bh[GFS2_MAX_META_HEIGHT];
 	__u16 mp_list[GFS2_MAX_META_HEIGHT];
 };
 
@@ -185,12 +186,11 @@ out:
  * Returns: errno
  */
 
-static int build_height(struct inode *inode, unsigned height)
+static int build_height(struct inode *inode, struct metapath *mp, unsigned height)
 {
 	struct gfs2_inode *ip = GFS2_I(inode);
 	unsigned new_height = height - ip->i_height;
 	struct buffer_head *dibh;
-	struct buffer_head *blocks[GFS2_MAX_META_HEIGHT];
 	struct gfs2_dinode *di;
 	int error;
 	__be64 *bp;
@@ -206,29 +206,29 @@ static int build_height(struct inode *inode, unsigned height)
 
 	for(n = 0; n < new_height; n++) {
 		bn = gfs2_alloc_meta(ip);
-		blocks[n] = gfs2_meta_new(ip->i_gl, bn);
-		gfs2_trans_add_bh(ip->i_gl, blocks[n], 1);
+		mp->mp_bh[n] = gfs2_meta_new(ip->i_gl, bn);
+		gfs2_trans_add_bh(ip->i_gl, mp->mp_bh[n], 1);
 	}
 
 	n = 0;
-	bn = blocks[0]->b_blocknr;
+	bn = mp->mp_bh[0]->b_blocknr;
 	if (new_height > 1) {
 		for(; n < new_height-1; n++) {
-			gfs2_metatype_set(blocks[n], GFS2_METATYPE_IN,
+			gfs2_metatype_set(mp->mp_bh[n], GFS2_METATYPE_IN,
 					  GFS2_FORMAT_IN);
-			gfs2_buffer_clear_tail(blocks[n],
+			gfs2_buffer_clear_tail(mp->mp_bh[n],
 					       sizeof(struct gfs2_meta_header));
-			bp = (__be64 *)(blocks[n]->b_data +
+			bp = (__be64 *)(mp->mp_bh[n]->b_data +
 				     sizeof(struct gfs2_meta_header));
-			*bp = cpu_to_be64(blocks[n+1]->b_blocknr);
-			brelse(blocks[n]);
-			blocks[n] = NULL;
+			*bp = cpu_to_be64(mp->mp_bh[n+1]->b_blocknr);
+			brelse(mp->mp_bh[n]);
+			mp->mp_bh[n] = NULL;
 		}
 	}
-	gfs2_metatype_set(blocks[n], GFS2_METATYPE_IN, GFS2_FORMAT_IN);
-	gfs2_buffer_copy_tail(blocks[n], sizeof(struct gfs2_meta_header),
+	gfs2_metatype_set(mp->mp_bh[n], GFS2_METATYPE_IN, GFS2_FORMAT_IN);
+	gfs2_buffer_copy_tail(mp->mp_bh[n], sizeof(struct gfs2_meta_header),
 			      dibh, sizeof(struct gfs2_dinode));
-	brelse(blocks[n]);
+	brelse(mp->mp_bh[n]);
 	gfs2_trans_add_bh(ip->i_gl, dibh, 1);
 	di = (struct gfs2_dinode *)dibh->b_data;
 	gfs2_buffer_clear_tail(dibh, sizeof(struct gfs2_dinode));
@@ -314,7 +314,6 @@ static void find_metapath(struct gfs2_inode *ip, u64 block,
 
 /**
  * metapointer - Return pointer to start of metadata in a buffer
- * @bh: The buffer
  * @height: The metadata height (0 = dinode)
  * @mp: The metapath
  *
@@ -323,9 +322,10 @@ static void find_metapath(struct gfs2_inode *ip, u64 block,
  * metadata tree.
  */
 
-static inline __be64 *metapointer(struct buffer_head *bh, int *boundary,
-			       unsigned int height, const struct metapath *mp)
+static inline __be64 *metapointer(int *boundary, unsigned int height,
+				  const struct metapath *mp)
 {
+	struct buffer_head *bh = mp->mp_bh[height];
 	unsigned int head_size = (height > 0) ?
 		sizeof(struct gfs2_meta_header) : sizeof(struct gfs2_dinode);
 	__be64 *ptr;
@@ -339,7 +339,6 @@ static inline __be64 *metapointer(struct buffer_head *bh, int *boundary,
 /**
  * lookup_block - Get the next metadata block in metadata tree
  * @ip: The GFS2 inode
- * @bh: Buffer containing the pointers to metadata blocks
  * @height: The height of the tree (0 = dinode)
  * @mp: The metapath
  * @create: Non-zero if we may create a new meatdata block
@@ -352,12 +351,12 @@ static inline __be64 *metapointer(struct buffer_head *bh, int *boundary,
  *
  */
 
-static int lookup_block(struct gfs2_inode *ip, struct buffer_head *bh,
-			unsigned int height, struct metapath *mp, int create,
+static int lookup_block(struct gfs2_inode *ip, unsigned int height,
+			struct metapath *mp, int create,
 			int *new, u64 *block)
 {
 	int boundary;
-	__be64 *ptr = metapointer(bh, &boundary, height, mp);
+	__be64 *ptr = metapointer(&boundary, height, mp);
 
 	if (*ptr) {
 		*block = be64_to_cpu(*ptr);
@@ -374,7 +373,7 @@ static int lookup_block(struct gfs2_inode *ip, struct buffer_head *bh,
 	else
 		*block = gfs2_alloc_meta(ip);
 
-	gfs2_trans_add_bh(ip->i_gl, bh, 1);
+	gfs2_trans_add_bh(ip->i_gl, mp->mp_bh[height], 1);
 
 	*ptr = cpu_to_be64(*block);
 	ip->i_di.di_blocks++;
@@ -385,32 +384,38 @@ static int lookup_block(struct gfs2_inode *ip, struct buffer_head *bh,
 }
 
 static int lookup_metapath(struct inode *inode, struct metapath *mp,
-			   int create, int *new, u64 *dblock,
-			   struct buffer_head **dibh, struct buffer_head **bh)
+			   int create, int *new, u64 *dblock)
 {
+	struct buffer_head *bh;
 	struct gfs2_inode *ip = GFS2_I(inode);
 	unsigned int end_of_metadata = ip->i_height - 1;
 	unsigned int x;
-	int ret = gfs2_meta_inode_buffer(ip, bh);
+	int ret = gfs2_meta_inode_buffer(ip, &bh);
 	if (ret)
 		return ret;
 
-	*dibh = *bh;
-	get_bh(*dibh);
+	mp->mp_bh[0] = bh;
 
 	for (x = 0; x < end_of_metadata; x++) {
-		lookup_block(ip, *bh, x, mp, create, new, dblock);
-		brelse(*bh);
-		*bh = NULL;
+		lookup_block(ip, x, mp, create, new, dblock);
 		if (!dblock)
 			return 0;
 
-		ret = gfs2_meta_indirect_buffer(ip, x+1, *dblock, *new, bh);
+		ret = gfs2_meta_indirect_buffer(ip, x+1, *dblock, *new, &mp->mp_bh[x+1]);
 		if (ret)
 			return ret;
 	}
 
-	return lookup_block(ip, *bh, end_of_metadata, mp, create, new, dblock);
+	return lookup_block(ip, end_of_metadata, mp, create, new, dblock);
+}
+
+static void release_metapath(struct metapath *mp)
+{
+	int i;
+
+	for (i = 0; i < GFS2_MAX_META_HEIGHT; i++)
+		if (mp->mp_bh[i])
+			brelse(mp->mp_bh[i]);
 }
 
 static inline void bmap_lock(struct inode *inode, int create)
@@ -449,7 +454,6 @@ int gfs2_block_map(struct inode *inode, sector_t lblock,
 	struct gfs2_inode *ip = GFS2_I(inode);
 	struct gfs2_sbd *sdp = GFS2_SB(inode);
 	unsigned int bsize = sdp->sd_sb.sb_bsize;
-	struct buffer_head *bh = NULL;
 	int error = 0;
 	int new = 0;
 	u64 dblock = 0;
@@ -457,13 +461,13 @@ int gfs2_block_map(struct inode *inode, sector_t lblock,
 	unsigned int maxlen = bh_map->b_size >> inode->i_blkbits;
 	struct metapath mp;
 	u64 size;
-	struct buffer_head *dibh = NULL;
 	const u64 *arr = sdp->sd_heightsize;
 	BUG_ON(maxlen == 0);
 
 	if (gfs2_assert_warn(sdp, !gfs2_is_stuffed(ip)))
 		return 0;
 
+	memset(mp.mp_bh, 0, sizeof(mp.mp_bh));
 	bmap_lock(inode, create);
 	clear_buffer_mapped(bh_map);
 	clear_buffer_new(bh_map);
@@ -480,13 +484,13 @@ int gfs2_block_map(struct inode *inode, sector_t lblock,
 			goto out_ok;
 		while (size > arr[height])
 			height++;
-		error = build_height(inode, height);
+		error = build_height(inode, &mp, height);
 		if (error)
 			goto out_fail;
 	}
 
 	find_metapath(ip, lblock, &mp);
-	error = lookup_metapath(inode, &mp, create, &new, &dblock, &dibh, &bh);
+	error = lookup_metapath(inode, &mp, create, &new, &dblock);
 	if (error < 0)
 		goto out_fail;
 	boundary = error;
@@ -496,17 +500,15 @@ int gfs2_block_map(struct inode *inode, sector_t lblock,
 		if (boundary)
 			set_buffer_boundary(bh_map);
 		if (new) {
-			gfs2_trans_add_bh(ip->i_gl, dibh, 1);
-			gfs2_dinode_out(ip, dibh->b_data);
+			gfs2_trans_add_bh(ip->i_gl, mp.mp_bh[0], 1);
+			gfs2_dinode_out(ip, mp.mp_bh[0]->b_data);
 			set_buffer_new(bh_map);
-			goto out_brelse;
+			goto out_ok;
 		}
 		while(--maxlen && !buffer_boundary(bh_map)) {
-			unsigned int end_of_metadata = ip->i_height - 1;
 			u64 eblock;
-
-			mp.mp_list[end_of_metadata]++;
-			boundary = lookup_block(ip, bh, end_of_metadata, &mp, 0, &new, &eblock);
+			mp.mp_list[ip->i_height - 1]++;
+			boundary = lookup_block(ip, ip->i_height - 1, &mp, 0, &new, &eblock);
 			if (eblock != ++dblock)
 				break;
 			bh_map->b_size += (1 << inode->i_blkbits);
@@ -514,14 +516,10 @@ int gfs2_block_map(struct inode *inode, sector_t lblock,
 				set_buffer_boundary(bh_map);
 		}
 	}
-out_brelse:
-	if (bh)
-		brelse(bh);
 out_ok:
 	error = 0;
 out_fail:
-	if (dibh)
-		brelse(dibh);
+	release_metapath(&mp);
 	bmap_unlock(inode, create);
 	return error;
 }
@@ -819,10 +817,11 @@ static int do_grow(struct gfs2_inode *ip, u64 size)
 
 		down_write(&ip->i_rw_mutex);
 		if (size > arr[ip->i_height]) {
+			struct metapath mp;
 			u8 height = ip->i_height;
 			while(size > arr[height])
 				height++;
-			error = build_height(&ip->i_inode, height);
+			error = build_height(&ip->i_inode, &mp, height);
 		}
 		up_write(&ip->i_rw_mutex);
 		if (error)
-- 
1.5.1.2



  reply	other threads:[~2008-04-17  8:38 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-17  8:37 [Cluster-devel] [GFS2] Pre-pull patch posting swhiteho
2008-04-17  8:38 ` [Cluster-devel] [PATCH 01/48] [GFS2] Speed up gfs2_write_alloc_required, deprecate gfs2_extent_map swhiteho
2008-04-17  8:38   ` [Cluster-devel] [PATCH 02/48] [GFS2] Streamline indirect pointer tree height calculation swhiteho
2008-04-17  8:38     ` [Cluster-devel] [PATCH 03/48] [GFS2] Get rid of unneeded parameter in gfs2_rlist_alloc swhiteho
2008-04-17  8:38       ` [Cluster-devel] [PATCH 04/48] [GFS2] Fix debug inode printing swhiteho
2008-04-17  8:38         ` [Cluster-devel] [PATCH 05/48] [GFS2] Only do lo_incore_commit once swhiteho
2008-04-17  8:38           ` [Cluster-devel] [PATCH 06/48] [GFS2] Misc fixups swhiteho
2008-04-17  8:38             ` [Cluster-devel] [PATCH 07/48] [GFS2] Only wake the reclaim daemon if we need to swhiteho
2008-04-17  8:38               ` [Cluster-devel] [PATCH 08/48] [GFS2] make gfs2_glock_hold() static swhiteho
2008-04-17  8:38                 ` [Cluster-devel] [PATCH 09/48] [GFS2] Plug an unlikely leak swhiteho
2008-04-17  8:38                   ` [Cluster-devel] [PATCH 10/48] [GFS2] Allocate gfs2_rgrpd from slab memory swhiteho
2008-04-17  8:38                     ` [Cluster-devel] [PATCH 11/48] [GFS2] Combine rg_flags and rd_flags swhiteho
2008-04-17  8:38                       ` [Cluster-devel] [PATCH 12/48] [GFS2] Get rid of gl_waiters2 swhiteho
2008-04-17  8:38                         ` [Cluster-devel] [PATCH 13/48] [GFS2] Move part of gfs2_block_map into a separate function swhiteho
2008-04-17  8:38                           ` swhiteho [this message]
2008-04-17  8:38                             ` [Cluster-devel] [PATCH 15/48] [GFS2] Add consts to various bits of rgrp.c swhiteho
2008-04-17  8:38                               ` [Cluster-devel] [PATCH 16/48] [GFS2] Eliminate gl_req_bh swhiteho
2008-04-17  8:38                                 ` [Cluster-devel] [PATCH 17/48] [GFS2] Remove lm.[ch] and distribute content swhiteho
2008-04-17  8:38                                   ` [Cluster-devel] [PATCH 18/48] [GFS2] Remove rgrp and glock version numbers swhiteho
2008-04-17  8:38                                     ` [Cluster-devel] [PATCH 19/48] [GFS2] Shrink & rename di_depth swhiteho
2008-04-17  8:38                                       ` [Cluster-devel] [PATCH 20/48] [GFS2] Remove unused counters swhiteho
2008-04-17  8:38                                         ` [Cluster-devel] [PATCH 21/48] [GFS2] Reduce inode size by merging fields swhiteho
2008-04-17  8:38                                           ` [Cluster-devel] [PATCH 22/48] [GFS2] Merge the rd_last_alloc_meta and rd_last_alloc_data fields swhiteho
2008-04-17  8:38                                             ` [Cluster-devel] [PATCH 23/48] [GFS2] Update gfs2_trans_add_unrevoke to accept extents swhiteho
2008-04-17  8:39                                               ` [Cluster-devel] [PATCH 24/48] [GFS2] Merge gfs2_alloc_meta and gfs2_alloc_data swhiteho
2008-04-17  8:39                                                 ` [Cluster-devel] [PATCH 25/48] [GFS2] Add extent allocation to block allocator swhiteho
2008-04-17  8:39                                                   ` [Cluster-devel] [PATCH 26/48] [GFS2] The case of the missing asterisk swhiteho
2008-04-17  8:39                                                     ` [Cluster-devel] [PATCH 27/48] [GFS2] Add a function to interate over an extent swhiteho
2008-04-17  8:39                                                       ` [Cluster-devel] [PATCH 28/48] [GFS2] Eliminate (almost) duplicate field from gfs2_inode swhiteho
2008-04-17  8:39                                                         ` [Cluster-devel] [PATCH 29/48] [GFS2] Get inode buffer only once per block map call swhiteho
2008-04-17  8:39                                                           ` [Cluster-devel] [PATCH 30/48] [GFS2] Fix bug where we called drop_bh incorrectly swhiteho
2008-04-17  8:39                                                             ` [Cluster-devel] [PATCH 31/48] [GFS2] be*_add_cpu conversion swhiteho
2008-04-17  8:39                                                               ` [Cluster-devel] [PATCH 32/48] [GFS2] gfs2/ops_file.c should #include "ops_inode.h" swhiteho
2008-04-17  8:39                                                                 ` [Cluster-devel] [PATCH 33/48] [GFS2] proper extern for gfs2/locking/dlm/mount.c:gdlm_ops swhiteho
2008-04-17  8:39                                                                   ` [Cluster-devel] [PATCH 34/48] [GFS2] Fix a page lock / glock deadlock swhiteho
2008-04-17  8:39                                                                     ` [Cluster-devel] [PATCH 35/48] [GFS2] Allow bmap to allocate extents swhiteho
2008-04-17  8:39                                                                       ` [Cluster-devel] [PATCH 36/48] [GFS2] fix file_system_type leak on gfs2meta mount swhiteho
2008-04-17  8:39                                                                         ` [Cluster-devel] [PATCH 37/48] [GFS2] remove gfs2_dev_iops swhiteho
2008-04-17  8:39                                                                           ` [Cluster-devel] [PATCH 38/48] [GFS2] re-support special inode swhiteho
2008-04-17  8:39                                                                             ` [Cluster-devel] [PATCH 39/48] [GFS2] Need to ensure that sector_t is 64bits for GFS2 swhiteho
2008-04-17  8:39                                                                               ` [Cluster-devel] [PATCH 40/48] [GFS2] possible null pointer dereference fixup swhiteho
2008-04-17  8:39                                                                                 ` [Cluster-devel] [PATCH 41/48] [GFS2] gfs2_adjust_quota has broken unstuffing code swhiteho
2008-04-17  8:39                                                                                   ` [Cluster-devel] [PATCH 42/48] [GFS2] Remove drop of module ref where not needed swhiteho
2008-04-17  8:39                                                                                     ` [Cluster-devel] [PATCH 43/48] [GFS2] Streamline quota lock/check for no-quota case swhiteho
2008-04-17  8:39                                                                                       ` [Cluster-devel] [PATCH 44/48] [GFS2] Faster gfs2_bitfit algorithm swhiteho
2008-04-17  8:39                                                                                         ` [Cluster-devel] [PATCH 45/48] [GFS2] fs/gfs2/recovery.c: suppress warnings swhiteho
2008-04-17  8:39                                                                                           ` [Cluster-devel] [PATCH 46/48] [GFS2] Invalidate cache at correct point swhiteho
2008-04-17  8:39                                                                                             ` [Cluster-devel] [PATCH 47/48] [GFS2] test for IS_ERR rather than 0 swhiteho
2008-04-17  8:39                                                                                               ` [Cluster-devel] [PATCH 48/48] [GFS2] fix GFP_KERNEL misuses swhiteho
2008-04-17 11:58                                                                         ` [Cluster-devel] Re: [PATCH 36/48] [GFS2] fix file_system_type leak on gfs2meta mount Christoph Hellwig

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=1208421597980-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).