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

[Cluster-devel] [Patch 37/44] libgfs2: combine ri_update and gfs1_ri_update



>From 1b5b46eb51f0784152792fe4f446bb8f78712665 Mon Sep 17 00:00:00 2001
From: Bob Peterson <rpeterso redhat com>
Date: Wed, 10 Aug 2011 14:20:11 -0500
Subject: [PATCH 37/44] libgfs2: combine ri_update and gfs1_ri_update

Since gfs1_ri_update is nearly identical to ri_update, I decided to
combine the main logic into a common function.  That simplifies the
code and if one gets fixed, they both get fixed automatically.

rhbz#675723
---
 gfs2/libgfs2/gfs1.c  |   49 -------------------------------------------------
 gfs2/libgfs2/super.c |   33 ++++++++++++++++++++++++++++++---
 2 files changed, 30 insertions(+), 52 deletions(-)

diff --git a/gfs2/libgfs2/gfs1.c b/gfs2/libgfs2/gfs1.c
index a0a6c6c..91d3641 100644
--- a/gfs2/libgfs2/gfs1.c
+++ b/gfs2/libgfs2/gfs1.c
@@ -161,55 +161,6 @@ void gfs1_block_map(struct gfs2_inode *ip, uint64_t lblock, int *new,
 	free(mp);
 }
 
-/**
- * gfs1_ri_update - attach rgrps to the super block
- *                  Stolen from libgfs2/super.c, but modified to handle gfs1.
- * @sdp:
- *
- * Given the rgrp index inode, link in all rgrps into the super block
- * and be sure that they can be read.
- *
- * Returns: 0 on success, -1 on failure.
- */
-int gfs1_ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int quiet)
-{
-	struct rgrp_list *rgd;
-	struct gfs2_rindex *ri;
-	osi_list_t *tmp;
-	int count1 = 0, count2 = 0;
-	uint64_t errblock = 0;
-	uint64_t rmax = 0;
-	int sane;
-
-	if (rindex_read(sdp, fd, &count1, &sane))
-	    goto fail;
-	for (tmp = sdp->rglist.next; tmp != &sdp->rglist; tmp = tmp->next) {
-		rgd = osi_list_entry(tmp, struct rgrp_list, list);
-		errblock = gfs2_rgrp_read(sdp, rgd);
-		if (errblock)
-			return errblock;
-		count2++;
-		if (!quiet && count2 % 100 == 0) {
-			printf(".");
-			fflush(stdout);
-		}
-		ri = &rgd->ri;
-		if (ri->ri_data0 + ri->ri_data - 1 > rmax)
-			rmax = ri->ri_data0 + ri->ri_data - 1;
-	}
-
-	sdp->fssize = rmax;
-	*rgcount = count1;
-	if (count1 != count2)
-		goto fail;
-
-	return 0;
-
- fail:
-	gfs2_rgrp_free(&sdp->rglist);
-	return -1;
-}
-
 /* ------------------------------------------------------------------------ */
 /* gfs_dinode_in */
 /* ------------------------------------------------------------------------ */
diff --git a/gfs2/libgfs2/super.c b/gfs2/libgfs2/super.c
index 61425aa..df77029 100644
--- a/gfs2/libgfs2/super.c
+++ b/gfs2/libgfs2/super.c
@@ -233,7 +233,8 @@ int rindex_read(struct gfs2_sbd *sdp, int fd, int *count1, int *sane)
  *
  * Returns: 0 on success, -1 on failure.
  */
-int ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int *sane)
+static int __ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int *sane,
+		       int quiet)
 {
 	struct rgrp_list *rgd;
 	struct gfs2_rindex *ri;
@@ -243,16 +244,20 @@ int ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int *sane)
 	uint64_t rmax = 0;
 
 	if (rindex_read(sdp, fd, &count1, sane))
-	    goto fail;
+		goto fail;
 	for (tmp = sdp->rglist.next; tmp != &sdp->rglist; tmp = tmp->next) {
 		rgd = osi_list_entry(tmp, struct rgrp_list, list);
 		errblock = gfs2_rgrp_read(sdp, rgd);
 		if (errblock)
 			return errblock;
+		count2++;
+		if (!quiet && count2 % 100 == 0) {
+			printf(".");
+			fflush(stdout);
+		}
 		ri = &rgd->ri;
 		if (ri->ri_data0 + ri->ri_data - 1 > rmax)
 			rmax = ri->ri_data0 + ri->ri_data - 1;
-		count2++;
 	}
 
 	sdp->fssize = rmax;
@@ -267,6 +272,28 @@ int ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int *sane)
 	return -1;
 }
 
+int ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int *sane)
+{
+	return __ri_update(sdp, fd, rgcount, sane, 1);
+}
+
+/**
+ * gfs1_ri_update - attach rgrps to the super block
+ *                  Stolen from libgfs2/super.c, but modified to handle gfs1.
+ * @sdp:
+ *
+ * Given the rgrp index inode, link in all rgrps into the super block
+ * and be sure that they can be read.
+ *
+ * Returns: 0 on success, -1 on failure.
+ */
+int gfs1_ri_update(struct gfs2_sbd *sdp, int fd, int *rgcount, int quiet)
+{
+	int sane;
+
+	return __ri_update(sdp, fd, rgcount, &sane, quiet);
+}
+
 int write_sb(struct gfs2_sbd *sbp)
 {
 	struct gfs2_buffer_head *bh;
-- 
1.7.4.4


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