cluster: STABLE3 - libgfs2, fsck.gfs2: simplify block_query code

Bob Peterson rpeterso at fedoraproject.org
Tue Jan 26 21:19:34 UTC 2010


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=48cd85089a1a12d4c36fca20b9b3fed362b8f4b7
Commit:        48cd85089a1a12d4c36fca20b9b3fed362b8f4b7
Parent:        2f222faced71bb3a90d1ed9d1dd4af3bede7eaf6
Author:        Bob Peterson <bob at ganesha.peterson>
AuthorDate:    Wed Jan 20 12:31:38 2010 -0600
Committer:     Bob Peterson <rpeterso at redhat.com>
CommitterDate: Tue Jan 26 14:39:28 2010 -0600

libgfs2, fsck.gfs2: simplify block_query code

This patch simplifies the block query code.  Now that the blockmap
code doesn't have the duplicate block reference responsibilities,
we don't need the query info to be in its own structure.  The
block query can be reduced to a simple fetch from memory and mask
off the bits we need.  The block query used to check for a valid
block range.  Now, for performance reasons, that's the
responsibility of the caller.  Most of the callers check for a
valid range anyway, so checking it in the query was a waste of
time.  This is for better performance and makes the code simpler
and more readable.

rhbz#455300
---
 gfs2/fsck/fsck.h          |    2 +-
 gfs2/fsck/lost_n_found.c  |   10 ++---
 gfs2/fsck/main.c          |   16 +++-----
 gfs2/fsck/metawalk.c      |   13 ++-----
 gfs2/fsck/pass1.c         |   81 +++++++++++----------------------------------
 gfs2/fsck/pass1b.c        |   24 +++++--------
 gfs2/fsck/pass1c.c        |   28 +++++----------
 gfs2/fsck/pass2.c         |   51 ++++++++++++----------------
 gfs2/fsck/pass3.c         |   56 ++++++++++--------------------
 gfs2/fsck/pass4.c         |   27 +++++++--------
 gfs2/fsck/pass5.c         |   16 ++++----
 gfs2/fsck/util.c          |    6 ++--
 gfs2/fsck/util.h          |   15 ++++++++-
 gfs2/libgfs2/block_list.c |   15 --------
 gfs2/libgfs2/libgfs2.h    |    6 ---
 15 files changed, 131 insertions(+), 235 deletions(-)

diff --git a/gfs2/fsck/fsck.h b/gfs2/fsck/fsck.h
index 05a1147..a15bc33 100644
--- a/gfs2/fsck/fsck.h
+++ b/gfs2/fsck/fsck.h
@@ -44,7 +44,7 @@ struct dir_info
 struct dir_status {
 	uint8_t dotdir:1;
 	uint8_t dotdotdir:1;
-	struct gfs2_block_query q;
+	uint8_t q;
 	uint32_t entry_count;
 };
 
diff --git a/gfs2/fsck/lost_n_found.c b/gfs2/fsck/lost_n_found.c
index ffa88b2..bc07d7b 100644
--- a/gfs2/fsck/lost_n_found.c
+++ b/gfs2/fsck/lost_n_found.c
@@ -12,6 +12,7 @@
 #include "libgfs2.h"
 #include "lost_n_found.h"
 #include "link.h"
+#include "util.h"
 
 /* add_inode_to_lf - Add dir entry to lost+found for the inode
  * @ip: inode to add to lost + found
@@ -29,16 +30,13 @@ int add_inode_to_lf(struct gfs2_inode *ip){
 	__be32 inode_type;
 
 	if(!lf_dip) {
-		struct gfs2_block_query q = {0};
+		uint8_t q;
 
 		log_info( _("Locating/Creating lost and found directory\n"));
 
         lf_dip = createi(ip->i_sbd->md.rooti, "lost+found", S_IFDIR | 0700, 0);
-	if(gfs2_block_check(ip->i_sbd, bl, lf_dip->i_di.di_num.no_addr, &q)) {
-			stack;
-			return -1;
-		}
-		if(q.block_type != gfs2_inode_dir) {
+		q = block_type(lf_dip->i_di.di_num.no_addr);
+		if(q != gfs2_inode_dir) {
 			/* This is a new lost+found directory, so set its
 			 * block type and increment link counts for
 			 * the directories */
diff --git a/gfs2/fsck/main.c b/gfs2/fsck/main.c
index 34cc045..c2f9722 100644
--- a/gfs2/fsck/main.c
+++ b/gfs2/fsck/main.c
@@ -15,6 +15,7 @@
 #include "libgfs2.h"
 #include "fsck.h"
 #include "osi_list.h"
+#include "util.h"
 
 struct gfs2_options opts = {0};
 struct gfs2_inode *lf_dip; /* Lost and found directory inode */
