cluster: RHEL510 - fsck.gfs2: Don't use strerror for libgfs2 errors

Bob Peterson rpeterso at fedoraproject.org
Fri Apr 5 13:46:32 UTC 2013


Gitweb:        http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=0059c9378ae6cfa28742f96065ade198d8807787
Commit:        0059c9378ae6cfa28742f96065ade198d8807787
Parent:        aa125b9443ab370b9bcfedafe1b0a69e1804f4b3
Author:        Bob Peterson <rpeterso at redhat.com>
AuthorDate:    Thu Jan 12 14:29:19 2012 -0600
Committer:     Bob Peterson <rpeterso at redhat.com>
CommitterDate: Fri Apr 5 06:25:01 2013 -0700

fsck.gfs2: Don't use strerror for libgfs2 errors

This patch removes the calls to strerror from initialize.c.
The errors returned by libgfs2 currently don't conform to system
errors.  For example, they can return positive or negative numbers.
Therefore, strerror could segfault or give nonsense messages.
I hate numeric error messages as much as the next guy, but using
strerror won't work until we systematically go through libgfs2 and
make all the return codes conform to the rules strerror lives by.

rhbz#877150
---
 gfs2/fsck/initialize.c   |   32 +++++++++++++++++++++++---------
 gfs2/fsck/lost_n_found.c |    7 +++++++
 2 files changed, 30 insertions(+), 9 deletions(-)

diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index fc4fdec..0e798ef 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -452,8 +452,8 @@ static void lookup_per_node(struct gfs2_sbd *sdp, int allow_rebuild)
 
 		err = build_per_node(sdp);
 		if (err) {
-			log_crit(_("Error rebuilding per_node directory: %s\n"),
-				 strerror(err));
+			log_crit(_("Error %d rebuilding per_node directory\n"),
+				 err);
 			exit(FSCK_ERROR);
 		}
 	}
@@ -570,9 +570,25 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
 		gfs2_lookupi(sdp->master_dir, "inum", 4,
 			     &sdp->md.inum);
 		if (!sdp->md.inum) {
-			log_crit("System inum inode was not rebuilt.  "
-				 "Aborting.\n");
-			goto fail;
+			if (!query( _("The gfs2 system inum inode is missing. "
+				      "Okay to rebuild it? (y/n) "))) {
+				log_err( _("fsck.gfs2 cannot continue without "
+					   "a valid inum file; aborting.\n"));
+				goto fail;
+			}
+			err = build_inum(sdp);
+			if (err) {
+				log_crit(_("Error %d rebuilding inum inode\n"),
+					 err);
+				exit(FSCK_ERROR);
+			}
+			gfs2_lookupi(sdp->master_dir, "inum", 4,
+				     &sdp->md.inum);
+			if (!sdp->md.inum) {
+				log_crit("System inum inode was not rebuilt.  "
+					 "Aborting.\n");
+				goto fail;
+			}
 		}
 	}
 	/* Read inum entry into buffer */
@@ -591,8 +607,7 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
 		}
 		err = build_statfs(sdp);
 		if (err) {
-			log_crit(_("Error rebuilding statfs inode: %s\n"),
-				 strerror(err));
+			log_crit(_("Error %d rebuilding statfs inode\n"), err);
 			exit(FSCK_ERROR);
 		}
 		gfs2_lookupi(sdp->master_dir, "statfs", 6, &sdp->md.statfs);
@@ -625,8 +640,7 @@ static int init_system_inodes(struct gfs2_sbd *sdp)
 		}
 		err = build_quota(sdp);
 		if (err) {
-			log_crit(_("Error rebuilding quota inode: %s\n"),
-				 strerror(err));
+			log_crit(_("Error %d rebuilding quota inode\n"), err);
 			exit(FSCK_ERROR);
 		}
 		gfs2_lookupi(sdp->master_dir, "quota", 5, &sdp->md.qinode);
diff --git a/gfs2/fsck/lost_n_found.c b/gfs2/fsck/lost_n_found.c
index f02fb5a..afdeefc 100644
--- a/gfs2/fsck/lost_n_found.c
+++ b/gfs2/fsck/lost_n_found.c
@@ -19,6 +19,7 @@
 #include <unistd.h>
 #include <dirent.h>
 #include <libintl.h>
+#include <errno.h>
 #define _(String) gettext(String)
 
 #include "fsck.h"
@@ -115,6 +116,12 @@ int add_inode_to_lf(struct gfs2_inode *ip){
 
 		lf_dip = createi(sdp->md.rooti, "lost+found",
 				 S_IFDIR | 0700, 0);
+		if (lf_dip == NULL) {
+			log_crit(_("Error %d creating lost+found: %s\n"),
+				 errno);
+			exit(FSCK_ERROR);
+		}
+
 		/* createi will have incremented the di_nlink link count for
 		   the root directory.  We must increment the nlink value
 		   in the hash table to keep them in sync so that pass4 can


More information about the cluster-commits mailing list