cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: rpeterso@redhat.com <rpeterso@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 36/42] fsck.gfs2: standardize check_metatree return codes
Date: Mon,  8 Apr 2013 07:41:08 -0700	[thread overview]
Message-ID: <1365432074-17615-37-git-send-email-rpeterso@redhat.com> (raw)
In-Reply-To: <1365432074-17615-1-git-send-email-rpeterso@redhat.com>

From: Bob Peterson <rpeterso@redhat.com>

This patch aims to not change functionality at all. What it does is
adds a standard set of three return codes with the following meanings:

meta_is_good - all is well, keep processing metadata normally
meta_skip_further - an non-fatal error occurred, so further metadata
                    processing for this inode should be skipped.
meta_error - a fatal error occurred in this metadata, so we need to
             abort processing.

rhbz#902920
---
 gfs2/fsck/metawalk.c | 14 +++++++-------
 gfs2/fsck/metawalk.h |  6 ++++++
 gfs2/fsck/pass1.c    | 28 ++++++++++++++--------------
 gfs2/fsck/pass1b.c   |  6 +++---
 gfs2/fsck/util.c     | 12 ++++++------
 5 files changed, 36 insertions(+), 30 deletions(-)

diff --git a/gfs2/fsck/metawalk.c b/gfs2/fsck/metawalk.c
index 772b210..d285ee5 100644
--- a/gfs2/fsck/metawalk.c
+++ b/gfs2/fsck/metawalk.c
@@ -996,9 +996,9 @@ int free_block_if_notdup(struct gfs2_inode *ip, uint64_t block,
 {
 	if (!find_remove_dup(ip, block, btype)) { /* not a dup */
 		fsck_blockmap_set(ip, block, btype, gfs2_block_free);
-		return 1;
+		return meta_skip_further;
 	}
-	return 0;
+	return meta_is_good;
 }
 
 /**
@@ -1015,7 +1015,7 @@ static int delete_block_if_notdup(struct gfs2_inode *ip, uint64_t block,
 	uint8_t q;
 
 	if (!valid_block(ip->i_sbd, block))
-		return -EFAULT;
+		return meta_error;
 
 	q = block_type(block);
 	if (q == gfs2_block_free) {
@@ -1025,7 +1025,7 @@ static int delete_block_if_notdup(struct gfs2_inode *ip, uint64_t block,
 			  (unsigned long long)block,
 			  (unsigned long long)ip->i_di.di_num.no_addr,
 			  (unsigned long long)ip->i_di.di_num.no_addr);
-		return 0;
+		return meta_is_good;
 	}
 	return free_block_if_notdup(ip, block, btype);
 }
@@ -1255,12 +1255,12 @@ static int build_and_check_metalist(struct gfs2_inode *ip, osi_list_t *mlp,
 							   pass->private);
 				/* check_metalist should hold any buffers
 				   it gets with "bread". */
-				if (err < 0) {
+				if (err == meta_error) {
 					stack;
 					error = err;
 					return error;
 				}
-				if (err > 0) {
+				if (err == meta_skip_further) {
 					if (!error)
 						error = err;
 					log_debug( _("Skipping block %llu (0x%llx)\n"),
@@ -1666,7 +1666,7 @@ static int alloc_metalist(struct gfs2_inode *ip, uint64_t block,
 			  (unsigned long long)block);
 		gfs2_blockmap_set(bl, block, gfs2_indir_blk);
 	}
-	return 0;
+	return meta_is_good;
 }
 
 static int alloc_data(struct gfs2_inode *ip, uint64_t metablock,
diff --git a/gfs2/fsck/metawalk.h b/gfs2/fsck/metawalk.h
index 2ba0d72..49217cc 100644
--- a/gfs2/fsck/metawalk.h
+++ b/gfs2/fsck/metawalk.h
@@ -56,6 +56,12 @@ extern int free_block_if_notdup(struct gfs2_inode *ip, uint64_t block,
 #define fsck_blockmap_set(ip, b, bt, m) _fsck_blockmap_set(ip, b, bt, m, \
 							   __FUNCTION__, __LINE__)
 
+enum meta_check_rc {
+	meta_error = -1,
+	meta_is_good = 0,
+	meta_skip_further = 1,
+};
+
 /* metawalk_fxns: function pointers to check various parts of the fs
  *
  * The functions should return -1 on fatal errors, 1 if the block
diff --git a/gfs2/fsck/pass1.c b/gfs2/fsck/pass1.c
index 0973dfd..12c5795 100644
--- a/gfs2/fsck/pass1.c
+++ b/gfs2/fsck/pass1.c
@@ -139,14 +139,14 @@ static int resuscitate_metalist(struct gfs2_inode *ip, uint64_t block,
 			   "range) found in system inode %lld (0x%llx).\n"),
 			 (unsigned long long)ip->i_di.di_num.no_addr,
 			 (unsigned long long)ip->i_di.di_num.no_addr);
-		return 1;
+		return meta_skip_further;
 	}
 	if (fsck_system_inode(ip->i_sbd, block))
 		fsck_blockmap_set(ip, block, _("system file"), gfs2_indir_blk);
 	else
 		check_n_fix_bitmap(ip->i_sbd, block, gfs2_indir_blk);
 	bc->indir_count++;
-	return 0;
+	return meta_is_good;
 }
 
 /*
@@ -263,7 +263,7 @@ static int check_metalist(struct gfs2_inode *ip, uint64_t block,
 			   (unsigned long long)ip->i_di.di_num.no_addr,
 			   (unsigned long long)ip->i_di.di_num.no_addr);
 
-		return 1;
+		return meta_skip_further;
 	}
 	if (is_dir(&ip->i_di, ip->i_sbd->gfs1) && h == ip->i_di.di_height) {
 		iblk_type = GFS2_METATYPE_JD;
@@ -300,7 +300,7 @@ static int check_metalist(struct gfs2_inode *ip, uint64_t block,
 					  gfs2_meta_inval);
 			brelse(nbh);
 			nbh = NULL;
-			return 1;
+			return meta_skip_further;
 		}
 		brelse(nbh);
 		nbh = NULL;
@@ -314,12 +314,12 @@ static int check_metalist(struct gfs2_inode *ip, uint64_t block,
 			nbh = NULL;
 			*bh = NULL;
 		}
-		return 1; /* don't process the metadata again */
+		return meta_skip_further; /* don't process the metadata again */
 	} else
 		fsck_blockmap_set(ip, block, _("indirect"),
 				  gfs2_indir_blk);
 
-	return 0;
+	return meta_is_good;
 }
 
 /* undo_reference - undo previously processed data or metadata
@@ -825,7 +825,7 @@ static int mark_block_invalid(struct gfs2_inode *ip, uint64_t block,
 	 * and as a result, they'll be freed when this dinode is deleted,
 	 * despite being used by another dinode as a valid block. */
 	if (!valid_block(ip->i_sbd, block))
-		return 0;
+		return meta_is_good;
 
 	q = block_type(block);
 	if (q != gfs2_block_free) {
@@ -837,10 +837,10 @@ static int mark_block_invalid(struct gfs2_inode *ip, uint64_t block,
 			  (unsigned long long)block,
 			  (unsigned long long)ip->i_di.di_num.no_addr,
 			  (unsigned long long)ip->i_di.di_num.no_addr);
-		return 0;
+		return meta_is_good;
 	}
 	fsck_blockmap_set(ip, block, btype, gfs2_meta_inval);
-	return 0;
+	return meta_is_good;
 }
 
 static int invalidate_metadata(struct gfs2_inode *ip, uint64_t block,
@@ -910,9 +910,9 @@ static int rangecheck_block(struct gfs2_inode *ip, uint64_t block,
 			  (unsigned long long)ip->i_di.di_num.no_addr,
 			  (unsigned long long)ip->i_di.di_num.no_addr);
 		if ((*bad_pointers) <= BAD_POINTER_TOLERANCE)
-			return ENOENT;
+			return meta_skip_further;
 		else
-			return -ENOENT; /* Exits check_metatree quicker */
+			return meta_error; /* Exits check_metatree quicker */
 	}
 	/* See how many duplicate blocks it has */
 	q = block_type(block);
@@ -925,11 +925,11 @@ static int rangecheck_block(struct gfs2_inode *ip, uint64_t block,
 			  (unsigned long long)ip->i_di.di_num.no_addr,
 			  (unsigned long long)ip->i_di.di_num.no_addr);
 		if ((*bad_pointers) <= BAD_POINTER_TOLERANCE)
-			return ENOENT;
+			return meta_skip_further;
 		else
-			return -ENOENT; /* Exits check_metatree quicker */
+			return meta_error; /* Exits check_metatree quicker */
 	}
