diff options
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-quota.c')
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-quota.c | 66 |
1 files changed, 38 insertions, 28 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-quota.c b/xlators/mgmt/glusterd/src/glusterd-quota.c index 103f88e7a..318267199 100644 --- a/xlators/mgmt/glusterd/src/glusterd-quota.c +++ b/xlators/mgmt/glusterd/src/glusterd-quota.c @@ -25,7 +25,7 @@ #include <sys/wait.h> int -glusterd_handle_quota (rpcsvc_request_t *req) +__glusterd_handle_quota (rpcsvc_request_t *req) { int32_t ret = -1; gf_cli_req cli_req = {{0,}}; @@ -34,11 +34,15 @@ glusterd_handle_quota (rpcsvc_request_t *req) char operation[256] = {0, }; char *volname = NULL; int32_t type = 0; + char msg[2048] = {0,}; + xlator_t *this = NULL; GF_ASSERT (req); + this = THIS; + GF_ASSERT (this); - if (!xdr_to_generic (req->msg[0], &cli_req, - (xdrproc_t)xdr_gf_cli_req)) { + ret = xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req); + if (ret < 0) { //failed to decode msg; req->rpc_err = GARBAGE_ARGS; goto out; @@ -52,8 +56,10 @@ glusterd_handle_quota (rpcsvc_request_t *req) cli_req.dict.dict_len, &dict); if (ret < 0) { - gf_log ("glusterd", GF_LOG_ERROR, "failed to " + gf_log (this->name, GF_LOG_ERROR, "failed to " "unserialize req-buffer to dictionary"); + snprintf (msg, sizeof (msg), "Unable to decode the " + "command"); goto out; } else { dict->extra_stdfree = cli_req.dict.dict_val; @@ -62,16 +68,18 @@ glusterd_handle_quota (rpcsvc_request_t *req) ret = dict_get_str (dict, "volname", &volname); if (ret) { - gf_log ("", GF_LOG_WARNING, "Unable to get volume name, while" - "handling quota command"); + snprintf (msg, sizeof (msg), "Unable to get volume name"); + gf_log (this->name, GF_LOG_ERROR, "Unable to get volume name, " + "while handling quota command"); goto out; } ret = dict_get_int32 (dict, "type", &type); if (ret) { - gf_log ("", GF_LOG_WARNING, "Unable to get type of cmd. , while" - "handling quota command"); - goto out; + snprintf (msg, sizeof (msg), "Unable to get type of command"); + gf_log (this->name, GF_LOG_ERROR, "Unable to get type of cmd, " + "while handling quota command"); + goto out; } switch (type) { @@ -91,22 +99,25 @@ glusterd_handle_quota (rpcsvc_request_t *req) strncpy (operation, "remove", sizeof (operation)); break; } - ret = glusterd_op_begin (req, GD_OP_QUOTA, dict); + ret = glusterd_op_begin_synctask (req, GD_OP_QUOTA, dict); out: - glusterd_friend_sm (); - glusterd_op_sm (); - if (ret) { + if (msg[0] == '\0') + snprintf (msg, sizeof (msg), "Operation failed"); ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, - dict, "operation failed"); - if (dict) - dict_unref (dict); + dict, msg); } return ret; } +int +glusterd_handle_quota (rpcsvc_request_t *req) +{ + return glusterd_big_locked_handler (req, __glusterd_handle_quota); +} + int32_t glusterd_check_if_quota_trans_enabled (glusterd_volinfo_t *volinfo) { @@ -252,7 +263,9 @@ glusterd_quota_initiate_fs_crawl (glusterd_conf_t *priv, char *volname) "-l", DEFAULT_LOG_FILE_DIRECTORY"/quota-crawl.log", mountdir, NULL); + synclock_unlock (&priv->big_lock); ret = runner_run_reuse (&runner); + synclock_lock (&priv->big_lock); if (ret == -1) { runner_log (&runner, "glusterd", GF_LOG_DEBUG, "command failed"); runner_end (&runner); @@ -371,18 +384,17 @@ glusterd_quota_get_limit_usages (glusterd_conf_t *priv, glusterd_volinfo_t *volinfo, char *volname, dict_t *dict, - char **op_errstr) + char **op_errstr, + dict_t *rsp_dict) { int32_t i = 0; int32_t ret = 0; int32_t count = 0; char *path = NULL; - dict_t *ctx = NULL; char cmd_str [1024] = {0, }; char *ret_str = NULL; - ctx = glusterd_op_get_ctx (); - if (ctx == NULL) + if (rsp_dict == NULL) return 0; ret = dict_get_int32 (dict, "count", &count); @@ -406,7 +418,7 @@ glusterd_quota_get_limit_usages (glusterd_conf_t *priv, } if (ret_str) { - ret = dict_set_dynstr (ctx, "limit_list", ret_str); + ret = dict_set_dynstr (rsp_dict, "limit_list", ret_str); } out: return ret; @@ -661,12 +673,11 @@ out: int -glusterd_op_quota (dict_t *dict, char **op_errstr) +glusterd_op_quota (dict_t *dict, char **op_errstr, dict_t *rsp_dict) { glusterd_volinfo_t *volinfo = NULL; int32_t ret = -1; char *volname = NULL; - dict_t *ctx = NULL; int type = -1; gf_boolean_t start_crawl = _gf_false; glusterd_conf_t *priv = NULL; @@ -731,7 +742,7 @@ glusterd_op_quota (dict_t *dict, char **op_errstr) } ret = glusterd_quota_get_limit_usages (priv, volinfo, volname, - dict, op_errstr); + dict, op_errstr, rsp_dict); goto out; } @@ -754,12 +765,11 @@ create_vol: ret = 0; out: - ctx = glusterd_op_get_ctx (); - if (ctx && start_crawl == _gf_true) + if (rsp_dict && start_crawl == _gf_true) glusterd_quota_initiate_fs_crawl (priv, volname); - if (ctx && *op_errstr) { - ret = dict_set_dynstr (ctx, "errstr", *op_errstr); + if (rsp_dict && *op_errstr) { + ret = dict_set_dynstr (rsp_dict, "errstr", *op_errstr); if (ret) { GF_FREE (*op_errstr); gf_log ("", GF_LOG_DEBUG, |
