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 | |
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')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-brick-ops.c | 66 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-geo-rep.c | 4 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-handler.c | 228 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-log-ops.c | 127 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-quota.c | 6 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-rebalance.c | 195 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-replace-brick.c | 27 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-rpc-ops.c | 443 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volume-ops.c | 270 |
9 files changed, 645 insertions, 721 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c index 76bbe6c9f19..6385ac6786f 100644 --- a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c @@ -297,7 +297,7 @@ int glusterd_handle_add_brick (rpcsvc_request_t *req) { int32_t ret = -1; - gf1_cli_add_brick_req cli_req = {0,}; + gf_cli_req cli_req = {{0,}}; dict_t *dict = NULL; glusterd_brickinfo_t *brickinfo = NULL; char *brick = NULL; @@ -309,7 +309,7 @@ glusterd_handle_add_brick (rpcsvc_request_t *req) char *brick_list = NULL; void *cli_rsp = NULL; char err_str[2048] = {0,}; - gf1_cli_add_brick_rsp rsp = {0,}; + gf_cli_rsp rsp = {0,}; glusterd_volinfo_t *volinfo = NULL; xlator_t *this = NULL; char *free_ptr = NULL; @@ -329,23 +329,21 @@ glusterd_handle_add_brick (rpcsvc_request_t *req) INIT_LIST_HEAD (&tmpvolinfo.bricks); if (!xdr_to_generic (req->msg[0], &cli_req, - (xdrproc_t)xdr_gf1_cli_add_brick_req)) { + (xdrproc_t)xdr_gf_cli_req)) { //failed to decode msg; req->rpc_err = GARBAGE_ARGS; snprintf (err_str, sizeof (err_str), "Garbage args received"); goto out; } - gf_cmd_log ("Volume add-brick", "on volname: %s attempted", - cli_req.volname); gf_log ("glusterd", GF_LOG_INFO, "Received add brick req"); - if (cli_req.bricks.bricks_len) { + if (cli_req.dict.dict_len) { /* Unserialize the dictionary */ dict = dict_new (); - ret = dict_unserialize (cli_req.bricks.bricks_val, - cli_req.bricks.bricks_len, + ret = dict_unserialize (cli_req.dict.dict_val, + cli_req.dict.dict_len, &dict); if (ret < 0) { gf_log ("glusterd", GF_LOG_ERROR, @@ -354,13 +352,13 @@ glusterd_handle_add_brick (rpcsvc_request_t *req) snprintf (err_str, sizeof (err_str), "Unable to decode " "the buffer"); goto out; - } else { - dict->extra_stdfree = cli_req.bricks.bricks_val; } } ret = dict_get_str (dict, "volname", &volname); + gf_cmd_log ("Volume add-brick", "on volname: %s attempted", + volname); if (ret) { gf_log ("", GF_LOG_ERROR, "Unable to get volume name"); snprintf (err_str, sizeof (err_str), "Unable to get volume " @@ -562,13 +560,12 @@ out: dict_unref (dict); rsp.op_ret = -1; rsp.op_errno = 0; - rsp.volname = ""; if (err_str[0] == '\0') snprintf (err_str, sizeof (err_str), "Operation failed"); rsp.op_errstr = err_str; cli_rsp = &rsp; glusterd_submit_reply(req, cli_rsp, NULL, 0, NULL, - (xdrproc_t)xdr_gf1_cli_add_brick_rsp); + (xdrproc_t)xdr_gf_cli_rsp); ret = 0; //sent error to cli, prevent second reply } @@ -580,8 +577,8 @@ out: glusterd_volume_brickinfos_delete (&tmpvolinfo); if (brickinfo) glusterd_brickinfo_delete (brickinfo); - if (cli_req.volname) - free (cli_req.volname); //its malloced by xdr + if (cli_req.dict.dict_val) + free (cli_req.dict.dict_val); //its malloced by xdr return ret; } @@ -591,7 +588,7 @@ int glusterd_handle_remove_brick (rpcsvc_request_t *req) { int32_t ret = -1; - gf1_cli_remove_brick_req cli_req = {0,}; + gf_cli_req cli_req = {{0,}}; dict_t *dict = NULL; int32_t count = 0; char *brick = NULL; @@ -606,7 +603,7 @@ glusterd_handle_remove_brick (rpcsvc_request_t *req) int32_t sub_volume_end = 0; glusterd_brickinfo_t *tmp = NULL; char err_str[2048] = {0}; - gf1_cli_remove_brick_rsp rsp = {0,}; + gf_cli_rsp rsp = {0,}; void *cli_rsp = NULL; char vol_type[256] = {0,}; int32_t replica_count = 0; @@ -614,46 +611,52 @@ glusterd_handle_remove_brick (rpcsvc_request_t *req) int32_t tmp_brick_idx = 0; int found = 0; int diff_count = 0; + char *volname = 0; GF_ASSERT (req); if (!xdr_to_generic (req->msg[0], &cli_req, - (xdrproc_t)xdr_gf1_cli_remove_brick_req)) { + (xdrproc_t)xdr_gf_cli_req)) { //failed to decode msg; req->rpc_err = GARBAGE_ARGS; goto out; } - gf_cmd_log ("Volume remove-brick","on volname: %s attempted",cli_req.volname); + gf_log ("glusterd", GF_LOG_INFO, "Received rem brick req"); - if (cli_req.bricks.bricks_len) { + if (cli_req.dict.dict_len) { /* Unserialize the dictionary */ dict = dict_new (); - ret = dict_unserialize (cli_req.bricks.bricks_val, - cli_req.bricks.bricks_len, + 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; - } else { - dict->extra_stdfree = cli_req.bricks.bricks_val; } } + ret = dict_get_str (dict, "volname", &volname); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, "Unable to get volname"); + goto out; + } + + gf_cmd_log ("Volume remove-brick","on volname: %s attempted", volname); ret = dict_get_int32 (dict, "count", &count); if (ret) { gf_log ("", GF_LOG_ERROR, "Unable to get count"); goto out; } - ret = glusterd_volinfo_find (cli_req.volname, &volinfo); + ret = glusterd_volinfo_find (volname, &volinfo); if (ret) { snprintf (err_str, 2048, "Volume %s does not exist", - cli_req.volname); + volname); gf_log ("", GF_LOG_ERROR, "%s", err_str); goto out; } @@ -739,7 +742,7 @@ glusterd_handle_remove_brick (rpcsvc_request_t *req) GF_PATH_COMPLETE); if (ret) { snprintf(err_str, 2048,"Incorrect brick %s for volume" - " %s", brick, cli_req.volname); + " %s", brick, volname); gf_log ("", GF_LOG_ERROR, "%s", err_str); goto out; } @@ -821,10 +824,10 @@ glusterd_handle_remove_brick (rpcsvc_request_t *req) } } gf_cmd_log ("Volume remove-brick","volname: %s count:%d bricks:%s", - cli_req.volname, count, brick_list); + volname, count, brick_list); ret = glusterd_op_begin (req, GD_OP_REMOVE_BRICK, dict); - gf_cmd_log ("Volume remove-brick","on volname: %s %s",cli_req.volname, + gf_cmd_log ("Volume remove-brick","on volname: %s %s", volname, (ret) ? "FAILED" : "SUCCESS"); out: @@ -833,22 +836,21 @@ out: dict_unref (dict); rsp.op_ret = -1; rsp.op_errno = 0; - rsp.volname = ""; if (err_str[0] == '\0') snprintf (err_str, sizeof (err_str), "Operation failed"); gf_log ("", GF_LOG_ERROR, "%s", err_str); rsp.op_errstr = err_str; cli_rsp = &rsp; glusterd_submit_reply(req, cli_rsp, NULL, 0, NULL, - (xdrproc_t)xdr_gf1_cli_remove_brick_rsp); + (xdrproc_t)xdr_gf_cli_rsp); ret = 0; //sent error to cli, prevent second reply } if (brick_list) GF_FREE (brick_list); - if (cli_req.volname) - free (cli_req.volname); //its malloced by xdr + if (cli_req.dict.dict_val) + free (cli_req.dict.dict_val); //its malloced by xdr glusterd_friend_sm (); glusterd_op_sm (); diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c index f6ea5aeae3d..3f56636cdf0 100644 --- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c +++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c @@ -47,7 +47,7 @@ glusterd_handle_gsync_set (rpcsvc_request_t *req) { int32_t ret = 0; dict_t *dict = NULL; - gf1_cli_gsync_set_req cli_req = {{0},}; + gf_cli_req cli_req = {{0},}; glusterd_op_t cli_op = GD_OP_GSYNC_SET; char *master = NULL; char *slave = NULL; @@ -63,7 +63,7 @@ glusterd_handle_gsync_set (rpcsvc_request_t *req) priv = THIS->private; if (!xdr_to_generic (req->msg[0], &cli_req, - (xdrproc_t)xdr_gf1_cli_gsync_set_req)) { + (xdrproc_t)xdr_gf_cli_req)) { req->rpc_err = GARBAGE_ARGS; goto out; } diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index ff00824642e..04d3525ae39 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -817,12 +817,13 @@ int glusterd_handle_cli_get_volume (rpcsvc_request_t *req) { int32_t ret = -1; - gf1_cli_get_vol_req cli_req = {0,}; + gf_cli_req cli_req = {{0,}}; dict_t *dict = NULL; + int32_t flags = 0; GF_ASSERT (req); - if (!xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf1_cli_get_vol_req)) { + if (!xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req)) { //failed to decode msg; req->rpc_err = GARBAGE_ARGS; goto out; @@ -847,7 +848,13 @@ glusterd_handle_cli_get_volume (rpcsvc_request_t *req) } } - ret = glusterd_get_volumes (req, dict, cli_req.flags); + ret = dict_get_int32 (dict, "flags", &flags); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, "failed to get flags"); + goto out; + } + + ret = glusterd_get_volumes (req, dict, flags); out: if (dict) @@ -875,13 +882,14 @@ int glusterd_handle_reset_volume (rpcsvc_request_t *req) { int32_t ret = -1; - gf1_cli_reset_vol_req cli_req = {0,}; + gf_cli_req cli_req = {{0,}}; dict_t *dict = NULL; glusterd_op_t cli_op = GD_OP_RESET_VOLUME; + char *volname = NULL; GF_ASSERT (req); - if (!xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf1_cli_set_vol_req)) { + if (!xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req)) { //failed to decode msg; req->rpc_err = GARBAGE_ARGS; goto out; @@ -903,15 +911,18 @@ glusterd_handle_reset_volume (rpcsvc_request_t *req) } } - gf_cmd_log ("Volume reset", "volume : %s", cli_req.volname); + ret = dict_get_str (dict, "volname", &volname); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, "failed to get volname"); + goto out; + } + + gf_cmd_log ("Volume reset", "volume : %s", volname); ret = glusterd_op_begin (req, GD_OP_RESET_VOLUME, dict); - gf_cmd_log ("Volume reset", " on volume %s %s ", cli_req.volname, + gf_cmd_log ("Volume reset", " on volume %s %s ", volname, ((ret == 0)? " SUCCEDED":" FAILED")); out: - if (cli_req.volname) - free (cli_req.volname);//malloced by xdr - glusterd_friend_sm (); glusterd_op_sm (); if (ret) { @@ -929,7 +940,7 @@ int glusterd_handle_set_volume (rpcsvc_request_t *req) { int32_t ret = -1; - gf1_cli_set_vol_req cli_req = {0,}; + gf_cli_req cli_req = {{0,}}; dict_t *dict = NULL; glusterd_op_t cli_op = GD_OP_SET_VOLUME; char *key = NULL; @@ -938,7 +949,7 @@ glusterd_handle_set_volume (rpcsvc_request_t *req) GF_ASSERT (req); - if (!xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf1_cli_set_vol_req)) { + if (!xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf_cli_req)) { //failed to decode msg; req->rpc_err = GARBAGE_ARGS; goto out; @@ -993,8 +1004,6 @@ glusterd_handle_set_volume (rpcsvc_request_t *req) gf_cmd_log ("volume set", "volume-name:%s: key:%s, value:%s %s", volname, key, value, (ret == 0)? "SUCCEDED" : "FAILED" ); out: - if (cli_req.volname) - free (cli_req.volname);//malloced by xdr glusterd_friend_sm (); glusterd_op_sm (); @@ -1012,73 +1021,83 @@ int glusterd_handle_sync_volume (rpcsvc_request_t *req) { int32_t ret = -1; - gf1_cli_sync_volume_req cli_req = {0,}; + gf_cli_req cli_req = {{0,}}; dict_t *dict = NULL; - gf1_cli_sync_volume_rsp cli_rsp = {0.}; + gf_cli_rsp cli_rsp = {0.}; char msg[2048] = {0,}; - gf_boolean_t free_hostname = _gf_true; - gf_boolean_t free_volname = _gf_true; glusterd_volinfo_t *volinfo = NULL; + char *volname = NULL; + gf1_cli_sync_volume flags = 0; + char *hostname = NULL; GF_ASSERT (req); - if (!xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf1_cli_sync_volume_req)) { + if (!xdr_to_generic (req->msg[0], &cli_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 volume sync req " - "for volume %s", - (cli_req.flags & GF_CLI_SYNC_ALL) ? "all" : cli_req.volname); - dict = dict_new (); - if (!dict) { - gf_log ("", GF_LOG_ERROR, "Can't allocate sync vol dict"); - goto out; - } + if (cli_req.dict.dict_len) { + /* Unserialize the dictionary */ + dict = dict_new (); - if (!glusterd_is_local_addr (cli_req.hostname)) { - ret = -1; - snprintf (msg, sizeof (msg), "sync from localhost" - " not allowed"); - 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; + } else { + dict->extra_stdfree = cli_req.dict.dict_val; + } } - ret = dict_set_dynmstr (dict, "hostname", cli_req.hostname); + ret = dict_get_str (dict, "hostname", &hostname); if (ret) { - gf_log ("", GF_LOG_ERROR, "hostname set failed"); - snprintf (msg, sizeof (msg), "hostname set failed"); + gf_log (THIS->name, GF_LOG_ERROR, "failed to get hostname"); goto out; - } else { - free_hostname = _gf_false; } - ret = dict_set_int32 (dict, "flags", cli_req.flags); + ret = dict_get_str (dict, "volname", &volname); if (ret) { - gf_log ("", GF_LOG_ERROR, "volume flags set failed"); - snprintf (msg, sizeof (msg), "volume flags set failed"); + ret = dict_get_int32 (dict, "flags", (int32_t*)&flags); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, "Unable to get volume" + "name, or flags"); + goto out; + } + } + + gf_log ("glusterd", GF_LOG_INFO, "Received volume sync req " + "for volume %s", + (flags & GF_CLI_SYNC_ALL) ? "all" : volname); + + if (!glusterd_is_local_addr (hostname)) { + ret = -1; + snprintf (msg, sizeof (msg), "sync from localhost" + " not allowed"); goto out; } - if (!cli_req.flags) { - ret = glusterd_volinfo_find (cli_req.volname, &volinfo); + if (!flags) { + ret = glusterd_volinfo_find (volname, &volinfo); if (!ret) { snprintf (msg, sizeof (msg), "please delete the " - "volume: %s before sync", cli_req.volname); + "volume: %s before sync", volname); ret = -1; goto out; } - ret = dict_set_dynmstr (dict, "volname", cli_req.volname); + ret = dict_set_dynmstr (dict, "volname", volname); if (ret) { gf_log ("", GF_LOG_ERROR, "volume name set failed"); snprintf (msg, sizeof (msg), "volume name set failed"); goto out; - } else { - free_volname = _gf_false; } } else { - free_volname = _gf_false; if (glusterd_volume_count_get ()) { snprintf (msg, sizeof (msg), "please delete all the " "volumes before full sync"); @@ -1096,11 +1115,7 @@ out: if (msg[0] == '\0') snprintf (msg, sizeof (msg), "Operation failed"); glusterd_submit_reply(req, &cli_rsp, NULL, 0, NULL, - (xdrproc_t)xdr_gf1_cli_sync_volume_rsp); - if (free_hostname && cli_req.hostname) - free (cli_req.hostname); - if (free_volname && cli_req.volname) - free (cli_req.volname); + (xdrproc_t)xdr_gf_cli_rsp); if (dict) dict_unref (dict); @@ -1686,72 +1701,60 @@ int glusterd_handle_cli_profile_volume (rpcsvc_request_t *req) { int32_t ret = -1; - gf1_cli_stats_volume_req cli_req = {0,}; + gf_cli_req cli_req = {{0,}}; dict_t *dict = NULL; - char msg[2048] = {0,}; - gf_boolean_t free_volname = _gf_true; glusterd_op_t cli_op = GD_OP_PROFILE_VOLUME; - dict_t *tmp_dict = NULL; + char *volname = NULL; + int32_t op = 0; GF_ASSERT (req); - if (!xdr_to_generic (req->msg[0], &cli_req, (xdrproc_t)xdr_gf1_cli_stats_volume_req)) { + if (!xdr_to_generic (req->msg[0], &cli_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 volume profile req " - "for volume %s", cli_req.volname); - dict = dict_new (); - if (!dict) - goto out; - ret = dict_set_dynmstr (dict, "volname", cli_req.volname); - if (ret) { - gf_log ("", GF_LOG_ERROR, "volume name set failed"); - snprintf (msg, sizeof (msg), "volume name set failed"); - goto out; - } else { - free_volname = _gf_false; + + + if (cli_req.dict.dict_len > 0) { + dict = dict_new(); + if (!dict) + goto out; + dict_unserialize (cli_req.dict.dict_val, + cli_req.dict.dict_len, &dict); + } - ret = dict_set_int32 (dict, "op", cli_req.op); + ret = dict_get_str (dict, "volname", &volname); if (ret) { - gf_log ("", GF_LOG_ERROR, "op set failed"); + gf_log (THIS->name, GF_LOG_ERROR, "failed to get volname"); goto out; } - if (cli_req.dict_req.dict_req_len > 0) { - tmp_dict = dict_new(); - if (!tmp_dict) - goto out; - dict_unserialize (cli_req.dict_req.dict_req_val, - cli_req.dict_req.dict_req_len, &tmp_dict); - - dict_copy (tmp_dict, dict); + gf_log ("glusterd", GF_LOG_INFO, "Received volume profile req " + "for volume %s", volname); + ret = dict_get_int32 (dict, "op", &op); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, "failed to get op"); + goto out; } - gf_cmd_log ("Volume stats", "volume : %s, op: %d", cli_req.volname, - cli_req.op); + gf_cmd_log ("Volume stats", "volume : %s, op: %d", volname, op); ret = glusterd_op_begin (req, cli_op, dict); gf_cmd_log ("Volume stats", " on volume %s, op: %d %s ", - cli_req.volname, cli_req.op, + volname, op, ((ret == 0)? " SUCCEDED":" FAILED")); out: glusterd_friend_sm (); glusterd_op_sm (); - if (tmp_dict) - dict_unref (tmp_dict); - if (ret && dict) dict_unref (dict); - if (cli_req.dict_req.dict_req_val) - free (cli_req.dict_req.dict_req_val); - if (free_volname) - free (cli_req.volname); // malloced by xdr + if (cli_req.dict.dict_val) + free (cli_req.dict.dict_val); if (ret) ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, NULL, "operation failed"); @@ -2389,7 +2392,7 @@ glusterd_get_volumes (rpcsvc_request_t *req, dict_t *dict, int32_t flags) glusterd_volinfo_t *entry = NULL; int32_t count = 0; dict_t *volumes = NULL; - gf1_cli_get_vol_rsp rsp = {0,}; + gf_cli_rsp rsp = {0,}; char *volname = NULL; priv = THIS->private; @@ -2466,8 +2469,8 @@ respond: ret = dict_set_int32 (volumes, "count", count); if (ret) goto out; - ret = dict_allocate_and_serialize (volumes, &rsp.volumes.volumes_val, - (size_t *)&rsp.volumes.volumes_len); + ret = dict_allocate_and_serialize (volumes, &rsp.dict.dict_val, + (size_t *)&rsp.dict.dict_len); if (ret) goto out; @@ -2476,14 +2479,15 @@ respond: out: rsp.op_ret = ret; + rsp.op_errstr = ""; ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL, - (xdrproc_t)xdr_gf1_cli_peer_list_rsp); + (xdrproc_t)xdr_gf_cli_rsp); if (volumes) dict_unref (volumes); - if (rsp.volumes.volumes_val) - GF_FREE (rsp.volumes.volumes_val); + if (rsp.dict.dict_val) + GF_FREE (rsp.dict.dict_val); return ret; } @@ -2491,29 +2495,43 @@ int glusterd_handle_status_volume (rpcsvc_request_t *req) { int32_t ret = -1; - gf1_cli_status_volume_req cli_req = {0,}; + gf_cli_req cli_req = {{0,}}; dict_t *dict = NULL; glusterd_op_t cli_op = GD_OP_STATUS_VOLUME; + char *volname = 0; GF_ASSERT (req); if (!xdr_to_generic (req->msg[0], &cli_req, - (xdrproc_t)xdr_gf1_cli_status_volume_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 status volume req " - "for volume %s", cli_req.volname); + if (cli_req.dict.dict_len > 0) { + 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 (THIS->name, GF_LOG_ERROR, "failed to " + "unserialize buffer"); + goto out; + } - dict = dict_new (); - if (!dict) - 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; + } + + gf_log ("glusterd", GF_LOG_INFO, "Received status volume req " + "for volume %s", volname); + ret = glusterd_op_begin (req, GD_OP_STATUS_VOLUME, dict); @@ -2527,6 +2545,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; } 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; } diff --git a/xlators/mgmt/glusterd/src/glusterd-quota.c b/xlators/mgmt/glusterd/src/glusterd-quota.c index aebaef974ad..881cf66b49d 100644 --- a/xlators/mgmt/glusterd/src/glusterd-quota.c +++ b/xlators/mgmt/glusterd/src/glusterd-quota.c @@ -38,7 +38,7 @@ int glusterd_handle_quota (rpcsvc_request_t *req) { int32_t ret = -1; - gf1_cli_quota_req cli_req = {0,}; + gf_cli_req cli_req = {{0,}}; dict_t *dict = NULL; glusterd_op_t cli_op = GD_OP_QUOTA; char operation[256] = {0, }; @@ -48,7 +48,7 @@ glusterd_handle_quota (rpcsvc_request_t *req) GF_ASSERT (req); if (!xdr_to_generic (req->msg[0], &cli_req, - (xdrproc_t)xdr_gf1_cli_quota_req)) { + (xdrproc_t)xdr_gf_cli_req)) { //failed to decode msg; req->rpc_err = GARBAGE_ARGS; goto out; @@ -116,8 +116,6 @@ out: ret = glusterd_op_send_cli_response (cli_op, ret, 0, req, NULL, "operation failed"); } - if (cli_req.volname) - free (cli_req.volname); //malloced by xdr return ret; } diff --git a/xlators/mgmt/glusterd/src/glusterd-rebalance.c b/xlators/mgmt/glusterd/src/glusterd-rebalance.c index f848d73fddf..a50180ea5f6 100644 --- a/xlators/mgmt/glusterd/src/glusterd-rebalance.c +++ b/xlators/mgmt/glusterd/src/glusterd-rebalance.c @@ -466,29 +466,53 @@ out: int glusterd_defrag_status_get (glusterd_volinfo_t *volinfo, - gf1_cli_defrag_vol_rsp *rsp) + dict_t *rsp) { - if (!volinfo) + uint64_t files = 0; + uint64_t size = 0; + uint64_t lookedup_files = 0; + int ret = -1; + + if (!volinfo || !rsp) goto out; if (volinfo->defrag) { LOCK (&volinfo->defrag->lock); { - rsp->files = volinfo->defrag->total_files; - rsp->size = volinfo->defrag->total_data; - rsp->lookedup_files = volinfo->defrag->num_files_lookedup; + files = volinfo->defrag->total_files; + size = volinfo->defrag->total_data; + lookedup_files = volinfo->defrag->num_files_lookedup; } UNLOCK (&volinfo->defrag->lock); } else { - rsp->files = volinfo->rebalance_files; - rsp->size = volinfo->rebalance_data; - rsp->lookedup_files = volinfo->lookedup_files; + files = volinfo->rebalance_files; + size = volinfo->rebalance_data; + lookedup_files = volinfo->lookedup_files; + } + + ret = dict_set_uint64 (rsp, "files", files); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, + "Failed to set dict"); + goto out; } - rsp->op_errno = volinfo->defrag_status; - rsp->op_ret = 0; + ret = dict_set_uint64 (rsp, "size", size); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, + "Failed to set dict"); + goto out; + } + ret = dict_set_uint64 (rsp, "lookedup-files", lookedup_files); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, + "Failed to set dict"); + goto out; + } + + return volinfo->defrag_status; out: - return 0; + return ret; } void @@ -683,51 +707,106 @@ int glusterd_handle_defrag_volume (rpcsvc_request_t *req) { int32_t ret = -1; - gf1_cli_defrag_vol_req cli_req = {0,}; + gf_cli_req cli_req = {{0,}}; glusterd_conf_t *priv = NULL; char cmd_str[4096] = {0,}; glusterd_volinfo_t *volinfo = NULL; - gf1_cli_defrag_vol_rsp rsp = {0,}; + gf_cli_rsp rsp = {0,}; char msg[2048] = {0}; + dict_t *dict = NULL; + char *volname = NULL; + gf_cli_defrag_type cmd = 0; + uint64_t files = 0; + uint64_t size = 0; GF_ASSERT (req); priv = THIS->private; if (!xdr_to_generic (req->msg[0], &cli_req, - (xdrproc_t)xdr_gf1_cli_defrag_vol_req)) { + (xdrproc_t)xdr_gf_cli_req)) { //failed to decode msg; req->rpc_err = GARBAGE_ARGS; goto out; } - glusterd_rebalance_cmd_attempted_log (cli_req.cmd, cli_req.volname); + if (cli_req.dict.dict_len) { + /* Unserialize the dictionary */ + dict = dict_new (); + + 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; + } + + ret = dict_get_int32 (dict, "rebalance-command", (int32_t*)&cmd); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, + "Failed to get command"); + goto out; + } + + glusterd_rebalance_cmd_attempted_log (cmd, volname); - rsp.volname = cli_req.volname; rsp.op_ret = -1; - ret = glusterd_rebalance_cmd_validate (cli_req.cmd, cli_req.volname, + ret = glusterd_rebalance_cmd_validate (cmd, volname, &volinfo, msg, sizeof (msg)); if (ret) goto out; - switch (cli_req.cmd) { + switch (cmd) { case GF_DEFRAG_CMD_START: case GF_DEFRAG_CMD_START_LAYOUT_FIX: case GF_DEFRAG_CMD_START_MIGRATE_DATA: case GF_DEFRAG_CMD_START_MIGRATE_DATA_FORCE: { ret = glusterd_handle_defrag_start (volinfo, msg, sizeof (msg), - cli_req.cmd, NULL); + cmd, NULL); rsp.op_ret = ret; break; } case GF_DEFRAG_CMD_STOP: - ret = glusterd_defrag_stop (volinfo, &rsp.files, &rsp.size, + ret = glusterd_defrag_stop (volinfo, &files, &size, msg, sizeof (msg)); + ret = dict_set_uint64 (dict, "files", files); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, + "Failed to set files argument"); + rsp.op_ret = ret; + goto out; + } + + ret = dict_set_uint64 (dict, "size", size); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, + "Failed to set size argument"); + rsp.op_ret = ret; + goto out; + } + rsp.op_ret = ret; break; case GF_DEFRAG_CMD_STATUS: - ret = glusterd_defrag_status_get (volinfo, &rsp); + ret = glusterd_defrag_status_get (volinfo, dict); + if (ret != -1) { + rsp.op_errno = ret; + rsp.op_ret = 0; + ret = 0; + } + break; default: break; @@ -735,17 +814,31 @@ glusterd_handle_defrag_volume (rpcsvc_request_t *req) if (ret) gf_log("glusterd", GF_LOG_DEBUG, "command: %s failed",cmd_str); - if (cli_req.cmd != GF_DEFRAG_CMD_STATUS) { + if (cmd != GF_DEFRAG_CMD_STATUS) { gf_cmd_log ("volume rebalance"," on volname: %s %d %s", - cli_req.volname, - cli_req.cmd, ((ret)?"FAILED":"SUCCESS")); + volname, + cmd, ((ret)?"FAILED":"SUCCESS")); } out: + ret = dict_allocate_and_serialize (dict, + &rsp.dict.dict_val, + (size_t *) &rsp.dict.dict_len); + if (ret < 0) { + gf_log (THIS->name, GF_LOG_ERROR, + "failed to serialize the data"); + + goto out; + } + ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL, - (xdrproc_t)xdr_gf1_cli_defrag_vol_rsp); - if (cli_req.volname) - free (cli_req.volname);//malloced by xdr + (xdrproc_t)xdr_gf_cli_rsp); + if (cli_req.dict.dict_val) + free (cli_req.dict.dict_val);//malloced by xdr + + if (dict) + dict_unref (dict); + return 0; } @@ -754,45 +847,57 @@ int glusterd_handle_defrag_volume_v2 (rpcsvc_request_t *req) { int32_t ret = -1; - gf1_cli_defrag_vol_req cli_req = {0,}; + gf_cli_req cli_req = {{0,}}; glusterd_conf_t *priv = NULL; dict_t *dict = NULL; char *volname = NULL; + gf_cli_defrag_type cmd = 0; GF_ASSERT (req); priv = THIS->private; if (!xdr_to_generic (req->msg[0], &cli_req, - (xdrproc_t)xdr_gf1_cli_defrag_vol_req)) { + (xdrproc_t)xdr_gf_cli_req)) { //failed to decode msg; req->rpc_err = GARBAGE_ARGS; goto out; } + if (cli_req.dict.dict_len) { + /* Unserialize the dictionary */ + dict = dict_new (); + + 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; + } + } - glusterd_rebalance_cmd_attempted_log (cli_req.cmd, cli_req.volname); - - dict = dict_new (); - if (!dict) + ret = dict_get_str (dict, "volname", &volname); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, + "Failed to get volname"); goto out; + } - volname = gf_strdup (cli_req.volname); - if (!volname) + ret = dict_get_int32 (dict, "rebalance-command", (int32_t*)&cmd); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, + "Failed to get command"); goto out; + } - /* let 'volname' be freed in dict_destroy */ - ret = dict_set_dynstr (dict, "volname", volname); - if (ret) - goto out; + glusterd_rebalance_cmd_attempted_log (cmd, volname); ret = dict_set_static_bin (dict, "node-uuid", priv->uuid, 16); if (ret) goto out; - ret = dict_set_int32 (dict, "rebalance-command", cli_req.cmd); - if (ret) - goto out; - ret = glusterd_op_begin (req, GD_OP_REBALANCE, dict); out: @@ -807,8 +912,8 @@ out: NULL, "operation failed"); } - if (cli_req.volname) - free (cli_req.volname);//malloced by xdr + if (cli_req.dict.dict_val) + free (cli_req.dict.dict_val);//malloced by xdr return 0; } diff --git a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c index 7ae59a833d5..640fd07e0e1 100644 --- a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c +++ b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c @@ -39,18 +39,19 @@ int glusterd_handle_replace_brick (rpcsvc_request_t *req) { int32_t ret = -1; - gf1_cli_replace_brick_req cli_req = {0,}; + gf_cli_req cli_req = {{0,}}; dict_t *dict = NULL; char *src_brick = NULL; char *dst_brick = NULL; int32_t op = 0; char operation[256]; glusterd_op_t cli_op = GD_OP_REPLACE_BRICK; + char *volname = NULL; GF_ASSERT (req); if (!xdr_to_generic (req->msg[0], &cli_req, - (xdrproc_t)xdr_gf1_cli_replace_brick_req)) { + (xdrproc_t)xdr_gf_cli_req)) { //failed to decode msg; req->rpc_err = GARBAGE_ARGS; goto out; @@ -58,23 +59,27 @@ glusterd_handle_replace_brick (rpcsvc_request_t *req) gf_log ("glusterd", GF_LOG_INFO, "Received replace brick req"); - if (cli_req.bricks.bricks_len) { + if (cli_req.dict.dict_len) { /* Unserialize the dictionary */ dict = dict_new (); - ret = dict_unserialize (cli_req.bricks.bricks_val, - cli_req.bricks.bricks_len, + 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; - } else { - dict->extra_stdfree = cli_req.bricks.bricks_val; } } + ret = dict_get_str (dict, "volname", &volname); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, "could not get volname"); + goto out; + } + ret = dict_get_int32 (dict, "operation", &op); if (ret) { gf_log ("", GF_LOG_DEBUG, @@ -120,18 +125,18 @@ glusterd_handle_replace_brick (rpcsvc_request_t *req) gf_log ("glusterd", GF_LOG_INFO, "Received replace brick %s request", operation); gf_cmd_log ("Volume replace-brick","volname: %s src_brick:%s" - " dst_brick:%s op:%s",cli_req.volname, src_brick, dst_brick + " dst_brick:%s op:%s", volname, src_brick, dst_brick ,operation); ret = glusterd_op_begin (req, GD_OP_REPLACE_BRICK, dict); - gf_cmd_log ("Volume replace-brick","on volname: %s %s", cli_req.volname, + gf_cmd_log ("Volume replace-brick","on volname: %s %s", volname, (ret) ? "FAILED" : "SUCCESS"); out: if (ret && dict) dict_unref (dict); - if (cli_req.volname) - free (cli_req.volname);//malloced by xdr + if (cli_req.dict.dict_val) + free (cli_req.dict.dict_val);//malloced by xdr glusterd_friend_sm (); glusterd_op_sm (); diff --git a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c index ea7a2620fae..92be21f9f0f 100644 --- a/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-rpc-ops.c @@ -58,6 +58,9 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret, char *free_ptr = NULL; glusterd_conf_t *conf = NULL; xdrproc_t xdrproc = NULL; + char *errstr = NULL; + int32_t status = 0; + int32_t is_ctx_dict = 0; GF_ASSERT (THIS); @@ -65,425 +68,115 @@ glusterd_op_send_cli_response (glusterd_op_t op, int32_t op_ret, GF_ASSERT (conf); - switch (op) { - case GD_OP_CREATE_VOLUME: - { - gf1_cli_create_vol_rsp rsp = {0,}; - rsp.op_ret = op_ret; - rsp.op_errno = op_errno; - rsp.volname = ""; - if (op_errstr) - rsp.op_errstr = op_errstr; - else - rsp.op_errstr = ""; - cli_rsp = &rsp; - xdrproc = (xdrproc_t)xdr_gf1_cli_create_vol_rsp; - break; - } - - case GD_OP_START_VOLUME: - { - gf1_cli_start_vol_rsp rsp = {0,}; - rsp.op_ret = op_ret; - rsp.op_errno = op_errno; - rsp.volname = ""; - if (op_errstr) - rsp.op_errstr = op_errstr; - else - rsp.op_errstr = ""; - cli_rsp = &rsp; - xdrproc = (xdrproc_t) xdr_gf1_cli_start_vol_rsp; - break; - } - - case GD_OP_STOP_VOLUME: - { - gf1_cli_stop_vol_rsp rsp = {0,}; - rsp.op_ret = op_ret; - rsp.op_errno = op_errno; - rsp.volname = ""; - if (op_errstr) - rsp.op_errstr = op_errstr; - else - rsp.op_errstr = ""; - cli_rsp = &rsp; - xdrproc = (xdrproc_t) xdr_gf1_cli_stop_vol_rsp; - break; - } - - case GD_OP_DELETE_VOLUME: - { - gf1_cli_delete_vol_rsp rsp = {0,}; - rsp.op_ret = op_ret; - rsp.op_errno = op_errno; - rsp.volname = ""; - if (op_errstr) - rsp.op_errstr = op_errstr; - else - rsp.op_errstr = ""; - cli_rsp = &rsp; - xdrproc = (xdrproc_t) xdr_gf1_cli_delete_vol_rsp; - break; - } - - case GD_OP_DEFRAG_VOLUME: - { - gf1_cli_defrag_vol_rsp rsp = {0,}; - rsp.op_ret = op_ret; - rsp.op_errno = op_errno; - //rsp.volname = ""; - cli_rsp = &rsp; - xdrproc = (xdrproc_t) xdr_gf1_cli_defrag_vol_rsp; - break; - } - - case GD_OP_ADD_BRICK: - { - gf1_cli_add_brick_rsp rsp = {0,}; - rsp.op_ret = op_ret; - rsp.op_errno = op_errno; - rsp.volname = ""; - if (op_errstr) - rsp.op_errstr = op_errstr; - else - rsp.op_errstr = ""; - cli_rsp = &rsp; - xdrproc = (xdrproc_t) xdr_gf1_cli_add_brick_rsp; - break; - } + ctx = op_ctx; + switch (op) { case GD_OP_REMOVE_BRICK: { - gf1_cli_remove_brick_rsp rsp = {0,}; - ctx = op_ctx; - if (ctx && - dict_get_str (ctx, "errstr", &rsp.op_errstr)) - rsp.op_errstr = ""; - rsp.op_ret = op_ret; - rsp.op_errno = op_errno; - rsp.volname = ""; - cli_rsp = &rsp; - xdrproc = (xdrproc_t) xdr_gf1_cli_remove_brick_rsp; - break; + if (ctx) + ret = dict_get_str (ctx, "errstr", &errstr); + is_ctx_dict = 1; + goto done; } - - case GD_OP_REPLACE_BRICK: + case GD_OP_RESET_VOLUME: { - gf1_cli_replace_brick_rsp rsp = {0,}; - ctx = op_ctx; - if (ctx && - dict_get_str (ctx, "status-reply", &rsp.status)) - rsp.status = ""; - rsp.op_ret = op_ret; - rsp.op_errno = op_errno; - if (op_errstr) - rsp.op_errstr = op_errstr; - else - rsp.op_errstr = ""; - rsp.volname = ""; - cli_rsp = &rsp; - xdrproc = (xdrproc_t) xdr_gf1_cli_replace_brick_rsp; - break; + if (op_ret && !op_errstr) + errstr = "Error while resetting options"; + goto done; } - - case GD_OP_SET_VOLUME: + case GD_OP_REBALANCE: { - gf1_cli_set_vol_rsp rsp = {0,}; - rsp.op_ret = op_ret; - rsp.op_errno = op_errno; - rsp.volname = ""; - ctx = op_ctx; - - if (op_errstr) - rsp.op_errstr = op_errstr; - else - rsp.op_errstr = ""; if (ctx) { - ret = dict_allocate_and_serialize (ctx, - &rsp.dict.dict_val, - (size_t*)&rsp.dict.dict_len); - if (ret == 0) - free_ptr = rsp.dict.dict_val; + ret = dict_get_int32 (ctx, "status", &status); + if (ret) { + gf_log (THIS->name, GF_LOG_TRACE, + "failed to get status"); + } + is_ctx_dict = 1; } - - cli_rsp = &rsp; - xdrproc = (xdrproc_t) xdr_gf1_cli_set_vol_rsp; - break; - } - - case GD_OP_RESET_VOLUME: - { - gf_log ("", GF_LOG_DEBUG, "Return value to CLI"); - gf1_cli_reset_vol_rsp rsp = {0,}; - rsp.op_ret = op_ret; - rsp.op_errno = 1; - rsp.volname = ""; - if (op_errstr) - rsp.op_errstr = op_errstr; - else - rsp.op_errstr = "Error while resetting options"; - cli_rsp = &rsp; - xdrproc = (xdrproc_t) xdr_gf1_cli_reset_vol_rsp; - break; - } - - case GD_OP_LOG_FILENAME: - { - gf1_cli_log_filename_rsp rsp = {0,}; - rsp.op_ret = op_ret; - rsp.op_errno = op_errno; - if (op_errstr) - rsp.errstr = op_errstr; - else - rsp.errstr = ""; - cli_rsp = &rsp; - xdrproc = (xdrproc_t) xdr_gf1_cli_log_filename_rsp; - break; - } - case GD_OP_LOG_ROTATE: - { - gf1_cli_log_rotate_rsp rsp = {0,}; - rsp.op_ret = op_ret; - rsp.op_errno = op_errno; - if (op_errstr) - rsp.errstr = op_errstr; - else - rsp.errstr = ""; - cli_rsp = &rsp; - xdrproc = (xdrproc_t) xdr_gf1_cli_log_rotate_rsp; - break; - } - case GD_OP_SYNC_VOLUME: - { - gf1_cli_sync_volume_rsp rsp = {0,}; - rsp.op_ret = op_ret; - rsp.op_errno = op_errno; - if (op_errstr) - rsp.op_errstr = op_errstr; - else - rsp.op_errstr = ""; - cli_rsp = &rsp; - xdrproc = (xdrproc_t) xdr_gf1_cli_sync_volume_rsp; - break; + goto done; } case GD_OP_GSYNC_SET: { - int type = 0; - char *str = NULL; - gf1_cli_gsync_set_rsp rsp = {0,}; - - ctx = op_ctx; - rsp.op_ret = op_ret; - rsp.op_errno = op_errno; - rsp.op_errstr = ""; - if (ctx) { - ret = dict_get_str (ctx, "errstr", &str); - if (ret == 0) - rsp.op_errstr = str; - ret = dict_get_int32 (ctx, "type", &type); - if (ret == 0) - rsp.type = type; + if (ctx) { + ret = dict_get_str (ctx, "errstr", &errstr); ret = dict_set_str (ctx, "glusterd_workdir", conf->workdir); /* swallow error here, that will be re-triggered in cli */ - ret = dict_allocate_and_serialize (ctx, - &rsp.dict.dict_val, - (size_t*)&rsp.dict.dict_len); + is_ctx_dict = 1; + goto done; + } - if (ret == 0) - free_ptr = rsp.dict.dict_val; - - } - if (op_errstr) - rsp.op_errstr = op_errstr; - cli_rsp = &rsp; - xdrproc = (xdrproc_t) xdr_gf1_cli_gsync_set_rsp; - break; - } - case GD_OP_RENAME_VOLUME: - case GD_OP_START_BRICK: - case GD_OP_STOP_BRICK: - case GD_OP_LOG_LOCATE: - { - gf_log ("", GF_LOG_DEBUG, "not supported op %d", op); - break; - } - case GD_OP_PROFILE_VOLUME: - { - gf1_cli_stats_volume_rsp rsp = {0,}; - rsp.op_ret = op_ret; - rsp.op_errno = op_errno; - if (op_errstr) - rsp.op_errstr = op_errstr; - else - rsp.op_errstr = ""; - ctx = op_ctx; - if (ctx) - dict_allocate_and_serialize (ctx, - &rsp.stats_info.stats_info_val, - (size_t*)&rsp.stats_info.stats_info_len); - free_ptr = rsp.stats_info.stats_info_val; - cli_rsp = &rsp; - xdrproc = (xdrproc_t) xdr_gf1_cli_stats_volume_rsp; - break; } - case GD_OP_QUOTA: { - int32_t type; - char *str = NULL; - char *errstr = NULL; - gf1_cli_quota_rsp rsp = {0,}; - - rsp.op_ret = op_ret; - rsp.op_errno = op_errno; - rsp.volname = ""; - - ctx = op_ctx; - - if (op_errstr) - rsp.op_errstr = op_errstr; - else { + if (ctx && !op_errstr) { ret = dict_get_str (ctx, "errstr", &errstr); - if (ret == 0) - rsp.op_errstr = errstr; - else - rsp.op_errstr = ""; - } - - rsp.limit_list = ""; - - if (op_ret == 0 && ctx) { - ret = dict_get_str (ctx, "volname", &str); - if (ret == 0) - rsp.volname = str; - - ret = dict_get_int32 (ctx, "type", &type); - if (ret == 0) - rsp.type = type; - else - rsp.type = 0; - - if (type == GF_QUOTA_OPTION_TYPE_LIST) { - ret = dict_get_str (ctx,"limit_list", &str); - - if (ret == 0) - rsp.limit_list = str; - } } - cli_rsp = &rsp; - xdrproc = (xdrproc_t) xdr_gf1_cli_quota_rsp; - break; + is_ctx_dict = 1; + goto done; } - - case GD_OP_LOG_LEVEL: + case GD_OP_REPLACE_BRICK: + case GD_OP_STATUS_VOLUME: + case GD_OP_SET_VOLUME: + case GD_OP_PROFILE_VOLUME: { - gf1_cli_log_level_rsp rsp = {0,}; - rsp.op_ret = op_ret; - rsp.op_errno = op_errno; - if (op_errstr) - rsp.op_errstr = op_errstr; - else - rsp.op_errstr = ""; - - cli_rsp = &rsp; - xdrproc = (xdrproc_t) xdr_gf1_cli_log_level_rsp; - break; + is_ctx_dict = 1; } + case GD_OP_CREATE_VOLUME: + case GD_OP_START_VOLUME: + case GD_OP_STOP_VOLUME: + case GD_OP_DELETE_VOLUME: + case GD_OP_DEFRAG_VOLUME: + case GD_OP_ADD_BRICK: + case GD_OP_LOG_FILENAME: + case GD_OP_LOG_ROTATE: + case GD_OP_SYNC_VOLUME: + case GD_OP_LOG_LEVEL: + case GD_OP_HEAL_VOLUME: + case GD_OP_STATEDUMP_VOLUME: - - case GD_OP_STATUS_VOLUME: +done: { - gf1_cli_status_volume_rsp rsp = {0,}; + gf_cli_rsp rsp = {0,}; rsp.op_ret = op_ret; - rsp.op_errno = op_errno; - if (op_errstr) + rsp.op_errno = errno; + if (errstr) + rsp.op_errstr = errstr; + else if (op_errstr) rsp.op_errstr = op_errstr; - else - rsp.op_errstr = ""; - ctx = op_ctx; - dict_allocate_and_serialize (ctx, - &rsp.dict.dict_val, - (size_t*)&rsp.dict.dict_len); - free_ptr = rsp.dict.dict_val; - cli_rsp = &rsp; - xdrproc = (xdrproc_t) xdr_gf1_cli_status_volume_rsp; - break; - } - case GD_OP_REBALANCE: - { - gf2_cli_defrag_vol_rsp rsp = {0,}; - int32_t status = 0; - ctx = op_ctx; - rsp.op_ret = op_ret; - rsp.op_errno = op_errno; - rsp.volname = ""; - if (op_errstr) - rsp.op_errstr = op_errstr; - else + if (!rsp.op_errstr) rsp.op_errstr = ""; - if (ctx) { - ret = dict_get_uint64 (ctx, "files", &rsp.files); - if (ret) { - gf_log (THIS->name, GF_LOG_DEBUG, - "failed to get the file count"); - } - ret = dict_get_uint64 (ctx, "size", &rsp.size); - if (ret) { - gf_log (THIS->name, GF_LOG_DEBUG, - "failed to get the size of migration"); - } - ret = dict_get_uint64 (ctx, "lookups", &rsp.lookedup_files); - if (ret) { - gf_log (THIS->name, GF_LOG_DEBUG, - "failed to get lookuped file count"); - } - - ret = dict_get_int32 (ctx, "status", &status); - if (ret) { - gf_log (THIS->name, GF_LOG_TRACE, - "failed to get status"); + if (ctx && is_ctx_dict) { + ret = dict_allocate_and_serialize (ctx, &rsp.dict.dict_val, + (size_t*)&rsp.dict.dict_len); + if (ret < 0 ) { + gf_log (THIS->name, GF_LOG_ERROR, "failed to " + "serialize buffer"); + break; } + free_ptr = rsp.dict.dict_val; } /* needed by 'rebalance status' */ if (status) rsp.op_errno = status; cli_rsp = &rsp; - xdrproc = (xdrproc_t)xdr_gf2_cli_defrag_vol_rsp; + xdrproc = (xdrproc_t) xdr_gf_cli_rsp; break; } - case GD_OP_HEAL_VOLUME: - { - gf1_cli_heal_vol_rsp rsp = {0,}; - rsp.op_ret = op_ret; - rsp.op_errno = op_errno; - rsp.volname = ""; - if (op_errstr) - rsp.op_errstr = op_errstr; - else - rsp.op_errstr = ""; - cli_rsp = &rsp; - xdrproc = (xdrproc_t) xdr_gf1_cli_heal_vol_rsp; - break; - } - case GD_OP_STATEDUMP_VOLUME: + case GD_OP_RENAME_VOLUME: + case GD_OP_START_BRICK: + case GD_OP_STOP_BRICK: + case GD_OP_LOG_LOCATE: { - gf1_cli_statedump_vol_rsp rsp = {0,}; - rsp.op_ret = op_ret; - rsp.op_errno = errno; - rsp.volname = ""; - if (op_errstr) - rsp.op_errstr = op_errstr; - else - rsp.op_errstr = ""; - cli_rsp = &rsp; - xdrproc = (xdrproc_t) xdr_gf1_cli_statedump_vol_rsp; + gf_log ("", GF_LOG_DEBUG, "not supported op %d", op); break; } + case GD_OP_NONE: case GD_OP_MAX: { diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c index b1686b32162..6c3da47ea24 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c @@ -39,7 +39,7 @@ int glusterd_handle_create_volume (rpcsvc_request_t *req) { int32_t ret = -1; - gf1_cli_create_vol_req cli_req = {0,}; + gf_cli_req cli_req = {{0,}}; dict_t *dict = NULL; glusterd_brickinfo_t *brickinfo = NULL; char *brick = NULL; @@ -51,13 +51,14 @@ glusterd_handle_create_volume (rpcsvc_request_t *req) char *brick_list = NULL; void *cli_rsp = NULL; char err_str[2048] = {0,}; - gf1_cli_create_vol_rsp rsp = {0,}; + gf_cli_rsp rsp = {0,}; xlator_t *this = NULL; char *free_ptr = NULL; char *trans_type = NULL; uuid_t volume_id = {0,}; glusterd_brickinfo_t *tmpbrkinfo = NULL; glusterd_volinfo_t tmpvolinfo = {{0},}; + int32_t type = 0; GF_ASSERT (req); @@ -68,7 +69,7 @@ glusterd_handle_create_volume (rpcsvc_request_t *req) ret = -1; if (!xdr_to_generic (req->msg[0], &cli_req, - (xdrproc_t)xdr_gf1_cli_create_vol_req)) { + (xdrproc_t)xdr_gf_cli_req)) { //failed to decode msg; req->rpc_err = GARBAGE_ARGS; snprintf (err_str, sizeof (err_str), "Garbage args received"); @@ -77,12 +78,12 @@ glusterd_handle_create_volume (rpcsvc_request_t *req) gf_log ("glusterd", GF_LOG_INFO, "Received create volume req"); - if (cli_req.bricks.bricks_len) { + if (cli_req.dict.dict_len) { /* Unserialize the dictionary */ dict = dict_new (); - ret = dict_unserialize (cli_req.bricks.bricks_val, - cli_req.bricks.bricks_len, + ret = dict_unserialize (cli_req.dict.dict_val, + cli_req.dict.dict_len, &dict); if (ret < 0) { gf_log ("glusterd", GF_LOG_ERROR, @@ -92,7 +93,7 @@ glusterd_handle_create_volume (rpcsvc_request_t *req) "the buffer"); goto out; } else { - dict->extra_stdfree = cli_req.bricks.bricks_val; + dict->extra_stdfree = cli_req.dict.dict_val; } } @@ -120,6 +121,14 @@ glusterd_handle_create_volume (rpcsvc_request_t *req) goto out; } + ret = dict_get_int32 (dict, "type", &type); + /*if (ret) { + gf_log ("", GF_LOG_ERROR, "Unable to get type"); + snprintf (err_str, sizeof (err_str), "Unable to get volume " + "type"); + goto out; + }*/ + ret = dict_get_str (dict, "transport", &trans_type); if (ret) { gf_log ("", GF_LOG_ERROR, "Unable to get transport-type"); @@ -152,9 +161,8 @@ glusterd_handle_create_volume (rpcsvc_request_t *req) } gf_cmd_log ("Volume create", "on volname: %s type:%s count:%d bricks:%s", - cli_req.volname, ((cli_req.type == 0)? "DEFAULT": - ((cli_req.type == 1)? "STRIPE":"REPLICATE")), cli_req.count, - bricks); + volname, ((type == 0)? "DEFAULT": + ((type == 1)? "STRIPE":"REPLICATE")), brick_count, bricks); while ( i < brick_count) { @@ -198,13 +206,12 @@ out: dict_unref (dict); rsp.op_ret = -1; rsp.op_errno = 0; - rsp.volname = ""; if (err_str[0] == '\0') snprintf (err_str, sizeof (err_str), "Operation failed"); rsp.op_errstr = err_str; cli_rsp = &rsp; glusterd_submit_reply(req, cli_rsp, NULL, 0, NULL, - (xdrproc_t)xdr_gf1_cli_create_vol_rsp); + (xdrproc_t)xdr_gf_cli_rsp); ret = 0; //Client response sent, prevent second response } @@ -215,8 +222,6 @@ out: glusterd_volume_brickinfos_delete (&tmpvolinfo); if (brickinfo) glusterd_brickinfo_delete (brickinfo); - if (cli_req.volname) - free (cli_req.volname); // its a malloced by xdr glusterd_friend_sm (); glusterd_op_sm (); @@ -228,7 +233,7 @@ int glusterd_handle_cli_start_volume (rpcsvc_request_t *req) { int32_t ret = -1; - gf1_cli_start_vol_req cli_req = {0,}; + gf_cli_req cli_req = {{0,}}; char *dup_volname = NULL; dict_t *dict = NULL; glusterd_op_t cli_op = GD_OP_START_VOLUME; @@ -236,41 +241,45 @@ glusterd_handle_cli_start_volume (rpcsvc_request_t *req) GF_ASSERT (req); if (!xdr_to_generic (req->msg[0], &cli_req, - (xdrproc_t)xdr_gf1_cli_start_vol_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 start vol 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 (); - dup_volname = gf_strdup (cli_req.volname); - if (!dup_volname) - goto out; + ret = dict_unserialize (cli_req.dict.dict_val, + cli_req.dict.dict_len, + &dict); + if (ret < 0) { + gf_log (THIS->name, GF_LOG_ERROR, + "failed to " + "unserialize req-buffer to dictionary"); + goto out; + } + } - ret = dict_set_dynstr (dict, "volname", dup_volname); - if (ret) + ret = dict_get_str (dict, "volname", &dup_volname); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, "dict get failed"); goto out; + } - ret = dict_set_int32 (dict, "flags", cli_req.flags); - if (ret) - goto out; + gf_log ("glusterd", GF_LOG_INFO, "Received start vol req" + "for volume %s", dup_volname); ret = glusterd_op_begin (req, GD_OP_START_VOLUME, dict); - gf_cmd_log ("volume start","on volname: %s %s", cli_req.volname, + gf_cmd_log ("volume start","on volname: %s %s", dup_volname, ((ret == 0) ? "SUCCESS": "FAILED")); out: if (ret && dict) dict_unref (dict); - if (cli_req.volname) - free (cli_req.volname); //its malloced by xdr + if (cli_req.dict.dict_val) + free (cli_req.dict.dict_val); //its malloced by xdr glusterd_friend_sm (); glusterd_op_sm (); @@ -287,7 +296,7 @@ int glusterd_handle_cli_stop_volume (rpcsvc_request_t *req) { int32_t ret = -1; - gf1_cli_stop_vol_req cli_req = {0,}; + gf_cli_req cli_req = {{0,}}; char *dup_volname = NULL; dict_t *dict = NULL; glusterd_op_t cli_op = GD_OP_STOP_VOLUME; @@ -295,39 +304,43 @@ glusterd_handle_cli_stop_volume (rpcsvc_request_t *req) GF_ASSERT (req); if (!xdr_to_generic (req->msg[0], &cli_req, - (xdrproc_t)xdr_gf1_cli_stop_vol_req)) { + (xdrproc_t)xdr_gf_cli_req)) { //failed to decode msg; req->rpc_err = GARBAGE_ARGS; goto out; } + if (cli_req.dict.dict_len) { + /* Unserialize the dictionary */ + dict = dict_new (); - gf_log ("glusterd", GF_LOG_INFO, "Received stop vol req" - "for volume %s", cli_req.volname); - - 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; + } + } - dup_volname = gf_strdup (cli_req.volname); - if (!dup_volname) - goto out; + ret = dict_get_str (dict, "volname", &dup_volname); - ret = dict_set_dynstr (dict, "volname", dup_volname); - if (ret) + if (ret) { + gf_log ("", GF_LOG_ERROR, "Unable to get volume name"); goto out; + } - ret = dict_set_int32 (dict, "flags", cli_req.flags); - if (ret) - goto out; + gf_log ("glusterd", GF_LOG_INFO, "Received stop vol req" + "for volume %s", dup_volname); ret = glusterd_op_begin (req, GD_OP_STOP_VOLUME, dict); - gf_cmd_log ("Volume stop","on volname: %s %s", cli_req.volname, + gf_cmd_log ("Volume stop","on volname: %s %s", dup_volname, ((ret)?"FAILED":"SUCCESS")); out: - if (cli_req.volname) - free (cli_req.volname); //its malloced by xdr + if (cli_req.dict.dict_val) + free (cli_req.dict.dict_val); //its malloced by xdr glusterd_friend_sm (); glusterd_op_sm (); @@ -346,37 +359,65 @@ int glusterd_handle_cli_delete_volume (rpcsvc_request_t *req) { int32_t ret = -1; - gf1_cli_delete_vol_req cli_req = {0,}; + gf_cli_req cli_req = {{0,}}; glusterd_op_delete_volume_ctx_t *ctx = NULL; glusterd_op_t cli_op = GD_OP_DELETE_VOLUME; + char *volname = NULL; + dict_t *dict = NULL; GF_ASSERT (req); if (!xdr_to_generic (req->msg[0], &cli_req, - (xdrproc_t)xdr_gf1_cli_delete_vol_req)) { + (xdrproc_t)xdr_gf_cli_req)) { //failed to decode msg; req->rpc_err = GARBAGE_ARGS; goto out; } - gf_cmd_log ("Volume delete","on volname: %s attempted", cli_req.volname); + + if (cli_req.dict.dict_len) { + /* Unserialize the dictionary */ + dict = dict_new (); + + ret = dict_unserialize (cli_req.dict.dict_val, + cli_req.dict.dict_len, + &dict); + if (ret < 0) { + gf_log (THIS->name, 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"); + req->rpc_err = GARBAGE_ARGS; + goto out; + } + + gf_cmd_log ("Volume delete","on volname: %s attempted", volname); gf_log ("glusterd", GF_LOG_INFO, "Received delete vol req" - "for volume %s", cli_req.volname); + "for volume %s", volname); ctx = GF_CALLOC (1, sizeof (*ctx), gf_gld_mt_delete_volume_ctx_t); if (!ctx) goto out; - strncpy (ctx->volume_name, cli_req.volname, GD_VOLUME_NAME_MAX); + strncpy (ctx->volume_name, volname, GD_VOLUME_NAME_MAX); ret = glusterd_op_begin (req, GD_OP_DELETE_VOLUME, ctx); - gf_cmd_log ("Volume delete", "on volname: %s %s", cli_req.volname, + gf_cmd_log ("Volume delete", "on volname: %s %s", volname, ((ret) ? "FAILED" : "SUCCESS")); out: - if (cli_req.volname) - free (cli_req.volname); //its malloced by xdr + if (cli_req.dict.dict_val) + free (cli_req.dict.dict_val); //its malloced by xdr + if (dict) + dict_unref (dict); glusterd_friend_sm (); glusterd_op_sm (); @@ -396,46 +437,53 @@ int glusterd_handle_cli_heal_volume (rpcsvc_request_t *req) { int32_t ret = -1; - gf1_cli_heal_vol_req cli_req = {0,}; - char *dup_volname = NULL; + gf_cli_req cli_req = {{0,}}; dict_t *dict = NULL; glusterd_op_t cli_op = GD_OP_HEAL_VOLUME; + char *volname = NULL; GF_ASSERT (req); if (!xdr_to_generic (req->msg[0], &cli_req, - (xdrproc_t)xdr_gf1_cli_heal_vol_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 heal vol 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 (); - dup_volname = gf_strdup (cli_req.volname); - if (!dup_volname) - goto out; + ret = dict_unserialize (cli_req.dict.dict_val, + cli_req.dict.dict_len, + &dict); + if (ret < 0) { + gf_log (THIS->name, GF_LOG_ERROR, + "failed to " + "unserialize req-buffer to dictionary"); + goto out; + } + } - ret = dict_set_dynstr (dict, "volname", dup_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; + } + gf_log ("glusterd", GF_LOG_INFO, "Received heal vol req" + "for volume %s", volname); ret = glusterd_op_begin (req, GD_OP_HEAL_VOLUME, dict); - gf_cmd_log ("volume heal","on volname: %s %s", cli_req.volname, + gf_cmd_log ("volume heal","on volname: %s %s", volname, ((ret == 0) ? "SUCCESS": "FAILED")); out: if (ret && dict) dict_unref (dict); - if (cli_req.volname) - free (cli_req.volname); //its malloced by xdr + if (cli_req.dict.dict_val) + free (cli_req.dict.dict_val); //its malloced by xdr glusterd_friend_sm (); glusterd_op_sm (); @@ -451,56 +499,66 @@ int glusterd_handle_cli_statedump_volume (rpcsvc_request_t *req) { int32_t ret = -1; - gf1_cli_statedump_vol_req cli_req = {0,}; - char *dup_volname = NULL; - char *dup_options = NULL; + gf_cli_req cli_req = {{0,}}; + char *volname = NULL; + char *options = NULL; dict_t *dict = NULL; + int32_t option_cnt = 0; GF_ASSERT (req); ret = -1; if (!xdr_to_generic (req->msg[0], &cli_req, - (xdrproc_t)xdr_gf1_cli_statedump_vol_req)) { + (xdrproc_t)xdr_gf_cli_req)) { req->rpc_err = GARBAGE_ARGS; goto out; } - gf_log ("glusterd", GF_LOG_INFO, "Recieved statedump request for " - "volume %s with options %s", cli_req.volname, cli_req.options); - dict = dict_new (); + if (cli_req.dict.dict_len) { + /* Unserialize the dictionary */ + dict = dict_new (); - if (!dict) + ret = dict_unserialize (cli_req.dict.dict_val, + cli_req.dict.dict_len, + &dict); + if (ret < 0) { + gf_log (THIS->name, 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; + } - dup_volname = gf_strdup (cli_req.volname); - if (!dup_volname) - goto out; - ret = dict_set_dynstr (dict, "volname", dup_volname); - if (ret) + ret = dict_get_str (dict, "options", &options); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, "failed to get options"); goto out; + } - dup_options = gf_strdup(cli_req.options); - if (!dup_volname) - goto out; - ret = dict_set_dynstr (dict, "options", dup_options); - if (ret) + ret = dict_get_int32 (dict, "option_cnt", &option_cnt); + if (ret) { + gf_log (THIS->name, GF_LOG_ERROR, "failed to get option cnt"); goto out; + } - ret = dict_set_int32 (dict, "option_cnt", cli_req.option_cnt); - if (ret) - goto out; + + gf_log ("glusterd", GF_LOG_INFO, "Recieved statedump request for " + "volume %s with options %s", volname, options); ret = glusterd_op_begin (req, GD_OP_STATEDUMP_VOLUME, dict); - gf_cmd_log ("statedump", "on volume %s %s", cli_req.volname, + gf_cmd_log ("statedump", "on volume %s %s", volname, ((0 == ret) ? "SUCCEEDED" : "FAILED")); out: if (ret && dict) dict_unref (dict); - if (cli_req.volname) - free (cli_req.volname); - if (cli_req.options) - free (cli_req.options); + if (cli_req.dict.dict_val) + free (cli_req.dict.dict_val); glusterd_friend_sm (); glusterd_op_sm(); |