summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/common-utils.c
diff options
context:
space:
mode:
authorshishir gowda <shishirng@gluster.com>2011-07-29 16:30:36 +0530
committerAnand Avati <avati@gluster.com>2011-07-31 23:15:15 -0700
commit76acac485b9f06f36d145b4c31fa6f4da3c70f52 (patch)
tree8d3bcc7f3cbb0e498f77a7d6998a9e7865a234ad /libglusterfs/src/common-utils.c
parent9867f3954138e795123b4b308e256e641c55f3ec (diff)
IOBUF: Bring in variable iobuf support
Rebasing Raghavendra's patch to master Change-Id: Ie7a0c9a7b8e73cfe48c4573a5153460d5126208e BUG: 2472 Reviewed-on: http://review.gluster.com/12 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Amar Tumballi <amar@gluster.com> Reviewed-by: Anand Avati <avati@gluster.com>
Diffstat (limited to 'libglusterfs/src/common-utils.c')
-rw-r--r--libglusterfs/src/common-utils.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 5f9f4a5c0..cb1e5a445 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -1783,6 +1783,60 @@ out:
return flag;
}
+/*
+ * rounds up nr to power of two. If nr is already a power of two, just returns
+ * nr
+ */
+
+inline int32_t
+gf_roundup_power_of_two (uint32_t nr)
+{
+ uint32_t result = 1;
+
+ if (nr < 0) {
+ gf_log ("common-utils", GF_LOG_WARNING,
+ "negative number passed");
+ result = -1;
+ goto out;
+ }
+
+ while (result < nr) {
+ result *= 2;
+ }
+
+out:
+ return result;
+}
+
+/*
+ * rounds up nr to next power of two. If nr is already a power of two, next
+ * power of two is returned.
+ */
+
+/*
+ * rounds up nr to next power of two. If nr is already a power of two, next
+ * power of two is returned.
+ */
+
+inline int32_t
+gf_roundup_next_power_of_two (uint32_t nr)
+{
+ int32_t result = 1;
+
+ if (nr < 0) {
+ gf_log ("common-utils", GF_LOG_WARNING,
+ "negative number passed");
+ result = -1;
+ goto out;
+ }
+
+ while (result <= nr) {
+ result *= 2;
+ }
+
+out:
+ return result;
+}
int
validate_brick_name (char *brick)