gfs2-utils: master - fsck.gfs2: Move function find_free_blk to util.c

Bob Peterson rpeterso at fedoraproject.org
Mon May 20 16:17:37 UTC 2013


Gitweb:        http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=286f616cdc0c68cd30bc8a5c42a4cc8ed4a7fa28
Commit:        286f616cdc0c68cd30bc8a5c42a4cc8ed4a7fa28
Parent:        12c7cb64437966e3d18b66789b94a0fbb96eea08
Author:        Bob Peterson <rpeterso at redhat.com>
AuthorDate:    Thu Feb 21 09:43:22 2013 -0700
Committer:     Bob Peterson <rpeterso at redhat.com>
CommitterDate: Mon May 20 11:12:45 2013 -0500

fsck.gfs2: Move function find_free_blk to util.c

In a future patch to fsck, function find_free_blk will be called in
order to correctly report blocks that will need to be allocated for
things such as leaf splits. This patch moves function find_free_blk
to a more centralized place, util.c, to that end.
---
 gfs2/fsck/lost_n_found.c |   39 ---------------------------------------
 gfs2/fsck/util.c         |   39 +++++++++++++++++++++++++++++++++++++++
 gfs2/fsck/util.h         |    2 ++
 3 files changed, 41 insertions(+), 39 deletions(-)

diff --git a/gfs2/fsck/lost_n_found.c b/gfs2/fsck/lost_n_found.c
index 570f3a8..1fb5076 100644
--- a/gfs2/fsck/lost_n_found.c
+++ b/gfs2/fsck/lost_n_found.c
@@ -88,45 +88,6 @@ static void add_dotdot(struct gfs2_inode *ip)
 	}
 }
 
-static uint64_t find_free_blk(struct gfs2_sbd *sdp)
-{
-	struct osi_node *n, *next = NULL;
-	struct rgrp_tree *rl = NULL;
-	struct gfs2_rindex *ri;
-	struct gfs2_rgrp *rg;
-	unsigned int block, bn = 0, x = 0, y = 0;
-	unsigned int state;
-	struct gfs2_buffer_head *bh;
-
-	memset(&rg, 0, sizeof(rg));
-	for (n = osi_first(&sdp->rgtree); n; n = next) {
-		next = osi_next(n);
-		rl = (struct rgrp_tree *)n;
-		if (rl->rg.rg_free)
-			break;
-	}
-
-	if (n == NULL)
-		return 0;
-
-	ri = &rl->ri;
-	rg = &rl->rg;
-
-	for (block = 0; block < ri->ri_length; block++) {
-		bh = rl->bh[block];
-		x = (block) ? sizeof(struct gfs2_meta_header) : sizeof(struct gfs2_rgrp);
-
-		for (; x < sdp->bsize; x++)
-			for (y = 0; y < GFS2_NBBY; y++) {
-				state = (bh->b_data[x] >> (GFS2_BIT_SIZE * y)) & 0x03;
-				if (state == GFS2_BLKST_FREE)
-					return ri->ri_data0 + bn;
-				bn++;
-			}
-	}
-	return 0;
-}
-
 /* add_inode_to_lf - Add dir entry to lost+found for the inode
  * @ip: inode to add to lost + found
  *
diff --git a/gfs2/fsck/util.c b/gfs2/fsck/util.c
index 7c89155..94d532e 100644
--- a/gfs2/fsck/util.c
+++ b/gfs2/fsck/util.c
@@ -615,3 +615,42 @@ bad_dinode:
 	stack;
 	return -EPERM;
 }
+
+uint64_t find_free_blk(struct gfs2_sbd *sdp)
+{
+	struct osi_node *n, *next = NULL;
+	struct rgrp_tree *rl = NULL;
+	struct gfs2_rindex *ri;
+	struct gfs2_rgrp *rg;
+	unsigned int block, bn = 0, x = 0, y = 0;
+	unsigned int state;
+	struct gfs2_buffer_head *bh;
+
+	memset(&rg, 0, sizeof(rg));
+	for (n = osi_first(&sdp->rgtree); n; n = next) {
+		next = osi_next(n);
+		rl = (struct rgrp_tree *)n;
+		if (rl->rg.rg_free)
+			break;
+	}
+
+	if (n == NULL)
+		return 0;
+
+	ri = &rl->ri;
+	rg = &rl->rg;
+
+	for (block = 0; block < ri->ri_length; block++) {
+		bh = rl->bh[block];
+		x = (block) ? sizeof(struct gfs2_meta_header) : sizeof(struct gfs2_rgrp);
+
+		for (; x < sdp->bsize; x++)
+			for (y = 0; y < GFS2_NBBY; y++) {
+				state = (bh->b_data[x] >> (GFS2_BIT_SIZE * y)) & 0x03;
+				if (state == GFS2_BLKST_FREE)
+					return ri->ri_data0 + bn;
+				bn++;
+			}
+	}
+	return 0;
+}
diff --git a/gfs2/fsck/util.h b/gfs2/fsck/util.h
index 80ed0c4..1a4811c 100644
--- a/gfs2/fsck/util.h
+++ b/gfs2/fsck/util.h
@@ -184,6 +184,8 @@ extern char generic_interrupt(const char *caller, const char *where,
                        const char *progress, const char *question,
                        const char *answers);
 extern char gfs2_getch(void);
+extern uint64_t find_free_blk(struct gfs2_sbd *sdp);
+
 #define stack log_debug("<backtrace> - %s()\n", __func__)
 
 #endif /* __UTIL_H__ */


More information about the cluster-commits mailing list