diff options
Diffstat (limited to 'cli/src/cli-cmd-parser.c')
-rw-r--r-- | cli/src/cli-cmd-parser.c | 110 |
1 files changed, 104 insertions, 6 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 2ad5d430c..c5d6fa009 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -3290,6 +3290,85 @@ out : return ret; } +/* snapshot status [(snapname | volume <volname>)] + * @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) { + + int ret = -1; + int32_t cmd = GF_SNAP_STATUS_TYPE_ALL; + + GF_ASSERT (words); + GF_ASSERT (dict); + + if (wordcount > 4 || wordcount < cmdi) { + gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } + + if (wordcount == cmdi) { + ret = 0; + goto out; + } + + /* if 3rd word is not "volume", then it must be "snapname" + */ + if (strcmp (words[cmdi], "volume") != 0) { + ret = dict_set_str (dict, "snapname", + (char *)words[cmdi]); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Count not save " + "snap name %s", words[cmdi]); + goto out; + } + + if ((cmdi + 1) != wordcount) { + ret = -1; + gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); + goto out; + } + + ret = 0; + cmd = GF_SNAP_STATUS_TYPE_SNAP; + goto out; + } + + /* 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_str (dict, "volname", (char *)words [wordcount - 1]); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Count not save " + "volume name %s", words[wordcount - 1]); + goto out; + } + cmd = GF_SNAP_STATUS_TYPE_VOL; + +out : + if (ret == 0) { + ret = dict_set_int32 (dict, "cmd", cmd); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Could not save cmd " + "of snapshot status"); + } + } + return ret; +} + int32_t cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, @@ -3326,18 +3405,21 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, goto out; } - if (!strcmp (w, "create")) + if (!strcmp (w, "create")) { type = GF_SNAP_OPTION_TYPE_CREATE; - if (!strcmp (w, "list")) + } else if (!strcmp (w, "list")) { type = GF_SNAP_OPTION_TYPE_LIST; - if (!strcmp (w, "info")) + } else if (!strcmp (w, "info")) { type = GF_SNAP_OPTION_TYPE_INFO; - if (!strcmp (w, "delete")) + } else if (!strcmp (w, "delete")) { type = GF_SNAP_OPTION_TYPE_DELETE; - if (!strcmp (w, "config")) + } else if (!strcmp (w, "config")) { type = GF_SNAP_OPTION_TYPE_CONFIG; - if (!strcmp (w, "restore")) + } else if (!strcmp (w, "restore")) { type = GF_SNAP_OPTION_TYPE_RESTORE; + } else if (!strcmp (w, "status")) { + type = GF_SNAP_OPTION_TYPE_STATUS; + } if (type != GF_SNAP_OPTION_TYPE_CONFIG) { ret = dict_set_int32 (dict, "hold_snap_locks", _gf_true); @@ -3437,6 +3519,22 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, } break; } + case GF_SNAP_OPTION_TYPE_STATUS: + { + /* Syntax : + * gluster snapshot status [(snapname | + * volume <volname>)] + */ + ret = cli_snap_status_parse (dict, words, wordcount, + cmdi); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Failed to parse " + "snapshot status command"); + goto out; + } + break; + } + case GF_SNAP_OPTION_TYPE_RESTORE: { /* Syntax: |