summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/mgmt')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c31
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-sm.c63
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-sm.h17
-rw-r--r--xlators/mgmt/glusterd/src/glusterd3_1-mops.c57
4 files changed, 141 insertions, 27 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index 67b4ab62c1c..39c1d59240e 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -2041,6 +2041,27 @@ out:
return ret;
}
+
+int
+glusterd_handle_friend_update_delete (dict_t *dict)
+{
+ char *hostname = NULL;
+ int32_t ret = -1;
+
+ GF_ASSERT (dict);
+
+ ret = dict_get_str (dict, "hostname", &hostname);
+ if (ret)
+ goto out;
+
+ ret = glusterd_friend_remove (NULL, hostname);
+
+out:
+ gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ return ret;
+}
+
+
int
glusterd_handle_friend_update (rpcsvc_request_t *req)
{
@@ -2060,6 +2081,7 @@ glusterd_handle_friend_update (rpcsvc_request_t *req)
int count = 0;
uuid_t uuid = {0,};
glusterd_peerctx_args_t args = {0};
+ int32_t op = 0;
GF_ASSERT (req);
@@ -2099,6 +2121,15 @@ glusterd_handle_friend_update (rpcsvc_request_t *req)
if (ret)
goto out;
+ ret = dict_get_int32 (dict, "op", &op);
+ if (ret)
+ goto out;
+
+ if (GD_FRIEND_UPDATE_DEL == op) {
+ ret = glusterd_handle_friend_update_delete (dict);
+ goto out;
+ }
+
args.mode = GD_MODE_SWITCH_ON;
while ( i <= count) {
snprintf (key, sizeof (key), "friend%d.uuid", i);
diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.c b/xlators/mgmt/glusterd/src/glusterd-sm.c
index fbe8430348a..268ccaff42e 100644
--- a/xlators/mgmt/glusterd/src/glusterd-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-sm.c
@@ -89,8 +89,58 @@ glusterd_destroy_friend_req_ctx (glusterd_friend_req_ctx_t *ctx)
GF_FREE (ctx);
}
-#define glusterd_destroy_friend_update_ctx(ctx)\
- glusterd_destroy_friend_req_ctx(ctx)
+void
+glusterd_destroy_friend_update_ctx (glusterd_friend_update_ctx_t *ctx)
+{
+ if (!ctx)
+ return;
+ if (ctx->hostname)
+ GF_FREE (ctx->hostname);
+ GF_FREE (ctx);
+}
+
+int
+glusterd_broadcast_friend_delete (char *hostname, uuid_t uuid)
+{
+ int ret = 0;
+ rpc_clnt_procedure_t *proc = NULL;
+ call_frame_t *frame = NULL;
+ glusterd_conf_t *conf = NULL;
+ xlator_t *this = NULL;
+ glusterd_friend_update_ctx_t *ctx = NULL;
+
+ this = THIS;
+ conf = this->private;
+
+ GF_ASSERT (conf);
+ GF_ASSERT (conf->mgmt);
+
+ ctx = GF_CALLOC (1, sizeof (*ctx),
+ gf_gld_mt_friend_update_ctx_t);
+
+ if (!ctx) {
+ ret = -1;
+ goto out;
+ }
+
+ ctx->hostname = gf_strdup (hostname);
+ ctx->op = GD_FRIEND_UPDATE_DEL;
+ proc = &conf->mgmt->proctable[GD_MGMT_FRIEND_UPDATE];
+ if (proc->fn) {
+ frame = create_frame (this, this->ctx->pool);
+ if (!frame) {
+ goto out;
+ }
+ frame->local = ctx;
+ ret = proc->fn (frame, this, ctx);
+ }
+
+out:
+ gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);
+
+ return ret;
+}
+
static int
glusterd_ac_none (glusterd_friend_sm_event_t *event, void *ctx)
@@ -305,7 +355,7 @@ glusterd_ac_send_friend_update (glusterd_friend_sm_event_t *event, void *ctx)
call_frame_t *frame = NULL;
glusterd_conf_t *conf = NULL;
xlator_t *this = NULL;
-
+ glusterd_friend_update_ctx_t *ev_ctx = NULL;
GF_ASSERT (event);
peerinfo = event->peerinfo;
@@ -315,6 +365,9 @@ glusterd_ac_send_friend_update (glusterd_friend_sm_event_t *event, void *ctx)
GF_ASSERT (conf);
GF_ASSERT (conf->mgmt);
+ ev_ctx = ctx;
+
+ ev_ctx->op = GD_FRIEND_UPDATE_ADD;
proc = &conf->mgmt->proctable[GD_MGMT_FRIEND_UPDATE];
if (proc->fn) {
@@ -323,7 +376,7 @@ glusterd_ac_send_friend_update (glusterd_friend_sm_event_t *event, void *ctx)
goto out;
}
frame->local = ctx;
- ret = proc->fn (frame, this, event);
+ ret = proc->fn (frame, this, ctx);
}
out:
@@ -377,7 +430,6 @@ glusterd_ac_friend_remove (glusterd_friend_sm_event_t *event, void *ctx)
gf_log ("", GF_LOG_ERROR, "Cleanup returned: %d", ret);
}
-
return 0;
}
@@ -444,6 +496,7 @@ glusterd_ac_handle_friend_add_req (glusterd_friend_sm_event_t *event, void *ctx)
uuid_copy (new_ev_ctx->uuid, ev_ctx->uuid);
new_ev_ctx->hostname = gf_strdup (ev_ctx->hostname);
+ new_ev_ctx->op = GD_FRIEND_UPDATE_ADD;
new_event->ctx = new_ev_ctx;
diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.h b/xlators/mgmt/glusterd/src/glusterd-sm.h
index 72dca811e69..5828f05e34e 100644
--- a/xlators/mgmt/glusterd/src/glusterd-sm.h
+++ b/xlators/mgmt/glusterd/src/glusterd-sm.h
@@ -117,6 +117,13 @@ typedef enum glusterd_friend_sm_event_type_ {
} glusterd_friend_sm_event_type_t;
+typedef enum glusterd_friend_update_op_ {
+ GD_FRIEND_UPDATE_NONE = 0,
+ GD_FRIEND_UPDATE_ADD,
+ GD_FRIEND_UPDATE_DEL,
+} glusterd_friend_update_op_t;
+
+
struct glusterd_friend_sm_event_ {
struct list_head list;
glusterd_peerinfo_t *peerinfo;
@@ -141,7 +148,11 @@ typedef struct glusterd_friend_req_ctx_ {
dict_t *vols;
} glusterd_friend_req_ctx_t;
-typedef glusterd_friend_req_ctx_t glusterd_friend_update_ctx_t;
+typedef struct glusterd_friend_update_ctx_ {
+ uuid_t uuid;
+ char *hostname;
+ int op;
+} glusterd_friend_update_ctx_t;
typedef struct glusterd_probe_ctx_ {
char *hostname;
@@ -165,6 +176,10 @@ glusterd_destroy_probe_ctx (glusterd_probe_ctx_t *ctx);
void
glusterd_destroy_friend_req_ctx (glusterd_friend_req_ctx_t *ctx);
+
char*
glusterd_friend_sm_state_name_get (glusterd_friend_sm_state_t state);
+
+int
+glusterd_broadcast_friend_delete (char *hostname, uuid_t uuid);
#endif
diff --git a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
index 76b8b9987b6..a92ccf4c55c 100644
--- a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
+++ b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
@@ -327,8 +327,10 @@ respond:
glusterd_op_sm ();
}
- if (ctx)
+ if (ctx) {
+ glusterd_broadcast_friend_delete (ctx->hostname, NULL);
glusterd_destroy_probe_ctx (ctx);
+ }
if (rsp.hostname)
free (rsp.hostname);//malloced by xdr
@@ -342,7 +344,7 @@ glusterd3_1_friend_update_cbk (struct rpc_req *req, struct iovec *iov,
{
gd1_mgmt_cluster_lock_rsp rsp = {{0},};
int ret = -1;
- int32_t op_ret = -1;
+ int32_t op_ret = 0;
char str[50] = {0,};
GF_ASSERT (req);
@@ -372,6 +374,7 @@ out:
GLUSTERD_STACK_DESTROY (((call_frame_t *)myframe));
return ret;
}
+
int32_t
glusterd3_1_cluster_lock_cbk (struct rpc_req *req, struct iovec *iov,
int count, void *myframe)
@@ -875,8 +878,7 @@ glusterd3_1_friend_remove (call_frame_t *frame, xlator_t *this,
GD_MGMT_FRIEND_REMOVE,
NULL, gd_xdr_from_mgmt_friend_req,
this, glusterd3_1_friend_remove_cbk);
- }
- if (ret) {
+ } else {
event_type = GD_FRIEND_EVENT_REMOVE_FRIEND;
ret = glusterd_friend_sm_new_event (event_type, &new_event);
@@ -888,13 +890,17 @@ glusterd3_1_friend_remove (call_frame_t *frame, xlator_t *this,
gf_log ("glusterd", GF_LOG_ERROR,
"Unable to get event");
}
+
if (ctx)
ret = glusterd_xfer_cli_deprobe_resp (ctx->req, ret, 0,
ctx->hostname);
glusterd_friend_sm ();
glusterd_op_sm ();
- if (ctx)
+
+ if (ctx) {
+ glusterd_broadcast_friend_delete (ctx->hostname, NULL);
glusterd_destroy_probe_ctx (ctx);
+ }
}
out:
@@ -911,7 +917,6 @@ glusterd3_1_friend_update (call_frame_t *frame, xlator_t *this,
int ret = 0;
glusterd_peerinfo_t *peerinfo = NULL;
glusterd_conf_t *priv = NULL;
- glusterd_friend_sm_event_t *event = NULL;
glusterd_friend_update_ctx_t *ctx = NULL;
dict_t *friends = NULL;
char key[100] = {0,};
@@ -928,36 +933,47 @@ glusterd3_1_friend_update (call_frame_t *frame, xlator_t *this,
goto out;
}
+ ctx = data;
friends = dict_new ();
if (!friends)
goto out;
- event = data;
priv = this->private;
GF_ASSERT (priv);
- list_for_each_entry (peerinfo, &priv->peers, uuid_list) {
- count++;
- uuid_unparse (peerinfo->uuid, uuid_buf);
- snprintf (key, sizeof (key), "friend%d.uuid", count);
- dup_buf = gf_strdup (uuid_buf);
- ret = dict_set_dynstr (friends, key, dup_buf);
- if (ret)
- goto out;
- snprintf (key, sizeof (key), "friend%d.hostname", count);
- ret = dict_set_str (friends, key, peerinfo->hostname);
+ snprintf (key, sizeof (key), "op");
+ ret = dict_set_int32 (friends, key, ctx->op);
+ if (ret)
+ goto out;
+
+ if (GD_FRIEND_UPDATE_ADD == ctx->op) {
+ list_for_each_entry (peerinfo, &priv->peers, uuid_list) {
+ count++;
+ uuid_unparse (peerinfo->uuid, uuid_buf);
+ snprintf (key, sizeof (key), "friend%d.uuid", count);
+ dup_buf = gf_strdup (uuid_buf);
+ ret = dict_set_dynstr (friends, key, dup_buf);
+ if (ret)
+ goto out;
+ snprintf (key, sizeof (key), "friend%d.hostname", count);
+ ret = dict_set_str (friends, key, peerinfo->hostname);
+ if (ret)
+ goto out;
+ gf_log ("", GF_LOG_NORMAL, "Added uuid: %s, host: %s",
+ dup_buf, peerinfo->hostname);
+ }
+ } else {
+ snprintf (key, sizeof (key), "hostname");
+ ret = dict_set_str (friends, key, ctx->hostname);
if (ret)
goto out;
- gf_log ("", GF_LOG_NORMAL, "Added uuid: %s, host: %s",
- dup_buf, peerinfo->hostname);
}
ret = dict_set_int32 (friends, "count", count);
if (ret)
goto out;
- ctx = event->ctx;
ret = dict_allocate_and_serialize (friends, &dict_buf, (size_t *)&len);
@@ -967,7 +983,6 @@ glusterd3_1_friend_update (call_frame_t *frame, xlator_t *this,
req.friends.friends_val = dict_buf;
req.friends.friends_len = len;
- peerinfo = event->peerinfo;
uuid_copy (req.uuid, priv->uuid);
list_for_each_entry (peerinfo, &priv->peers, uuid_list) {