-	return 0;
+	return meta_is_good;
 }
 
 static int rangecheck_metadata(struct gfs2_inode *ip, uint64_t block,
diff --git a/gfs2/fsck/pass1b.c b/gfs2/fsck/pass1b.c
index b2532fd..b5da200 100644
--- a/gfs2/fsck/pass1b.c
+++ b/gfs2/fsck/pass1b.c
@@ -215,7 +215,7 @@ static int clear_dup_metalist(struct gfs2_inode *ip, uint64_t block,
 	struct duptree *dt;
 
 	if (!valid_block(ip->i_sbd, block))
-		return 0;
+		return meta_is_good;
 
 	/* This gets tricky. We're traversing a metadata tree trying to
 	   delete an inode based on it having a duplicate block reference
@@ -231,7 +231,7 @@ static int clear_dup_metalist(struct gfs2_inode *ip, uint64_t block,
 	if (!dt) {
 		fsck_blockmap_set(ip, block, _("no longer valid"),
 				  gfs2_block_free);
-		return 0;
+		return meta_is_good;
 	}
 	/* This block, having failed the above test, is duplicated somewhere */
 	if (block == dh->dt->block) {
@@ -254,7 +254,7 @@ static int clear_dup_metalist(struct gfs2_inode *ip, uint64_t block,
 	   be mistakenly freed as "no longer valid" (in this function above)
 	   even though it's valid metadata for a different inode. Returning
 	   1 ensures that the metadata isn't processed again. */
-	return 1;
+	return meta_skip_further;
 }
 
 static int clear_dup_data(struct gfs2_inode *ip, uint64_t metablock,
diff --git a/gfs2/fsck/util.c b/gfs2/fsck/util.c
index c11768f..078d5f6 100644
--- a/gfs2/fsck/util.c
+++ b/gfs2/fsck/util.c
@@ -316,19 +316,19 @@ int add_duplicate_ref(struct gfs2_inode *ip, uint64_t block,
 	struct duptree *dt;
 
 	if (!valid_block(ip->i_sbd, block))
-		return 0;
+		return meta_is_good;
 	/* If this is not the first reference (i.e. all calls from pass1) we
 	   need to create the duplicate reference. If this is pass1b, we want
 	   to ignore references that aren't found. */
 	dt = gfs2_dup_set(block, !first);
 	if (!dt)        /* If this isn't a duplicate */
-		return 0;
+		return meta_is_good;
 
 	/* If we found the duplicate reference but we've already discovered
 	   the first reference (in pass1b) and the other references in pass1,
 	   we don't need to count it, so just return. */
 	if (dt->first_ref_found)
-		return 0;
+		return meta_is_good;
 
 	/* The first time this is called from pass1 is actually the second
 	   reference.  When we go back in pass1b looking for the original
@@ -350,12 +350,12 @@ int add_duplicate_ref(struct gfs2_inode *ip, uint64_t block,
 		if (!(id = malloc(sizeof(*id)))) {
 			log_crit( _("Unable to allocate "
 				    "inode_with_dups structure\n"));
-			return -1;
+			return meta_error;
 		}
 		if (!(memset(id, 0, sizeof(*id)))) {
 			log_crit( _("Unable to zero inode_with_dups "
 				    "structure\n"));
-			return -1;
+			return meta_error;
 		}
 		id->block_no = ip->i_di.di_num.no_addr;
 		q = block_type(ip->i_di.di_num.no_addr);
@@ -389,7 +389,7 @@ int add_duplicate_ref(struct gfs2_inode *ip, uint64_t block,
 	else
 		log_info( _("This brings the total to: %d duplicate "
 			    "references\n"), dt->refs);
-	return 0;
+	return meta_is_good;
 }
 
 struct dir_info *dirtree_insert(struct gfs2_inum inum)
-- 
1.7.11.7



  parent reply	other threads:[~2013-04-08 14:41 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-08 14:40 [Cluster-devel] [PATCH 00/42] fsck.gfs2 fixes and improvements rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 01/42] libgfs2: externalize dir_split_leaf rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 02/42] libgfs2: allow dir_split_leaf to receive a leaf buffer rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 03/42] libgfs2: let dir_split_leaf receive a "broken" lindex rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 04/42] fsck.gfs2: Move function find_free_blk to util.c rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 05/42] fsck.gfs2: Split out function to make sure lost+found exists rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 06/42] fsck.gfs2: Check for formal inode mismatch when adding to lost+found rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 07/42] fsck.gfs2: shorten some debug messages in lost+found rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 08/42] fsck.gfs2: Move basic directory entry checks to separate function rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 09/42] fsck.gfs2: Add formal inode check to basic dirent checks rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 10/42] fsck.gfs2: Add new function to check dir hash tables rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 11/42] fsck.gfs2: Special case '..' when processing bad formal inode number rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 12/42] fsck.gfs2: Move function to read directory hash table to util.c rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 13/42] fsck.gfs2: Misc cleanups rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 14/42] fsck.gfs2: Verify dirent hash values correspond to proper leaf block rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 15/42] fsck.gfs2: re-read hash table if directory height or depth changes rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 16/42] fsck.gfs2: fix leaf blocks, don't try to patch the hash table rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 17/42] fsck.gfs2: check leaf depth when validating leaf blocks rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 18/42] fsck.gfs2: small cleanups rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 19/42] fsck.gfs2: reprocess inodes when blocks are added rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 20/42] fsck.gfs2: Remove redundant leaf depth check rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 21/42] fsck.gfs2: link dinodes that only have extended attribute problems rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 22/42] fsck.gfs2: Add clarifying message to duplicate processing rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 23/42] fsck.gfs2: separate function to calculate metadata block header size rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 24/42] fsck.gfs2: Rework the "undo" functions rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 25/42] fsck.gfs2: Check for interrupt when resolving duplicates rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 26/42] fsck.gfs2: Consistent naming of struct duptree variables rpeterso
2013-04-08 14:40 ` [Cluster-devel] [PATCH 27/42] fsck.gfs2: Keep proper counts when duplicates are found rpeterso
2013-04-08 14:41 ` [Cluster-devel] [PATCH 28/42] fsck.gfs2: print metadata block reference on data errors rpeterso
2013-04-08 14:41 ` [Cluster-devel] [PATCH 29/42] fsck.gfs2: print block count values when fixing them rpeterso
2013-04-08 14:41 ` [Cluster-devel] [PATCH 30/42] fsck.gfs2: Do not invalidate metablocks of dinodes with invalid mode rpeterso
2013-04-08 14:41 ` [Cluster-devel] [PATCH 31/42] fsck.gfs2: Log when unrecoverable data block errors are encountered rpeterso
2013-04-08 14:41 ` [Cluster-devel] [PATCH 32/42] fsck.gfs2: don't remove buffers from the list when errors are found rpeterso
2013-04-08 14:41 ` [Cluster-devel] [PATCH 33/42] fsck.gfs2: Don't flag GFS1 non-dinode blocks as duplicates rpeterso
2013-04-08 14:41 ` [Cluster-devel] [PATCH 34/42] fsck.gfs2: externalize check_leaf rpeterso
2013-04-08 14:41 ` [Cluster-devel] [PATCH 35/42] fsck.gfs2 pass2: check leaf blocks when fixing hash table rpeterso
2013-04-08 14:41 ` rpeterso [this message]
2013-04-08 14:41 ` [Cluster-devel] [PATCH 37/42] fsck.gfs2: don't invalidate files with duplicate data block refs rpeterso
2013-04-08 14:41 ` [Cluster-devel] [PATCH 38/42] fsck.gfs2: check for duplicate first references rpeterso
2013-04-08 14:41 ` [Cluster-devel] [PATCH 39/42] fsck.gfs2: When flagging a duplicate reference, show valid or invalid rpeterso
2013-04-08 14:41 ` [Cluster-devel] [PATCH 40/42] fsck.gfs2: major duplicate reference reform rpeterso
2013-04-08 14:41 ` [Cluster-devel] [PATCH 41/42] fsck.gfs2: Remove all bad eattr blocks rpeterso
2013-04-08 14:41 ` [Cluster-devel] [PATCH 42/42] fsck.gfs2: Remove unused variable rpeterso

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=1365432074-17615-37-git-send-email-rpeterso@redhat.com \
    --to=rpeterso@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).