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 /rpc | |
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 'rpc')
-rw-r--r-- | rpc/block_svc_routines.c | 28 |
1 files changed, 19 insertions, 9 deletions
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; } |