diff options
author | vmallika <vmallika@redhat.com> | 2014-10-28 12:25:43 +0530 |
---|---|---|
committer | Kaushal M <kaushal@redhat.com> | 2014-11-12 04:36:11 -0800 |
commit | 4fa4b7f2c2b57d1055adb76e8258b0db176bc356 (patch) | |
tree | e4beb4567c57370b8622f19746721e2a0b0f96f1 /cli/src | |
parent | 55aa4b185561edd7b3d1ab77a4f29a4facfdd7ff (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: 1157991
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>
Diffstat (limited to 'cli/src')
-rw-r--r-- | cli/src/cli-cmd-parser.c | 51 | ||||
-rw-r--r-- | cli/src/cli-cmd-snapshot.c | 3 | ||||
-rw-r--r-- | cli/src/cli-rpc-ops.c | 12 | ||||
-rw-r--r-- | cli/src/cli-xml-output.c | 27 |
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 e9db57259b2..08f51558506 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -7808,6 +7808,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); @@ -7839,9 +7840,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"); @@ -7865,6 +7868,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; @@ -7891,7 +7897,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 66bec7ee96f..aacce140946 100644 --- a/cli/src/cli-xml-output.c +++ b/cli/src/cli-xml-output.c @@ -5156,7 +5156,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; } @@ -5164,6 +5164,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); @@ -5267,6 +5278,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); @@ -5277,12 +5289,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; } @@ -5325,6 +5338,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); |