FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Cluster Development

 
 
LinkBack Thread Tools
 
Old 09-02-2011, 08:42 PM
Carlos Maiolino
 
Default gfs2_grow: fix and move figure_out_rgsize() to libgfs2

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
 

Thread Tools




All times are GMT. The time now is 08:45 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org