From 92d1ae829ce5dfca7af2fdb33f10305732028602 Mon Sep 17 00:00:00 2001 From: Sachin Pandit Date: Mon, 25 Aug 2014 05:42:38 +0530 Subject: cli/snapshot : Add confirmation dialog to snapshot restore operation When restoring a volume, the user is not prompted for confirmation. Since restoring a volume rolls back the data to a previous point in time, there is the potential for updates to be lost. Hence it is better to display a confirmation dialogue during snapshot restore operation. Change-Id: I7b23eaeb43ad2aafa508e2ca5750d9b0fc7d6e36 BUG: 1133426 Signed-off-by: Sachin Pandit Reviewed-on: http://review.gluster.org/8525 Tested-by: Gluster Build System Reviewed-by: Vijaikumar Mallikarjuna Reviewed-by: Rajesh Joseph Reviewed-by: Kaushal M --- cli/src/cli-cmd-parser.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'cli') diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 6e30a7094a8..27f1fec0df8 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -3500,10 +3500,13 @@ out: * 0 on success */ int -cli_snap_restore_parse (dict_t *dict, const char **words, int wordcount) +cli_snap_restore_parse (dict_t *dict, const char **words, int wordcount, + struct cli_state *state) { int ret = -1; + const char *question = NULL; + gf_answer_t answer = GF_ANSWER_NO; GF_ASSERT (words); GF_ASSERT (dict); @@ -3519,6 +3522,18 @@ cli_snap_restore_parse (dict_t *dict, const char **words, int wordcount) words[2]); goto out; } + + question = "Restore operation will replace the " + "original volume with the snapshotted volume. " + "Do you still want to continue?"; + + answer = cli_cmd_get_confirmation (state, question); + if (GF_ANSWER_NO == answer) { + ret = 1; + gf_log ("cli", GF_LOG_ERROR, "User cancelled a snapshot " + "restore operation for snap %s", (char *)words[2]); + goto out; + } out: return ret; } @@ -4215,13 +4230,14 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, /* Syntax: * snapshot restore */ - ret = cli_snap_restore_parse (dict, words, wordcount); + ret = cli_snap_restore_parse (dict, words, wordcount, state); if (ret) { gf_log ("cli", GF_LOG_ERROR, "Failed to parse " "restore command"); goto out; } break; + case GF_SNAP_OPTION_TYPE_ACTIVATE: /* Syntax: * snapshot activate [force] @@ -4250,6 +4266,7 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, goto out; } break; + default: gf_log ("", GF_LOG_ERROR, "Opword Mismatch"); goto out; -- cgit