From 5af2f09a1f30e7ed5a741d8eeee122d44241ddfc Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Sun, 29 Sep 2024 14:10:22 +1000 Subject: [PATCH] ctdb-server: Optimise local IP verification It is more efficient calling ctdb_sys_local_ip_check() inside a loop compared to calling ctdb_sys_have_ip(). There is a chance that this is premature optimisation... but it sure is easy. Fall back to checking with bind(). I think these checks really exist because of the weirdness fixed by commit 4b4e4d8870475d994fe42a7b2c57dc69842d91f6. However, we might as well do what we can. Signed-off-by: Martin Schwenke Reviewed-by: John Mulligan Reviewed-by: Anoop C S --- ctdb/server/ctdb_recoverd.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/ctdb/server/ctdb_recoverd.c b/ctdb/server/ctdb_recoverd.c index f31ff43ee0b..11644868e46 100644 --- a/ctdb/server/ctdb_recoverd.c +++ b/ctdb/server/ctdb_recoverd.c @@ -2285,6 +2285,7 @@ static int verify_local_ip_allocation(struct ctdb_recoverd *rec) int ret; bool need_takeover_run = false; struct ctdb_public_ip_list_old *ips = NULL; + struct ctdb_sys_local_ips_context *ips_ctx = NULL; /* If we are not the leader then do some housekeeping */ if (!this_node_is_leader(rec)) { @@ -2355,9 +2356,30 @@ static int verify_local_ip_allocation(struct ctdb_recoverd *rec) return -1; } + ret = ctdb_sys_local_ips_init(mem_ctx, &ips_ctx); + if (ret != 0) { + /* + * What to do? The point here is to allow public + * addresses to be checked when + * net.ipv4.ip_nonlocal_bind = 1, which is probably + * just Linux... though other platforms may have a + * similar setting. For non-Linux platforms without a + * usable getifaddrs(3) function/replacement, fall + * back to bind() below... + */ + DBG_DEBUG("Failed to get local addresses, depending on bind\n"); + ips_ctx = NULL; /* Just in case */ + } + for (j=0; jnum; j++) { ctdb_sock_addr *addr = &ips->ips[j].addr; - bool have_ip = ctdb_sys_have_ip(addr); + bool have_ip; + + if (ips_ctx != NULL) { + have_ip = ctdb_sys_local_ip_check(ips_ctx, addr); + } else { + have_ip = ctdb_sys_bind_ip_check(addr); + } if (ips->ips[j].pnn == rec->pnn) { if (!have_ip) { @@ -2374,6 +2396,8 @@ static int verify_local_ip_allocation(struct ctdb_recoverd *rec) } } + TALLOC_FREE(ips_ctx); + done: if (need_takeover_run) { struct ctdb_srvid_message rd; -- 2.47.3