All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cluster-devel] [PATCH 1/2] gfs2_grow: fix and move figure_out_rgsize() to libgfs2
@ 2011-09-02 20:42 Carlos Maiolino
  2011-09-02 20:42 ` [Cluster-devel] [PATCH 2/2] libgfs2: fix compute_rgrp_layout Carlos Maiolino
  0 siblings, 1 reply; 2+ messages in thread
From: Carlos Maiolino @ 2011-09-02 20:42 UTC (permalink / raw)
  To: cluster-devel.redhat.com

This patch fix the rgsize calculation into the
figure_out_rgsize() function, and move the function
to libgfs2, since there is more than one place into
gfs2 which needs to calculate the rgsize, so, it's
useful to have this function available to any other
part of gfs2-utils.

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
---
 gfs2/libgfs2/libgfs2.h |    1 +
 gfs2/libgfs2/rgrp.c    |   64 ++++++++++++++++++++++++++++++++++++++++++++++++
 gfs2/mkfs/main_grow.c  |   19 +-------------
 3 files changed, 66 insertions(+), 18 deletions(-)

diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 53df6cd..c8d7758 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -708,6 +708,7 @@ extern void gfs2_rgrp_relse(struct rgrp_tree *rgd);
 extern struct rgrp_tree *rgrp_insert(struct osi_root *rgtree,
 				     uint64_t rgblock);
 extern void gfs2_rgrp_free(struct osi_root *rgrp_tree);
+extern unsigned int figure_out_rgsize(struct gfs2_sbd *sdp);
 
 /* structures.c */
 extern int build_master(struct gfs2_sbd *sdp);
diff --git a/gfs2/libgfs2/rgrp.c b/gfs2/libgfs2/rgrp.c
index e7b5f72..dcbccf2 100644
--- a/gfs2/libgfs2/rgrp.c
+++ b/gfs2/libgfs2/rgrp.c
@@ -228,3 +228,67 @@ void gfs2_rgrp_free(struct osi_root *rgrp_tree)
 		free(rgd);
 	}
 }
+
+/*is_power_of_2 - check if a number is a power of 2
+ *
+ *num - the number to be checked
+ * return:
+ * 	non-zero - if num is a power of 2
+ *	zero     - if num is not a power of 2
+ *
+ */
+static inline unsigned int is_power_of_2(unsigned int num)
+{
+        return (num != 0) && ((num & (num - 1)) == 0);
+}
+
+/*get_next_power_of_2 - returns the next nearest power 
+ * 			of 2 number from num
+ *
+ * num - the current non power of 2 number
+ */
+static inline unsigned int get_next_power_of_2(unsigned int num)
+{
+        int power;
+
+        for(power = 1; power < 31; power++){
+                num = num | (num >> power);
+        }
+        return num + 1;
+}
+
+unsigned int figure_out_rgsize(struct gfs2_sbd *sdp)
+{
+
+	struct osi_node *n = osi_first(&sdp->rgtree);
+	struct rgrp_tree *r1;
+	unsigned int rgsize, rbsize, bcount, tmp_bcount;
+	int bitblocks;
+
+	sdp->rgsize = GFS2_DEFAULT_RGSIZE;
+	r1 = (struct rgrp_tree *)n;
+
+	/* Get number of bitmap blocks*/
+	if (r1->ri.ri_bitbytes % sdp->bsize){
+		bitblocks = (r1->ri.ri_bitbytes / sdp->bsize) + 1;
+	}else{
+		bitblocks = r1->ri.ri_bitbytes / sdp->bsize;
+	}
+
+	/* Get amount of blocks in the RG */
+	rbsize = bitblocks + r1->ri.ri_data;
+
+	/* Get amount of bytes in the RG */
+	bcount = rbsize * sdp->bsize;
+
+	/*RGs should be power of 2. If the current RG
+	 *is not a power of 2, assume the next power*/
+	if(is_power_of_2(bcount)){
+		rgsize = rbsize;
+	}else{
+		tmp_bcount = get_next_power_of_2(bcount);
+		rgsize = (tmp_bcount - 1) / sdp->bsize;
+	}
+	
+	return rgsize;
+}
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index dc092ee..48bd2da 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -122,23 +122,6 @@ static void decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp)
 }
 
 /**
- * figure_out_rgsize
- */
-static void figure_out_rgsize(struct gfs2_sbd *sdp, unsigned int *orgsize)
-{
-	struct osi_node *n = osi_first(&sdp->rgtree), *next = NULL;
-	struct rgrp_tree *r1, *r2;
-
-	sdp->rgsize = GFS2_DEFAULT_RGSIZE;
-	next = osi_next(n);
-	r1 = (struct rgrp_tree *)next;
-	next = osi_next(next);
-	r2 = (struct rgrp_tree *)next;
-
-	*orgsize = r2->ri.ri_addr - r1->ri.ri_addr;
-}
-
-/**
  * filesystem_size - Calculate the size of the filesystem
  *
  * Reads the lists of resource groups in order to
@@ -391,7 +374,7 @@ main_grow(int argc, char *argv[])
 		/* the existing RGs, and only write to the index at EOF.    */
 		ri_update(sdp, rindex_fd, &rgcount, &sane);
 		fssize = filesystem_size(sdp);
-		figure_out_rgsize(sdp, &rgsize);
+		rgsize = figure_out_rgsize(sdp);
 		fsgrowth = ((sdp->device.length - fssize) * sdp->bsize);
 		if (fsgrowth < rgsize * sdp->bsize) {
 			log_err( _("Error: The device has grown by less than "
-- 
1.7.6



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [Cluster-devel] [PATCH 2/2] libgfs2: fix compute_rgrp_layout
  2011-09-02 20:42 [Cluster-devel] [PATCH 1/2] gfs2_grow: fix and move figure_out_rgsize() to libgfs2 Carlos Maiolino
@ 2011-09-02 20:42 ` Carlos Maiolino
  0 siblings, 0 replies; 2+ messages in thread
