summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorshishir gowda <shishirng@gluster.com>2010-09-20 23:55:55 +0000
committerVijay Bellur <vijay@dev.gluster.com>2010-09-21 03:24:01 -0700
commitae376259304b654206c50b095dabf172fc355438 (patch)
tree2ec2a4c3f30942561bb3e00d5a75e4e77d97e7c3
parentad234382336a6f2dafb4cb698dfabbf7957b498b (diff)
Friend find should handle hostname/ip
Regardless of friend being added(probe) using hostname or ip address, friend find should succeed if any of the above pair is provided. Signed-off-by: shishir gowda <shishirng@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 971 (dynamic volume management) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=971
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c55
1 files changed, 54 insertions, 1 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index da9eca02174..112ca296bb2 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -62,6 +62,12 @@ glusterd_friend_find_by_hostname (const char *hoststr,
glusterd_conf_t *priv = NULL;
glusterd_peerinfo_t *entry = NULL;
glusterd_peer_hostname_t *name = NULL;
+ struct addrinfo *addr, *p;
+ char *host = NULL;
+ struct sockaddr_in6 *s6 = NULL;
+ struct sockaddr_in *s4 = NULL;
+ struct in_addr *in_addr = NULL;
+ char hname[1024] = {0,};
GF_ASSERT (hoststr);
GF_ASSERT (peerinfo);
@@ -85,7 +91,54 @@ glusterd_friend_find_by_hostname (const char *hoststr,
}
}
- return ret;
+ ret = getaddrinfo(hoststr, NULL, NULL, &addr);
+ if (ret != 0) {
+ gf_log ("", GF_LOG_ERROR, "error in getaddrinfo: %s\n",
+ gai_strerror(ret));
+ goto out;
+ }
+
+ for (p = addr; p != NULL; p = p->ai_next) {
+ switch (p->ai_family) {
+ case AF_INET:
+ s4 = (struct sockaddr_in *) p->ai_addr;
+ in_addr = &s4->sin_addr;
+ break;
+ case AF_INET6:
+ s6 = (struct sockaddr_in6 *) p->ai_addr;
+ in_addr =(struct in_addr *) &s6->sin6_addr;
+ break;
+ default: ret = -1;
+ goto out;
+ }
+ host = inet_ntoa(*in_addr);
+
+ ret = getnameinfo (p->ai_addr, p->ai_addrlen, hname,
+ 1024, NULL, 0, 0);
+ if (ret)
+ 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;
+ }
+ }
+ }
+ }
+
+out:
+ if (addr)
+ freeaddrinfo (addr);
+ return -1;
}
static int