glusterd: Moved peer rsp handling functions to glusterd-utils

- Moved inner functions used in conjunction with synctask, 'out'.

Change-Id: I7fbfd9881ea58645c4295a9fa7163ddd15a45d2f
BUG: 862834
Signed-off-by: Krishnan Parthasarathi <kparthas@redhat.com>
Reviewed-on: http://review.gluster.org/4066
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
This commit is contained in:
Krishnan Parthasarathi 2012-10-11 22:41:56 +05:30 committed by Anand Avati
parent 751da4675c
commit 1f2dbafc72
5 changed files with 630 additions and 560 deletions

View File

@ -24,6 +24,7 @@
struct gf_printer {
ssize_t (*write) (struct gf_printer *gp, char *buf, size_t len);
void *priv;
int len;
};
static ssize_t
@ -80,17 +81,30 @@ gpprintf (struct gf_printer *gp, const char *format, ...)
return ret;
}
static int
glusterfs_graph_print (struct gf_printer *gp, glusterfs_graph_t *graph)
{
#define GPPRINTF(gp, fmt, ...) do { \
ret = gpprintf (gp, fmt, ## __VA_ARGS__); \
if (ret == -1) \
goto out; \
else \
len += ret; \
gp->len += ret; \
} while (0)
static int
_print_volume_options (dict_t *d, char *k, data_t *v,
void *tmp)
{
struct gf_printer *gp = tmp;
int ret = 0;
GPPRINTF (gp, " option %s %s\n", k, v->data);
return 0;
out:
/* means, it is a failure */
return -1;
}
static int
glusterfs_graph_print (struct gf_printer *gp, glusterfs_graph_t *graph)
{
xlator_t *trav = NULL;
xlator_list_t *xch = NULL;
int ret = 0;
@ -104,16 +118,7 @@ glusterfs_graph_print (struct gf_printer *gp, glusterfs_graph_t *graph)
GPPRINTF (gp, "volume %s\n type %s\n", trav->name,
trav->type);
int _print_volume_options (dict_t *d, char *k, data_t *v,
void *tmp)
{
GPPRINTF (gp, " option %s %s\n", k, v->data);
return 0;
out:
/* means, it is a failure */
return -1;
}
ret = dict_foreach (trav->options, _print_volume_options, NULL);
ret = dict_foreach (trav->options, _print_volume_options, gp);
if (ret)
goto out;
@ -132,6 +137,7 @@ glusterfs_graph_print (struct gf_printer *gp, glusterfs_graph_t *graph)
}
out:
len = gp->len;
if (ret == -1) {
gf_log ("graph-print", GF_LOG_ERROR, "printing failed");

View File

@ -266,10 +266,32 @@ out:
return ret;
}
struct args_pack {
dict_t *dict;
int vol_count;
int opt_count;
};
static int
_build_option_key (dict_t *d, char *k, data_t *v, void *tmp)
{
char reconfig_key[256] = {0, };
struct args_pack *pack = NULL;
int ret = -1;
pack = tmp;
snprintf (reconfig_key, 256, "volume%d.option.%s",
pack->vol_count, k);
ret = dict_set_str (pack->dict, reconfig_key, v->data);
if (0 == ret)
pack->opt_count++;
return 0;
}
int
glusterd_add_volume_detail_to_dict (glusterd_volinfo_t *volinfo,
dict_t *volumes, int count)
dict_t *volumes, int count)
{
int ret = -1;
@ -277,11 +299,10 @@ glusterd_add_volume_detail_to_dict (glusterd_volinfo_t *volinfo,
glusterd_brickinfo_t *brickinfo = NULL;
char *buf = NULL;
int i = 1;
char reconfig_key[256] = {0, };
dict_t *dict = NULL;
int opt_count = 0;
glusterd_conf_t *priv = NULL;
char *volume_id_str = NULL;
struct args_pack pack = {0,};
GF_ASSERT (volinfo);
@ -363,18 +384,13 @@ glusterd_add_volume_detail_to_dict (glusterd_volinfo_t *volinfo,
goto out;
}
int _build_option_key (dict_t *d, char *k, data_t *v, void *tmp)
{
snprintf (reconfig_key, 256, "volume%d.option.%s", count, k);
ret = dict_set_str (volumes, reconfig_key, v->data);
if (0 == ret)
opt_count++;
return 0;
}
dict_foreach (dict, _build_option_key, NULL);
pack.dict = volumes;
pack.vol_count = count;
pack.opt_count = 0;
dict_foreach (dict, _build_option_key, (void *) &pack);
snprintf (key, 256, "volume%d.opt_count", count);
ret = dict_set_int32 (volumes, key, opt_count);
snprintf (key, 256, "volume%d.opt_count", pack.vol_count);
ret = dict_set_int32 (volumes, key, pack.opt_count);
out:
return ret;
}

View File

@ -620,195 +620,6 @@ out:
return ret;
}
static int32_t
glusterd_append_gsync_status (dict_t *dst, dict_t *src)
{
int ret = 0;
char *stop_msg = NULL;
ret = dict_get_str (src, "gsync-status", &stop_msg);
if (ret) {
ret = 0;
goto out;
}
ret = dict_set_dynstr (dst, "gsync-status", gf_strdup (stop_msg));
if (ret) {
gf_log ("glusterd", GF_LOG_WARNING, "Unable to set the stop"
"message in the ctx dictionary");
goto out;
}
ret = 0;
out:
gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
static int32_t
glusterd_append_status_dicts (dict_t *dst, dict_t *src)
{
int dst_count = 0;
int src_count = 0;
int i = 0;
int ret = 0;
char mst[PATH_MAX] = {0,};
char slv[PATH_MAX] = {0, };
char sts[PATH_MAX] = {0, };
char *mst_val = NULL;
char *slv_val = NULL;
char *sts_val = NULL;
GF_ASSERT (dst);
if (src == NULL)
goto out;
ret = dict_get_int32 (dst, "gsync-count", &dst_count);
if (ret)
dst_count = 0;
ret = dict_get_int32 (src, "gsync-count", &src_count);
if (ret || !src_count) {
gf_log ("", GF_LOG_DEBUG, "Source brick empty");
ret = 0;
goto out;
}
for (i = 1; i <= src_count; i++) {
snprintf (mst, sizeof(mst), "master%d", i);
snprintf (slv, sizeof(slv), "slave%d", i);
snprintf (sts, sizeof(sts), "status%d", i);
ret = dict_get_str (src, mst, &mst_val);
if (ret)
goto out;
ret = dict_get_str (src, slv, &slv_val);
if (ret)
goto out;
ret = dict_get_str (src, sts, &sts_val);
if (ret)
goto out;
snprintf (mst, sizeof(mst), "master%d", i+dst_count);
snprintf (slv, sizeof(slv), "slave%d", i+dst_count);
snprintf (sts, sizeof(sts), "status%d", i+dst_count);
ret = dict_set_dynstr (dst, mst, gf_strdup (mst_val));
if (ret)
goto out;
ret = dict_set_dynstr (dst, slv, gf_strdup (slv_val));
if (ret)
goto out;
ret = dict_set_dynstr (dst, sts, gf_strdup (sts_val));
if (ret)
goto out;
}
ret = dict_set_int32 (dst, "gsync-count", dst_count+src_count);
out:
gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
static int32_t
glusterd_gsync_use_rsp_dict (dict_t *rsp_dict, char *op_errstr)
{
dict_t *ctx = NULL;
int ret = 0;
ctx = glusterd_op_get_ctx ();
if (!ctx) {
gf_log ("", GF_LOG_ERROR,
"Operation Context is not present");
GF_ASSERT (0);
}
if (rsp_dict) {
ret = glusterd_append_status_dicts (ctx, rsp_dict);
if (ret)
goto out;
ret = glusterd_append_gsync_status (ctx, rsp_dict);
if (ret)
goto out;
}
if (strcmp ("", op_errstr)) {
ret = dict_set_dynstr (ctx, "errstr", gf_strdup(op_errstr));
if (ret)
goto out;
}
ret = 0;
out:
gf_log ("", GF_LOG_DEBUG, "Returning %d ", ret);
return ret;
}
static int32_t
glusterd_rb_use_rsp_dict (dict_t *rsp_dict)
{
int32_t src_port = 0;
int32_t dst_port = 0;
int ret = 0;
dict_t *ctx = NULL;
ctx = glusterd_op_get_ctx ();
if (!ctx) {
gf_log ("", GF_LOG_ERROR,
"Operation Context is not present");
GF_ASSERT (0);
}
if (rsp_dict) {
ret = dict_get_int32 (rsp_dict, "src-brick-port", &src_port);
if (ret == 0) {
gf_log ("", GF_LOG_DEBUG,
"src-brick-port=%d found", src_port);
}
ret = dict_get_int32 (rsp_dict, "dst-brick-port", &dst_port);
if (ret == 0) {
gf_log ("", GF_LOG_DEBUG,
"dst-brick-port=%d found", dst_port);
}
}
if (src_port) {
ret = dict_set_int32 (ctx, "src-brick-port",
src_port);
if (ret) {
gf_log ("", GF_LOG_DEBUG,
"Could not set src-brick");
goto out;
}
}
if (dst_port) {
ret = dict_set_int32 (ctx, "dst-brick-port",
dst_port);
if (ret) {
gf_log ("", GF_LOG_DEBUG,
"Could not set dst-brick");
goto out;
}
}
out:
return ret;
}
int32_t
glusterd_stage_op_cbk (struct rpc_req *req, struct iovec *iov,
int count, void *myframe)
@ -901,7 +712,7 @@ out:
switch (rsp.op) {
case GD_OP_REPLACE_BRICK:
glusterd_rb_use_rsp_dict (dict);
glusterd_rb_use_rsp_dict (NULL, dict);
break;
}
@ -924,341 +735,6 @@ out:
return ret;
}
static int32_t
glusterd_sync_use_rsp_dict (dict_t *rsp_dict)
{
int ret = 0;
GF_ASSERT (rsp_dict);
if (!rsp_dict) {
goto out;
}
ret = glusterd_import_friend_volumes (rsp_dict);
out:
return ret;
}
int
_profile_volume_add_friend_rsp (dict_t *this, char *key, data_t *value,
void *data)
{
char new_key[256] = {0};
glusterd_pr_brick_rsp_conv_t *rsp_ctx = NULL;
data_t *new_value = NULL;
int brick_count = 0;
char brick_key[256];
if (strcmp (key, "count") == 0)
return 0;
sscanf (key, "%d%s", &brick_count, brick_key);
rsp_ctx = data;
new_value = data_copy (value);
GF_ASSERT (new_value);
snprintf (new_key, sizeof (new_key), "%d%s",
rsp_ctx->count + brick_count, brick_key);
dict_set (rsp_ctx->dict, new_key, new_value);
return 0;
}
int
glusterd_profile_volume_use_rsp_dict (dict_t *rsp_dict)
{
int ret = 0;
glusterd_pr_brick_rsp_conv_t rsp_ctx = {0};
int32_t brick_count = 0;
int32_t count = 0;
dict_t *ctx_dict = NULL;
glusterd_op_t op = GD_OP_NONE;
GF_ASSERT (rsp_dict);
ret = dict_get_int32 (rsp_dict, "count", &brick_count);
if (ret) {
ret = 0; //no bricks in the rsp
goto out;
}
op = glusterd_op_get_op ();
GF_ASSERT (GD_OP_PROFILE_VOLUME == op);
ctx_dict = glusterd_op_get_ctx ();
ret = dict_get_int32 (ctx_dict, "count", &count);
rsp_ctx.count = count;
rsp_ctx.dict = ctx_dict;
dict_foreach (rsp_dict, _profile_volume_add_friend_rsp, &rsp_ctx);
dict_del (ctx_dict, "count");
ret = dict_set_int32 (ctx_dict, "count", count + brick_count);
out:
return ret;
}
int
glusterd_volume_status_add_peer_rsp (dict_t *this, char *key, data_t *value,
void *data)
{
glusterd_status_rsp_conv_t *rsp_ctx = NULL;
data_t *new_value = NULL;
char brick_key[1024] = {0,};
char new_key[1024] = {0,};
int32_t index = 0;
int32_t ret = 0;
/* Skip the following keys, they are already present in the ctx_dict */
if (!strcmp (key, "count") || !strcmp (key, "cmd") ||
!strcmp (key, "brick-index-max") || !strcmp (key, "other-count"))
return 0;
rsp_ctx = data;
new_value = data_copy (value);
GF_ASSERT (new_value);
sscanf (key, "brick%d.%s", &index, brick_key);
if (index > rsp_ctx->brick_index_max) {
snprintf (new_key, sizeof (new_key), "brick%d.%s",
index + rsp_ctx->other_count, brick_key);
} else {
strncpy (new_key, key, sizeof (new_key));
new_key[sizeof (new_key) - 1] = 0;
}
ret = dict_set (rsp_ctx->dict, new_key, new_value);
if (ret)
gf_log ("", GF_LOG_ERROR, "Unable to set key: %s in dict",
key);
return 0;
}
int
glusterd_volume_status_copy_to_op_ctx_dict (dict_t *rsp_dict)
{
int ret = 0;
glusterd_status_rsp_conv_t rsp_ctx = {0};
int32_t node_count = 0;
int32_t rsp_node_count = 0;
int32_t brick_index_max = -1;
int32_t other_count = 0;
int32_t rsp_other_count = 0;
dict_t *ctx_dict = NULL;
glusterd_op_t op = GD_OP_NONE;
GF_ASSERT (rsp_dict);
ret = dict_get_int32 (rsp_dict, "count", &rsp_node_count);
if (ret) {
ret = 0; //no bricks in the rsp
goto out;
}
ret = dict_get_int32 (rsp_dict, "other-count", &rsp_other_count);
if (ret) {
gf_log (THIS->name, GF_LOG_ERROR,
"Failed to get other count from rsp_dict");
goto out;
}
op = glusterd_op_get_op ();
GF_ASSERT (GD_OP_STATUS_VOLUME == op);
ctx_dict = glusterd_op_get_ctx (op);
ret = dict_get_int32 (ctx_dict, "count", &node_count);
ret = dict_get_int32 (ctx_dict, "brick-index-max", &brick_index_max);
ret = dict_get_int32 (ctx_dict, "other-count", &other_count);
rsp_ctx.count = node_count;
rsp_ctx.brick_index_max = brick_index_max;
rsp_ctx.other_count = other_count;
rsp_ctx.dict = ctx_dict;
dict_foreach (rsp_dict, glusterd_volume_status_add_peer_rsp, &rsp_ctx);
ret = dict_set_int32 (ctx_dict, "count", node_count + rsp_node_count);
if (ret) {
gf_log (THIS->name, GF_LOG_ERROR,
"Failed to update node count");
goto out;
}
ret = dict_set_int32 (ctx_dict, "other-count",
(other_count + rsp_other_count));
if (ret)
gf_log (THIS->name, GF_LOG_ERROR,
"Failed to update other-count");
out:
return ret;
}
int
glusterd_volume_rebalance_use_rsp_dict (dict_t *rsp_dict)
{
int ret = 0;
dict_t *ctx_dict = NULL;
glusterd_op_t op = GD_OP_NONE;
uint64_t value = 0;
int32_t value32 = 0;
char *volname = NULL;
glusterd_volinfo_t *volinfo = NULL;
char key[256] = {0,};
int32_t index = 0;
int32_t i = 0;
char *node_uuid = NULL;
char *node_uuid_str = NULL;
double elapsed_time = 0;
GF_ASSERT (rsp_dict);
op = glusterd_op_get_op ();
GF_ASSERT ((GD_OP_REBALANCE == op) ||
(GD_OP_DEFRAG_BRICK_VOLUME == op));
ctx_dict = glusterd_op_get_ctx (op);
if (!ctx_dict)
goto out;
ret = dict_get_int32 (ctx_dict, "count", &i);
i++;
ret = dict_set_int32 (ctx_dict, "count", i);
if (ret)
gf_log ("", GF_LOG_ERROR, "Failed to set index");
ret = dict_get_str (ctx_dict, "volname", &volname);
if (ret) {
gf_log ("", GF_LOG_ERROR, "Unable to get volume name");
goto out;
}
ret = glusterd_volinfo_find (volname, &volinfo);
if (ret)
goto out;
ret = dict_get_int32 (rsp_dict, "count", &index);
if (ret)
gf_log ("", GF_LOG_ERROR, "failed to get index");
snprintf (key, 256, "files-%d", index);
ret = dict_get_uint64 (rsp_dict, key, &value);
if (!ret) {
memset (key, 0, 256);
snprintf (key, 256, "files-%d", i);
ret = dict_set_uint64 (ctx_dict, key, value);
if (ret) {
gf_log (THIS->name, GF_LOG_DEBUG,
"failed to set the file count");
}
}
memset (key, 0, 256);
snprintf (key, 256, "size-%d", index);
ret = dict_get_uint64 (rsp_dict, key, &value);
if (!ret) {
memset (key, 0, 256);
snprintf (key, 256, "size-%d", i);
ret = dict_set_uint64 (ctx_dict, key, value);
if (ret) {
gf_log (THIS->name, GF_LOG_DEBUG,
"failed to set the size of migration");
}
}
memset (key, 0, 256);
snprintf (key, 256, "lookups-%d", index);
ret = dict_get_uint64 (rsp_dict, key, &value);
if (!ret) {
memset (key, 0, 256);
snprintf (key, 256, "lookups-%d", i);
ret = dict_set_uint64 (ctx_dict, key, value);
if (ret) {
gf_log (THIS->name, GF_LOG_DEBUG,
"failed to set lookuped file count");
}
}
memset (key, 0, 256);
snprintf (key, 256, "status-%d", index);
ret = dict_get_int32 (rsp_dict, key, &value32);
if (!ret) {
memset (key, 0, 256);
snprintf (key, 256, "status-%d", i);
ret = dict_set_int32 (ctx_dict, key, value32);
if (ret) {
gf_log (THIS->name, GF_LOG_DEBUG,
"failed to set status");
}
}
memset (key, 0, 256);
snprintf (key, 256, "node-uuid-%d", index);
ret = dict_get_str (rsp_dict, key, &node_uuid);
if (!ret) {
memset (key, 0, 256);
snprintf (key, 256, "node-uuid-%d", i);
node_uuid_str = gf_strdup (node_uuid);
ret = dict_set_dynstr (ctx_dict, key, node_uuid_str);
if (ret) {
gf_log (THIS->name, GF_LOG_DEBUG,
"failed to set node-uuid");
}
}
memset (key, 0, 256);
snprintf (key, 256, "failures-%d", index);
ret = dict_get_uint64 (rsp_dict, key, &value);
if (!ret) {
memset (key, 0, 256);
snprintf (key, 256, "failures-%d", i);
ret = dict_set_uint64 (ctx_dict, key, value);
if (ret) {
gf_log (THIS->name, GF_LOG_DEBUG,
"failed to set failure count");
}
}
memset (key, 0, 256);
snprintf (key, 256, "run-time-%d", index);
ret = dict_get_double (rsp_dict, key, &elapsed_time);
if (!ret) {
memset (key, 0, 256);
snprintf (key, 256, "run-time-%d", i);
ret = dict_set_double (ctx_dict, key, elapsed_time);
if (ret) {
gf_log (THIS->name, GF_LOG_DEBUG,
"failed to set run-time");
}
}
ret = 0;
out:
return ret;
}
int
glusterd_volume_heal_use_rsp_dict (dict_t *rsp_dict)
{
int ret = 0;
dict_t *ctx_dict = NULL;
glusterd_op_t op = GD_OP_NONE;
GF_ASSERT (rsp_dict);
op = glusterd_op_get_op ();
GF_ASSERT (GD_OP_HEAL_VOLUME == op);
ctx_dict = glusterd_op_get_ctx (op);
if (!ctx_dict)
goto out;
dict_copy (rsp_dict, ctx_dict);
out:
return ret;
}
int32_t
glusterd_commit_op_cbk (struct rpc_req *req, struct iovec *iov,
int count, void *myframe)
@ -1351,44 +827,44 @@ glusterd_commit_op_cbk (struct rpc_req *req, struct iovec *iov,
event_type = GD_OP_EVENT_RCVD_ACC;
switch (rsp.op) {
case GD_OP_REPLACE_BRICK:
ret = glusterd_rb_use_rsp_dict (dict);
ret = glusterd_rb_use_rsp_dict (NULL, dict);
if (ret)
goto out;
break;
case GD_OP_SYNC_VOLUME:
ret = glusterd_sync_use_rsp_dict (dict);
ret = glusterd_sync_use_rsp_dict (NULL, dict);
if (ret)
goto out;
break;
case GD_OP_PROFILE_VOLUME:
ret = glusterd_profile_volume_use_rsp_dict (dict);
ret = glusterd_profile_volume_use_rsp_dict (NULL, dict);
if (ret)
goto out;
break;
case GD_OP_GSYNC_SET:
ret = glusterd_gsync_use_rsp_dict (dict, rsp.op_errstr);
ret = glusterd_gsync_use_rsp_dict (NULL, dict, rsp.op_errstr);
if (ret)
goto out;
break;
case GD_OP_STATUS_VOLUME:
ret = glusterd_volume_status_copy_to_op_ctx_dict (dict);
ret = glusterd_volume_status_copy_to_op_ctx_dict (NULL, dict);
if (ret)
goto out;
break;
case GD_OP_REBALANCE:
case GD_OP_DEFRAG_BRICK_VOLUME:
ret = glusterd_volume_rebalance_use_rsp_dict (dict);
ret = glusterd_volume_rebalance_use_rsp_dict (NULL, dict);
if (ret)
goto out;
break;
case GD_OP_HEAL_VOLUME:
ret = glusterd_volume_heal_use_rsp_dict (dict);
ret = glusterd_volume_heal_use_rsp_dict (NULL, dict);
if (ret)
goto out;

View File

@ -5750,3 +5750,560 @@ glusterd_to_cli (rpcsvc_request_t *req, gf_cli_rsp *arg, struct iovec *payload,
return ret;
}
static int32_t
glusterd_append_gsync_status (dict_t *dst, dict_t *src)
{
int ret = 0;
char *stop_msg = NULL;
ret = dict_get_str (src, "gsync-status", &stop_msg);
if (ret) {
ret = 0;
goto out;
}
ret = dict_set_dynstr (dst, "gsync-status", gf_strdup (stop_msg));
if (ret) {
gf_log ("glusterd", GF_LOG_WARNING, "Unable to set the stop"
"message in the ctx dictionary");
goto out;
}
ret = 0;
out:
gf_log ("glusterd", GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
static int32_t
glusterd_append_status_dicts (dict_t *dst, dict_t *src)
{
int dst_count = 0;
int src_count = 0;
int i = 0;
int ret = 0;
char mst[PATH_MAX] = {0,};
char slv[PATH_MAX] = {0, };
char sts[PATH_MAX] = {0, };
char *mst_val = NULL;
char *slv_val = NULL;
char *sts_val = NULL;
GF_ASSERT (dst);
if (src == NULL)
goto out;
ret = dict_get_int32 (dst, "gsync-count", &dst_count);
if (ret)
dst_count = 0;
ret = dict_get_int32 (src, "gsync-count", &src_count);
if (ret || !src_count) {
gf_log ("", GF_LOG_DEBUG, "Source brick empty");
ret = 0;
goto out;
}
for (i = 1; i <= src_count; i++) {
snprintf (mst, sizeof(mst), "master%d", i);
snprintf (slv, sizeof(slv), "slave%d", i);
snprintf (sts, sizeof(sts), "status%d", i);
ret = dict_get_str (src, mst, &mst_val);
if (ret)
goto out;
ret = dict_get_str (src, slv, &slv_val);
if (ret)
goto out;
ret = dict_get_str (src, sts, &sts_val);
if (ret)
goto out;
snprintf (mst, sizeof(mst), "master%d", i+dst_count);
snprintf (slv, sizeof(slv), "slave%d", i+dst_count);
snprintf (sts, sizeof(sts), "status%d", i+dst_count);
ret = dict_set_dynstr (dst, mst, gf_strdup (mst_val));
if (ret)
goto out;
ret = dict_set_dynstr (dst, slv, gf_strdup (slv_val));
if (ret)
goto out;
ret = dict_set_dynstr (dst, sts, gf_strdup (sts_val));
if (ret)
goto out;
}
ret = dict_set_int32 (dst, "gsync-count", dst_count+src_count);
out:
gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
int32_t
glusterd_gsync_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict, char *op_errstr)
{
dict_t *ctx = NULL;
int ret = 0;
if (aggr) {
ctx = aggr;
} else {
ctx = glusterd_op_get_ctx ();
if (!ctx) {
gf_log ("", GF_LOG_ERROR,
"Operation Context is not present");
GF_ASSERT (0);
}
}
if (rsp_dict) {
ret = glusterd_append_status_dicts (ctx, rsp_dict);
if (ret)
goto out;
ret = glusterd_append_gsync_status (ctx, rsp_dict);
if (ret)
goto out;
}
if (strcmp ("", op_errstr)) {
ret = dict_set_dynstr (ctx, "errstr", gf_strdup(op_errstr));
if (ret)
goto out;
}
ret = 0;
out:
gf_log ("", GF_LOG_DEBUG, "Returning %d ", ret);
return ret;
}
int32_t
glusterd_rb_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict)
{
int32_t src_port = 0;
int32_t dst_port = 0;
int ret = 0;
dict_t *ctx = NULL;
if (aggr) {
ctx = aggr;
} else {
ctx = glusterd_op_get_ctx ();
if (!ctx) {
gf_log ("", GF_LOG_ERROR,
"Operation Context is not present");
GF_ASSERT (0);
}
}
if (rsp_dict) {
ret = dict_get_int32 (rsp_dict, "src-brick-port", &src_port);
if (ret == 0) {
gf_log ("", GF_LOG_DEBUG,
"src-brick-port=%d found", src_port);
}
ret = dict_get_int32 (rsp_dict, "dst-brick-port", &dst_port);
if (ret == 0) {
gf_log ("", GF_LOG_DEBUG,
"dst-brick-port=%d found", dst_port);
}
}
if (src_port) {
ret = dict_set_int32 (ctx, "src-brick-port",
src_port);
if (ret) {
gf_log ("", GF_LOG_DEBUG,
"Could not set src-brick");
goto out;
}
}
if (dst_port) {
ret = dict_set_int32 (ctx, "dst-brick-port",
dst_port);
if (ret) {
gf_log ("", GF_LOG_DEBUG,
"Could not set dst-brick");
goto out;
}
}
out:
return ret;
}
int32_t
glusterd_sync_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict)
{
int ret = 0;
GF_ASSERT (rsp_dict);
if (!rsp_dict) {
goto out;
}
ret = glusterd_import_friend_volumes (rsp_dict);
out:
return ret;
}
static int
_profile_volume_add_friend_rsp (dict_t *this, char *key, data_t *value,
void *data)
{
char new_key[256] = {0};
glusterd_pr_brick_rsp_conv_t *rsp_ctx = NULL;
data_t *new_value = NULL;
int brick_count = 0;
char brick_key[256];
if (strcmp (key, "count") == 0)
return 0;
sscanf (key, "%d%s", &brick_count, brick_key);
rsp_ctx = data;
new_value = data_copy (value);
GF_ASSERT (new_value);
snprintf (new_key, sizeof (new_key), "%d%s",
rsp_ctx->count + brick_count, brick_key);
dict_set (rsp_ctx->dict, new_key, new_value);
return 0;
}
int
glusterd_profile_volume_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict)
{
int ret = 0;
glusterd_pr_brick_rsp_conv_t rsp_ctx = {0};
int32_t brick_count = 0;
int32_t count = 0;
dict_t *ctx_dict = NULL;
glusterd_op_t op = GD_OP_NONE;
GF_ASSERT (rsp_dict);
ret = dict_get_int32 (rsp_dict, "count", &brick_count);
if (ret) {
ret = 0; //no bricks in the rsp
goto out;
}
op = glusterd_op_get_op ();
GF_ASSERT (GD_OP_PROFILE_VOLUME == op);
if (aggr) {
ctx_dict = aggr;
} else {
ctx_dict = glusterd_op_get_ctx ();
}
ret = dict_get_int32 (ctx_dict, "count", &count);
rsp_ctx.count = count;
rsp_ctx.dict = ctx_dict;
dict_foreach (rsp_dict, _profile_volume_add_friend_rsp, &rsp_ctx);
dict_del (ctx_dict, "count");
ret = dict_set_int32 (ctx_dict, "count", count + brick_count);
out:
return ret;
}
static int
glusterd_volume_status_add_peer_rsp (dict_t *this, char *key, data_t *value,
void *data)
{
glusterd_status_rsp_conv_t *rsp_ctx = NULL;
data_t *new_value = NULL;
char brick_key[1024] = {0,};
char new_key[1024] = {0,};
int32_t index = 0;
int32_t ret = 0;
/* Skip the following keys, they are already present in the ctx_dict */
if (!strcmp (key, "count") || !strcmp (key, "cmd") ||
!strcmp (key, "brick-index-max") || !strcmp (key, "other-count"))
return 0;
rsp_ctx = data;
new_value = data_copy (value);
GF_ASSERT (new_value);
sscanf (key, "brick%d.%s", &index, brick_key);
if (index > rsp_ctx->brick_index_max) {
snprintf (new_key, sizeof (new_key), "brick%d.%s",
index + rsp_ctx->other_count, brick_key);
} else {
strncpy (new_key, key, sizeof (new_key));
new_key[sizeof (new_key) - 1] = 0;
}
ret = dict_set (rsp_ctx->dict, new_key, new_value);
if (ret)
gf_log ("", GF_LOG_ERROR, "Unable to set key: %s in dict",
key);
return 0;
}
int
glusterd_volume_status_copy_to_op_ctx_dict (dict_t *aggr, dict_t *rsp_dict)
{
int ret = 0;
glusterd_status_rsp_conv_t rsp_ctx = {0};
int32_t node_count = 0;
int32_t rsp_node_count = 0;
int32_t brick_index_max = -1;
int32_t other_count = 0;
int32_t rsp_other_count = 0;
dict_t *ctx_dict = NULL;
glusterd_op_t op = GD_OP_NONE;
GF_ASSERT (rsp_dict);
ret = dict_get_int32 (rsp_dict, "count", &rsp_node_count);
if (ret) {
ret = 0; //no bricks in the rsp
goto out;
}
ret = dict_get_int32 (rsp_dict, "other-count", &rsp_other_count);
if (ret) {
gf_log (THIS->name, GF_LOG_ERROR,
"Failed to get other count from rsp_dict");
goto out;
}
op = glusterd_op_get_op ();
GF_ASSERT (GD_OP_STATUS_VOLUME == op);
if (aggr) {
ctx_dict = aggr;
} else {
ctx_dict = glusterd_op_get_ctx (op);
}
ret = dict_get_int32 (ctx_dict, "count", &node_count);
ret = dict_get_int32 (ctx_dict, "brick-index-max", &brick_index_max);
ret = dict_get_int32 (ctx_dict, "other-count", &other_count);
rsp_ctx.count = node_count;
rsp_ctx.brick_index_max = brick_index_max;
rsp_ctx.other_count = other_count;
rsp_ctx.dict = ctx_dict;
dict_foreach (rsp_dict, glusterd_volume_status_add_peer_rsp, &rsp_ctx);
ret = dict_set_int32 (ctx_dict, "count", node_count + rsp_node_count);
if (ret) {
gf_log (THIS->name, GF_LOG_ERROR,
"Failed to update node count");
goto out;
}
ret = dict_set_int32 (ctx_dict, "other-count",
(other_count + rsp_other_count));
if (ret)
gf_log (THIS->name, GF_LOG_ERROR,
"Failed to update other-count");
out:
return ret;
}
int
glusterd_volume_rebalance_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict)
{
int ret = 0;
dict_t *ctx_dict = NULL;
glusterd_op_t op = GD_OP_NONE;
uint64_t value = 0;
int32_t value32 = 0;
char *volname = NULL;
glusterd_volinfo_t *volinfo = NULL;
char key[256] = {0,};
int32_t index = 0;
int32_t i = 0;
char *node_uuid = NULL;
char *node_uuid_str = NULL;
double elapsed_time = 0;
GF_ASSERT (rsp_dict);
op = glusterd_op_get_op ();
GF_ASSERT ((GD_OP_REBALANCE == op) ||
(GD_OP_DEFRAG_BRICK_VOLUME == op));
if (aggr) {
ctx_dict = aggr;
} else {
ctx_dict = glusterd_op_get_ctx (op);
}
if (!ctx_dict)
goto out;
ret = dict_get_int32 (ctx_dict, "count", &i);
i++;
ret = dict_set_int32 (ctx_dict, "count", i);
if (ret)
gf_log ("", GF_LOG_ERROR, "Failed to set index");
ret = dict_get_str (ctx_dict, "volname", &volname);
if (ret) {
gf_log ("", GF_LOG_ERROR, "Unable to get volume name");
goto out;
}
ret = glusterd_volinfo_find (volname, &volinfo);
if (ret)
goto out;
ret = dict_get_int32 (rsp_dict, "count", &index);
if (ret)
gf_log ("", GF_LOG_ERROR, "failed to get index");
snprintf (key, 256, "files-%d", index);
ret = dict_get_uint64 (rsp_dict, key, &value);
if (!ret) {
memset (key, 0, 256);
snprintf (key, 256, "files-%d", i);
ret = dict_set_uint64 (ctx_dict, key, value);
if (ret) {
gf_log (THIS->name, GF_LOG_DEBUG,
"failed to set the file count");
}
}
memset (key, 0, 256);
snprintf (key, 256, "size-%d", index);
ret = dict_get_uint64 (rsp_dict, key, &value);
if (!ret) {
memset (key, 0, 256);
snprintf (key, 256, "size-%d", i);
ret = dict_set_uint64 (ctx_dict, key, value);
if (ret) {
gf_log (THIS->name, GF_LOG_DEBUG,
"failed to set the size of migration");
}
}
memset (key, 0, 256);
snprintf (key, 256, "lookups-%d", index);
ret = dict_get_uint64 (rsp_dict, key, &value);
if (!ret) {
memset (key, 0, 256);
snprintf (key, 256, "lookups-%d", i);
ret = dict_set_uint64 (ctx_dict, key, value);
if (ret) {
gf_log (THIS->name, GF_LOG_DEBUG,
"failed to set lookuped file count");
}
}
memset (key, 0, 256);
snprintf (key, 256, "status-%d", index);
ret = dict_get_int32 (rsp_dict, key, &value32);
if (!ret) {
memset (key, 0, 256);
snprintf (key, 256, "status-%d", i);
ret = dict_set_int32 (ctx_dict, key, value32);
if (ret) {
gf_log (THIS->name, GF_LOG_DEBUG,
"failed to set status");
}
}
memset (key, 0, 256);
snprintf (key, 256, "node-uuid-%d", index);
ret = dict_get_str (rsp_dict, key, &node_uuid);
if (!ret) {
memset (key, 0, 256);
snprintf (key, 256, "node-uuid-%d", i);
node_uuid_str = gf_strdup (node_uuid);
ret = dict_set_dynstr (ctx_dict, key, node_uuid_str);
if (ret) {
gf_log (THIS->name, GF_LOG_DEBUG,
"failed to set node-uuid");
}
}
memset (key, 0, 256);
snprintf (key, 256, "failures-%d", index);
ret = dict_get_uint64 (rsp_dict, key, &value);
if (!ret) {
memset (key, 0, 256);
snprintf (key, 256, "failures-%d", i);
ret = dict_set_uint64 (ctx_dict, key, value);
if (ret) {
gf_log (THIS->name, GF_LOG_DEBUG,
"failed to set failure count");
}
}
memset (key, 0, 256);
snprintf (key, 256, "run-time-%d", index);
ret = dict_get_double (rsp_dict, key, &elapsed_time);
if (!ret) {
memset (key, 0, 256);
snprintf (key, 256, "run-time-%d", i);
ret = dict_set_double (ctx_dict, key, elapsed_time);
if (ret) {
gf_log (THIS->name, GF_LOG_DEBUG,
"failed to set run-time");
}
}
ret = 0;
out:
return ret;
}
int
glusterd_volume_heal_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict)
{
int ret = 0;
dict_t *ctx_dict = NULL;
glusterd_op_t op = GD_OP_NONE;
GF_ASSERT (rsp_dict);
op = glusterd_op_get_op ();
GF_ASSERT (GD_OP_HEAL_VOLUME == op);
if (aggr) {
ctx_dict = aggr;
} else {
ctx_dict = glusterd_op_get_ctx (op);
}
if (!ctx_dict)
goto out;
dict_copy (rsp_dict, ctx_dict);
out:
return ret;
}

View File

@ -440,4 +440,19 @@ void
glusterd_volinfo_reset_defrag_stats (glusterd_volinfo_t *volinfo);
int
glusterd_volset_help (dict_t *dict, char **op_errstr);
int32_t
glusterd_sync_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict);
int32_t
glusterd_gsync_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict, char *op_errstr);
int32_t
glusterd_rb_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict);
int
glusterd_profile_volume_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict);
int
glusterd_volume_status_copy_to_op_ctx_dict (dict_t *aggr, dict_t *rsp_dict);
int
glusterd_volume_rebalance_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict);
int
glusterd_volume_heal_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict);
#endif