From e45c3e22a13332253fcc89ea528a4d77aa9ecc0f Mon Sep 17 00:00:00 2001 From: Junaid Date: Mon, 6 Jun 2011 22:36:43 +0000 Subject: mgmt/glusterd: Updated the error messages sent on cli quota command failure. Signed-off-by: Junaid Signed-off-by: Anand Avati BUG: 2856 ([glusterfs-3.2]: Misleading 'quota remove' output.) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2856 --- xlators/mgmt/glusterd/src/glusterd-op-sm.c | 54 +++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c index 3354e78e7..d43454510 100644 --- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c +++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c @@ -4735,8 +4735,13 @@ out: return ret; } +/* At the end of the function, the variable found will be set + * to true if the path to be removed was present in the limit-list, + * else will be false. + */ int32_t -_glusterd_quota_remove_limits (char **quota_limits, char *path) +_glusterd_quota_remove_limits (char **quota_limits, char *path, + gf_boolean_t *found) { int ret = 0; int i = 0; @@ -4748,6 +4753,9 @@ _glusterd_quota_remove_limits (char **quota_limits, char *path) char *limits = NULL; char *qlimits = NULL; + if (found != NULL) + *found = _gf_false; + if (*quota_limits == NULL) return -1; @@ -4758,14 +4766,16 @@ _glusterd_quota_remove_limits (char **quota_limits, char *path) len = strlen (qlimits); limits = GF_CALLOC (len + 1, sizeof (char), gf_gld_mt_char); - if (!limits) return -1; while (i < len) { if (!memcmp ((void *) &qlimits [i], (void *)path, pathlen)) - if (qlimits [i + pathlen] == ':') + if (qlimits [i + pathlen] == ':') { flag = 1; + if (found != NULL) + *found = _gf_true; + } while (qlimits [i + size] != ',' && qlimits [i + size] != '\0') @@ -4951,7 +4961,7 @@ _glusterd_quota_get_limit_usages (glusterd_volinfo_t *volinfo, return NULL; if (quota_limits == NULL) { ret_str = NULL; - *op_errstr = gf_strdup ("Limits not set any directory"); + *op_errstr = gf_strdup ("Limit not set on any directory"); } else if (path == NULL) ret_str = gf_strdup (quota_limits); else @@ -4984,7 +4994,8 @@ glusterd_quota_get_limit_usages (glusterd_conf_t *priv, goto out; if (count == 0) { - ret_str = _glusterd_quota_get_limit_usages (volinfo, NULL, op_errstr); + ret_str = _glusterd_quota_get_limit_usages (volinfo, NULL, + op_errstr); } else { i = 0; while (count--) { @@ -5134,7 +5145,7 @@ glusterd_quota_limit_usage (glusterd_volinfo_t *volinfo, dict_t *dict, char **op } if (quota_limits) { - ret = _glusterd_quota_remove_limits ("a_limits, path); + ret = _glusterd_quota_remove_limits ("a_limits, path, NULL); if (ret == -1) { gf_log ("", GF_LOG_ERROR, "Unable to allocate memory"); *op_errstr = gf_strdup ("failed to set limit"); @@ -5181,18 +5192,21 @@ out: int32_t glusterd_quota_remove_limits (glusterd_volinfo_t *volinfo, dict_t *dict, char **op_errstr) { - int32_t ret = -1; + int32_t ret = -1; char str [PATH_MAX + 1024] = {0,}; - char *quota_limits = NULL; - char *path = NULL; + char *quota_limits = NULL; + char *path = NULL; + gf_boolean_t flag = _gf_false; GF_VALIDATE_OR_GOTO ("glusterd", dict, out); GF_VALIDATE_OR_GOTO ("glusterd", volinfo, out); GF_VALIDATE_OR_GOTO ("glusterd", op_errstr, out); ret = glusterd_check_if_quota_trans_enabled (volinfo); - if (ret == -1) + if (ret == -1) { + *op_errstr = gf_strdup ("Quota is disabled, please enable quota"); goto out; + } ret = glusterd_volinfo_get (volinfo, VKEY_FEATURES_LIMIT_USAGE, "a_limits); @@ -5207,13 +5221,22 @@ glusterd_quota_remove_limits (glusterd_volinfo_t *volinfo, dict_t *dict, char ** goto out; } - ret = _glusterd_quota_remove_limits ("a_limits, path); + ret = _glusterd_quota_remove_limits ("a_limits, path, &flag); if (ret == -1) { - snprintf (str, sizeof (str), "Removing limit on %s has been unsuccessful", path); + if (flag == _gf_true) + snprintf (str, sizeof (str), "Removing limit on %s has " + "been unsuccessful", path); + else + snprintf (str, sizeof (str), "%s has no limit set", path); *op_errstr = gf_strdup (str); goto out; } else { - snprintf (str, sizeof (str), "Removed quota limit on %s", path); + if (flag == _gf_true) + snprintf (str, sizeof (str), "Removed quota limit on " + "%s", path); + else + snprintf (str, sizeof (str), "no limit set on %s", + path); *op_errstr = gf_strdup (str); } @@ -5301,11 +5324,12 @@ glusterd_op_quota (dict_t *dict, char **op_errstr) ret = glusterd_check_if_quota_trans_enabled (volinfo); if (ret == -1) { *op_errstr = gf_strdup ("cannot list the limits, " - "quota feature is disabled"); + "quota is disabled"); goto out; } - glusterd_quota_get_limit_usages (priv, volinfo, volname, dict, op_errstr); + ret = glusterd_quota_get_limit_usages (priv, volinfo, volname, + dict, op_errstr); goto out; } -- cgit