From c109ffb893ab80dd7b9dac038f5778961859ceff Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Wed, 15 Sep 2010 06:49:56 +0000 Subject: cli, mgmt/glusterd: disallow probe to a cluster Signed-off-by: Pranith Kumar K Signed-off-by: Vijay Bellur BUG: 1594 (make probe oneway) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1594 --- xlators/mgmt/glusterd/src/glusterd-handler.c | 60 +++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 10 deletions(-) (limited to 'xlators/mgmt/glusterd/src/glusterd-handler.c') diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c index a069e0ec5..102cc01c9 100644 --- a/xlators/mgmt/glusterd/src/glusterd-handler.c +++ b/xlators/mgmt/glusterd/src/glusterd-handler.c @@ -103,6 +103,9 @@ glusterd_friend_find_by_uuid (uuid_t uuid, GF_ASSERT (priv); + if (uuid_is_null (uuid)) + return -1; + list_for_each_entry (entry, &priv->peers, uuid_list) { if (!uuid_compare (entry->uuid, uuid)) { @@ -285,6 +288,11 @@ glusterd_add_peer_detail_to_dict (glusterd_peerinfo_t *peerinfo, if (ret) goto out; + snprintf (key, 256, "friend%d.connected", count); + ret = dict_set_int32 (friends, key, (int32_t)peerinfo->connected); + if (ret) + goto out; + out: return ret; } @@ -2349,6 +2357,8 @@ glusterd_handle_probe_query (rpcsvc_request_t *req) gd1_mgmt_probe_req probe_req = {{0},}; gd1_mgmt_probe_rsp rsp = {{0},}; glusterd_peer_hostname_t *name = NULL; + glusterd_peerinfo_t *peerinfo = NULL; + char remote_hostname[UNIX_PATH_MAX + 1] = {0,}; GF_ASSERT (req); @@ -2367,23 +2377,35 @@ glusterd_handle_probe_query (rpcsvc_request_t *req) gf_log ("glusterd", GF_LOG_NORMAL, "Received probe from uuid: %s", str); - ret = glusterd_peer_hostname_new (probe_req.hostname, &name); - + ret = glusterd_remote_hostname_get (req, remote_hostname, + sizeof (remote_hostname)); if (ret) { - gf_log ("", GF_LOG_ERROR, "Unable to get new peer_hostname"); - } else { - list_add_tail (&name->hostname_list, &conf->hostnames); + GF_ASSERT (0); + goto out; } + ret = glusterd_friend_find (NULL, remote_hostname, &peerinfo); + if ((ret == 0 ) || list_empty (&conf->peers)) { + ret = glusterd_peer_hostname_new (probe_req.hostname, &name); + if (ret) { + gf_log ("", GF_LOG_ERROR, "Unable to get new peer_hostname"); + } else { + list_add_tail (&name->hostname_list, &conf->hostnames); + } + uuid_copy (rsp.uuid, conf->uuid); + } else { + rsp.op_ret = -1; + rsp.op_errno = GF_PROBE_ANOTHER_CLUSTER; + } - uuid_copy (rsp.uuid, conf->uuid); rsp.hostname = probe_req.hostname; ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL, gd_xdr_serialize_mgmt_probe_rsp); - gf_log ("glusterd", GF_LOG_NORMAL, - "Responded to %s, ret: %d", probe_req.hostname, ret); + gf_log ("glusterd", GF_LOG_NORMAL, "Responded to %s, op_ret: %d, " + "op_errno: %d, ret: %d", probe_req.hostname, + rsp.op_ret, rsp.op_errno, ret); out: if (probe_req.hostname) @@ -2391,6 +2413,22 @@ out: return ret; } +int +glusterd_friend_remove (uuid_t uuid, char *hostname) +{ + int ret = 0; + glusterd_peerinfo_t *peerinfo = NULL; + + ret = glusterd_friend_find (uuid, hostname, &peerinfo); + if (ret) + goto out; + + ret = glusterd_friend_cleanup (peerinfo); +out: + gf_log ("", GF_LOG_DEBUG, "returning %d"); + return ret; +} + int glusterd_friend_add (const char *hoststr, int port, glusterd_friend_sm_state_t state, @@ -2665,6 +2703,8 @@ glusterd_xfer_friend_add_resp (rpcsvc_request_t *req, char *hostname, int port, gf_log ("glusterd", GF_LOG_NORMAL, "Responded to %s (%d), ret: %d", hostname, port, ret); + if (rsp.hostname) + GF_FREE (rsp.hostname) return ret; } @@ -3169,7 +3209,7 @@ glusterd_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, case RPC_CLNT_CONNECT: { - gf_log (this->name, GF_LOG_TRACE, "got RPC_CLNT_CONNECT"); + gf_log (this->name, GF_LOG_DEBUG, "got RPC_CLNT_CONNECT"); peerinfo->connected = 1; glusterd_friend_sm (); glusterd_op_sm (); @@ -3188,7 +3228,7 @@ glusterd_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event, //Inject friend disconnected here - gf_log (this->name, GF_LOG_TRACE, "got RPC_CLNT_DISCONNECT"); + gf_log (this->name, GF_LOG_DEBUG, "got RPC_CLNT_DISCONNECT"); peerinfo->connected = 0; //default_notify (this, GF_EVENT_CHILD_DOWN, NULL); -- cgit