diff options
author | Prasanna Kumar Kalever <prasanna.kalever@redhat.com> | 2017-06-12 16:53:13 +0530 |
---|---|---|
committer | Prasanna Kumar Kalever <pkalever@redhat.com> | 2017-06-13 06:28:42 +0000 |
commit | f632a4b1243814c2568c29b18587dc5931792d06 (patch) | |
tree | b9366d3dfa9805ce731d04c69d5433fa7c26d5a7 /utils/common.c | |
parent | e87f76a1720d76bad198a0bb6c25d954e3c18a9c (diff) |
info: show size in human readable format
Also s/BLOCK CONFIG NODE(S)/EXPORTED NODE(S)/ in the info output
$ gluster-block info sample/block
NAME: block
VOLUME: sample
GBID: 6bd70984-be2c-43ac-9e9d-bad04010e42f
SIZE: 1.0 GiB
HA: 1
PASSWORD:
EXPORTED NODE(S): 192.168.0.105
Change-Id: I473b854b939c96b99be8e0b172ac6957b8bc6006
Fixes: #23
Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
Diffstat (limited to 'utils/common.c')
-rw-r--r-- | utils/common.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/utils/common.c b/utils/common.c index c42ce03..c6d1c34 100644 --- a/utils/common.c +++ b/utils/common.c @@ -38,7 +38,7 @@ jsonResponseFormatParse(const char *opt) ssize_t -glusterBlockCreateParseSize(const char *dom, char *value) +glusterBlockParseSize(const char *dom, char *value) { char *postfix; char *tmp; @@ -85,6 +85,7 @@ glusterBlockCreateParseSize(const char *dom, char *value) case 'k': sizef *= 1024; /* fall through */ + case 'B': case 'b': case '\0': return sizef; @@ -96,3 +97,27 @@ glusterBlockCreateParseSize(const char *dom, char *value) return -1; } } + + +char * +glusterBlockFormatSize(const char *dom, size_t bytes) +{ + char *buf; + size_t i = 0; + size_t rem = 0; + const char* units[] = {"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"}; + + + while (bytes >= 1024) { + rem = (bytes % 1024); + bytes /= 1024; + i++; + } + + if (GB_ASPRINTF(&buf, "%.1f %s", (float)bytes + (float)rem / 1024.0, units[i]) < 0) { + LOG(dom, GB_LOG_ERROR, "%s", "glusterBlockFormatSize() failed"); + buf = NULL; + } + + return buf; +} |