diff options
author | Krishnan Parthasarathi <kparthas@redhat.com> | 2013-09-16 04:11:25 -0700 |
---|---|---|
committer | Gerrit Code Review <review@dev.gluster.org> | 2013-09-16 04:11:25 -0700 |
commit | 872788c8a4d86db26d9097d21dc9384472fcfc3a (patch) | |
tree | 12fa8b2955ae7aed3f22137d9b61337f94a9452c /xlators/mgmt | |
parent | 696f44a4dcce9f83aac75d90ea2b7986e36c8f1c (diff) | |
parent | 6fe49d28c59f3618f935c928e90a59750d383c1e (diff) |
Merge "glusterd: Validate timeout options during volume quota stage op" into upstream_on_quota
Diffstat (limited to 'xlators/mgmt')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-quota.c | 75 |
1 files changed, 68 insertions, 7 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-quota.c b/xlators/mgmt/glusterd/src/glusterd-quota.c index 3bcf54b5..aeaa51d9 100644 --- a/xlators/mgmt/glusterd/src/glusterd-quota.c +++ b/xlators/mgmt/glusterd/src/glusterd-quota.c @@ -1300,14 +1300,28 @@ int glusterd_op_stage_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict) { int ret = 0; + int type = 0; + int i = 0; char *volname = NULL; + char *value = NULL; gf_boolean_t exists = _gf_false; - int type = 0; dict_t *ctx = NULL; + dict_t *tmp_dict = NULL; xlator_t *this = NULL; glusterd_conf_t *priv = NULL; glusterd_volinfo_t *volinfo = NULL; + struct { + int opcode; + char *key; + } optable[] = { + {GF_QUOTA_OPTION_TYPE_ALERT_TIME, + "features.alert-time"}, + {GF_QUOTA_OPTION_TYPE_SOFT_TIMEOUT, "features.soft-timeout"}, + {GF_QUOTA_OPTION_TYPE_HARD_TIMEOUT, "features.hard-timeout"}, + {GF_QUOTA_OPTION_TYPE_NONE, NULL} + }; + this = THIS; GF_ASSERT (this); priv = this->private; @@ -1316,6 +1330,10 @@ glusterd_op_stage_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict) GF_ASSERT (dict); GF_ASSERT (op_errstr); + tmp_dict = dict_new (); + if (!tmp_dict) + goto out; + ret = dict_get_str (dict, "volname", &volname); if (ret) { gf_log (this->name, GF_LOG_ERROR, "Unable to get volume name"); @@ -1334,6 +1352,12 @@ glusterd_op_stage_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict) goto out; } + if (glusterd_is_volume_started (volinfo) == 0) { + *op_errstr = gf_strdup ("Volume is stopped, start volume " + "before executing quota command."); + ret = -1; + goto out; + } ret = dict_get_int32 (dict, "type", &type); if (ret) { @@ -1342,6 +1366,13 @@ glusterd_op_stage_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict) goto out; } + ret = glusterd_check_if_quota_trans_enabled (volinfo); + if ((ret == -1) && (type != GF_QUOTA_OPTION_TYPE_ENABLE)) { + *op_errstr = gf_strdup ("Quota is disabled, please enable " + "quota"); + goto out; + } + ctx = glusterd_op_get_ctx(); if (ctx && (type == GF_QUOTA_OPTION_TYPE_ENABLE || type == GF_QUOTA_OPTION_TYPE_LIST)) { @@ -1353,16 +1384,46 @@ glusterd_op_stage_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict) } } - if (type == GF_QUOTA_OPTION_TYPE_LIMIT_USAGE || - type == GF_QUOTA_OPTION_TYPE_REMOVE) { - ret = glusterd_get_gfid_from_brick (dict, volinfo, rsp_dict, - op_errstr); - if (ret) - goto out; + switch (type) { + case GF_QUOTA_OPTION_TYPE_LIMIT_USAGE: + case GF_QUOTA_OPTION_TYPE_REMOVE: + ret = glusterd_get_gfid_from_brick (dict, volinfo, + rsp_dict, + op_errstr); + if (ret) + goto out; + break; + + case GF_QUOTA_OPTION_TYPE_ALERT_TIME: + case GF_QUOTA_OPTION_TYPE_SOFT_TIMEOUT: + case GF_QUOTA_OPTION_TYPE_HARD_TIMEOUT: + ret = dict_get_str (dict, "value", &value); + if (ret) + goto out; + + for (i = 0; optable[i].key; i++) { + if (type == optable[i].opcode) + break; + } + ret = dict_set_str (tmp_dict, optable[i].key, value); + if (ret) + goto out; + + ret = glusterd_validate_reconfopts (volinfo, tmp_dict, + op_errstr); + if (ret) + goto out; + break; + + default: + ret = 0; } + ret = 0; out: + if (tmp_dict) + dict_unref (tmp_dict); if (ret && op_errstr && *op_errstr) gf_log (this->name, GF_LOG_ERROR, "%s", *op_errstr); gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret); |