diff options
author | shishir gowda <shishirng@gluster.com> | 2011-11-02 18:38:50 +0530 |
---|---|---|
committer | Vijay Bellur <vijay@gluster.com> | 2011-11-16 01:42:29 -0800 |
commit | 7a97478dd1a343fcc5d9d4eab963882191a3de69 (patch) | |
tree | 54f48eacb357561a9ebc5f5089e666e0979c7d55 /xlators/mgmt/glusterd/src/glusterd-log-ops.c | |
parent | 913b21621e2dad9146366f24048ff07a8046e5c5 (diff) |
XDR: cli-glusterd xdr consolidation
By using only 1 xdr struct for request and 1 xdr struct for response,
we will be able scale better and also be able to parse the o/p better
For request use-
gf1_cli_req - contains dict
For response use-
gf1_cli_rsp - conains op_ret, op_errno, op_errstr, dict
Change-Id: I94b034e1d8fa82dfd0cf96e7602d4039bc43fef3
BUG: 3720
Reviewed-on: http://review.gluster.com/662
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Amar Tumballi <amar@gluster.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-log-ops.c')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-log-ops.c | 127 |
1 files changed, 85 insertions, 42 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-log-ops.c b/xlators/mgmt/glusterd/src/glusterd-log-ops.c index 9d1c9782671..b032e902d8b 100644 --- a/xlators/mgmt/glusterd/src/glusterd-log-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-log-ops.c @@ -37,36 +37,44 @@ int glusterd_handle_log_filename (rpcsvc_request_t *req) { int32_t ret = -1; - gf1_cli_log_filename_req cli_req = {0,}; + gf_cli_req cli_req = {{0,}}; dict_t *dict = NULL; glusterd_op_t cli_op = GD_OP_LOG_FILENAME; + char *volname = NULL; GF_ASSERT (req); if (!xdr_to_generic (req->msg[0], &cli_req, - (xdrproc_t)xdr_gf1_cli_log_filename_req)) { + (xdrproc_t)xdr_gf_cli_req)) { //failed to decode msg; req->rpc_err = GARBAGE_ARGS; goto out; } - gf_log ("glusterd", GF_LOG_INFO, "Received log filename req " - "for volume %s", cli_req.volname); - dict = dict_new (); - if (!dict) - goto out; + if (cli_req.dict.dict_len) { + /* Unserialize the dictionary */ + dict = dict_new (); - ret = dict_set_dynmstr (dict, "volname", cli_req.volname); - if (ret) - goto out; - ret = dict_set_dynmstr (dict, "brick", cli_req.brick); - if (ret) - goto out; - ret = dict_set_dynmstr (dict, "path", cli_req.path); - if (ret) + ret = dict_unserialize (cli_req.dict.dict_val, + cli_req.dict.dict_len, + &dict); + if (ret < 0) { + gf_log ("glusterd", GF_LOG_ERROR, + "failed to " + "unserialize req-buffer to dictionary"); + goto out; + } + } + + ret = dict_get_str (dict, "volname", &volname); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, "failed to get volname"); goto out; + } + gf_log ("glusterd", GF_LOG_INFO, "Received log filename req " + "for volume %s", volname); ret = glusterd_op_begin (req, GD_OP_LOG_FILENAME, dict); out: @@ -79,7 +87,8 @@ out: if (ret) ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, NULL, "operation failed"); - + if (cli_req.dict.dict_val) + free (cli_req.dict.dict_val); return ret; } @@ -190,38 +199,57 @@ glusterd_handle_log_level (rpcsvc_request_t *req) { int32_t ret = -1; dict_t *dict = NULL; - gf1_cli_log_level_req cli_req = {0,}; - glusterd_op_t cli_op = GD_OP_LOG_LEVEL; + gf_cli_req cli_req = {{0,}}; + glusterd_op_t cli_op = GD_OP_LOG_LEVEL; + char *loglevel = NULL; + char *xlator = NULL; + char *volname = NULL; GF_ASSERT(req); if (!xdr_to_generic (req->msg[0], &cli_req, - (xdrproc_t)xdr_gf1_cli_log_level_req)) { + (xdrproc_t)xdr_gf_cli_req)) { gf_log ("glusterd", GF_LOG_ERROR, "Failed to decode rpc message"); req->rpc_err = GARBAGE_ARGS; goto out; } - gf_log ("glusterd", GF_LOG_DEBUG, "Got log level request for: Volume [%s]" - " Xlator [%s] LogLevel [\"%s\"]", cli_req.volname, cli_req.xlator, cli_req.loglevel); + if (cli_req.dict.dict_len) { + /* Unserialize the dictionary */ + dict = dict_new (); - dict = dict_new (); - if (!dict) - goto out; + ret = dict_unserialize (cli_req.dict.dict_val, + cli_req.dict.dict_len, + &dict); + if (ret < 0) { + gf_log ("glusterd", GF_LOG_ERROR, + "failed to " + "unserialize req-buffer to dictionary"); + goto out; + } + } - ret = dict_set_dynmstr (dict, "volname", cli_req.volname); - if (ret) + ret = dict_get_str (dict, "volname", &volname); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, "failed to get volname"); goto out; + } - ret = dict_set_dynmstr (dict, "xlator", cli_req.xlator); - if (ret) + ret = dict_get_str (dict, "xlator", &xlator); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, "failed to get xlator"); goto out; + } - ret = dict_set_dynmstr (dict, "loglevel", cli_req.loglevel); - if (ret) + ret = dict_get_str (dict, "loglevel", &loglevel); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, "failed to get loglevel"); goto out; + } + gf_log ("glusterd", GF_LOG_DEBUG, "Got log level request for: Volume [%s]" + " Xlator [%s] LogLevel [\"%s\"]", volname, xlator, loglevel); ret = glusterd_op_begin (req, cli_op, dict); out: @@ -235,6 +263,9 @@ glusterd_handle_log_level (rpcsvc_request_t *req) ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, NULL, "Operation failed"); + if (cli_req.dict.dict_val) + free (cli_req.dict.dict_val); + return ret; } @@ -242,33 +273,43 @@ int glusterd_handle_log_rotate (rpcsvc_request_t *req) { int32_t ret = -1; - gf1_cli_log_rotate_req cli_req = {0,}; + gf_cli_req cli_req = {{0,}}; dict_t *dict = NULL; glusterd_op_t cli_op = GD_OP_LOG_ROTATE; + char *volname = NULL; GF_ASSERT (req); if (!xdr_to_generic (req->msg[0], &cli_req, - (xdrproc_t)xdr_gf1_cli_log_rotate_req)) { + (xdrproc_t)xdr_gf_cli_req)) { //failed to decode msg; req->rpc_err = GARBAGE_ARGS; goto out; } - gf_log ("glusterd", GF_LOG_INFO, "Received log rotate req " - "for volume %s", cli_req.volname); + if (cli_req.dict.dict_len) { + /* Unserialize the dictionary */ + dict = dict_new (); - dict = dict_new (); - if (!dict) - goto out; + ret = dict_unserialize (cli_req.dict.dict_val, + cli_req.dict.dict_len, + &dict); + if (ret < 0) { + gf_log ("glusterd", GF_LOG_ERROR, + "failed to " + "unserialize req-buffer to dictionary"); + goto out; + } + } - ret = dict_set_dynmstr (dict, "volname", cli_req.volname); - if (ret) + ret = dict_get_str (dict, "volname", &volname); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, "failed to get volname"); goto out; + } - ret = dict_set_dynmstr (dict, "brick", cli_req.brick); - if (ret) - goto out; + gf_log ("glusterd", GF_LOG_INFO, "Received log rotate req " + "for volume %s", volname); ret = dict_set_uint64 (dict, "rotate-key", (uint64_t)time (NULL)); if (ret) @@ -287,6 +328,8 @@ out: ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, NULL, "operation failed"); + if (cli_req.dict.dict_val) + free (cli_req.dict.dict_val); return ret; } |