summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPranith Kumar K <pranithk@gluster.com>2010-09-14 02:23:32 +0000
committerVijay Bellur <vijay@dev.gluster.com>2010-09-14 01:14:01 -0700
commit429a94c78ad3e6a956c847836a061c860d19e499 (patch)
tree01a5d606ca9b2184fd8940b86c09b5b81d827ee2
parent8a2d1cf7a1425b9de2622635a1149f460bf1f36b (diff)
mgmt/glusterd: make probe one way
Signed-off-by: Pranith Kumar K <pranithk@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 1594 (make probe oneway) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1594
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c125
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-sm.c63
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-sm.h1
-rw-r--r--xlators/mgmt/glusterd/src/glusterd3_1-mops.c5
4 files changed, 128 insertions, 66 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index c87ba07aa95..040dff1be8e 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -518,7 +518,7 @@ glusterd_handle_cli_probe (rpcsvc_request_t *req)
{
int32_t ret = -1;
gf1_cli_probe_req cli_req = {0,};
- glusterd_peerinfo_t *peerinfo = NULL;
+ glusterd_peerinfo_t *peerinfo = NULL;
GF_ASSERT (req);
if (!gf_xdr_to_cli_probe_req (req->msg[0], &cli_req)) {
@@ -533,23 +533,23 @@ glusterd_handle_cli_probe (rpcsvc_request_t *req)
gf_log ("glusterd", GF_LOG_NORMAL, "Received CLI probe req %s %d",
cli_req.hostname, cli_req.port);
- if (!(ret = glusterd_is_local_addr(cli_req.hostname))) {
- glusterd_xfer_cli_probe_resp (req, 0, GF_PROBE_LOCALHOST,
- cli_req.hostname, cli_req.port);
- goto out;
- }
- if (!(ret = glusterd_friend_find_by_hostname(cli_req.hostname,
- &peerinfo))) {
- if ((peerinfo->state.state != GD_FRIEND_STATE_REQ_RCVD)
+ if (!(ret = glusterd_is_local_addr(cli_req.hostname))) {
+ glusterd_xfer_cli_probe_resp (req, 0, GF_PROBE_LOCALHOST,
+ cli_req.hostname, cli_req.port);
+ goto out;
+ }
+ if (!(ret = glusterd_friend_find_by_hostname(cli_req.hostname,
+ &peerinfo))) {
+ if ((peerinfo->state.state != GD_FRIEND_STATE_REQ_RCVD)
|| (peerinfo->state.state != GD_FRIEND_STATE_DEFAULT)) {
- gf_log ("glusterd", GF_LOG_NORMAL, "Probe host %s port %d"
- "already a friend", cli_req.hostname, cli_req.port);
- glusterd_xfer_cli_probe_resp (req, 0, GF_PROBE_FRIEND,
- cli_req.hostname, cli_req.port);
- goto out;
- }
- }
+ gf_log ("glusterd", GF_LOG_NORMAL, "Probe host %s port %d"
+ "already a friend", cli_req.hostname, cli_req.port);
+ glusterd_xfer_cli_probe_resp (req, 0, GF_PROBE_FRIEND,
+ cli_req.hostname, cli_req.port);
+ goto out;
+ }
+ }
ret = glusterd_probe_begin (req, cli_req.hostname, cli_req.port);
gf_cmd_log ("peer probe","on host %s:%d %s",cli_req.hostname, cli_req.port,
@@ -1052,16 +1052,16 @@ glusterd_handle_create_volume (rpcsvc_request_t *req)
gf1_cli_create_vol_req cli_req = {0,};
dict_t *dict = NULL;
glusterd_brickinfo_t *brickinfo = NULL;
- char *brick = NULL;
- char *bricks = NULL;
- char *volname = NULL;
- int brick_count = 0;
+ char *brick = NULL;
+ char *bricks = NULL;
+ char *volname = NULL;
+ int brick_count = 0;
char *tmpptr = NULL;
- int i = 0;
+ int i = 0;
glusterd_peerinfo_t *peerinfo = NULL;
- char *brick_list = NULL;
- void *cli_rsp = NULL;
- char err_str[1048];
+ char *brick_list = NULL;
+ void *cli_rsp = NULL;
+ char err_str[1048];
gf1_cli_create_vol_rsp rsp = {0,};
glusterd_conf_t *priv = NULL;
int err_ret = 0;
@@ -1108,23 +1108,23 @@ glusterd_handle_create_volume (rpcsvc_request_t *req)
ret = dict_get_str (dict, "volname", &volname);
if (ret) {
- gf_log ("", GF_LOG_ERROR, "Unable to get volume name");
- goto out;
+ gf_log ("", GF_LOG_ERROR, "Unable to get volume name");
+ goto out;
}
gf_cmd_log ("Volume create", "on volname: %s attempted", volname);
- if ((ret = glusterd_check_volume_exists (volname))) {
- snprintf(err_str, 1048, "Volname %s already exists",
- volname);
- gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str);
- err_ret = 1;
- goto out;
- }
+ if ((ret = glusterd_check_volume_exists (volname))) {
+ snprintf(err_str, 1048, "Volname %s already exists",
+ volname);
+ gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str);
+ err_ret = 1;
+ goto out;
+ }
ret = dict_get_int32 (dict, "count", &brick_count);
if (ret) {
- gf_log ("", GF_LOG_ERROR, "Unable to get count");
- goto out;
+ gf_log ("", GF_LOG_ERROR, "Unable to get count");
+ goto out;
}
ret = dict_get_str (dict, "transport", &trans_type);
@@ -1134,8 +1134,8 @@ glusterd_handle_create_volume (rpcsvc_request_t *req)
}
ret = dict_get_str (dict, "bricks", &bricks);
if (ret) {
- gf_log ("", GF_LOG_ERROR, "Unable to get bricks");
- goto out;
+ gf_log ("", GF_LOG_ERROR, "Unable to get bricks");
+ goto out;
}
uuid_generate (volume_id);
@@ -1159,37 +1159,37 @@ glusterd_handle_create_volume (rpcsvc_request_t *req)
bricks);
while ( i < brick_count) {
- i++;
- brick= strtok_r (brick_list, " \n", &tmpptr);
- brick_list = tmpptr;
+ i++;
+ brick= strtok_r (brick_list, " \n", &tmpptr);
+ brick_list = tmpptr;
if (brickinfo)
glusterd_brickinfo_delete (brickinfo);
- ret = glusterd_brickinfo_from_brick (brick, &brickinfo);
- if (ret)
- goto out;
+ ret = glusterd_brickinfo_from_brick (brick, &brickinfo);
+ if (ret)
+ goto out;
- if(!(ret = glusterd_is_local_addr (brickinfo->hostname)))
- goto brick_validation; //localhost, continue without validation
+ if(!(ret = glusterd_is_local_addr (brickinfo->hostname)))
+ goto brick_validation; //localhost, continue without validation
- ret = glusterd_friend_find_by_hostname (brickinfo->hostname,
- &peerinfo);
- if (ret) {
+ ret = glusterd_friend_find_by_hostname (brickinfo->hostname,
+ &peerinfo);
+ if (ret) {
snprintf (err_str, 1048, "Host %s not a friend",
- brickinfo->hostname);
- gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str);
- err_ret = 1;
- goto out;
- }
- if ((!peerinfo->connected) &&
- (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)) {
+ brickinfo->hostname);
+ gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str);
+ err_ret = 1;
+ goto out;
+ }
+ if ((!peerinfo->connected) &&
+ (peerinfo->state.state != GD_FRIEND_STATE_BEFRIENDED)) {
snprintf(err_str, 1048, "Host %s not connected",
- brickinfo->hostname);
+ brickinfo->hostname);
gf_log ("glusterd", GF_LOG_ERROR, "%s", err_str);
err_ret = 1;
goto out;
- }
+ }
brick_validation:
- list_for_each_entry (volinfo, &priv->volumes, vol_list) {
+ list_for_each_entry (volinfo, &priv->volumes, vol_list) {
list_for_each_entry (tmpbrkinfo, &volinfo->bricks,
brick_list) {
@@ -1204,9 +1204,9 @@ brick_validation:
err_ret = 1;
goto out;
}
- }
- }
- }
+ }
+ }
+ }
ret = glusterd_create_volume (req, dict);
gf_cmd_log ("Volume create", "on volname: %s %s", volname,
@@ -2425,7 +2425,7 @@ glusterd_friend_add (const char *hoststr, int port,
goto out;
list_add_tail (&peerinfo->hostnames, &name->hostname_list);
rpc_cfg.remote_host = gf_strdup (hoststr);
- peerinfo->hostname = gf_strdup (hoststr);
+ peerinfo->hostname = gf_strdup (hoststr);
}
INIT_LIST_HEAD (&peerinfo->uuid_list);
@@ -2503,7 +2503,6 @@ glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr, int port)
glusterd_probe_ctx_t *ctx = NULL;
GF_ASSERT (hoststr);
- GF_ASSERT (req);
ret = glusterd_friend_find (NULL, (char *)hoststr, &peerinfo);
diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.c b/xlators/mgmt/glusterd/src/glusterd-sm.c
index 9656dba1ee8..a38d2fd8c41 100644
--- a/xlators/mgmt/glusterd/src/glusterd-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-sm.c
@@ -67,6 +67,8 @@ glusterd_destroy_friend_req_ctx (glusterd_friend_req_ctx_t *ctx)
dict_unref (ctx->vols);
if (ctx->hostname)
GF_FREE (ctx->hostname);
+ if (ctx->remote_hostname)
+ GF_FREE (ctx->remote_hostname);
GF_FREE (ctx);
}
@@ -94,6 +96,22 @@ glusterd_ac_error (glusterd_friend_sm_event_t *event, void *ctx)
}
static int
+glusterd_ac_reverse_probe_begin (glusterd_friend_sm_event_t *event, void *ctx)
+{
+ int ret = 0;
+ glusterd_friend_update_ctx_t *ev_ctx = NULL;
+
+ GF_ASSERT (event);
+ GF_ASSERT (ctx);
+
+ ev_ctx = ctx;
+ ret = glusterd_probe_begin (NULL, ev_ctx->remote_hostname, 0);
+
+ gf_log ("", GF_LOG_DEBUG, "returning with %d", ret);
+ return ret;
+}
+
+static int
glusterd_ac_friend_add (glusterd_friend_sm_event_t *event, void *ctx)
{
int ret = 0;
@@ -322,6 +340,31 @@ glusterd_ac_none (void *ctx)
return ret;
}*/
+int
+glusterd_remote_hostname_get (rpcsvc_request_t *req, char *remote_host, int len)
+{
+ GF_ASSERT (req);
+ GF_ASSERT (remote_host);
+ GF_ASSERT (req->trans);
+
+ char *name = NULL;
+ char *delimiter = NULL;
+
+ name = req->trans->peerinfo.identifier;
+ strncpy (remote_host, name, len);
+ delimiter = strchr (remote_host, ':');
+
+ GF_ASSERT (delimiter);
+ if (!delimiter) {
+ memset (remote_host, 0, len);
+ return -1;
+ }
+
+ *delimiter = '\0';
+
+ return 0;
+}
+
static int
glusterd_ac_handle_friend_add_req (glusterd_friend_sm_event_t *event, void *ctx)
{
@@ -334,6 +377,7 @@ glusterd_ac_handle_friend_add_req (glusterd_friend_sm_event_t *event, void *ctx)
glusterd_friend_sm_event_type_t event_type = GD_FRIEND_EVENT_NONE;
int status = 0;
int32_t op_ret = -1;
+ char remote_hostname[UNIX_PATH_MAX + 1] = {0,};
GF_ASSERT (ctx);
ev_ctx = ctx;
@@ -374,6 +418,14 @@ 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);
+ ret = glusterd_remote_hostname_get (ev_ctx->req, remote_hostname,
+ sizeof (remote_hostname));
+ if (ret) {
+ ret = -1;
+ goto out;
+ }
+
+ new_ev_ctx->remote_hostname = gf_strdup (remote_hostname);
new_event->ctx = new_ev_ctx;
glusterd_friend_sm_inject_event (new_event);
@@ -441,7 +493,7 @@ glusterd_sm_t glusterd_state_req_rcvd [] = {
{GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_friend_probe}, //EVENT_PROBE,
{GD_FRIEND_STATE_REQ_SENT_RCVD, glusterd_ac_friend_add}, //EVENT_INIT_FRIEND_REQ,
{GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none}, //EVENT_RCVD_ACC
- {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC
+ {GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_reverse_probe_begin}, //EVENT_RCVD_LOCAL_ACC
{GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none}, //EVENT_RCVD_RJT
{GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT
{GD_FRIEND_STATE_REQ_RCVD, glusterd_ac_none}, //EVENT_RCV_FRIEND_REQ
@@ -603,6 +655,7 @@ glusterd_friend_sm ()
glusterd_peerinfo_t *peerinfo = NULL;
glusterd_friend_sm_event_type_t event_type = 0;
int port = 6969; //TODO, use standard
+ gf_boolean_t is_await_conn = _gf_false;
while (!list_empty (&gd_friend_sm_queue)) {
list_for_each_entry_safe (event, tmp, &gd_friend_sm_queue, list) {
@@ -638,6 +691,10 @@ glusterd_friend_sm ()
GF_ASSERT (handler);
ret = handler (event, event->ctx);
+ if (ret == GLUSTERD_CONNECTION_AWAITED) {
+ is_await_conn = _gf_true;
+ ret = 0;
+ }
if (ret) {
gf_log ("glusterd", GF_LOG_ERROR, "handler returned: "
@@ -667,7 +724,11 @@ glusterd_friend_sm ()
glusterd_destroy_friend_event_context (event);
GF_FREE (event);
+ if (is_await_conn)
+ break;
}
+ if (is_await_conn)
+ break;
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.h b/xlators/mgmt/glusterd/src/glusterd-sm.h
index 2442c6eb13a..1b845b9027b 100644
--- a/xlators/mgmt/glusterd/src/glusterd-sm.h
+++ b/xlators/mgmt/glusterd/src/glusterd-sm.h
@@ -121,6 +121,7 @@ typedef struct glusterd_sm_ {
typedef struct glusterd_friend_req_ctx_ {
uuid_t uuid;
char *hostname;
+ char *remote_hostname;
rpcsvc_request_t *req;
int port;
dict_t *vols;
diff --git a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
index f9083852e1a..9bc05ec78c6 100644
--- a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
+++ b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
@@ -211,8 +211,9 @@ 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->port);
+ if (ctx->req)//reverse probe doesnt have req
+ ret = glusterd_xfer_cli_probe_resp (ctx->req, op_ret, op_errno,
+ ctx->hostname, ctx->port);
if (!ret) {
glusterd_friend_sm ();
glusterd_op_sm ();