From 096b23f187d0b3ccbed25d8bd02723a61cc4da2d Mon Sep 17 00:00:00 2001 From: shishir gowda Date: Thu, 24 Oct 2013 15:47:14 +0530 Subject: mgmt/glusterd: snapshot config changes Also refactored code in glusterd for create command Additionally, removed brick-op func from mgmt_iniate_all_phases Change-Id: Iddcc332009c5716adee7f2b04c93b352fb983446 Signed-off-by: shishir gowda --- cli/src/cli-cmd-parser.c | 104 +++++++++++++++++++++++++++++++++++++++------ cli/src/cli-cmd-snapshot.c | 6 ++- cli/src/cli-rpc-ops.c | 49 +++++++++++++++++++++ 3 files changed, 144 insertions(+), 15 deletions(-) (limited to 'cli/src') diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index cf790918c..b7078ff28 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -3163,6 +3163,82 @@ out: return ret; } +int32_t +cli_snap_config_parse (const char **words, int wordcount, dict_t *options) +{ + dict_t *dict = NULL; + char *volname = NULL; + int ret = -1; + char *key = NULL; + char *value = NULL; + uint64_t limit = 0; + gf1_cli_snapshot type = GF_SNAP_OPTION_TYPE_NONE; + + GF_ASSERT (words); + GF_ASSERT (options); + + if ((wordcount != 3) && (wordcount != 5)) + goto out; + + volname = (char *)words[2]; + + GF_ASSERT (volname); + + type = GF_SNAP_OPTION_TYPE_CONFIG; + ret = dict_set_int32 (options, "type", type); + if (ret) { + gf_log ("", GF_LOG_ERROR, + "Failed to set type."); + goto out; + } + + ret = dict_set_str (options, "volname", volname); + if (ret) { + gf_log ("", GF_LOG_ERROR, + "Failed to set volname."); + goto out; + } + + /* snapshot config [snap_max_limit ] */ + + if (wordcount == 3) { + ret = dict_set_int32 (options, "config-command", + GF_SNAP_CONFIG_DISPLAY); + goto out; + } + + key = (char *) words[3]; + value = (char *) words[4]; + if ( !key || !value) { + ret = -1; + goto out; + } + if (strncmp (key, "snap-max-limit", 14)) { + gf_log ("", GF_LOG_ERROR, "Invalid key"); + goto out; + } + if (!strncmp (volname, "all", 3)) { + ret = dict_set_int32 (options, "config-command", + GF_SNAP_CONFIG_SYS_MAX); + } else { + ret = dict_set_int32 (options, "config-command", + GF_SNAP_CONFIG_VOL_MAX); + } + + limit = (uint64_t) atoll (value); + ret = dict_set_uint64 (options, "limit", limit); + if (ret) { + gf_log ("", GF_LOG_ERROR, + "Failed to set limit."); + goto out; + } + if (ret) + goto out; + +out: + return ret; +} + int32_t cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options) @@ -3171,7 +3247,7 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options) dict_t *dict = NULL; gf1_cli_snapshot type = GF_SNAP_OPTION_TYPE_NONE; int32_t cmdi = 0; - char *opwords[] = {"create", "list", NULL}; + char *opwords[] = {"create", "list", "config", NULL}; char *w = NULL; int i = 0; @@ -3211,12 +3287,6 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options) goto out; type = GF_SNAP_OPTION_TYPE_CREATE; cmdi = 1; - ret = dict_set_int32 (dict, "type", type); - if (ret) { - gf_log ("", GF_LOG_ERROR, - "Failed to set type."); - goto out; - } ret = cli_snap_create_parse (dict, words, wordcount, cmdi); @@ -3239,14 +3309,8 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options) goto out; } } - type = GF_SNAP_OPTION_TYPE_LIST; - ret = dict_set_int32 (dict, "type" , type); - if (ret) { - gf_log ("" , GF_LOG_ERROR, - "Failed to set type."); - goto out; - } + type = GF_SNAP_OPTION_TYPE_LIST; ret = cli_snap_list_parse (dict, words, wordcount, cmdi); @@ -3256,11 +3320,23 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options) "list command parsing failed."); goto out; } + } else if (strcmp (w, "config") == 0){ + /* snapshot config [snap_max_limit ] */ + + type = GF_SNAP_OPTION_TYPE_CONFIG; + + ret = cli_snap_config_parse (words, wordcount, dict); } else { gf_log ("", GF_LOG_ERROR, "Opword Mismatch"); goto out; } + ret = dict_set_int32 (dict, "type", type); + if (ret) { + gf_log ("", GF_LOG_ERROR, + "Failed to set type."); + goto out; + } /* If you got so far, input is valid */ ret = 0; out: diff --git a/cli/src/cli-cmd-snapshot.c b/cli/src/cli-cmd-snapshot.c index afe8bf901..6c2b3d5e5 100644 --- a/cli/src/cli-cmd-snapshot.c +++ b/cli/src/cli-cmd-snapshot.c @@ -77,7 +77,7 @@ struct cli_cmd snapshot_cmds[] = { cli_cmd_snapshot_help_cbk, "display help for snapshot commands" }, - {"snapshot create [-n ] [-d ]", + {"snapshot create [-n ] [-d ]", cli_cmd_snapshot_cbk, "Snapshot Create." }, @@ -86,6 +86,10 @@ struct cli_cmd snapshot_cmds[] = { cli_cmd_snapshot_cbk, "Snapshot List." }, + {"snapshot config < volname | all > [ snap-max-limit ]", + cli_cmd_snapshot_cbk, + "Snapshot Config." + }, { NULL, NULL, NULL } }; diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 20cad3bb3..e881e18fc 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -7806,6 +7806,9 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov, int32_t type = 0; int64_t volcount = -1; call_frame_t *frame = NULL; + uint64_t limit = 0; + int32_t config_command = 0; + char *volname = NULL; if (req->rpc_status == -1) { ret = -1; @@ -7903,6 +7906,52 @@ gf_cli_snapshot_cbk (struct rpc_req *req, struct iovec *iov, } break; + case GF_SNAP_OPTION_TYPE_CONFIG: + if (rsp.op_ret) { + cli_err ("Snapshot Config : failed: %s", + rsp.op_errstr ? rsp.op_errstr : + "Please check log file for details"); + ret = rsp.op_ret; + goto out; + } + + ret = dict_get_int32 (dict, "config-command", &config_command); + + if (ret) { + gf_log("", GF_LOG_DEBUG, "Could not fetch config type"); + ret = -1; + goto out; + } + + ret = dict_get_str (dict, "volname", &volname); + if (ret) { + gf_log("", GF_LOG_DEBUG, "Could not fetch " + "volname"); + ret = -1; + goto out; + } + + if (!strcmp (volname, "all")) { + volname = "System"; + } + + if (config_command == GF_SNAP_CONFIG_DISPLAY) { + + ret = dict_get_uint64 (dict, "limit", &limit); + if (ret) { + gf_log("", GF_LOG_DEBUG, "Could not fetch " + "limit for %s", volname); + ret = -1; + goto out; + } + cli_out ("Max snapshot count set for %s is %"PRIu64, + volname, limit); + } else { + cli_out ("Snapshot config max set for %s successfull", + volname); + } + break; + default: cli_err ("Unknown command executed"); ret = -1; -- cgit