diff options
author | shishir gowda <shishirng@gluster.com> | 2011-03-31 04:56:10 +0000 |
---|---|---|
committer | Vijay Bellur <vijay@dev.gluster.com> | 2011-03-31 05:04:36 -0700 |
commit | 58974b02b6ebb65ee1f7baf23b0fe6c3e7fcf8cd (patch) | |
tree | 20cfa527ff37e8a6b2a17aa871e2f0bdca939db2 | |
parent | 3b5195cfa4976e1d83646b70b0f08f583a7a1094 (diff) |
TOP: handle list-cnt behaviour uniformly.
Valid range is 0-100. if list-cnt is 0 or there are no files in the list,
handle it uniformly.
Signed-off-by: shishir gowda <shishirng@gluster.com>
Signed-off-by: Vijay Bellur <vijay@dev.gluster.com>
BUG: 2622 ()
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2622
-rw-r--r-- | cli/src/cli-cmd-parser.c | 18 | ||||
-rw-r--r-- | cli/src/cli-rpc-ops.c | 20 | ||||
-rw-r--r-- | xlators/debug/io-stats/src/io-stats.c | 4 |
3 files changed, 28 insertions, 14 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 66e5643fcb9..69f95653d2a 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -1253,7 +1253,7 @@ cli_cmd_volume_top_parse (const char **words, int wordcount, int ret = -1; gf1_cli_stats_op op = GF_CLI_STATS_NONE; gf1_cli_top_op top_op = GF_CLI_TOP_NONE; - int32_t list_cnt = 0; + int32_t list_cnt = -1; int index = 0; int perf = 0; int32_t blk_size = 0; @@ -1332,15 +1332,11 @@ cli_cmd_volume_top_parse (const char **words, int wordcount, } else if (!strcmp (key, "list-cnt")) { list_cnt = atoi(value); - if (!list_cnt) { - list_cnt = 100; - } - if (list_cnt < 1 || list_cnt > 100) { - cli_out ("list-cnt should be between 1 to 100"); + if (list_cnt < 0 || list_cnt > 100) { + cli_out ("list-cnt should be between 0 to 100"); ret = -1; goto out; } - ret = dict_set_int32 (dict, "list-cnt", list_cnt); } else if (perf && !strcmp (key, "bs")){ blk_size = atoi (value); if (blk_size < 0){ @@ -1369,6 +1365,14 @@ cli_cmd_volume_top_parse (const char **words, int wordcount, goto out; } } + if (list_cnt == -1) + list_cnt = 100; + ret = dict_set_int32 (dict, "list-cnt", list_cnt); + if (ret) { + gf_log ("", GF_LOG_WARNING, "Dict set failed for list_cnt"); + goto out; + } + *options = dict; out: if (ret && dict) diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 92658af4735..e1f51d306ec 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -3184,7 +3184,7 @@ gf_cli3_1_top_volume_cbk (struct rpc_req *req, struct iovec *iov, dict_t *dict = NULL; gf1_cli_stats_op op = GF_CLI_STATS_NONE; char key[256] = {0}; - int i = 1; + int i = 0; int32_t brick_count = 0; char brick[1024]; int32_t members = 0; @@ -3251,16 +3251,20 @@ gf_cli3_1_top_volume_cbk (struct rpc_req *req, struct iovec *iov, ret = dict_get_int32 (dict, "count", &brick_count); if (ret) goto out; - snprintf (key, sizeof (key), "%d-top-op", i); + snprintf (key, sizeof (key), "%d-top-op", 1); ret = dict_get_int32 (dict, key, (int32_t*)&top_op); if (ret) goto out; while (i <= brick_count) { + i++; snprintf (brick, sizeof (brick), "%d-brick", i); ret = dict_get_str (dict, brick, &bricks); if (ret) goto out; cli_out ("Brick: %s", bricks); + snprintf(key, sizeof (key), "%d-members", i); + ret = dict_get_int32 (dict, key, &members); + switch (top_op) { case GF_CLI_TOP_OPEN: snprintf (key, sizeof (key), "%d-current-open", i); @@ -3277,6 +3281,10 @@ gf_cli3_1_top_volume_cbk (struct rpc_req *req, struct iovec *iov, case GF_CLI_TOP_WRITE: case GF_CLI_TOP_OPENDIR: case GF_CLI_TOP_READDIR: + if (!members) { + cli_out ("No entries in list"); + continue; + } cli_out ("Count\t\tfilename\n======================="); break; case GF_CLI_TOP_READ_PERF: @@ -3291,13 +3299,16 @@ gf_cli3_1_top_volume_cbk (struct rpc_req *req, struct iovec *iov, cli_out ("Throughput %.2f MBps time %.4f secs", throughput, time / 1e6); + if (!members) { + cli_out ("No entries in list"); + continue; + } cli_out ("MBps\t\tfilename\t\t time\n========================"); break; default: goto out; } - snprintf(key, sizeof (key), "%d-members", i); - ret = dict_get_int32 (dict, key, &members); + for (j = 1; j <= members; j++) { snprintf (key, sizeof (key), "%d-filename-%d", i, j); ret = dict_get_str (dict, key, &filename); @@ -3329,7 +3340,6 @@ gf_cli3_1_top_volume_cbk (struct rpc_req *req, struct iovec *iov, cli_out ("%"PRIu64"\t\t%s", value, filename); } } - i++; } ret = rsp.op_ret; diff --git a/xlators/debug/io-stats/src/io-stats.c b/xlators/debug/io-stats/src/io-stats.c index 863f77a2ae1..d4dd786ab78 100644 --- a/xlators/debug/io-stats/src/io-stats.c +++ b/xlators/debug/io-stats/src/io-stats.c @@ -1039,6 +1039,8 @@ io_stats_dump_stats_to_dict (xlator_t *this, dict_t *resp, goto out; } ret = dict_set_int32 (resp, "top-op", flags); + if (!list_cnt) + goto out; LOCK (&list_head->lock); { list_for_each_entry (entry, &list_head->iosstats->list, list) { @@ -2600,8 +2602,6 @@ notify (xlator_t *this, int32_t event, void *data, ...) ret = dict_get_int32 (dict, "top-op", &top_op); if (!ret) { ret = dict_get_int32 (dict, "list-cnt", &list_cnt); - if (!list_cnt) - list_cnt = 100; if (top_op > IOS_STATS_TYPE_NONE && top_op < IOS_STATS_TYPE_MAX) ret = io_stats_dump_stats_to_dict (this, output, |