From 89414cb24ed47984445aecd88fa3ca73597ebed9 Mon Sep 17 00:00:00 2001 From: Sachin Pandit Date: Thu, 3 Apr 2014 04:57:48 +0530 Subject: cli/snapshot : cli fixes for upstream review comments. Change-Id: I69f32920dc48c6c52b579c792f28951bb38db344 Signed-off-by: Sachin Pandit Reviewed-on: http://review.gluster.org/7385 Reviewed-by: Raghavendra Bhat Reviewed-by: Rajesh Joseph Tested-by: Rajesh Joseph --- cli/src/cli-cmd-parser.c | 99 ++++++++++++++++++++++-------------------------- cli/src/cli-rpc-ops.c | 1 + cli/src/cli-xml-output.c | 13 +++++++ 3 files changed, 60 insertions(+), 53 deletions(-) diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 6232f6301..5ab208b8f 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -195,7 +195,8 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options char *invalid_volnames[] = {"volume", "type", "subvolumes", "option", "end-volume", "all", "volume_not_in_ring", - "description", "force", "snap-max-hard-limit", + "description", "force", + "snap-max-hard-limit", "snap-max-soft-limit", NULL}; char *w = NULL; int op_count = 0; @@ -2811,15 +2812,15 @@ out: /* Function to check whether the Volume name is repeated */ int -check_if_volname_repeated (const char **words, unsigned int start_index, - uint64_t end_index) { +cli_check_if_volname_repeated (const char **words, unsigned int start_index, + uint64_t cur_index) { uint64_t i = -1; int ret = 0; GF_ASSERT (words); - for (i = start_index ; i < end_index ; i++) { - if (strcmp (words[i], words[end_index]) == 0) { + for (i = start_index ; i < cur_index ; i++) { + if (strcmp (words[i], words[cur_index]) == 0) { ret = -1; goto out; } @@ -2828,26 +2829,24 @@ out : return ret; } - - /* snapshot create [description ] * [force] * @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 create) * * return value : -1 on failure * 0 on success */ int -cli_snap_create_parse (dict_t *dict, const char **words, int wordcount, - unsigned int cmdi) { +cli_snap_create_parse (dict_t *dict, const char **words, int wordcount) { uint64_t i = 0; int ret = -1; uint64_t volcount = 0; char key[PATH_MAX] = ""; char *snapname = NULL; + unsigned int cmdi = 2; + /* cmdi is command index, here cmdi is "2" (gluster snapshot create)*/ GF_ASSERT (words); GF_ASSERT (dict); @@ -2873,7 +2872,8 @@ cli_snap_create_parse (dict_t *dict, const char **words, int wordcount, if (!isalnum (snapname[i]) && (snapname[i] != '_' && (snapname[i] != '-'))) { /* TODO : Is this message enough?? */ - cli_err ("Please provide a valid snapname"); + cli_err ("Snapname can contain only alphanumeric, " + "\"-\" and \"_\" characters"); goto out; } } @@ -2991,20 +2991,18 @@ out : * @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 list) * * return value : -1 on failure * 0 on success */ int -cli_snap_list_parse (dict_t *dict, const char **words, int wordcount, - unsigned int cmdi) { - int ret = -1; +cli_snap_list_parse (dict_t *dict, const char **words, int wordcount) { + int ret = -1; GF_ASSERT (words); GF_ASSERT (dict); - if (wordcount < cmdi || wordcount > 3) { + if (wordcount < 2 || wordcount > 3) { gf_log ("cli", GF_LOG_ERROR, "Invalid Syntax"); goto out; } @@ -3014,7 +3012,7 @@ cli_snap_list_parse (dict_t *dict, const char **words, int wordcount, goto out; } - ret = dict_set_str (dict, "volname", (char *)words[cmdi]); + ret = dict_set_str (dict, "volname", (char *)words[2]); if (ret) { gf_log ("cli", GF_LOG_ERROR, "Failed to save volname in dictionary"); @@ -3028,17 +3026,18 @@ out : * @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 info) * * return value : -1 on failure * 0 on success */ int -cli_snap_info_parse (dict_t *dict, const char **words, int wordcount, - unsigned int cmdi) { +cli_snap_info_parse (dict_t *dict, const char **words, int wordcount) +{ - int ret = -1; - int32_t cmd = GF_SNAP_INFO_TYPE_ALL; + int ret = -1; + int32_t cmd = GF_SNAP_INFO_TYPE_ALL; + unsigned int cmdi = 2; + /* cmdi is command index, here cmdi is "2" (gluster snapshot info)*/ GF_ASSERT (words); GF_ASSERT (dict); @@ -3117,14 +3116,13 @@ out : * @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) { +cli_snap_restore_parse (dict_t *dict, const char **words, int wordcount) +{ int ret = -1; @@ -3136,10 +3134,10 @@ cli_snap_restore_parse (dict_t *dict, const char **words, int wordcount, goto out; } - ret = dict_set_str (dict, "snapname", (char *)words[cmdi]); + ret = dict_set_str (dict, "snapname", (char *)words[2]); if (ret) { gf_log ("cli", GF_LOG_ERROR, "Unable to save snap-name %s", - words[cmdi]); + words[2]); goto out; } out : @@ -3150,7 +3148,6 @@ out : * @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 delete) * * return value : -1 on failure * 0 on success @@ -3158,7 +3155,7 @@ out : */ int cli_snap_delete_parse (dict_t *dict, const char **words, int wordcount, - unsigned int cmdi, struct cli_state *state) { + struct cli_state *state) { int ret = -1; const char *question = NULL; @@ -3175,10 +3172,10 @@ cli_snap_delete_parse (dict_t *dict, const char **words, int wordcount, goto out; } - ret = dict_set_str (dict, "snapname", (char *)words[cmdi]); + ret = dict_set_str (dict, "snapname", (char *)words[2]); if (ret) { gf_log ("cli", GF_LOG_ERROR, "Unable to save snapname %s", - words[cmdi]); + words[2]); goto out; } @@ -3197,17 +3194,18 @@ out : * @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 status) * * return value : -1 on failure * 0 on success */ int -cli_snap_status_parse (dict_t *dict, const char **words, int wordcount, - unsigned int cmdi) { +cli_snap_status_parse (dict_t *dict, const char **words, int wordcount) +{ - int ret = -1; - int32_t cmd = GF_SNAP_STATUS_TYPE_ALL; + int ret = -1; + int32_t cmd = GF_SNAP_STATUS_TYPE_ALL; + unsigned int cmdi = 2; + /* cmdi is command index, here cmdi is "2" (gluster snapshot status)*/ GF_ASSERT (words); GF_ASSERT (dict); @@ -3323,7 +3321,7 @@ out : */ int32_t cli_snap_config_parse (const char **words, int wordcount, dict_t *dict, - unsigned int cmdi, struct cli_state *state) + struct cli_state *state) { int ret = -1; gf_answer_t answer = GF_ANSWER_NO; @@ -3333,6 +3331,8 @@ 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; + /* cmdi is command index, here cmdi is "2" (gluster snapshot config)*/ GF_ASSERT (words); GF_ASSERT (dict); @@ -3473,7 +3473,6 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, int32_t ret = -1; dict_t *dict = NULL; gf1_cli_snapshot type = GF_SNAP_OPTION_TYPE_NONE; - unsigned int cmdi = 0; char *w = NULL; char *opwords[] = {"create", "delete", "restore", "start", "stop", "list", "status", "config", @@ -3523,13 +3522,12 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, ret = dict_set_int32 (dict, "hold_snap_locks", _gf_true); if (ret) { gf_log ("cli", GF_LOG_ERROR, - "Unable to set hold-snap-locks value as _gf_true"); + "Unable to set hold-snap-locks value " + "as _gf_true"); goto out; } } - cmdi = 2; - /* Check which op is intended */ switch (type) { case GF_SNAP_OPTION_TYPE_CREATE: @@ -3556,8 +3554,7 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, goto out; } - ret = cli_snap_create_parse (dict, words, - wordcount, cmdi); + ret = cli_snap_create_parse (dict, words, wordcount); if (ret) { gf_log ("cli", GF_LOG_ERROR, "create command parsing failed."); @@ -3570,8 +3567,7 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, /* Syntax : * gluster snapshot info [(snapname] | [vol )] */ - ret = cli_snap_info_parse (dict, words, wordcount, - cmdi); + ret = cli_snap_info_parse (dict, words, wordcount); if (ret) { gf_log ("cli", GF_LOG_ERROR, "Failed to parse " "snapshot info command"); @@ -3586,8 +3582,7 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, * gluster snaphsot list [volname] */ - ret = cli_snap_list_parse (dict, words, wordcount, - cmdi); + ret = cli_snap_list_parse (dict, words, wordcount); if (ret) { gf_log ("cli", GF_LOG_ERROR, "Failed to parse " "snapshot list command"); @@ -3602,7 +3597,7 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, * gluster snapshot delete */ ret = cli_snap_delete_parse (dict, words, wordcount, - cmdi, state); + state); if (ret) { gf_log ("cli", GF_LOG_ERROR, "Failed to parse " "snapshot delete command"); @@ -3616,7 +3611,7 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, /* snapshot config [volname] [snap-max-hard-limit ] * [snap-max-soft-limit ] */ ret = cli_snap_config_parse (words, wordcount, dict, - cmdi, state); + state); if (ret) { if (ret < 0) gf_log ("cli", GF_LOG_ERROR, @@ -3640,8 +3635,7 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, * gluster snapshot status [(snapname | * volume )] */ - ret = cli_snap_status_parse (dict, words, wordcount, - cmdi); + ret = cli_snap_status_parse (dict, words, wordcount); if (ret) { gf_log ("cli", GF_LOG_ERROR, "Failed to parse " "snapshot status command"); @@ -3655,8 +3649,7 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, /* Syntax: * snapshot restore */ - ret = cli_snap_restore_parse (dict, words, wordcount, - cmdi); + ret = cli_snap_restore_parse (dict, words, wordcount); if (ret) { gf_log ("cli", GF_LOG_ERROR, "Failed to parse " "restore command"); diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index e3eae022a..bfeb854ad 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -8521,6 +8521,7 @@ out: cli_cmd_broadcast_response (ret); free (rsp.dict.dict_val); + free (rsp.op_errstr); return ret; } diff --git a/cli/src/cli-xml-output.c b/cli/src/cli-xml-output.c index 0f837fc74..d8884d44b 100644 --- a/cli/src/cli-xml-output.c +++ b/cli/src/cli-xml-output.c @@ -2499,6 +2499,7 @@ cli_xml_output_vol_info (cli_local_t *local, dict_t *dict) int j = 1; char *caps = NULL; int k __attribute__((unused)) = 0; + char *snap_volume = NULL; ret = dict_get_int32 (dict, "count", &count); if (ret) @@ -2540,6 +2541,18 @@ cli_xml_output_vol_info (cli_local_t *local, dict_t *dict) "%d", status); XML_RET_CHECK_AND_GOTO (ret, out); + memset (key, 0, sizeof (key)); + snprintf (key, sizeof (key), "volume%d.snap_volume", i); + ret = dict_get_str (dict, key, &snap_volume); + if (ret) + goto out; + if (snap_volume) { + ret = xmlTextWriterWriteFormatElement (local->writer, + (xmlChar *)"snapVol", + "%s", snap_volume); + XML_RET_CHECK_AND_GOTO (ret, out); + } + ret =xmlTextWriterWriteFormatElement (local->writer, (xmlChar *)"statusStr", "%s", cli_vol_status_str[status]); -- cgit