2006-11-28 03:51:33 +03:00
/*
ctdb over TCP
Copyright ( C ) Andrew Tridgell 2006
This library is free software ; you can redistribute it and / or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation ; either
version 2 of the License , or ( at your option ) any later version .
This library is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public
License along with this library ; if not , write to the Free Software
Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*/
# include "includes.h"
2007-01-23 03:38:45 +03:00
# include "lib/tdb/include/tdb.h"
2006-11-28 03:51:33 +03:00
# include "lib/events/events.h"
# include "system/network.h"
# include "system/filesys.h"
2007-01-23 03:38:45 +03:00
# include "../include/ctdb_private.h"
2006-11-28 03:51:33 +03:00
# include "ctdb_tcp.h"
/*
start the protocol going
*/
2007-04-10 13:40:29 +04:00
static int ctdb_tcp_start ( struct ctdb_context * ctdb )
2006-11-28 03:51:33 +03:00
{
2006-11-28 09:56:10 +03:00
int i ;
2006-11-28 03:51:33 +03:00
/* listen on our own address */
if ( ctdb_tcp_listen ( ctdb ) ! = 0 ) return - 1 ;
/* startup connections to the other servers - will happen on
next event loop */
2006-11-28 09:56:10 +03:00
for ( i = 0 ; i < ctdb - > num_nodes ; i + + ) {
struct ctdb_node * node = * ( ctdb - > nodes + i ) ;
2006-12-01 07:45:24 +03:00
if ( ! ( ctdb - > flags & CTDB_FLAG_SELF_CONNECT ) & &
ctdb_same_address ( & ctdb - > address , & node - > address ) ) continue ;
2006-11-28 03:51:33 +03:00
event_add_timed ( ctdb - > ev , node , timeval_zero ( ) ,
ctdb_tcp_node_connect , node ) ;
}
return 0 ;
}
/*
initialise tcp portion of a ctdb node
*/
2007-04-10 13:40:29 +04:00
static int ctdb_tcp_add_node ( struct ctdb_node * node )
2006-11-28 03:51:33 +03:00
{
struct ctdb_tcp_node * tnode ;
tnode = talloc_zero ( node , struct ctdb_tcp_node ) ;
CTDB_NO_MEMORY ( node - > ctdb , tnode ) ;
tnode - > fd = - 1 ;
2007-04-11 22:12:15 +04:00
node - > private_data = tnode ;
2007-04-10 14:48:31 +04:00
tnode - > queue = ctdb_queue_setup ( node - > ctdb , node , tnode - > fd , CTDB_TCP_ALIGNMENT ,
ctdb_tcp_tnode_cb , node ) ;
2006-11-28 03:51:33 +03:00
return 0 ;
}
2006-12-19 04:03:10 +03:00
/*
transport packet allocator - allows transport to control memory for packets
*/
2007-04-19 04:37:44 +04:00
static void * ctdb_tcp_allocate_pkt ( TALLOC_CTX * mem_ctx , size_t size )
2006-12-19 04:03:10 +03:00
{
/* tcp transport needs to round to 8 byte alignment to ensure
that we can use a length header and 64 bit elements in
structures */
2006-12-19 04:07:07 +03:00
size = ( size + ( CTDB_TCP_ALIGNMENT - 1 ) ) & ~ ( CTDB_TCP_ALIGNMENT - 1 ) ;
2007-04-19 04:37:44 +04:00
return talloc_size ( mem_ctx , size ) ;
2006-12-19 04:03:10 +03:00
}
2006-11-28 03:51:33 +03:00
static const struct ctdb_methods ctdb_tcp_methods = {
2006-11-28 06:15:46 +03:00
. start = ctdb_tcp_start ,
. add_node = ctdb_tcp_add_node ,
2006-12-19 04:03:10 +03:00
. queue_pkt = ctdb_tcp_queue_pkt ,
. allocate_pkt = ctdb_tcp_allocate_pkt
2006-11-28 03:51:33 +03:00
} ;
/*
initialise tcp portion of ctdb
*/
int ctdb_tcp_init ( struct ctdb_context * ctdb )
{
struct ctdb_tcp * ctcp ;
ctcp = talloc_zero ( ctdb , struct ctdb_tcp ) ;
CTDB_NO_MEMORY ( ctdb , ctcp ) ;
ctcp - > listen_fd = - 1 ;
2007-04-11 22:12:15 +04:00
ctdb - > private_data = ctcp ;
2006-11-28 03:51:33 +03:00
ctdb - > methods = & ctdb_tcp_methods ;
return 0 ;
}