summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-handshake.c
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-handshake.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handshake.c120
1 files changed, 94 insertions, 26 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handshake.c b/xlators/mgmt/glusterd/src/glusterd-handshake.c
index 611e9fbf545..ddb1403b391 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handshake.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handshake.c
@@ -975,9 +975,11 @@ gd_validate_mgmt_hndsk_req (rpcsvc_request_t *req)
if (ret)
return _gf_false;
- peer = glusterd_peerinfo_find (NULL, hostname);
- if (peer == NULL) {
- ret = -1;
+ rcu_read_lock ();
+ ret = (glusterd_peerinfo_find (NULL, hostname) == NULL);
+ rcu_read_unlock ();
+
+ if (ret) {
gf_log (this->name, GF_LOG_ERROR, "Rejecting management "
"handshake request from unknown peer %s",
req->trans->peerinfo.identifier);
@@ -1504,22 +1506,31 @@ glusterd_event_connected_inject (glusterd_peerctx_t *peerctx)
goto out;
}
- peerinfo = peerctx->peerinfo;
+ rcu_read_lock ();
+
+ peerinfo = glusterd_peerinfo_find (peerctx->peerid, peerctx->peername);
+ if (!peerinfo) {
+ ret = -1;
+ gf_log (THIS->name, GF_LOG_ERROR, "Could not find peer %s(%s)",
+ peerctx->peername, uuid_utoa (peerctx->peerid));
+ goto unlock;
+ }
ctx->hostname = gf_strdup (peerinfo->hostname);
ctx->port = peerinfo->port;
ctx->req = peerctx->args.req;
ctx->dict = peerctx->args.dict;
- event->peerinfo = peerinfo;
+ event->peername = gf_strdup (peerinfo->hostname);
+ uuid_copy (event->peerid, peerinfo->uuid);
event->ctx = ctx;
ret = glusterd_friend_sm_inject_event (event);
- if (ret) {
+ if (ret)
gf_log ("glusterd", GF_LOG_ERROR, "Unable to inject "
"EVENT_CONNECTED ret = %d", ret);
- goto out;
- }
+unlock:
+ rcu_read_unlock ();
out:
gf_log ("", GF_LOG_DEBUG, "returning %d", ret);
@@ -1589,7 +1600,15 @@ __glusterd_mgmt_hndsk_version_ack_cbk (struct rpc_req *req, struct iovec *iov,
this = THIS;
frame = myframe;
peerctx = frame->local;
- peerinfo = peerctx->peerinfo;
+
+ rcu_read_lock ();
+ peerinfo = glusterd_peerinfo_find (peerctx->peerid, peerctx->peername);
+ if (!peerinfo) {
+ gf_log (this->name, GF_LOG_DEBUG, "Could not find peer %s(%s)",
+ peerctx->peername, uuid_utoa (peerctx->peerid));
+ ret = -1;
+ goto out;
+ }
if (-1 == req->rpc_status) {
snprintf (msg, sizeof (msg),
@@ -1636,20 +1655,22 @@ __glusterd_mgmt_hndsk_version_ack_cbk (struct rpc_req *req, struct iovec *iov,
peerctx->args.mode);
}
- glusterd_friend_sm ();
-
ret = 0;
out:
+ if (ret != 0 && peerinfo)
+ rpc_transport_disconnect (peerinfo->rpc->conn.trans);
+
+ rcu_read_unlock ();
+
frame->local = NULL;
STACK_DESTROY (frame->root);
- if (ret != 0)
- rpc_transport_disconnect (peerinfo->rpc->conn.trans);
-
if (rsp.hndsk.hndsk_val)
free (rsp.hndsk.hndsk_val);
+ glusterd_friend_sm ();
+
return 0;
}
@@ -1682,7 +1703,16 @@ __glusterd_mgmt_hndsk_version_cbk (struct rpc_req *req, struct iovec *iov,
conf = this->private;
frame = myframe;
peerctx = frame->local;
- peerinfo = peerctx->peerinfo;
+
+ rcu_read_lock ();
+
+ peerinfo = glusterd_peerinfo_find (peerctx->peerid, peerctx->peername);
+ if (!peerinfo) {
+ ret = -1;
+ gf_log (this->name, GF_LOG_DEBUG, "Could not find peer %s(%s)",
+ peerctx->peername, uuid_utoa (peerctx->peerid));
+ goto out;
+ }
if (-1 == req->rpc_status) {
ret = -1;
@@ -1738,7 +1768,7 @@ __glusterd_mgmt_hndsk_version_cbk (struct rpc_req *req, struct iovec *iov,
GF_PROTOCOL_DICT_SERIALIZE (this, rsp_dict, (&arg.hndsk.hndsk_val),
arg.hndsk.hndsk_len, op_errno, out);
- ret = glusterd_submit_request (peerctx->peerinfo->rpc, &arg, frame,
+ ret = glusterd_submit_request (peerinfo->rpc, &arg, frame,
&gd_clnt_mgmt_hndsk_prog,
GD_MGMT_HNDSK_VERSIONS_ACK, NULL, this,
glusterd_mgmt_hndsk_version_ack_cbk,
@@ -1748,9 +1778,12 @@ out:
if (ret) {
frame->local = NULL;
STACK_DESTROY (frame->root);
- rpc_transport_disconnect (peerinfo->rpc->conn.trans);
+ if (peerinfo)
+ rpc_transport_disconnect (peerinfo->rpc->conn.trans);
}
+ rcu_read_unlock ();
+
if (rsp.hndsk.hndsk_val)
free (rsp.hndsk.hndsk_val);
@@ -1779,6 +1812,7 @@ glusterd_mgmt_handshake (xlator_t *this, glusterd_peerctx_t *peerctx)
{
call_frame_t *frame = NULL;
gf_mgmt_hndsk_req req = {{0,},};
+ glusterd_peerinfo_t *peerinfo = NULL;
int ret = -1;
frame = create_frame (this, this->ctx->pool);
@@ -1787,12 +1821,23 @@ glusterd_mgmt_handshake (xlator_t *this, glusterd_peerctx_t *peerctx)
frame->local = peerctx;
- ret = glusterd_submit_request (peerctx->peerinfo->rpc, &req, frame,
+ rcu_read_lock ();
+
+ peerinfo = glusterd_peerinfo_find (peerctx->peerid, peerctx->peername);
+ if (!peerinfo) {
+ gf_log (THIS->name, GF_LOG_DEBUG, "Could not find peer %s(%s)",
+ peerctx->peername, uuid_utoa (peerctx->peerid));
+ goto unlock;
+ }
+
+ ret = glusterd_submit_request (peerinfo->rpc, &req, frame,
&gd_clnt_mgmt_hndsk_prog,
GD_MGMT_HNDSK_VERSIONS, NULL, this,
glusterd_mgmt_hndsk_version_cbk,
(xdrproc_t)xdr_gf_mgmt_hndsk_req);
ret = 0;
+unlock:
+ rcu_read_unlock ();
out:
if (ret && frame)
STACK_DESTROY (frame->root);
@@ -1904,7 +1949,15 @@ __glusterd_peer_dump_version_cbk (struct rpc_req *req, struct iovec *iov,
conf = this->private;
frame = myframe;
peerctx = frame->local;
- peerinfo = peerctx->peerinfo;
+
+ rcu_read_lock ();
+
+ peerinfo = glusterd_peerinfo_find (peerctx->peerid, peerctx->peername);
+ if (!peerinfo) {
+ gf_log (this->name, GF_LOG_DEBUG, "Couldn't find peer %s(%s)",
+ peerctx->peername, uuid_utoa (peerctx->peerid));
+ goto out;
+ }
if (-1 == req->rpc_status) {
snprintf (msg, sizeof (msg),
@@ -1964,12 +2017,16 @@ __glusterd_peer_dump_version_cbk (struct rpc_req *req, struct iovec *iov,
peerctx->args.mode);
}
- glusterd_friend_sm();
- glusterd_op_sm();
-
ret = 0;
out:
+ if (ret != 0 && peerinfo)
+ rpc_transport_disconnect (peerinfo->rpc->conn.trans);
+
+ rcu_read_unlock ();
+
+ glusterd_friend_sm ();
+ glusterd_op_sm ();
/* don't use GF_FREE, buffer was allocated by libc */
if (rsp.prog) {
@@ -1985,9 +2042,6 @@ out:
frame->local = NULL;
STACK_DESTROY (frame->root);
- if (ret != 0)
- rpc_transport_disconnect (peerinfo->rpc->conn.trans);
-
return 0;
}
@@ -2006,6 +2060,7 @@ glusterd_peer_dump_version (xlator_t *this, struct rpc_clnt *rpc,
{
call_frame_t *frame = NULL;
gf_dump_req req = {0,};
+ glusterd_peerinfo_t *peerinfo = NULL;
int ret = -1;
frame = create_frame (this, this->ctx->pool);
@@ -2013,14 +2068,27 @@ glusterd_peer_dump_version (xlator_t *this, struct rpc_clnt *rpc,
goto out;
frame->local = peerctx;
+ if (!peerctx)
+ goto out;
+
+ rcu_read_lock ();
+
+ peerinfo = glusterd_peerinfo_find (peerctx->peerid, peerctx->peername);
+ if (!peerinfo) {
+ gf_log (this->name, GF_LOG_DEBUG, "Couldn't find peer %s(%s)",
+ peerctx->peername, uuid_utoa (peerctx->peerid));
+ goto unlock;
+ }
req.gfs_id = 0xcafe;
- ret = glusterd_submit_request (peerctx->peerinfo->rpc, &req, frame,
+ ret = glusterd_submit_request (peerinfo->rpc, &req, frame,
&glusterd_dump_prog, GF_DUMP_DUMP,
NULL, this,
glusterd_peer_dump_version_cbk,
(xdrproc_t)xdr_gf_dump_req);
+unlock:
+ rcu_read_unlock ();
out:
return ret;
}