summaryrefslogtreecommitdiffstats
path: root/cli
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
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')
-rw-r--r--cli/src/cli-cmd-parser.c137
-rw-r--r--cli/src/cli-cmd-snapshot.c2
-rw-r--r--cli/src/cli-rpc-ops.c147
-rw-r--r--cli/src/cli.h5
4 files changed, 201 insertions, 90 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index d1afa72..2762f0c 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) {
diff --git a/cli/src/cli-cmd-snapshot.c b/cli/src/cli-cmd-snapshot.c
index 6aac4d2..5562789 100644
--- a/cli/src/cli-cmd-snapshot.c
+++ b/cli/src/cli-cmd-snapshot.c
@@ -90,7 +90,7 @@ struct cli_cmd snapshot_cmds[] = {
cli_cmd_snapshot_cbk,
"Snapshot List."
},
- {"snapshot config < volname | all > [ snap-max-limit <count> ]",
+ {"snapshot config < volname | all > [ snap-max-hard-limit <count> | snap-max-soft-limit <count> ]",
cli_cmd_snapshot_cbk,
"Snapshot Config."
},
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index 31fd616..926c01b 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -7896,6 +7896,106 @@ out:
}
int
+cli_snapshot_config_display (dict_t *dict, gf_cli_rsp *rsp)
+{
+ char *volname = NULL;
+ char *key = NULL;
+ int ret = -1;
+ int config_command = 0;
+ uint64_t value = 0;
+
+ GF_ASSERT (dict);
+ GF_ASSERT (rsp);
+
+ if (rsp->op_ret) {
+ cli_err ("Snapshot Config : failed: %s",
+ rsp->op_errstr ? rsp->op_errstr :
+ "Please check log file for details");
+ ret = rsp->op_ret;
+ goto out;
+ }
+
+ ret = dict_get_int32 (dict, "config-command", &config_command);
+ if (ret) {
+ gf_log("", GF_LOG_DEBUG, "Could not fetch config type");
+ ret = -1;
+ goto out;
+ }
+
+ ret = dict_get_str (dict, "volname", &volname);
+ if (ret) {
+ gf_log("", GF_LOG_ERROR, "Could not fetch "
+ "volname");
+ ret = -1;
+ goto out;
+ }
+
+ if (!strcmp (volname, "all")) {
+ volname = "System";
+ }
+
+ ret = dict_get_str (dict, "config-key", &key);
+ if (ret)
+ gf_log("", GF_LOG_ERROR, "No config-key set");
+
+ switch (config_command) {
+ case GF_SNAP_CONFIG_TYPE_SET:
+ cli_out ("snapshot config: %s "
+ "for %s set successfully", key, volname);
+ break;
+
+ case GF_SNAP_CONFIG_DISPLAY :
+ if (!key) {
+ /* For all options */
+ ret = dict_get_uint64 (dict, "snap-max-hard-limit",
+ &value);
+ if (ret) {
+ gf_log("", GF_LOG_DEBUG, "Could not fetch "
+ "snap_max_hard_limit for %s", volname);
+ ret = -1;
+ goto out;
+ }
+ cli_out ("snapshot config: snap-max-hard-limit for "
+ "%s set to %"PRIu64,
+ volname, value);
+
+ ret = dict_get_uint64 (dict, "snap-max-soft-limit",
+ &value);
+ if (ret) {
+ gf_log("", GF_LOG_DEBUG, "Could not fetch "
+ "snap-max-soft-limit for %s", volname);
+ ret = -1;
+ goto out;
+ }
+ cli_out ("snapshot config: snap-max-soft-limit for "
+ "%s set to %"PRIu64,
+ volname, value);
+ } else {
+ if ((!strncmp (key, "snap-max-hard-limit", strlen(key))) ||
+ (!strncmp (key, "snap-max-soft-limit", strlen(key)))) {
+ ret = dict_get_uint64 (dict, key, &value);
+ if (ret) {
+ gf_log("", GF_LOG_DEBUG, "Could not fetch "
+ "%s for %s", key, volname);
+ ret = -1;
+ goto out;
+ }
+ cli_out ("snapshot config: %s for "
+ "%s set to %"PRIu64, key,
+ volname, value);
+ }
+ }
+ break;
+ default :
+ break;
+ }
+
+ ret = 0;
+out:
+ return ret;
+}
+
+int
gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov,
int count, void *myframe)
{
@@ -7907,9 +8007,6 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov,
int32_t type = 0;
int64_t volcount = -1;
call_frame_t *frame = NULL;
- uint64_t limit = 0;
- int32_t config_command = 0;
- char *volname = NULL;
if (req->rpc_status == -1) {
ret = -1;
@@ -8056,50 +8153,12 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov,
break;
case GF_SNAP_OPTION_TYPE_CONFIG:
- if (rsp.op_ret) {
- cli_err ("Snapshot Config : failed: %s",
- rsp.op_errstr ? rsp.op_errstr :
- "Please check log file for details");
- ret = rsp.op_ret;
- goto out;
- }
-
- ret = dict_get_int32 (dict, "config-command", &config_command);
-
+ ret = cli_snapshot_config_display (dict, &rsp);
if (ret) {
- gf_log("", GF_LOG_DEBUG, "Could not fetch config type");
- ret = -1;
- goto out;
- }
-
- ret = dict_get_str (dict, "volname", &volname);
- if (ret) {
- gf_log("", GF_LOG_DEBUG, "Could not fetch "
- "volname");
- ret = -1;
+ gf_log ("", GF_LOG_ERROR, "Failed to display snapshot "
+ "config output.");
goto out;
}
-
- if (!strcmp (volname, "all")) {
- volname = "System";
- }
-
- if (config_command == GF_SNAP_CONFIG_DISPLAY) {
-
- ret = dict_get_uint64 (dict, "limit", &limit);
- if (ret) {
- gf_log("", GF_LOG_DEBUG, "Could not fetch "
- "limit for %s", volname);
- ret = -1;
- goto out;
- }
- cli_out ("snapshot config: snap-max-limit for "
- "%s set to %"PRIu64,
- volname, limit);
- } else {
- cli_out ("snapshot config: snap-max-limit "
- "for %s set successfully", volname);
- }
break;
case GF_SNAP_OPTION_TYPE_DELETE:
diff --git a/cli/src/cli.h b/cli/src/cli.h
index 3d987a8..8daa4b7 100644
--- a/cli/src/cli.h
+++ b/cli/src/cli.h
@@ -166,6 +166,11 @@ struct cli_volume_status {
#endif
};
+struct snap_config_opt_vals_ {
+ char *op_name;
+ char *question;
+};
+
typedef struct gf_cli_gsync_detailed_status_ gf_cli_gsync_status_t;
typedef struct cli_volume_status cli_volume_status_t;