diff options
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | cli/gluster-block.c | 2 | ||||
-rw-r--r-- | rpc/block_svc_routines.c | 28 | ||||
-rw-r--r-- | utils/common.c | 27 | ||||
-rw-r--r-- | utils/common.h | 4 |
5 files changed, 50 insertions, 15 deletions
@@ -163,9 +163,9 @@ sample-block NAME: sample-block VOLUME: block-test GBID: 6b60c53c-8ce0-4d8d-a42c-5b546bca3d09 -SIZE: 1073741824 +SIZE: 1.0 GiB HA: 3 -BLOCK CONFIG NODE(S): 192.168.1.11 192.168.1.12 192.168.1.13 +EXPORTED NODE(S): 192.168.1.11 192.168.1.12 192.168.1.13 </pre> <b>NOTE:</b> Block targets created using gluster-block utility will use TPG: 1 and LUN: 0. diff --git a/cli/gluster-block.c b/cli/gluster-block.c index f2334e6..833f232 100644 --- a/cli/gluster-block.c +++ b/cli/gluster-block.c @@ -386,7 +386,7 @@ glusterBlockCreate(int argcount, char **options, int json) } /* last arg will be size */ - sparse_ret = glusterBlockCreateParseSize("cli", options[optind]); + sparse_ret = glusterBlockParseSize("cli", options[optind]); if (sparse_ret < 0) { MSG("%s\n", "'<size>' is incorrect"); MSG("%s\n", GB_CREATE_HELP_STR); diff --git a/rpc/block_svc_routines.c b/rpc/block_svc_routines.c index 094e3ff..f2efbaf 100644 --- a/rpc/block_svc_routines.c +++ b/rpc/block_svc_routines.c @@ -2635,6 +2635,7 @@ blockInfoCliFormatResponse(blockInfoCli *blk, int errCode, char *tmp = NULL; char *out = NULL; int i = 0; + char *hr_size = NULL; /* Human Readable size */ if (!reply) { return; @@ -2649,8 +2650,16 @@ blockInfoCliFormatResponse(blockInfoCli *blk, int errCode, return; } - if (!info) { - return; + if (!info) + goto out; + + hr_size = glusterBlockFormatSize("mgmt", info->size); + if (!hr_size) { + GB_ASPRINTF (&errMsg, "%s", "failed in glusterBlockFormatSize"); + blockFormatErrorResponse(INFO_SRV, blk->json_resp, ENOMEM, + errMsg, reply); + GB_FREE(errMsg); + goto out; } if (blk->json_resp) { @@ -2658,7 +2667,7 @@ blockInfoCliFormatResponse(blockInfoCli *blk, int errCode, json_object_object_add(json_obj, "NAME", GB_JSON_OBJ_TO_STR(blk->block_name)); json_object_object_add(json_obj, "VOLUME", GB_JSON_OBJ_TO_STR(info->volume)); json_object_object_add(json_obj, "GBID", GB_JSON_OBJ_TO_STR(info->gbid)); - json_object_object_add(json_obj, "SIZE", json_object_new_int64(info->size)); + json_object_object_add(json_obj, "SIZE", GB_JSON_OBJ_TO_STR(hr_size)); json_object_object_add(json_obj, "HA", json_object_new_int(info->mpath)); json_object_object_add(json_obj, "PASSWORD", GB_JSON_OBJ_TO_STR(info->passwd)); @@ -2670,7 +2679,7 @@ blockInfoCliFormatResponse(blockInfoCli *blk, int errCode, } } - json_object_object_add(json_obj, "BLOCK CONFIG NODE(S)", json_array); + json_object_object_add(json_obj, "EXPORTED NODE(S)", json_array); GB_ASPRINTF(&reply->out, "%s\n", json_object_to_json_string_ext(json_obj, @@ -2678,10 +2687,10 @@ blockInfoCliFormatResponse(blockInfoCli *blk, int errCode, json_object_put(json_array); json_object_put(json_obj); } else { - if (GB_ASPRINTF(&tmp, "NAME: %s\nVOLUME: %s\nGBID: %s\nSIZE: %zu\n" - "HA: %zu\nPASSWORD: %s\nBLOCK CONFIG NODE(S):", - blk->block_name, info->volume, info->gbid, info->size, info->mpath, - info->passwd) == -1) { + if (GB_ASPRINTF(&tmp, "NAME: %s\nVOLUME: %s\nGBID: %s\nSIZE: %s\n" + "HA: %zu\nPASSWORD: %s\nEXPORTED NODE(S):", + blk->block_name, info->volume, info->gbid, hr_size, + info->mpath, info->passwd) == -1) { goto out; } for (i = 0; i < info->nhosts; i++) { @@ -2702,9 +2711,10 @@ blockInfoCliFormatResponse(blockInfoCli *blk, int errCode, out: /*catch all*/ if (!reply->out) { - blockFormatErrorResponse(DELETE_SRV, blk->json_resp, errCode, + blockFormatErrorResponse(INFO_SRV, blk->json_resp, errCode, GB_DEFAULT_ERRMSG, reply); } + GB_FREE(hr_size); return; } 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; +} diff --git a/utils/common.h b/utils/common.h index 21bf855..118d3f0 100644 --- a/utils/common.h +++ b/utils/common.h @@ -52,8 +52,8 @@ static const char *const JsonResponseFormatLookup[] = { enum JsonResponseFormat jsonResponseFormatParse(const char *opt); -int convertStringToTrillianParse(const char *opt); +ssize_t glusterBlockParseSize(const char *dom, char *value); -ssize_t glusterBlockCreateParseSize(const char *dom, char *value); +char* glusterBlockFormatSize(const char *dom, size_t bytes); # endif /* _COMMON_H */ |