summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
authorSachin Pandit <spandit@redhat.com>2014-06-11 09:03:16 +0530
committerVijay Bellur <vbellur@redhat.com>2014-06-13 02:12:29 -0700
commit10cd2bc38e1f0a1297d59c0791a85ed9d01c93ff (patch)
treee7230795e97b668c04011fa018597aae0619ef10 /cli
parent6ba178fd9ebf9fc98415c30bcd338a68ee5eb601 (diff)
glusterd/snapshot : Provide enable/disable option for snapshot auto-delete feature.
This patch provides an interface to enable or disable the auto-delete feature. Syntax : gluster snapshot config auto-delete <enable/disable> DETAILS : 1) When auto-delete feature is disabled, If the the soft-limit is reached then user is given a warning about exceeding soft-limit along with successful snapshot creation message (oldest snapshot is not deleted). And upon reaching hard-limit further snapshot creation is not allowed. Example : ------------------------------------------------------------------ |Case - 1: Upon reaching soft-limit | |Snapshot create : snap successfully created. |Warning : soft-limit of volume (vol) is reached. Snapshot creation |is not possible once hard-limit is reached. | |----------------------------------------------------- |Case - 2: Upon reaching hard-limit | |Snapshot create : snap creation failed. |Error : hard-limit of volume (vol) is reached, Hence it is not |possible to take further snapshots. Please delete few snapshots |of the volume (vol) before taking another snapshot. ------------------------------------------------------------------ 2) When auto-delete feature is enabled, then as soon as the soft-limit is reached the oldest snapshot is deleted for every successful snapshot creation (same as existing method), With this it is made sure that number of snapshot created is not more than snap-max-hard-limit. Change-Id: Ie3ca64bbd2c763371f541cd2e378314e73b695b4 BUG: 1105415 Signed-off-by: Sachin Pandit <spandit@redhat.com> Reviewed-on: http://review.gluster.org/8017 Tested-by: Justin Clift <justin@gluster.org> Reviewed-by: Rajesh Joseph <rjoseph@redhat.com> Reviewed-by: Krishnan Parthasarathi <kparthas@redhat.com> Tested-by: Krishnan Parthasarathi <kparthas@redhat.com> Reviewed-by: Raghavendra Bhat <raghavendra@redhat.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'cli')
-rw-r--r--cli/src/cli-cmd-parser.c57
-rw-r--r--cli/src/cli-cmd-snapshot.c4
-rw-r--r--cli/src/cli-rpc-ops.c37
3 files changed, 91 insertions, 7 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index 7c6e3176dc6..d855dbf8a0a 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -197,7 +197,8 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options
"end-volume", "all", "volume_not_in_ring",
"description", "force",
"snap-max-hard-limit",
- "snap-max-soft-limit", NULL};
+ "snap-max-soft-limit", "auto-delete",
+ NULL};
char *w = NULL;
int op_count = 0;
int32_t replica_count = 1;
@@ -3612,6 +3613,7 @@ cli_snap_config_parse (const char **words, int wordcount, dict_t *dict,
int8_t config_type = -1;
const char *question = NULL;
unsigned int cmdi = 2;
+ int8_t auto_delete = -1;
/* cmdi is command index, here cmdi is "2" (gluster snapshot config)*/
GF_ASSERT (words);
@@ -3630,9 +3632,11 @@ cli_snap_config_parse (const char **words, int wordcount, dict_t *dict,
goto set;
}
+ /* auto-delete cannot be a volume name */
/* Check whether the 3rd word is volname */
if (strcmp (words[cmdi], "snap-max-hard-limit") != 0
- && strcmp (words[cmdi], "snap-max-soft-limit") != 0) {
+ && strcmp (words[cmdi], "snap-max-soft-limit") != 0
+ && strcmp (words[cmdi], "auto-delete") != 0) {
ret = dict_set_str (dict, "volname", (char *)words[cmdi]);
if (ret) {
gf_log ("cli", GF_LOG_ERROR, "Failed to set volname");
@@ -3690,7 +3694,52 @@ cli_snap_config_parse (const char **words, int wordcount, dict_t *dict,
goto out;
}
soft_limit = 1;
- } else {
+ goto set;
+ }
+
+ if (hard_limit != 1 && (strcmp(words[cmdi], "auto-delete") == 0)) {
+ if (vol_presence == 1) {
+ ret = -1;
+ cli_err ("As of now, auto-delete option cannot be set "
+ "to volumes");
+ gf_log ("cli", GF_LOG_ERROR, "auto-delete option "
+ "cannot be set to volumes");
+ goto out;
+ }
+
+ if (++cmdi >= wordcount) {
+ ret = -1;
+ gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
+ goto out;
+ }
+
+ if ((strcmp (words[cmdi], "enable") == 0) ||
+ (strcmp (words[cmdi], "disable") == 0)) {
+ ret = dict_set_str (dict, "auto-delete",
+ (char *)words[cmdi]);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Failed to set "
+ "value of auto-delete in request "
+ "dictionary");
+ goto out;
+ }
+ auto_delete = 1;
+ } else {
+ ret = -1;
+ cli_err ("Please enter a valid value (enable/disable) "
+ "for auto-delete");
+ gf_log ("cli", GF_LOG_ERROR, "Invalid value for "
+ "auto-delete");
+ goto out;
+ }
+
+ if (++cmdi != wordcount) {
+ ret = -1;
+ gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
+ goto out;
+ }
+ }
+ else {
ret = -1;
gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
goto out;
@@ -3705,7 +3754,7 @@ set:
goto out;
}
- if (config_type == GF_SNAP_CONFIG_TYPE_SET) {
+ if (config_type == GF_SNAP_CONFIG_TYPE_SET && auto_delete != 1) {
conf_vals = snap_confopt_vals;
if (hard_limit && soft_limit) {
question = conf_vals[GF_SNAP_CONFIG_SET_BOTH].question;
diff --git a/cli/src/cli-cmd-snapshot.c b/cli/src/cli-cmd-snapshot.c
index 45fa5673f7a..1fb4e5e634c 100644
--- a/cli/src/cli-cmd-snapshot.c
+++ b/cli/src/cli-cmd-snapshot.c
@@ -102,7 +102,9 @@ struct cli_cmd snapshot_cmds[] = {
cli_cmd_snapshot_cbk,
"Snapshot List."
},
- {"snapshot config [volname] [snap-max-hard-limit <count>] [snap-max-soft-limit <percent>]",
+ {"snapshot config [volname] ([snap-max-hard-limit <count>] "
+ "[snap-max-soft-limit <percent>]) "
+ "| ([auto-delete <enable|disable>])",
cli_cmd_snapshot_cbk,
"Snapshot Config."
},
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index b998fff3f4c..348fbe4e2e5 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -7682,6 +7682,7 @@ cli_snapshot_config_display (dict_t *dict, gf_cli_rsp *rsp)
uint64_t soft_limit = 0;
uint64_t i = 0;
uint64_t voldisplaycount = 0;
+ char *auto_delete = NULL;
GF_ASSERT (dict);
GF_ASSERT (rsp);
@@ -7711,8 +7712,11 @@ cli_snapshot_config_display (dict_t *dict, gf_cli_rsp *rsp)
/* Ignore the error, as the key specified is optional */
ret = dict_get_uint64 (dict, "snap-max-soft-limit", &soft_limit);
+ ret = dict_get_str (dict, "auto-delete", &auto_delete);
+
if (!hard_limit && !soft_limit
- && config_command != GF_SNAP_CONFIG_DISPLAY) {
+ && config_command != GF_SNAP_CONFIG_DISPLAY
+ && !auto_delete) {
ret = -1;
gf_log(THIS->name, GF_LOG_ERROR,
"Could not fetch config-key");
@@ -7733,6 +7737,10 @@ cli_snapshot_config_display (dict_t *dict, gf_cli_rsp *rsp)
cli_out ("snapshot config: %s "
"for snap-max-soft-limit set successfully",
volname);
+ } else if (auto_delete) {
+ cli_out ("snapshot config: %s "
+ "auto-delete successfully %sd",
+ volname, auto_delete);
}
break;
@@ -7756,9 +7764,11 @@ cli_snapshot_config_display (dict_t *dict, gf_cli_rsp *rsp)
ret = -1;
goto out;
}
- cli_out ("snap-max-soft-limit : %"PRIu64"%%\n",
+ cli_out ("snap-max-soft-limit : %"PRIu64"%%",
soft_limit);
+ cli_out ("auto-delete : %s\n", auto_delete);
+
cli_out ("Snapshot Volume Configuration:");
ret = dict_get_uint64 (dict, "voldisplaycount",
@@ -8501,6 +8511,8 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov,
int32_t type = 0;
call_frame_t *frame = NULL;
gf_boolean_t snap_driven = _gf_false;
+ int8_t soft_limit_flag = -1;
+ char *volname = NULL;
if (req->rpc_status == -1) {
ret = -1;
@@ -8550,8 +8562,29 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov,
"Failed to get snap name");
goto out;
}
+
+ /* TODO : Instead of using volname1 directly use
+ * volname$i in loop once snapshot of multiple
+ * volumes are supported
+ */
+ ret = dict_get_str (dict, "volname1", &volname);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR,
+ "Failed to get volume name");
+ goto out;
+ }
+
cli_out ("snapshot create: success: Snap %s created "
"successfully", snap_name);
+
+ ret = dict_get_int8 (dict, "soft-limit-reach",
+ &soft_limit_flag);
+ if (soft_limit_flag == 1) {
+ cli_out ("Warning: Soft-limit of volume (%s) is "
+ "reached. Snapshot creation is not possible "
+ "once hard-limit is reached.", volname);
+ }
+ ret = 0;
break;
case GF_SNAP_OPTION_TYPE_RESTORE: