From 4afa88d6cc39be11f122489900af07b57a50fcc4 Mon Sep 17 00:00:00 2001 From: Avra Sengupta Date: Wed, 18 Dec 2013 01:01:47 +0000 Subject: glusterd/snapshot: Defining snap-max-soft-limit as a percentage of snap-max-hard-limit. This patch also prohibits configuration of snap-max-hard-limit and snap-max-soft-limit for snap volumes. Also displaying the snapshot configs by reading data only from local node, as all config data will be in sync across the cluster. Change-Id: I635b925c02ed5b108cd10c7193b154ad82d5afad BUG: 1043792 Signed-off-by: Avra Sengupta --- cli/src/cli-cmd-parser.c | 45 +++++++++++--------- cli/src/cli-cmd-snapshot.c | 2 +- cli/src/cli-rpc-ops.c | 104 +++++++++++++++++++++++++++++---------------- 3 files changed, 93 insertions(+), 58 deletions(-) (limited to 'cli') diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 2762f0cf4..59e951636 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -3203,8 +3203,11 @@ cli_snap_config_parse (const char **words, int wordcount, dict_t *options, GF_ASSERT (options); GF_ASSERT (state); - if ((wordcount < 3) || (wordcount > 5)) + if ((wordcount != 3) && (wordcount != 5)) { + gf_log ("", GF_LOG_ERROR, + "Invalid wordcount(%d)", wordcount); goto out; + } volname = (char *)words[2]; @@ -3226,11 +3229,19 @@ cli_snap_config_parse (const char **words, int wordcount, dict_t *options, } /* snapshot config [snap-max-hard-limit - * | snap-max-soft-limit ] */ + * | snap-max-soft-limit ] */ if (wordcount > 3) { key = (char *) words[3]; value = (char *) words[4]; + } else { + ret = dict_set_int32 (options, "config-command", + GF_SNAP_CONFIG_DISPLAY); + if (ret) { + gf_log ("", GF_LOG_ERROR, "Unable to set config-command"); + ret = -1; + goto out; + } } if (key) { @@ -3264,15 +3275,7 @@ cli_snap_config_parse (const char **words, int wordcount, dict_t *options, } } - if (!value) { - ret = dict_set_int32 (options, "config-command", - GF_SNAP_CONFIG_DISPLAY); - if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to set config-command"); - ret = -1; - goto out; - } - } else { + if (value) { ret = dict_set_int32 (options, "config-command", GF_SNAP_CONFIG_TYPE_SET); if (ret) { @@ -3288,17 +3291,18 @@ cli_snap_config_parse (const char **words, int wordcount, dict_t *options, "Failed to set %s.", key); goto out; } - } - /* Ask question only for a set op */ - if (value && conf_vals && conf_vals->question) { - answer = cli_cmd_get_confirmation (state, - conf_vals->question); - if (GF_ANSWER_NO == answer) { - ret = -1; - goto out; + /* Ask question only for a set op */ + if (conf_vals->question) { + answer = cli_cmd_get_confirmation (state, + conf_vals->question); + if (GF_ANSWER_NO == answer) { + ret = -1; + goto out; + } } } + out: return ret; } @@ -3619,7 +3623,8 @@ cli_cmd_snapshot_parse (const char **words, int wordcount, dict_t **options, } case GF_SNAP_OPTION_TYPE_CONFIG: { - /* snapshot config [snap-max-hard-limit | snap-max-soft-limit ] */ + /* snapshot config [snap-max-hard-limit | + * snap-max-soft-limit ] */ ret = cli_snap_config_parse (words, wordcount, dict, state); if (ret) { diff --git a/cli/src/cli-cmd-snapshot.c b/cli/src/cli-cmd-snapshot.c index 556278931..6d31dc2d5 100644 --- a/cli/src/cli-cmd-snapshot.c +++ b/cli/src/cli-cmd-snapshot.c @@ -90,7 +90,7 @@ struct cli_cmd snapshot_cmds[] = { cli_cmd_snapshot_cbk, "Snapshot List." }, - {"snapshot config < volname | all > [ snap-max-hard-limit | snap-max-soft-limit ]", + {"snapshot config < volname | all > [ snap-max-hard-limit | snap-max-soft-limit ]", cli_cmd_snapshot_cbk, "Snapshot Config." }, diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c index 926c01b70..6ee039fbc 100644 --- a/cli/src/cli-rpc-ops.c +++ b/cli/src/cli-rpc-ops.c @@ -7898,11 +7898,15 @@ out: int cli_snapshot_config_display (dict_t *dict, gf_cli_rsp *rsp) { + char buf[PATH_MAX] = ""; char *volname = NULL; char *key = NULL; int ret = -1; int config_command = 0; uint64_t value = 0; + uint64_t soft_limit = 0; + uint64_t i = 0; + uint64_t voldisplaycount = 0; GF_ASSERT (dict); GF_ASSERT (rsp); @@ -7917,8 +7921,7 @@ cli_snapshot_config_display (dict_t *dict, gf_cli_rsp *rsp) ret = dict_get_int32 (dict, "config-command", &config_command); if (ret) { - gf_log("", GF_LOG_DEBUG, "Could not fetch config type"); - ret = -1; + gf_log("", GF_LOG_ERROR, "Could not fetch config type"); goto out; } @@ -7926,7 +7929,6 @@ cli_snapshot_config_display (dict_t *dict, gf_cli_rsp *rsp) if (ret) { gf_log("", GF_LOG_ERROR, "Could not fetch " "volname"); - ret = -1; goto out; } @@ -7935,8 +7937,11 @@ cli_snapshot_config_display (dict_t *dict, gf_cli_rsp *rsp) } ret = dict_get_str (dict, "config-key", &key); - if (ret) - gf_log("", GF_LOG_ERROR, "No config-key set"); + if (ret && config_command != GF_SNAP_CONFIG_DISPLAY) { + gf_log(THIS->name, GF_LOG_ERROR, + "Could not fetch config-key"); + goto out; + } switch (config_command) { case GF_SNAP_CONFIG_TYPE_SET: @@ -7945,49 +7950,74 @@ cli_snapshot_config_display (dict_t *dict, gf_cli_rsp *rsp) break; case GF_SNAP_CONFIG_DISPLAY : - if (!key) { - /* For all options */ - ret = dict_get_uint64 (dict, "snap-max-hard-limit", - &value); + cli_out ("\nSnapshot System Configuration:"); + ret = dict_get_uint64 (dict, "snap-max-hard-limit", + &value); + if (ret) { + gf_log("", GF_LOG_ERROR, "Could not fetch " + "snap_max_hard_limit for %s", volname); + ret = -1; + goto out; + } + cli_out ("snap-max-hard-limit : %"PRIu64, value); + + ret = dict_get_uint64 (dict, "snap-max-soft-limit", + &soft_limit); + if (ret) { + gf_log("", GF_LOG_ERROR, "Could not fetch " + "snap-max-soft-limit for %s", volname); + ret = -1; + goto out; + } + cli_out ("snap-max-soft-limit : %"PRIu64"%%\n", soft_limit); + + cli_out ("Snapshot Volume Configuration:"); + + ret = dict_get_uint64 (dict, "voldisplaycount", + &voldisplaycount); + if (ret) { + gf_log("", GF_LOG_ERROR, "Could not fetch voldisplaycount"); + ret = -1; + goto out; + } + + for (i = 0; i < voldisplaycount; i++) { + snprintf (buf, sizeof(buf), "volume%ld-volname", i); + ret = dict_get_str (dict, buf, &volname); if (ret) { - gf_log("", GF_LOG_DEBUG, "Could not fetch " - "snap_max_hard_limit for %s", volname); + gf_log("", GF_LOG_ERROR, "Could not fetch " + " %s", buf); ret = -1; goto out; } - cli_out ("snapshot config: snap-max-hard-limit for " - "%s set to %"PRIu64, - volname, value); + cli_out ("\nVolume : %s", volname); - ret = dict_get_uint64 (dict, "snap-max-soft-limit", - &value); + snprintf (buf, sizeof(buf), + "volume%ld-snap-max-hard-limit", i); + ret = dict_get_uint64 (dict, buf, &value); if (ret) { - gf_log("", GF_LOG_DEBUG, "Could not fetch " - "snap-max-soft-limit for %s", volname); + gf_log("", GF_LOG_ERROR, "Could not fetch " + " %s", buf); ret = -1; goto out; } - cli_out ("snapshot config: snap-max-soft-limit for " - "%s set to %"PRIu64, - volname, value); - } else { - if ((!strncmp (key, "snap-max-hard-limit", strlen(key))) || - (!strncmp (key, "snap-max-soft-limit", strlen(key)))) { - ret = dict_get_uint64 (dict, key, &value); - if (ret) { - gf_log("", GF_LOG_DEBUG, "Could not fetch " - "%s for %s", key, volname); - ret = -1; - goto out; - } - cli_out ("snapshot config: %s for " - "%s set to %"PRIu64, key, - volname, value); + cli_out ("snap-max-hard-limit : %"PRIu64, value); + + snprintf (buf, sizeof(buf), + "volume%ld-snap-max-soft-limit-value", i); + ret = dict_get_uint64 (dict, buf, &value); + if (ret) { + gf_log("", GF_LOG_ERROR, "Could not fetch " + " %s", buf); + ret = -1; + goto out; } - } - break; + cli_out ("snap-max-soft-limit : %"PRIu64" (%"PRIu64"%%)", + value, soft_limit); + } + break; default : - break; + break; } ret = 0; -- cgit