diff options
Diffstat (limited to 'cli/src/cli-cmd-parser.c')
-rw-r--r-- | cli/src/cli-cmd-parser.c | 96 |
1 files changed, 76 insertions, 20 deletions
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 [<volnames> | <volname> -s <snapname> | -c <cgname>] [-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: |