2007-04-26 16:27:49 +04:00
/*
ctdb control tool
Copyright ( C ) Andrew Tridgell 2007
2007-10-08 03:47:20 +04:00
Copyright ( C ) Ronnie Sahlberg 2007
2007-04-26 16:27:49 +04:00
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-04-26 16:27:49 +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-04-26 16:27:49 +04:00
*/
# include "includes.h"
# include "lib/events/events.h"
2008-01-17 03:33:23 +03:00
# include "system/time.h"
2007-04-26 16:27:49 +04:00
# include "system/filesys.h"
2007-06-07 16:26:27 +04:00
# include "system/network.h"
2008-02-05 02:36:06 +03:00
# include "system/locale.h"
2007-04-26 16:27:49 +04:00
# include "popt.h"
# include "cmdline.h"
2007-05-02 06:43:35 +04:00
# include "../include/ctdb.h"
2007-04-26 16:27:49 +04:00
# include "../include/ctdb_private.h"
2008-04-22 18:55:57 +04:00
# include "../common/rb_tree.h"
2007-04-26 16:27:49 +04:00
2007-05-29 06:16:59 +04:00
static void usage ( void ) ;
2007-04-26 16:27:49 +04:00
2007-05-29 06:16:59 +04:00
static struct {
int timelimit ;
2007-09-04 04:14:41 +04:00
uint32_t pnn ;
2007-06-03 13:50:51 +04:00
int machinereadable ;
2008-01-10 00:04:54 +03:00
int maxruntime ;
2007-05-29 06:16:59 +04:00
} options ;
# define TIMELIMIT() timeval_current_ofs(options.timelimit, 0)
2007-04-26 16:27:49 +04:00
2008-04-03 10:07:00 +04:00
# ifdef CTDB_VERS
static int control_version ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
# define STR(x) #x
# define XSTR(x) STR(x)
printf ( " CTDB version: %s \n " , XSTR ( CTDB_VERS ) ) ;
return 0 ;
}
# endif
2007-04-27 17:14:36 +04:00
/*
see if a process exists
*/
2007-04-26 16:27:49 +04:00
static int control_process_exists ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
2007-09-04 04:14:41 +04:00
uint32_t pnn , pid ;
2007-04-26 16:27:49 +04:00
int ret ;
2007-04-26 16:51:41 +04:00
if ( argc < 1 ) {
2007-04-26 16:27:49 +04:00
usage ( ) ;
}
2007-09-04 04:14:41 +04:00
if ( sscanf ( argv [ 0 ] , " %u:%u " , & pnn , & pid ) ! = 2 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Badly formed pnn:pid \n " ) ) ;
2007-04-26 16:51:41 +04:00
return - 1 ;
}
2007-04-26 16:27:49 +04:00
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_process_exists ( ctdb , pnn , pid ) ;
2007-04-26 16:27:49 +04:00
if ( ret = = 0 ) {
2007-09-04 04:14:41 +04:00
printf ( " %u:%u exists \n " , pnn , pid ) ;
2007-04-26 16:27:49 +04:00
} else {
2007-09-04 04:14:41 +04:00
printf ( " %u:%u does not exist \n " , pnn , pid ) ;
2007-04-26 16:27:49 +04:00
}
return ret ;
}
2007-04-26 16:51:41 +04:00
/*
2007-05-29 06:16:59 +04:00
display statistics structure
2007-04-26 16:51:41 +04:00
*/
2007-05-29 06:16:59 +04:00
static void show_statistics ( struct ctdb_statistics * s )
2007-04-26 16:51:41 +04:00
{
2007-05-05 02:11:54 +04:00
TALLOC_CTX * tmp_ctx = talloc_new ( NULL ) ;
int i ;
const char * prefix = NULL ;
2007-05-12 15:25:26 +04:00
int preflen = 0 ;
2007-05-05 02:11:54 +04:00
const struct {
const char * name ;
uint32_t offset ;
} fields [ ] = {
2007-05-29 06:16:59 +04:00
# define STATISTICS_FIELD(n) { #n, offsetof(struct ctdb_statistics, n) }
STATISTICS_FIELD ( num_clients ) ,
STATISTICS_FIELD ( frozen ) ,
STATISTICS_FIELD ( recovering ) ,
STATISTICS_FIELD ( client_packets_sent ) ,
STATISTICS_FIELD ( client_packets_recv ) ,
STATISTICS_FIELD ( node_packets_sent ) ,
STATISTICS_FIELD ( node_packets_recv ) ,
STATISTICS_FIELD ( keepalive_packets_sent ) ,
STATISTICS_FIELD ( keepalive_packets_recv ) ,
STATISTICS_FIELD ( node . req_call ) ,
STATISTICS_FIELD ( node . reply_call ) ,
STATISTICS_FIELD ( node . req_dmaster ) ,
STATISTICS_FIELD ( node . reply_dmaster ) ,
STATISTICS_FIELD ( node . reply_error ) ,
STATISTICS_FIELD ( node . req_message ) ,
STATISTICS_FIELD ( node . req_control ) ,
STATISTICS_FIELD ( node . reply_control ) ,
STATISTICS_FIELD ( client . req_call ) ,
STATISTICS_FIELD ( client . req_message ) ,
STATISTICS_FIELD ( client . req_control ) ,
STATISTICS_FIELD ( timeouts . call ) ,
STATISTICS_FIELD ( timeouts . control ) ,
STATISTICS_FIELD ( timeouts . traverse ) ,
STATISTICS_FIELD ( total_calls ) ,
STATISTICS_FIELD ( pending_calls ) ,
STATISTICS_FIELD ( lockwait_calls ) ,
STATISTICS_FIELD ( pending_lockwait_calls ) ,
STATISTICS_FIELD ( memory_used ) ,
STATISTICS_FIELD ( max_hop_count ) ,
2007-05-05 02:11:54 +04:00
} ;
2007-04-26 16:51:41 +04:00
printf ( " CTDB version %u \n " , CTDB_VERSION ) ;
2007-05-05 02:11:54 +04:00
for ( i = 0 ; i < ARRAY_SIZE ( fields ) ; i + + ) {
if ( strchr ( fields [ i ] . name , ' . ' ) ) {
preflen = strcspn ( fields [ i ] . name , " . " ) + 1 ;
if ( ! prefix | | strncmp ( prefix , fields [ i ] . name , preflen ) ! = 0 ) {
prefix = fields [ i ] . name ;
printf ( " %*.*s \n " , preflen - 1 , preflen - 1 , fields [ i ] . name ) ;
}
} else {
preflen = 0 ;
}
printf ( " %*s%-22s%*s%10u \n " ,
preflen ? 4 : 0 , " " ,
fields [ i ] . name + preflen ,
preflen ? 0 : 4 , " " ,
* ( uint32_t * ) ( fields [ i ] . offset + ( uint8_t * ) s ) ) ;
}
printf ( " %-30s %.6f sec \n " , " max_call_latency " , s - > max_call_latency ) ;
printf ( " %-30s %.6f sec \n " , " max_lockwait_latency " , s - > max_lockwait_latency ) ;
talloc_free ( tmp_ctx ) ;
2007-04-26 16:51:41 +04:00
}
2007-04-28 19:13:30 +04:00
/*
2007-05-29 06:16:59 +04:00
display remote ctdb statistics combined from all nodes
2007-04-28 19:13:30 +04:00
*/
2007-05-29 06:16:59 +04:00
static int control_statistics_all ( struct ctdb_context * ctdb )
2007-04-28 19:13:30 +04:00
{
int ret , i ;
2007-05-29 06:16:59 +04:00
struct ctdb_statistics statistics ;
2007-04-28 19:42:40 +04:00
uint32_t * nodes ;
uint32_t num_nodes ;
2007-05-29 06:16:59 +04:00
nodes = ctdb_get_connected_nodes ( ctdb , TIMELIMIT ( ) , ctdb , & num_nodes ) ;
2007-04-28 19:42:40 +04:00
CTDB_NO_MEMORY ( ctdb , nodes ) ;
2007-05-29 06:16:59 +04:00
ZERO_STRUCT ( statistics ) ;
2007-04-28 19:13:30 +04:00
2007-04-28 19:42:40 +04:00
for ( i = 0 ; i < num_nodes ; i + + ) {
2007-05-29 06:16:59 +04:00
struct ctdb_statistics s1 ;
2007-04-28 19:13:30 +04:00
int j ;
uint32_t * v1 = ( uint32_t * ) & s1 ;
2007-05-29 06:16:59 +04:00
uint32_t * v2 = ( uint32_t * ) & statistics ;
2007-04-28 19:13:30 +04:00
uint32_t num_ints =
2007-05-29 06:16:59 +04:00
offsetof ( struct ctdb_statistics , __last_counter ) / sizeof ( uint32_t ) ;
ret = ctdb_ctrl_statistics ( ctdb , nodes [ i ] , & s1 ) ;
2007-04-28 19:13:30 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to get statistics from node %u \n " , nodes [ i ] ) ) ;
2007-04-28 19:13:30 +04:00
return ret ;
}
for ( j = 0 ; j < num_ints ; j + + ) {
v2 [ j ] + = v1 [ j ] ;
}
2007-05-29 06:16:59 +04:00
statistics . max_hop_count =
MAX ( statistics . max_hop_count , s1 . max_hop_count ) ;
statistics . max_call_latency =
MAX ( statistics . max_call_latency , s1 . max_call_latency ) ;
statistics . max_lockwait_latency =
MAX ( statistics . max_lockwait_latency , s1 . max_lockwait_latency ) ;
2007-04-28 19:13:30 +04:00
}
2007-04-28 19:42:40 +04:00
talloc_free ( nodes ) ;
2007-05-29 06:16:59 +04:00
printf ( " Gathered statistics for %u nodes \n " , num_nodes ) ;
show_statistics ( & statistics ) ;
2007-04-28 19:13:30 +04:00
return 0 ;
}
2007-04-27 17:14:36 +04:00
/*
2007-05-29 06:16:59 +04:00
display remote ctdb statistics
2007-04-27 17:14:36 +04:00
*/
2007-05-29 06:16:59 +04:00
static int control_statistics ( struct ctdb_context * ctdb , int argc , const char * * argv )
2007-04-26 16:51:41 +04:00
{
int ret ;
2007-05-29 06:16:59 +04:00
struct ctdb_statistics statistics ;
2007-04-26 16:51:41 +04:00
2007-09-04 04:14:41 +04:00
if ( options . pnn = = CTDB_BROADCAST_ALL ) {
2007-05-29 06:16:59 +04:00
return control_statistics_all ( ctdb ) ;
2007-04-28 19:13:30 +04:00
}
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_statistics ( ctdb , options . pnn , & statistics ) ;
2007-04-26 16:51:41 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to get statistics from node %u \n " , options . pnn ) ) ;
2007-04-26 16:51:41 +04:00
return ret ;
}
2007-05-29 06:16:59 +04:00
show_statistics ( & statistics ) ;
2007-04-26 16:51:41 +04:00
return 0 ;
}
2007-04-28 21:13:36 +04:00
/*
2007-05-29 06:16:59 +04:00
reset remote ctdb statistics
2007-04-28 21:13:36 +04:00
*/
2007-05-29 06:16:59 +04:00
static int control_statistics_reset ( struct ctdb_context * ctdb , int argc , const char * * argv )
2007-04-28 21:13:36 +04:00
{
int ret ;
2007-09-04 04:14:41 +04:00
ret = ctdb_statistics_reset ( ctdb , options . pnn ) ;
2007-04-28 21:13:36 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to reset statistics on node %u \n " , options . pnn ) ) ;
2007-04-28 21:13:36 +04:00
return ret ;
}
return 0 ;
}
2007-05-02 04:20:34 +04:00
2008-01-17 03:33:23 +03:00
/*
display uptime of remote node
*/
static int control_uptime ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
int ret ;
int mypnn ;
struct ctdb_uptime * uptime = NULL ;
int tmp , days , hours , minutes , seconds ;
mypnn = ctdb_ctrl_getpnn ( ctdb , TIMELIMIT ( ) , options . pnn ) ;
if ( mypnn = = - 1 ) {
return - 1 ;
}
ret = ctdb_ctrl_uptime ( ctdb , ctdb , TIMELIMIT ( ) , options . pnn , & uptime ) ;
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to get uptime from node %u \n " , options . pnn ) ) ;
2008-01-17 03:33:23 +03:00
return ret ;
}
2008-03-04 05:29:48 +03:00
if ( options . machinereadable ) {
printf ( " :Current Node Time:Ctdb Start Time:Last Recovery Time: \n " ) ;
printf ( " :%u:%u:%u: \n " ,
( unsigned int ) uptime - > current_time . tv_sec ,
( unsigned int ) uptime - > ctdbd_start_time . tv_sec ,
( unsigned int ) uptime - > last_recovery_time . tv_sec ) ;
return 0 ;
}
2008-01-17 03:33:23 +03:00
printf ( " Current time of node : %s " , ctime ( & uptime - > current_time . tv_sec ) ) ;
tmp = uptime - > current_time . tv_sec - uptime - > ctdbd_start_time . tv_sec ;
seconds = tmp % 60 ;
tmp / = 60 ;
minutes = tmp % 60 ;
tmp / = 60 ;
hours = tmp % 24 ;
tmp / = 24 ;
days = tmp ;
printf ( " Ctdbd start time : (%03d %02d:%02d:%02d) %s " , days , hours , minutes , seconds , ctime ( & uptime - > ctdbd_start_time . tv_sec ) ) ;
tmp = uptime - > current_time . tv_sec - uptime - > last_recovery_time . tv_sec ;
seconds = tmp % 60 ;
tmp / = 60 ;
minutes = tmp % 60 ;
tmp / = 60 ;
hours = tmp % 24 ;
tmp / = 24 ;
days = tmp ;
printf ( " Time of last recovery : (%03d %02d:%02d:%02d) %s " , days , hours , minutes , seconds , ctime ( & uptime - > last_recovery_time . tv_sec ) ) ;
return 0 ;
}
2007-04-27 17:14:36 +04:00
/*
2007-05-29 06:16:59 +04:00
display remote ctdb status
2007-04-27 17:14:36 +04:00
*/
2007-05-29 06:16:59 +04:00
static int control_status ( struct ctdb_context * ctdb , int argc , const char * * argv )
2007-04-27 14:56:10 +04:00
{
int i , ret ;
2007-05-03 05:06:24 +04:00
struct ctdb_vnn_map * vnnmap = NULL ;
2007-05-29 06:16:59 +04:00
struct ctdb_node_map * nodemap = NULL ;
uint32_t recmode , recmaster ;
2007-09-04 04:14:41 +04:00
int mypnn ;
2007-05-29 06:16:59 +04:00
2007-09-04 04:38:48 +04:00
mypnn = ctdb_ctrl_getpnn ( ctdb , TIMELIMIT ( ) , options . pnn ) ;
2007-09-04 04:14:41 +04:00
if ( mypnn = = - 1 ) {
2007-08-07 07:40:13 +04:00
return - 1 ;
}
2007-05-29 06:16:59 +04:00
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_getnodemap ( ctdb , TIMELIMIT ( ) , options . pnn , ctdb , & nodemap ) ;
2007-05-29 06:16:59 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to get nodemap from node %u \n " , options . pnn ) ) ;
2007-05-29 06:16:59 +04:00
return ret ;
2007-04-27 14:56:10 +04:00
}
2007-06-03 13:50:51 +04:00
if ( options . machinereadable ) {
2008-01-29 03:39:06 +03:00
printf ( " :Node:IP:Disconnected:Banned:Disabled:Unhealthy: \n " ) ;
2007-06-03 13:50:51 +04:00
for ( i = 0 ; i < nodemap - > num ; i + + ) {
2008-01-29 03:39:06 +03:00
printf ( " :%d:%s:%d:%d:%d:%d: \n " , nodemap - > nodes [ i ] . pnn ,
2007-06-04 07:26:07 +04:00
inet_ntoa ( nodemap - > nodes [ i ] . sin . sin_addr ) ,
2007-06-07 09:18:55 +04:00
! ! ( nodemap - > nodes [ i ] . flags & NODE_FLAGS_DISCONNECTED ) ,
2008-01-29 03:39:06 +03:00
! ! ( nodemap - > nodes [ i ] . flags & NODE_FLAGS_BANNED ) ,
! ! ( nodemap - > nodes [ i ] . flags & NODE_FLAGS_PERMANENTLY_DISABLED ) ,
! ! ( nodemap - > nodes [ i ] . flags & NODE_FLAGS_UNHEALTHY ) ) ;
2007-06-03 13:50:51 +04:00
}
return 0 ;
}
2007-05-29 06:16:59 +04:00
printf ( " Number of nodes:%d \n " , nodemap - > num ) ;
for ( i = 0 ; i < nodemap - > num ; i + + ) {
2007-06-07 10:34:33 +04:00
static const struct {
uint32_t flag ;
const char * name ;
} flag_names [ ] = {
{ NODE_FLAGS_DISCONNECTED , " DISCONNECTED " } ,
{ NODE_FLAGS_PERMANENTLY_DISABLED , " DISABLED " } ,
{ NODE_FLAGS_BANNED , " BANNED " } ,
{ NODE_FLAGS_UNHEALTHY , " UNHEALTHY " } ,
} ;
char * flags_str = NULL ;
int j ;
for ( j = 0 ; j < ARRAY_SIZE ( flag_names ) ; j + + ) {
if ( nodemap - > nodes [ i ] . flags & flag_names [ j ] . flag ) {
if ( flags_str = = NULL ) {
flags_str = talloc_strdup ( ctdb , flag_names [ j ] . name ) ;
} else {
flags_str = talloc_asprintf_append ( flags_str , " |%s " ,
flag_names [ j ] . name ) ;
}
CTDB_NO_MEMORY_FATAL ( ctdb , flags_str ) ;
}
}
if ( flags_str = = NULL ) {
flags_str = talloc_strdup ( ctdb , " OK " ) ;
CTDB_NO_MEMORY_FATAL ( ctdb , flags_str ) ;
2007-06-06 04:25:46 +04:00
}
2007-09-04 03:50:07 +04:00
printf ( " pnn:%d %-16s %s%s \n " , nodemap - > nodes [ i ] . pnn ,
2007-06-06 04:25:46 +04:00
inet_ntoa ( nodemap - > nodes [ i ] . sin . sin_addr ) ,
flags_str ,
2007-09-04 04:14:41 +04:00
nodemap - > nodes [ i ] . pnn = = mypnn ? " (THIS NODE) " : " " ) ;
2007-06-07 10:34:33 +04:00
talloc_free ( flags_str ) ;
2007-05-29 06:16:59 +04:00
}
2007-04-27 14:56:10 +04:00
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_getvnnmap ( ctdb , TIMELIMIT ( ) , options . pnn , ctdb , & vnnmap ) ;
2007-04-27 14:56:10 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to get vnnmap from node %u \n " , options . pnn ) ) ;
2007-04-27 14:56:10 +04:00
return ret ;
}
2007-08-22 06:38:31 +04:00
if ( vnnmap - > generation = = INVALID_GENERATION ) {
printf ( " Generation:INVALID \n " ) ;
} else {
printf ( " Generation:%d \n " , vnnmap - > generation ) ;
}
2007-04-27 14:56:10 +04:00
printf ( " Size:%d \n " , vnnmap - > size ) ;
for ( i = 0 ; i < vnnmap - > size ; i + + ) {
2007-05-29 06:16:59 +04:00
printf ( " hash:%d lmaster:%d \n " , i , vnnmap - > map [ i ] ) ;
2007-05-05 22:31:22 +04:00
}
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_getrecmode ( ctdb , ctdb , TIMELIMIT ( ) , options . pnn , & recmode ) ;
2007-05-05 22:31:22 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to get recmode from node %u \n " , options . pnn ) ) ;
2007-05-05 22:31:22 +04:00
return ret ;
}
2007-05-29 06:16:59 +04:00
printf ( " Recovery mode:%s (%d) \n " , recmode = = CTDB_RECOVERY_NORMAL ? " NORMAL " : " RECOVERY " , recmode ) ;
2007-05-17 04:45:31 +04:00
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_getrecmaster ( ctdb , ctdb , TIMELIMIT ( ) , options . pnn , & recmaster ) ;
2007-05-17 04:45:31 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to get recmaster from node %u \n " , options . pnn ) ) ;
2007-05-17 04:45:31 +04:00
return ret ;
}
2007-05-29 06:16:59 +04:00
printf ( " Recovery master:%d \n " , recmaster ) ;
2007-05-17 04:45:31 +04:00
return 0 ;
}
2007-07-20 09:05:55 +04:00
/*
2007-09-04 04:14:41 +04:00
get a list of all tickles for this pnn
2007-07-20 09:05:55 +04:00
*/
static int control_get_tickles ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
struct ctdb_control_tcp_tickle_list * list ;
2007-09-04 03:50:07 +04:00
struct sockaddr_in ip ;
2007-07-20 09:05:55 +04:00
int i , ret ;
if ( argc < 1 ) {
usage ( ) ;
}
2007-09-04 03:50:07 +04:00
ip . sin_family = AF_INET ;
if ( inet_aton ( argv [ 0 ] , & ip . sin_addr ) = = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Wrongly formed ip address '%s' \n " , argv [ 0 ] ) ) ;
2007-09-04 03:50:07 +04:00
return - 1 ;
}
2007-07-20 09:05:55 +04:00
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_get_tcp_tickles ( ctdb , TIMELIMIT ( ) , options . pnn , ctdb , & ip , & list ) ;
2007-07-20 09:05:55 +04:00
if ( ret = = - 1 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to list tickles \n " ) ) ;
2007-07-20 09:05:55 +04:00
return - 1 ;
}
2007-09-04 03:50:07 +04:00
printf ( " Tickles for ip:%s \n " , inet_ntoa ( list - > ip . sin_addr ) ) ;
2007-07-20 09:05:55 +04:00
printf ( " Num tickles:%u \n " , list - > tickles . num ) ;
for ( i = 0 ; i < list - > tickles . num ; i + + ) {
printf ( " SRC: %s:%u " , inet_ntoa ( list - > tickles . connections [ i ] . saddr . sin_addr ) , ntohs ( list - > tickles . connections [ i ] . saddr . sin_port ) ) ;
printf ( " DST: %s:%u \n " , inet_ntoa ( list - > tickles . connections [ i ] . daddr . sin_addr ) , ntohs ( list - > tickles . connections [ i ] . daddr . sin_port ) ) ;
}
talloc_free ( list ) ;
return 0 ;
}
2008-03-04 04:20:23 +03:00
/*
move / failover an ip address to a specific node
*/
static int control_moveip ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
uint32_t pnn ;
struct sockaddr_in ip ;
uint32_t value ;
struct ctdb_all_public_ips * ips ;
struct ctdb_public_ip pip ;
TDB_DATA data ;
struct ctdb_node_map * nodemap = NULL ;
int i , ret ;
if ( argc < 2 ) {
usage ( ) ;
}
ip . sin_family = AF_INET ;
if ( inet_aton ( argv [ 0 ] , & ip . sin_addr ) = = 0 ) {
DEBUG ( DEBUG_ERR , ( " Wrongly formed ip address '%s' \n " , argv [ 0 ] ) ) ;
return - 1 ;
}
ret = ctdb_ctrl_getnodemap ( ctdb , TIMELIMIT ( ) , CTDB_CURRENT_NODE , ctdb , & nodemap ) ;
if ( ret ! = 0 ) {
DEBUG ( DEBUG_ERR , ( " Unable to get nodemap from local node \n " ) ) ;
return ret ;
}
if ( sscanf ( argv [ 1 ] , " %u " , & pnn ) ! = 1 ) {
DEBUG ( DEBUG_ERR , ( " Badly formed pnn \n " ) ) ;
return - 1 ;
}
ret = ctdb_ctrl_get_tunable ( ctdb , TIMELIMIT ( ) , CTDB_CURRENT_NODE , " DeterministicIPs " , & value ) ;
if ( ret = = - 1 ) {
DEBUG ( DEBUG_ERR , ( " Unable to get tunable variable 'DeterministicIPs' from local node \n " ) ) ;
return - 1 ;
}
if ( value ! = 0 ) {
DEBUG ( DEBUG_ERR , ( " The tunable 'DeterministicIPs' is set. You can only move ip addresses when this feature is disabled \n " ) ) ;
return - 1 ;
}
ret = ctdb_ctrl_get_tunable ( ctdb , TIMELIMIT ( ) , CTDB_CURRENT_NODE , " NoIPFailback " , & value ) ;
if ( ret = = - 1 ) {
DEBUG ( DEBUG_ERR , ( " Unable to get tunable variable 'NoIPFailback' from local node \n " ) ) ;
return - 1 ;
}
if ( value = = 0 ) {
DEBUG ( DEBUG_ERR , ( " The tunable 'NoIPFailback' is NOT set. You can only move ip addresses when this feature is enabled \n " ) ) ;
return - 1 ;
}
/* read the public ip list from the node */
ret = ctdb_ctrl_get_public_ips ( ctdb , TIMELIMIT ( ) , pnn , ctdb , & ips ) ;
if ( ret ! = 0 ) {
DEBUG ( DEBUG_ERR , ( " Unable to get public ip list from node %u \n " , pnn ) ) ;
return - 1 ;
}
for ( i = 0 ; i < ips - > num ; i + + ) {
if ( ctdb_same_ip ( & ip , & ips - > ips [ i ] . sin ) ) {
break ;
}
}
if ( i = = ips - > num ) {
DEBUG ( DEBUG_ERR , ( " Node %u can not host ip address '%s' \n " ,
pnn , inet_ntoa ( ip . sin_addr ) ) ) ;
return - 1 ;
}
if ( ips - > ips [ i ] . pnn = = pnn ) {
DEBUG ( DEBUG_ERR , ( " Host %u is already hosting '%s' \n " ,
pnn , inet_ntoa ( ips - > ips [ i ] . sin . sin_addr ) ) ) ;
return - 1 ;
}
/* send a moveip message to the recovery master */
pip . pnn = pnn ;
pip . sin . sin_family = AF_INET ;
pip . sin . sin_addr = ips - > ips [ i ] . sin . sin_addr ;
data . dsize = sizeof ( pip ) ;
data . dptr = ( unsigned char * ) & pip ;
/* send release ip to all nodes */
if ( ctdb_client_async_control ( ctdb , CTDB_CONTROL_RELEASE_IP ,
list_of_active_nodes ( ctdb , nodemap , ctdb , true ) ,
TIMELIMIT ( ) , false , data ) ! = 0 ) {
DEBUG ( DEBUG_ERR , ( __location__ " Unable to send 'ReleaseIP' to all nodes. \n " ) ) ;
return - 1 ;
}
return 0 ;
}
2008-03-27 01:23:27 +03:00
/*
add a public ip address to a node
*/
static int control_addip ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
int ret ;
int len ;
unsigned mask ;
struct sockaddr_in addr ;
struct ctdb_control_ip_iface * pub ;
if ( argc ! = 2 ) {
usage ( ) ;
}
if ( ! parse_ip_mask ( argv [ 0 ] , & addr , & mask ) ) {
DEBUG ( DEBUG_ERR , ( " Badly formed ip/mask : %s \n " , argv [ 0 ] ) ) ;
return - 1 ;
}
2008-04-03 09:35:23 +04:00
len = offsetof ( struct ctdb_control_ip_iface , iface ) + strlen ( argv [ 1 ] ) + 1 ;
2008-03-27 01:23:27 +03:00
pub = talloc_size ( ctdb , len ) ;
CTDB_NO_MEMORY ( ctdb , pub ) ;
pub - > sin = addr ;
pub - > mask = mask ;
2008-03-31 05:49:39 +04:00
pub - > len = strlen ( argv [ 1 ] ) + 1 ;
memcpy ( & pub - > iface [ 0 ] , argv [ 1 ] , strlen ( argv [ 1 ] ) + 1 ) ;
2008-03-27 01:23:27 +03:00
ret = ctdb_ctrl_add_public_ip ( ctdb , TIMELIMIT ( ) , options . pnn , pub ) ;
if ( ret ! = 0 ) {
DEBUG ( DEBUG_ERR , ( " Unable to add public ip to node %u \n " , options . pnn ) ) ;
return ret ;
}
return 0 ;
}
/*
delete a public ip address from a node
*/
static int control_delip ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
int ret ;
struct sockaddr_in addr ;
struct ctdb_control_ip_iface pub ;
if ( argc ! = 1 ) {
usage ( ) ;
}
addr . sin_family = AF_INET ;
if ( inet_aton ( argv [ 0 ] , & addr . sin_addr ) = = 0 ) {
DEBUG ( DEBUG_ERR , ( " Wrongly formed ip address '%s' \n " , argv [ 0 ] ) ) ;
return - 1 ;
}
pub . sin = addr ;
pub . mask = 0 ;
pub . len = 0 ;
ret = ctdb_ctrl_del_public_ip ( ctdb , TIMELIMIT ( ) , options . pnn , & pub ) ;
if ( ret ! = 0 ) {
DEBUG ( DEBUG_ERR , ( " Unable to del public ip from node %u \n " , options . pnn ) ) ;
return ret ;
}
return 0 ;
}
2007-07-04 08:14:48 +04:00
/*
kill a tcp connection
*/
static int kill_tcp ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
2007-07-12 02:30:04 +04:00
int ret ;
struct ctdb_control_killtcp killtcp ;
2007-07-04 08:14:48 +04:00
2007-07-12 02:30:04 +04:00
if ( argc < 2 ) {
2007-07-04 08:14:48 +04:00
usage ( ) ;
}
2007-07-12 02:30:04 +04:00
if ( ! parse_ip_port ( argv [ 0 ] , & killtcp . src ) ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Bad IP:port '%s' \n " , argv [ 0 ] ) ) ;
2007-07-04 10:51:13 +04:00
return - 1 ;
}
2007-07-04 08:14:48 +04:00
2007-07-12 02:30:04 +04:00
if ( ! parse_ip_port ( argv [ 1 ] , & killtcp . dst ) ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Bad IP:port '%s' \n " , argv [ 1 ] ) ) ;
2007-07-04 10:51:13 +04:00
return - 1 ;
}
2007-07-04 08:14:48 +04:00
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_killtcp ( ctdb , TIMELIMIT ( ) , options . pnn , & killtcp ) ;
2007-07-12 02:30:04 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to killtcp from node %u \n " , options . pnn ) ) ;
2007-07-12 02:30:04 +04:00
return ret ;
2007-07-04 08:14:48 +04:00
}
2007-09-13 04:02:56 +04:00
return 0 ;
2007-07-04 08:14:48 +04:00
}
2007-08-24 09:53:41 +04:00
2007-10-09 05:56:09 +04:00
/*
send a gratious arp
*/
static int control_gratious_arp ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
int ret ;
struct sockaddr_in sin ;
if ( argc < 2 ) {
usage ( ) ;
}
sin . sin_family = AF_INET ;
if ( inet_aton ( argv [ 0 ] , & sin . sin_addr ) = = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Wrongly formed ip address '%s' \n " , argv [ 0 ] ) ) ;
2007-10-09 05:56:09 +04:00
return - 1 ;
}
ret = ctdb_ctrl_gratious_arp ( ctdb , TIMELIMIT ( ) , options . pnn , & sin , argv [ 1 ] ) ;
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to send gratious_arp from node %u \n " , options . pnn ) ) ;
2007-10-09 05:56:09 +04:00
return ret ;
}
return 0 ;
}
2007-08-24 09:53:41 +04:00
/*
register a server id
*/
static int regsrvid ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
int ret ;
struct ctdb_server_id server_id ;
if ( argc < 3 ) {
usage ( ) ;
}
2007-09-04 04:21:51 +04:00
server_id . pnn = strtoul ( argv [ 0 ] , NULL , 0 ) ;
2007-08-24 09:53:41 +04:00
server_id . type = strtoul ( argv [ 1 ] , NULL , 0 ) ;
server_id . server_id = strtoul ( argv [ 2 ] , NULL , 0 ) ;
ret = ctdb_ctrl_register_server_id ( ctdb , TIMELIMIT ( ) , & server_id ) ;
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to register server_id from node %u \n " , options . pnn ) ) ;
2007-08-24 09:53:41 +04:00
return ret ;
}
return - 1 ;
}
/*
unregister a server id
*/
static int unregsrvid ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
int ret ;
struct ctdb_server_id server_id ;
if ( argc < 3 ) {
usage ( ) ;
}
2007-09-04 04:21:51 +04:00
server_id . pnn = strtoul ( argv [ 0 ] , NULL , 0 ) ;
2007-08-24 09:53:41 +04:00
server_id . type = strtoul ( argv [ 1 ] , NULL , 0 ) ;
server_id . server_id = strtoul ( argv [ 2 ] , NULL , 0 ) ;
ret = ctdb_ctrl_unregister_server_id ( ctdb , TIMELIMIT ( ) , & server_id ) ;
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to unregister server_id from node %u \n " , options . pnn ) ) ;
2007-08-24 09:53:41 +04:00
return ret ;
}
return - 1 ;
}
/*
check if a server id exists
*/
static int chksrvid ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
uint32_t status ;
int ret ;
struct ctdb_server_id server_id ;
if ( argc < 3 ) {
usage ( ) ;
}
2007-09-04 04:21:51 +04:00
server_id . pnn = strtoul ( argv [ 0 ] , NULL , 0 ) ;
2007-08-24 09:53:41 +04:00
server_id . type = strtoul ( argv [ 1 ] , NULL , 0 ) ;
server_id . server_id = strtoul ( argv [ 2 ] , NULL , 0 ) ;
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_check_server_id ( ctdb , TIMELIMIT ( ) , options . pnn , & server_id , & status ) ;
2007-08-24 09:53:41 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to check server_id from node %u \n " , options . pnn ) ) ;
2007-08-24 09:53:41 +04:00
return ret ;
}
if ( status ) {
2007-09-04 04:21:51 +04:00
printf ( " Server id %d:%d:%d EXISTS \n " , server_id . pnn , server_id . type , server_id . server_id ) ;
2007-08-24 09:53:41 +04:00
} else {
2007-09-04 04:21:51 +04:00
printf ( " Server id %d:%d:%d does NOT exist \n " , server_id . pnn , server_id . type , server_id . server_id ) ;
2007-08-24 09:53:41 +04:00
}
return 0 ;
}
2007-08-26 04:57:02 +04:00
/*
get a list of all server ids that are registered on a node
*/
static int getsrvids ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
int i , ret ;
struct ctdb_server_id_list * server_ids ;
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_get_server_id_list ( ctdb , ctdb , TIMELIMIT ( ) , options . pnn , & server_ids ) ;
2007-08-26 04:57:02 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to get server_id list from node %u \n " , options . pnn ) ) ;
2007-08-26 04:57:02 +04:00
return ret ;
}
for ( i = 0 ; i < server_ids - > num ; i + + ) {
printf ( " Server id %d:%d:%d \n " ,
2007-09-04 04:21:51 +04:00
server_ids - > server_ids [ i ] . pnn ,
2007-08-26 04:57:02 +04:00
server_ids - > server_ids [ i ] . type ,
server_ids - > server_ids [ i ] . server_id ) ;
}
return - 1 ;
}
2007-07-05 02:56:02 +04:00
/*
send a tcp tickle ack
*/
static int tickle_tcp ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
2007-07-12 03:22:06 +04:00
int s , ret ;
2007-07-05 02:56:02 +04:00
struct sockaddr_in src , dst ;
if ( argc < 2 ) {
usage ( ) ;
}
if ( ! parse_ip_port ( argv [ 0 ] , & src ) ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Bad IP:port '%s' \n " , argv [ 0 ] ) ) ;
2007-07-05 02:56:02 +04:00
return - 1 ;
}
if ( ! parse_ip_port ( argv [ 1 ] , & dst ) ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Bad IP:port '%s' \n " , argv [ 1 ] ) ) ;
2007-07-05 02:56:02 +04:00
return - 1 ;
}
2007-07-12 03:22:06 +04:00
s = ctdb_sys_open_sending_socket ( ) ;
if ( s = = - 1 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Failed to open socket for sending tickle \n " ) ) ;
2007-07-12 03:22:06 +04:00
return 0 ;
}
ret = ctdb_sys_send_tcp ( s , & src , & dst , 0 , 0 , 0 ) ;
close ( s ) ;
2007-07-05 02:56:02 +04:00
if ( ret = = 0 ) {
return 0 ;
}
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Error while sending tickle ack \n " ) ) ;
2007-07-05 02:56:02 +04:00
return - 1 ;
}
2007-09-07 10:45:19 +04:00
2008-04-22 18:55:57 +04:00
struct node_ip {
uint32_t pnn ;
struct sockaddr_in sin ;
} ;
void getips_store_callback ( void * param , void * data )
{
struct node_ip * node_ip = ( struct node_ip * ) data ;
struct ctdb_all_public_ips * ips = param ;
int i ;
i = ips - > num + + ;
ips - > ips [ i ] . pnn = node_ip - > pnn ;
ips - > ips [ i ] . sin = node_ip - > sin ;
}
void getips_count_callback ( void * param , void * data )
{
uint32_t * count = param ;
( * count ) + + ;
}
static int
control_get_all_public_ips ( struct ctdb_context * ctdb , TALLOC_CTX * tmp_ctx , struct ctdb_all_public_ips * * ips )
{
struct ctdb_all_public_ips * tmp_ips ;
struct ctdb_node_map * nodemap = NULL ;
trbt_tree_t * tree ;
int i , j , len , ret ;
uint32_t count ;
ret = ctdb_ctrl_getnodemap ( ctdb , TIMELIMIT ( ) , CTDB_CURRENT_NODE , tmp_ctx , & nodemap ) ;
if ( ret ! = 0 ) {
DEBUG ( DEBUG_ERR , ( " Unable to get nodemap from node %u \n " , options . pnn ) ) ;
return ret ;
}
tree = trbt_create ( tmp_ctx , 0 ) ;
for ( i = 0 ; i < nodemap - > num ; i + + ) {
if ( nodemap - > nodes [ i ] . flags & NODE_FLAGS_DISCONNECTED ) {
continue ;
}
/* read the public ip list from this node */
ret = ctdb_ctrl_get_public_ips ( ctdb , TIMELIMIT ( ) , nodemap - > nodes [ i ] . pnn , tmp_ctx , & tmp_ips ) ;
if ( ret ! = 0 ) {
DEBUG ( DEBUG_ERR , ( " Unable to get public ip list from node %u \n " , nodemap - > nodes [ i ] . pnn ) ) ;
return - 1 ;
}
for ( j = 0 ; j < tmp_ips - > num ; j + + ) {
struct node_ip * node_ip ;
node_ip = talloc ( tmp_ctx , struct node_ip ) ;
node_ip - > pnn = tmp_ips - > ips [ j ] . pnn ;
node_ip - > sin = tmp_ips - > ips [ j ] . sin ;
trbt_insert32 ( tree , tmp_ips - > ips [ j ] . sin . sin_addr . s_addr , node_ip ) ;
}
talloc_free ( tmp_ips ) ;
}
/* traverse */
count = 0 ;
trbt_traversearray32 ( tree , 1 , getips_count_callback , & count ) ;
len = offsetof ( struct ctdb_all_public_ips , ips ) +
count * sizeof ( struct ctdb_public_ip ) ;
tmp_ips = talloc_zero_size ( tmp_ctx , len ) ;
trbt_traversearray32 ( tree , 1 , getips_store_callback , tmp_ips ) ;
* ips = tmp_ips ;
return 0 ;
}
2007-06-04 15:11:51 +04:00
/*
display public ip status
*/
static int control_ip ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
2007-09-14 09:19:44 +04:00
int i , ret ;
2007-09-07 10:45:19 +04:00
TALLOC_CTX * tmp_ctx = talloc_new ( ctdb ) ;
2007-06-04 15:11:51 +04:00
struct ctdb_all_public_ips * ips ;
2008-04-22 18:55:57 +04:00
if ( options . pnn = = CTDB_BROADCAST_ALL ) {
/* read the list of public ips from all nodes */
ret = control_get_all_public_ips ( ctdb , tmp_ctx , & ips ) ;
} else {
/* read the public ip list from this node */
ret = ctdb_ctrl_get_public_ips ( ctdb , TIMELIMIT ( ) , options . pnn , tmp_ctx , & ips ) ;
}
2007-06-04 15:11:51 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to get public ips from node %u \n " , options . pnn ) ) ;
2007-09-07 10:45:19 +04:00
talloc_free ( tmp_ctx ) ;
2007-06-04 15:11:51 +04:00
return ret ;
}
2007-09-14 09:23:23 +04:00
if ( options . machinereadable ) {
printf ( " :Public IP:Node: \n " ) ;
} else {
2008-04-22 18:55:57 +04:00
if ( options . pnn = = CTDB_BROADCAST_ALL ) {
printf ( " Public IPs on ALL nodes \n " ) ;
} else {
printf ( " Public IPs on node %u \n " , options . pnn ) ;
}
2007-09-07 10:45:19 +04:00
}
2007-10-17 07:42:42 +04:00
for ( i = 1 ; i < = ips - > num ; i + + ) {
2008-03-04 05:18:27 +03:00
if ( options . machinereadable ) {
printf ( " :%s:%d: \n " , inet_ntoa ( ips - > ips [ ips - > num - i ] . sin . sin_addr ) , ips - > ips [ ips - > num - i ] . pnn ) ;
} else {
printf ( " %s %d \n " , inet_ntoa ( ips - > ips [ ips - > num - i ] . sin . sin_addr ) , ips - > ips [ ips - > num - i ] . pnn ) ;
}
2007-06-04 15:11:51 +04:00
}
2007-09-07 10:45:19 +04:00
talloc_free ( tmp_ctx ) ;
2007-06-04 15:11:51 +04:00
return 0 ;
}
2007-05-25 07:05:25 +04:00
/*
2007-05-29 06:16:59 +04:00
display pid of a ctdb daemon
2007-05-25 07:05:25 +04:00
*/
2007-05-29 06:16:59 +04:00
static int control_getpid ( struct ctdb_context * ctdb , int argc , const char * * argv )
2007-05-25 07:05:25 +04:00
{
2007-05-29 06:16:59 +04:00
uint32_t pid ;
2007-05-25 07:05:25 +04:00
int ret ;
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_getpid ( ctdb , TIMELIMIT ( ) , options . pnn , & pid ) ;
2007-05-25 07:05:25 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to get daemon pid from node %u \n " , options . pnn ) ) ;
2007-05-25 07:05:25 +04:00
return ret ;
}
2007-05-29 06:16:59 +04:00
printf ( " Pid:%d \n " , pid ) ;
2007-05-25 07:05:25 +04:00
return 0 ;
}
2007-06-07 03:16:17 +04:00
/*
disable a remote node
*/
static int control_disable ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
int ret ;
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_modflags ( ctdb , TIMELIMIT ( ) , options . pnn , NODE_FLAGS_PERMANENTLY_DISABLED , 0 ) ;
2007-06-07 03:16:17 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to disable node %u \n " , options . pnn ) ) ;
2007-06-07 03:16:17 +04:00
return ret ;
}
return 0 ;
}
/*
enable a disabled remote node
*/
static int control_enable ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
int ret ;
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_modflags ( ctdb , TIMELIMIT ( ) , options . pnn , 0 , NODE_FLAGS_PERMANENTLY_DISABLED ) ;
2007-06-07 03:16:17 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to enable node %u \n " , options . pnn ) ) ;
2007-06-07 03:16:17 +04:00
return ret ;
}
return 0 ;
}
2007-06-07 10:34:33 +04:00
/*
ban a node from the cluster
*/
static int control_ban ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
int ret ;
struct ctdb_ban_info b ;
TDB_DATA data ;
uint32_t ban_time ;
if ( argc < 1 ) {
usage ( ) ;
}
ban_time = strtoul ( argv [ 0 ] , NULL , 0 ) ;
2007-09-04 04:33:10 +04:00
b . pnn = options . pnn ;
2007-06-07 10:34:33 +04:00
b . ban_time = ban_time ;
data . dptr = ( uint8_t * ) & b ;
data . dsize = sizeof ( b ) ;
2007-12-03 07:45:53 +03:00
ret = ctdb_send_message ( ctdb , options . pnn , CTDB_SRVID_BAN_NODE , data ) ;
2007-06-07 10:34:33 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Failed to ban node %u \n " , options . pnn ) ) ;
2007-06-07 10:34:33 +04:00
return - 1 ;
}
return 0 ;
}
/*
unban a node from the cluster
*/
static int control_unban ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
int ret ;
TDB_DATA data ;
2007-09-04 04:14:41 +04:00
data . dptr = ( uint8_t * ) & options . pnn ;
2007-06-07 10:34:33 +04:00
data . dsize = sizeof ( uint32_t ) ;
2007-12-03 07:45:53 +03:00
ret = ctdb_send_message ( ctdb , options . pnn , CTDB_SRVID_UNBAN_NODE , data ) ;
2007-06-07 10:34:33 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Failed to to unban node %u \n " , options . pnn ) ) ;
2007-06-07 10:34:33 +04:00
return - 1 ;
}
return 0 ;
}
2007-05-25 07:05:25 +04:00
/*
2007-05-29 06:16:59 +04:00
shutdown a daemon
2007-05-25 07:05:25 +04:00
*/
2007-05-29 06:16:59 +04:00
static int control_shutdown ( struct ctdb_context * ctdb , int argc , const char * * argv )
2007-05-25 07:05:25 +04:00
{
int ret ;
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_shutdown ( ctdb , TIMELIMIT ( ) , options . pnn ) ;
2007-05-25 07:05:25 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to shutdown node %u \n " , options . pnn ) ) ;
2007-05-25 07:05:25 +04:00
return ret ;
}
return 0 ;
}
2007-05-24 02:08:45 +04:00
/*
trigger a recovery
*/
2007-05-29 06:16:59 +04:00
static int control_recover ( struct ctdb_context * ctdb , int argc , const char * * argv )
2007-05-24 02:08:45 +04:00
{
int ret ;
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_freeze ( ctdb , TIMELIMIT ( ) , options . pnn ) ;
2007-05-24 02:08:45 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to freeze node \n " ) ) ;
2007-05-24 02:08:45 +04:00
return ret ;
}
2007-04-29 16:51:56 +04:00
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_setrecmode ( ctdb , TIMELIMIT ( ) , options . pnn , CTDB_RECOVERY_ACTIVE ) ;
2007-04-29 16:51:56 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to set recovery mode \n " ) ) ;
2007-04-29 16:51:56 +04:00
return ret ;
}
return 0 ;
}
2007-05-21 03:24:34 +04:00
/*
display monitoring mode of a remote node
*/
static int control_getmonmode ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
2007-05-29 06:16:59 +04:00
uint32_t monmode ;
2007-05-21 03:24:34 +04:00
int ret ;
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_getmonmode ( ctdb , TIMELIMIT ( ) , options . pnn , & monmode ) ;
2007-05-21 03:24:34 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to get monmode from node %u \n " , options . pnn ) ) ;
2007-05-21 03:24:34 +04:00
return ret ;
}
printf ( " Monitoring mode:%s (%d) \n " , monmode = = CTDB_MONITORING_ACTIVE ? " ACTIVE " : " DISABLED " , monmode ) ;
return 0 ;
}
2008-03-25 00:27:38 +03:00
/*
disable monitoring on a node
*/
static int control_disable_monmode ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
int ret ;
ret = ctdb_ctrl_disable_monmode ( ctdb , TIMELIMIT ( ) , options . pnn ) ;
if ( ret ! = 0 ) {
DEBUG ( DEBUG_ERR , ( " Unable to disable monmode on node %u \n " , options . pnn ) ) ;
return ret ;
}
printf ( " Monitoring mode:%s \n " , " DISABLED " ) ;
return 0 ;
}
/*
enable monitoring on a node
*/
static int control_enable_monmode ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
int ret ;
ret = ctdb_ctrl_enable_monmode ( ctdb , TIMELIMIT ( ) , options . pnn ) ;
if ( ret ! = 0 ) {
DEBUG ( DEBUG_ERR , ( " Unable to enable monmode on node %u \n " , options . pnn ) ) ;
return ret ;
}
printf ( " Monitoring mode:%s \n " , " ACTIVE " ) ;
return 0 ;
}
2007-04-28 23:47:13 +04:00
/*
2007-05-04 06:18:39 +04:00
display remote list of keys / data for a db
2007-04-28 23:47:13 +04:00
*/
2007-04-29 18:58:27 +04:00
static int control_catdb ( struct ctdb_context * ctdb , int argc , const char * * argv )
2007-04-28 23:47:13 +04:00
{
2007-05-04 07:25:30 +04:00
const char * db_name ;
2007-05-04 06:18:39 +04:00
struct ctdb_db_context * ctdb_db ;
int ret ;
2007-04-28 23:47:13 +04:00
2007-05-04 06:18:39 +04:00
if ( argc < 1 ) {
2007-04-28 23:47:13 +04:00
usage ( ) ;
}
2007-05-04 07:25:30 +04:00
db_name = argv [ 0 ] ;
2007-09-21 06:24:02 +04:00
ctdb_db = ctdb_attach ( ctdb , db_name , false ) ;
2007-05-29 06:16:59 +04:00
2007-05-04 06:18:39 +04:00
if ( ctdb_db = = NULL ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to attach to database '%s' \n " , db_name ) ) ;
2007-05-04 06:18:39 +04:00
return - 1 ;
2007-04-28 23:47:13 +04:00
}
2007-05-04 06:18:39 +04:00
2007-05-29 06:16:59 +04:00
/* traverse and dump the cluster tdb */
ret = ctdb_dump_db ( ctdb_db , stdout ) ;
if ( ret = = - 1 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to dump database \n " ) ) ;
2007-05-29 06:16:59 +04:00
return - 1 ;
2007-05-05 23:53:15 +04:00
}
2007-05-04 07:25:30 +04:00
talloc_free ( ctdb_db ) ;
2007-05-04 06:18:39 +04:00
printf ( " Dumped %d records \n " , ret ) ;
2007-04-28 23:47:13 +04:00
return 0 ;
}
2007-04-29 18:58:27 +04:00
2007-04-28 14:00:50 +04:00
/*
display a list of the databases on a remote ctdb
*/
static int control_getdbmap ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
int i , ret ;
2007-05-03 07:07:34 +04:00
struct ctdb_dbid_map * dbmap = NULL ;
2007-04-28 14:00:50 +04:00
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_getdbmap ( ctdb , TIMELIMIT ( ) , options . pnn , ctdb , & dbmap ) ;
2007-04-28 14:00:50 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to get dbids from node %u \n " , options . pnn ) ) ;
2007-04-28 14:00:50 +04:00
return ret ;
}
2007-05-03 07:07:34 +04:00
printf ( " Number of databases:%d \n " , dbmap - > num ) ;
for ( i = 0 ; i < dbmap - > num ; i + + ) {
2007-04-28 14:00:50 +04:00
const char * path ;
2007-05-05 23:53:15 +04:00
const char * name ;
2007-09-21 06:24:02 +04:00
bool persistent ;
2007-04-28 14:00:50 +04:00
2007-09-21 06:24:02 +04:00
ctdb_ctrl_getdbpath ( ctdb , TIMELIMIT ( ) , options . pnn , dbmap - > dbs [ i ] . dbid , ctdb , & path ) ;
ctdb_ctrl_getdbname ( ctdb , TIMELIMIT ( ) , options . pnn , dbmap - > dbs [ i ] . dbid , ctdb , & name ) ;
persistent = dbmap - > dbs [ i ] . persistent ;
printf ( " dbid:0x%08x name:%s path:%s %s \n " , dbmap - > dbs [ i ] . dbid , name ,
path , persistent ? " PERSISTENT " : " " ) ;
2007-04-28 14:00:50 +04:00
}
2007-05-02 04:20:34 +04:00
2007-04-28 14:00:50 +04:00
return 0 ;
}
2008-02-29 02:03:39 +03:00
/*
get the filename of the reclock file
*/
static int control_getreclock ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
2008-02-29 04:37:42 +03:00
int i , ret , fd ;
2008-02-29 02:03:39 +03:00
const char * reclock ;
2008-02-29 04:37:42 +03:00
struct ctdb_node_map * nodemap = NULL ;
char * pnnfile ;
2008-02-29 02:03:39 +03:00
ret = ctdb_ctrl_getreclock ( ctdb , TIMELIMIT ( ) , options . pnn , ctdb , & reclock ) ;
if ( ret ! = 0 ) {
DEBUG ( DEBUG_ERR , ( " Unable to get reclock file from node %u \n " , options . pnn ) ) ;
return ret ;
}
2008-02-29 04:37:42 +03:00
ret = ctdb_ctrl_getnodemap ( ctdb , TIMELIMIT ( ) , options . pnn , ctdb , & nodemap ) ;
if ( ret ! = 0 ) {
DEBUG ( DEBUG_ERR , ( " Unable to get nodemap from node %u \n " , options . pnn ) ) ;
return ret ;
}
pnnfile = talloc_asprintf ( ctdb , " %s.pnn " , reclock ) ;
CTDB_NO_MEMORY ( ctdb , pnnfile ) ;
fd = open ( pnnfile , O_RDONLY ) ;
if ( fd = = - 1 ) {
DEBUG ( DEBUG_CRIT , ( __location__ " Failed to open reclock pnn file %s - (%s) \n " ,
pnnfile , strerror ( errno ) ) ) ;
exit ( 10 ) ;
}
printf ( " Reclock file : %s \n " , reclock ) ;
for ( i = 0 ; i < nodemap - > num ; i + + ) {
int count ;
count = ctdb_read_pnn_lock ( fd , nodemap - > nodes [ i ] . pnn ) ;
printf ( " pnn:%d %-16s " , nodemap - > nodes [ i ] . pnn ,
inet_ntoa ( nodemap - > nodes [ i ] . sin . sin_addr ) ) ;
if ( count = = - 1 ) {
printf ( " NOT ACTIVE \n " ) ;
} else {
printf ( " ACTIVE with %d connections \n " , count ) ;
}
}
close ( fd ) ;
2008-02-29 02:03:39 +03:00
return 0 ;
}
2007-10-08 03:47:20 +04:00
/*
check if the local node is recmaster or not
it will return 1 if this node is the recmaster and 0 if it is not
or if the local ctdb daemon could not be contacted
*/
static int control_isnotrecmaster ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
uint32_t mypnn , recmaster ;
int ret ;
mypnn = ctdb_ctrl_getpnn ( ctdb , TIMELIMIT ( ) , options . pnn ) ;
if ( mypnn = = - 1 ) {
printf ( " Failed to get pnn of node \n " ) ;
return 1 ;
}
ret = ctdb_ctrl_getrecmaster ( ctdb , ctdb , TIMELIMIT ( ) , options . pnn , & recmaster ) ;
if ( ret ! = 0 ) {
printf ( " Failed to get the recmaster \n " ) ;
return 1 ;
}
if ( recmaster ! = mypnn ) {
printf ( " this node is not the recmaster \n " ) ;
return 1 ;
}
printf ( " this node is the recmaster \n " ) ;
return 0 ;
}
2007-04-28 14:40:26 +04:00
/*
2007-05-29 06:16:59 +04:00
ping a node
2007-04-27 17:14:36 +04:00
*/
2007-04-26 21:27:07 +04:00
static int control_ping ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
2007-06-11 16:25:26 +04:00
int ret ;
struct timeval tv = timeval_current ( ) ;
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_ping ( ctdb , options . pnn ) ;
2007-06-11 16:25:26 +04:00
if ( ret = = - 1 ) {
2007-09-04 04:14:41 +04:00
printf ( " Unable to get ping response from node %u \n " , options . pnn ) ;
2007-06-11 16:25:26 +04:00
} else {
printf ( " response from %u time=%.6f sec (%d clients) \n " ,
2007-09-04 04:14:41 +04:00
options . pnn , timeval_elapsed ( & tv ) , ret ) ;
2007-04-26 21:27:07 +04:00
}
return 0 ;
}
2007-04-27 17:14:36 +04:00
2007-06-04 13:53:19 +04:00
/*
get a tunable
*/
static int control_getvar ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
const char * name ;
uint32_t value ;
int ret ;
if ( argc < 1 ) {
usage ( ) ;
}
name = argv [ 0 ] ;
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_get_tunable ( ctdb , TIMELIMIT ( ) , options . pnn , name , & value ) ;
2007-06-04 13:53:19 +04:00
if ( ret = = - 1 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to get tunable variable '%s' \n " , name ) ) ;
2007-06-04 13:53:19 +04:00
return - 1 ;
}
2007-06-07 09:18:55 +04:00
printf ( " %-19s = %u \n " , name , value ) ;
2007-06-04 13:53:19 +04:00
return 0 ;
}
/*
set a tunable
*/
static int control_setvar ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
const char * name ;
uint32_t value ;
int ret ;
if ( argc < 2 ) {
usage ( ) ;
}
name = argv [ 0 ] ;
value = strtoul ( argv [ 1 ] , NULL , 0 ) ;
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_set_tunable ( ctdb , TIMELIMIT ( ) , options . pnn , name , value ) ;
2007-06-04 13:53:19 +04:00
if ( ret = = - 1 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to set tunable variable '%s' \n " , name ) ) ;
2007-06-04 13:53:19 +04:00
return - 1 ;
}
return 0 ;
}
/*
list all tunables
*/
static int control_listvars ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
uint32_t count ;
const char * * list ;
int ret , i ;
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_list_tunables ( ctdb , TIMELIMIT ( ) , options . pnn , ctdb , & list , & count ) ;
2007-06-04 13:53:19 +04:00
if ( ret = = - 1 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to list tunable variables \n " ) ) ;
2007-06-04 13:53:19 +04:00
return - 1 ;
}
for ( i = 0 ; i < count ; i + + ) {
control_getvar ( ctdb , 1 , & list [ i ] ) ;
}
talloc_free ( list ) ;
return 0 ;
}
2008-02-05 02:36:06 +03:00
static struct {
2008-02-05 02:26:23 +03:00
int32_t level ;
const char * description ;
2008-02-05 02:36:06 +03:00
} debug_levels [ ] = {
2008-02-05 02:26:23 +03:00
{ DEBUG_EMERG , " EMERG " } ,
{ DEBUG_ALERT , " ALERT " } ,
{ DEBUG_CRIT , " CRIT " } ,
{ DEBUG_ERR , " ERR " } ,
{ DEBUG_WARNING , " WARNING " } ,
{ DEBUG_NOTICE , " NOTICE " } ,
{ DEBUG_INFO , " INFO " } ,
2008-02-05 02:36:06 +03:00
{ DEBUG_DEBUG , " DEBUG " }
2008-02-05 02:26:23 +03:00
} ;
static const char * get_debug_by_level ( int32_t level )
{
int i ;
2008-02-05 02:36:06 +03:00
for ( i = 0 ; i < ARRAY_SIZE ( debug_levels ) ; i + + ) {
2008-02-05 02:26:23 +03:00
if ( debug_levels [ i ] . level = = level ) {
return debug_levels [ i ] . description ;
}
}
2008-02-05 02:36:06 +03:00
return " Unknown " ;
2008-02-05 02:26:23 +03:00
}
static int32_t get_debug_by_desc ( const char * desc )
{
int i ;
2008-02-05 02:36:06 +03:00
for ( i = 0 ; i < ARRAY_SIZE ( debug_levels ) ; i + + ) {
2008-02-05 02:26:23 +03:00
if ( ! strcmp ( debug_levels [ i ] . description , desc ) ) {
return debug_levels [ i ] . level ;
}
}
return DEBUG_ERR ;
}
2007-04-27 17:14:36 +04:00
/*
2007-05-29 06:16:59 +04:00
display debug level on a node
2007-04-27 17:14:36 +04:00
*/
2007-05-29 06:16:59 +04:00
static int control_getdebug ( struct ctdb_context * ctdb , int argc , const char * * argv )
2007-04-27 17:14:36 +04:00
{
2007-06-11 16:25:26 +04:00
int ret ;
2008-02-05 02:26:23 +03:00
int32_t level ;
2007-04-28 19:42:40 +04:00
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_get_debuglevel ( ctdb , options . pnn , & level ) ;
2007-06-11 16:25:26 +04:00
if ( ret ! = 0 ) {
2008-03-04 05:23:06 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to get debuglevel response from node %u \n " , options . pnn ) ) ;
return ret ;
2007-06-11 16:25:26 +04:00
} else {
2008-03-04 05:23:06 +03:00
if ( options . machinereadable ) {
printf ( " :Name:Level: \n " ) ;
printf ( " :%s:%d: \n " , get_debug_by_level ( level ) , level ) ;
} else {
printf ( " Node %u is at debug level %s (%u) \n " , options . pnn , get_debug_by_level ( level ) , level ) ;
}
2007-04-27 17:14:36 +04:00
}
return 0 ;
}
2007-05-29 06:16:59 +04:00
2007-04-27 17:14:36 +04:00
/*
2007-05-29 06:16:59 +04:00
set debug level on a node or all nodes
2007-04-27 17:14:36 +04:00
*/
2007-05-29 06:16:59 +04:00
static int control_setdebug ( struct ctdb_context * ctdb , int argc , const char * * argv )
2007-04-27 17:14:36 +04:00
{
int ret ;
2007-06-11 16:25:26 +04:00
uint32_t level ;
2007-04-27 17:14:36 +04:00
2007-05-29 06:16:59 +04:00
if ( argc < 1 ) {
2007-04-27 17:14:36 +04:00
usage ( ) ;
}
2008-02-05 02:36:06 +03:00
if ( isalpha ( argv [ 0 ] [ 0 ] ) ) {
2008-02-05 02:26:23 +03:00
level = get_debug_by_desc ( argv [ 0 ] ) ;
} else {
level = strtoul ( argv [ 0 ] , NULL , 0 ) ;
}
2007-04-27 17:14:36 +04:00
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_set_debuglevel ( ctdb , options . pnn , level ) ;
2007-06-11 16:25:26 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to set debug level on node %u \n " , options . pnn ) ) ;
2007-04-27 17:14:36 +04:00
}
return 0 ;
}
2007-04-30 17:54:06 +04:00
2007-05-12 09:15:27 +04:00
/*
freeze a node
*/
static int control_freeze ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
2007-06-11 16:25:26 +04:00
int ret ;
2007-05-12 09:15:27 +04:00
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_freeze ( ctdb , TIMELIMIT ( ) , options . pnn ) ;
2007-06-11 16:25:26 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to freeze node %u \n " , options . pnn ) ) ;
2007-06-11 16:25:26 +04:00
}
2007-05-12 09:15:27 +04:00
return 0 ;
}
/*
thaw a node
*/
static int control_thaw ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
2007-06-11 16:25:26 +04:00
int ret ;
2007-05-12 09:15:27 +04:00
2007-09-04 04:14:41 +04:00
ret = ctdb_ctrl_thaw ( ctdb , TIMELIMIT ( ) , options . pnn ) ;
2007-06-11 16:25:26 +04:00
if ( ret ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to thaw node %u \n " , options . pnn ) ) ;
2007-06-11 16:25:26 +04:00
}
2007-05-12 09:15:27 +04:00
return 0 ;
}
2007-04-30 17:54:06 +04:00
/*
attach to a database
*/
static int control_attach ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
const char * db_name ;
struct ctdb_db_context * ctdb_db ;
2007-05-29 06:16:59 +04:00
2007-04-30 17:54:06 +04:00
if ( argc < 1 ) {
usage ( ) ;
}
db_name = argv [ 0 ] ;
2007-09-21 06:24:02 +04:00
ctdb_db = ctdb_attach ( ctdb , db_name , false ) ;
2007-04-30 17:54:06 +04:00
if ( ctdb_db = = NULL ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to attach to database '%s' \n " , db_name ) ) ;
2007-04-30 17:54:06 +04:00
return - 1 ;
}
return 0 ;
}
2008-04-02 04:13:30 +04:00
/*
dump memory usage
*/
static int control_eventscript ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
TDB_DATA data ;
int ret ;
int32_t res ;
char * errmsg ;
TALLOC_CTX * tmp_ctx = talloc_new ( ctdb ) ;
if ( argc ! = 1 ) {
DEBUG ( DEBUG_ERR , ( " Invalid arguments \n " ) ) ;
return - 1 ;
}
data . dptr = ( unsigned char * ) discard_const ( argv [ 0 ] ) ;
data . dsize = strlen ( ( char * ) data . dptr ) + 1 ;
DEBUG ( DEBUG_ERR , ( " Running eventscripts with arguments \" %s \" on node %u \n " , data . dptr , options . pnn ) ) ;
ret = ctdb_control ( ctdb , options . pnn , 0 , CTDB_CONTROL_RUN_EVENTSCRIPTS ,
0 , data , tmp_ctx , NULL , & res , NULL , & errmsg ) ;
if ( ret ! = 0 | | res ! = 0 ) {
DEBUG ( DEBUG_ERR , ( " Failed to run eventscripts - %s \n " , errmsg ) ) ;
talloc_free ( tmp_ctx ) ;
return - 1 ;
}
talloc_free ( tmp_ctx ) ;
return 0 ;
}
2007-05-05 05:03:10 +04:00
/*
dump memory usage
*/
static int control_dumpmemory ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
2008-01-22 06:22:41 +03:00
TDB_DATA data ;
int ret ;
int32_t res ;
char * errmsg ;
TALLOC_CTX * tmp_ctx = talloc_new ( ctdb ) ;
ret = ctdb_control ( ctdb , options . pnn , 0 , CTDB_CONTROL_DUMP_MEMORY ,
0 , tdb_null , tmp_ctx , & data , & res , NULL , & errmsg ) ;
if ( ret ! = 0 | | res ! = 0 ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Failed to dump memory - %s \n " , errmsg ) ) ;
2008-01-22 06:22:41 +03:00
talloc_free ( tmp_ctx ) ;
return - 1 ;
}
write ( 1 , data . dptr , data . dsize ) ;
talloc_free ( tmp_ctx ) ;
return 0 ;
2007-05-29 06:16:59 +04:00
}
2008-04-01 08:34:54 +04:00
/*
handler for memory dumps
*/
static void mem_dump_handler ( struct ctdb_context * ctdb , uint64_t srvid ,
TDB_DATA data , void * private_data )
{
write ( 1 , data . dptr , data . dsize ) ;
exit ( 0 ) ;
}
/*
dump memory usage on the recovery daemon
*/
static int control_rddumpmemory ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
int ret ;
TDB_DATA data ;
struct rd_memdump_reply rd ;
rd . pnn = ctdb_ctrl_getpnn ( ctdb , TIMELIMIT ( ) , CTDB_CURRENT_NODE ) ;
if ( rd . pnn = = - 1 ) {
DEBUG ( DEBUG_ERR , ( " Failed to get pnn of local node \n " ) ) ;
return - 1 ;
}
rd . srvid = getpid ( ) ;
/* register a message port for receiveing the reply so that we
can receive the reply
*/
ctdb_set_message_handler ( ctdb , rd . srvid , mem_dump_handler , NULL ) ;
data . dptr = ( uint8_t * ) & rd ;
data . dsize = sizeof ( rd ) ;
ret = ctdb_send_message ( ctdb , options . pnn , CTDB_SRVID_MEM_DUMP , data ) ;
if ( ret ! = 0 ) {
DEBUG ( DEBUG_ERR , ( " Failed to send memdump request message to %u \n " , options . pnn ) ) ;
return - 1 ;
}
/* this loop will terminate when we have received the reply */
while ( 1 ) {
event_loop_once ( ctdb - > ev ) ;
}
return 0 ;
}
2008-02-19 06:44:48 +03:00
/*
list all nodes in the cluster
*/
static int control_listnodes ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
int i , ret ;
struct ctdb_node_map * nodemap = NULL ;
ret = ctdb_ctrl_getnodemap ( ctdb , TIMELIMIT ( ) , options . pnn , ctdb , & nodemap ) ;
if ( ret ! = 0 ) {
DEBUG ( DEBUG_ERR , ( " Unable to get nodemap from node %u \n " , options . pnn ) ) ;
return ret ;
}
for ( i = 0 ; i < nodemap - > num ; i + + ) {
printf ( " %s \n " , inet_ntoa ( nodemap - > nodes [ i ] . sin . sin_addr ) ) ;
}
return 0 ;
}
/*
reload the nodes file on the local node
*/
static int control_reload_nodes_file ( struct ctdb_context * ctdb , int argc , const char * * argv )
{
2008-02-21 00:25:01 +03:00
int i , ret ;
int mypnn ;
struct ctdb_node_map * nodemap = NULL ;
2008-02-19 06:44:48 +03:00
2008-02-21 00:25:01 +03:00
mypnn = ctdb_ctrl_getpnn ( ctdb , TIMELIMIT ( ) , CTDB_CURRENT_NODE ) ;
if ( mypnn = = - 1 ) {
DEBUG ( DEBUG_ERR , ( " Failed to read pnn of local node \n " ) ) ;
return - 1 ;
}
2008-02-19 06:44:48 +03:00
2008-02-21 00:25:01 +03:00
ret = ctdb_ctrl_getnodemap ( ctdb , TIMELIMIT ( ) , CTDB_CURRENT_NODE , ctdb , & nodemap ) ;
2008-02-19 06:44:48 +03:00
if ( ret ! = 0 ) {
2008-02-21 00:25:01 +03:00
DEBUG ( DEBUG_ERR , ( " Unable to get nodemap from local node \n " ) ) ;
return ret ;
2008-02-19 06:44:48 +03:00
}
2008-02-21 00:25:01 +03:00
/* reload the nodes file on all remote nodes */
for ( i = 0 ; i < nodemap - > num ; i + + ) {
if ( nodemap - > nodes [ i ] . pnn = = mypnn ) {
continue ;
}
DEBUG ( DEBUG_NOTICE , ( " Reloading nodes file on node %u \n " , nodemap - > nodes [ i ] . pnn ) ) ;
ret = ctdb_ctrl_reload_nodes_file ( ctdb , TIMELIMIT ( ) ,
nodemap - > nodes [ i ] . pnn ) ;
if ( ret ! = 0 ) {
DEBUG ( DEBUG_ERR , ( " ERROR: Failed to reload nodes file on node %u. You MUST fix that node manually! \n " , nodemap - > nodes [ i ] . pnn ) ) ;
}
}
/* reload the nodes file on the local node */
DEBUG ( DEBUG_NOTICE , ( " Reloading nodes file on node %u \n " , mypnn ) ) ;
ret = ctdb_ctrl_reload_nodes_file ( ctdb , TIMELIMIT ( ) , mypnn ) ;
if ( ret ! = 0 ) {
DEBUG ( DEBUG_ERR , ( " ERROR: Failed to reload nodes file on node %u. You MUST fix that node manually! \n " , mypnn ) ) ;
}
2008-02-19 06:44:48 +03:00
return 0 ;
}
2007-05-29 06:16:59 +04:00
static const struct {
const char * name ;
int ( * fn ) ( struct ctdb_context * , int , const char * * ) ;
2007-06-11 16:25:26 +04:00
bool auto_all ;
2007-05-29 06:16:59 +04:00
const char * msg ;
const char * args ;
} ctdb_commands [ ] = {
2008-04-03 10:07:00 +04:00
# ifdef CTDB_VERS
{ " version " , control_version , true , " show version of ctdb " } ,
# endif
2007-06-11 16:25:26 +04:00
{ " status " , control_status , true , " show node status " } ,
2008-01-17 03:33:23 +03:00
{ " uptime " , control_uptime , true , " show node uptime " } ,
2007-06-11 16:25:26 +04:00
{ " ping " , control_ping , true , " ping all nodes " } ,
{ " getvar " , control_getvar , true , " get a tunable variable " , " <name> " } ,
{ " setvar " , control_setvar , true , " set a tunable variable " , " <name> <value> " } ,
{ " listvars " , control_listvars , true , " list tunable variables " } ,
{ " statistics " , control_statistics , false , " show statistics " } ,
{ " statisticsreset " , control_statistics_reset , true , " reset statistics " } ,
2008-04-22 18:55:57 +04:00
{ " ip " , control_ip , false , " show which public ip's that ctdb manages " } ,
2007-06-11 16:25:26 +04:00
{ " process-exists " , control_process_exists , true , " check if a process exists on a node " , " <pid> " } ,
{ " getdbmap " , control_getdbmap , true , " show the database map " } ,
{ " catdb " , control_catdb , true , " dump a database " , " <dbname> " } ,
{ " getmonmode " , control_getmonmode , true , " show monitoring mode " } ,
2008-03-25 00:27:38 +03:00
{ " disablemonitor " , control_disable_monmode , true , " set monitoring mode to DISABLE " } ,
{ " enablemonitor " , control_enable_monmode , true , " set monitoring mode to ACTIVE " } ,
2008-02-05 02:26:23 +03:00
{ " setdebug " , control_setdebug , true , " set debug level " , " <EMERG|ALERT|CRIT|ERR|WARNING|NOTICE|INFO|DEBUG> " } ,
2007-06-11 16:25:26 +04:00
{ " getdebug " , control_getdebug , true , " get debug level " } ,
{ " attach " , control_attach , true , " attach to a database " , " <dbname> " } ,
2008-01-22 06:22:41 +03:00
{ " dumpmemory " , control_dumpmemory , true , " dump memory map to stdout " } ,
2008-04-01 08:34:54 +04:00
{ " rddumpmemory " , control_rddumpmemory , true , " dump memory map from the recovery daemon to stdout " } ,
2007-06-11 16:25:26 +04:00
{ " getpid " , control_getpid , true , " get ctdbd process ID " } ,
{ " disable " , control_disable , true , " disable a nodes public IP " } ,
{ " enable " , control_enable , true , " enable a nodes public IP " } ,
{ " ban " , control_ban , true , " ban a node from the cluster " , " <bantime|0> " } ,
{ " unban " , control_unban , true , " unban a node from the cluster " } ,
{ " shutdown " , control_shutdown , true , " shutdown ctdbd " } ,
{ " recover " , control_recover , true , " force recovery " } ,
{ " freeze " , control_freeze , true , " freeze all databases " } ,
{ " thaw " , control_thaw , true , " thaw all databases " } ,
2007-10-08 03:47:20 +04:00
{ " isnotrecmaster " , control_isnotrecmaster , false , " check if the local node is recmaster or not " } ,
2007-07-12 02:30:04 +04:00
{ " killtcp " , kill_tcp , false , " kill a tcp connection. " , " <srcip:port> <dstip:port> " } ,
2007-10-09 05:56:09 +04:00
{ " gratiousarp " , control_gratious_arp , false , " send a gratious arp " , " <ip> <interface> " } ,
2007-07-05 02:56:02 +04:00
{ " tickle " , tickle_tcp , false , " send a tcp tickle ack " , " <srcip:port> <dstip:port> " } ,
2007-09-04 03:50:07 +04:00
{ " gettickles " , control_get_tickles , false , " get the list of tickles registered for this ip " , " <ip> " } ,
2007-08-24 09:53:41 +04:00
2007-09-04 04:14:41 +04:00
{ " regsrvid " , regsrvid , false , " register a server id " , " <pnn> <type> <id> " } ,
{ " unregsrvid " , unregsrvid , false , " unregister a server id " , " <pnn> <type> <id> " } ,
{ " chksrvid " , chksrvid , false , " check if a server id exists " , " <pnn> <type> <id> " } ,
2007-08-26 04:57:02 +04:00
{ " getsrvids " , getsrvids , false , " get a list of all server ids " } ,
2008-01-08 09:23:27 +03:00
{ " vacuum " , ctdb_vacuum , false , " vacuum the databases of empty records " , " [max_records] " } ,
{ " repack " , ctdb_repack , false , " repack all databases " , " [max_freelist] " } ,
2008-02-19 06:44:48 +03:00
{ " listnodes " , control_listnodes , false , " list all nodes in the cluster " } ,
2008-02-29 02:03:39 +03:00
{ " reloadnodes " , control_reload_nodes_file , false , " reload the nodes file and restart the transport on all nodes " } ,
{ " getreclock " , control_getreclock , false , " get the path to the reclock file " } ,
2008-03-04 04:20:23 +03:00
{ " moveip " , control_moveip , false , " move/failover an ip address to another node " , " <ip> <node> " } ,
2008-03-27 01:23:27 +03:00
{ " addip " , control_addip , false , " add a ip address to a node " , " <ip/mask> <iface> " } ,
{ " delip " , control_delip , false , " delete an ip address from a node " , " <ip> " } ,
2008-04-02 04:13:30 +04:00
{ " eventscript " , control_eventscript , false , " run the eventscript with the given parameters on a node " , " <arguments> " } ,
2007-05-29 06:16:59 +04:00
} ;
2007-05-05 05:03:10 +04:00
2007-05-29 06:16:59 +04:00
/*
show usage message
*/
static void usage ( void )
{
int i ;
printf (
" Usage: ctdb [options] <control> \n " \
" Options: \n " \
" -n <node> choose node number, or 'all' (defaults to local node) \n "
2007-06-03 13:50:51 +04:00
" -Y generate machinereadable output \n "
2007-05-29 06:16:59 +04:00
" -t <timelimit> set timelimit for control in seconds (default %u) \n " , options . timelimit ) ;
printf ( " Controls: \n " ) ;
for ( i = 0 ; i < ARRAY_SIZE ( ctdb_commands ) ; i + + ) {
2007-07-05 04:00:51 +04:00
printf ( " %-15s %-27s %s \n " ,
2007-05-29 06:16:59 +04:00
ctdb_commands [ i ] . name ,
ctdb_commands [ i ] . args ? ctdb_commands [ i ] . args : " " ,
ctdb_commands [ i ] . msg ) ;
2007-05-05 05:03:10 +04:00
}
2007-05-29 06:16:59 +04:00
exit ( 1 ) ;
2007-05-05 05:03:10 +04:00
}
2007-05-29 06:16:59 +04:00
2008-01-10 00:04:54 +03:00
static void ctdb_alarm ( int sig )
{
printf ( " Maximum runtime exceeded - exiting \n " ) ;
_exit ( 0 ) ;
}
2007-04-26 16:27:49 +04:00
/*
main program
*/
int main ( int argc , const char * argv [ ] )
{
struct ctdb_context * ctdb ;
2007-05-29 06:16:59 +04:00
char * nodestring = NULL ;
2007-04-26 16:27:49 +04:00
struct poptOption popt_options [ ] = {
POPT_AUTOHELP
POPT_CTDB_CMDLINE
2007-05-29 06:16:59 +04:00
{ " timelimit " , ' t ' , POPT_ARG_INT , & options . timelimit , 0 , " timelimit " , " integer " } ,
{ " node " , ' n ' , POPT_ARG_STRING , & nodestring , 0 , " node " , " integer|all " } ,
2007-06-03 13:50:51 +04:00
{ " machinereadable " , ' Y ' , POPT_ARG_NONE , & options . machinereadable , 0 , " enable machinereadable output " , NULL } ,
2008-01-10 00:04:54 +03:00
{ " maxruntime " , ' T ' , POPT_ARG_INT , & options . maxruntime , 0 , " die if runtime exceeds this limit (in seconds) " , " integer " } ,
2007-04-26 16:27:49 +04:00
POPT_TABLEEND
} ;
int opt ;
const char * * extra_argv ;
int extra_argc = 0 ;
2007-05-29 10:02:02 +04:00
int ret = - 1 , i ;
2007-04-26 16:27:49 +04:00
poptContext pc ;
struct event_context * ev ;
const char * control ;
2007-05-29 06:16:59 +04:00
2008-01-08 15:02:43 +03:00
setlinebuf ( stdout ) ;
2007-05-29 06:16:59 +04:00
/* set some defaults */
2008-01-10 00:04:54 +03:00
options . maxruntime = 0 ;
2007-05-29 06:16:59 +04:00
options . timelimit = 3 ;
2007-09-04 04:14:41 +04:00
options . pnn = CTDB_CURRENT_NODE ;
2007-04-26 16:27:49 +04:00
pc = poptGetContext ( argv [ 0 ] , argc , argv , popt_options , POPT_CONTEXT_KEEP_FIRST ) ;
while ( ( opt = poptGetNextOpt ( pc ) ) ! = - 1 ) {
switch ( opt ) {
default :
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Invalid option %s: %s \n " ,
2007-08-08 04:19:42 +04:00
poptBadOption ( pc , 0 ) , poptStrerror ( opt ) ) ) ;
2007-04-26 16:27:49 +04:00
exit ( 1 ) ;
}
}
/* setup the remaining options for the main program to use */
extra_argv = poptGetArgs ( pc ) ;
if ( extra_argv ) {
extra_argv + + ;
while ( extra_argv [ extra_argc ] ) extra_argc + + ;
}
if ( extra_argc < 1 ) {
usage ( ) ;
}
2008-01-10 00:04:54 +03:00
if ( options . maxruntime ! = 0 ) {
signal ( SIGALRM , ctdb_alarm ) ;
alarm ( options . maxruntime ) ;
}
2007-05-29 06:16:59 +04:00
/* setup the node number to contact */
if ( nodestring ! = NULL ) {
if ( strcmp ( nodestring , " all " ) = = 0 ) {
2007-09-04 04:14:41 +04:00
options . pnn = CTDB_BROADCAST_ALL ;
2007-05-29 06:16:59 +04:00
} else {
2007-09-04 04:14:41 +04:00
options . pnn = strtoul ( nodestring , NULL , 0 ) ;
2007-05-29 06:16:59 +04:00
}
}
2007-04-26 16:27:49 +04:00
control = extra_argv [ 0 ] ;
ev = event_context_init ( NULL ) ;
/* initialise ctdb */
ctdb = ctdb_cmdline_client ( ev ) ;
if ( ctdb = = NULL ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Failed to init ctdb \n " ) ) ;
2007-04-26 16:27:49 +04:00
exit ( 1 ) ;
}
2007-05-29 06:16:59 +04:00
for ( i = 0 ; i < ARRAY_SIZE ( ctdb_commands ) ; i + + ) {
if ( strcmp ( control , ctdb_commands [ i ] . name ) = = 0 ) {
2007-06-11 16:25:26 +04:00
int j ;
2007-09-04 04:14:41 +04:00
if ( options . pnn = = CTDB_CURRENT_NODE ) {
int pnn ;
2007-09-04 04:38:48 +04:00
pnn = ctdb_ctrl_getpnn ( ctdb , TIMELIMIT ( ) , options . pnn ) ;
2007-09-04 04:14:41 +04:00
if ( pnn = = - 1 ) {
2007-08-07 07:40:13 +04:00
return - 1 ;
}
2007-09-04 04:14:41 +04:00
options . pnn = pnn ;
2007-06-11 16:25:26 +04:00
}
if ( ctdb_commands [ i ] . auto_all & &
2007-09-04 04:14:41 +04:00
options . pnn = = CTDB_BROADCAST_ALL ) {
2007-06-11 16:25:26 +04:00
uint32_t * nodes ;
uint32_t num_nodes ;
ret = 0 ;
nodes = ctdb_get_connected_nodes ( ctdb , TIMELIMIT ( ) , ctdb , & num_nodes ) ;
CTDB_NO_MEMORY ( ctdb , nodes ) ;
for ( j = 0 ; j < num_nodes ; j + + ) {
2007-09-04 04:14:41 +04:00
options . pnn = nodes [ j ] ;
2007-06-11 16:25:26 +04:00
ret | = ctdb_commands [ i ] . fn ( ctdb , extra_argc - 1 , extra_argv + 1 ) ;
}
talloc_free ( nodes ) ;
} else {
ret = ctdb_commands [ i ] . fn ( ctdb , extra_argc - 1 , extra_argv + 1 ) ;
}
2007-05-02 07:34:55 +04:00
break ;
}
}
2007-05-29 06:16:59 +04:00
if ( i = = ARRAY_SIZE ( ctdb_commands ) ) {
2008-02-04 12:07:15 +03:00
DEBUG ( DEBUG_ERR , ( " Unknown control '%s' \n " , control ) ) ;
2007-04-26 16:27:49 +04:00
exit ( 1 ) ;
}
return ret ;
}