@@ -161,22 +162,17 @@ static int check_system_inode(struct gfs2_inode *sysinode, const char *filename,
 		
 		/* FIXME: check this block's validity */
 
-		if(gfs2_block_check(sysinode->i_sbd, bl, iblock, &ds.q)) {
-			log_crit( _("Can't get %s inode block %" PRIu64 " (0x%"
-				 PRIx64 ") from block list\n"), filename,
-				 iblock, iblock);
-			return -1;
-		}
+		ds.q = block_type(iblock);
 		/* If the inode exists but the block is marked      */
 		/* free, we might be recovering from a corrupt      */
 		/* bitmap.  In that case, don't rebuild the inode.  */
 		/* Just reuse the inode and fix the bitmap.         */
-		if (ds.q.block_type == gfs2_block_free) {
+		if (ds.q == gfs2_block_free) {
 			log_info( _("The inode exists but the block is not marked 'in use'; fixing it.\n"));
 			gfs2_blockmap_set(sysinode->i_sbd, bl,
 				       sysinode->i_di.di_num.no_addr,
 				       mark);
-			ds.q.block_type = mark;
+			ds.q = mark;
 			if (mark == gfs2_inode_dir)
 				add_to_dir_list(sysinode->i_sbd,
 						sysinode->i_di.di_num.no_addr);
@@ -188,14 +184,14 @@ static int check_system_inode(struct gfs2_inode *sysinode, const char *filename,
 	 * create a new inode and get it all setup - of course,
 	 * everything will be in lost+found then, but we *need* our
 	 * system inodes before we can do any of that. */
-	if(!sysinode || ds.q.block_type != mark) {
+	if(!sysinode || ds.q != mark) {
 		log_err( _("Invalid or missing %s system inode.\n"), filename);
 		if (query(_("Create new %s system inode? (y/n) "), filename)) {
 			builder(sysinode->i_sbd);
 			gfs2_blockmap_set(sysinode->i_sbd, bl,
 				       sysinode->i_di.di_num.no_addr,
 				       mark);
-			ds.q.block_type = mark;
+			ds.q = mark;
 			if (mark == gfs2_inode_dir)
 				add_to_dir_list(sysinode->i_sbd,
 						sysinode->i_di.di_num.no_addr);
diff --git a/gfs2/fsck/metawalk.c b/gfs2/fsck/metawalk.c
index aaa1144..d348123 100644
--- a/gfs2/fsck/metawalk.c
+++ b/gfs2/fsck/metawalk.c
@@ -1086,7 +1086,7 @@ int remove_dentry_from_dir(struct gfs2_sbd *sbp, uint64_t dir,
 			   uint64_t dentryblock)
 {
 	struct metawalk_fxns remove_dentry_fxns = {0};
-	struct gfs2_block_query q;
+	uint8_t q;
 	int error;
 
 	log_debug( _("Removing dentry %" PRIu64 " (0x%" PRIx64 ") from directory %"
@@ -1098,11 +1098,8 @@ int remove_dentry_from_dir(struct gfs2_sbd *sbp, uint64_t dir,
 	remove_dentry_fxns.private = &dentryblock;
 	remove_dentry_fxns.check_dentry = remove_dentry;
 
-	if(gfs2_block_check(sbp, bl, dir, &q)) {
-		stack;
-		return -1;
-	}
-	if(q.block_type != gfs2_inode_dir) {
+	q = block_type(dir);
+	if(q != gfs2_inode_dir) {
 		log_info( _("Parent block is not a directory...ignoring\n"));
 		return 1;
 	}
@@ -1193,11 +1190,7 @@ int delete_blocks(struct gfs2_inode *ip, uint64_t block,
 		  struct gfs2_buffer_head **bh, const char *btype,
 		  void *private)
 {
-	struct gfs2_block_query q = {0};
-
 	if (gfs2_check_range(ip->i_sbd, block) == 0) {
-		if (gfs2_block_check(ip->i_sbd, bl, block, &q))
-			return 0;
 		if(!is_duplicate(block)) {
 			log_info( _("Deleting %s block %lld (0x%llx) as part "
 				    "of inode %lld (0x%llx)\n"), btype,
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index 5baf351..2d1aed5 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -83,7 +83,7 @@ static int leaf(struct gfs2_inode *ip, uint64_t block,
 static int check_metalist(struct gfs2_inode *ip, uint64_t block,
 			  struct gfs2_buffer_head **bh, void *private)
 {
-	struct gfs2_block_query q = {0};
+	uint8_t q;
 	int found_dup = 0;
 	struct gfs2_buffer_head *nbh;
 	struct block_count *bc = (struct block_count *)private;
@@ -97,13 +97,10 @@ static int check_metalist(struct gfs2_inode *ip, uint64_t block,
 
 		return 1;
 	}
-	if(gfs2_block_check(ip->i_sbd, bl, block, &q)) {
-		stack;
-		return -1;
-	}
-	if(q.block_type != gfs2_block_free) {
+	q = block_type(block);
+	if(q != gfs2_block_free) {
 		log_err( _("Found duplicate block referenced as metadata in "
-			   "indirect block - was marked %d\n"), q.block_type);
+			   "indirect block - was marked %d\n"), q);
 		gfs2_dup_set(block);
 		found_dup = 1;
 	}
@@ -133,7 +130,7 @@ static int check_metalist(struct gfs2_inode *ip, uint64_t block,
 
 static int check_data(struct gfs2_inode *ip, uint64_t block, void *private)
 {
-	struct gfs2_block_query q = {0};
+	uint8_t q;
 	struct block_count *bc = (struct block_count *) private;
 	int error = 0, btype;
 
@@ -150,20 +147,15 @@ static int check_data(struct gfs2_inode *ip, uint64_t block, void *private)
 			       gfs2_bad_block);
 		return 1;
 	}
-	if(gfs2_block_check(ip->i_sbd, bl, block, &q)) {
-		stack;
-		log_err( _("Found bad block referenced as data at %"
-			   PRIu64 " (0x%"PRIx64 ")\n"), block, block);
-		return -1;
-	}
-	if(q.block_type != gfs2_block_free) {
+	q = block_type(block);
+	if(q != gfs2_block_free) {
 		log_err( _("Found duplicate block referenced as data at %"
 			   PRIu64 " (0x%"PRIx64 ")\n"), block, block);
-		if (q.block_type != gfs2_meta_inval) {
+		if (q != gfs2_meta_inval) {
 			gfs2_dup_set(block);
 			/* If the prev ref was as data, this is likely a data
 			   block, so keep the block count for both refs. */
-			if (q.block_type == gfs2_block_used)
+			if (q == gfs2_block_used)
 				bc->data_count++;
 			return 1;
 		}
@@ -244,11 +236,6 @@ static int ask_remove_inode_eattr(struct gfs2_inode *ip,
 		 (unsigned long long)ip->i_di.di_num.no_addr);
 	if (query( _("Clear all Extended Attributes from the "
 		     "inode? (y/n) "))) {
-		struct gfs2_block_query q;
-		if(gfs2_block_check(ip->i_sbd, bl, ip->i_di.di_eattr, &q)) {
-			stack;
-			return -1;
-		}
 		if (!remove_inode_eattr(ip, bc,
 					is_duplicate(ip->i_di.di_eattr)))
 			log_err( _("Extended attributes were removed.\n"));
@@ -305,7 +292,7 @@ static int check_eattr_indir(struct gfs2_inode *ip, uint64_t indirect,
 {
 	struct gfs2_sbd *sdp = ip->i_sbd;
 	int ret = 0;
-	struct gfs2_block_query q = {0};
+	uint8_t q;
 	struct block_count *bc = (struct block_count *) private;
 
 	/* This inode contains an eattr - it may be invalid, but the
@@ -318,10 +305,7 @@ static int check_eattr_indir(struct gfs2_inode *ip, uint64_t indirect,
 		 * in pass1c */
 		return 1;
 	}
-	if(gfs2_block_check(sdp, bl, indirect, &q)) {
-		stack;
-		return -1;
-	}
+	q = block_type(indirect);
 
 	/* Special duplicate processing:  If we have an EA block,
 	   check if it really is an EA.  If it is, let duplicate
@@ -329,7 +313,7 @@ static int check_eattr_indir(struct gfs2_inode *ip, uint64_t indirect,
 	   count it as a duplicate. */
 	*bh = bread(sdp, indirect);
 	if(gfs2_check_meta(*bh, GFS2_METATYPE_IN)) {
-		if(q.block_type != gfs2_block_free) { /* Duplicate? */
+		if(q != gfs2_block_free) { /* Duplicate? */
 			if (!clear_eas(ip, bc, indirect, 1,
 				       _("Bad indirect Extended Attribute "
 					 "duplicate found"))) {
@@ -343,7 +327,7 @@ static int check_eattr_indir(struct gfs2_inode *ip, uint64_t indirect,
 			    "type"));
 		return 1;
 	}
-	if(q.block_type != gfs2_block_free) { /* Duplicate? */
+	if(q != gfs2_block_free) { /* Duplicate? */
 		log_err( _("Inode #%llu (0x%llx): Duplicate Extended "
 			   "Attribute indirect block found at #%llu "
 			   "(0x%llx).\n"),
@@ -400,19 +384,16 @@ static int check_leaf_block(struct gfs2_inode *ip, uint64_t block, int btype,
 {
 	struct gfs2_buffer_head *leaf_bh = NULL;
 	struct gfs2_sbd *sdp = ip->i_sbd;
-	struct gfs2_block_query q = {0};
+	uint8_t q;
 	struct block_count *bc = (struct block_count *) private;
 
-	if(gfs2_block_check(sdp, bl, block, &q)) {
-		stack;
-		return -1;
-	}
+	q = block_type(block);
 	/* Special duplicate processing:  If we have an EA block, check if it
 	   really is an EA.  If it is, let duplicate handling sort it out.
 	   If it isn't, clear it but don't count it as a duplicate. */
 	leaf_bh = bread(sdp, block);
 	if(gfs2_check_meta(leaf_bh, btype)) {
-		if(q.block_type != gfs2_block_free) { /* Duplicate? */
+		if(q != gfs2_block_free) { /* Duplicate? */
 			clear_eas(ip, bc, block, 1,
 				  _("Bad Extended Attribute duplicate found"));
 		} else {
@@ -423,7 +404,7 @@ static int check_leaf_block(struct gfs2_inode *ip, uint64_t block, int btype,
 		brelse(leaf_bh);
 		return 1;
 	}
-	if(q.block_type != gfs2_block_free) { /* Duplicate? */
+	if(q != gfs2_block_free) { /* Duplicate? */
 		log_debug( _("Duplicate block found at #%lld (0x%llx).\n"),
 			   (unsigned long long)block,
 			   (unsigned long long)block);
@@ -567,14 +548,8 @@ static int check_eattr_entries(struct gfs2_inode *ip,
 static int clear_metalist(struct gfs2_inode *ip, uint64_t block,
 		   struct gfs2_buffer_head **bh, void *private)
 {
-	struct gfs2_block_query q = {0};
-
 	*bh = NULL;
 
-	if(gfs2_block_check(ip->i_sbd, bl, block, &q)) {
-		stack;
-		return -1;
-	}
 	if(!is_duplicate(block)) {
 		gfs2_blockmap_set(ip->i_sbd, bl, block, gfs2_block_free);
 		return 0;
@@ -584,12 +559,6 @@ static int clear_metalist(struct gfs2_inode *ip, uint64_t block,
 
 static int clear_data(struct gfs2_inode *ip, uint64_t block, void *private)
 {
-	struct gfs2_block_query q = {0};
-
-	if(gfs2_block_check(ip->i_sbd, bl, block, &q)) {
-		stack;
-		return -1;
-	}
 	if(!is_duplicate(block)) {
 		gfs2_blockmap_set(ip->i_sbd, bl, block, gfs2_block_free);
 		return 0;
@@ -601,15 +570,9 @@ static int clear_data(struct gfs2_inode *ip, uint64_t block, void *private)
 static int clear_leaf(struct gfs2_inode *ip, uint64_t block,
 	       struct gfs2_buffer_head *bh, void *private)
 {
-	struct gfs2_block_query q = {0};
-
 	log_crit( _("Clearing leaf #%" PRIu64 " (0x%" PRIx64 ")\n"),
 		  block, block);
 
-	if(gfs2_block_check(ip->i_sbd, bl, block, &q)) {
-		stack;
-		return -1;
-	}
 	if(!is_duplicate(block)) {
 		log_crit( _("Setting leaf #%" PRIu64 " (0x%" PRIx64 ") invalid\n"),
 				 block, block);
@@ -655,7 +618,7 @@ int add_to_dir_list(struct gfs2_sbd *sbp, uint64_t block)
 static int handle_di(struct gfs2_sbd *sdp, struct gfs2_buffer_head *bh,
 			  uint64_t block)
 {
-	struct gfs2_block_query q = {0};
+	uint8_t q;
 	struct gfs2_inode *ip;
 	int error;
 	struct block_count bc = {0};
@@ -683,12 +646,8 @@ static int handle_di(struct gfs2_sbd *sdp, struct gfs2_buffer_head *bh,
 				 " (0x%" PRIx64 ") not fixed\n"), block, block);
 	}
 
-	if(gfs2_block_check(sdp, bl, block, &q)) {
-		stack;
-		fsck_inode_put(&ip);
-		return -1;
-	}
-	if(q.block_type != gfs2_block_free) {
+	q = block_type(block);
+	if(q != gfs2_block_free) {
 		log_err( _("Found duplicate block referenced as an inode at "
 			   "#%" PRIu64 " (0x%" PRIx64 ")\n"), block, block);
 		gfs2_dup_set(block);
diff --git a/gfs2/fsck/pass1b.c b/gfs2/fsck/pass1b.c
index a25e4da..4827534 100644
--- a/gfs2/fsck/pass1b.c
+++ b/gfs2/fsck/pass1b.c
@@ -494,7 +494,7 @@ int pass1b(struct gfs2_sbd *sbp)
 {
 	struct dup_blks *b;
 	uint64_t i;
-	struct gfs2_block_query q;
+	uint8_t q;
 	osi_list_t *tmp = NULL, *x;
 	struct metawalk_fxns find_dirents = {0};
 	int rc = FSCK_OK;
@@ -519,18 +519,14 @@ int pass1b(struct gfs2_sbd *sbp)
 			goto out;
 		log_debug( _("Scanning block %" PRIu64 " (0x%" PRIx64 ") for inodes\n"),
 				  i, i);
-		if(gfs2_block_check(sbp, bl, i, &q)) {
-			stack;
-			rc = FSCK_ERROR;
-			goto out;
-		}
-		if((q.block_type == gfs2_inode_dir) ||
-		   (q.block_type == gfs2_inode_file) ||
-		   (q.block_type == gfs2_inode_lnk) ||
-		   (q.block_type == gfs2_inode_blk) ||
-		   (q.block_type == gfs2_inode_chr) ||
-		   (q.block_type == gfs2_inode_fifo) ||
-		   (q.block_type == gfs2_inode_sock)) {
+		q = block_type(i);
+		if((q == gfs2_inode_dir) ||
+		   (q == gfs2_inode_file) ||
+		   (q == gfs2_inode_lnk) ||
+		   (q == gfs2_inode_blk) ||
+		   (q == gfs2_inode_chr) ||
+		   (q == gfs2_inode_fifo) ||
+		   (q == gfs2_inode_sock)) {
 			osi_list_foreach_safe(tmp, &dup_blocks.list, x) {
 				b = osi_list_entry(tmp, struct dup_blks,
 						   list);
@@ -541,7 +537,7 @@ int pass1b(struct gfs2_sbd *sbp)
 				}
 			}
 		}
-		if(q.block_type == gfs2_inode_dir) {
+		if(q == gfs2_inode_dir) {
 			check_dir(sbp, i, &find_dirents);
 		}
 	}
diff --git a/gfs2/fsck/pass1c.c b/gfs2/fsck/pass1c.c
index e3bd010..4174363 100644
--- a/gfs2/fsck/pass1c.c
+++ b/gfs2/fsck/pass1c.c
@@ -72,7 +72,7 @@ static int check_eattr_indir(struct gfs2_inode *ip, uint64_t block,
 		      void *private)
 {
 	struct gfs2_sbd *sbp = ip->i_sbd;
-	struct gfs2_block_query q;
+	uint8_t q;
 	struct gfs2_buffer_head *indir_bh = NULL;
 
 	if(gfs2_check_range(sbp, block)) {
@@ -85,11 +85,8 @@ static int check_eattr_indir(struct gfs2_inode *ip, uint64_t block,
 			(unsigned long long)ip->i_di.di_num.no_addr);
 		return ask_remove_eattr(ip);
 	}
-	else if (gfs2_block_check(sbp, bl, block, &q)) {
-		stack;
-		return -1;
-	}
-	else if(q.block_type != gfs2_indir_blk) {
+	q = block_type(block);
+	if(q != gfs2_indir_blk) {
 		log_err( _("Extended attributes indirect block #%llu"
 			" (0x%llx) for inode #%llu"
 			" (0x%llx) invalid.\n"),
@@ -111,7 +108,7 @@ static int check_eattr_leaf(struct gfs2_inode *ip, uint64_t block,
 		     void *private)
 {
 	struct gfs2_sbd *sbp = ip->i_sbd;
-	struct gfs2_block_query q;
+	uint8_t q;
 
 	if(gfs2_check_range(sbp, block)) {
 		log_err( _("Extended attributes block for inode #%llu"
@@ -120,11 +117,8 @@ static int check_eattr_leaf(struct gfs2_inode *ip, uint64_t block,
 			(unsigned long long)ip->i_di.di_num.no_addr);
 		return ask_remove_eattr(ip);
 	}
-	else if (gfs2_block_check(sbp, bl, block, &q)) {
-		stack;
-		return -1;
-	}
-	else if(q.block_type != gfs2_meta_eattr) {
+	q = block_type(block);
+	if(q != gfs2_meta_eattr) {
 		log_err( _("Extended attributes block for inode #%llu"
 			   " (0x%llx) invalid.\n"),
 			 (unsigned long long)ip->i_di.di_num.no_addr,
@@ -209,14 +203,12 @@ static int check_eattr_extentry(struct gfs2_inode *ip, uint64_t *ea_ptr,
 			 struct gfs2_ea_header *ea_hdr,
 			 struct gfs2_ea_header *ea_hdr_prev, void *private)
 {
-	struct gfs2_block_query q;
+	uint8_t q;
 	struct gfs2_sbd *sbp = ip->i_sbd;
 
-	if(gfs2_block_check(sbp, bl, be64_to_cpu(*ea_ptr), &q)) {
-		stack;
-		return -1;
-	}
-	if(q.block_type != gfs2_meta_eattr) {
+
+	q = block_type(be64_to_cpu(*ea_ptr));
+	if(q != gfs2_meta_eattr) {
 		if(remove_eattr_entry(sbp, leaf_bh, ea_hdr, ea_hdr_prev)){
 			stack;
 			return -1;
diff --git a/gfs2/fsck/pass2.c b/gfs2/fsck/pass2.c
index 7453e47..5e60b50 100644
--- a/gfs2/fsck/pass2.c
+++ b/gfs2/fsck/pass2.c
@@ -101,9 +101,9 @@ static const char *de_type_string(uint8_t de_type)
 	return de_types[3]; /* invalid */
 }
 
-static int check_file_type(uint8_t de_type, uint8_t block_type)
+static int check_file_type(uint8_t de_type, uint8_t blk_type)
 {
-	switch(block_type) {
+	switch(blk_type) {
 	case gfs2_inode_dir:
 		if(de_type != DT_DIR)
 			return 1;
@@ -156,7 +156,7 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 		 uint16_t *count, void *priv)
 {
 	struct gfs2_sbd *sbp = ip->i_sbd;
-	struct gfs2_block_query q = {0};
+	uint8_t q;
 	char tmp_name[MAX_FILENAME];
 	uint64_t entryblock;
 	struct dir_status *ds = (struct dir_status *) priv;
@@ -234,12 +234,9 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 			return 0;
 		}
 	}
-	if(gfs2_block_check(sbp, bl, de->de_inum.no_addr, &q)) {
-		stack;
-		return -1;
-	}
+	q = block_type(de->de_inum.no_addr);
 	/* Get the status of the directory inode */
-	if(q.block_type == gfs2_bad_block) {
+	if(q == gfs2_bad_block) {
 		/* This entry's inode has bad blocks in it */
 
 		/* Handle bad blocks */
@@ -266,10 +263,10 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 		}
 
 	}
-	if(q.block_type != gfs2_inode_dir && q.block_type != gfs2_inode_file &&
-	   q.block_type != gfs2_inode_lnk && q.block_type != gfs2_inode_blk &&
-	   q.block_type != gfs2_inode_chr && q.block_type != gfs2_inode_fifo &&
-	   q.block_type != gfs2_inode_sock) {
+	if(q != gfs2_inode_dir && q != gfs2_inode_file &&
+	   q != gfs2_inode_lnk && q != gfs2_inode_blk &&
+	   q != gfs2_inode_chr && q != gfs2_inode_fifo &&
+	   q != gfs2_inode_sock) {
 		log_err( _("Directory entry '%s' at block %llu (0x%llx"
 			   ") in dir inode %llu (0x%llx"
 			   ") block type %d: %s.\n"), tmp_name,
@@ -277,7 +274,7 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 			 (unsigned long long)de->de_inum.no_addr,
 			 (unsigned long long)ip->i_di.di_num.no_addr,
 			 (unsigned long long)ip->i_di.di_num.no_addr,
-			 q.block_type, q.block_type == gfs2_meta_inval ?
+			 q, q == gfs2_meta_inval ?
 			 _("previously marked invalid") :
 			 _("is not an inode"));
 
@@ -291,7 +288,7 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 			/* If it was previously marked invalid (i.e. known
 			   to be bad, not just a free block, etc.) then
 			   delete any metadata it holds.  If not, return. */
-			if (q.block_type != gfs2_meta_inval)
+			if (q != gfs2_meta_inval)
 				return 1;
 
 			/* Now try to clear the dinode, if it is an dinode */
@@ -319,7 +316,7 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 		}
 	}
 
-	error = check_file_type(de->de_type, q.block_type);
+	error = check_file_type(de->de_type, q);
 	if(error < 0) {
 		stack;
 		return -1;
@@ -330,7 +327,7 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 			 de_type_string(de->de_type), tmp_name,
 			 (unsigned long long)de->de_inum.no_addr,
 			 (unsigned long long)de->de_inum.no_addr,
-			 block_type_string(&q));
+			 block_type_string(q));
 		if(query( _("Clear stale directory entry? (y/n) "))) {
 			entry_ip = fsck_load_inode(sbp, de->de_inum.no_addr);
 			check_inode_eattr(entry_ip, &clear_eattrs);
@@ -446,7 +443,7 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 			}
 		}
 
-		if(q.block_type != gfs2_inode_dir) {
+		if(q != gfs2_inode_dir) {
 			log_err( _("Found '..' entry in directory %llu (0x%llx) "
 				"pointing to something that's not a directory"),
 				(unsigned long long)ip->i_di.di_num.no_addr,
@@ -487,7 +484,7 @@ static int check_dentry(struct gfs2_inode *ip, struct gfs2_dirent *dent,
 
 	/* After this point we're only concerned with
 	 * directories */
-	if(q.block_type != gfs2_inode_dir) {
+	if(q != gfs2_inode_dir) {
 		log_debug( _("Found non-dir inode dentry\n"));
 		increment_link(sbp, de->de_inum.no_addr);
 		(*count)++;
@@ -553,12 +550,10 @@ static int check_system_dir(struct gfs2_inode *sysinode, const char *dirname,
 
 	if (sysinode) {
 		iblock = sysinode->i_di.di_num.no_addr;
-		if(gfs2_block_check(sysinode->i_sbd, bl, iblock, &ds.q)) {
-			iblock = sysinode->i_di.di_num.no_addr;
-		}
+		ds.q = block_type(iblock);
 	}
 	pass2_fxns.private = (void *) &ds;
-	if(ds.q.block_type == gfs2_bad_block) {
+	if(ds.q == gfs2_bad_block) {
 		/* First check that the directory's metatree is valid */
 		if(check_metatree(sysinode, &pass2_fxns)) {
 			stack;
@@ -656,7 +651,7 @@ static inline int is_system_dir(struct gfs2_sbd *sbp, uint64_t block)
 int pass2(struct gfs2_sbd *sbp)
 {
 	uint64_t i;
-	struct gfs2_block_query q;
+	uint8_t q;
 	struct dir_status ds = {0};
 	struct gfs2_inode *ip;
 	char *filename;
@@ -693,13 +688,9 @@ int pass2(struct gfs2_sbd *sbp)
 		if (is_system_dir(sbp, i))
 			continue;
 
-		if(gfs2_block_check(sbp, bl, i, &q)) {
-			log_err( _("Can't get block %"PRIu64 " (0x%" PRIx64
-					") from block list\n"), i, i);
-			return FSCK_ERROR;
-		}
+		q = block_type(i);
 
-		if(q.block_type != gfs2_inode_dir)
+		if(q != gfs2_inode_dir)
 			continue;
 
 		log_debug( _("Checking directory inode at block %"PRIu64" (0x%"
@@ -707,7 +698,7 @@ int pass2(struct gfs2_sbd *sbp)
 
 		memset(&ds, 0, sizeof(ds));
 		pass2_fxns.private = (void *) &ds;
-		if(ds.q.block_type == gfs2_bad_block) {
+		if(ds.q == gfs2_bad_block) {
 			/* First check that the directory's metatree
 			 * is valid */
 			ip = fsck_load_inode(sbp, i);
diff --git a/gfs2/fsck/pass3.c b/gfs2/fsck/pass3.c
index 2b9a3ef..bcca68c 100644
--- a/gfs2/fsck/pass3.c
+++ b/gfs2/fsck/pass3.c
@@ -12,6 +12,7 @@
 #include "lost_n_found.h"
 #include "link.h"
 #include "metawalk.h"
+#include "util.h"
 
 static int attach_dotdot_to(struct gfs2_sbd *sbp, uint64_t newdotdot,
 			    uint64_t olddotdot, uint64_t block)
@@ -61,7 +62,7 @@ static struct dir_info *mark_and_return_parent(struct gfs2_sbd *sbp,
 										struct dir_info *di)
 {
 	struct dir_info *pdi;
-	struct gfs2_block_query q_dotdot, q_treewalk;
+	uint8_t q_dotdot, q_treewalk;
 
 	di->checked = 1;
 
@@ -75,19 +76,8 @@ static struct dir_info *mark_and_return_parent(struct gfs2_sbd *sbp,
 				   PRIu64" (0x%" PRIx64 ")\n"), di->dotdot_parent,
 				   di->dotdot_parent, di->treewalk_parent,
 				   di->treewalk_parent);
-		if(gfs2_block_check(sbp, bl, di->dotdot_parent, &q_dotdot)) {
-			log_err( _("Unable to find block %"PRIu64
-					" (0x%" PRIx64 ") in block map.\n"),
-					di->dotdot_parent, di->dotdot_parent);
-			return NULL;
-		}
-		if(gfs2_block_check(sbp, bl, di->treewalk_parent,
-				    &q_treewalk)) {
-			log_err( _("Unable to find block %"PRIu64
-					" (0x%" PRIx64 ") in block map\n"),
-					di->treewalk_parent, di->treewalk_parent);
-			return NULL;
-		}
+		q_dotdot = block_type(di->dotdot_parent);
+		q_treewalk = block_type(di->treewalk_parent);
 		/* if the dotdot entry isn't a directory, but the
 		 * treewalk is, treewalk is correct - if the treewalk
 		 * entry isn't a directory, but the dotdot is, dotdot
@@ -95,8 +85,8 @@ static struct dir_info *mark_and_return_parent(struct gfs2_sbd *sbp,
 		 * choose? if neither are directories, we have a
 		 * problem - need to move this directory into lost+found
 		 */
-		if(q_dotdot.block_type != gfs2_inode_dir) {
-			if(q_treewalk.block_type != gfs2_inode_dir) {
+		if(q_dotdot != gfs2_inode_dir) {
+			if(q_treewalk != gfs2_inode_dir) {
 				log_err( _("Orphaned directory, move to lost+found\n"));
 				return NULL;
 			}
@@ -110,7 +100,7 @@ static struct dir_info *mark_and_return_parent(struct gfs2_sbd *sbp,
 			}
 		}
 		else {
-			if(q_treewalk.block_type != gfs2_inode_dir) {
+			if(q_treewalk != gfs2_inode_dir) {
 				int error = 0;
 				log_warn( _(".. parent is valid, but treewalk"
 						 "is bad - reattaching to lost+found"));
@@ -152,13 +142,8 @@ static struct dir_info *mark_and_return_parent(struct gfs2_sbd *sbp,
 		}
 	}
 	else {
-		if(gfs2_block_check(sbp, bl, di->dotdot_parent, &q_dotdot)) {
-			log_err( _("Unable to find parent block %"PRIu64
-					" (0x%" PRIx64 ")  in block map\n"),
-					di->dotdot_parent, di->dotdot_parent);
-			return NULL;
-		}
-		if(q_dotdot.block_type != gfs2_inode_dir) {
+		q_dotdot = block_type(di->dotdot_parent);
+		if(q_dotdot != gfs2_inode_dir) {
 			log_err( _("Orphaned directory at block %" PRIu64 " (0x%" PRIx64
 					") moved to lost+found\n"), di->dinode, di->dinode);
 			return NULL;
@@ -180,7 +165,7 @@ int pass3(struct gfs2_sbd *sbp)
 	osi_list_t *tmp;
 	struct dir_info *di, *tdi;
 	struct gfs2_inode *ip;
-	struct gfs2_block_query q;
+	uint8_t q;
 	int i;
 
 	find_di(sbp, sbp->md.rooti->i_di.di_num.no_addr, &di);
@@ -212,11 +197,8 @@ int pass3(struct gfs2_sbd *sbp)
 
 			/* FIXME: Factor this ? */
 			if(!tdi) {
-				if(gfs2_block_check(sbp, bl, di->dinode, &q)) {
-					stack;
-					return FSCK_ERROR;
-				}
-				if(q.block_type == gfs2_bad_block) {
+				q = block_type(di->dinode);
+				if(q == gfs2_bad_block) {
 					log_err( _("Found unlinked directory containing bad block\n"));
 					if(query(
 					   _("Clear unlinked directory with bad blocks? (y/n) "))) {
@@ -227,13 +209,13 @@ int pass3(struct gfs2_sbd *sbp)
 					} else
 						log_err( _("Unlinked directory with bad block remains\n"));
 				}
-				if(q.block_type != gfs2_inode_dir &&
-				   q.block_type != gfs2_inode_file &&
-				   q.block_type != gfs2_inode_lnk &&
-				   q.block_type != gfs2_inode_blk &&
-				   q.block_type != gfs2_inode_chr &&
-				   q.block_type != gfs2_inode_fifo &&
-				   q.block_type != gfs2_inode_sock) {
+				if(q != gfs2_inode_dir &&
+				   q != gfs2_inode_file &&
+				   q != gfs2_inode_lnk &&
+				   q != gfs2_inode_blk &&
+				   q != gfs2_inode_chr &&
+				   q != gfs2_inode_fifo &&
+				   q != gfs2_inode_sock) {
 					log_err( _("Unlinked block marked as inode not an inode\n"));
 					gfs2_blockmap_set(sbp, bl, di->dinode,
 						       gfs2_block_free);
diff --git a/gfs2/fsck/pass4.c b/gfs2/fsck/pass4.c
index 2bc64b5..b3f28d7 100644
--- a/gfs2/fsck/pass4.c
+++ b/gfs2/fsck/pass4.c
@@ -9,6 +9,7 @@
 #include "lost_n_found.h"
 #include "inode_hash.h"
 #include "metawalk.h"
+#include "util.h"
 
 struct metawalk_fxns pass4_fxns_delete = {
 	.private = NULL,
@@ -43,7 +44,7 @@ static int scan_inode_list(struct gfs2_sbd *sbp, osi_list_t *list) {
 	struct inode_info *ii;
 	struct gfs2_inode *ip;
 	int lf_addition = 0;
-	struct gfs2_block_query q;
+	uint8_t q;
 
 	/* FIXME: should probably factor this out into a generic
 	 * scanning fxn */
@@ -59,11 +60,8 @@ static int scan_inode_list(struct gfs2_sbd *sbp, osi_list_t *list) {
 		if(ii->counted_links == 0) {
 			log_err( _("Found unlinked inode at %" PRIu64 " (0x%" PRIx64 ")\n"),
 					ii->inode, ii->inode);
-			if(gfs2_block_check(sbp, bl, ii->inode, &q)) {
-				stack;
-				return -1;
-			}
-			if(q.block_type == gfs2_bad_block) {
+			q = block_type(ii->inode);
+			if(q == gfs2_bad_block) {
 				log_err( _("Unlinked inode %llu (0x%llx) contains"
 					"bad blocks\n"),
 					(unsigned long long)ii->inode,
@@ -82,16 +80,15 @@ static int scan_inode_list(struct gfs2_sbd *sbp, osi_list_t *list) {
 				} else
 					log_err( _("Unlinked inode with bad blocks not cleared\n"));
 			}
-			if(q.block_type != gfs2_inode_dir &&
-			   q.block_type != gfs2_inode_file &&
-			   q.block_type != gfs2_inode_lnk &&
-			   q.block_type != gfs2_inode_blk &&
-			   q.block_type != gfs2_inode_chr &&
-			   q.block_type != gfs2_inode_fifo &&
-			   q.block_type != gfs2_inode_sock) {
+			if(q != gfs2_inode_dir &&
+			   q != gfs2_inode_file &&
+			   q != gfs2_inode_lnk &&
+			   q != gfs2_inode_blk &&
+			   q != gfs2_inode_chr &&
+			   q != gfs2_inode_fifo &&
+			   q != gfs2_inode_sock) {
 				log_err( _("Unlinked block marked as inode is "
-					   "not an inode (%d)\n"),
-					 q.block_type);
+					   "not an inode (%d)\n"), q);
 				ip = fsck_load_inode(sbp, ii->inode);
 				if(query(_("Delete unlinked inode? (y/n) "))) {
 					check_inode_eattr(ip,
diff --git a/gfs2/fsck/pass5.c b/gfs2/fsck/pass5.c
index f0d5911..3448204 100644
--- a/gfs2/fsck/pass5.c
+++ b/gfs2/fsck/pass5.c
@@ -10,9 +10,9 @@
 #include "fs_bits.h"
 #include "util.h"
 
-static int convert_mark(struct gfs2_block_query *q, uint32_t *count)
+static int convert_mark(uint8_t q, uint32_t *count)
 {
-	switch(q->block_type) {
+	switch(q) {
 
 	case gfs2_meta_inval:
 		/* Convert invalid metadata to free blocks */
@@ -43,7 +43,7 @@ static int convert_mark(struct gfs2_block_query *q, uint32_t *count)
 		return GFS2_BLKST_USED;
 
 	default:
-		log_err( _("Invalid state %d found\n"), q->block_type);
+		log_err( _("Invalid state %d found\n"), q);
 		return -1;
 	}
 	return -1;
@@ -55,7 +55,7 @@ static int check_block_status(struct gfs2_sbd *sbp, char *buffer, unsigned int b
 	unsigned char *byte, *end;
 	unsigned int bit;
 	unsigned char rg_status, block_status;
-	struct gfs2_block_query q;
+	uint8_t q;
 	uint64_t block;
 	static int free_unlinked = -1;
 
@@ -70,9 +70,9 @@ static int check_block_status(struct gfs2_sbd *sbp, char *buffer, unsigned int b
 		warm_fuzzy_stuff(block);
 		if (skip_this_pass || fsck_abort) /* if asked to skip the rest */
 			return 0;
-		gfs2_block_check(sbp, bl, block, &q);
+		q = block_type(block);
 
-		block_status = convert_mark(&q, count);
+		block_status = convert_mark(q, count);
 
 		/* If one node opens a file and another node deletes it, we
 		   may be left with a block that appears to be "unlinked" in
@@ -119,8 +119,8 @@ static int check_block_status(struct gfs2_sbd *sbp, char *buffer, unsigned int b
 			log_err( _("Ondisk status is %u (%s) but FSCK thinks it should be "),
 					rg_status, blockstatus[rg_status]);
 			log_err("%u (%s)\n", block_status, blockstatus[block_status]);
-			log_err( _("Metadata type is %u (%s)\n"), q.block_type,
-					block_type_string(&q));
+			log_err( _("Metadata type is %u (%s)\n"), q,
+					block_type_string(q));
 
 			if(query( _("Fix bitmap for block %" PRIu64
 				    " (0x%" PRIx64 ") ? (y/n) "),
diff --git a/gfs2/fsck/util.c b/gfs2/fsck/util.c
index 08eb831..2d601ef 100644
--- a/gfs2/fsck/util.c
+++ b/gfs2/fsck/util.c
@@ -79,15 +79,15 @@ void warm_fuzzy_stuff(uint64_t block)
 	}
 }
 
-const char *block_type_string(struct gfs2_block_query *q)
+const char *block_type_string(uint8_t q)
 {
 	const char *blktyp[] = {"free", "used", "indirect data", "inode",
 							"file", "symlink", "block dev", "char dev",
 							"fifo", "socket", "dir leaf", "journ data",
 							"other meta", "eattribute", "unused",
 							"invalid"};
-	if (q->block_type < 16)
-		return (blktyp[q->block_type]);
+	if (q < 16)
+		return (blktyp[q]);
 	return blktyp[15];
 }
 
diff --git a/gfs2/fsck/util.h b/gfs2/fsck/util.h
index 5e5f96e..e3ff7e3 100644
--- a/gfs2/fsck/util.h
+++ b/gfs2/fsck/util.h
@@ -1,6 +1,7 @@
 #ifndef __UTIL_H__
 #define __UTIL_H__
 
+#include "fsck.h"
 #include "libgfs2.h"
 
 #define fsck_lseek(fd, off) \
@@ -9,7 +10,19 @@
 struct di_info *search_list(osi_list_t *list, uint64_t addr);
 void big_file_comfort(struct gfs2_inode *ip, uint64_t blks_checked);
 void warm_fuzzy_stuff(uint64_t block);
-const char *block_type_string(struct gfs2_block_query *q);
+const char *block_type_string(uint8_t q);
 void gfs2_dup_set(uint64_t block);
 
+static inline uint8_t block_type(uint64_t bblock)
+{
+	static unsigned char *byte;
+	static uint64_t b;
+	static uint8_t btype;
+
+	byte = bl->map + BLOCKMAP_SIZE4(bblock);
+	b = BLOCKMAP_BYTE_OFFSET4(bblock);
+	btype = (*byte & (BLOCKMAP_MASK4 << b )) >> b;
+	return btype;
+}
+
 #endif /* __UTIL_H__ */
diff --git a/gfs2/libgfs2/block_list.c b/gfs2/libgfs2/block_list.c
index e76217b..aa774be 100644
--- a/gfs2/libgfs2/block_list.c
+++ b/gfs2/libgfs2/block_list.c
@@ -137,21 +137,6 @@ int gfs2_blockmap_set(struct gfs2_sbd *sdp, struct gfs2_bmap *bmap,
 	return 0;
 }
 
-int gfs2_block_check(struct gfs2_sbd *sdp, struct gfs2_bmap *il,
-		     uint64_t block, struct gfs2_block_query *val)
-{
-	static unsigned char *byte;
-	static uint64_t b;
-
-	if(block >= il->size)
-		return -1;
-
-	byte = il->map + BLOCKMAP_SIZE4(block);
-	b = BLOCKMAP_BYTE_OFFSET4(block);
-	val->block_type = (*byte & (BLOCKMAP_MASK4 << b )) >> b;
-	return 0;
-}
-
 void *gfs2_bmap_destroy(struct gfs2_sbd *sdp, struct gfs2_bmap *il)
 {
 	if(il) {
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 035193f..3b843e5 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -300,10 +300,6 @@ enum gfs2_mark_block {
 	gfs2_meta_inval = INVALID_META,
 };
 
-struct gfs2_block_query {
-        uint8_t block_type;
-};
-
 extern struct gfs2_bmap *gfs2_bmap_create(struct gfs2_sbd *sdp, uint64_t size,
 					  uint64_t *addl_mem_needed);
 extern struct special_blocks *blockfind(struct special_blocks *blist, uint64_t num);
@@ -319,8 +315,6 @@ extern int gfs2_block_unmark(struct gfs2_sbd *sdp, struct gfs2_bmap *il,
 /* gfs2_block_clear clears all the marks for the given block */
 extern int gfs2_blockmap_clear(struct gfs2_sbd *sdp, struct gfs2_bmap *il,
 			    uint64_t block);
-extern int gfs2_block_check(struct gfs2_sbd *sdp, struct gfs2_bmap *il,
-			    uint64_t block, struct gfs2_block_query *val);
 extern void *gfs2_bmap_destroy(struct gfs2_sbd *sdp, struct gfs2_bmap *il);
 
 /* buf.c */


More information about the cluster-commits mailing list