summaryrefslogtreecommitdiff
path: root/ctdb/common
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2015-02-20 11:47:23 +1100
committerAmitay Isaacs <amitay@samba.org>2015-03-23 12:23:12 +0100
commita5be2c245d5634695bd23387913c7e2e2481879b (patch)
tree3d891e1e738045b5fd52a1dbd3b8a93315f6228c /ctdb/common
parent3cbeb17d0f9f1e4b6a3faa9aba2982793cf8494b (diff)
downloadsamba-a5be2c245d5634695bd23387913c7e2e2481879b.tar.gz
ctdb-daemon: Store node addresses as ctdb_sock_addr rather than strings
Every time a nodemap is contructed the node IP addresses all need to be parsed. This isn't very productive use of CPU. Instead, parse each string once when the nodes file is loaded. This results in much simpler code. This code also removes the use of ctdb_address. Duplicating the port is pointless without an abstraction layer around ctdb_address. If CTDB gets an incompatible transport in the future then add an abstraction layer. Note that the infiniband code is not updated. Compilation of the infiniband code is already broken. Fixing it will be a separate, properly tested effort. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com> Pair-programmed-with: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb/common')
-rw-r--r--ctdb/common/ctdb_util.c27
-rw-r--r--ctdb/common/system_util.c6
2 files changed, 16 insertions, 17 deletions
diff --git a/ctdb/common/ctdb_util.c b/ctdb/common/ctdb_util.c
index b3b30b45822..59a24af967b 100644
--- a/ctdb/common/ctdb_util.c
+++ b/ctdb/common/ctdb_util.c
@@ -156,33 +156,25 @@ void ctdb_external_trace(void)
parse a IP:port pair
*/
int ctdb_parse_address(TALLOC_CTX *mem_ctx, const char *str,
- struct ctdb_address *address)
+ ctdb_sock_addr *address)
{
struct servent *se;
- ctdb_sock_addr addr;
+ int port;
setservent(0);
se = getservbyname("ctdb", "tcp");
endservent();
- /* Parse IP address and re-convert to string. This ensure correct
- * string form for IPv6 addresses.
- */
- if (! parse_ip(str, NULL, 0, &addr)) {
- return -1;
+ if (se == NULL) {
+ port = CTDB_PORT;
+ } else {
+ port = ntohs(se->s_port);
}
- address->address = talloc_strdup(mem_ctx, ctdb_addr_to_str(&addr));
- if (address->address == NULL) {
- DEBUG(DEBUG_ERR, (__location__ " Out of memory\n"));
+ if (! parse_ip(str, NULL, port, address)) {
return -1;
}
- if (se == NULL) {
- address->port = CTDB_PORT;
- } else {
- address->port = ntohs(se->s_port);
- }
return 0;
}
@@ -190,9 +182,10 @@ int ctdb_parse_address(TALLOC_CTX *mem_ctx, const char *str,
/*
check if two addresses are the same
*/
-bool ctdb_same_address(struct ctdb_address *a1, struct ctdb_address *a2)
+bool ctdb_same_address(ctdb_sock_addr *a1, ctdb_sock_addr *a2)
{
- return strcmp(a1->address, a2->address) == 0 && a1->port == a2->port;
+ return ctdb_same_ip(a1, a2) &&
+ ctdb_addr_to_port(a1) == ctdb_addr_to_port(a2);
}
diff --git a/ctdb/common/system_util.c b/ctdb/common/system_util.c
index 6ff82f7147b..1ae0bae8039 100644
--- a/ctdb/common/system_util.c
+++ b/ctdb/common/system_util.c
@@ -156,6 +156,9 @@ bool parse_ipv4(const char *s, unsigned port, struct sockaddr_in *sin)
return false;
}
+#ifdef HAVE_SOCK_SIN_LEN
+ sin->ip.sin_len = sizeof(*sin);
+#endif
return true;
}
@@ -181,6 +184,9 @@ static bool parse_ipv6(const char *s, const char *ifaces, unsigned port, ctdb_so
saddr->ip6.sin6_scope_id = if_nametoindex(ifaces);
}
+#ifdef HAVE_SOCK_SIN_LEN
+ saddr->ip6.sin6_len = sizeof(*saddr);
+#endif
return true;
}