summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-rebalance.c
diff options
context:
space:
mode:
authorshishir gowda <shishirng@gluster.com>2011-11-02 18:38:50 +0530
committerVijay Bellur <vijay@gluster.com>2011-11-16 01:42:29 -0800
commit7a97478dd1a343fcc5d9d4eab963882191a3de69 (patch)
tree54f48eacb357561a9ebc5f5089e666e0979c7d55 /xlators/mgmt/glusterd/src/glusterd-rebalance.c
parent913b21621e2dad9146366f24048ff07a8046e5c5 (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-rebalance.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-rebalance.c195
1 files changed, 150 insertions, 45 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-rebalance.c b/xlators/mgmt/glusterd/src/glusterd-rebalance.c
index f848d73..a50180e 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;
}