From cffe1de37453f81992047408e4c4ce5e35e21434 Mon Sep 17 00:00:00 2001 From: Sachin Pandit Date: Thu, 13 Feb 2014 03:41:28 +0530 Subject: CLI/snapshot : Snapshot info CLI changes snapshot info [(snapname | volume )]. Snapshot info will list all the basic information. Syntax : ** gluster snapshot info ** This will list all the snap object along with that it also prints the snaps volume name, UUID and status. ** gluster snapshot info ** This will list only the mentioned snap object and also snap volume information along with that ** gluster snapshot info volume ** This will list all the snaps present in the mentioned volume. Change-Id: I1e92774cb08eaebbfe141b9b47d1a887d76916a4 Signed-off-by: Sachin Pandit Reviewed-on: http://review.gluster.org/6996 Reviewed-by: Rajesh Joseph Tested-by: Rajesh Joseph --- cli/src/cli-cmd-parser.c | 252 ++++++++++++++--------------------------------- 1 file changed, 75 insertions(+), 177 deletions(-) (limited to 'cli/src/cli-cmd-parser.c') diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 62c383c44..2505bbc7f 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -2956,170 +2956,80 @@ cli_snap_create_parse (dict_t *dict, const char **words, int wordcount, 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" +/* snapshot info [(snapname | volume )] + * @arg-0, dict : Request Dictionary to be sent to server side. + * @arg-1, words : Contains individual words of CLI command. + * @arg-2, wordcount: Contains number of words present in the CLI command. + * @arg-3, cmdi : command index, here cmdi is "2" (gluster snapshot info) + * + * return value : -1 on failure + * 0 on success */ int -cli_snap_list_parse (dict_t *dict, const char **words, int wordcount, - unsigned int cmdi) -{ - 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] = ""; +cli_snap_info_parse (dict_t *dict, const char **words, int wordcount, + unsigned int cmdi) { + + int ret = -1; - GF_ASSERT (dict); GF_ASSERT (words); - GF_ASSERT (wordcount >= cmdi); - /* if command is "gluster snapshot list*/ + GF_ASSERT (dict); + + if (wordcount > 4 || wordcount < cmdi) { + gf_log ("", GF_LOG_ERROR, "Invalid syntax"); + goto out; + } + if (wordcount == cmdi) { - ret = dict_set_int8 (dict, "snap-details", snap_details); + ret = 0; + goto out; + } + + /* If 3rd word is not "volume", then it must + * be snap-name. + */ + if (strcmp (words[cmdi], "volume") != 0) { + ret = dict_set_str (dict, "snapname", + (char *)words[cmdi]); if (ret) { - gf_log("", GF_LOG_ERROR, "Failed to set snap-details"); + gf_log ("cli", GF_LOG_ERROR, "Unable to save " + "snap-name %s", words[cmdi]); + goto out; + } + + /* Once snap name is parsed, if we encounter any other + * word then fail it. Invalid Syntax. + * example : snapshot info word + */ + if ((cmdi + 1) != wordcount) { ret = -1; + gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); goto out; } + ret = 0; goto out; + /* No need to continue the parsing once we + * get the snap-name + */ } - for (i = cmdi; i < wordcount; ++i) { - if (strcmp (words[i], "-d") == 0) { - if (snap_details == 1) { - /* If option is already set */ - gf_log("", GF_LOG_ERROR, - "snap_details already set"); - ret = -1; - goto out; - } - snap_details = 1; - } else if (strcmp (words[i], "-s") == 0) { - if ((wordcount - 1) == i || (snap_name != NULL) - || vol_count != 1 || strcmp (words[++i], "-d") == 0 - || strcmp (words[i], "-c") == 0) { - /* if -s is not followed by a valid snap_name - * or if snap_name is already parsed - * or number of volname specified - * is not equal to 1 - */ - gf_log("", GF_LOG_ERROR, "Invalid snap_name" - " or snap_name already parsed" - " or number of volumes greater than 1"); - ret = -1; - goto out; - } - /* 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 - || strcmp (words[i], "-s") == 0) { - /* if -c is not followed by a valid cg_name - * or if cg_name is already parsed - */ - gf_log("", GF_LOG_ERROR, "Invalid cg_name" - " or cg_name already parsed"); - ret = -1; - goto out; - } - 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; - } - - vol_start_index = i; - vol_count = 1; - - while (++i < wordcount) { - if ((strcmp (words[i], "-d") == 0) || - (strcmp (words[i], "-s") == 0) || - (strcmp (words[i], "-c") == 0)) { - /*if option -d, -s or -c is given after volname - *then go back in index to parse this option - *again - */ - --i; - break; - } - ++vol_count; - } - } + /* If 3rd word is "volume", then check if next word + * is present. As, "snapshot info volume" is an + * invalid command. + */ + if ((cmdi + 1) == wordcount) { + ret = -1; + gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; } - ret = dict_set_int8 (dict, "snap-details", snap_details); + ret = dict_set_str (dict, "volname", (char *)words[wordcount - 1]); if (ret) { - gf_log("", GF_LOG_ERROR, "Failed to set snap-details"); + gf_log ("", GF_LOG_ERROR, "Count not save " + "volume name %s", words[wordcount - 1]); 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) { - /* When -s option or volume name is given along - * with -c option. Details of single snap belonging - * to a CG is not supported. - */ - 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, "cgname", (char *)cg_name); - if (ret) { - gf_log("", GF_LOG_ERROR, - "Failed to set CG name %s", cg_name); - goto out; - } - } else { - /* if snap name is present in the command - * then fill it to dictionary - */ - if (snap_name != NULL) { - ret = dict_set_str (dict, "snapname", - (char *)snap_name); - if (ret) { - gf_log ("", GF_LOG_ERROR, - "Failed to set snap name %s", - snap_name); - ret = -1; - goto out; - } - } - - /* fill volume name in dictionary */ - for (i = 0; i < vol_count; ++i) { - vol_name = (char*) words[vol_start_index + i]; - /* check if volume name is repeated */ - 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 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: +out : return ret; } @@ -3471,10 +3381,9 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, gf1_cli_snapshot type = GF_SNAP_OPTION_TYPE_NONE; unsigned int cmdi = 0; char *w = NULL; - int i = 0; char *opwords[] = {"create", "delete", "restore", "start", "stop", "list", "status", - "config", NULL}; + "config", "info", NULL}; GF_ASSERT (words); GF_ASSERT (options); @@ -3502,6 +3411,8 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, type = GF_SNAP_OPTION_TYPE_CREATE; if (!strcmp (w, "list")) type = GF_SNAP_OPTION_TYPE_LIST; + if (!strcmp (w, "info")) + type = GF_SNAP_OPTION_TYPE_INFO; if (!strcmp (w, "delete")) type = GF_SNAP_OPTION_TYPE_DELETE; if (!strcmp (w, "config")) @@ -3509,6 +3420,8 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, if (!strcmp (w, "restore")) type = GF_SNAP_OPTION_TYPE_RESTORE; + cmdi = 2; + /* Check which op is intended */ switch (type) { case GF_SNAP_OPTION_TYPE_CREATE: @@ -3526,7 +3439,6 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, w = str_getunamb (words[2], opwords); if (w) goto out; - cmdi = 2; ret = cli_snap_create_parse (dict, words, wordcount, cmdi); @@ -3537,35 +3449,21 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, } break; } - case GF_SNAP_OPTION_TYPE_LIST: - { - /* snapshot list [ | [-s ] - * | -c ] [-d] */ - /* check if arguments contains any Keyword */ - cmdi = 2; - for (i = cmdi ; i < wordcount ; i++) { - w = str_getunamb (words[i], opwords); - if (w) { - /*Checks if the operation is a valid - operation*/ - cli_out ("Usage of Keyword in wrong " - "place"); - gf_log ("", GF_LOG_ERROR, "Opword " - "Mismatch"); - goto out; - } - } - - ret = cli_snap_list_parse (dict, words, - wordcount, cmdi); + case GF_SNAP_OPTION_TYPE_INFO: + { + /* Syntax : + * gluster snapshot info ([snap-name] | [vol ]) + */ + ret = cli_snap_info_parse (dict, words, wordcount, + cmdi); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to parse " + "snapshot list command"); + goto out; + } + break; + } - if (ret) { - gf_log ("", GF_LOG_ERROR, - "list command parsing failed."); - goto out; - } - break; - } case GF_SNAP_OPTION_TYPE_DELETE: { /*syntax: -- cgit