summaryrefslogtreecommitdiffstats
path: root/cli/src/cli-cmd-parser.c
diff options
context:
space:
mode:
authorAvra Sengupta <asengupt@redhat.com>2013-12-16 03:09:58 +0000
committerRajesh Joseph <rjoseph@redhat.com>2014-01-06 15:59:43 +0530
commit5d57885a1b63ba89406c0dbd02bb254eacf531bd (patch)
tree81675d15f4d450ac80c2b67cf1e4b2e68a5405b2 /cli/src/cli-cmd-parser.c
parent31ed53e48a2066ba344c257856384ad105803281 (diff)
glusterd/snapshot: Introducing snap-max-hard-limit and snap-max-soft-limit
Note: Manually adding this patch again as this patch got missed in git reset option done on remote development branch Change-Id: I9e81c5ec003c1e1722d0fcb27dd87c365ee43ff4 Signed-off-by: Avra Sengupta <asengupt@redhat.com> Signed-off-by: Rajesh Joseph <rjoseph@redhat.com>
Diffstat (limited to 'cli/src/cli-cmd-parser.c')
-rw-r--r--cli/src/cli-cmd-parser.c137
1 files changed, 92 insertions, 45 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index d1afa72a4..2762f0cf4 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -28,6 +28,23 @@
#define MAX_SNAP_DESCRIPTION_LEN 1024
+struct snap_config_opt_vals_ snap_confopt_vals[] = {
+ {.op_name = "snap-max-hard-limit",
+ .question = "Changing snapshot-max-hard-limit "
+ "will lead deletion of snapshots "
+ "if they exceed the new limit.\n"
+ "Do you want to continue?"
+ },
+ {.op_name = "snap-max-soft-limit",
+ .question = "Changing snapshot-max-soft-limit "
+ "will lead deletion of snapshots "
+ "if they exceed the new limit.\n"
+ "Do you want to continue?"
+ },
+ {.op_name = NULL,
+ }
+};
+
static const char *
id_sel (void *wcon)
{
@@ -3171,24 +3188,22 @@ int32_t
cli_snap_config_parse (const char **words, int wordcount, dict_t *options,
struct cli_state *state)
{
- char *volname = NULL;
- int ret = -1;
- char *key = NULL;
- char *value = NULL;
- uint64_t limit = 0;
- gf1_cli_snapshot type = GF_SNAP_OPTION_TYPE_NONE;
- gf_answer_t answer = GF_ANSWER_NO;
- const char *question = "Changing snapshot-max-limit"
- " will lead deletion of snap"
- "shots if they exceed the "
- "new limit.\nDo you want to"
- " continue?";
+ char *volname = NULL;
+ int ret = -1;
+ int i = -1;
+ char *key = NULL;
+ char *value = NULL;
+ uint64_t limit = 0;
+ gf1_cli_snapshot type = GF_SNAP_OPTION_TYPE_NONE;
+ gf_answer_t answer = GF_ANSWER_NO;
+ struct snap_config_opt_vals_ *conf_vals = NULL;
+ gf_boolean_t op_match = _gf_true;
GF_ASSERT (words);
GF_ASSERT (options);
GF_ASSERT (state);
- if ((wordcount != 3) && (wordcount != 5))
+ if ((wordcount < 3) || (wordcount > 5))
goto out;
volname = (char *)words[2];
@@ -3210,47 +3225,79 @@ cli_snap_config_parse (const char **words, int wordcount, dict_t *options,
goto out;
}
- /* snapshot config <volname | all> [snap_max_limit <count>] */
+ /* snapshot config <volname | all> [snap-max-hard-limit <count>
+ * | snap-max-soft-limit <count>] */
- if (wordcount == 3) {
- ret = dict_set_int32 (options, "config-command",
- GF_SNAP_CONFIG_DISPLAY);
- goto out;
+ if (wordcount > 3) {
+ key = (char *) words[3];
+ value = (char *) words[4];
}
- key = (char *) words[3];
- value = (char *) words[4];
- if ( !key || !value) {
- ret = -1;
- goto out;
- }
- if (strncmp (key, "snap-max-limit", 14)) {
- gf_log ("", GF_LOG_ERROR, "Invalid key");
- goto out;
+ if (key) {
+ /* Check options in snap_confopt_vals for invalid keys */
+ for (conf_vals = snap_confopt_vals; conf_vals->op_name;
+ conf_vals++) {
+ op_match = _gf_true;
+ for (i = 0; conf_vals->op_name[i] && key[i]; i++) {
+ if (conf_vals->op_name[i] == key[i] ||
+ (conf_vals->op_name[i] == '-' &&
+ key[i] == '_'))
+ continue;
+ op_match = _gf_false;
+ break;
+ }
+
+ if (op_match)
+ break;
+ }
+
+ if (!op_match) {
+ gf_log ("", GF_LOG_ERROR, "Invalid key");
+ ret = -1;
+ goto out;
+ }
+
+ ret = dict_set_str (options, "config-key", conf_vals->op_name);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to set config-key");
+ goto out;
+ }
}
- if (!strncmp (volname, "all", 3)) {
+
+ if (!value) {
ret = dict_set_int32 (options, "config-command",
- GF_SNAP_CONFIG_SYS_MAX);
+ GF_SNAP_CONFIG_DISPLAY);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to set config-command");
+ ret = -1;
+ goto out;
+ }
} else {
ret = dict_set_int32 (options, "config-command",
- GF_SNAP_CONFIG_VOL_MAX);
- }
+ GF_SNAP_CONFIG_TYPE_SET);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to set config-command");
+ ret = -1;
+ goto out;
+ }
- limit = (uint64_t) atoll (value);
- ret = dict_set_uint64 (options, "limit", limit);
- if (ret) {
- gf_log ("", GF_LOG_ERROR,
- "Failed to set limit.");
- goto out;
+ limit = (uint64_t) atoll (value);
+ ret = dict_set_uint64 (options, conf_vals->op_name, limit);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR,
+ "Failed to set %s.", key);
+ goto out;
+ }
}
- if (ret)
- goto out;
- answer = cli_cmd_get_confirmation (state, question);
-
- if (GF_ANSWER_NO == answer) {
- ret = -1;
- goto out;
+ /* Ask question only for a set op */
+ if (value && conf_vals && conf_vals->question) {
+ answer = cli_cmd_get_confirmation (state,
+ conf_vals->question);
+ if (GF_ANSWER_NO == answer) {
+ ret = -1;
+ goto out;
+ }
}
out:
return ret;
@@ -3572,7 +3619,7 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options,
}
case GF_SNAP_OPTION_TYPE_CONFIG:
{
- /* snapshot config <volname | all> [snap_max_limit <count>] */
+ /* snapshot config <volname | all> [snap-max-hard-limit <count> | snap-max-soft-limit <count>] */
ret = cli_snap_config_parse (words, wordcount, dict,
state);
if (ret) {