From 38134f374ca5c76cf636dd9d10ab8e2cf5e4bf1e Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 16 Nov 2023 11:56:59 +0100 Subject: [PATCH] ctdb: remove unused ctdb->client_ip_list and print debug on ctdb_tcp_list instead BUG: https://bugzilla.samba.org/show_bug.cgi?id=15523 Signed-off-by: Stefan Metzmacher Reviewed-by: Martin Schwenke (cherry picked from commit 92badd3bdd82d1fa79727efcf81b6f479016811f) --- ctdb/include/ctdb_private.h | 1 - ctdb/server/ctdb_takeover.c | 74 ++++++++++++++++++++++----------------------- 2 files changed, 37 insertions(+), 38 deletions(-) diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index 3395f077ab9..37842a151d6 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -296,7 +296,6 @@ struct ctdb_context { struct ctdb_statistics statistics_history[MAX_STAT_HISTORY]; struct ctdb_vnn_map *vnn_map; uint32_t num_clients; - struct ctdb_client_ip *client_ip_list; bool do_checkpublicip; bool do_setsched; const char *event_script_dir; diff --git a/ctdb/server/ctdb_takeover.c b/ctdb/server/ctdb_takeover.c index 26cca1aefff..cdd3ac7a32a 100644 --- a/ctdb/server/ctdb_takeover.c +++ b/ctdb/server/ctdb_takeover.c @@ -348,21 +348,11 @@ struct ctdb_takeover_arp { */ struct ctdb_tcp_list { struct ctdb_tcp_list *prev, *next; + struct ctdb_client *client; struct ctdb_connection connection; }; /* - list of clients to kill on IP release - */ -struct ctdb_client_ip { - struct ctdb_client_ip *prev, *next; - struct ctdb_context *ctdb; - ctdb_sock_addr addr; - uint32_t client_id; -}; - - -/* send a gratuitous arp */ static void ctdb_control_send_arp(struct tevent_context *ev, @@ -1233,16 +1223,37 @@ int ctdb_set_public_addresses(struct ctdb_context *ctdb, bool check_addresses) } /* - destroy a ctdb_client_ip structure + destroy a ctdb_tcp_list structure */ -static int ctdb_client_ip_destructor(struct ctdb_client_ip *ip) +static int ctdb_tcp_list_destructor(struct ctdb_tcp_list *tcp) { - DEBUG(DEBUG_DEBUG,("destroying client tcp for %s:%u (client_id %u)\n", - ctdb_addr_to_str(&ip->addr), - ntohs(ip->addr.ip.sin_port), - ip->client_id)); + struct ctdb_client *client = tcp->client; + struct ctdb_connection *conn = &tcp->connection; + char conn_str[132] = { 0, }; + int ret; + + ret = ctdb_connection_to_buf(conn_str, + sizeof(conn_str), + conn, + false, + " -> "); + if (ret != 0) { + strlcpy(conn_str, "UNKNOWN", sizeof(conn_str)); + } + + D_DEBUG("removing client TCP connection %s " + "(client_id %u pid %d)\n", + conn_str, client->client_id, client->pid); + + DLIST_REMOVE(client->tcp_list, tcp); + + /* + * We don't call ctdb_remove_connection(vnn, conn) here + * as we want the caller to decide if it's called + * directly (local only) or indirectly via a + * CTDB_CONTROL_TCP_REMOVE broadcast + */ - DLIST_REMOVE(ip->ctdb->client_ip_list, ip); return 0; } @@ -1259,7 +1270,6 @@ int32_t ctdb_control_tcp_client(struct ctdb_context *ctdb, uint32_t client_id, struct ctdb_connection t; int ret; TDB_DATA data; - struct ctdb_client_ip *ip; struct ctdb_vnn *vnn; ctdb_sock_addr src_addr; ctdb_sock_addr dst_addr; @@ -1324,22 +1334,15 @@ int32_t ctdb_control_tcp_client(struct ctdb_context *ctdb, uint32_t client_id, return -1; } - ip = talloc(client, struct ctdb_client_ip); - CTDB_NO_MEMORY(ctdb, ip); - - ip->ctdb = ctdb; - ip->addr = dst_addr; - ip->client_id = client_id; - talloc_set_destructor(ip, ctdb_client_ip_destructor); - DLIST_ADD(ctdb->client_ip_list, ip); - tcp = talloc(client, struct ctdb_tcp_list); CTDB_NO_MEMORY(ctdb, tcp); + tcp->client = client; tcp->connection.src = tcp_sock->src; tcp->connection.dst = tcp_sock->dst; DLIST_ADD(client->tcp_list, tcp); + talloc_set_destructor(tcp, ctdb_tcp_list_destructor); t.src = tcp_sock->src; t.dst = tcp_sock->dst; @@ -1599,20 +1602,12 @@ void ctdb_takeover_client_destructor_hook(struct ctdb_client *client) struct ctdb_tcp_list *tcp = client->tcp_list; struct ctdb_connection *conn = &tcp->connection; - DLIST_REMOVE(client->tcp_list, tcp); - vnn = find_public_ip_vnn(client->ctdb, &conn->dst); - if (vnn == NULL) { - DEBUG(DEBUG_ERR, - (__location__ " unable to find public address %s\n", - ctdb_addr_to_str(&conn->dst))); - continue; - } /* If the IP address is hosted on this node then * remove the connection. */ - if (vnn->pnn == client->ctdb->pnn) { + if (vnn != NULL && vnn->pnn == client->ctdb->pnn) { ctdb_remove_connection(vnn, conn); } @@ -1621,6 +1616,11 @@ void ctdb_takeover_client_destructor_hook(struct ctdb_client *client) * and the client has exited. This means that we * should not delete the connection information. The * takeover node processes connections too. */ + + /* + * The destructor removes from the list + */ + TALLOC_FREE(tcp); } } -- 2.11.4.GIT