2007-05-25 11:16:50 +04:00
/*
ctdb recovery code
Copyright ( C ) Ronnie Sahlberg 2007
Copyright ( C ) Andrew Tridgell 2007
2007-05-31 07:50:53 +04:00
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 09:29:31 +04:00
the Free Software Foundation ; either version 3 of the License , or
2007-05-31 07:50:53 +04:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
2007-05-25 11:16:50 +04:00
but WITHOUT ANY WARRANTY ; without even the implied warranty of
2007-05-31 07:50:53 +04:00
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 09:29:31 +04:00
along with this program ; if not , see < http : //www.gnu.org/licenses/>.
2007-05-25 11:16:50 +04:00
*/
# include "includes.h"
# include "lib/events/events.h"
# include "lib/tdb/include/tdb.h"
2007-06-07 16:26:27 +04:00
# include "lib/util/dlinklist.h"
2007-05-25 11:16:50 +04:00
# include "system/network.h"
# include "system/filesys.h"
# include "system/wait.h"
# include "../include/ctdb_private.h"
2007-08-08 09:09:19 +04:00
# include "../common/rb_tree.h"
2007-05-25 11:16:50 +04:00
2007-06-05 11:43:19 +04:00
# define TAKEOVER_TIMEOUT() timeval_current_ofs(ctdb->tunable.takeover_timeout,0)
2007-05-25 11:16:50 +04:00
2007-05-27 09:26:29 +04:00
# define CTDB_ARP_INTERVAL 1
# define CTDB_ARP_REPEAT 3
2007-05-25 15:27:26 +04:00
struct ctdb_takeover_arp {
struct ctdb_context * ctdb ;
uint32_t count ;
struct sockaddr_in sin ;
2007-07-24 01:46:51 +04:00
struct ctdb_tcp_array * tcparray ;
2007-09-04 03:50:07 +04:00
struct ctdb_vnn * vnn ;
2007-05-25 15:27:26 +04:00
} ;
2007-07-20 04:06:41 +04:00
2007-05-27 09:26:29 +04:00
/*
lists of tcp endpoints
*/
struct ctdb_tcp_list {
struct ctdb_tcp_list * prev , * next ;
2007-07-20 04:06:41 +04:00
struct ctdb_tcp_connection connection ;
2007-05-27 09:26:29 +04:00
} ;
2007-06-18 21:54:06 +04:00
/*
list of clients to kill on IP release
*/
struct ctdb_client_ip {
struct ctdb_client_ip * prev , * next ;
struct ctdb_context * ctdb ;
struct sockaddr_in ip ;
uint32_t client_id ;
} ;
2007-05-25 15:27:26 +04:00
/*
send a gratuitous arp
*/
static void ctdb_control_send_arp ( struct event_context * ev , struct timed_event * te ,
struct timeval t , void * private_data )
{
struct ctdb_takeover_arp * arp = talloc_get_type ( private_data ,
struct ctdb_takeover_arp ) ;
2007-07-24 01:46:51 +04:00
int i , s , ret ;
struct ctdb_tcp_array * tcparray ;
2007-05-25 15:27:26 +04:00
2007-09-04 03:50:07 +04:00
ret = ctdb_sys_send_arp ( & arp - > sin , arp - > vnn - > vnn_list - > iface ) ;
2007-05-25 15:27:26 +04:00
if ( ret ! = 0 ) {
2007-06-09 15:47:06 +04:00
DEBUG ( 0 , ( __location__ " sending of arp failed (%s) \n " , strerror ( errno ) ) ) ;
2007-05-25 15:27:26 +04:00
}
2007-07-12 03:22:06 +04:00
s = ctdb_sys_open_sending_socket ( ) ;
if ( s = = - 1 ) {
DEBUG ( 0 , ( __location__ " failed to open raw socket for sending tickles \n " ) ) ;
return ;
}
2007-07-24 01:46:51 +04:00
tcparray = arp - > tcparray ;
if ( tcparray ) {
for ( i = 0 ; i < tcparray - > num ; i + + ) {
DEBUG ( 2 , ( " sending tcp tickle ack for %u->%s:%u \n " ,
( unsigned ) ntohs ( tcparray - > connections [ i ] . daddr . sin_port ) ,
inet_ntoa ( tcparray - > connections [ i ] . saddr . sin_addr ) ,
( unsigned ) ntohs ( tcparray - > connections [ i ] . saddr . sin_port ) ) ) ;
ret = ctdb_sys_send_tcp ( s , & tcparray - > connections [ i ] . saddr ,
& tcparray - > connections [ i ] . daddr , 0 , 0 , 0 ) ;
if ( ret ! = 0 ) {
DEBUG ( 0 , ( __location__ " Failed to send tcp tickle ack for %s \n " ,
inet_ntoa ( tcparray - > connections [ i ] . saddr . sin_addr ) ) ) ;
}
2007-05-27 09:26:29 +04:00
}
}
2007-07-12 03:22:06 +04:00
close ( s ) ;
2007-05-25 15:27:26 +04:00
arp - > count + + ;
if ( arp - > count = = CTDB_ARP_REPEAT ) {
talloc_free ( arp ) ;
return ;
}
2007-07-12 03:22:06 +04:00
2007-09-04 03:50:07 +04:00
event_add_timed ( arp - > ctdb - > ev , arp - > ctdb - > takeover_ctx ,
2007-05-25 15:27:26 +04:00
timeval_current_ofs ( CTDB_ARP_INTERVAL , 0 ) ,
ctdb_control_send_arp , arp ) ;
}
2007-06-01 13:05:41 +04:00
struct takeover_callback_state {
struct ctdb_req_control * c ;
struct sockaddr_in * sin ;
2007-09-04 03:50:07 +04:00
struct ctdb_vnn * vnn ;
2007-06-01 13:05:41 +04:00
} ;
2007-05-27 09:26:29 +04:00
2007-05-25 11:16:50 +04:00
/*
2007-06-01 13:05:41 +04:00
called when takeip event finishes
2007-05-25 11:16:50 +04:00
*/
2007-06-01 13:05:41 +04:00
static void takeover_ip_callback ( struct ctdb_context * ctdb , int status ,
void * private_data )
2007-05-25 11:16:50 +04:00
{
2007-06-01 13:05:41 +04:00
struct takeover_callback_state * state =
talloc_get_type ( private_data , struct takeover_callback_state ) ;
2007-05-25 15:27:26 +04:00
struct ctdb_takeover_arp * arp ;
2007-06-01 13:05:41 +04:00
char * ip = inet_ntoa ( state - > sin - > sin_addr ) ;
2007-07-20 04:06:41 +04:00
struct ctdb_tcp_array * tcparray ;
2007-05-25 11:16:50 +04:00
2007-06-06 07:45:12 +04:00
ctdb_start_monitoring ( ctdb ) ;
2007-06-01 13:05:41 +04:00
if ( status ! = 0 ) {
2007-05-26 08:01:08 +04:00
DEBUG ( 0 , ( __location__ " Failed to takeover IP %s on interface %s \n " ,
2007-09-04 03:50:07 +04:00
ip , state - > vnn - > vnn_list - > iface ) ) ;
2007-06-01 13:05:41 +04:00
ctdb_request_control_reply ( ctdb , state - > c , NULL , status , NULL ) ;
talloc_free ( state ) ;
return ;
2007-05-26 08:01:08 +04:00
}
2007-05-25 11:16:50 +04:00
2007-09-04 03:50:07 +04:00
if ( ! ctdb - > takeover_ctx ) {
ctdb - > takeover_ctx = talloc_new ( ctdb ) ;
if ( ! ctdb - > takeover_ctx ) goto failed ;
2007-05-25 11:16:50 +04:00
}
2007-09-04 03:50:07 +04:00
arp = talloc_zero ( ctdb - > takeover_ctx , struct ctdb_takeover_arp ) ;
2007-06-01 13:05:41 +04:00
if ( ! arp ) goto failed ;
2007-05-25 15:27:26 +04:00
arp - > ctdb = ctdb ;
2007-06-01 13:05:41 +04:00
arp - > sin = * state - > sin ;
2007-09-04 03:50:07 +04:00
arp - > vnn = state - > vnn ;
2007-05-25 15:27:26 +04:00
2007-09-04 03:50:07 +04:00
tcparray = state - > vnn - > tcp_array ;
2007-07-20 04:06:41 +04:00
if ( tcparray ) {
/* add all of the known tcp connections for this IP to the
list of tcp connections to send tickle acks for */
2007-07-25 02:03:58 +04:00
arp - > tcparray = talloc_steal ( arp , tcparray ) ;
2007-07-20 04:06:41 +04:00
2007-09-04 03:50:07 +04:00
state - > vnn - > tcp_array = NULL ;
state - > vnn - > tcp_update_needed = true ;
2007-05-27 09:26:29 +04:00
}
2007-09-04 03:50:07 +04:00
event_add_timed ( arp - > ctdb - > ev , arp - > ctdb - > takeover_ctx ,
2007-05-25 15:27:26 +04:00
timeval_zero ( ) , ctdb_control_send_arp , arp ) ;
2007-06-01 13:05:41 +04:00
/* the control succeeded */
ctdb_request_control_reply ( ctdb , state - > c , NULL , 0 , NULL ) ;
talloc_free ( state ) ;
return ;
failed :
ctdb_request_control_reply ( ctdb , state - > c , NULL , - 1 , NULL ) ;
talloc_free ( state ) ;
return ;
2007-05-25 11:16:50 +04:00
}
2007-07-20 04:06:41 +04:00
/*
Find the vnn of the node that has a public ip address
returns - 1 if the address is not known as a public address
*/
2007-09-04 03:50:07 +04:00
static struct ctdb_vnn * find_public_ip_vnn ( struct ctdb_context * ctdb , char * ip )
2007-07-20 04:06:41 +04:00
{
2007-09-04 03:50:07 +04:00
struct ctdb_vnn_list * vnn_list ;
struct ctdb_vnn * vnn ;
2007-07-20 04:06:41 +04:00
2007-09-04 03:50:07 +04:00
for ( vnn_list = ctdb - > vnn_list ; vnn_list ; vnn_list = vnn_list - > next ) {
for ( vnn = vnn_list - > vnn ; vnn ; vnn = vnn - > next ) {
if ( ! strcmp ( vnn - > public_address , ip ) ) {
return vnn ;
}
2007-07-20 04:06:41 +04:00
}
}
2007-09-04 03:50:07 +04:00
return NULL ;
2007-07-20 04:06:41 +04:00
}
2007-05-25 11:16:50 +04:00
/*
2007-06-01 13:05:41 +04:00
take over an ip address
2007-05-25 11:16:50 +04:00
*/
2007-06-01 13:05:41 +04:00
int32_t ctdb_control_takeover_ip ( struct ctdb_context * ctdb ,
struct ctdb_req_control * c ,
TDB_DATA indata ,
bool * async_reply )
2007-05-25 11:16:50 +04:00
{
2007-06-01 13:05:41 +04:00
int ret ;
struct takeover_callback_state * state ;
2007-06-04 14:07:37 +04:00
struct ctdb_public_ip * pip = ( struct ctdb_public_ip * ) indata . dptr ;
char * ip = inet_ntoa ( pip - > sin . sin_addr ) ;
2007-09-04 03:50:07 +04:00
struct ctdb_vnn * vnn ;
2007-06-04 14:07:37 +04:00
2007-09-04 03:50:07 +04:00
/* update out vnn list */
vnn - > pnn = pip - > pnn ;
vnn = find_public_ip_vnn ( ctdb , ip ) ;
if ( vnn = = NULL ) {
DEBUG ( 0 , ( " takeoverip called for an ip '%s' that is not a public address \n " , ip ) ) ;
return 0 ;
}
vnn - > pnn = pip - > pnn ;
2007-05-26 08:01:08 +04:00
2007-06-01 13:05:41 +04:00
/* if our kernel already has this IP, do nothing */
if ( ctdb_sys_have_ip ( ip ) ) {
2007-05-27 18:34:40 +04:00
return 0 ;
}
2007-06-01 13:05:41 +04:00
state = talloc ( ctdb , struct takeover_callback_state ) ;
CTDB_NO_MEMORY ( ctdb , state ) ;
state - > c = talloc_steal ( ctdb , c ) ;
state - > sin = talloc ( ctdb , struct sockaddr_in ) ;
CTDB_NO_MEMORY ( ctdb , state - > sin ) ;
2007-06-04 17:54:56 +04:00
* state - > sin = pip - > sin ;
2007-06-01 13:05:41 +04:00
2007-09-04 03:50:07 +04:00
state - > vnn = vnn ;
2007-07-20 04:06:41 +04:00
2007-09-04 08:21:35 +04:00
DEBUG ( 0 , ( " Takeover of IP %s/%u on interface %s \n " ,
2007-09-04 03:50:07 +04:00
ip , vnn - > public_netmask_bits ,
vnn - > vnn_list - > iface ) ) ;
2007-05-25 11:16:50 +04:00
2007-06-06 07:45:12 +04:00
ctdb_stop_monitoring ( ctdb ) ;
ret = ctdb_event_script_callback ( ctdb ,
timeval_current_ofs ( ctdb - > tunable . script_timeout , 0 ) ,
state , takeover_ip_callback , state ,
2007-06-01 13:05:41 +04:00
" takeip %s %s %u " ,
2007-09-04 03:50:07 +04:00
vnn - > vnn_list - > iface ,
2007-06-01 13:05:41 +04:00
ip ,
2007-09-04 03:50:07 +04:00
vnn - > public_netmask_bits ) ;
2007-05-26 08:01:08 +04:00
if ( ret ! = 0 ) {
2007-06-01 13:05:41 +04:00
DEBUG ( 0 , ( __location__ " Failed to takeover IP %s on interface %s \n " ,
2007-09-04 03:50:07 +04:00
ip , vnn - > vnn_list - > iface ) ) ;
2007-06-01 13:05:41 +04:00
talloc_free ( state ) ;
2007-05-26 08:01:08 +04:00
return - 1 ;
}
2007-05-25 11:16:50 +04:00
2007-06-01 13:05:41 +04:00
/* tell ctdb_control.c that we will be replying asynchronously */
* async_reply = true ;
return 0 ;
}
2007-06-18 21:54:06 +04:00
/*
kill any clients that are registered with a IP that is being released
*/
2007-07-08 14:45:12 +04:00
static void release_kill_clients ( struct ctdb_context * ctdb , struct in_addr in )
2007-06-18 21:54:06 +04:00
{
struct ctdb_client_ip * ip ;
for ( ip = ctdb - > client_ip_list ; ip ; ip = ip - > next ) {
2007-07-08 14:45:12 +04:00
if ( ip - > ip . sin_addr . s_addr = = in . s_addr ) {
2007-06-18 21:54:06 +04:00
struct ctdb_client * client = ctdb_reqid_find ( ctdb ,
ip - > client_id ,
struct ctdb_client ) ;
if ( client - > pid ! = 0 ) {
DEBUG ( 0 , ( __location__ " Killing client pid %u for IP %s on client_id %u \n " ,
2007-07-08 14:45:12 +04:00
( unsigned ) client - > pid , inet_ntoa ( in ) ,
ip - > client_id ) ) ;
2007-06-18 21:54:06 +04:00
kill ( client - > pid , SIGKILL ) ;
}
}
}
}
2007-06-01 13:05:41 +04:00
/*
called when releaseip event finishes
*/
static void release_ip_callback ( struct ctdb_context * ctdb , int status ,
void * private_data )
{
struct takeover_callback_state * state =
talloc_get_type ( private_data , struct takeover_callback_state ) ;
char * ip = inet_ntoa ( state - > sin - > sin_addr ) ;
TDB_DATA data ;
2007-06-06 07:45:12 +04:00
ctdb_start_monitoring ( ctdb ) ;
2007-05-25 18:05:30 +04:00
/* send a message to all clients of this node telling them
that the cluster has been reconfigured and they should
release any sockets on this IP */
data . dptr = ( uint8_t * ) ip ;
data . dsize = strlen ( ip ) + 1 ;
2007-09-04 04:06:36 +04:00
ctdb_daemon_send_message ( ctdb , ctdb - > pnn , CTDB_SRVID_RELEASE_IP , data ) ;
2007-05-25 18:05:30 +04:00
2007-06-18 21:54:06 +04:00
/* kill clients that have registered with this IP */
2007-07-08 14:45:12 +04:00
release_kill_clients ( ctdb , state - > sin - > sin_addr ) ;
2007-06-18 21:54:06 +04:00
2007-06-01 13:05:41 +04:00
/* the control succeeded */
ctdb_request_control_reply ( ctdb , state - > c , NULL , 0 , NULL ) ;
talloc_free ( state ) ;
}
/*
release an ip address
*/
int32_t ctdb_control_release_ip ( struct ctdb_context * ctdb ,
struct ctdb_req_control * c ,
TDB_DATA indata ,
bool * async_reply )
{
int ret ;
struct takeover_callback_state * state ;
2007-06-04 14:07:37 +04:00
struct ctdb_public_ip * pip = ( struct ctdb_public_ip * ) indata . dptr ;
char * ip = inet_ntoa ( pip - > sin . sin_addr ) ;
2007-09-04 03:50:07 +04:00
struct ctdb_vnn * vnn ;
2007-06-04 14:07:37 +04:00
2007-09-04 03:50:07 +04:00
/* update our vnn list */
vnn = find_public_ip_vnn ( ctdb , ip ) ;
if ( vnn = = NULL ) {
DEBUG ( 0 , ( " releaseip called for an ip '%s' that is not a public address \n " , ip ) ) ;
return 0 ;
}
vnn - > pnn = pip - > pnn ;
2007-06-01 13:05:41 +04:00
if ( ! ctdb_sys_have_ip ( ip ) ) {
return 0 ;
}
DEBUG ( 0 , ( " Release of IP %s/%u on interface %s \n " ,
2007-09-04 03:50:07 +04:00
ip , vnn - > public_netmask_bits ,
vnn - > vnn_list - > iface ) ) ;
2007-06-01 13:05:41 +04:00
/* stop any previous arps */
2007-09-04 03:50:07 +04:00
talloc_free ( ctdb - > takeover_ctx ) ;
ctdb - > takeover_ctx = NULL ;
2007-06-01 13:05:41 +04:00
state = talloc ( ctdb , struct takeover_callback_state ) ;
CTDB_NO_MEMORY ( ctdb , state ) ;
state - > c = talloc_steal ( state , c ) ;
state - > sin = talloc ( state , struct sockaddr_in ) ;
CTDB_NO_MEMORY ( ctdb , state - > sin ) ;
2007-06-04 17:54:56 +04:00
* state - > sin = pip - > sin ;
2007-06-01 13:05:41 +04:00
2007-09-04 03:50:07 +04:00
state - > vnn = vnn ;
2007-07-20 04:06:41 +04:00
2007-06-06 07:45:12 +04:00
ctdb_stop_monitoring ( ctdb ) ;
ret = ctdb_event_script_callback ( ctdb ,
timeval_current_ofs ( ctdb - > tunable . script_timeout , 0 ) ,
state , release_ip_callback , state ,
2007-06-01 13:05:41 +04:00
" releaseip %s %s %u " ,
2007-09-04 03:50:07 +04:00
vnn - > vnn_list - > iface ,
2007-06-01 13:05:41 +04:00
ip ,
2007-09-04 03:50:07 +04:00
vnn - > public_netmask_bits ) ;
2007-06-01 13:05:41 +04:00
if ( ret ! = 0 ) {
DEBUG ( 0 , ( __location__ " Failed to release IP %s on interface %s \n " ,
2007-09-04 03:50:07 +04:00
ip , vnn - > vnn_list - > iface ) ) ;
2007-06-01 13:05:41 +04:00
talloc_free ( state ) ;
return - 1 ;
}
/* tell the control that we will be reply asynchronously */
* async_reply = true ;
2007-05-27 18:51:10 +04:00
2007-05-25 11:16:50 +04:00
return 0 ;
}
2007-09-04 03:50:07 +04:00
static int add_public_address ( struct ctdb_context * ctdb , int ip0 , int ip1 , int ip2 , int ip3 , int nm , char * iface )
{
struct ctdb_vnn * vnn ;
struct ctdb_vnn_list * vnn_list ;
const char * public_address ;
/* first find the entry for this interface if we have one */
for ( vnn_list = ctdb - > vnn_list ; vnn_list ; vnn_list = vnn_list - > next ) {
if ( ! strcmp ( iface , vnn_list - > iface ) ) {
break ;
}
}
/* If we dont have a vnn_list for this interface, we must create one */
if ( vnn_list = = NULL ) {
vnn_list = talloc_zero ( ctdb , struct ctdb_vnn_list ) ;
CTDB_NO_MEMORY_FATAL ( ctdb , vnn_list ) ;
vnn_list - > iface = talloc_strdup ( vnn_list , iface ) ;
vnn_list - > next = ctdb - > vnn_list ;
ctdb - > vnn_list = vnn_list ;
}
/* Verify that we dont have an entry for this ip yet */
public_address = talloc_asprintf ( vnn_list , " %d.%d.%d.%d " , ip0 , ip1 , ip2 , ip3 ) ;
CTDB_NO_MEMORY_FATAL ( ctdb , public_address ) ;
for ( vnn = vnn_list - > vnn ; vnn ; vnn = vnn - > next ) {
if ( ! strcmp ( public_address , vnn - > public_address ) ) {
DEBUG ( 0 , ( " Same ip '%s' specified multiple times in the public address list \n " , public_address ) ) ;
exit ( 1 ) ;
}
}
/* make sure the netmask is ok */
if ( nm > 32 ) {
DEBUG ( 0 , ( " Illegal netmask for IP %s \n " , public_address ) ) ;
return - 1 ;
}
/* create a new vnn structure for this ip address */
vnn = talloc_zero ( vnn_list , struct ctdb_vnn ) ;
CTDB_NO_MEMORY_FATAL ( ctdb , vnn ) ;
vnn - > vnn_list = vnn_list ;
vnn - > public_address = talloc_steal ( vnn , public_address ) ;
vnn - > public_netmask_bits = nm ;
vnn - > pnn = - 1 ;
vnn - > next = vnn_list - > vnn ;
vnn_list - > vnn = vnn ;
vnn_list - > num_ips + + ;
return 0 ;
}
2007-08-15 08:44:03 +04:00
/*
setup the event script directory
*/
int ctdb_set_event_script_dir ( struct ctdb_context * ctdb , const char * script_dir )
{
2007-09-04 03:50:07 +04:00
ctdb - > event_script_dir = talloc_strdup ( ctdb , script_dir ) ;
CTDB_NO_MEMORY ( ctdb , ctdb - > event_script_dir ) ;
2007-05-29 06:49:25 +04:00
return 0 ;
}
2007-05-25 11:16:50 +04:00
/*
2007-09-04 03:50:07 +04:00
setup the public address lists from a file
2007-05-25 11:16:50 +04:00
*/
int ctdb_set_public_addresses ( struct ctdb_context * ctdb , const char * alist )
{
char * * lines ;
int nlines ;
int i ;
lines = file_lines_load ( alist , & nlines , ctdb ) ;
if ( lines = = NULL ) {
ctdb_set_error ( ctdb , " Failed to load public address list '%s' \n " , alist ) ;
return - 1 ;
}
2007-05-29 10:23:47 +04:00
while ( nlines > 0 & & strcmp ( lines [ nlines - 1 ] , " " ) = = 0 ) {
nlines - - ;
}
2007-05-25 11:16:50 +04:00
for ( i = 0 ; i < nlines ; i + + ) {
2007-09-04 03:50:07 +04:00
int ip0 , ip1 , ip2 , ip3 , nm ;
char iface [ 256 ] ;
2007-05-29 06:16:59 +04:00
2007-09-04 03:50:07 +04:00
if ( sscanf ( lines [ i ] , " %d.%d.%d.%d/%d %255s " , & ip0 , & ip1 , & ip2 , & ip3 , & nm , iface ) ! = 6 ) {
DEBUG ( 0 , ( " Badly formed line '%s' in public address list \n " , lines [ i ] ) ) ;
talloc_free ( lines ) ;
2007-05-29 06:16:59 +04:00
return - 1 ;
}
2007-09-04 03:50:07 +04:00
if ( add_public_address ( ctdb , ip0 , ip1 , ip2 , ip3 , nm , iface ) ) {
DEBUG ( 0 , ( " Failed to add '%s' to the public address list \n " , lines [ i ] ) ) ;
talloc_free ( lines ) ;
2007-05-29 06:16:59 +04:00
return - 1 ;
}
2007-05-25 11:16:50 +04:00
}
talloc_free ( lines ) ;
return 0 ;
}
2007-05-29 06:16:59 +04:00
2007-09-04 03:50:07 +04:00
/* Given a physical node and an interface, return the number of
public addresses that is currently assigned to this node / interface .
*/
static int node_ip_coverage ( struct ctdb_context * ctdb ,
int32_t pnn , struct ctdb_vnn_list * vnn_list )
{
int num = 0 ;
struct ctdb_vnn * vnn ;
2007-05-29 06:16:59 +04:00
2007-09-04 03:50:07 +04:00
for ( vnn = vnn_list - > vnn ; vnn ; vnn = vnn - > next ) {
if ( vnn - > pnn = = pnn ) {
num + + ;
}
2007-05-29 06:16:59 +04:00
}
2007-09-04 03:50:07 +04:00
return num ;
2007-05-29 06:16:59 +04:00
}
2007-05-25 11:16:50 +04:00
2007-09-04 03:50:07 +04:00
/* search the vnn list for a node to takeover vnn.
pick the node that currently are serving the least number of vnns for
this interface so that the vnns get spread out evenly .
*/
static int find_takeover_node ( struct ctdb_context * ctdb ,
struct ctdb_node_map * nodemap , uint32_t mask ,
struct ctdb_vnn_list * vnn_list , struct ctdb_vnn * vnn )
2007-06-07 09:18:55 +04:00
{
2007-09-04 03:50:07 +04:00
int pnn , min , num ;
int i ;
2007-07-16 02:36:09 +04:00
2007-09-04 03:50:07 +04:00
pnn = - 1 ;
for ( i = 0 ; i < nodemap - > num ; i + + ) {
if ( nodemap - > nodes [ i ] . flags & mask ) {
/* This node is not healty and can not be used to serve
a public address
*/
continue ;
2007-07-16 02:28:44 +04:00
}
2007-09-04 03:50:07 +04:00
num = node_ip_coverage ( ctdb , i , vnn_list ) ;
/* was this the first node we checked ? */
if ( pnn = = - 1 ) {
pnn = i ;
min = num ;
} else {
if ( num < min ) {
pnn = i ;
min = num ;
}
2007-06-07 09:18:55 +04:00
}
2007-09-04 03:50:07 +04:00
}
if ( pnn = = - 1 ) {
DEBUG ( 0 , ( __location__ " Could not find node to take over public address '%s' \n " , vnn - > public_address ) ) ;
return - 1 ;
2007-06-07 09:18:55 +04:00
}
2007-07-16 02:28:44 +04:00
2007-09-04 03:50:07 +04:00
vnn - > pnn = pnn ;
return 0 ;
2007-06-07 09:18:55 +04:00
}
2007-05-25 11:16:50 +04:00
/*
make any IP alias changes for public addresses that are necessary
*/
int ctdb_takeover_run ( struct ctdb_context * ctdb , struct ctdb_node_map * nodemap )
{
2007-09-04 03:50:07 +04:00
int i , num_healthy ;
2007-05-25 11:16:50 +04:00
int ret ;
2007-06-04 14:07:37 +04:00
struct ctdb_public_ip ip ;
2007-09-04 03:50:07 +04:00
uint32_t mask ;
struct ctdb_vnn_list * vnn_list ;
struct ctdb_vnn * vnn ;
int maxnode , maxnum , minnode , minnum , num ;
2007-05-25 11:16:50 +04:00
2007-06-10 03:54:27 +04:00
ZERO_STRUCT ( ip ) ;
2007-09-04 03:50:07 +04:00
/* Count how many completely healthy nodes we have */
num_healthy = 0 ;
2007-05-25 11:16:50 +04:00
for ( i = 0 ; i < nodemap - > num ; i + + ) {
2007-06-07 09:18:55 +04:00
if ( ! ( nodemap - > nodes [ i ] . flags & ( NODE_FLAGS_INACTIVE | NODE_FLAGS_DISABLED ) ) ) {
2007-09-04 03:50:07 +04:00
num_healthy + + ;
}
}
2007-08-20 08:16:58 +04:00
2007-09-04 03:50:07 +04:00
if ( num_healthy > 0 ) {
/* We have healthy nodes, so only consider them for
serving public addresses
*/
mask = NODE_FLAGS_INACTIVE | NODE_FLAGS_DISABLED ;
} else {
/* We didnt have any completely healthy nodes so
use " disabled " nodes as a fallback
*/
mask = NODE_FLAGS_INACTIVE ;
}
/* mark all public addresses with a masked node as being served by
node - 1
*/
for ( vnn_list = ctdb - > vnn_list ; vnn_list ; vnn_list = vnn_list - > next ) {
for ( vnn = vnn_list - > vnn ; vnn ; vnn = vnn - > next ) {
if ( vnn - > pnn = = - 1 ) {
2007-08-20 08:16:58 +04:00
continue ;
}
2007-09-04 03:50:07 +04:00
if ( nodemap - > nodes [ vnn - > pnn ] . flags & mask ) {
vnn - > pnn = - 1 ;
}
}
}
2007-08-20 08:16:58 +04:00
2007-09-04 03:50:07 +04:00
/* now we must redistribute all public addresses with takeover node
- 1 among the nodes available
*/
for ( vnn_list = ctdb - > vnn_list ; vnn_list ; vnn_list = vnn_list - > next ) {
try_again :
/* loop over all vnn's and find a physical node to cover for
each unassigned vnn .
*/
for ( vnn = vnn_list - > vnn ; vnn ; vnn = vnn - > next ) {
if ( vnn - > pnn = = - 1 ) {
if ( find_takeover_node ( ctdb , nodemap , mask , vnn_list , vnn ) ) {
DEBUG ( 0 , ( " Failed to find node to cover ip %s \n " , vnn - > public_address ) ) ;
return - 1 ;
}
}
}
2007-06-07 09:18:55 +04:00
2007-09-04 03:50:07 +04:00
/* Get the highest and lowes number of vnn's a valid node
covers for this interface
*/
maxnode = - 1 ;
minnode = - 1 ;
for ( i = 0 ; i < nodemap - > num ; i + + ) {
if ( nodemap - > nodes [ i ] . flags & mask ) {
continue ;
}
num = node_ip_coverage ( ctdb , i , vnn_list ) ;
if ( maxnode = = - 1 ) {
maxnode = i ;
maxnum = num ;
} else {
if ( num > maxnum ) {
maxnode = i ;
maxnum = num ;
}
}
if ( minnode = = - 1 ) {
minnode = i ;
minnum = num ;
} else {
if ( num < minnum ) {
minnode = i ;
minnum = num ;
}
2007-06-06 10:49:59 +04:00
}
2007-09-04 03:50:07 +04:00
}
if ( maxnode = = - 1 ) {
DEBUG ( 0 , ( __location__ " Could not find maxnode \n " ) ) ;
return - 1 ;
}
2007-06-07 09:18:55 +04:00
2007-09-04 03:50:07 +04:00
/* if the spread between the smallest and largest coverage by
a node is > = 2 we steal one of the ips from the node with the
most coverage to even things out a bit
*/
if ( maxnum > minnum + 1 ) {
/* mark one of maxnode's vnn's as unassigned and try
again
*/
for ( vnn = vnn_list - > vnn ; vnn ; vnn = vnn - > next ) {
if ( vnn - > pnn = = maxnode ) {
vnn - > pnn = - 1 ;
goto try_again ;
}
2007-05-25 11:16:50 +04:00
}
}
2007-09-04 03:50:07 +04:00
}
2007-05-25 11:16:50 +04:00
2007-09-04 03:50:07 +04:00
/* at this point ->pnn is the node which will own each IP */
2007-05-25 11:16:50 +04:00
/* now tell all nodes to delete any alias that they should not
have . This will be a NOOP on nodes that don ' t currently
hold the given alias */
for ( i = 0 ; i < nodemap - > num ; i + + ) {
2007-07-08 14:24:03 +04:00
/* don't talk to unconnected nodes, but do talk to banned nodes */
if ( nodemap - > nodes [ i ] . flags & NODE_FLAGS_DISCONNECTED ) {
2007-06-07 09:18:55 +04:00
continue ;
}
2007-05-25 11:16:50 +04:00
2007-09-04 03:50:07 +04:00
for ( vnn_list = ctdb - > vnn_list ; vnn_list ; vnn_list = vnn_list - > next ) {
for ( vnn = vnn_list - > vnn ; vnn ; vnn = vnn - > next ) {
if ( vnn - > pnn = = nodemap - > nodes [ i ] . pnn ) {
/* This node should be serving this
vnn so dont tell it to release the ip
*/
continue ;
}
ip . pnn = vnn - > pnn ;
2007-06-04 14:07:37 +04:00
ip . sin . sin_family = AF_INET ;
2007-09-04 03:50:07 +04:00
inet_aton ( vnn - > public_address , & ip . sin . sin_addr ) ;
2007-06-04 14:07:37 +04:00
2007-05-25 11:16:50 +04:00
ret = ctdb_ctrl_release_ip ( ctdb , TAKEOVER_TIMEOUT ( ) ,
2007-09-04 03:50:07 +04:00
nodemap - > nodes [ i ] . pnn ,
2007-06-04 14:07:37 +04:00
& ip ) ;
2007-05-25 11:16:50 +04:00
if ( ret ! = 0 ) {
DEBUG ( 0 , ( " Failed to tell vnn %u to release IP %s \n " ,
2007-09-04 03:50:07 +04:00
nodemap - > nodes [ i ] . pnn ,
vnn - > public_address ) ) ;
2007-05-25 11:16:50 +04:00
return - 1 ;
}
}
}
}
/* tell all nodes to get their own IPs */
2007-09-04 03:50:07 +04:00
for ( vnn_list = ctdb - > vnn_list ; vnn_list ; vnn_list = vnn_list - > next ) {
for ( vnn = vnn_list - > vnn ; vnn ; vnn = vnn - > next ) {
if ( vnn - > pnn = = - 1 ) {
/* this IP won't be taken over */
continue ;
}
ip . pnn = vnn - > pnn ;
ip . sin . sin_family = AF_INET ;
inet_aton ( vnn - > public_address , & ip . sin . sin_addr ) ;
2007-06-04 14:07:37 +04:00
2007-09-04 03:50:07 +04:00
ret = ctdb_ctrl_takeover_ip ( ctdb , TAKEOVER_TIMEOUT ( ) ,
vnn - > pnn ,
2007-06-04 14:07:37 +04:00
& ip ) ;
2007-09-04 03:50:07 +04:00
if ( ret ! = 0 ) {
DEBUG ( 0 , ( " Failed asking vnn %u to take over IP %s \n " ,
vnn - > pnn ,
vnn - > public_address ) ) ;
return - 1 ;
}
2007-05-25 11:16:50 +04:00
}
}
return 0 ;
}
2007-05-27 09:26:29 +04:00
2007-06-18 21:54:06 +04:00
/*
destroy a ctdb_client_ip structure
*/
static int ctdb_client_ip_destructor ( struct ctdb_client_ip * ip )
{
DLIST_REMOVE ( ip - > ctdb - > client_ip_list , ip ) ;
return 0 ;
}
2007-05-27 09:26:29 +04:00
/*
called by a client to inform us of a TCP connection that it is managing
that should tickled with an ACK when IP takeover is done
*/
2007-07-20 04:06:41 +04:00
int32_t ctdb_control_tcp_client ( struct ctdb_context * ctdb , uint32_t client_id ,
2007-05-27 09:26:29 +04:00
TDB_DATA indata )
{
struct ctdb_client * client = ctdb_reqid_find ( ctdb , client_id , struct ctdb_client ) ;
struct ctdb_control_tcp * p = ( struct ctdb_control_tcp * ) indata . dptr ;
struct ctdb_tcp_list * tcp ;
2007-05-27 18:34:40 +04:00
struct ctdb_control_tcp_vnn t ;
2007-05-27 09:26:29 +04:00
int ret ;
2007-05-27 18:34:40 +04:00
TDB_DATA data ;
2007-06-18 21:54:06 +04:00
struct ctdb_client_ip * ip ;
2007-07-20 04:06:41 +04:00
char * addr ;
2007-09-04 03:50:07 +04:00
struct ctdb_vnn * vnn ;
2007-06-18 21:54:06 +04:00
2007-08-27 05:49:42 +04:00
addr = inet_ntoa ( p - > dest . sin_addr ) ;
2007-09-04 03:50:07 +04:00
vnn = find_public_ip_vnn ( ctdb , addr ) ;
if ( vnn = = NULL ) {
2007-08-27 05:49:42 +04:00
DEBUG ( 3 , ( " Could not add client IP %s. This is not a public address. \n " , addr ) ) ;
return 0 ;
}
2007-06-18 21:54:06 +04:00
ip = talloc ( client , struct ctdb_client_ip ) ;
CTDB_NO_MEMORY ( ctdb , ip ) ;
ip - > ctdb = ctdb ;
ip - > ip = p - > dest ;
ip - > client_id = client_id ;
talloc_set_destructor ( ip , ctdb_client_ip_destructor ) ;
DLIST_ADD ( ctdb - > client_ip_list , ip ) ;
2007-05-27 09:26:29 +04:00
tcp = talloc ( client , struct ctdb_tcp_list ) ;
CTDB_NO_MEMORY ( ctdb , tcp ) ;
2007-07-20 04:06:41 +04:00
tcp - > connection . saddr = p - > src ;
tcp - > connection . daddr = p - > dest ;
2007-05-27 09:26:29 +04:00
DLIST_ADD ( client - > tcp_list , tcp ) ;
2007-05-27 18:34:40 +04:00
t . src = p - > src ;
t . dest = p - > dest ;
data . dptr = ( uint8_t * ) & t ;
data . dsize = sizeof ( t ) ;
2007-07-19 09:04:54 +04:00
DEBUG ( 2 , ( " registered tcp client for %u->%s:%u \n " ,
( unsigned ) ntohs ( p - > dest . sin_port ) ,
2007-08-27 05:49:42 +04:00
inet_ntoa ( p - > src . sin_addr ) ,
2007-07-19 09:04:54 +04:00
( unsigned ) ntohs ( p - > src . sin_port ) ) ) ;
2007-05-27 09:26:29 +04:00
/* tell all nodes about this tcp connection */
2007-06-10 02:46:33 +04:00
ret = ctdb_daemon_send_control ( ctdb , CTDB_BROADCAST_CONNECTED , 0 ,
2007-05-27 09:26:29 +04:00
CTDB_CONTROL_TCP_ADD ,
2007-05-27 18:34:40 +04:00
0 , CTDB_CTRL_FLAG_NOREPLY , data , NULL , NULL ) ;
2007-05-27 09:26:29 +04:00
if ( ret ! = 0 ) {
DEBUG ( 0 , ( __location__ " Failed to send CTDB_CONTROL_TCP_ADD \n " ) ) ;
return - 1 ;
}
return 0 ;
}
/*
see if two sockaddr_in are the same
*/
static bool same_sockaddr_in ( struct sockaddr_in * in1 , struct sockaddr_in * in2 )
{
return in1 - > sin_family = = in2 - > sin_family & &
in1 - > sin_port = = in2 - > sin_port & &
in1 - > sin_addr . s_addr = = in2 - > sin_addr . s_addr ;
}
/*
find a tcp address on a list
*/
2007-07-20 04:06:41 +04:00
static struct ctdb_tcp_connection * ctdb_tcp_find ( struct ctdb_tcp_array * array ,
struct ctdb_tcp_connection * tcp )
2007-05-27 09:26:29 +04:00
{
2007-07-20 04:06:41 +04:00
int i ;
if ( array = = NULL ) {
return NULL ;
}
for ( i = 0 ; i < array - > num ; i + + ) {
if ( same_sockaddr_in ( & array - > connections [ i ] . saddr , & tcp - > saddr ) & &
same_sockaddr_in ( & array - > connections [ i ] . daddr , & tcp - > daddr ) ) {
return & array - > connections [ i ] ;
2007-05-27 09:26:29 +04:00
}
}
return NULL ;
}
/*
called by a daemon to inform us of a TCP connection that one of its
clients managing that should tickled with an ACK when IP takeover is
done
*/
int32_t ctdb_control_tcp_add ( struct ctdb_context * ctdb , TDB_DATA indata )
{
2007-05-27 18:34:40 +04:00
struct ctdb_control_tcp_vnn * p = ( struct ctdb_control_tcp_vnn * ) indata . dptr ;
2007-07-20 04:06:41 +04:00
struct ctdb_tcp_array * tcparray ;
struct ctdb_tcp_connection tcp ;
2007-09-04 03:50:07 +04:00
struct ctdb_vnn * vnn ;
char * addr ;
2007-05-27 09:26:29 +04:00
2007-09-04 03:50:07 +04:00
addr = inet_ntoa ( p - > dest . sin_addr ) ;
vnn = find_public_ip_vnn ( ctdb , addr ) ;
if ( vnn = = NULL ) {
DEBUG ( 0 , ( __location__ " got TCP_ADD control for an address which is not a public address '%s' \n " , addr ) ) ;
return - 1 ;
}
tcparray = vnn - > tcp_array ;
2007-07-20 04:06:41 +04:00
/* If this is the first tickle */
if ( tcparray = = NULL ) {
tcparray = talloc_size ( ctdb - > nodes ,
offsetof ( struct ctdb_tcp_array , connections ) +
sizeof ( struct ctdb_tcp_connection ) * 1 ) ;
CTDB_NO_MEMORY ( ctdb , tcparray ) ;
2007-09-04 03:50:07 +04:00
vnn - > tcp_array = tcparray ;
2007-07-20 04:06:41 +04:00
tcparray - > num = 0 ;
2007-07-20 09:05:55 +04:00
tcparray - > connections = talloc_size ( tcparray , sizeof ( struct ctdb_tcp_connection ) ) ;
CTDB_NO_MEMORY ( ctdb , tcparray - > connections ) ;
2007-07-20 04:06:41 +04:00
tcparray - > connections [ tcparray - > num ] . saddr = p - > src ;
tcparray - > connections [ tcparray - > num ] . daddr = p - > dest ;
tcparray - > num + + ;
return 0 ;
}
2007-05-27 09:26:29 +04:00
2007-07-20 04:06:41 +04:00
/* Do we already have this tickle ?*/
tcp . saddr = p - > src ;
tcp . daddr = p - > dest ;
2007-09-04 03:50:07 +04:00
if ( ctdb_tcp_find ( vnn - > tcp_array , & tcp ) ! = NULL ) {
DEBUG ( 4 , ( " Already had tickle info for %s:%u for vnn:%u \n " ,
2007-07-20 04:06:41 +04:00
inet_ntoa ( tcp . daddr . sin_addr ) ,
ntohs ( tcp . daddr . sin_port ) ,
2007-09-04 03:50:07 +04:00
vnn - > pnn ) ) ;
2007-07-20 04:06:41 +04:00
return 0 ;
2007-05-27 09:26:29 +04:00
}
2007-07-20 04:06:41 +04:00
/* A new tickle, we must add it to the array */
2007-07-20 09:05:55 +04:00
tcparray - > connections = talloc_realloc ( tcparray , tcparray - > connections ,
struct ctdb_tcp_connection ,
tcparray - > num + 1 ) ;
CTDB_NO_MEMORY ( ctdb , tcparray - > connections ) ;
2007-07-20 04:06:41 +04:00
2007-09-04 03:50:07 +04:00
vnn - > tcp_array = tcparray ;
2007-07-20 04:06:41 +04:00
tcparray - > connections [ tcparray - > num ] . saddr = p - > src ;
tcparray - > connections [ tcparray - > num ] . daddr = p - > dest ;
tcparray - > num + + ;
DEBUG ( 2 , ( " Added tickle info for %s:%u from vnn %u \n " ,
inet_ntoa ( tcp . daddr . sin_addr ) ,
ntohs ( tcp . daddr . sin_port ) ,
2007-09-04 03:50:07 +04:00
vnn - > pnn ) ) ;
2007-07-20 04:06:41 +04:00
2007-05-27 09:26:29 +04:00
return 0 ;
}
2007-07-11 12:24:25 +04:00
2007-05-27 09:26:29 +04:00
/*
called by a daemon to inform us of a TCP connection that one of its
clients managing that should tickled with an ACK when IP takeover is
done
*/
2007-07-20 09:05:55 +04:00
static void ctdb_remove_tcp_connection ( struct ctdb_context * ctdb , struct ctdb_tcp_connection * conn )
2007-05-27 09:26:29 +04:00
{
2007-07-20 09:05:55 +04:00
struct ctdb_tcp_connection * tcpp ;
2007-09-04 03:50:07 +04:00
struct ctdb_vnn * vnn = find_public_ip_vnn ( ctdb , inet_ntoa ( conn - > daddr . sin_addr ) ) ;
2007-07-20 04:06:41 +04:00
2007-09-04 03:50:07 +04:00
if ( vnn = = NULL ) {
2007-07-20 09:05:55 +04:00
DEBUG ( 0 , ( __location__ " unable to find public address %s \n " , inet_ntoa ( conn - > daddr . sin_addr ) ) ) ;
return ;
}
2007-07-20 04:06:41 +04:00
/* if the array is empty we cant remove it
and we dont need to do anything
*/
2007-09-04 03:50:07 +04:00
if ( vnn - > tcp_array = = NULL ) {
2007-07-20 09:05:55 +04:00
DEBUG ( 2 , ( " Trying to remove tickle that doesnt exist (array is empty) %s:%u \n " ,
inet_ntoa ( conn - > daddr . sin_addr ) ,
ntohs ( conn - > daddr . sin_port ) ) ) ;
return ;
2007-05-27 09:26:29 +04:00
}
2007-07-20 04:06:41 +04:00
/* See if we know this connection
if we dont know this connection then we dont need to do anything
*/
2007-09-04 03:50:07 +04:00
tcpp = ctdb_tcp_find ( vnn - > tcp_array , conn ) ;
2007-07-20 04:06:41 +04:00
if ( tcpp = = NULL ) {
2007-07-20 09:05:55 +04:00
DEBUG ( 2 , ( " Trying to remove tickle that doesnt exist %s:%u \n " ,
inet_ntoa ( conn - > daddr . sin_addr ) ,
ntohs ( conn - > daddr . sin_port ) ) ) ;
return ;
2007-07-20 04:06:41 +04:00
}
/* We need to remove this entry from the array.
Instead of allocating a new array and copying data to it
we cheat and just copy the last entry in the existing array
to the entry that is to be removed and just shring the
- > num field
*/
2007-09-04 03:50:07 +04:00
* tcpp = vnn - > tcp_array - > connections [ vnn - > tcp_array - > num - 1 ] ;
vnn - > tcp_array - > num - - ;
2007-07-20 04:06:41 +04:00
/* If we deleted the last entry we also need to remove the entire array
*/
2007-09-04 03:50:07 +04:00
if ( vnn - > tcp_array - > num = = 0 ) {
talloc_free ( vnn - > tcp_array ) ;
vnn - > tcp_array = NULL ;
2007-07-20 04:06:41 +04:00
}
2007-09-04 03:50:07 +04:00
vnn - > tcp_update_needed = true ;
2007-07-20 04:06:41 +04:00
2007-07-20 09:05:55 +04:00
DEBUG ( 2 , ( " Removed tickle info for %s:%u \n " ,
inet_ntoa ( conn - > saddr . sin_addr ) ,
ntohs ( conn - > saddr . sin_port ) ) ) ;
2007-05-27 09:26:29 +04:00
}
2007-05-27 18:34:40 +04:00
/*
2007-07-20 04:06:41 +04:00
called when a daemon restarts - send all tickes for all public addresses
we are serving immediately to the new node .
2007-05-27 18:34:40 +04:00
*/
int32_t ctdb_control_startup ( struct ctdb_context * ctdb , uint32_t vnn )
{
2007-07-20 04:06:41 +04:00
/*XXX here we should send all tickes we are serving to the new node */
2007-05-27 18:34:40 +04:00
return 0 ;
}
2007-05-27 09:26:29 +04:00
/*
called when a client structure goes away - hook to remove
elements from the tcp_list in all daemons
*/
void ctdb_takeover_client_destructor_hook ( struct ctdb_client * client )
{
while ( client - > tcp_list ) {
struct ctdb_tcp_list * tcp = client - > tcp_list ;
DLIST_REMOVE ( client - > tcp_list , tcp ) ;
2007-07-20 09:05:55 +04:00
ctdb_remove_tcp_connection ( client - > ctdb , & tcp - > connection ) ;
2007-05-27 09:26:29 +04:00
}
}
2007-05-29 07:33:59 +04:00
/*
release all IPs on shutdown
*/
void ctdb_release_all_ips ( struct ctdb_context * ctdb )
{
2007-09-04 03:50:07 +04:00
struct ctdb_vnn_list * vnn_list ;
struct ctdb_vnn * vnn ;
for ( vnn_list = ctdb - > vnn_list ; vnn_list ; vnn_list = vnn_list - > next ) {
for ( vnn = vnn_list - > vnn ; vnn ; vnn = vnn - > next ) {
if ( ctdb_sys_have_ip ( vnn - > public_address ) ) {
struct in_addr in ;
ctdb_event_script ( ctdb , " releaseip %s %s %u " ,
vnn_list - > iface ,
vnn - > public_address ,
vnn - > public_netmask_bits ) ;
if ( inet_aton ( vnn - > public_address , & in ) ! = 0 ) {
release_kill_clients ( ctdb , in ) ;
}
2007-07-08 14:45:12 +04:00
}
2007-05-29 07:33:59 +04:00
}
}
}
2007-06-04 15:11:51 +04:00
/*
2007-06-04 16:28:52 +04:00
get list of public IPs
2007-06-04 15:11:51 +04:00
*/
2007-07-13 05:31:18 +04:00
int32_t ctdb_control_get_public_ips ( struct ctdb_context * ctdb ,
struct ctdb_req_control * c , TDB_DATA * outdata )
2007-06-04 15:11:51 +04:00
{
2007-09-04 03:50:07 +04:00
int i , num , len ;
2007-06-04 15:11:51 +04:00
struct ctdb_all_public_ips * ips ;
2007-09-04 03:50:07 +04:00
struct ctdb_vnn_list * vnn_list ;
struct ctdb_vnn * vnn ;
/* count how many public ip structures we have */
num = 0 ;
for ( vnn_list = ctdb - > vnn_list ; vnn_list ; vnn_list = vnn_list - > next ) {
for ( vnn = vnn_list - > vnn ; vnn ; vnn = vnn - > next ) {
num + + ;
}
}
2007-06-04 15:11:51 +04:00
2007-07-13 05:31:18 +04:00
len = offsetof ( struct ctdb_all_public_ips , ips ) +
2007-09-04 03:50:07 +04:00
num * sizeof ( struct ctdb_public_ip ) ;
2007-06-04 16:28:52 +04:00
ips = talloc_zero_size ( outdata , len ) ;
2007-06-04 15:11:51 +04:00
CTDB_NO_MEMORY ( ctdb , ips ) ;
outdata - > dsize = len ;
outdata - > dptr = ( uint8_t * ) ips ;
2007-09-04 03:50:07 +04:00
ips - > num = num ;
i = 0 ;
for ( vnn_list = ctdb - > vnn_list ; vnn_list ; vnn_list = vnn_list - > next ) {
for ( vnn = vnn_list - > vnn ; vnn ; vnn = vnn - > next ) {
ips - > ips [ i ] . pnn = vnn - > pnn ;
ips - > ips [ i ] . sin . sin_family = AF_INET ;
inet_aton ( vnn - > public_address ,
2007-07-13 05:31:18 +04:00
& ips - > ips [ i ] . sin . sin_addr ) ;
2007-09-04 03:50:07 +04:00
i + + ;
2007-06-04 16:28:52 +04:00
}
2007-06-04 15:11:51 +04:00
}
return 0 ;
}
2007-07-11 06:33:14 +04:00
2007-07-13 05:31:18 +04:00
/*
structure containing the listening socket and the list of tcp connections
that the ctdb daemon is to kill
*/
struct ctdb_kill_tcp {
2007-09-04 03:50:07 +04:00
struct ctdb_vnn_list * vnn_list ;
2007-07-13 05:31:18 +04:00
struct ctdb_context * ctdb ;
int capture_fd ;
int sending_fd ;
struct fd_event * fde ;
2007-08-08 09:09:19 +04:00
trbt_tree_t * connections ;
2007-07-13 11:07:10 +04:00
void * private_data ;
2007-07-13 05:31:18 +04:00
} ;
2007-08-08 09:09:19 +04:00
/*
a tcp connection that is to be killed
*/
struct ctdb_killtcp_con {
struct sockaddr_in src ;
struct sockaddr_in dst ;
int count ;
struct ctdb_kill_tcp * killtcp ;
} ;
2007-08-15 04:01:00 +04:00
/* this function is used to create a key to represent this socketpair
in the killtcp tree .
this key is used to insert and lookup matching socketpairs that are
to be tickled and RST
*/
# define KILLTCP_KEYLEN 4
static uint32_t * killtcp_key ( struct sockaddr_in * src , struct sockaddr_in * dst )
{
static uint32_t key [ KILLTCP_KEYLEN ] ;
key [ 0 ] = dst - > sin_addr . s_addr ;
key [ 1 ] = src - > sin_addr . s_addr ;
key [ 2 ] = dst - > sin_port ;
key [ 3 ] = src - > sin_port ;
return key ;
}
2007-08-08 09:09:19 +04:00
2007-07-13 05:31:18 +04:00
/*
called when we get a read event on the raw socket
*/
2007-07-11 11:43:51 +04:00
static void capture_tcp_handler ( struct event_context * ev , struct fd_event * fde ,
2007-07-13 05:31:18 +04:00
uint16_t flags , void * private_data )
2007-07-11 11:43:51 +04:00
{
struct ctdb_kill_tcp * killtcp = talloc_get_type ( private_data , struct ctdb_kill_tcp ) ;
2007-08-08 09:09:19 +04:00
struct ctdb_killtcp_con * con ;
2007-07-13 05:31:18 +04:00
struct sockaddr_in src , dst ;
uint32_t ack_seq , seq ;
2007-07-11 06:33:14 +04:00
2007-07-13 05:31:18 +04:00
if ( ! ( flags & EVENT_FD_READ ) ) {
return ;
}
2007-07-13 11:07:10 +04:00
if ( ctdb_sys_read_tcp_packet ( killtcp - > capture_fd ,
killtcp - > private_data ,
& src , & dst ,
& ack_seq , & seq ) ! = 0 ) {
2007-07-13 05:31:18 +04:00
/* probably a non-tcp ACK packet */
return ;
}
2007-08-08 09:09:19 +04:00
/* check if we have this guy in our list of connections
to kill
*/
2007-08-15 04:01:00 +04:00
con = trbt_lookuparray32 ( killtcp - > connections ,
KILLTCP_KEYLEN , killtcp_key ( & src , & dst ) ) ;
2007-08-08 09:09:19 +04:00
if ( con = = NULL ) {
/* no this was some other packet we can just ignore */
return ;
}
2007-07-13 05:31:18 +04:00
2007-08-08 09:09:19 +04:00
/* This one has been tickled !
now reset him and remove him from the list .
*/
DEBUG ( 1 , ( " sending a tcp reset to kill connection :%d -> %s:%d \n " , ntohs ( con - > dst . sin_port ) , inet_ntoa ( con - > src . sin_addr ) , ntohs ( con - > src . sin_port ) ) ) ;
ctdb_sys_send_tcp ( killtcp - > sending_fd , & con - > dst ,
& con - > src , ack_seq , seq , 1 ) ;
2007-08-09 08:08:59 +04:00
talloc_free ( con ) ;
2007-08-08 09:09:19 +04:00
}
/* when traversing the list of all tcp connections to send tickle acks to
( so that we can capture the ack coming back and kill the connection
by a RST )
this callback is called for each connection we are currently trying to kill
*/
static void tickle_connection_traverse ( void * param , void * data )
{
struct ctdb_killtcp_con * con = talloc_get_type ( data , struct ctdb_killtcp_con ) ;
struct ctdb_kill_tcp * killtcp = talloc_get_type ( param , struct ctdb_kill_tcp ) ;
/* have tried too many times, just give up */
if ( con - > count > = 5 ) {
talloc_free ( con ) ;
return ;
2007-07-11 11:43:51 +04:00
}
2007-08-08 09:09:19 +04:00
/* othervise, try tickling it again */
con - > count + + ;
ctdb_sys_send_tcp ( killtcp - > sending_fd , & con - > dst , & con - > src , 0 , 0 , 0 ) ;
2007-07-11 11:43:51 +04:00
}
2007-07-11 06:33:14 +04:00
2007-07-11 11:43:51 +04:00
2007-07-13 05:55:58 +04:00
/*
called every second until all sentenced connections have been reset
2007-07-11 06:33:14 +04:00
*/
2007-07-11 11:43:51 +04:00
static void ctdb_tickle_sentenced_connections ( struct event_context * ev , struct timed_event * te ,
2007-07-13 05:31:18 +04:00
struct timeval t , void * private_data )
2007-07-11 06:33:14 +04:00
{
2007-07-11 11:43:51 +04:00
struct ctdb_kill_tcp * killtcp = talloc_get_type ( private_data , struct ctdb_kill_tcp ) ;
2007-08-08 09:09:19 +04:00
2007-07-11 06:33:14 +04:00
2007-07-13 05:31:18 +04:00
/* loop over all connections sending tickle ACKs */
2007-08-15 04:01:00 +04:00
trbt_traversearray32 ( killtcp - > connections , KILLTCP_KEYLEN , tickle_connection_traverse , killtcp ) ;
2007-08-08 09:09:19 +04:00
2007-06-04 15:11:51 +04:00
2007-07-11 11:43:51 +04:00
/* If there are no more connections to kill we can remove the
entire killtcp structure
*/
2007-08-08 09:09:19 +04:00
if ( ( killtcp - > connections = = NULL ) | |
( killtcp - > connections - > root = = NULL ) ) {
2007-07-11 11:43:51 +04:00
talloc_free ( killtcp ) ;
return ;
2007-07-11 06:33:14 +04:00
}
2007-07-11 11:43:51 +04:00
/* try tickling them again in a seconds time
*/
event_add_timed ( killtcp - > ctdb - > ev , killtcp , timeval_current_ofs ( 1 , 0 ) ,
ctdb_tickle_sentenced_connections , killtcp ) ;
2007-07-11 06:33:14 +04:00
}
2007-07-11 11:43:51 +04:00
/*
destroy the killtcp structure
*/
static int ctdb_killtcp_destructor ( struct ctdb_kill_tcp * killtcp )
2007-07-11 06:33:14 +04:00
{
2007-07-12 03:22:06 +04:00
if ( killtcp - > sending_fd ! = - 1 ) {
close ( killtcp - > sending_fd ) ;
2007-07-13 05:31:18 +04:00
killtcp - > sending_fd = - 1 ;
2007-07-12 03:22:06 +04:00
}
2007-09-04 03:50:07 +04:00
killtcp - > vnn_list - > killtcp = NULL ;
2007-07-11 11:43:51 +04:00
return 0 ;
2007-07-11 06:33:14 +04:00
}
2007-08-08 09:09:19 +04:00
/* nothing fancy here, just unconditionally replace any existing
connection structure with the new one .
dont even free the old one if it did exist , that one is talloc_stolen
by the same node in the tree anyway and will be deleted when the new data
is deleted
*/
static void * add_killtcp_callback ( void * parm , void * data )
{
return parm ;
}
2007-07-13 05:31:18 +04:00
/*
add a tcp socket to the list of connections we will kill on failover
*/
static int ctdb_killtcp_add_connection ( struct ctdb_context * ctdb ,
struct sockaddr_in * src , struct sockaddr_in * dst )
2007-07-11 11:43:51 +04:00
{
2007-09-04 03:50:07 +04:00
struct ctdb_kill_tcp * killtcp ;
2007-08-08 09:09:19 +04:00
struct ctdb_killtcp_con * con ;
2007-09-04 03:50:07 +04:00
char * addr ;
struct ctdb_vnn * vnn ;
struct ctdb_vnn_list * vnn_list ;
addr = inet_ntoa ( dst - > sin_addr ) ;
vnn = find_public_ip_vnn ( ctdb , addr ) ;
if ( vnn = = NULL ) {
DEBUG ( 0 , ( __location__ " Could not killtcp, '%s' is not a public address \n " , addr ) ) ;
2007-09-04 08:19:18 +04:00
return - 1 ;
2007-09-04 03:50:07 +04:00
}
vnn_list = vnn - > vnn_list ;
killtcp = vnn_list - > killtcp ;
2007-07-11 06:33:14 +04:00
2007-07-11 11:43:51 +04:00
/* If this is the first connection to kill we must allocate
a new structure
*/
if ( killtcp = = NULL ) {
2007-07-13 05:55:58 +04:00
killtcp = talloc_zero ( ctdb , struct ctdb_kill_tcp ) ;
2007-07-11 11:43:51 +04:00
CTDB_NO_MEMORY ( ctdb , killtcp ) ;
2007-09-04 03:50:07 +04:00
killtcp - > vnn_list = vnn_list ;
2007-07-11 11:43:51 +04:00
killtcp - > ctdb = ctdb ;
2007-07-12 02:52:24 +04:00
killtcp - > capture_fd = - 1 ;
2007-07-12 03:22:06 +04:00
killtcp - > sending_fd = - 1 ;
2007-08-09 08:08:59 +04:00
killtcp - > connections = trbt_create ( killtcp , 0 ) ;
2007-08-08 09:09:19 +04:00
2007-09-04 03:50:07 +04:00
vnn_list - > killtcp = killtcp ;
2007-07-11 11:43:51 +04:00
talloc_set_destructor ( killtcp , ctdb_killtcp_destructor ) ;
2007-07-11 06:33:14 +04:00
}
2007-08-08 09:09:19 +04:00
/* create a structure that describes this connection we want to
RST and store it in killtcp - > connections
*/
con = talloc ( killtcp , struct ctdb_killtcp_con ) ;
CTDB_NO_MEMORY ( ctdb , con ) ;
con - > src = * src ;
con - > dst = * dst ;
con - > count = 0 ;
con - > killtcp = killtcp ;
2007-08-09 08:08:59 +04:00
2007-08-08 09:09:19 +04:00
2007-08-15 04:01:00 +04:00
trbt_insertarray32_callback ( killtcp - > connections ,
KILLTCP_KEYLEN , killtcp_key ( & con - > dst , & con - > src ) ,
add_killtcp_callback , con ) ;
2007-07-11 06:33:14 +04:00
2007-07-13 05:31:18 +04:00
/*
If we dont have a socket to send from yet we must create it
2007-07-12 03:22:06 +04:00
*/
if ( killtcp - > sending_fd = = - 1 ) {
killtcp - > sending_fd = ctdb_sys_open_sending_socket ( ) ;
if ( killtcp - > sending_fd = = - 1 ) {
DEBUG ( 0 , ( __location__ " Failed to open sending socket for killtcp \n " ) ) ;
goto failed ;
}
}
2007-07-11 06:33:14 +04:00
2007-07-13 05:31:18 +04:00
/*
If we dont have a socket to listen on yet we must create it
*/
if ( killtcp - > capture_fd = = - 1 ) {
2007-09-04 03:50:07 +04:00
killtcp - > capture_fd = ctdb_sys_open_capture_socket ( vnn_list - > iface , & killtcp - > private_data ) ;
2007-07-13 05:31:18 +04:00
if ( killtcp - > capture_fd = = - 1 ) {
DEBUG ( 0 , ( __location__ " Failed to open capturing socket for killtcp \n " ) ) ;
goto failed ;
}
}
2007-07-11 06:33:14 +04:00
2007-07-13 05:31:18 +04:00
if ( killtcp - > fde = = NULL ) {
killtcp - > fde = event_add_fd ( ctdb - > ev , killtcp , killtcp - > capture_fd ,
EVENT_FD_READ | EVENT_FD_AUTOCLOSE ,
capture_tcp_handler , killtcp ) ;
2007-07-11 06:33:14 +04:00
2007-07-13 05:31:18 +04:00
/* We also need to set up some events to tickle all these connections
until they are all reset
*/
2007-08-09 08:08:59 +04:00
event_add_timed ( ctdb - > ev , killtcp , timeval_current_ofs ( 1 , 0 ) ,
2007-07-13 05:31:18 +04:00
ctdb_tickle_sentenced_connections , killtcp ) ;
}
2007-07-11 06:33:14 +04:00
2007-07-13 05:31:18 +04:00
/* tickle him once now */
2007-08-08 09:09:19 +04:00
ctdb_sys_send_tcp ( killtcp - > sending_fd , & con - > dst , & con - > src , 0 , 0 , 0 ) ;
2007-07-11 06:33:14 +04:00
2007-07-11 11:43:51 +04:00
return 0 ;
2007-07-11 06:33:14 +04:00
2007-07-11 11:43:51 +04:00
failed :
2007-09-04 03:50:07 +04:00
talloc_free ( vnn_list - > killtcp ) ;
vnn_list - > killtcp = NULL ;
2007-07-11 11:43:51 +04:00
return - 1 ;
}
2007-07-13 05:31:18 +04:00
/*
called by a daemon to inform us of a TCP connection that one of its
clients managing that should reset when IP takeover is done
*/
int32_t ctdb_control_kill_tcp ( struct ctdb_context * ctdb , TDB_DATA indata )
{
struct ctdb_control_killtcp * killtcp = ( struct ctdb_control_killtcp * ) indata . dptr ;
2007-09-04 08:19:18 +04:00
return ctdb_killtcp_add_connection ( ctdb , & killtcp - > src , & killtcp - > dst ) ;
2007-06-04 15:11:51 +04:00
}
2007-07-20 04:06:41 +04:00
/*
called by a daemon to inform us of the entire list of TCP tickles for
a particular public address .
this control should only be sent by the node that is currently serving
that public address .
*/
2007-07-20 09:05:55 +04:00
int32_t ctdb_control_set_tcp_tickle_list ( struct ctdb_context * ctdb , TDB_DATA indata )
2007-07-20 04:06:41 +04:00
{
struct ctdb_control_tcp_tickle_list * list = ( struct ctdb_control_tcp_tickle_list * ) indata . dptr ;
struct ctdb_tcp_array * tcparray ;
2007-09-04 03:50:07 +04:00
char * addr ;
struct ctdb_vnn * vnn ;
2007-07-20 04:06:41 +04:00
/* We must at least have tickles.num or else we cant verify the size
of the received data blob
*/
if ( indata . dsize < offsetof ( struct ctdb_control_tcp_tickle_list ,
tickles . connections ) ) {
2007-07-20 09:05:55 +04:00
DEBUG ( 0 , ( " Bad indata in ctdb_control_set_tcp_tickle_list. Not enough data for the tickle.num field \n " ) ) ;
2007-07-20 04:06:41 +04:00
return - 1 ;
}
/* verify that the size of data matches what we expect */
if ( indata . dsize < offsetof ( struct ctdb_control_tcp_tickle_list ,
tickles . connections )
+ sizeof ( struct ctdb_tcp_connection )
* list - > tickles . num ) {
2007-07-20 09:05:55 +04:00
DEBUG ( 0 , ( " Bad indata in ctdb_control_set_tcp_tickle_list \n " ) ) ;
2007-07-20 04:06:41 +04:00
return - 1 ;
}
2007-09-04 03:50:07 +04:00
addr = inet_ntoa ( list - > ip . sin_addr ) ;
2007-07-20 04:06:41 +04:00
2007-09-04 03:50:07 +04:00
vnn = find_public_ip_vnn ( ctdb , addr ) ;
if ( vnn = = NULL ) {
DEBUG ( 0 , ( __location__ " Could not set tcp tickle list, '%s' is not a public address \n " , addr ) ) ;
return 1 ;
}
2007-07-20 04:06:41 +04:00
/* remove any old ticklelist we might have */
2007-09-04 03:50:07 +04:00
talloc_free ( vnn - > tcp_array ) ;
vnn - > tcp_array = NULL ;
2007-07-20 04:06:41 +04:00
2007-07-20 09:05:55 +04:00
tcparray = talloc ( ctdb - > nodes , struct ctdb_tcp_array ) ;
2007-07-20 04:06:41 +04:00
CTDB_NO_MEMORY ( ctdb , tcparray ) ;
2007-07-20 09:05:55 +04:00
tcparray - > num = list - > tickles . num ;
tcparray - > connections = talloc_array ( tcparray , struct ctdb_tcp_connection , tcparray - > num ) ;
CTDB_NO_MEMORY ( ctdb , tcparray - > connections ) ;
memcpy ( tcparray - > connections , & list - > tickles . connections [ 0 ] ,
sizeof ( struct ctdb_tcp_connection ) * tcparray - > num ) ;
2007-07-20 04:06:41 +04:00
/* We now have a new fresh tickle list array for this vnn */
2007-09-04 03:50:07 +04:00
vnn - > tcp_array = talloc_steal ( vnn , tcparray ) ;
2007-07-20 04:06:41 +04:00
return 0 ;
}
2007-07-20 09:05:55 +04:00
/*
called to return the full list of tickles for the puclic address associated
with the provided vnn
*/
int32_t ctdb_control_get_tcp_tickle_list ( struct ctdb_context * ctdb , TDB_DATA indata , TDB_DATA * outdata )
{
2007-09-04 03:50:07 +04:00
struct sockaddr_in * ip = ( struct sockaddr_in * ) indata . dptr ;
2007-07-20 09:05:55 +04:00
struct ctdb_control_tcp_tickle_list * list ;
struct ctdb_tcp_array * tcparray ;
int num ;
2007-09-04 03:50:07 +04:00
char * addr ;
struct ctdb_vnn * vnn ;
2007-07-20 09:05:55 +04:00
2007-09-04 03:50:07 +04:00
addr = inet_ntoa ( ip - > sin_addr ) ;
vnn = find_public_ip_vnn ( ctdb , addr ) ;
if ( vnn = = NULL ) {
DEBUG ( 0 , ( __location__ " Could not get tcp tickle list, '%s' is not a public address \n " , addr ) ) ;
return 1 ;
2007-07-20 09:05:55 +04:00
}
2007-09-04 03:50:07 +04:00
tcparray = vnn - > tcp_array ;
2007-07-20 09:05:55 +04:00
if ( tcparray ) {
num = tcparray - > num ;
} else {
num = 0 ;
}
outdata - > dsize = offsetof ( struct ctdb_control_tcp_tickle_list ,
tickles . connections )
+ sizeof ( struct ctdb_tcp_connection ) * num ;
outdata - > dptr = talloc_size ( outdata , outdata - > dsize ) ;
CTDB_NO_MEMORY ( ctdb , outdata - > dptr ) ;
list = ( struct ctdb_control_tcp_tickle_list * ) outdata - > dptr ;
2007-09-04 03:50:07 +04:00
list - > ip = * ip ;
2007-07-20 09:05:55 +04:00
list - > tickles . num = num ;
if ( num ) {
memcpy ( & list - > tickles . connections [ 0 ] , tcparray - > connections ,
sizeof ( struct ctdb_tcp_connection ) * num ) ;
}
return 0 ;
}
/*
set the list of all tcp tickles for a public address
*/
static int ctdb_ctrl_set_tcp_tickles ( struct ctdb_context * ctdb ,
struct timeval timeout , uint32_t destnode ,
2007-09-04 03:50:07 +04:00
struct sockaddr_in * ip ,
2007-07-20 09:05:55 +04:00
struct ctdb_tcp_array * tcparray )
{
int ret , num ;
TDB_DATA data ;
struct ctdb_control_tcp_tickle_list * list ;
if ( tcparray ) {
num = tcparray - > num ;
} else {
num = 0 ;
}
data . dsize = offsetof ( struct ctdb_control_tcp_tickle_list ,
tickles . connections ) +
sizeof ( struct ctdb_tcp_connection ) * num ;
data . dptr = talloc_size ( ctdb , data . dsize ) ;
CTDB_NO_MEMORY ( ctdb , data . dptr ) ;
list = ( struct ctdb_control_tcp_tickle_list * ) data . dptr ;
2007-09-04 03:50:07 +04:00
list - > ip = * ip ;
2007-07-20 09:05:55 +04:00
list - > tickles . num = num ;
if ( tcparray ) {
memcpy ( & list - > tickles . connections [ 0 ] , tcparray - > connections , sizeof ( struct ctdb_tcp_connection ) * num ) ;
}
ret = ctdb_daemon_send_control ( ctdb , CTDB_BROADCAST_CONNECTED , 0 ,
CTDB_CONTROL_SET_TCP_TICKLE_LIST ,
0 , CTDB_CTRL_FLAG_NOREPLY , data , NULL , NULL ) ;
if ( ret ! = 0 ) {
DEBUG ( 0 , ( __location__ " ctdb_control for set tcp tickles failed \n " ) ) ;
return - 1 ;
}
talloc_free ( data . dptr ) ;
return ret ;
}
/*
perform tickle updates if required
*/
static void ctdb_update_tcp_tickles ( struct event_context * ev ,
struct timed_event * te ,
struct timeval t , void * private_data )
{
struct ctdb_context * ctdb = talloc_get_type ( private_data , struct ctdb_context ) ;
2007-09-04 03:50:07 +04:00
int ret ;
struct ctdb_vnn_list * vnn_list ;
struct ctdb_vnn * vnn ;
2007-07-20 09:05:55 +04:00
2007-09-04 03:50:07 +04:00
for ( vnn_list = ctdb - > vnn_list ; vnn_list ; vnn_list = vnn_list - > next ) {
struct sockaddr_in ip ;
2007-07-20 09:05:55 +04:00
2007-09-04 03:50:07 +04:00
for ( vnn = vnn_list - > vnn ; vnn ; vnn = vnn - > next ) {
/* we only send out updates for public addresses that
we have taken over
*/
2007-09-04 04:06:36 +04:00
if ( ctdb - > pnn ! = vnn - > pnn ) {
2007-09-04 03:50:07 +04:00
continue ;
}
/* We only send out the updates if we need to */
if ( ! vnn - > tcp_update_needed ) {
continue ;
}
inet_aton ( vnn - > public_address , & ip . sin_addr ) ;
ret = ctdb_ctrl_set_tcp_tickles ( ctdb ,
TAKEOVER_TIMEOUT ( ) ,
CTDB_BROADCAST_CONNECTED ,
& ip ,
vnn - > tcp_array ) ;
2007-07-20 09:05:55 +04:00
2007-09-04 03:50:07 +04:00
if ( ret ! = 0 ) {
DEBUG ( 0 , ( " Failed to send the tickle update for public address %s \n " , vnn - > public_address ) ) ;
}
2007-07-20 09:05:55 +04:00
}
}
event_add_timed ( ctdb - > ev , ctdb - > tickle_update_context ,
timeval_current_ofs ( ctdb - > tunable . tickle_update_interval , 0 ) ,
ctdb_update_tcp_tickles , ctdb ) ;
}
/*
start periodic update of tcp tickles
*/
void ctdb_start_tcp_tickle_update ( struct ctdb_context * ctdb )
{
ctdb - > tickle_update_context = talloc_new ( ctdb ) ;
event_add_timed ( ctdb - > ev , ctdb - > tickle_update_context ,
timeval_current_ofs ( ctdb - > tunable . tickle_update_interval , 0 ) ,
ctdb_update_tcp_tickles , ctdb ) ;
}