diff options
-rw-r--r-- | cli/src/cli-quotad-client.c | 154 | ||||
-rw-r--r-- | cli/src/cli-quotad-client.h | 33 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-quota.c | 88 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-store.c | 8 |
4 files changed, 270 insertions, 13 deletions
diff --git a/cli/src/cli-quotad-client.c b/cli/src/cli-quotad-client.c new file mode 100644 index 00000000..f0efc864 --- /dev/null +++ b/cli/src/cli-quotad-client.c @@ -0,0 +1,154 @@ +/* + Copyright (c) 2010-2013 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ +#ifndef _CONFIG_H +#define _CONFIG_H +#include "config.h" +#endif + + +#include "cli-quotad-client.h" + +extern struct rpc_clnt global_quotad_rpc; +extern struct rpc_clnt_program cli_quotad_clnt; + +int +cli_quotad_submit_request (void *req, call_frame_t *frame, + rpc_clnt_prog_t *prog, + int procnum, struct iobref *iobref, + xlator_t *this, fop_cbk_fn_t cbkfn, + xdrproc_t xdrproc) +{ + int ret = -1; + int count = 0; + struct iovec iov = {0, }; + struct iobuf *iobuf = NULL; + char new_iobref = 0; + ssize_t xdr_size = 0; + + GF_ASSERT (this); + + if (req) { + xdr_size = xdr_sizeof (xdrproc, req); + iobuf = iobuf_get2 (this->ctx->iobuf_pool, xdr_size); + if (!iobuf) { + goto out; + }; + + if (!iobref) { + iobref = iobref_new (); + if (!iobref) { + goto out; + } + + new_iobref = 1; + } + + iobref_add (iobref, iobuf); + + iov.iov_base = iobuf->ptr; + iov.iov_len = iobuf_size (iobuf); + + /* Create the xdr payload */ + ret = xdr_serialize_generic (iov, req, xdrproc); + if (ret == -1) { + goto out; + } + iov.iov_len = ret; + count = 1; + } + + /* Send the msg */ + ret = rpc_clnt_submit (&global_quotad_rpc, prog, procnum, cbkfn, + &iov, count, + NULL, 0, iobref, frame, NULL, 0, NULL, 0, NULL); + ret = 0; + +out: + if (new_iobref) + iobref_unref (iobref); + if (iobuf) + iobuf_unref (iobuf); + + return ret; +} + +int +cli_quotad_notify (struct rpc_clnt *rpc, void *mydata, + rpc_clnt_event_t event, void *data) +{ + xlator_t *this = NULL; + int ret = 0; + + this = mydata; + + switch (event) { + case RPC_CLNT_CONNECT: + { + gf_log (this->name, GF_LOG_TRACE, "got RPC_CLNT_CONNECT"); + break; + } + + case RPC_CLNT_DISCONNECT: + { + gf_log (this->name, GF_LOG_TRACE, "got RPC_CLNT_DISCONNECT"); + break; + } + + default: + gf_log (this->name, GF_LOG_TRACE, + "got some other RPC event %d", event); + ret = 0; + break; + } + + return ret; +} + +struct rpc_clnt * +cli_quotad_clnt_init (xlator_t *this, dict_t *options) +{ + struct rpc_clnt *rpc = NULL; + int ret = -1; + + + ret = dict_set_str (options, "transport.address-family", "unix"); + if (ret) + goto out; + + ret = dict_set_str (options, "transport-type", "socket"); + if (ret) + goto out; + + ret = dict_set_str (options, "transport.socket.connect-path", + "/tmp/quotad.socket"); + if (ret) + goto out; + + rpc = rpc_clnt_new (options, this->ctx, this->name, 16); + if (!rpc) + goto out; + + ret = rpc_clnt_register_notify (rpc, cli_quotad_notify, this); + if (ret) { + gf_log ("cli", GF_LOG_ERROR, "failed to register notify"); + goto out; + } + + rpc_clnt_start (rpc); +out: + if (ret) { + if (rpc) + rpc_clnt_unref (rpc); + rpc = NULL; + } + + return rpc; +} + diff --git a/cli/src/cli-quotad-client.h b/cli/src/cli-quotad-client.h new file mode 100644 index 00000000..aa0b42af --- /dev/null +++ b/cli/src/cli-quotad-client.h @@ -0,0 +1,33 @@ +/* + Copyright (c) 2010-2013 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ +#include "cli.h" +#include "compat-errno.h" +#include "compat.h" +#include "cli-cmd.h" +#include "cli1-xdr.h" +#include "xdr-generic.h" +#include "protocol-common.h" +#include "cli-mem-types.h" + + +int +cli_quotad_submit_request (void *req, call_frame_t *frame, + rpc_clnt_prog_t *prog, + int procnum, struct iobref *iobref, + xlator_t *this, fop_cbk_fn_t cbkfn, + xdrproc_t xdrproc); + +struct rpc_clnt * +cli_quotad_clnt_init (xlator_t *this, dict_t *options); + +int +cli_quotad_notify (struct rpc_clnt *rpc, void *mydata, + rpc_clnt_event_t event, void *data); + diff --git a/xlators/mgmt/glusterd/src/glusterd-quota.c b/xlators/mgmt/glusterd/src/glusterd-quota.c index e4c654b9..c2d37b03 100644 --- a/xlators/mgmt/glusterd/src/glusterd-quota.c +++ b/xlators/mgmt/glusterd/src/glusterd-quota.c @@ -105,8 +105,8 @@ __glusterd_handle_quota (rpcsvc_request_t *req) if ((conf->op_version == GD_OP_VERSION_MIN) && (type > GF_QUOTA_OPTION_TYPE_VERSION)) { snprintf (msg, sizeof (msg), "Cannot execute command. The " - "cluster is operating at version 1. Executing command " - "%s is disallowed in this state", + "cluster is operating at version %d. Quota command %s " + "is unavailable in this version", conf->op_version, gd_quota_op_list[type]); ret = -1; goto out; @@ -1109,8 +1109,8 @@ glusterd_op_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict) if ((priv->op_version == GD_OP_VERSION_MIN) && (type > GF_QUOTA_OPTION_TYPE_VERSION)) { gf_asprintf (op_errstr, "Volume quota failed. The cluster is " - "operating at version %d. Option %s " - "is disallowed in this state.", + "operating at version %d. Quota command" + " %s is unavailable in this version.", priv->op_version, gd_quota_op_list[type]); ret = -1; @@ -1321,14 +1321,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; @@ -1337,6 +1351,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"); @@ -1355,6 +1373,12 @@ glusterd_op_stage_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict) goto out; } + if (!glusterd_is_volume_started (volinfo)) { + *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) { @@ -1363,11 +1387,19 @@ glusterd_op_stage_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict) goto out; } + if ((!glusterd_is_volume_quota_enabled (volinfo)) && + (type != GF_QUOTA_OPTION_TYPE_ENABLE)) { + *op_errstr = gf_strdup ("Quota is disabled, please enable " + "quota"); + ret = -1; + goto out; + } + if ((priv->op_version == GD_OP_VERSION_MIN) && (type > GF_QUOTA_OPTION_TYPE_VERSION)) { gf_asprintf (op_errstr, "Volume quota failed. The cluster is " - "operating at version %d. Option %s " - "is disallowed in this state.", + "operating at version %d. Quota command" + " %s is unavailable in this version.", priv->op_version, gd_quota_op_list[type]); ret = -1; @@ -1385,16 +1417,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); diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c index db0829bb..591aba68 100644 --- a/xlators/mgmt/glusterd/src/glusterd-store.c +++ b/xlators/mgmt/glusterd/src/glusterd-store.c @@ -1906,6 +1906,14 @@ glusterd_store_retrieve_volume (char *volname) break; case 1: + /*The following strcmp check is to ensure that + * glusterd does not restore the quota limits + * into volinfo->dict post upgradation from 3.3 + * to 3.4 as the same limits will now be stored + * in xattrs on the respective directories. + */ + if (!strcmp (key, "features.limit-usage")) + break; ret = dict_set_str(volinfo->dict, key, gf_strdup (value)); if (ret) { |