summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
authorvmallika <vmallika@redhat.com>2014-10-28 12:25:43 +0530
committerRaghavendra Bhat <raghavendra@redhat.com>2014-12-18 22:52:22 -0800
commitdf0ff94a64bd597e61f26a2a56297de7abf80a0f (patch)
tree163dfd82065add6b19ab32a1599dfb389d49911a /cli
parentf0a90bf48135c480c41a71ef25f46619001a3116 (diff)
glusterd/snapshot: Snapshot should be deactivated when it is created.
By default snapshot should be deactivated and this should be a configurable option. This behaviour can be configured by the command below: gluster snapshot config activate-on-create <enable|disable> Change-Id: I1911595c32beed43bb2fca4bf99f0d264b422513 BUG: 1170921 Signed-off-by: vmallika <vmallika@redhat.com> Reviewed-on: http://review.gluster.org/8985 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Avra Sengupta <asengupt@redhat.com> Reviewed-by: Rajesh Joseph <rjoseph@redhat.com> Reviewed-by: Kaushal M <kaushal@redhat.com> Signed-off-by: Sachin Pandit <spandit@redhat.com> Reviewed-on: http://review.gluster.org/9241 Reviewed-by: Raghavendra Bhat <raghavendra@redhat.com>
Diffstat (limited to 'cli')
-rw-r--r--cli/src/cli-cmd-parser.c51
-rw-r--r--cli/src/cli-cmd-snapshot.c3
-rw-r--r--cli/src/cli-rpc-ops.c12
-rw-r--r--cli/src/cli-xml-output.c27
4 files changed, 76 insertions, 17 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index 27f1fec0df8..28888ba656d 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -278,7 +278,7 @@ cli_cmd_volume_create_parse (struct cli_state *state, const char **words,
"description", "force",
"snap-max-hard-limit",
"snap-max-soft-limit", "auto-delete",
- NULL};
+ "activate-on-create", NULL};
char *w = NULL;
char *ptr = NULL;
int op_count = 0;
@@ -3868,8 +3868,7 @@ cli_snap_config_parse (const char **words, int wordcount, dict_t *dict,
int8_t soft_limit = 0;
int8_t config_type = -1;
const char *question = NULL;
- unsigned int cmdi = 2;
- int8_t auto_delete = -1;
+ unsigned int cmdi = 2;
/* cmdi is command index, here cmdi is "2" (gluster snapshot config)*/
GF_ASSERT (words);
@@ -3892,7 +3891,8 @@ cli_snap_config_parse (const char **words, int wordcount, dict_t *dict,
/* 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], "auto-delete") != 0) {
+ && strcmp (words[cmdi], "auto-delete") != 0
+ && strcmp (words[cmdi], "activate-on-create") != 0) {
ret = dict_set_str (dict, "volname", (char *)words[cmdi]);
if (ret) {
gf_log ("cli", GF_LOG_ERROR, "Failed to set volname");
@@ -3950,10 +3950,12 @@ cli_snap_config_parse (const char **words, int wordcount, dict_t *dict,
goto out;
}
soft_limit = 1;
- goto set;
}
- if (hard_limit != 1 && (strcmp(words[cmdi], "auto-delete") == 0)) {
+ if (hard_limit || soft_limit)
+ goto set;
+
+ if (strcmp(words[cmdi], "auto-delete") == 0) {
if (vol_presence == 1) {
ret = -1;
cli_err ("As of now, auto-delete option cannot be set "
@@ -3976,19 +3978,47 @@ cli_snap_config_parse (const char **words, int wordcount, dict_t *dict,
"dictionary");
goto out;
}
- auto_delete = 1;
if (++cmdi != wordcount) {
ret = -1;
gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
goto out;
}
- }
- else {
+ } else if (strcmp(words[cmdi], "activate-on-create") == 0) {
+ if (vol_presence == 1) {
+ ret = -1;
+ cli_err ("As of now, activate-on-create option "
+ "cannot be set to volumes");
+ gf_log ("cli", GF_LOG_ERROR, "activate-on-create "
+ "option cannot be set to volumes");
+ goto out;
+ }
+
+ if (++cmdi >= wordcount) {
+ ret = -1;
+ gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax");
+ goto out;
+ }
+
+ ret = dict_set_str (dict, "snap-activate-on-create",
+ (char *)words[cmdi]);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR, "Failed to set value "
+ "of activate-on-create in request dictionary");
+ 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;
}
+
ret = 0; /* Success */
set:
@@ -3999,7 +4029,8 @@ set:
goto out;
}
- if (config_type == GF_SNAP_CONFIG_TYPE_SET && auto_delete != 1) {
+ if (config_type == GF_SNAP_CONFIG_TYPE_SET &&
+ (hard_limit || soft_limit)) {
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 07d04595b06..d03b5b99dd0 100644
--- a/cli/src/cli-cmd-snapshot.c
+++ b/cli/src/cli-cmd-snapshot.c
@@ -104,7 +104,8 @@ struct cli_cmd snapshot_cmds[] = {
},
{"snapshot config [volname] ([snap-max-hard-limit <count>] "
"[snap-max-soft-limit <percent>]) "
- "| ([auto-delete <enable|disable>])",
+ "| ([auto-delete <enable|disable>])"
+ "| ([activate-on-create <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 bb5e3b56378..f194a76efb4 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -7792,6 +7792,7 @@ cli_snapshot_config_display (dict_t *dict, gf_cli_rsp *rsp)
uint64_t i = 0;
uint64_t voldisplaycount = 0;
char *auto_delete = NULL;
+ char *snap_activate = NULL;
GF_ASSERT (dict);
GF_ASSERT (rsp);
@@ -7823,9 +7824,11 @@ cli_snapshot_config_display (dict_t *dict, gf_cli_rsp *rsp)
ret = dict_get_str (dict, "auto-delete", &auto_delete);
+ ret = dict_get_str (dict, "snap-activate-on-create", &snap_activate);
+
if (!hard_limit && !soft_limit
&& config_command != GF_SNAP_CONFIG_DISPLAY
- && !auto_delete) {
+ && !auto_delete && !snap_activate) {
ret = -1;
gf_log(THIS->name, GF_LOG_ERROR,
"Could not fetch config-key");
@@ -7849,6 +7852,9 @@ cli_snapshot_config_display (dict_t *dict, gf_cli_rsp *rsp)
} else if (auto_delete) {
cli_out ("snapshot config: auto-delete "
"successfully set");
+ } else if (snap_activate) {
+ cli_out ("snapshot config: activate-on-create "
+ "successfully set");
}
break;
@@ -7875,7 +7881,9 @@ cli_snapshot_config_display (dict_t *dict, gf_cli_rsp *rsp)
cli_out ("snap-max-soft-limit : %"PRIu64"%%",
soft_limit);
- cli_out ("auto-delete : %s\n", auto_delete);
+ cli_out ("auto-delete : %s", auto_delete);
+
+ cli_out ("activate-on-create : %s\n", snap_activate);
cli_out ("Snapshot Volume Configuration:");
diff --git a/cli/src/cli-xml-output.c b/cli/src/cli-xml-output.c
index d0a72772085..90b184d9f3f 100644
--- a/cli/src/cli-xml-output.c
+++ b/cli/src/cli-xml-output.c
@@ -5164,7 +5164,7 @@ cli_xml_snapshot_config_show (xmlTextWriterPtr writer,
ret = dict_get_str (dict, "auto-delete", &str_value);
if (ret) {
- gf_log ("cli", GF_LOG_ERROR, "Could not fetch auto-delet");
+ gf_log ("cli", GF_LOG_ERROR, "Could not fetch auto-delete");
goto out;
}
@@ -5172,6 +5172,17 @@ cli_xml_snapshot_config_show (xmlTextWriterPtr writer,
(xmlChar *) "autoDelete", "%s", str_value);
XML_RET_CHECK_AND_GOTO (ret, out);
+ ret = dict_get_str (dict, "snap-activate-on-create", &str_value);
+ if (ret) {
+ gf_log ("cli", GF_LOG_ERROR,
+ "Could not fetch snap-activate-on-create-delete");
+ goto out;
+ }
+
+ ret = xmlTextWriterWriteFormatElement (writer,
+ (xmlChar *) "activateOnCreate", "%s", str_value);
+ XML_RET_CHECK_AND_GOTO (ret, out);
+
/* </systemConfig> */
ret = xmlTextWriterEndElement (writer);
XML_RET_CHECK_AND_GOTO (ret, out);
@@ -5275,6 +5286,7 @@ cli_xml_snapshot_config_set (xmlTextWriterPtr writer, xmlDocPtr doc,
uint64_t soft_limit = 0;
char *volname = NULL;
char *auto_delete = NULL;
+ char *snap_activate = NULL;
GF_ASSERT (writer);
GF_ASSERT (doc);
@@ -5285,12 +5297,13 @@ cli_xml_snapshot_config_set (xmlTextWriterPtr writer, xmlDocPtr doc,
/* This is optional parameter therefore ignore the error */
ret = dict_get_uint64 (dict, "snap-max-soft-limit", &soft_limit);
ret = dict_get_str (dict, "auto-delete", &auto_delete);
+ ret = dict_get_str (dict, "snap-activate-on-create", &snap_activate);
- if (!hard_limit && !soft_limit && !auto_delete) {
+ if (!hard_limit && !soft_limit && !auto_delete && !snap_activate) {
ret = -1;
gf_log ("cli", GF_LOG_ERROR, "At least one option from "
- "snap-max-hard-limit, snap-max-soft-limit and "
- "auto-delete should be set");
+ "snap-max-hard-limit, snap-max-soft-limit, auto-delete"
+ " and snap-activate-on-create should be set");
goto out;
}
@@ -5333,6 +5346,12 @@ cli_xml_snapshot_config_set (xmlTextWriterPtr writer, xmlDocPtr doc,
XML_RET_CHECK_AND_GOTO (ret, out);
}
+ if (snap_activate) {
+ ret = xmlTextWriterWriteFormatElement (writer,
+ (xmlChar *) "activateOnCreate", "%s", snap_activate);
+ XML_RET_CHECK_AND_GOTO (ret, out);
+ }
+
/* </volumeConfig> or </systemConfig> */
ret = xmlTextWriterEndElement (writer);
XML_RET_CHECK_AND_GOTO (ret, out);