From 876529054a00d107ece720771b11b2403bfa608d Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Tue, 17 Feb 2015 15:21:15 +1100 Subject: [PATCH] ctdb-daemon: Set node PNN in one place This is currently set in 2 places. One of them makes the node loading code difficult to refactor. Also, when the surrounding code in either place is touched then it might get broken. This only needs to be done once at startup, not on every reload. So do it once in a very obvious way, sacrificing a few CPU cycles for some added clarity. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- ctdb/server/ctdb_daemon.c | 24 +++++++++++++++++++++++- ctdb/server/ctdb_server.c | 6 ------ ctdb/tcp/tcp_connect.c | 16 +++++++--------- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/ctdb/server/ctdb_daemon.c b/ctdb/server/ctdb_daemon.c index 5a0bde2a868..b04cf58e052 100644 --- a/ctdb/server/ctdb_daemon.c +++ b/ctdb/server/ctdb_daemon.c @@ -1168,6 +1168,25 @@ static void ctdb_initialise_vnn_map(struct ctdb_context *ctdb) } } +static void ctdb_set_my_pnn(struct ctdb_context *ctdb) +{ + int nodeid; + + if (ctdb->address.address == NULL) { + ctdb_fatal(ctdb, + "Can not determine PNN - node address is not set\n"); + } + + nodeid = ctdb_ip_to_nodeid(ctdb, ctdb->address.address); + if (nodeid == -1) { + ctdb_fatal(ctdb, + "Can not determine PNN - node address not found in node list\n"); + } + + ctdb->pnn = ctdb->nodes[nodeid]->pnn; + DEBUG(DEBUG_NOTICE, ("PNN is %u\n", ctdb->pnn)); +} + /* start the protocol going as a daemon */ @@ -1276,11 +1295,14 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork) ctdb_fatal(ctdb, "transport is unavailable. can not initialize."); } - /* initialise the transport */ + /* Initialise the transport. This sets the node address if it + * was not set via the command-line. */ if (ctdb->methods->initialise(ctdb) != 0) { ctdb_fatal(ctdb, "transport failed to initialise"); } + ctdb_set_my_pnn(ctdb); + initialise_node_flags(ctdb); if (ctdb->public_addresses_file) { diff --git a/ctdb/server/ctdb_server.c b/ctdb/server/ctdb_server.c index 8b4960a1087..bd731954bb5 100644 --- a/ctdb/server/ctdb_server.c +++ b/ctdb/server/ctdb_server.c @@ -105,12 +105,6 @@ static int ctdb_add_node(struct ctdb_context *ctdb, char *nstr) /* nodes start out disconnected and unhealthy */ node->flags = (NODE_FLAGS_DISCONNECTED | NODE_FLAGS_UNHEALTHY); - if (ctdb->address.address && - ctdb_same_address(&ctdb->address, &node->address)) { - /* for automatic binding to interfaces, see tcp_connect.c */ - ctdb->pnn = node->pnn; - } - ctdb->num_nodes++; node->dead_count = 0; diff --git a/ctdb/tcp/tcp_connect.c b/ctdb/tcp/tcp_connect.c index 8a112ff68b8..51aa21fc944 100644 --- a/ctdb/tcp/tcp_connect.c +++ b/ctdb/tcp/tcp_connect.c @@ -385,22 +385,20 @@ static int ctdb_tcp_listen_automatic(struct ctdb_context *ctdb) strerror(errno), errno)); } } - + if (i == ctdb->num_nodes) { DEBUG(DEBUG_CRIT,("Unable to bind to any of the node addresses - giving up\n")); goto failed; } ctdb->address.address = talloc_strdup(ctdb, ctdb->nodes[i]->address.address); ctdb->address.port = ctdb->nodes[i]->address.port; - ctdb->name = talloc_asprintf(ctdb, "%s:%u", - ctdb->address.address, + ctdb->name = talloc_asprintf(ctdb, "%s:%u", + ctdb->address.address, ctdb->address.port); - ctdb->pnn = ctdb->nodes[i]->pnn; - DEBUG(DEBUG_INFO,("ctdb chose network address %s:%u pnn %u\n", - ctdb->address.address, - ctdb->address.port, - ctdb->pnn)); - + DEBUG(DEBUG_INFO,("ctdb chose network address %s:%u\n", + ctdb->address.address, + ctdb->address.port)); + if (listen(ctcp->listen_fd, 10) == -1) { goto failed; } -- 2.11.4.GIT