From 30e6c5364a0484fddc655d43cd3a0224f21343e4 Mon Sep 17 00:00:00 2001 From: Sachin Pandit Date: Thu, 24 Oct 2013 10:35:58 +0000 Subject: CLI : Snapshot List,Integration with glusterd Change in Naming convention: "snap_details", "snap_count" and so on is replaced by "snap-details", "snap-count" so on. Total snapcount introduced. Separate check is made for repeated Volume Name Ex : "gluster snapshot list vol1 vol2 vol1 vol2" is considered as "gluster snapshot list vol1 vol2" *This is still a work in progress* *have to test CG list once CG Store is ready* Change-Id: I45e2904eb8bdbf78de8665f20ba9605c38320307 Signed-off-by: Sachin Pandit --- cli/src/cli-cmd-parser.c | 96 ++++++++++++++++++++++++++++++++++++++---------- cli/src/cli-rpc-ops.c | 66 +++++++++++++++++++-------------- 2 files changed, 115 insertions(+), 47 deletions(-) (limited to 'cli') diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index cf743e22b..cf790918c 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -2972,6 +2972,26 @@ out: return ret; } +/* Function to check whether the Volume name is repeated */ +int +check_if_volname_repeated (char *volname, const char **words, + int64_t start_index, int64_t end_index) { + int64_t i = -1; + int ret = 0; + + GF_ASSERT (volname); + GF_ASSERT (words); + + for (i = start_index ; i < end_index ; i++) { + if (strcmp (words[i], (char *)volname) == 0) { + ret = -1; + goto out; + } + } +out : + return ret; +} + /* snapshot list [ | -s | -c ] [-d] * cmdi is command index which contains number of standard arguments in * command, here cmdi is 2 i.e "gluster snapshot list" @@ -2979,21 +2999,29 @@ out: int cli_snap_list_parse (dict_t *dict, const char **words, int wordcount, int cmdi) { - int ret = -1; - int i = 0; - int64_t vol_count = 0; - int vol_start_index = -1; - int8_t snap_details = 0; - char *snap_name = NULL; - char *cg_name = NULL; - char *vol_name = NULL; - char key[256] = ""; + int ret = -1; + int loop_ret = -1; + int64_t actual_vol_count = 0; + int64_t i = 0; + int64_t vol_count = 0; + int vol_start_index = -1; + int8_t snap_details = 0; + const char *snap_name = NULL; + const char *cg_name = NULL; + const char *vol_name = NULL; + char key[256] = ""; GF_ASSERT (dict); GF_ASSERT (words); GF_ASSERT (wordcount >= cmdi); /* if command is "gluster snapshot list*/ if (wordcount == cmdi) { + ret = dict_set_int8 (dict, "snap-details", snap_details); + if (ret) { + gf_log("", GF_LOG_ERROR, "Failed to set snap-details"); + ret = -1; + goto out; + } ret = 0; goto out; } @@ -3004,6 +3032,7 @@ cli_snap_list_parse (dict_t *dict, const char **words, int wordcount, int cmdi) /* If option is already set */ gf_log("", GF_LOG_ERROR, "snap_details already set"); + ret = -1; goto out; } snap_details = 1; @@ -3018,10 +3047,12 @@ cli_snap_list_parse (dict_t *dict, const char **words, int wordcount, int cmdi) */ gf_log("", GF_LOG_ERROR, "Invalid snap_name" " or snap_name already parsed" - " or volname specified is not equal 1"); + " or number of volumes greater than 1"); + ret = -1; goto out; } - snap_name = (char*) words[i]; // word followed by -s is snapname + /* word followed by -s is snapname */ + snap_name = words[i]; } else if (strcmp (words[i], "-c") == 0) { if ((wordcount - 1) == i || (cg_name != NULL) || strcmp (words[++i], "-d") == 0 @@ -3031,14 +3062,16 @@ cli_snap_list_parse (dict_t *dict, const char **words, int wordcount, int cmdi) */ gf_log("", GF_LOG_ERROR, "Invalid cg_name" " or cg_name already parsed"); + ret = -1; goto out; } - cg_name = (char*) words[i]; + cg_name = words[i]; } else { if (vol_count != 0) { /* if vol names already set */ gf_log("", GF_LOG_ERROR, "Vol Names already set"); + ret = -1; goto out; } @@ -3061,6 +3094,11 @@ cli_snap_list_parse (dict_t *dict, const char **words, int wordcount, int cmdi) } } + ret = dict_set_int8 (dict, "snap-details", snap_details); + if (ret) { + gf_log("", GF_LOG_ERROR, "Failed to set snap-details"); + goto out; + } /* if CG name is present in the command then fill it to dictionary */ if (cg_name != NULL) { if (snap_name != NULL || vol_count != 0) { @@ -3070,11 +3108,13 @@ cli_snap_list_parse (dict_t *dict, const char **words, int wordcount, int cmdi) */ gf_log("", GF_LOG_ERROR, "details of single snap" " belonging to a CG is not supported"); + ret = -1; goto out; } - ret = dict_set_str(dict, "cg_name", cg_name); + ret = dict_set_str(dict, "cgname", (char *)cg_name); if (ret) { - gf_log("", GF_LOG_ERROR, "Failed to set cg_name"); + gf_log("", GF_LOG_ERROR, + "Failed to set CG name %s", cg_name); goto out; } } else { @@ -3082,25 +3122,41 @@ cli_snap_list_parse (dict_t *dict, const char **words, int wordcount, int cmdi) * then fill it to dictionary */ if (snap_name != NULL) { - ret = dict_set_str (dict, "snap_name", snap_name); + ret = dict_set_str (dict, "snapname", + (char *)snap_name); if (ret) { gf_log ("", GF_LOG_ERROR, - "Failed to set snap_name"); + "Failed to set snap name %s", + snap_name); + ret = -1; goto out; } } - ret = dict_set_int64 (dict, "vol_count", vol_count); /* fill volume name in dictionary */ for (i = 0; i < vol_count; ++i) { vol_name = (char*) words[vol_start_index + i]; - snprintf (key, sizeof (key), "vol%d", i); - ret = dict_set_str (dict, key, vol_name); + /* check if volume name is repeated */ + if (i >= 1) + loop_ret = check_if_volname_repeated + ((char *)vol_name, words, + vol_start_index, vol_start_index+i); + if (loop_ret == -1 && i>=1) + continue; + snprintf (key, sizeof (key), "vol%ld", actual_vol_count); + ret = dict_set_str (dict, key, (char *)vol_name); if (ret) { gf_log("", GF_LOG_ERROR, - "Failed to set vol_name"); + "Failed to set Volume Name %s", + vol_name); goto out; } + actual_vol_count++; + } + ret = dict_set_int64 (dict, "vol-count", actual_vol_count); + if (ret) { + gf_log("", GF_LOG_ERROR, "Failed to set Volume Count"); + ret = -1; } } out: diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 50eeda3d2..20cad3bb3 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -7522,6 +7522,7 @@ 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; @@ -7541,7 +7542,7 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) { * if volume not present then display that volume doesnot exist * and try to fetch next volume mentioned */ - ret = snprintf (buffer, sizeof(buffer), "%s.vol_name", prefix_str); + ret = snprintf (buffer, sizeof(buffer), "%s.volname", prefix_str); if (ret < 0) { /* Negative value is an error */ goto out; } @@ -7552,10 +7553,10 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) { } cli_out ("Vol Name : %s", get_buffer); /* if Volume is present then get the snapcount. - * string is "snaplist.vol{0..}.snap_count. + * string is "snaplist.vol{0..}.snap-count. */ ret = snprintf (buffer, sizeof(buffer), - "%s.snap_count", prefix_str); + "%s.snap-count", prefix_str); if (ret < 0) { /* Negative value is an error */ goto out; } @@ -7566,28 +7567,38 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) { } /* To check if the user has given "-d" option */ - ret = dict_get_int8 (dict_n, "snap_details", &detail); + ret = dict_get_int8 (dict_n, "snap-details", &detail); if (ret) { gf_log ("",GF_LOG_ERROR, "could not get snap_details status"); goto out; } - cli_out ("Number of Snaps Taken : %ld", snapcount); + 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); + if (!ret) + cli_out ("Total Snap Count : %ld", snapcount_total); + else + gf_log ("", GF_LOG_ERROR, "Failed to get snapcount total"); + for (i = 0 ; i < snapcount; i++) { - /* get snapname "snaplist.vol{0..}.snap{0..}.snap_name" */ + /* get snapname "snaplist.vol-{0..}.snap-{0..}.snapname" */ ret = snprintf (buffer, sizeof(buffer), - "%s.snap%ld.snap_name", prefix_str,i); + "%s.snap-%ld.snapname", prefix_str,i); if (ret < 0) { /* Negative value is an error */ goto out; } ret = dict_get_str (dict_n, buffer, &get_buffer); if (!ret) - cli_out ("\tSnap Name : %s",get_buffer); + cli_out ("\n\tSnap Name : %s",get_buffer); else - cli_out ("\tSnap Name : %s","Does not exist"); + cli_out ("\n\tSnap Name : %s","Does not exist"); ret = snprintf (buffer, sizeof(buffer), - "%s.snap%ld.snap_time", prefix_str, i); + "%s.snap-%ld.snap-time", prefix_str, i); if (ret < 0) { /* Negative value is an error */ goto out; } @@ -7598,7 +7609,7 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) { cli_out ("\tSnap Time : %s","Does not exist"); - ret = snprintf (buffer, sizeof(buffer), "%s.snap%ld.snap_id" + ret = snprintf (buffer, sizeof(buffer), "%s.snap-%ld.snap-id" , prefix_str, i); if (ret < 0) { /* Negative value is an error */ goto out; @@ -7616,7 +7627,7 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) { continue; } ret = snprintf (buffer, sizeof(buffer), - "%s.snap%ld.cg_name", prefix_str, i); + "%s.snap-%ld.cgname", prefix_str, i); if (ret < 0) { /* Negative value is an error */ goto out; } @@ -7627,7 +7638,7 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) { cli_out("\tCG Name : %s","Does not exist"); ret = snprintf (buffer, sizeof(buffer), - "%s.snap%ld.cg_id", prefix_str, i); + "%s.snap-%ld.cg-id", prefix_str, i); if (ret < 0) { /* Negative value is an error */ goto out; } @@ -7638,7 +7649,7 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) { cli_out("\tCG ID : %s","Does not exist"); ret = snprintf (buffer, sizeof(buffer), - "%s.snap%ld.snap_desc", prefix_str, i); + "%s.snap-%ld.snap-desc", prefix_str, i); if (ret < 0) { /* Negative value is an error */ goto out; } @@ -7650,7 +7661,7 @@ list_snap_of_volume (dict_t *dict_n, char *prefix_str) { "Description not present"); ret = snprintf (buffer, sizeof(buffer), - "%s.snap%ld.snap_status", prefix_str, i); + "%s.snap-%ld.snap-status", prefix_str, i); if (ret < 0) { /* Negative value is an error */ goto out; } @@ -7683,13 +7694,13 @@ list_snap_of_cg (dict_t *dict) { * or else we can keep that string in some variable * and use the same variable every where */ - ret = dict_get_int8 (dict, "snap_details", &detail); + ret = dict_get_int8 (dict, "snap-details", &detail); if (ret) { gf_log ("", GF_LOG_ERROR, "could not get snap_details status"); goto out; } - ret = dict_get_str (dict, "snaplist.cg0.cg_name", &get_buffer); + ret = dict_get_str (dict, "snaplist.cg-0.cgname", &get_buffer); if (ret) { /* if cg_name is not present then exit, it is not necessary * to check other details if cg_name is not present @@ -7700,14 +7711,15 @@ list_snap_of_cg (dict_t *dict) { } cli_out ("CG Name : %s", get_buffer); - ret = dict_get_str (dict, "snaplist.cg0.cg_id", &get_buffer); + ret = dict_get_str (dict, "snaplist.cg-0.cg-id", &get_buffer); if (!ret) cli_out ("CG ID : %s",get_buffer); else cli_out ("CG ID : %s","Does not exist"); if (detail == 1) { - ret = dict_get_str (dict, "snaplist.cg0.cg_desc", &get_buffer); + ret = dict_get_str (dict, + "snaplist.cg-0.cg-desc", &get_buffer); if (!ret) cli_out ("CG Description : %s", get_buffer); @@ -7715,7 +7727,7 @@ list_snap_of_cg (dict_t *dict) { cli_out ("CG Description : %s", "Does not exist"); - ret = dict_get_str (dict, "snaplist.cg0.cg_status", + ret = dict_get_str (dict, "snaplist.cg-0.cg-status", &get_buffer); if (!ret) cli_out ("CG Status : %s", get_buffer); @@ -7725,7 +7737,7 @@ list_snap_of_cg (dict_t *dict) { } - ret = dict_get_int64 (dict, "snaplist.cg0.vol_count", &cg_volcount); + ret = dict_get_int64 (dict, "snaplist.cg-0.vol-count", &cg_volcount); if (ret) { gf_log ("", GF_LOG_ERROR, "Could not fetch cg_volcount"); goto out; @@ -7733,7 +7745,7 @@ list_snap_of_cg (dict_t *dict) { /* list the snaps of each volume present in a CG*/ for (i = 0 ; i < cg_volcount ; i++){ ret = snprintf (cg_name_list, sizeof(cg_name_list), - "snaplist.cg0.vol%ld",i); + "snaplist.cg-0.vol%ld",i); if (ret < 0) { /* Negative value is an error */ goto out; } @@ -7752,20 +7764,20 @@ static int call_list_snap_of_volume(dict_t *dict){ int ret = -1; int64_t volcount = -1; - int i = -1; + int64_t i = -1; char vol_name_prefix[PATH_MAX] = ""; - ret = dict_get_int64 (dict, "snaplist.vol_count", &volcount); + ret = dict_get_int64 (dict, "snaplist.vol-count", &volcount); if (ret) { gf_log ("", GF_LOG_ERROR, "Could not fetch volcount"); goto out; } for (i = 0 ; i < volcount ; i++) { /* list the snap of each volume - * vol_name_prefix = "snaplist.vol{0..}" + * vol_name_prefix = "snaplist.vol-{0..}" */ ret = snprintf (vol_name_prefix, sizeof(vol_name_prefix), - "snaplist.vol%d", i); + "snaplist.vol%ld", i); if (ret < 0) { /* Negative value is an error */ goto out; } @@ -7875,7 +7887,7 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov, /* get the vol_count * if vol_count = 0, then there must be presence of CG */ - ret = dict_get_int64 (dict, "snaplist.vol_count", &volcount); + ret = dict_get_int64 (dict, "snaplist.vol-count", &volcount); if (ret){ gf_log("", GF_LOG_ERROR, "Could not fetch volcount"); ret = -1; -- cgit