summaryrefslogtreecommitdiffstats
path: root/xlators
diff options
context:
space:
mode:
authorAmar Tumballi <amar@gluster.com>2010-07-20 02:40:58 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-07-20 20:44:18 -0700
commit3e34ad9388e3cf2493f3d75a760e6943f59dc55c (patch)
tree327f91f93799c6eba2f89abd20dfcbb57e5277f7 /xlators
parent9e3b58a2abdee5c1cf748eb463042ca9ef6aac66 (diff)
add port as an optional argument to 'probe' command
* there will be just 'one' glusterd per machine, but in case if its run on different port, then this option is useful to probe. Signed-off-by: Amar Tumballi <amar@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 1074 (port related issues in 'gluster probe' command) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1074
Diffstat (limited to 'xlators')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c77
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-sm.c44
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-sm.h2
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.h12
-rw-r--r--xlators/mgmt/glusterd/src/glusterd3_1-mops.c27
5 files changed, 100 insertions, 62 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index cd23362a6c9..308a761fdcd 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -126,13 +126,16 @@ glusterd_friend_find_by_uuid (uuid_t uuid,
}
static int
-glusterd_handle_friend_req (rpcsvc_request_t *req, uuid_t uuid, char *hostname)
+glusterd_handle_friend_req (rpcsvc_request_t *req, uuid_t uuid, char *hostname, int port)
{
int ret = -1;
glusterd_peerinfo_t *peerinfo = NULL;
glusterd_friend_sm_event_t *event = NULL;
glusterd_friend_req_ctx_t *ctx = NULL;
+ if (!port)
+ port = 6969; // TODO: use define values.
+
ret = glusterd_friend_find (uuid, hostname, &peerinfo);
if (ret) {
@@ -189,13 +192,17 @@ out:
static int
-glusterd_handle_unfriend_req (rpcsvc_request_t *req, uuid_t uuid, char *hostname)
+glusterd_handle_unfriend_req (rpcsvc_request_t *req, uuid_t uuid,
+ char *hostname, int port)
{
int ret = -1;
glusterd_peerinfo_t *peerinfo = NULL;
glusterd_friend_sm_event_t *event = NULL;
glusterd_friend_req_ctx_t *ctx = NULL;
+ if (!port)
+ port = 6969; //TODO: use define'd macro
+
ret = glusterd_friend_find (uuid, hostname, &peerinfo);
if (ret) {
@@ -272,6 +279,11 @@ glusterd_add_peer_detail_to_dict (glusterd_peerinfo_t *peerinfo,
if (ret)
goto out;
+ snprintf (key, 256, "friend%d.port", count);
+ ret = dict_set_int32 (friends, key, peerinfo->port);
+ if (ret)
+ goto out;
+
snprintf (key, 256, "friend%d.state", count);
ret = dict_set_int32 (friends, key, (int32_t)peerinfo->state.state);
if (ret)
@@ -519,14 +531,16 @@ glusterd_handle_cli_probe (rpcsvc_request_t *req)
if (!gf_xdr_to_cli_probe_req (req->msg[0], &cli_req)) {
//failed to decode msg;
+ gf_log ("", 1, "error");
req->rpc_err = GARBAGE_ARGS;
goto out;
}
- gf_log ("glusterd", GF_LOG_NORMAL, "Received CLI probe req");
+ gf_log ("glusterd", GF_LOG_NORMAL, "Received CLI probe req %s %d",
+ cli_req.hostname, cli_req.port);
- ret = glusterd_probe_begin (req, cli_req.hostname);
+ ret = glusterd_probe_begin (req, cli_req.hostname, cli_req.port);
out:
return ret;
@@ -549,7 +563,7 @@ glusterd_handle_cli_deprobe (rpcsvc_request_t *req)
gf_log ("glusterd", GF_LOG_NORMAL, "Received CLI deprobe req");
- ret = glusterd_deprobe_begin (req, cli_req.hostname);
+ ret = glusterd_deprobe_begin (req, cli_req.hostname, cli_req.port);
out:
return ret;
@@ -937,7 +951,7 @@ glusterd_handle_incoming_friend_req (rpcsvc_request_t *req)
"Received probe from uuid: %s", str);
ret = glusterd_handle_friend_req (req, friend_req.uuid,
- friend_req.hostname);
+ friend_req.hostname, friend_req.port);
out:
@@ -963,7 +977,7 @@ glusterd_handle_incoming_unfriend_req (rpcsvc_request_t *req)
"Received unfriend from uuid: %s", str);
ret = glusterd_handle_unfriend_req (req, friend_req.uuid,
- friend_req.hostname);
+ friend_req.hostname, friend_req.port);
out:
@@ -1003,7 +1017,7 @@ glusterd_handle_friend_update (rpcsvc_request_t *req)
if (!ret)
goto out;
- ret = glusterd_friend_add (friend_req.hostname,
+ ret = glusterd_friend_add (friend_req.hostname, friend_req.port,
GD_FRIEND_STATE_BEFRIENDED,
&friend_req.uuid, NULL, &peerinfo);
@@ -1391,7 +1405,7 @@ unwind:
int
-glusterd_friend_add (const char *hoststr,
+glusterd_friend_add (const char *hoststr, int port,
glusterd_friend_sm_state_t state,
uuid_t *uuid,
struct rpc_clnt *rpc,
@@ -1401,8 +1415,6 @@ glusterd_friend_add (const char *hoststr,
glusterd_conf_t *priv = NULL;
glusterd_peerinfo_t *peerinfo = NULL;
dict_t *options = NULL;
- char *port_str = NULL;
- int port_num = 0;
struct rpc_clnt_config rpc_cfg = {0,};
glusterd_peer_hostname_t *name = NULL;
@@ -1444,16 +1456,12 @@ glusterd_friend_add (const char *hoststr,
goto out;
- port_str = getenv ("GLUSTERD_REMOTE_PORT");
- if (port_str)
- port_num = atoi (port_str);
- else
- port_num = GLUSTERD_DEFAULT_PORT;
+ if (!port)
+ port = GLUSTERD_DEFAULT_PORT;
- rpc_cfg.remote_port = port_num;
- gf_log ("glusterd", GF_LOG_NORMAL, "remote-port: %d", port_num);
+ rpc_cfg.remote_port = port;
- ret = dict_set_int32 (options, "remote-port", port_num);
+ ret = dict_set_int32 (options, "remote-port", port);
if (ret)
goto out;
@@ -1487,7 +1495,7 @@ out:
int
-glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr)
+glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr, int port)
{
int ret = -1;
glusterd_peerinfo_t *peerinfo = NULL;
@@ -1501,8 +1509,8 @@ glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr)
if (ret) {
gf_log ("glusterd", GF_LOG_NORMAL, "Unable to find peerinfo"
- " for host: %s", hoststr);
- ret = glusterd_friend_add ((char *)hoststr,
+ " for host: %s (%d)", hoststr, port);
+ ret = glusterd_friend_add ((char *)hoststr, port,
GD_FRIEND_STATE_DEFAULT,
NULL, NULL, &peerinfo);
}
@@ -1522,6 +1530,7 @@ glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr)
}
ctx->hostname = gf_strdup (hoststr);
+ ctx->port = port;
ctx->req = req;
event->peerinfo = peerinfo;
@@ -1539,7 +1548,7 @@ glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr)
}
int
-glusterd_deprobe_begin (rpcsvc_request_t *req, const char *hoststr)
+glusterd_deprobe_begin (rpcsvc_request_t *req, const char *hoststr, int port)
{
int ret = -1;
glusterd_peerinfo_t *peerinfo = NULL;
@@ -1553,7 +1562,7 @@ glusterd_deprobe_begin (rpcsvc_request_t *req, const char *hoststr)
if (ret) {
gf_log ("glusterd", GF_LOG_NORMAL, "Unable to find peerinfo"
- " for host: %s", hoststr);
+ " for host: %s %d", hoststr, port);
goto out;
}
@@ -1573,10 +1582,11 @@ glusterd_deprobe_begin (rpcsvc_request_t *req, const char *hoststr)
ctx = GF_CALLOC (1, sizeof(*ctx), gf_gld_mt_probe_ctx_t);
if (!ctx) {
- return ret;
+ goto out;
}
ctx->hostname = gf_strdup (hoststr);
+ ctx->port = port;
ctx->req = req;
event->peerinfo = peerinfo;
@@ -1587,7 +1597,7 @@ glusterd_deprobe_begin (rpcsvc_request_t *req, const char *hoststr)
if (ret) {
gf_log ("glusterd", GF_LOG_ERROR, "Unable to inject event %d, "
"ret = %d", event->event, ret);
- return ret;
+ goto out;
}
out:
@@ -1596,7 +1606,7 @@ out:
int
-glusterd_xfer_friend_remove_resp (rpcsvc_request_t *req, char *hostname)
+glusterd_xfer_friend_remove_resp (rpcsvc_request_t *req, char *hostname, int port)
{
gd1_mgmt_friend_rsp rsp = {{0}, };
int32_t ret = -1;
@@ -1613,17 +1623,17 @@ glusterd_xfer_friend_remove_resp (rpcsvc_request_t *req, char *hostname)
uuid_copy (rsp.uuid, conf->uuid);
rsp.hostname = hostname;
-
+ rsp.port = port;
ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
gd_xdr_serialize_mgmt_friend_rsp);
gf_log ("glusterd", GF_LOG_NORMAL,
- "Responded to %s, ret: %d", hostname, ret);
+ "Responded to %s (%d), ret: %d", hostname, port, ret);
return ret;
}
int
-glusterd_xfer_friend_add_resp (rpcsvc_request_t *req, char *hostname)
+glusterd_xfer_friend_add_resp (rpcsvc_request_t *req, char *hostname, int port)
{
gd1_mgmt_friend_rsp rsp = {{0}, };
int32_t ret = -1;
@@ -1640,19 +1650,19 @@ glusterd_xfer_friend_add_resp (rpcsvc_request_t *req, char *hostname)
uuid_copy (rsp.uuid, conf->uuid);
rsp.hostname = gf_strdup (hostname);
-
+ rsp.port = port;
ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
gd_xdr_serialize_mgmt_friend_rsp);
gf_log ("glusterd", GF_LOG_NORMAL,
- "Responded to %s, ret: %d", hostname, ret);
+ "Responded to %s (%d), ret: %d", hostname, port, ret);
return ret;
}
int
glusterd_xfer_cli_probe_resp (rpcsvc_request_t *req, int32_t op_ret,
- int32_t op_errno, char *hostname)
+ int32_t op_errno, char *hostname, int port)
{
gf1_cli_probe_rsp rsp = {0, };
int32_t ret = -1;
@@ -1662,6 +1672,7 @@ glusterd_xfer_cli_probe_resp (rpcsvc_request_t *req, int32_t op_ret,
rsp.op_ret = op_ret;
rsp.op_errno = op_errno;
rsp.hostname = hostname;
+ rsp.port = port;
ret = glusterd_submit_reply (req, &rsp, NULL, 0, NULL,
gf_xdr_serialize_cli_probe_rsp);
diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.c b/xlators/mgmt/glusterd/src/glusterd-sm.c
index a5f760f369d..817d520e13b 100644
--- a/xlators/mgmt/glusterd/src/glusterd-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-sm.c
@@ -75,7 +75,6 @@ glusterd_ac_friend_add (glusterd_friend_sm_event_t *event, void *ctx)
glusterd_conf_t *conf = NULL;
xlator_t *this = NULL;
-
GF_ASSERT (event);
peerinfo = event->peerinfo;
@@ -105,17 +104,16 @@ static int
glusterd_ac_friend_probe (glusterd_friend_sm_event_t *event, void *ctx)
{
int ret = -1;
- char *hostname = NULL;
rpc_clnt_procedure_t *proc = NULL;
call_frame_t *frame = NULL;
glusterd_conf_t *conf = NULL;
xlator_t *this = NULL;
glusterd_probe_ctx_t *probe_ctx = NULL;
+ dict_t *dict = NULL;
GF_ASSERT (ctx);
probe_ctx = ctx;
- hostname = probe_ctx->hostname;
this = THIS;
@@ -135,11 +133,26 @@ glusterd_ac_friend_probe (glusterd_friend_sm_event_t *event, void *ctx)
goto out;
}
frame->local = ctx;
- ret = proc->fn (frame, this, hostname);
+ dict = dict_new ();
+ if (!dict)
+ goto out;
+ ret = dict_set_str (dict, "hostname", probe_ctx->hostname);
+ if (ret)
+ goto out;
+
+ ret = dict_set_int32 (dict, "port", probe_ctx->port);
+ if (ret)
+ goto out;
+ ret = proc->fn (frame, this, dict);
+ if (ret)
+ goto out;
+
}
out:
+ if (dict)
+ dict_destroy (dict);
gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);
return ret;
@@ -233,7 +246,8 @@ glusterd_ac_handle_friend_remove_req (glusterd_friend_sm_event_t *event,
uuid_clear (peerinfo->uuid);
- ret = glusterd_xfer_friend_remove_resp (ev_ctx->req, ev_ctx->hostname);
+ ret = glusterd_xfer_friend_remove_resp (ev_ctx->req, ev_ctx->hostname,
+ ev_ctx->port);
rpc_clnt_destroy (peerinfo->rpc);
peerinfo->rpc = NULL;
@@ -316,7 +330,8 @@ glusterd_ac_handle_friend_add_req (glusterd_friend_sm_event_t *event, void *ctx)
glusterd_friend_sm_inject_event (new_event);
- ret = glusterd_xfer_friend_add_resp (ev_ctx->req, ev_ctx->hostname);
+ ret = glusterd_xfer_friend_add_resp (ev_ctx->req, ev_ctx->hostname,
+ ev_ctx->port);
out:
gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);
@@ -503,13 +518,14 @@ glusterd_friend_sm_inject_event (glusterd_friend_sm_event_t *event)
int
glusterd_friend_sm ()
{
- glusterd_friend_sm_event_t *event = NULL;
- glusterd_friend_sm_event_t *tmp = NULL;
- int ret = -1;
- glusterd_friend_sm_ac_fn handler = NULL;
- glusterd_sm_t *state = NULL;
- glusterd_peerinfo_t *peerinfo = NULL;
- glusterd_friend_sm_event_type_t event_type = 0;
+ glusterd_friend_sm_event_t *event = NULL;
+ glusterd_friend_sm_event_t *tmp = NULL;
+ int ret = -1;
+ glusterd_friend_sm_ac_fn handler = NULL;
+ glusterd_sm_t *state = NULL;
+ glusterd_peerinfo_t *peerinfo = NULL;
+ glusterd_friend_sm_event_type_t event_type = 0;
+ int port = 6969; //TODO, use standard
while (!list_empty (&gd_friend_sm_queue)) {
list_for_each_entry_safe (event, tmp, &gd_friend_sm_queue, list) {
@@ -521,7 +537,7 @@ glusterd_friend_sm ()
if (!peerinfo &&
(GD_FRIEND_EVENT_PROBE == event_type ||
GD_FRIEND_EVENT_RCVD_FRIEND_REQ == event_type)) {
- ret = glusterd_friend_add (NULL,
+ ret = glusterd_friend_add (NULL, port,
GD_FRIEND_STATE_DEFAULT,
NULL, NULL, &peerinfo);
diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.h b/xlators/mgmt/glusterd/src/glusterd-sm.h
index ee1b4cc6b6f..72fc811e71a 100644
--- a/xlators/mgmt/glusterd/src/glusterd-sm.h
+++ b/xlators/mgmt/glusterd/src/glusterd-sm.h
@@ -111,6 +111,7 @@ typedef struct glusterd_friend_req_ctx_ {
uuid_t uuid;
char *hostname;
rpcsvc_request_t *req;
+ int port;
} glusterd_friend_req_ctx_t;
typedef glusterd_friend_req_ctx_t glusterd_friend_update_ctx_t;
@@ -118,6 +119,7 @@ typedef glusterd_friend_req_ctx_t glusterd_friend_update_ctx_t;
typedef struct glusterd_probe_ctx_ {
char *hostname;
rpcsvc_request_t *req;
+ int port;
} glusterd_probe_ctx_t;
int
glusterd_friend_sm_new_event (glusterd_friend_sm_event_type_t event_type,
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
index 1c483920aac..963541b68cd 100644
--- a/xlators/mgmt/glusterd/src/glusterd.h
+++ b/xlators/mgmt/glusterd/src/glusterd.h
@@ -90,17 +90,17 @@ typedef ssize_t (*gd_serialize_t) (struct iovec outmsg, void *args);
#define GLUSTERD_GET_BRICK_PIDFILE(pidfile, volpath, hostname)\
snprintf (pidfile, PATH_MAX, "%s/run/%s.pid", volpath, hostname);
int
-glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr);
+glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr, int port);
int
-glusterd_xfer_friend_add_resp (rpcsvc_request_t *req, char *hostname);
+glusterd_xfer_friend_add_resp (rpcsvc_request_t *req, char *hostname, int port);
int
glusterd_friend_find (uuid_t uuid, char *hostname,
glusterd_peerinfo_t **peerinfo);
int
-glusterd_friend_add (const char *hoststr,
+glusterd_friend_add (const char *hoststr, int port,
glusterd_friend_sm_state_t state,
uuid_t *uuid, struct rpc_clnt *rpc,
glusterd_peerinfo_t **friend);
@@ -156,17 +156,17 @@ glusterd_handle_defrag_volume (rpcsvc_request_t *req);
int
glusterd_xfer_cli_probe_resp (rpcsvc_request_t *req, int32_t op_ret,
- int32_t op_errno, char *hostname);
+ int32_t op_errno, char *hostname, int port);
int
glusterd_op_commit_send_resp (rpcsvc_request_t *req,
int32_t op, int32_t status);
int
-glusterd_xfer_friend_remove_resp (rpcsvc_request_t *req, char *hostname);
+glusterd_xfer_friend_remove_resp (rpcsvc_request_t *req, char *hostname, int port);
int
-glusterd_deprobe_begin (rpcsvc_request_t *req, const char *hoststr);
+glusterd_deprobe_begin (rpcsvc_request_t *req, const char *hoststr, int port);
int
glusterd_handle_cli_deprobe (rpcsvc_request_t *req);
diff --git a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
index 2dff9d654c7..8e0a958d873 100644
--- a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
+++ b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
@@ -163,8 +163,8 @@ glusterd3_1_friend_add_cbk (struct rpc_req * req, struct iovec *iov,
op_errno = rsp.op_errno;
gf_log ("glusterd", GF_LOG_NORMAL,
- "Received %s from uuid: %s, host: %s",
- (op_ret)?"RJT":"ACC", str, rsp.hostname);
+ "Received %s from uuid: %s, host: %s, port: %d",
+ (op_ret)?"RJT":"ACC", str, rsp.hostname, rsp.port);
ret = glusterd_friend_find (rsp.uuid, rsp.hostname, &peerinfo);
@@ -206,7 +206,7 @@ glusterd3_1_friend_add_cbk (struct rpc_req * req, struct iovec *iov,
GF_ASSERT (ctx);
ret = glusterd_xfer_cli_probe_resp (ctx->req, op_ret, op_errno,
- ctx->hostname);
+ ctx->hostname, ctx->port);
if (!ret) {
glusterd_friend_sm ();
glusterd_op_sm ();
@@ -256,8 +256,8 @@ glusterd3_1_friend_remove_cbk (struct rpc_req * req, struct iovec *iov,
op_errno = rsp.op_errno;
gf_log ("glusterd", GF_LOG_NORMAL,
- "Received %s from uuid: %s, host: %s",
- (op_ret)?"RJT":"ACC", str, rsp.hostname);
+ "Received %s from uuid: %s, host: %s, port: %d",
+ (op_ret)?"RJT":"ACC", str, rsp.hostname, rsp.port);
if (op_ret)
goto respond;
@@ -292,7 +292,7 @@ glusterd3_1_friend_remove_cbk (struct rpc_req * req, struct iovec *iov,
respond:
ret = glusterd_xfer_cli_probe_resp (ctx->req, op_ret, op_errno,
- ctx->hostname);
+ ctx->hostname, ctx->port);
if (!ret) {
glusterd_friend_sm ();
glusterd_op_sm ();
@@ -580,19 +580,27 @@ glusterd3_1_probe (call_frame_t *frame, xlator_t *this,
{
gd1_mgmt_probe_req req = {{0},};
int ret = 0;
+ int port = 0;
char *hostname = NULL;
glusterd_peerinfo_t *peerinfo = NULL;
glusterd_conf_t *priv = NULL;
+ dict_t *dict = NULL;
if (!frame || !this || !data) {
ret = -1;
goto out;
}
- hostname = data;
+ dict = data;
priv = this->private;
GF_ASSERT (priv);
+ ret = dict_get_str (dict, "hostname", &hostname);
+ if (ret)
+ goto out;
+ ret = dict_get_int32 (dict, "port", &port);
+ if (ret)
+ port = 6969;
ret = glusterd_friend_find (NULL, hostname, &peerinfo);
@@ -604,6 +612,7 @@ glusterd3_1_probe (call_frame_t *frame, xlator_t *this,
uuid_copy (req.uuid, priv->uuid);
req.hostname = gf_strdup (hostname);
+ req.port = port;
ret = glusterd_submit_request (peerinfo, &req, frame, priv->mgmt,
GD_MGMT_PROBE_QUERY,
@@ -644,7 +653,7 @@ glusterd3_1_friend_add (call_frame_t *frame, xlator_t *this,
uuid_copy (req.uuid, priv->uuid);
req.hostname = gf_strdup (peerinfo->hostname);
-
+ req.port = peerinfo->port;
ret = glusterd_submit_request (peerinfo, &req, frame, priv->mgmt,
GD_MGMT_FRIEND_ADD,
NULL, gd_xdr_from_mgmt_friend_req,
@@ -683,7 +692,7 @@ glusterd3_1_friend_remove (call_frame_t *frame, xlator_t *this,
uuid_copy (req.uuid, priv->uuid);
req.hostname = peerinfo->hostname;
-
+ req.port = peerinfo->port;
ret = glusterd_submit_request (peerinfo, &req, frame, priv->mgmt,
GD_MGMT_FRIEND_REMOVE,
NULL, gd_xdr_from_mgmt_friend_req,