summaryrefslogtreecommitdiffstats
path: root/cli/src
diff options
context:
space:
mode:
Diffstat (limited to 'cli/src')
-rw-r--r--cli/src/cli-cmd-parser.c42
1 files changed, 28 insertions, 14 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index 4357e65..15675c8 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -2851,13 +2851,6 @@ cli_snap_create_parse (dict_t *dict, const char **words, int wordcount,
goto out;
}
- /* Snap name cannot be keyword "description" or "force" */
- if (strcmp (words[cmdi], "description") == 0 ||
- strcmp (words[cmdi], "force") == 0) {
- gf_log ("cli", GF_LOG_ERROR, "snapname cannot be keyword");
- goto out;
- }
-
ret = dict_set_str (dict, "snapname", (char *)words[cmdi]);
if (ret) {
gf_log ("cli", GF_LOG_ERROR, "Could not save snap "
@@ -3378,6 +3371,24 @@ out :
return ret;
}
+int
+validate_snapname (const char *snapname, char **opwords) {
+ int ret = -1;
+ int i = 0;
+
+ GF_ASSERT (snapname);
+ GF_ASSERT (opwords);
+
+ for (i = 0 ; opwords[i] != NULL; i++) {
+ if (strcmp (opwords[i], snapname) == 0) {
+ cli_out ("\"%s\" cannot be a snapname", snapname);
+ goto out;
+ }
+ }
+ ret = 0;
+out :
+ return ret;
+}
int32_t
cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options,
@@ -3388,9 +3399,11 @@ 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;
- char *opwords[] = {"create", "delete", "restore",
- "start", "stop", "list", "status",
- "config", "info", NULL};
+ char *opwords[] = {"create", "delete", "restore", "start",
+ "stop", "list", "status", "config",
+ "info", NULL};
+ char *invalid_snapnames[] = {"description", "force",
+ "volume", NULL};
GF_ASSERT (words);
GF_ASSERT (options);
@@ -3452,12 +3465,13 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options,
*/
/* In cases where the snapname is not given then
- * parsing fails & snapname cannot be an opword,
- * that check is made here
+ * parsing fails & snapname cannot be "description",
+ * "force" and "volume", that check is made here
*/
- w = str_getunamb (words[2], opwords);
- if (w)
+ ret = validate_snapname (words[2], invalid_snapnames);
+ if (ret) {
goto out;
+ }
ret = cli_snap_create_parse (dict, words,
wordcount, cmdi);