From: Carlos Maiolino @ 2011-09-02 20:42 UTC (permalink / raw)
  To: cluster-devel.redhat.com

The function uses the same buggy trick as
gfs2_grow to calculate rgsize, which cause
a segmentation fault if there is only one
RG into the filesystem.
This patch makes compute_rgrp_layout() to
use figure_out_rgsize() function.

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
---
 gfs2/libgfs2/fs_geometry.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/gfs2/libgfs2/fs_geometry.c b/gfs2/libgfs2/fs_geometry.c
index 2b70f11..bdc8225 100644
--- a/gfs2/libgfs2/fs_geometry.c
+++ b/gfs2/libgfs2/fs_geometry.c
@@ -80,8 +80,8 @@ void compute_rgrp_layout(struct gfs2_sbd *sdp, struct osi_root *rgtree,
 	struct device *dev;
 	struct rgrp_tree *rl, *rlast = NULL, *rlast2 = NULL;
 	struct osi_node *n, *next = NULL;
-	unsigned int rgrp = 0, nrgrp;
-	uint64_t rglength, rgaddr;
+	unsigned int rgrp = 0, nrgrp, rglength;
+	uint64_t rgaddr;
 
 	sdp->new_rgrps = 0;
 	dev = &sdp->device;
@@ -113,7 +113,7 @@ void compute_rgrp_layout(struct gfs2_sbd *sdp, struct osi_root *rgtree,
 			rlast = rl;
 		}
 		rlast->start = rlast->ri.ri_addr;
-		rglength = rlast->ri.ri_addr - rlast2->ri.ri_addr;
+		rglength = figure_out_rgsize(sdp);
 		rlast->length = rglength;
 		old_length = rlast->ri.ri_addr + rglength;
 		new_chunk = dev->length - old_length;
-- 
1.7.6



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-09-02 20:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-02 20:42 [Cluster-devel] [PATCH 1/2] gfs2_grow: fix and move figure_out_rgsize() to libgfs2 Carlos Maiolino
2011-09-02 20:42 ` [Cluster-devel] [PATCH 2/2] libgfs2: fix compute_rgrp_layout Carlos Maiolino

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.