From e5838eeea0ccc4ff6af6457be6d7ac8736ee748e Mon Sep 17 00:00:00 2001 From: Sachin Pandit Date: Fri, 22 Nov 2013 12:18:48 +0530 Subject: mgmt/glusterd : snapshot list, minor fixes. This patch fixes the below mentioned issue. Snapshot list : Listing number of snaps available. Display proper message if snapshot not present. Change-Id: Iabfc47430a9c89fb5114e33e9feb7ef21973fc6a Signed-off-by: Sachin Pandit --- cli/src/cli-rpc-ops.c | 81 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 22 deletions(-) (limited to 'cli/src/cli-rpc-ops.c') diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index c625cc955..830bd763f 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -7534,13 +7534,14 @@ out: /*Function to list the snap "gluster snapshot list" */ static int list_snap_of_volume (dict_t *dict_n, char *prefix_str) { - int64_t snapcount_total = -1 ; - int64_t snapcount = -1 ; - char buffer[PATH_MAX] = "" ; - char *get_buffer = NULL; - int8_t detail = 0 ; - int64_t i = 0 ; - int ret = -1 ; + uint64_t snapcount_total = 0 ; + uint64_t snapcount = 0 ; + char buffer[PATH_MAX] = "" ; + char *get_buffer = NULL; + int8_t detail = 0 ; + uint64_t i = 0 ; + int ret = -1 ; + uint64_t snap_available = 0 ; GF_ASSERT (dict_n); GF_ASSERT (prefix_str); @@ -7574,7 +7575,7 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) { ret = 0; goto out; } - cli_out ("Vol Name : %s", get_buffer); + cli_out ("\nVolume Name : %s", get_buffer); /* if Volume is present then get the snapcount. * string is "snaplist.vol{0..}.snap-count. */ @@ -7583,7 +7584,7 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) { if (ret < 0) { /* Negative value is an error */ goto out; } - ret = dict_get_int64 (dict_n, buffer, &snapcount); + ret = dict_get_uint64 (dict_n, buffer, &snapcount); if (ret) { gf_log("", GF_LOG_ERROR, "Could not fetch snapcount"); goto out; @@ -7596,17 +7597,37 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) { goto out; } + /* "snap-count-total" holds number of snapshots taken + * whereas "snap-count" holds number of snapshots to + * be displayed + * Ex : gluster snapshot list vol1 -s snap1 + * Here "snap-count-total" contains number of snapshots + * of volume "vol1", whereas "snap-count" is 1 here, + * as we are displaying details of only 1 snap "snap1" + */ ret = snprintf (buffer, sizeof (buffer), "%s.snap-count-total", prefix_str); if (ret < 0) { goto out; } - ret = dict_get_int64 (dict_n, buffer, &snapcount_total); + ret = dict_get_uint64 (dict_n, buffer, &snapcount_total); if (!ret) - cli_out ("Total Snap Count : %ld", snapcount_total); + cli_out ("Number of snaps taken : %ld", snapcount_total); else gf_log ("", GF_LOG_ERROR, "Failed to get snapcount total"); + ret = snprintf (buffer, sizeof (buffer), + "%s.snap-available", prefix_str); + if (ret < 0) { + goto out; + } + ret = dict_get_uint64 (dict_n, buffer, &snap_available); + if (!ret) + cli_out ("Number of snaps available : %ld", + snap_available); + else + gf_log ("", GF_LOG_ERROR, "Failed to get snap-available"); + for (i = 0 ; i < snapcount; i++) { /* get snapname "snaplist.vol-{0..}.snap-{0..}.snapname" */ ret = snprintf (buffer, sizeof(buffer), @@ -7707,8 +7728,8 @@ list_snap_of_cg (dict_t *dict) { int8_t detail = 0 ; char *get_buffer = NULL; char cg_name_list[PATH_MAX] = "" ; - int64_t cg_volcount = -1 ; - int64_t i = -1 ; + int64_t cg_volcount = 0 ; + uint64_t i = 0 ; GF_ASSERT(dict); @@ -7786,8 +7807,8 @@ out : static int call_list_snap_of_volume(dict_t *dict){ int ret = -1; - int64_t volcount = -1; - int64_t i = -1; + int64_t volcount = 0; + uint64_t i = 0; char vol_name_prefix[PATH_MAX] = ""; ret = dict_get_int64 (dict, "snaplist.vol-count", &volcount); @@ -7947,17 +7968,33 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov, */ ret = dict_get_int64 (dict, "snaplist.vol-count", &volcount); if (ret){ - gf_log("", GF_LOG_ERROR, "Could not fetch volcount"); - ret = -1; + /* if "snaplist.vol-count" is not present then check + * whether "snaplist.cg-0.vol-count" is present + */ + ret = dict_get_int64 (dict, "snaplist.cg-0.vol-count", + &volcount); + if (ret) { + gf_log ("", GF_LOG_ERROR, "Could not fetch" + " cg-volcount"); + goto out; + } + ret = list_snap_of_cg (dict); + if (ret) { + gf_log ("", GF_LOG_ERROR, + "Could not list snaps present in CG"); + } goto out; } if (volcount >= 1) { ret = call_list_snap_of_volume (dict); - } else { - /* get the volumes present in CG - * and list snap of each volume - */ - ret = list_snap_of_cg (dict); + if (ret) { + gf_log ("", GF_LOG_ERROR, + "Could not list snaps of volume"); + goto out; + } + } + else { + cli_out ("Snapshots not present"); } break; -- cgit