[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] [PATCH 5/6] libgfs2: Clean up sb read/check functions



There is no need to specify in advance whether we want to accept
gfs1 format super blocks or not. We can simply return that info
and let the caller decide if gfs1 format is acceptable or not.

We can also remove the message regarding the magic number of the
superblock, since the caller prints out a message anyway if
the check fails.

That removes some more of the log_ messages from libgfs2 as a
result.

Signed-off-by: Steven Whitehouse <swhiteho redhat com>
---
 gfs2/edit/savemeta.c   |    4 ++--
 gfs2/fsck/initialize.c |    4 ++--
 gfs2/libgfs2/libgfs2.h |    4 ++--
 gfs2/libgfs2/super.c   |   23 ++++++-----------------
 gfs2/mkfs/main_grow.c  |    6 ++++--
 5 files changed, 16 insertions(+), 25 deletions(-)

diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index 31af23d..9d790fe 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -670,7 +670,7 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
 			fprintf(stderr, "Bad constants (1)\n");
 			exit(-1);
 		}
-		ret = read_sb(&sbd, 1);
+		ret = read_sb(&sbd);
 		if (ret < 0) {
 			slow = TRUE;
 			sbd.gfs1 = 0;
@@ -911,7 +911,7 @@ static int restore_data(int fd, gzFile *gzin_fd, int printblocksonly,
 			memcpy(&bufsb, savedata->buf, sizeof(bufsb));
 			gfs2_sb_in(&sbd.sd_sb, &dummy_bh);
 			sbd1 = (struct gfs_sb *)&sbd.sd_sb;
-			ret = check_sb(&sbd.sd_sb, 1);
+			ret = check_sb(&sbd.sd_sb);
 			if (ret < 0) {
 				fprintf(stderr,"Error: Invalid superblock data.\n");
 				return -1;
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index ba0df41..132d65a 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -1227,12 +1227,12 @@ static int fill_super_block(struct gfs2_sbd *sdp)
 		log_crit(_("Bad constants (1)\n"));
 		exit(FSCK_ERROR);
 	}
-	ret = read_sb(sdp, 1);
+	ret = read_sb(sdp);
 	if (ret < 0) {
 		if (sb_repair(sdp) != 0)
 			return -1; /* unrepairable, so exit */
 		/* Now that we've tried to repair it, re-read it. */
-		ret = read_sb(sdp, 1);
+		ret = read_sb(sdp);
 		if (ret < 0)
 			return -1;
 	}
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 04169bf..b24e555 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -722,8 +722,8 @@ extern int gfs2_next_rg_freemeta(struct rgrp_tree *rgd, uint64_t *block,
 				 int first);
 
 /* super.c */
-extern int check_sb(struct gfs2_sb *sb, int allow_gfs);
-extern int read_sb(struct gfs2_sbd *sdp, int allow_gfs);
+extern int check_sb(struct gfs2_sb *sb);
+extern int read_sb(struct gfs2_sbd *sdp);
 extern int rindex_read(struct gfs2_sbd *sdp, int fd, int *count1, int *sane);
 extern int ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int *sane);
 extern int write_sb(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/super.c b/gfs2/libgfs2/super.c
index 2f544ab..c9a9ad3 100644
--- a/gfs2/libgfs2/super.c
+++ b/gfs2/libgfs2/super.c
@@ -13,7 +13,6 @@
 
 /**
  * check_sb - Check superblock
- * @sdp: the filesystem
  * @sb: The superblock
  *
  * Checks the version code of the FS is one that we understand how to
@@ -22,25 +21,17 @@
  *
  * Returns: -1 on failure, 1 if this is gfs (gfs1), 2 if this is gfs2
  */
-int check_sb(struct gfs2_sb *sb, int allow_gfs)
+int check_sb(struct gfs2_sb *sb)
 {
 	if (sb->sb_header.mh_magic != GFS2_MAGIC ||
 	    sb->sb_header.mh_type != GFS2_METATYPE_SB) {
-		log_crit("Either the super block is corrupted, or this "
-				 "is not a GFS2 filesystem\n");
-		log_crit("Header magic: %X Header Type: %X\n",
-				  sb->sb_header.mh_magic,
-				  sb->sb_header.mh_type);
-		return -EINVAL;
+		errno = -EIO;
+		return -1;
 	}
 	if (sb->sb_fs_format == GFS_FORMAT_FS &&
 	    sb->sb_header.mh_format == GFS_FORMAT_SB &&
 	    sb->sb_multihost_format == GFS_FORMAT_MULTI) {
-		if (allow_gfs)
-			return 1;
-
-		log_crit("Old gfs1 file system detected.\n");
-		return -EINVAL;
+		return 1;
 	}
 	return 2;
 }
@@ -54,12 +45,10 @@ int check_sb(struct gfs2_sb *sb, int allow_gfs)
  * initializes various constants maintained in the super
  * block
  *
- * allow_gfs - passed in as 1 if we're allowed to accept gfs1 file systems
- *
  * Returns: 0 on success, -1 on failure
  * sdp->gfs1 will be set if this is gfs (gfs1)
  */
-int read_sb(struct gfs2_sbd *sdp, int allow_gfs)
+int read_sb(struct gfs2_sbd *sdp)
 {
 	struct gfs2_buffer_head *bh;
 	uint64_t space = 0;
@@ -70,7 +59,7 @@ int read_sb(struct gfs2_sbd *sdp, int allow_gfs)
 	gfs2_sb_in(&sdp->sd_sb, bh);
 	brelse(bh);
 
-	ret = check_sb(&sdp->sd_sb, allow_gfs);
+	ret = check_sb(&sdp->sd_sb);
 	if (ret < 0)
 		return ret;
 	if (ret == 1)
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index 1dc911a..5ed5a2d 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -358,9 +358,11 @@ main_grow(int argc, char *argv[])
 			perror(_("Bad constants (1)"));
 			exit(EXIT_FAILURE);
 		}
-		if (read_sb(sdp, 0) < 0)
+		if (read_sb(sdp) < 0)
 			die( _("gfs: Error reading superblock.\n"));
-
+		if (sdp->gfs1) {
+			die( _("cannot grow gfs1 filesystem\n"));
+		}
 		if (fix_device_geometry(sdp)) {
 			fprintf(stderr, _("Device is too small (%llu bytes)\n"),
 				(unsigned long long)sdp->device.length << GFS2_BASIC_BLOCK_SHIFT);
-- 
1.7.4.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]