summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPranith K <pranithk@gluster.com>2010-11-12 04:01:01 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-11-13 07:02:51 -0800
commit20fb15dc02a4d1a4b38335a988c0c1abafee7355 (patch)
tree8503c2df5a758650a7d9f6efcd77bb23e8d585ab
parentfe349e42baa47dd7c010707bddbd114946f4d95b (diff)
mgmt/glusterd: "peer probe new-hostname" should replace old-hostname of friend
Signed-off-by: Pranith Kumar K <pranithk@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 1995 (Gluster Peer probe command keeps ip address instead of server name in the destination server) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1995
-rw-r--r--cli/src/cli3_1-cops.c2
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c71
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-sm.c17
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-sm.h1
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.c14
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c47
-rw-r--r--xlators/mgmt/glusterd/src/glusterd3_1-mops.c14
7 files changed, 79 insertions, 87 deletions
diff --git a/cli/src/cli3_1-cops.c b/cli/src/cli3_1-cops.c
index dec20d904..eeb0f05c0 100644
--- a/cli/src/cli3_1-cops.c
+++ b/cli/src/cli3_1-cops.c
@@ -101,7 +101,7 @@ gf_cli3_1_probe_cbk (struct rpc_req *req, struct iovec *iov,
break;
case GF_PROBE_FRIEND:
cli_out ("Probe on host %s port %d already"
- " a friend",rsp.hostname, rsp.port);
+ " in peer list", rsp.hostname, rsp.port);
break;
default:
cli_out ("Probe returned with unknown errno %d",
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index 20d2efa03..b6fbd5641 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -567,13 +567,13 @@ glusterd_handle_cli_probe (rpcsvc_request_t *req)
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)) {
+ if (strcmp (peerinfo->hostname, cli_req.hostname) == 0) {
- gf_log ("glusterd", GF_LOG_NORMAL, "Probe host %s port %d"
- "already a friend", cli_req.hostname, cli_req.port);
+ gf_log ("glusterd", GF_LOG_DEBUG, "Probe host %s port %d"
+ " already a peer", cli_req.hostname, cli_req.port);
glusterd_xfer_cli_probe_resp (req, 0, GF_PROBE_FRIEND,
cli_req.hostname, cli_req.port);
goto out;
@@ -2196,6 +2196,31 @@ out:
return ret;
}
+int
+glusterd_friend_hostname_update (glusterd_peerinfo_t *peerinfo,
+ char *hostname,
+ gf_boolean_t store_update)
+{
+ char *new_hostname = NULL;
+ int ret = 0;
+
+ GF_ASSERT (peerinfo);
+ GF_ASSERT (hostname);
+
+ new_hostname = gf_strdup (hostname);
+ if (!new_hostname) {
+ ret = -1;
+ goto out;
+ }
+
+ GF_FREE (peerinfo->hostname);
+ peerinfo->hostname = new_hostname;
+ if (store_update)
+ ret = glusterd_store_update_peerinfo (peerinfo);
+out:
+ gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
+ return ret;
+}
int
glusterd_handle_friend_update (rpcsvc_request_t *req)
@@ -2295,6 +2320,10 @@ glusterd_handle_friend_update (rpcsvc_request_t *req)
ret = glusterd_friend_find (uuid, hostname, &tmp);
if (!ret) {
+ if (strcmp (hostname, tmp->hostname) != 0) {
+ glusterd_friend_hostname_update (tmp, hostname,
+ _gf_true);
+ }
i++;
continue;
}
@@ -2410,7 +2439,7 @@ glusterd_friend_remove (uuid_t uuid, char *hostname)
ret = glusterd_friend_cleanup (peerinfo);
out:
- gf_log ("", GF_LOG_DEBUG, "returning %d");
+ gf_log ("", GF_LOG_DEBUG, "returning %d", ret);
return ret;
}
@@ -2501,7 +2530,7 @@ out:
*rpc = NULL;
}
- gf_log ("", GF_LOG_DEBUG, "returning %d");
+ gf_log ("", GF_LOG_DEBUG, "returning %d", ret);
return ret;
}
@@ -2572,14 +2601,13 @@ out:
return ret;
}
-
-
int
glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr, int port)
{
int ret = -1;
glusterd_peerinfo_t *peerinfo = NULL;
glusterd_peerctx_args_t args = {0};
+ glusterd_friend_sm_event_t *event = NULL;
GF_ASSERT (hoststr);
@@ -2593,13 +2621,32 @@ glusterd_probe_begin (rpcsvc_request_t *req, const char *hoststr, int port)
ret = glusterd_friend_add ((char *)hoststr, port,
GD_FRIEND_STATE_DEFAULT,
NULL, NULL, &peerinfo, 0, &args);
- }
+ if ((!ret) && (!peerinfo->connected)) {
+ ret = GLUSTERD_CONNECTION_AWAITED;
+ }
- if ((!ret) && (!peerinfo->connected)) {
- return GLUSTERD_CONNECTION_AWAITED;
+ } else if (peerinfo->connected &&
+ (GD_FRIEND_STATE_BEFRIENDED == peerinfo->state.state)) {
+ ret = glusterd_friend_hostname_update (peerinfo, (char*)hoststr,
+ _gf_false);
+ if (ret)
+ goto out;
+ //this is just to rename so inject local acc for cluster update
+ ret = glusterd_friend_sm_new_event (GD_FRIEND_EVENT_LOCAL_ACC,
+ &event);
+ if (!ret) {
+ event->peerinfo = peerinfo;
+ ret = glusterd_friend_sm_inject_event (event);
+ glusterd_xfer_cli_probe_resp (req, 0, GF_PROBE_SUCCESS,
+ (char*)hoststr, port);
+ }
+ } else {
+ glusterd_xfer_cli_probe_resp (req, 0, GF_PROBE_FRIEND,
+ (char*)hoststr, port);
}
-
+out:
+ gf_log ("", GF_LOG_DEBUG, "returning %d", ret);
return ret;
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.c b/xlators/mgmt/glusterd/src/glusterd-sm.c
index d572ee70c..1412d1bdd 100644
--- a/xlators/mgmt/glusterd/src/glusterd-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-sm.c
@@ -362,10 +362,9 @@ glusterd_ac_send_friend_update (glusterd_friend_sm_event_t *event, void *ctx)
int ret = 0;
glusterd_peerinfo_t *peerinfo = NULL;
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 *ev_ctx = NULL;
+ glusterd_friend_update_ctx_t ev_ctx = {{0}};
GF_ASSERT (event);
peerinfo = event->peerinfo;
@@ -375,23 +374,15 @@ 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;
+ ev_ctx.op = GD_FRIEND_UPDATE_ADD;
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);
+ ret = proc->fn (NULL, this, &ev_ctx);
}
-out:
gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);
-
return ret;
}
@@ -602,7 +593,7 @@ glusterd_sm_t glusterd_state_befriended [] = {
{GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_PROBE,
{GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_INIT_FRIEND_REQ,
{GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCVD_ACC
- {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_ACC
+ {GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_send_friend_update}, //EVENT_RCVD_LOCAL_ACC
{GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_RJT
{GD_FRIEND_STATE_REJECTED, glusterd_ac_none}, //EVENT_RCVD_LOCAL_RJT
{GD_FRIEND_STATE_BEFRIENDED, glusterd_ac_handle_friend_add_req}, //EVENT_RCV_FRIEND_REQ
diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.h b/xlators/mgmt/glusterd/src/glusterd-sm.h
index 41ec26943..b62feb76c 100644
--- a/xlators/mgmt/glusterd/src/glusterd-sm.h
+++ b/xlators/mgmt/glusterd/src/glusterd-sm.h
@@ -92,7 +92,6 @@ struct glusterd_peerinfo_ {
int port;
struct list_head uuid_list;
struct list_head op_peers_list;
- struct list_head hostnames;
struct rpc_clnt *rpc;
int connected;
glusterd_store_handle_t *shandle;
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
index 4b9895219..aa63226a5 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
@@ -1312,8 +1312,6 @@ glusterd_store_update_peerinfo (glusterd_peerinfo_t *peerinfo)
char filepath[PATH_MAX] = {0,};
char str[512] = {0,};
char buf[4096] = {0,};
- glusterd_peer_hostname_t *hname = NULL;
- int i = 0;
char hostname_path[PATH_MAX] = {0,};
@@ -1383,15 +1381,9 @@ glusterd_store_update_peerinfo (glusterd_peerinfo_t *peerinfo)
if (ret)
goto out;
- list_for_each_entry (hname, &peerinfo->hostnames, hostname_list) {
- i++;
- snprintf (buf, sizeof (buf), "%s%d",
- GLUSTERD_STORE_KEY_PEER_HOSTNAME, i);
- ret = glusterd_store_save_value (peerinfo->shandle,
- buf, hname->hostname);
- if (ret)
- goto out;
- }
+ ret = glusterd_store_save_value (peerinfo->shandle,
+ GLUSTERD_STORE_KEY_PEER_HOSTNAME "1",
+ peerinfo->hostname);
out:
gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index b63286630..f7934ef73 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -2076,7 +2076,6 @@ glusterd_friend_find_by_hostname (const char *hoststr,
int ret = -1;
glusterd_conf_t *priv = NULL;
glusterd_peerinfo_t *entry = NULL;
- glusterd_peer_hostname_t *name = NULL;
struct addrinfo *addr = NULL;
struct addrinfo *p = NULL;
char *host = NULL;
@@ -2094,16 +2093,14 @@ glusterd_friend_find_by_hostname (const char *hoststr,
GF_ASSERT (priv);
list_for_each_entry (entry, &priv->peers, uuid_list) {
- list_for_each_entry (name, &entry->hostnames, hostname_list) {
- if (!strncmp (name->hostname, hoststr,
- 1024)) {
+ if (!strncmp (entry->hostname, hoststr,
+ 1024)) {
gf_log ("glusterd", GF_LOG_NORMAL,
"Friend %s found.. state: %d", hoststr,
entry->state.state);
*peerinfo = entry;
return 0;
- }
}
}
@@ -2135,18 +2132,15 @@ glusterd_friend_find_by_hostname (const char *hoststr,
goto out;
list_for_each_entry (entry, &priv->peers, uuid_list) {
- list_for_each_entry (name, &entry->hostnames,
- hostname_list) {
- if (!strncmp (name->hostname, host,
- 1024) || !strncmp (name->hostname,hname,
- 1024)) {
- gf_log ("glusterd", GF_LOG_NORMAL,
- "Friend %s found.. state: %d",
- hoststr, entry->state.state);
- *peerinfo = entry;
- freeaddrinfo (addr);
- return 0;
- }
+ if (!strncmp (entry->hostname, host,
+ 1024) || !strncmp (entry->hostname,hname,
+ 1024)) {
+ gf_log ("glusterd", GF_LOG_NORMAL,
+ "Friend %s found.. state: %d",
+ hoststr, entry->state.state);
+ *peerinfo = entry;
+ freeaddrinfo (addr);
+ return 0;
}
}
}
@@ -2614,7 +2608,6 @@ glusterd_peerinfo_new (glusterd_peerinfo_t **peerinfo,
uuid_t *uuid, const char *hostname)
{
glusterd_peerinfo_t *new_peer = NULL;
- glusterd_peer_hostname_t *name = NULL;
int ret = -1;
GF_ASSERT (peerinfo);
@@ -2625,15 +2618,9 @@ glusterd_peerinfo_new (glusterd_peerinfo_t **peerinfo,
if (!new_peer)
goto out;
- INIT_LIST_HEAD (&new_peer->hostnames);
new_peer->state.state = state;
- if (hostname) {
- ret = glusterd_peer_hostname_new ((char *)hostname, &name);
- if (ret)
- goto out;
- list_add_tail (&new_peer->hostnames, &name->hostname_list);
+ if (hostname)
new_peer->hostname = gf_strdup (hostname);
- }
INIT_LIST_HEAD (&new_peer->uuid_list);
@@ -2660,8 +2647,6 @@ int32_t
glusterd_peer_destroy (glusterd_peerinfo_t *peerinfo)
{
int32_t ret = -1;
- glusterd_peer_hostname_t *name = NULL;
- glusterd_peer_hostname_t *tmp = NULL;
if (!peerinfo)
goto out;
@@ -2673,14 +2658,6 @@ glusterd_peer_destroy (glusterd_peerinfo_t *peerinfo)
}
list_del_init (&peerinfo->uuid_list);
- list_for_each_entry_safe (name, tmp, &peerinfo->hostnames,
- hostname_list) {
- list_del_init (&name->hostname_list);
- GF_FREE (name->hostname);
- GF_FREE (name);
- }
-
- list_del_init (&peerinfo->hostnames);
if (peerinfo->hostname)
GF_FREE (peerinfo->hostname);
glusterd_sm_tr_log_delete (&peerinfo->sm_log);
diff --git a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
index 3004954ce..b5ac57194 100644
--- a/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
+++ b/xlators/mgmt/glusterd/src/glusterd3_1-mops.c
@@ -57,9 +57,7 @@ glusterd3_1_probe_cbk (struct rpc_req *req, struct iovec *iov,
int ret = 0;
char str[50] = {0,};
glusterd_peerinfo_t *peerinfo = NULL;
- glusterd_peerinfo_t *dup_peerinfo = NULL;
glusterd_friend_sm_event_t *event = NULL;
- glusterd_peer_hostname_t *name = NULL;
glusterd_probe_ctx_t *ctx = NULL;
conf = THIS->private;
@@ -102,18 +100,6 @@ glusterd3_1_probe_cbk (struct rpc_req *req, struct iovec *iov,
GF_ASSERT (0);
}
- if (list_empty (&peerinfo->hostnames)) {
- glusterd_friend_find (NULL, rsp.hostname, &dup_peerinfo);
- GF_ASSERT (dup_peerinfo);
- peerinfo->hostname = gf_strdup (rsp.hostname);
- glusterd_peer_hostname_new (rsp.hostname, &name);
- list_add_tail (&name->hostname_list, &peerinfo->hostnames);
- peerinfo->rpc = dup_peerinfo->rpc;
- peerinfo->connected = dup_peerinfo->connected;
- glusterd_peer_destroy (dup_peerinfo);
- }
- if (!peerinfo->hostname)
- peerinfo->hostname = gf_strdup (rsp.hostname);
uuid_copy (peerinfo->uuid, rsp.uuid);
ret = glusterd_friend_sm_new_event