From: Carlos Maiolino <cmaiolino@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 1/2] gfs2_grow: fix and move figure_out_rgsize() to libgfs2
Date: Fri, 2 Sep 2011 17:42:47 -0300 [thread overview]
Message-ID: <1314996168-4369-1-git-send-email-cmaiolino@redhat.com> (raw)
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
next reply other threads:[~2011-09-02 20:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-02 20:42 Carlos Maiolino [this message]
2011-09-02 20:42 ` [Cluster-devel] [PATCH 2/2] libgfs2: fix compute_rgrp_layout Carlos Maiolino
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1314996168-4369-1-git-send-email-cmaiolino@redhat.com \
--to=cmaiolino@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).