From 3a7fdc198ada9621333b560c8911a05844413751 Mon Sep 17 00:00:00 2001 From: Sachin Pandit Date: Wed, 5 Mar 2014 11:27:06 +0530 Subject: snapshot/restore : Snapshot restore changes. This Patch includes cli change and few backend changes. Syntax : gluster snapshot restore ** Also removed unwanted snapshot remove parsing code. Change-Id: Ie32590ccd4080da9409fd16c543866c14fae28f5 Signed-off-by: Sachin Pandit Reviewed-on: http://review.gluster.org/7191 Reviewed-by: Vijaikumar Mallikarjuna Reviewed-by: Rajesh Joseph Tested-by: Rajesh Joseph --- cli/src/cli-cmd-parser.c | 220 +++++---------------------------------------- cli/src/cli-cmd-snapshot.c | 2 +- cli/src/cli-rpc-ops.c | 60 +++++-------- 3 files changed, 41 insertions(+), 241 deletions(-) (limited to 'cli') diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 727206ab0..adfb85e9e 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -3201,211 +3201,36 @@ out: return ret; } -/* remove command takes either the snapname or the cg name. - If snap has to be remvoed for a volume, then the volume name - also should be given in the command. If cg should be removed, - then volume name is not necessary. Giving "force" will delete - the snapshot without giving notification. - "gluster snapshot delete ( -s | -c ) [force]" - return value: -1 on failure - 1 if user cancels the operation - 0 on success -*/ -int32_t -cli_snap_remove_parse (dict_t *dict, const char **words, int wordcount, - unsigned int cmdi, struct cli_state *state) -{ - uint32_t name_opt_loc = 0; - int32_t ret = -1; - uint32_t i = 0; - gf_boolean_t is_cg = _gf_false; - const char *question = NULL; - gf_answer_t answer = GF_ANSWER_NO; - - question = "Deleting snap will erase all information about the snap. " - "Do you want to continue?"; - - GF_ASSERT (dict); - GF_ASSERT (words); - - /* Finding the "-s or -c" in the cli */ - for (i = cmdi; i < wordcount; i++) { - if (!strcmp (words[i], "-s") || !strcmp (words[i], "-c")) { - name_opt_loc = i; - if (!strcmp (words[i], "-c")) - is_cg = _gf_true; - break; - } - } - - if (name_opt_loc == 0) { - gf_log ("", GF_LOG_ERROR, "options -s/-c is not found in the " - "command"); - goto out; - } - - if (name_opt_loc == (wordcount - 1)) { - gf_log ("", GF_LOG_ERROR, "%s name is not given", - is_cg?"cg":"snap"); - goto out; - } - - if (!is_cg) { - if (!strcmp (words[cmdi], "-s")) { - gf_log ("", GF_LOG_ERROR, "Volume name is not given " - "for the snapshot deletion"); - ret = -1; - goto out; - } - } else { - if (strcmp (words[cmdi], "-c")) { - gf_log ("", GF_LOG_ERROR, "volume name is not needed " - "for consistency group deletion"); - ret = -1; - goto out; - } - } - - /* Saving snapname/cg-name in dict */ - if (name_opt_loc >= cmdi) { - /* Decide if it's a cg-name or a snapname */ - if (is_cg) { - ret = dict_set_str (dict, "cgname", - (char *)words[name_opt_loc + 1]); - if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to save cg-name"); - goto out; - } - } else { - ret = dict_set_int64 (dict, "volcount", 1); - if (ret) { - gf_log ("", GF_LOG_ERROR, "failed to set " - "volcount"); - goto out; - } - ret = dict_set_str (dict, "volname1", - (char *)words[name_opt_loc - 1]); - if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to save volname"); - goto out; - } - ret = dict_set_str (dict, "snapname", - (char *)words[name_opt_loc + 1]); - if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to save snapname"); - goto out; - } - } - } - - if ((strcmp (words[wordcount - 1], "force"))) { - answer = cli_cmd_get_confirmation (state, question); - if (GF_ANSWER_NO == answer) { - ret = 1; - gf_log ("", GF_LOG_DEBUG, "User cancelled " - "snapshot delete operation"); - goto out; - } - } - -out: - return ret; -} - -/* Syntax: - * snapshot restore (-v | -c ) +/* snapshot restore + * @arg-0, dict : Request Dictionary to be sent to server side. + * @arg-1, words : Contains individual words of CLI command. + * @arg-2, wordcount: Contains number of words present in the CLI command. + * @arg-3, cmdi : command index, here cmdi is "2"(gluster snapshot restore) + * + * return value : -1 on failure + * 0 on success */ int cli_snap_restore_parse (dict_t *dict, const char **words, int wordcount, - unsigned int cmdi) -{ - int ret = -1; /* Failure */ - const char* vol_name = NULL; - const char* snap_name = NULL; - const char* cg_name = NULL; + unsigned int cmdi) { + + int ret = -1; - GF_ASSERT (dict); GF_ASSERT (words); + GF_ASSERT (dict); - /* At least CG_INDEX argument should be there for a valid command */ - if (wordcount <= cmdi) { - gf_log ("cli", GF_LOG_ERROR, "Invalid command: Not enough " - "arguments"); + if (wordcount != 3) { + gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); goto out; } - if (0 == strcmp (words[cmdi], "-v")) { - /* snapshot restore -v - * - * cmdi points to -v, therefore wordcount should be exactly - * equal to (cmdi + 2) + 1. +1 is added to convert index to - * count - */ - if ((cmdi + 3) != wordcount) { - gf_log ("cli", GF_LOG_ERROR, "Invalid argument count"); - goto out; - } - - vol_name = words[++cmdi]; - snap_name = words[++cmdi]; - - if ((NULL == vol_name) || (NULL == snap_name)) { - gf_log ("cli", GF_LOG_ERROR, "Volume or snap " - "name missing"); - goto out; - } - - /* Single volume should be represented by volcount 1 - * and a volname in dictionary - */ - ret = dict_set_int64 (dict, "volcount", 1); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Failed to set " - "vol count"); - goto out; - } - - /* TODO: Change the index to 0 once Jarvis code is fixed */ - ret = dict_set_str (dict, "volname1", (char *)vol_name); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Failed to set " - "volume name"); - goto out; - } - - ret = dict_set_str (dict, "snapname", (char *)snap_name); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Failed to set " - "snap name"); - goto out; - } - } else if (0 == strcmp (words[cmdi], "-c")) { - /* If -c option is provided then command should look like - * snapshot restore -c - * - * cmdi points to -c, therefore wordcount should be exactly - * equal to (cmdi + 1) + 1. +1 is added to convert index to - * count - */ - if ((cmdi + 2) != wordcount) { - gf_log ("cli", GF_LOG_ERROR, "Invalid argument count"); - goto out; - } - cg_name = words[++cmdi]; - ret = dict_set_str (dict, "cgname", (char *)cg_name); - if (ret) { - gf_log ("cli", GF_LOG_ERROR, "Failed to set " - "CG name"); - goto out; - } - } else { - gf_log ("cli", GF_LOG_ERROR, "Invalid (%s) option", - words[cmdi]); + ret = dict_set_str (dict, "snapname", (char *)words[cmdi]); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "Unable to save snap-name %s", + words[cmdi]); goto out; } - - ret = 0; /* Success */ -out: +out : return ret; } @@ -3605,13 +3430,8 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, case GF_SNAP_OPTION_TYPE_RESTORE: { /* Syntax: - * snapshot restore (-v | - * -c ) + * snapshot restore */ - - /* Start parsing from the first option after "restore" */ - cmdi = 2; - ret = cli_snap_restore_parse (dict, words, wordcount, cmdi); if (ret) { diff --git a/cli/src/cli-cmd-snapshot.c b/cli/src/cli-cmd-snapshot.c index a7e39e64c..2389252b3 100644 --- a/cli/src/cli-cmd-snapshot.c +++ b/cli/src/cli-cmd-snapshot.c @@ -87,7 +87,7 @@ struct cli_cmd snapshot_cmds[] = { cli_cmd_snapshot_cbk, "Snapshot Create." }, - { "snapshot restore (-v | -c )", + { "snapshot restore ", cli_cmd_snapshot_cbk, "Snapshot Restore." }, diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index ee26e7d76..0447e5baf 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -8028,9 +8028,7 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov, gf_cli_rsp rsp = {0, }; dict_t *dict = NULL; char *snap_name = NULL; - char *cg_name = NULL; int32_t type = 0; - int64_t volcount = -1; call_frame_t *frame = NULL; gf_boolean_t snap_driven = _gf_false; @@ -8076,31 +8074,16 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov, goto out; } - ret = dict_get_int64 (dict, "volcount", &volcount); + ret = dict_get_str (dict, "snapname", &snap_name); if (ret) { - gf_log (frame->this->name, GF_LOG_ERROR, - "failed to get volcount"); + gf_log ("cli", GF_LOG_ERROR, + "Failed to get snap name"); goto out; } - - if (volcount > 1) { - if (dict_get_str (dict, "cg-name", - &cg_name) != 0) - cg_name = "???"; - - cli_out ("snapshot create: %s: consistency " - "group created successfully", - cg_name); - } else { - if (dict_get_str (dict, "snapname", - &snap_name) != 0) - snap_name = "???"; - - cli_out ("snapshot create: %s: " - "snap created successfully", - snap_name); - } + cli_out ("snapshot create: %s: snap created successfully", + snap_name); break; + case GF_SNAP_OPTION_TYPE_RESTORE: /* TODO: Check if rsp.op_ret needs to be checked here. Or is * it ok to check this in the start of the function where we @@ -8113,23 +8096,15 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov, goto out; } - ret = dict_get_str (dict, "cgname", &cg_name); + ret = dict_get_str (dict, "snapname", &snap_name); if (ret) { - ret = dict_get_str (dict, "snapname", &snap_name); - if (ret) { - gf_log (frame->this->name, GF_LOG_ERROR, - "Failed to get CG name or snap name"); - goto out; - } + gf_log ("cli", GF_LOG_ERROR, + "Failed to get snap name"); + goto out; } - if (NULL != snap_name) { - cli_out ("Snapshot restore: %s: Snap restored " + cli_out ("Snapshot restore: %s: Snap restored " "successfully", snap_name); - } else { - cli_out ("Snapshot restore: %s: Consistency group " - "restored successfully", cg_name); - } ret = 0; break; @@ -8165,8 +8140,8 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov, case GF_SNAP_OPTION_TYPE_CONFIG: ret = cli_snapshot_config_display (dict, &rsp); if (ret) { - gf_log ("", GF_LOG_ERROR, "Failed to display snapshot " - "config output."); + gf_log ("cli", GF_LOG_ERROR, "Failed to display " + "snapshot config output."); goto out; } break; @@ -8174,14 +8149,19 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov, case GF_SNAP_OPTION_TYPE_LIST: ret = cli_snapshot_list (dict); if (ret) { - gf_log ("", GF_LOG_ERROR, "Failed to display snapshot" - " list"); + gf_log ("cli", GF_LOG_ERROR, "Failed to display " + "snapshot list"); goto out; } break; case GF_SNAP_OPTION_TYPE_DELETE: ret = cli_snapshot_remove_reply (&rsp, dict, frame); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, + "Failed to delete snap"); + goto out; + } break; default: -- cgit