diff options
Diffstat (limited to 'cli/src/cli-cmd-parser.c')
-rw-r--r-- | cli/src/cli-cmd-parser.c | 99 |
1 files changed, 46 insertions, 53 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 6232f6301..5ab208b8f 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -195,7 +195,8 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options char *invalid_volnames[] = {"volume", "type", "subvolumes", "option", "end-volume", "all", "volume_not_in_ring", - "description", "force", "snap-max-hard-limit", + "description", "force", + "snap-max-hard-limit", "snap-max-soft-limit", NULL}; char *w = NULL; int op_count = 0; @@ -2811,15 +2812,15 @@ out: /* Function to check whether the Volume name is repeated */ int -check_if_volname_repeated (const char **words, unsigned int start_index, - uint64_t end_index) { +cli_check_if_volname_repeated (const char **words, unsigned int start_index, + uint64_t cur_index) { uint64_t i = -1; int ret = 0; GF_ASSERT (words); - for (i = start_index ; i < end_index ; i++) { - if (strcmp (words[i], words[end_index]) == 0) { + for (i = start_index ; i < cur_index ; i++) { + if (strcmp (words[i], words[cur_index]) == 0) { ret = -1; goto out; } @@ -2828,26 +2829,24 @@ out : return ret; } - - /* snapshot create <snapname> <vol-name(s)> [description <description>] * [force] * @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 create) * * return value : -1 on failure * 0 on success */ int -cli_snap_create_parse (dict_t *dict, const char **words, int wordcount, - unsigned int cmdi) { +cli_snap_create_parse (dict_t *dict, const char **words, int wordcount) { uint64_t i = 0; int ret = -1; uint64_t volcount = 0; char key[PATH_MAX] = ""; char *snapname = NULL; + unsigned int cmdi = 2; + /* cmdi is command index, here cmdi is "2" (gluster snapshot create)*/ GF_ASSERT (words); GF_ASSERT (dict); @@ -2873,7 +2872,8 @@ cli_snap_create_parse (dict_t *dict, const char **words, int wordcount, if (!isalnum (snapname[i]) && (snapname[i] != '_' && (snapname[i] != '-'))) { /* TODO : Is this message enough?? */ - cli_err ("Please provide a valid snapname"); + cli_err ("Snapname can contain only alphanumeric, " + "\"-\" and \"_\" characters"); goto out; } } @@ -2991,20 +2991,18 @@ out : * @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 list) * * 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; +cli_snap_list_parse (dict_t *dict, const char **words, int wordcount) { + int ret = -1; GF_ASSERT (words); GF_ASSERT (dict); - if (wordcount < cmdi || wordcount > 3) { + if (wordcount < 2 || wordcount > 3) { gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); goto out; } @@ -3014,7 +3012,7 @@ cli_snap_list_parse (dict_t *dict, const char **words, int wordcount, goto out; } - ret = dict_set_str (dict, "volname", (char *)words[cmdi]); + ret = dict_set_str (dict, "volname", (char *)words[2]); if (ret) { gf_log ("cli", GF_LOG_ERROR, "Failed to save volname in dictionary"); @@ -3028,17 +3026,18 @@ out : * @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_info_parse (dict_t *dict, const char **words, int wordcount, - unsigned int cmdi) { +cli_snap_info_parse (dict_t *dict, const char **words, int wordcount) +{ - int ret = -1; - int32_t cmd = GF_SNAP_INFO_TYPE_ALL; + int ret = -1; + int32_t cmd = GF_SNAP_INFO_TYPE_ALL; + unsigned int cmdi = 2; + /* cmdi is command index, here cmdi is "2" (gluster snapshot info)*/ GF_ASSERT (words); GF_ASSERT (dict); @@ -3117,14 +3116,13 @@ out : * @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 restore) * * return value : -1 on failure * 0 on success */ int -cli_snap_restore_parse (dict_t *dict, const char **words, int wordcount, - unsigned int cmdi) { +cli_snap_restore_parse (dict_t *dict, const char **words, int wordcount) +{ int ret = -1; @@ -3136,10 +3134,10 @@ cli_snap_restore_parse (dict_t *dict, const char **words, int wordcount, goto out; } - ret = dict_set_str (dict, "snapname", (char *)words[cmdi]); + ret = dict_set_str (dict, "snapname", (char *)words[2]); if (ret) { gf_log ("cli", GF_LOG_ERROR, "Unable to save snap-name %s", - words[cmdi]); + words[2]); goto out; } out : @@ -3150,7 +3148,6 @@ out : * @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 delete) * * return value : -1 on failure * 0 on success @@ -3158,7 +3155,7 @@ out : */ int cli_snap_delete_parse (dict_t *dict, const char **words, int wordcount, - unsigned int cmdi, struct cli_state *state) { + struct cli_state *state) { int ret = -1; const char *question = NULL; @@ -3175,10 +3172,10 @@ cli_snap_delete_parse (dict_t *dict, const char **words, int wordcount, goto out; } - ret = dict_set_str (dict, "snapname", (char *)words[cmdi]); + ret = dict_set_str (dict, "snapname", (char *)words[2]); if (ret) { gf_log ("cli", GF_LOG_ERROR, "Unable to save snapname %s", - words[cmdi]); + words[2]); goto out; } @@ -3197,17 +3194,18 @@ out : * @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 status) * * return value : -1 on failure * 0 on success */ int -cli_snap_status_parse (dict_t *dict, const char **words, int wordcount, - unsigned int cmdi) { +cli_snap_status_parse (dict_t *dict, const char **words, int wordcount) +{ - int ret = -1; - int32_t cmd = GF_SNAP_STATUS_TYPE_ALL; + int ret = -1; + int32_t cmd = GF_SNAP_STATUS_TYPE_ALL; + unsigned int cmdi = 2; + /* cmdi is command index, here cmdi is "2" (gluster snapshot status)*/ GF_ASSERT (words); GF_ASSERT (dict); @@ -3323,7 +3321,7 @@ out : */ int32_t cli_snap_config_parse (const char **words, int wordcount, dict_t *dict, - unsigned int cmdi, struct cli_state *state) + struct cli_state *state) { int ret = -1; gf_answer_t answer = GF_ANSWER_NO; @@ -3333,6 +3331,8 @@ cli_snap_config_parse (const char **words, int wordcount, dict_t *dict, int8_t soft_limit = 0; int8_t config_type = -1; const char *question = NULL; + unsigned int cmdi = 2; + /* cmdi is command index, here cmdi is "2" (gluster snapshot config)*/ GF_ASSERT (words); GF_ASSERT (dict); @@ -3473,7 +3473,6 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, int32_t ret = -1; dict_t *dict = NULL; gf1_cli_snapshot type = GF_SNAP_OPTION_TYPE_NONE; - unsigned int cmdi = 0; char *w = NULL; char *opwords[] = {"create", "delete", "restore", "start", "stop", "list", "status", "config", @@ -3523,13 +3522,12 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, ret = dict_set_int32 (dict, "hold_snap_locks", _gf_true); if (ret) { gf_log ("cli", GF_LOG_ERROR, - "Unable to set hold-snap-locks value as _gf_true"); + "Unable to set hold-snap-locks value " + "as _gf_true"); goto out; } } - cmdi = 2; - /* Check which op is intended */ switch (type) { case GF_SNAP_OPTION_TYPE_CREATE: @@ -3556,8 +3554,7 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, goto out; } - ret = cli_snap_create_parse (dict, words, - wordcount, cmdi); + ret = cli_snap_create_parse (dict, words, wordcount); if (ret) { gf_log ("cli", GF_LOG_ERROR, "create command parsing failed."); @@ -3570,8 +3567,7 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, /* Syntax : * gluster snapshot info [(snapname] | [vol <volname>)] */ - ret = cli_snap_info_parse (dict, words, wordcount, - cmdi); + ret = cli_snap_info_parse (dict, words, wordcount); if (ret) { gf_log ("cli", GF_LOG_ERROR, "Failed to parse " "snapshot info command"); @@ -3586,8 +3582,7 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, * gluster snaphsot list [volname] */ - ret = cli_snap_list_parse (dict, words, wordcount, - cmdi); + ret = cli_snap_list_parse (dict, words, wordcount); if (ret) { gf_log ("cli", GF_LOG_ERROR, "Failed to parse " "snapshot list command"); @@ -3602,7 +3597,7 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, * gluster snapshot delete <snapname> */ ret = cli_snap_delete_parse (dict, words, wordcount, - cmdi, state); + state); if (ret) { gf_log ("cli", GF_LOG_ERROR, "Failed to parse " "snapshot delete command"); @@ -3616,7 +3611,7 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, /* snapshot config [volname] [snap-max-hard-limit <count>] * [snap-max-soft-limit <percent>] */ ret = cli_snap_config_parse (words, wordcount, dict, - cmdi, state); + state); if (ret) { if (ret < 0) gf_log ("cli", GF_LOG_ERROR, @@ -3640,8 +3635,7 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, * gluster snapshot status [(snapname | * volume <volname>)] */ - ret = cli_snap_status_parse (dict, words, wordcount, - cmdi); + ret = cli_snap_status_parse (dict, words, wordcount); if (ret) { gf_log ("cli", GF_LOG_ERROR, "Failed to parse " "snapshot status command"); @@ -3655,8 +3649,7 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, /* Syntax: * snapshot restore <snapname> */ - ret = cli_snap_restore_parse (dict, words, wordcount, - cmdi); + ret = cli_snap_restore_parse (dict, words, wordcount); if (ret) { gf_log ("cli", GF_LOG_ERROR, "Failed to parse " "restore command"); |