2007-04-26 14:27:49 +02:00
/*
ctdb_control protocol code
Copyright ( C ) Andrew Tridgell 2007
2007-05-31 13:50:53 +10: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 15:29:31 +10:00
the Free Software Foundation ; either version 3 of the License , or
2007-05-31 13:50:53 +10:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
2007-04-26 14:27:49 +02:00
but WITHOUT ANY WARRANTY ; without even the implied warranty of
2007-05-31 13:50:53 +10: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 15:29:31 +10:00
along with this program ; if not , see < http : //www.gnu.org/licenses/>.
2007-04-26 14:27:49 +02:00
*/
2015-10-26 16:50:46 +11:00
# include "replace.h"
2007-04-26 14:27:49 +02:00
# include "system/network.h"
# include "system/filesys.h"
# include "system/wait.h"
2015-10-26 16:50:46 +11:00
# include <talloc.h>
# include <tevent.h>
2014-08-15 15:46:33 +10:00
# include "lib/tdb_wrap/tdb_wrap.h"
2015-10-26 16:50:46 +11:00
# include "lib/util/dlinklist.h"
# include "lib/util/debug.h"
# include "lib/util/samba_util.h"
2015-08-16 13:19:15 +02:00
# include "lib/util/talloc_report.h"
2015-10-26 16:50:46 +11:00
# include "ctdb_private.h"
# include "ctdb_client.h"
2019-07-30 14:17:11 +10:00
# include "protocol/protocol_private.h"
2015-03-17 14:30:18 +11:00
# include "common/reqid.h"
2015-10-23 14:17:34 +11:00
# include "common/common.h"
2015-11-11 15:41:10 +11:00
# include "common/logging.h"
2007-04-26 14:27:49 +02:00
2007-08-24 15:53:41 +10:00
2007-04-26 14:27:49 +02:00
struct ctdb_control_state {
struct ctdb_context * ctdb ;
uint32_t reqid ;
ctdb_control_callback_fn_t callback ;
void * private_data ;
2007-05-17 14:10:38 +10:00
unsigned flags ;
2007-04-26 14:27:49 +02:00
} ;
2007-08-24 15:53:41 +10:00
2008-01-22 14:22:41 +11:00
/*
dump talloc memory hierarchy , returning it as a blob to the client
*/
2008-04-01 15:34:54 +11:00
int32_t ctdb_dump_memory ( struct ctdb_context * ctdb , TDB_DATA * outdata )
2008-01-22 14:22:41 +11:00
{
2015-08-16 13:19:15 +02:00
char * report ;
size_t reportlen ;
report = talloc_report_str ( outdata , NULL ) ;
if ( report = = NULL ) {
DEBUG ( DEBUG_ERR ,
( __location__ " talloc_report_str failed \n " ) ) ;
2013-11-11 12:39:27 +11:00
return - 1 ;
}
2015-08-16 13:19:15 +02:00
reportlen = talloc_get_size ( report ) ;
if ( reportlen > 0 ) {
reportlen - = 1 ; /* strip trailing zero */
2008-01-22 14:22:41 +11:00
}
2015-08-16 13:19:15 +02:00
outdata - > dptr = ( uint8_t * ) report ;
outdata - > dsize = reportlen ;
2008-01-22 14:22:41 +11:00
return 0 ;
}
2013-09-12 16:36:09 +10:00
static int32_t control_not_implemented ( const char * unsupported ,
const char * alternate )
{
if ( alternate = = NULL ) {
DEBUG ( DEBUG_ERR ,
( " Control %s is not implemented any more \n " ,
unsupported ) ) ;
} else {
DEBUG ( DEBUG_ERR ,
( " Control %s is not implemented any more, use %s instead \n " ,
unsupported , alternate ) ) ;
}
return - 1 ;
}
2008-01-22 14:22:41 +11:00
2020-03-18 11:31:14 +01:00
struct ctdb_echo_data_state {
struct ctdb_context * ctdb ;
struct ctdb_req_control_old * c ;
struct ctdb_echo_data * data ;
} ;
static void ctdb_echo_data_timeout (
struct tevent_context * ev ,
struct tevent_timer * te ,
struct timeval now ,
void * private_data ) ;
static int32_t ctdb_control_echo_data (
struct ctdb_context * ctdb ,
struct ctdb_req_control_old * c ,
TDB_DATA indata ,
bool * async_reply )
{
struct ctdb_echo_data_state * state = NULL ;
struct tevent_timer * te = NULL ;
uint32_t delay = 0 ;
size_t np = 0 ;
int ret ;
state = talloc_zero ( ctdb , struct ctdb_echo_data_state ) ;
CTDB_NO_MEMORY ( ctdb , state ) ;
state - > ctdb = ctdb ;
ret = ctdb_echo_data_pull (
indata . dptr , indata . dsize , state , & state - > data , & np ) ;
if ( ret ! = 0 ) {
DBG_DEBUG ( " ctdb_echo_data_pull failed: %s \n " ,
strerror ( ret ) ) ;
TALLOC_FREE ( state ) ;
return - 1 ;
}
te = tevent_add_timer (
ctdb - > ev ,
state ,
timeval_current_ofs_msec ( delay ) ,
ctdb_echo_data_timeout ,
state ) ;
if ( te = = NULL ) {
DBG_DEBUG ( " tevent_add_timer failed \n " ) ;
TALLOC_FREE ( state ) ;
return - 1 ;
}
state - > c = talloc_move ( state , & c ) ;
* async_reply = true ;
return 0 ;
}
static void ctdb_echo_data_timeout (
struct tevent_context * ev ,
struct tevent_timer * te ,
struct timeval now ,
void * private_data )
{
struct ctdb_echo_data_state * state = talloc_get_type_abort (
private_data , struct ctdb_echo_data_state ) ;
size_t len = ctdb_echo_data_len ( state - > data ) ;
uint8_t * buf = NULL ;
size_t np ;
TDB_DATA data ;
DBG_DEBUG ( " reqid=% " PRIu32 " len=%zu \n " , state - > c - > hdr . reqid , len ) ;
buf = talloc_array ( state , uint8_t , len ) ;
if ( buf = = NULL ) {
DBG_WARNING ( " talloc_array(%zu) failed \n " , len ) ;
goto done ;
}
ctdb_echo_data_push ( state - > data , buf , & np ) ;
data = ( TDB_DATA ) { . dptr = buf , . dsize = np } ;
ctdb_request_control_reply ( state - > ctdb , state - > c , & data , 0 , NULL ) ;
done :
TALLOC_FREE ( state ) ;
}
2021-07-09 14:12:59 +10:00
static int ctdb_control_disable_node ( struct ctdb_context * ctdb )
{
struct ctdb_node * node ;
node = ctdb_find_node ( ctdb , CTDB_CURRENT_NODE ) ;
if ( node = = NULL ) {
/* Can't happen */
DBG_ERR ( " Unable to find current node \n " ) ;
return - 1 ;
}
D_ERR ( " Disable node \n " ) ;
node - > flags | = NODE_FLAGS_PERMANENTLY_DISABLED ;
return 0 ;
}
static int ctdb_control_enable_node ( struct ctdb_context * ctdb )
{
struct ctdb_node * node ;
node = ctdb_find_node ( ctdb , CTDB_CURRENT_NODE ) ;
if ( node = = NULL ) {
/* Can't happen */
DBG_ERR ( " Unable to find current node \n " ) ;
return - 1 ;
}
D_ERR ( " Enable node \n " ) ;
node - > flags & = ~ NODE_FLAGS_PERMANENTLY_DISABLED ;
return 0 ;
}
2007-04-26 14:27:49 +02:00
/*
process a control request
*/
static int32_t ctdb_control_dispatch ( struct ctdb_context * ctdb ,
2015-10-29 16:42:05 +11:00
struct ctdb_req_control_old * c ,
2007-05-04 11:41:29 +10:00
TDB_DATA indata ,
2007-05-12 15:15:27 +10:00
TDB_DATA * outdata , uint32_t srcnode ,
2007-05-12 21:25:26 +10:00
const char * * errormsg ,
2007-05-12 15:15:27 +10:00
bool * async_reply )
2007-04-26 14:27:49 +02:00
{
2007-05-12 15:15:27 +10:00
uint32_t opcode = c - > opcode ;
uint64_t srvid = c - > srvid ;
uint32_t client_id = c - > client_id ;
2018-11-07 14:14:05 +01:00
static int level = DEBUG_ERR ;
2007-05-12 15:15:27 +10:00
2007-04-26 14:27:49 +02:00
switch ( opcode ) {
case CTDB_CONTROL_PROCESS_EXISTS : {
2007-05-05 08:11:54 +10:00
CHECK_CONTROL_DATA_SIZE ( sizeof ( pid_t ) ) ;
2009-12-02 13:58:27 +11:00
return ctdb_control_process_exists ( ctdb , * ( pid_t * ) indata . dptr ) ;
2007-04-26 14:27:49 +02:00
}
2007-04-26 19:27:07 +02:00
2007-04-27 15:14:36 +02:00
case CTDB_CONTROL_SET_DEBUG : {
2018-11-07 14:14:05 +01:00
union {
uint8_t * ptr ;
int32_t * level ;
} debug ;
2008-02-05 10:26:23 +11:00
CHECK_CONTROL_DATA_SIZE ( sizeof ( int32_t ) ) ;
2018-11-07 14:14:05 +01:00
debug . ptr = indata . dptr ;
debuglevel_set ( * debug . level ) ;
2007-04-27 15:14:36 +02:00
return 0 ;
}
case CTDB_CONTROL_GET_DEBUG : {
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
2018-11-07 14:14:05 +01:00
level = debuglevel_get ( ) ;
outdata - > dptr = ( uint8_t * ) & ( level ) ;
2014-09-24 17:12:56 +10:00
outdata - > dsize = sizeof ( DEBUGLEVEL ) ;
2007-04-27 15:14:36 +02:00
return 0 ;
}
2007-05-29 12:16:59 +10:00
case CTDB_CONTROL_STATISTICS : {
2007-04-27 14:49:44 +02:00
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
2008-01-16 09:44:48 +11:00
ctdb - > statistics . memory_used = talloc_total_size ( NULL ) ;
2013-04-19 13:29:04 +10:00
ctdb - > statistics . num_clients = ctdb - > num_clients ;
2014-08-21 12:32:02 +10:00
ctdb - > statistics . frozen = ( ctdb_db_all_frozen ( ctdb ) ? 1 : 0 ) ;
2007-05-29 12:16:59 +10:00
ctdb - > statistics . recovering = ( ctdb - > recovery_mode = = CTDB_RECOVERY_ACTIVE ) ;
2010-06-02 13:13:09 +10:00
ctdb - > statistics . statistics_current_time = timeval_current ( ) ;
2007-05-29 12:16:59 +10:00
outdata - > dptr = ( uint8_t * ) & ctdb - > statistics ;
outdata - > dsize = sizeof ( ctdb - > statistics ) ;
2007-04-26 14:51:41 +02:00
return 0 ;
}
2007-04-26 19:27:07 +02:00
2007-06-07 18:05:25 +10:00
case CTDB_CONTROL_GET_ALL_TUNABLES : {
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
outdata - > dptr = ( uint8_t * ) & ctdb - > tunable ;
outdata - > dsize = sizeof ( ctdb - > tunable ) ;
return 0 ;
}
2007-05-05 11:03:10 +10:00
case CTDB_CONTROL_DUMP_MEMORY : {
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
2008-01-22 14:22:41 +11:00
return ctdb_dump_memory ( ctdb , outdata ) ;
2007-05-05 11:03:10 +10:00
}
2007-05-29 12:16:59 +10:00
case CTDB_CONTROL_STATISTICS_RESET : {
2015-04-02 13:53:09 +11:00
struct ctdb_db_context * ctdb_db ;
2007-04-28 19:13:36 +02:00
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
2007-05-29 12:16:59 +10:00
ZERO_STRUCT ( ctdb - > statistics ) ;
2015-04-02 13:53:09 +11:00
for ( ctdb_db = ctdb - > db_list ;
ctdb_db ! = NULL ;
ctdb_db = ctdb_db - > next ) {
ctdb_db_statistics_reset ( ctdb_db ) ;
}
2010-06-02 13:13:09 +10:00
ctdb - > statistics . statistics_start_time = timeval_current ( ) ;
2007-04-28 19:13:36 +02:00
return 0 ;
}
2007-05-03 11:06:24 +10:00
case CTDB_CONTROL_GETVNNMAP :
return ctdb_control_getvnnmap ( ctdb , opcode , indata , outdata ) ;
2007-04-27 20:56:10 +10:00
2007-05-03 13:07:34 +10:00
case CTDB_CONTROL_GET_DBMAP :
return ctdb_control_getdbmap ( ctdb , opcode , indata , outdata ) ;
2007-04-28 20:00:50 +10:00
2008-10-14 10:40:29 +11:00
case CTDB_CONTROL_GET_NODEMAPv4 :
2015-03-23 17:06:31 +11:00
return control_not_implemented ( " GET_NODEMAPv4 " , " GET_NODEMAP " ) ;
2008-10-14 10:40:29 +11:00
2007-05-03 13:30:38 +10:00
case CTDB_CONTROL_GET_NODEMAP :
return ctdb_control_getnodemap ( ctdb , opcode , indata , outdata ) ;
2007-04-28 20:40:26 +10:00
2015-02-20 21:19:01 +11:00
case CTDB_CONTROL_GET_NODES_FILE :
return ctdb_control_getnodesfile ( ctdb , opcode , indata , outdata ) ;
2008-02-19 14:44:48 +11:00
case CTDB_CONTROL_RELOAD_NODES_FILE :
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
return ctdb_control_reload_nodes_file ( ctdb , opcode ) ;
2012-03-20 16:58:35 +11:00
case CTDB_CONTROL_SET_DB_STICKY : {
uint32_t db_id ;
struct ctdb_db_context * ctdb_db ;
CHECK_CONTROL_DATA_SIZE ( sizeof ( db_id ) ) ;
db_id = * ( uint32_t * ) indata . dptr ;
ctdb_db = find_ctdb_db ( ctdb , db_id ) ;
if ( ctdb_db = = NULL ) return - 1 ;
return ctdb_set_db_sticky ( ctdb , ctdb_db ) ;
}
2007-05-03 11:06:24 +10:00
case CTDB_CONTROL_SETVNNMAP :
return ctdb_control_setvnnmap ( ctdb , opcode , indata , outdata ) ;
2007-04-27 22:08:12 +10:00
2020-08-06 21:35:14 +10:00
case CTDB_CONTROL_PULL_DB :
return control_not_implemented ( " PULL_DB " , NULL ) ;
2007-04-29 05:47:13 +10:00
2007-05-10 17:43:45 +10:00
case CTDB_CONTROL_SET_DMASTER :
2013-09-12 16:36:09 +10:00
return control_not_implemented ( " SET_DMASTER " , NULL ) ;
2007-04-29 05:47:13 +10:00
2007-05-10 17:43:45 +10:00
case CTDB_CONTROL_PUSH_DB :
2020-08-06 21:35:14 +10:00
return control_not_implemented ( " PUSH_DB " , NULL ) ;
2007-05-02 21:00:02 +10:00
2007-04-29 22:51:56 +10:00
case CTDB_CONTROL_GET_RECMODE : {
2014-05-06 14:07:00 +10:00
return ctdb - > recovery_mode ;
2007-04-29 22:51:56 +10:00
}
2020-05-06 00:01:05 +10:00
case CTDB_CONTROL_SET_RECMASTER :
return control_not_implemented ( " SET_RECMASTER " , NULL ) ;
2007-05-07 05:02:48 +10:00
2007-05-15 10:17:16 +10:00
case CTDB_CONTROL_GET_RECMASTER :
2020-05-06 00:01:05 +10:00
return control_not_implemented ( " GET_RECMASTER " , NULL ) ;
2007-05-07 05:02:48 +10:00
2007-05-15 10:17:16 +10:00
case CTDB_CONTROL_GET_PID :
2007-05-06 08:05:22 +10:00
return getpid ( ) ;
2007-05-15 10:17:16 +10:00
2007-09-04 10:38:48 +10:00
case CTDB_CONTROL_GET_PNN :
2007-09-04 10:06:36 +10:00
return ctdb - > pnn ;
2007-05-06 04:31:22 +10:00
2007-04-26 19:27:07 +02:00
case CTDB_CONTROL_PING :
2007-04-27 14:49:44 +02:00
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
2013-04-19 13:29:04 +10:00
return ctdb - > num_clients ;
2007-04-26 19:27:07 +02:00
2013-05-21 16:18:28 +10:00
case CTDB_CONTROL_GET_RUNSTATE :
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
outdata - > dptr = ( uint8_t * ) & ctdb - > runstate ;
outdata - > dsize = sizeof ( uint32_t ) ;
return 0 ;
2011-09-01 11:08:18 +10:00
case CTDB_CONTROL_SET_DB_READONLY : {
uint32_t db_id ;
struct ctdb_db_context * ctdb_db ;
CHECK_CONTROL_DATA_SIZE ( sizeof ( db_id ) ) ;
db_id = * ( uint32_t * ) indata . dptr ;
ctdb_db = find_ctdb_db ( ctdb , db_id ) ;
if ( ctdb_db = = NULL ) return - 1 ;
return ctdb_set_db_readonly ( ctdb , ctdb_db ) ;
}
2007-05-04 15:21:40 +10:00
case CTDB_CONTROL_GET_DBNAME : {
uint32_t db_id ;
struct ctdb_db_context * ctdb_db ;
CHECK_CONTROL_DATA_SIZE ( sizeof ( db_id ) ) ;
db_id = * ( uint32_t * ) indata . dptr ;
ctdb_db = find_ctdb_db ( ctdb , db_id ) ;
if ( ctdb_db = = NULL ) return - 1 ;
outdata - > dptr = discard_const ( ctdb_db - > db_name ) ;
outdata - > dsize = strlen ( ctdb_db - > db_name ) + 1 ;
return 0 ;
}
2007-04-26 23:10:35 +02:00
case CTDB_CONTROL_GETDBPATH : {
uint32_t db_id ;
struct ctdb_db_context * ctdb_db ;
2007-04-27 15:14:36 +02:00
CHECK_CONTROL_DATA_SIZE ( sizeof ( db_id ) ) ;
2007-04-26 23:10:35 +02:00
db_id = * ( uint32_t * ) indata . dptr ;
ctdb_db = find_ctdb_db ( ctdb , db_id ) ;
if ( ctdb_db = = NULL ) return - 1 ;
outdata - > dptr = discard_const ( ctdb_db - > db_path ) ;
2007-04-26 23:29:26 +02:00
outdata - > dsize = strlen ( ctdb_db - > db_path ) + 1 ;
2007-04-26 23:10:35 +02:00
return 0 ;
}
2007-04-30 15:31:40 +02:00
case CTDB_CONTROL_DB_ATTACH :
2018-06-26 20:12:23 +10:00
return ctdb_control_db_attach ( ctdb ,
indata ,
outdata ,
0 ,
srcnode ,
client_id ,
c ,
async_reply ) ;
2007-09-21 12:24:02 +10:00
case CTDB_CONTROL_DB_ATTACH_PERSISTENT :
2018-06-26 20:12:23 +10:00
return ctdb_control_db_attach ( ctdb ,
indata ,
outdata ,
CTDB_DB_FLAGS_PERSISTENT ,
srcnode ,
client_id ,
c ,
async_reply ) ;
2007-04-30 15:31:40 +02:00
2017-03-02 16:38:58 +11:00
case CTDB_CONTROL_DB_ATTACH_REPLICATED :
2018-06-26 20:12:23 +10:00
return ctdb_control_db_attach ( ctdb ,
indata ,
outdata ,
CTDB_DB_FLAGS_REPLICATED ,
srcnode ,
client_id ,
c ,
async_reply ) ;
2017-03-02 16:38:58 +11:00
2015-07-09 22:33:23 +10:00
case CTDB_CONTROL_SET_CALL :
return control_not_implemented ( " SET_CALL " , NULL ) ;
2007-04-30 15:31:40 +02:00
2007-05-03 17:12:23 +10:00
case CTDB_CONTROL_TRAVERSE_START :
CHECK_CONTROL_DATA_SIZE ( sizeof ( struct ctdb_traverse_start ) ) ;
2009-05-06 07:32:25 +10:00
return ctdb_control_traverse_start ( ctdb , indata , outdata , srcnode , client_id ) ;
2007-05-03 17:12:23 +10:00
2011-12-03 02:15:30 +01:00
case CTDB_CONTROL_TRAVERSE_START_EXT :
CHECK_CONTROL_DATA_SIZE ( sizeof ( struct ctdb_traverse_start_ext ) ) ;
return ctdb_control_traverse_start_ext ( ctdb , indata , outdata , srcnode , client_id ) ;
2007-05-03 17:12:23 +10:00
case CTDB_CONTROL_TRAVERSE_ALL :
return ctdb_control_traverse_all ( ctdb , indata , outdata ) ;
2013-04-11 13:18:36 +10:00
case CTDB_CONTROL_TRAVERSE_ALL_EXT :
return ctdb_control_traverse_all_ext ( ctdb , indata , outdata ) ;
2007-05-03 17:12:23 +10:00
case CTDB_CONTROL_TRAVERSE_DATA :
return ctdb_control_traverse_data ( ctdb , indata , outdata ) ;
2009-05-06 07:32:25 +10:00
case CTDB_CONTROL_TRAVERSE_KILL :
CHECK_CONTROL_DATA_SIZE ( sizeof ( struct ctdb_traverse_start ) ) ;
return ctdb_control_traverse_kill ( ctdb , indata , outdata , srcnode ) ;
2007-05-04 11:41:29 +10:00
case CTDB_CONTROL_REGISTER_SRVID :
return daemon_register_message_handler ( ctdb , client_id , srvid ) ;
case CTDB_CONTROL_DEREGISTER_SRVID :
return daemon_deregister_message_handler ( ctdb , client_id , srvid ) ;
2011-10-31 13:29:13 +01:00
case CTDB_CONTROL_CHECK_SRVIDS :
2017-08-10 14:50:02 +10:00
return control_not_implemented ( " CHECK_SRVIDS " , NULL ) ;
2011-10-31 13:29:13 +01:00
2007-05-04 22:18:00 +10:00
case CTDB_CONTROL_ENABLE_SEQNUM :
CHECK_CONTROL_DATA_SIZE ( sizeof ( uint32_t ) ) ;
return ctdb_ltdb_enable_seqnum ( ctdb , * ( uint32_t * ) indata . dptr ) ;
case CTDB_CONTROL_UPDATE_SEQNUM :
CHECK_CONTROL_DATA_SIZE ( sizeof ( uint32_t ) ) ;
return ctdb_ltdb_update_seqnum ( ctdb , * ( uint32_t * ) indata . dptr , srcnode ) ;
2007-05-12 15:15:27 +10:00
case CTDB_CONTROL_FREEZE :
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
return ctdb_control_freeze ( ctdb , c , async_reply ) ;
case CTDB_CONTROL_THAW :
2016-07-21 14:17:02 +10:00
return control_not_implemented ( " THAW " , NULL ) ;
2007-05-12 15:15:27 +10:00
case CTDB_CONTROL_SET_RECMODE :
CHECK_CONTROL_DATA_SIZE ( sizeof ( uint32_t ) ) ;
2007-06-02 08:41:19 +10:00
return ctdb_control_set_recmode ( ctdb , c , indata , async_reply , errormsg ) ;
2007-05-12 15:15:27 +10:00
2017-09-04 14:22:44 +10:00
case CTDB_CONTROL_GET_MONMODE :
return control_not_implemented ( " GET_MONMODE " , NULL ) ;
case CTDB_CONTROL_ENABLE_MONITOR :
return control_not_implemented ( " ENABLE_MONITOR " , NULL ) ;
2016-09-12 11:25:11 +10:00
case CTDB_CONTROL_RUN_EVENTSCRIPTS :
return control_not_implemented ( " RUN_EVENTSCRIPTS " , NULL ) ;
2008-04-02 11:13:30 +11:00
2017-09-04 14:22:44 +10:00
case CTDB_CONTROL_DISABLE_MONITOR :
return control_not_implemented ( " DISABLE_MONITOR " , NULL ) ;
2007-05-21 09:24:34 +10:00
2007-05-17 10:45:31 +10:00
case CTDB_CONTROL_SHUTDOWN :
2013-06-19 10:58:14 +10:00
DEBUG ( DEBUG_NOTICE , ( " Received SHUTDOWN command. \n " ) ) ;
ctdb_shutdown_sequence ( ctdb , 0 ) ;
2013-06-22 15:44:28 +10:00
/* In case above returns due to duplicate shutdown */
return 0 ;
2007-05-17 10:45:31 +10:00
2008-10-14 10:40:29 +11:00
case CTDB_CONTROL_TAKEOVER_IPv4 :
2015-03-23 17:06:31 +11:00
return control_not_implemented ( " TAKEOVER_IPv4 " , " TAKEOVER_IP " ) ;
2008-10-14 10:40:29 +11:00
2007-05-25 13:05:25 +10:00
case CTDB_CONTROL_TAKEOVER_IP :
2007-06-04 20:07:37 +10:00
CHECK_CONTROL_DATA_SIZE ( sizeof ( struct ctdb_public_ip ) ) ;
2007-06-01 19:05:41 +10:00
return ctdb_control_takeover_ip ( ctdb , c , indata , async_reply ) ;
2007-05-25 13:05:25 +10:00
2008-10-14 10:40:29 +11:00
case CTDB_CONTROL_RELEASE_IPv4 :
2015-03-23 17:06:31 +11:00
return control_not_implemented ( " RELEASE_IPv4 " , " RELEASE_IP " ) ;
2008-10-14 10:40:29 +11:00
2007-05-25 13:05:25 +10:00
case CTDB_CONTROL_RELEASE_IP :
2007-06-04 20:07:37 +10:00
CHECK_CONTROL_DATA_SIZE ( sizeof ( struct ctdb_public_ip ) ) ;
2007-06-01 19:05:41 +10:00
return ctdb_control_release_ip ( ctdb , c , indata , async_reply ) ;
2007-05-25 13:05:25 +10:00
2013-04-19 13:05:02 +10:00
case CTDB_CONTROL_IPREALLOCATED :
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
return ctdb_control_ipreallocated ( ctdb , c , async_reply ) ;
2008-10-14 10:40:29 +11:00
case CTDB_CONTROL_GET_PUBLIC_IPSv4 :
2015-03-23 17:06:31 +11:00
return control_not_implemented ( " GET_PUBLIC_IPSv4 " ,
" GET_PUBLIC_IPS " ) ;
2008-10-14 10:40:29 +11:00
2007-06-04 21:11:51 +10:00
case CTDB_CONTROL_GET_PUBLIC_IPS :
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
return ctdb_control_get_public_ips ( ctdb , c , outdata ) ;
2015-03-23 17:32:34 +11:00
case CTDB_CONTROL_TCP_CLIENT :
2015-10-29 14:25:34 +11:00
CHECK_CONTROL_DATA_SIZE ( sizeof ( struct ctdb_connection ) ) ;
2007-07-20 10:06:41 +10:00
return ctdb_control_tcp_client ( ctdb , client_id , indata ) ;
2007-05-28 00:34:40 +10:00
case CTDB_CONTROL_STARTUP :
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
return ctdb_control_startup ( ctdb , srcnode ) ;
2007-05-27 15:26:29 +10:00
case CTDB_CONTROL_TCP_ADD :
2015-10-28 18:14:21 +11:00
CHECK_CONTROL_DATA_SIZE ( sizeof ( struct ctdb_connection ) ) ;
2010-08-18 12:36:03 +10:00
return ctdb_control_tcp_add ( ctdb , indata , false ) ;
case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE :
2015-10-28 18:14:21 +11:00
CHECK_CONTROL_DATA_SIZE ( sizeof ( struct ctdb_connection ) ) ;
2010-08-18 12:36:03 +10:00
return ctdb_control_tcp_add ( ctdb , indata , true ) ;
case CTDB_CONTROL_TCP_REMOVE :
2015-10-28 18:14:21 +11:00
CHECK_CONTROL_DATA_SIZE ( sizeof ( struct ctdb_connection ) ) ;
2010-08-18 12:36:03 +10:00
return ctdb_control_tcp_remove ( ctdb , indata ) ;
2007-05-27 15:26:29 +10:00
2007-06-04 19:53:19 +10:00
case CTDB_CONTROL_SET_TUNABLE :
return ctdb_control_set_tunable ( ctdb , indata ) ;
case CTDB_CONTROL_GET_TUNABLE :
return ctdb_control_get_tunable ( ctdb , indata , outdata ) ;
case CTDB_CONTROL_LIST_TUNABLES :
return ctdb_control_list_tunables ( ctdb , outdata ) ;
2007-06-07 15:18:55 +10:00
case CTDB_CONTROL_MODIFY_FLAGS :
2008-11-19 14:43:46 +11:00
CHECK_CONTROL_DATA_SIZE ( sizeof ( struct ctdb_node_flag_change ) ) ;
2007-06-07 15:18:55 +10:00
return ctdb_control_modflags ( ctdb , indata ) ;
2007-06-07 09:16:17 +10:00
2016-03-11 15:57:44 +11:00
case CTDB_CONTROL_KILL_TCP :
return control_not_implemented ( " KILL_TCP " , NULL ) ;
2007-07-11 18:24:25 +10:00
2007-07-20 15:05:55 +10:00
case CTDB_CONTROL_GET_TCP_TICKLE_LIST :
2008-08-19 14:58:29 +10:00
CHECK_CONTROL_DATA_SIZE ( sizeof ( ctdb_sock_addr ) ) ;
2007-07-20 15:05:55 +10:00
return ctdb_control_get_tcp_tickle_list ( ctdb , indata , outdata ) ;
case CTDB_CONTROL_SET_TCP_TICKLE_LIST :
2007-07-20 10:06:41 +10:00
/* data size is verified in the called function */
2007-07-20 15:05:55 +10:00
return ctdb_control_set_tcp_tickle_list ( ctdb , indata ) ;
2007-07-20 10:06:41 +10:00
2016-04-21 15:18:33 +10:00
case CTDB_CONTROL_REGISTER_SERVER_ID :
return control_not_implemented ( " REGISTER_SERVER_ID " , NULL ) ;
2007-08-24 15:53:41 +10:00
2016-04-21 15:18:33 +10:00
case CTDB_CONTROL_UNREGISTER_SERVER_ID :
return control_not_implemented ( " UNREGISTER_SERVER_ID " , NULL ) ;
2007-08-24 15:53:41 +10:00
2016-04-21 15:18:33 +10:00
case CTDB_CONTROL_CHECK_SERVER_ID :
return control_not_implemented ( " CHECK_SERVER_ID " , NULL ) ;
2007-08-24 15:53:41 +10:00
2007-08-26 10:57:02 +10:00
case CTDB_CONTROL_GET_SERVER_ID_LIST :
2016-04-21 15:18:33 +10:00
return control_not_implemented ( " SERVER_ID_LIST " , NULL ) ;
2007-08-26 10:57:02 +10:00
2007-09-21 12:24:02 +10:00
case CTDB_CONTROL_PERSISTENT_STORE :
2013-09-12 16:27:39 +10:00
return control_not_implemented ( " PERSISTENT_STORE " , NULL ) ;
2007-09-21 12:24:02 +10:00
case CTDB_CONTROL_UPDATE_RECORD :
return ctdb_control_update_record ( ctdb , c , indata , async_reply ) ;
2015-10-29 17:51:52 +11:00
case CTDB_CONTROL_SEND_GRATUITOUS_ARP :
2007-10-09 11:56:09 +10:00
return ctdb_control_send_gratious_arp ( ctdb , indata ) ;
2008-01-06 12:38:01 +11:00
case CTDB_CONTROL_TRANSACTION_START :
2016-07-25 15:41:34 +10:00
return control_not_implemented ( " TRANSACTION_START " , NULL ) ;
2008-01-06 12:38:01 +11:00
case CTDB_CONTROL_TRANSACTION_COMMIT :
2016-07-25 15:41:34 +10:00
return control_not_implemented ( " TRANSACTION_COMMIT " , NULL ) ;
2008-01-06 12:38:01 +11:00
case CTDB_CONTROL_WIPE_DATABASE :
2015-10-28 19:22:23 +11:00
CHECK_CONTROL_DATA_SIZE ( sizeof ( struct ctdb_transdb ) ) ;
2008-01-06 12:38:01 +11:00
return ctdb_control_wipe_database ( ctdb , indata ) ;
2008-01-17 11:33:23 +11:00
case CTDB_CONTROL_UPTIME :
return ctdb_control_uptime ( ctdb , outdata ) ;
2008-01-29 13:59:28 +11:00
case CTDB_CONTROL_START_RECOVERY :
return ctdb_control_start_recovery ( ctdb , c , async_reply ) ;
case CTDB_CONTROL_END_RECOVERY :
return ctdb_control_end_recovery ( ctdb , c , async_reply ) ;
2008-02-29 10:03:39 +11:00
2008-03-13 07:53:29 +11:00
case CTDB_CONTROL_TRY_DELETE_RECORDS :
return ctdb_control_try_delete_records ( ctdb , indata , outdata ) ;
2008-03-27 09:23:27 +11:00
case CTDB_CONTROL_ADD_PUBLIC_IP :
return ctdb_control_add_public_address ( ctdb , indata ) ;
case CTDB_CONTROL_DEL_PUBLIC_IP :
2014-01-22 17:12:09 +11:00
return ctdb_control_del_public_address ( ctdb , indata ) ;
2008-03-27 09:23:27 +11:00
2008-05-06 10:02:27 +10:00
case CTDB_CONTROL_GET_CAPABILITIES :
2008-05-06 15:42:59 +10:00
return ctdb_control_get_capabilities ( ctdb , outdata ) ;
2008-05-06 10:02:27 +10:00
2008-07-17 13:50:55 +10:00
case CTDB_CONTROL_START_PERSISTENT_UPDATE :
return ctdb_control_start_persistent_update ( ctdb , c , indata ) ;
case CTDB_CONTROL_CANCEL_PERSISTENT_UPDATE :
return ctdb_control_cancel_persistent_update ( ctdb , c , indata ) ;
2008-07-30 19:57:00 +10:00
case CTDB_CONTROL_TRANS2_COMMIT :
2008-08-08 13:11:28 +10:00
case CTDB_CONTROL_TRANS2_COMMIT_RETRY :
2013-09-12 16:27:39 +10:00
return control_not_implemented ( " TRANS2_COMMIT " , " TRANS3_COMMIT " ) ;
2008-07-30 19:57:00 +10:00
case CTDB_CONTROL_TRANS2_ERROR :
2013-09-12 16:27:39 +10:00
return control_not_implemented ( " TRANS2_ERROR " , NULL ) ;
2008-07-30 19:57:00 +10:00
case CTDB_CONTROL_TRANS2_FINISHED :
2013-09-12 16:27:39 +10:00
return control_not_implemented ( " TRANS2_FINISHED " , NULL ) ;
2008-07-30 19:57:00 +10:00
2009-10-29 10:49:00 +11:00
case CTDB_CONTROL_TRANS2_ACTIVE :
2013-09-12 16:27:39 +10:00
return control_not_implemented ( " TRANS2_ACTIVE " , NULL ) ;
2009-10-29 10:49:00 +11:00
2009-12-03 17:59:49 +01:00
case CTDB_CONTROL_TRANS3_COMMIT :
return ctdb_control_trans3_commit ( ctdb , c , indata , async_reply ) ;
2008-09-09 13:44:46 +10:00
case CTDB_CONTROL_RECD_PING :
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
return ctdb_control_recd_ping ( ctdb ) ;
2009-03-23 19:07:45 +11:00
case CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS :
2016-09-12 11:25:11 +10:00
return control_not_implemented ( " GET_EVENT_SCRIPT_STATUS " , NULL ) ;
2009-03-23 19:07:45 +11:00
2009-05-14 10:33:25 +10:00
case CTDB_CONTROL_RECD_RECLOCK_LATENCY :
CHECK_CONTROL_DATA_SIZE ( sizeof ( double ) ) ;
2010-09-29 10:38:41 +10:00
CTDB_UPDATE_RECLOCK_LATENCY ( ctdb , " recd reclock " , reclock . recd , * ( ( double * ) indata . dptr ) ) ;
2009-05-14 10:33:25 +10:00
return 0 ;
2009-06-25 12:17:19 +10:00
case CTDB_CONTROL_GET_RECLOCK_FILE :
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
2016-05-17 18:28:56 +10:00
if ( ctdb - > recovery_lock ! = NULL ) {
outdata - > dptr = discard_const ( ctdb - > recovery_lock ) ;
outdata - > dsize = strlen ( ctdb - > recovery_lock ) + 1 ;
2009-06-25 12:17:19 +10:00
}
return 0 ;
2016-04-05 16:13:43 +10:00
case CTDB_CONTROL_SET_RECLOCK_FILE :
return control_not_implemented ( " SET_RECLOCK " , NULL ) ;
2009-10-12 18:31:59 +11:00
2009-07-09 12:22:46 +10:00
case CTDB_CONTROL_STOP_NODE :
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
2013-02-21 14:28:13 +11:00
return ctdb_control_stop_node ( ctdb ) ;
2009-07-09 12:22:46 +10:00
case CTDB_CONTROL_CONTINUE_NODE :
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
return ctdb_control_continue_node ( ctdb ) ;
2016-01-05 16:02:09 +11:00
case CTDB_CONTROL_SET_NATGWSTATE :
return control_not_implemented ( " SET_NATGWSTATE " , NULL ) ;
2009-07-28 09:58:11 +10:00
2009-07-28 13:45:13 +10:00
case CTDB_CONTROL_SET_LMASTERROLE : {
uint32_t lmasterrole ;
CHECK_CONTROL_DATA_SIZE ( sizeof ( uint32_t ) ) ;
lmasterrole = * ( uint32_t * ) indata . dptr ;
if ( lmasterrole = = 0 ) {
ctdb - > capabilities & = ~ CTDB_CAP_LMASTER ;
} else {
ctdb - > capabilities | = CTDB_CAP_LMASTER ;
}
return 0 ;
}
case CTDB_CONTROL_SET_RECMASTERROLE : {
uint32_t recmasterrole ;
CHECK_CONTROL_DATA_SIZE ( sizeof ( uint32_t ) ) ;
recmasterrole = * ( uint32_t * ) indata . dptr ;
if ( recmasterrole = = 0 ) {
ctdb - > capabilities & = ~ CTDB_CAP_RECMASTER ;
} else {
ctdb - > capabilities | = CTDB_CAP_RECMASTER ;
}
return 0 ;
}
2009-08-13 13:04:08 +10:00
case CTDB_CONTROL_ENABLE_SCRIPT :
2016-09-12 11:25:11 +10:00
return control_not_implemented ( " ENABLE_SCRIPT " , NULL ) ;
2009-08-13 13:04:08 +10:00
case CTDB_CONTROL_DISABLE_SCRIPT :
2016-09-12 11:25:11 +10:00
return control_not_implemented ( " DISABLE_SCRIPT " , NULL ) ;
2009-08-13 13:04:08 +10:00
2009-09-04 02:20:39 +10:00
case CTDB_CONTROL_SET_BAN_STATE :
2015-10-28 18:18:33 +11:00
CHECK_CONTROL_DATA_SIZE ( sizeof ( struct ctdb_ban_state ) ) ;
2009-09-04 02:20:39 +10:00
return ctdb_control_set_ban_state ( ctdb , indata ) ;
case CTDB_CONTROL_GET_BAN_STATE :
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
return ctdb_control_get_ban_state ( ctdb , outdata ) ;
2009-10-10 14:26:09 +11:00
case CTDB_CONTROL_SET_DB_PRIORITY :
2016-07-28 12:02:25 +10:00
return control_not_implemented ( " SET_DB_PRIORITY " , NULL ) ;
2009-10-10 14:26:09 +11:00
2016-07-19 17:34:03 +10:00
case CTDB_CONTROL_GET_DB_PRIORITY :
2016-07-28 12:02:25 +10:00
return control_not_implemented ( " GET_DB_PRIORITY " , NULL ) ;
2009-10-10 15:04:18 +11:00
2009-10-12 18:31:59 +11:00
case CTDB_CONTROL_TRANSACTION_CANCEL :
2016-07-25 15:41:34 +10:00
return control_not_implemented ( " TRANSACTION_CANCEL " , NULL ) ;
2009-10-12 18:31:59 +11:00
2009-10-23 15:24:51 +11:00
case CTDB_CONTROL_REGISTER_NOTIFY :
return ctdb_control_register_notify ( ctdb , client_id , indata ) ;
case CTDB_CONTROL_DEREGISTER_NOTIFY :
2015-10-28 17:47:03 +11:00
CHECK_CONTROL_DATA_SIZE ( sizeof ( uint64_t ) ) ;
2009-10-23 15:24:51 +11:00
return ctdb_control_deregister_notify ( ctdb , client_id , indata ) ;
2009-11-18 12:44:18 +11:00
case CTDB_CONTROL_GET_LOG :
2014-08-08 12:51:03 +10:00
return control_not_implemented ( " GET_LOG " , NULL ) ;
2009-11-18 12:44:18 +11:00
case CTDB_CONTROL_CLEAR_LOG :
2014-08-08 12:51:03 +10:00
return control_not_implemented ( " CLEAR_LOG " , NULL ) ;
2009-11-18 12:44:18 +11:00
2009-12-11 15:31:02 +01:00
case CTDB_CONTROL_GET_DB_SEQNUM :
CHECK_CONTROL_DATA_SIZE ( sizeof ( uint64_t ) ) ;
return ctdb_control_get_db_seqnum ( ctdb , indata , outdata ) ;
2009-12-02 12:48:22 +01:00
case CTDB_CONTROL_DB_SET_HEALTHY :
CHECK_CONTROL_DATA_SIZE ( sizeof ( uint32_t ) ) ;
return ctdb_control_db_set_healthy ( ctdb , indata ) ;
case CTDB_CONTROL_DB_GET_HEALTH :
CHECK_CONTROL_DATA_SIZE ( sizeof ( uint32_t ) ) ;
return ctdb_control_db_get_health ( ctdb , indata , outdata ) ;
2009-12-16 14:40:21 +01:00
case CTDB_CONTROL_GET_PUBLIC_IP_INFO :
CHECK_CONTROL_DATA_SIZE ( sizeof ( ctdb_sock_addr ) ) ;
return ctdb_control_get_public_ip_info ( ctdb , c , indata , outdata ) ;
case CTDB_CONTROL_GET_IFACES :
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
return ctdb_control_get_ifaces ( ctdb , c , outdata ) ;
case CTDB_CONTROL_SET_IFACE_LINK_STATE :
2015-10-28 19:37:17 +11:00
CHECK_CONTROL_DATA_SIZE ( sizeof ( struct ctdb_iface ) ) ;
2009-12-16 14:40:21 +01:00
return ctdb_control_set_iface_link ( ctdb , c , indata ) ;
2010-09-29 12:13:05 +10:00
case CTDB_CONTROL_GET_STAT_HISTORY :
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
return ctdb_control_get_stat_history ( ctdb , c , outdata ) ;
2010-12-21 14:25:48 +01:00
case CTDB_CONTROL_SCHEDULE_FOR_DELETION : {
struct ctdb_control_schedule_for_deletion * d ;
size_t size = offsetof ( struct ctdb_control_schedule_for_deletion , key ) ;
CHECK_CONTROL_MIN_DATA_SIZE ( size ) ;
d = ( struct ctdb_control_schedule_for_deletion * ) indata . dptr ;
size + = d - > keylen ;
CHECK_CONTROL_DATA_SIZE ( size ) ;
return ctdb_control_schedule_for_deletion ( ctdb , indata ) ;
}
2013-07-15 14:52:07 +10:00
case CTDB_CONTROL_GET_DB_STATISTICS :
CHECK_CONTROL_DATA_SIZE ( sizeof ( uint32_t ) ) ;
return ctdb_control_get_db_statistics ( ctdb , * ( uint32_t * ) indata . dptr , outdata ) ;
2012-02-08 15:29:27 +11:00
2012-04-30 15:50:44 +10:00
case CTDB_CONTROL_RELOAD_PUBLIC_IPS :
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
return ctdb_control_reload_public_ips ( ctdb , c , async_reply ) ;
2012-12-21 00:24:47 +01:00
case CTDB_CONTROL_RECEIVE_RECORDS :
2018-02-15 12:04:32 +11:00
return control_not_implemented ( " RECEIVE_RECORDS " , NULL ) ;
2012-12-21 00:24:47 +01:00
2014-03-31 15:44:21 +11:00
case CTDB_CONTROL_DB_DETACH :
return ctdb_control_db_detach ( ctdb , indata , client_id ) ;
2014-08-05 14:16:29 +10:00
case CTDB_CONTROL_DB_FREEZE :
CHECK_CONTROL_DATA_SIZE ( sizeof ( uint32_t ) ) ;
return ctdb_control_db_freeze ( ctdb , c , * ( uint32_t * ) indata . dptr ,
async_reply ) ;
case CTDB_CONTROL_DB_THAW :
CHECK_CONTROL_DATA_SIZE ( sizeof ( uint32_t ) ) ;
return ctdb_control_db_thaw ( ctdb , * ( uint32_t * ) indata . dptr ) ;
2015-09-09 15:38:36 +10:00
case CTDB_CONTROL_DB_TRANSACTION_START :
2015-10-28 19:22:23 +11:00
CHECK_CONTROL_DATA_SIZE ( sizeof ( struct ctdb_transdb ) ) ;
2015-09-09 15:38:36 +10:00
return ctdb_control_db_transaction_start ( ctdb , indata ) ;
case CTDB_CONTROL_DB_TRANSACTION_COMMIT :
2015-10-28 19:22:23 +11:00
CHECK_CONTROL_DATA_SIZE ( sizeof ( struct ctdb_transdb ) ) ;
2015-09-09 15:38:36 +10:00
return ctdb_control_db_transaction_commit ( ctdb , indata ) ;
case CTDB_CONTROL_DB_TRANSACTION_CANCEL :
CHECK_CONTROL_DATA_SIZE ( sizeof ( uint32_t ) ) ;
return ctdb_control_db_transaction_cancel ( ctdb , indata ) ;
2016-02-19 17:32:09 +11:00
case CTDB_CONTROL_DB_PULL :
CHECK_CONTROL_DATA_SIZE ( sizeof ( struct ctdb_pulldb_ext ) ) ;
return ctdb_control_db_pull ( ctdb , c , indata , outdata ) ;
case CTDB_CONTROL_DB_PUSH_START :
CHECK_CONTROL_DATA_SIZE ( sizeof ( struct ctdb_pulldb_ext ) ) ;
return ctdb_control_db_push_start ( ctdb , indata ) ;
case CTDB_CONTROL_DB_PUSH_CONFIRM :
CHECK_CONTROL_DATA_SIZE ( sizeof ( uint32_t ) ) ;
return ctdb_control_db_push_confirm ( ctdb , indata , outdata ) ;
2017-06-14 16:30:39 +10:00
case CTDB_CONTROL_DB_OPEN_FLAGS : {
uint32_t db_id ;
struct ctdb_db_context * ctdb_db ;
int tdb_flags ;
CHECK_CONTROL_DATA_SIZE ( sizeof ( db_id ) ) ;
db_id = * ( uint32_t * ) indata . dptr ;
ctdb_db = find_ctdb_db ( ctdb , db_id ) ;
if ( ctdb_db = = NULL ) {
return - 1 ;
}
tdb_flags = tdb_get_flags ( ctdb_db - > ltdb - > tdb ) ;
outdata - > dptr = talloc_size ( outdata , sizeof ( tdb_flags ) ) ;
if ( outdata - > dptr = = NULL ) {
return - 1 ;
}
outdata - > dsize = sizeof ( tdb_flags ) ;
memcpy ( outdata - > dptr , & tdb_flags , outdata - > dsize ) ;
return 0 ;
}
2017-08-30 16:18:02 +10:00
case CTDB_CONTROL_CHECK_PID_SRVID :
CHECK_CONTROL_DATA_SIZE ( ( sizeof ( pid_t ) + sizeof ( uint64_t ) ) ) ;
return ctdb_control_check_pid_srvid ( ctdb , indata ) ;
2017-04-06 19:03:51 +10:00
case CTDB_CONTROL_TUNNEL_REGISTER :
return ctdb_control_tunnel_register ( ctdb , client_id , srvid ) ;
case CTDB_CONTROL_TUNNEL_DEREGISTER :
return ctdb_control_tunnel_deregister ( ctdb , client_id , srvid ) ;
2018-02-16 15:30:13 +11:00
case CTDB_CONTROL_VACUUM_FETCH :
return ctdb_control_vacuum_fetch ( ctdb , indata ) ;
2019-07-30 14:17:11 +10:00
case CTDB_CONTROL_DB_VACUUM : {
struct ctdb_db_vacuum db_vacuum ;
CHECK_CONTROL_DATA_SIZE ( ctdb_db_vacuum_len ( & db_vacuum ) ) ;
return ctdb_control_db_vacuum ( ctdb , c , indata , async_reply ) ;
}
2020-03-18 11:31:14 +01:00
case CTDB_CONTROL_ECHO_DATA : {
return ctdb_control_echo_data ( ctdb , c , indata , async_reply ) ;
}
2019-07-30 14:17:11 +10:00
2021-07-09 14:12:59 +10:00
case CTDB_CONTROL_DISABLE_NODE :
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
return ctdb_control_disable_node ( ctdb ) ;
case CTDB_CONTROL_ENABLE_NODE :
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
return ctdb_control_enable_node ( ctdb ) ;
2023-11-15 16:31:53 +01:00
case CTDB_CONTROL_TCP_CLIENT_DISCONNECTED :
CHECK_CONTROL_DATA_SIZE ( sizeof ( struct ctdb_connection ) ) ;
return ctdb_control_tcp_client_disconnected ( ctdb , client_id , indata ) ;
2023-11-17 15:59:57 +01:00
case CTDB_CONTROL_TCP_CLIENT_PASSED :
CHECK_CONTROL_DATA_SIZE ( sizeof ( struct ctdb_connection ) ) ;
return ctdb_control_tcp_client_passed ( ctdb , client_id , indata ) ;
2023-10-25 23:55:17 -07:00
case CTDB_CONTROL_START_IPREALLOCATE :
CHECK_CONTROL_DATA_SIZE ( 0 ) ;
return ctdb_control_start_ipreallocate ( ctdb , c , async_reply ) ;
2007-04-26 14:27:49 +02:00
default :
2008-02-04 20:07:15 +11:00
DEBUG ( DEBUG_CRIT , ( __location__ " Unknown CTDB control opcode %u \n " , opcode ) ) ;
2007-04-26 14:27:49 +02:00
return - 1 ;
}
}
/*
2007-05-12 14:34:21 +10:00
send a reply for a ctdb control
*/
2015-10-29 16:42:05 +11:00
void ctdb_request_control_reply ( struct ctdb_context * ctdb , struct ctdb_req_control_old * c ,
2007-05-12 21:25:26 +10:00
TDB_DATA * outdata , int32_t status , const char * errormsg )
2007-04-26 14:27:49 +02:00
{
2015-10-29 16:44:08 +11:00
struct ctdb_reply_control_old * r ;
2007-04-26 14:27:49 +02:00
size_t len ;
2007-05-12 21:25:26 +10:00
2007-04-30 15:31:40 +02:00
/* some controls send no reply */
if ( c - > flags & CTDB_CTRL_FLAG_NOREPLY ) {
return ;
}
2015-10-29 16:44:08 +11:00
len = offsetof ( struct ctdb_reply_control_old , data ) + ( outdata ? outdata - > dsize : 0 ) ;
2007-05-12 21:25:26 +10:00
if ( errormsg ) {
len + = strlen ( errormsg ) ;
}
2015-10-29 16:44:08 +11:00
r = ctdb_transport_allocate ( ctdb , ctdb , CTDB_REPLY_CONTROL , len , struct ctdb_reply_control_old ) ;
2011-11-16 15:25:14 +11:00
if ( r = = NULL ) {
DEBUG ( DEBUG_ERR , ( __location__ " Unable to allocate transport - OOM or transport is down \n " ) ) ;
return ;
}
2007-04-26 14:27:49 +02:00
2007-05-12 14:34:21 +10:00
r - > hdr . destnode = c - > hdr . srcnode ;
r - > hdr . reqid = c - > hdr . reqid ;
2007-04-26 14:27:49 +02:00
r - > status = status ;
2007-05-12 14:34:21 +10:00
r - > datalen = outdata ? outdata - > dsize : 0 ;
if ( outdata & & outdata - > dsize ) {
2007-04-27 20:56:10 +10:00
memcpy ( & r - > data [ 0 ] , outdata - > dptr , outdata - > dsize ) ;
2007-04-26 14:27:49 +02:00
}
2007-05-12 21:25:26 +10:00
if ( errormsg ) {
r - > errorlen = strlen ( errormsg ) ;
memcpy ( & r - > data [ r - > datalen ] , errormsg , r - > errorlen ) ;
}
2008-07-04 18:00:24 +10:00
ctdb_queue_packet_opcode ( ctdb , & r - > hdr , c - > opcode ) ;
2007-04-26 14:27:49 +02:00
talloc_free ( r ) ;
}
2007-05-12 14:34:21 +10:00
/*
called when a CTDB_REQ_CONTROL packet comes in
*/
void ctdb_request_control ( struct ctdb_context * ctdb , struct ctdb_req_header * hdr )
{
2015-10-29 16:42:05 +11:00
struct ctdb_req_control_old * c = ( struct ctdb_req_control_old * ) hdr ;
2007-05-12 14:34:21 +10:00
TDB_DATA data , * outdata ;
int32_t status ;
2012-05-17 16:08:37 +10:00
bool async_reply = false ;
2007-05-12 21:25:26 +10:00
const char * errormsg = NULL ;
2007-05-12 14:34:21 +10:00
data . dptr = & c - > data [ 0 ] ;
data . dsize = c - > datalen ;
outdata = talloc_zero ( c , TDB_DATA ) ;
2007-05-12 21:25:26 +10:00
status = ctdb_control_dispatch ( ctdb , c , data , outdata , hdr - > srcnode ,
& errormsg , & async_reply ) ;
2007-05-12 14:34:21 +10:00
2007-05-12 15:15:27 +10:00
if ( ! async_reply ) {
2007-05-12 21:25:26 +10:00
ctdb_request_control_reply ( ctdb , c , outdata , status , errormsg ) ;
2007-05-12 15:15:27 +10:00
}
2007-05-12 14:34:21 +10:00
}
2007-04-26 14:27:49 +02:00
/*
called when a CTDB_REPLY_CONTROL packet comes in
*/
void ctdb_reply_control ( struct ctdb_context * ctdb , struct ctdb_req_header * hdr )
{
2015-10-29 16:44:08 +11:00
struct ctdb_reply_control_old * c = ( struct ctdb_reply_control_old * ) hdr ;
2007-04-26 14:27:49 +02:00
TDB_DATA data ;
struct ctdb_control_state * state ;
2007-05-12 21:25:26 +10:00
const char * errormsg = NULL ;
2007-04-26 14:27:49 +02:00
2015-03-17 14:30:18 +11:00
state = reqid_find ( ctdb - > idr , hdr - > reqid , struct ctdb_control_state ) ;
2007-04-26 14:27:49 +02:00
if ( state = = NULL ) {
2008-02-04 20:07:15 +11:00
DEBUG ( DEBUG_ERR , ( " pnn %u Invalid reqid %u in ctdb_reply_control \n " ,
2007-09-04 10:06:36 +10:00
ctdb - > pnn , hdr - > reqid ) ) ;
2007-04-26 14:27:49 +02:00
return ;
}
if ( hdr - > reqid ! = state - > reqid ) {
/* we found a record but it was the wrong one */
2008-02-04 20:07:15 +11:00
DEBUG ( DEBUG_ERR , ( " Dropped orphaned control reply with reqid:%u \n " , hdr - > reqid ) ) ;
2007-04-26 14:27:49 +02:00
return ;
}
data . dptr = & c - > data [ 0 ] ;
data . dsize = c - > datalen ;
2007-05-12 21:25:26 +10:00
if ( c - > errorlen ) {
errormsg = talloc_strndup ( state ,
( char * ) & c - > data [ c - > datalen ] , c - > errorlen ) ;
}
2007-04-26 14:27:49 +02:00
2007-05-05 08:33:35 +10:00
/* make state a child of the packet, so it goes away when the packet
is freed . */
talloc_steal ( hdr , state ) ;
2007-05-12 21:25:26 +10:00
state - > callback ( ctdb , c - > status , data , errormsg , state - > private_data ) ;
2007-04-26 14:27:49 +02:00
}
static int ctdb_control_destructor ( struct ctdb_control_state * state )
{
2015-03-17 14:30:18 +11:00
reqid_remove ( state - > ctdb - > idr , state - > reqid ) ;
2007-04-26 14:27:49 +02:00
return 0 ;
}
2007-05-10 14:06:48 +10:00
/*
handle a timeout of a control
*/
2015-10-26 16:50:09 +11:00
static void ctdb_control_timeout ( struct tevent_context * ev ,
struct tevent_timer * te ,
struct timeval t , void * private_data )
2007-05-10 14:06:48 +10:00
{
struct ctdb_control_state * state = talloc_get_type ( private_data , struct ctdb_control_state ) ;
2007-05-12 14:34:21 +10:00
TALLOC_CTX * tmp_ctx = talloc_new ( ev ) ;
2007-05-10 14:06:48 +10:00
2010-09-29 10:38:41 +10:00
CTDB_INCREMENT_STAT ( state - > ctdb , timeouts . control ) ;
2007-05-10 14:06:48 +10:00
2007-05-12 14:34:21 +10:00
talloc_steal ( tmp_ctx , state ) ;
2007-05-17 14:10:38 +10:00
state - > callback ( state - > ctdb , - 1 , tdb_null ,
" ctdb_control timed out " ,
state - > private_data ) ;
2007-05-12 14:34:21 +10:00
talloc_free ( tmp_ctx ) ;
2007-05-10 14:06:48 +10:00
}
2007-04-26 14:27:49 +02:00
/*
send a control message to a node
*/
int ctdb_daemon_send_control ( struct ctdb_context * ctdb , uint32_t destnode ,
2007-05-04 11:41:29 +10:00
uint64_t srvid , uint32_t opcode , uint32_t client_id ,
uint32_t flags ,
2007-04-30 15:31:40 +02:00
TDB_DATA data ,
2007-04-26 14:27:49 +02:00
ctdb_control_callback_fn_t callback ,
void * private_data )
{
2015-10-29 16:42:05 +11:00
struct ctdb_req_control_old * c ;
2007-04-26 14:27:49 +02:00
struct ctdb_control_state * state ;
size_t len ;
2009-06-30 12:03:12 +10:00
if ( ctdb - > methods = = NULL ) {
2010-10-28 13:38:34 +11:00
DEBUG ( DEBUG_INFO , ( __location__ " Failed to send control. Transport is DOWN \n " ) ) ;
2009-06-30 12:03:12 +10:00
return - 1 ;
}
2018-06-15 06:01:52 +10:00
if ( ( ( destnode = = CTDB_BROADCAST_ACTIVE ) | |
2007-06-09 21:58:50 +10:00
( destnode = = CTDB_BROADCAST_ALL ) | |
( destnode = = CTDB_BROADCAST_CONNECTED ) ) & &
! ( flags & CTDB_CTRL_FLAG_NOREPLY ) ) {
2008-02-04 20:07:15 +11:00
DEBUG ( DEBUG_CRIT , ( " Attempt to broadcast control without NOREPLY \n " ) ) ;
2007-04-30 15:31:40 +02:00
return - 1 ;
}
2018-06-15 06:01:52 +10:00
if ( destnode ! = CTDB_BROADCAST_ACTIVE & &
2007-06-09 21:58:50 +10:00
destnode ! = CTDB_BROADCAST_ALL & &
destnode ! = CTDB_BROADCAST_CONNECTED & &
2007-09-04 10:09:58 +10:00
( ! ctdb_validate_pnn ( ctdb , destnode ) | |
2007-06-07 15:18:55 +10:00
( ctdb - > nodes [ destnode ] - > flags & NODE_FLAGS_DISCONNECTED ) ) ) {
2007-05-17 23:23:41 +10:00
if ( ! ( flags & CTDB_CTRL_FLAG_NOREPLY ) ) {
callback ( ctdb , - 1 , tdb_null , " ctdb_control to disconnected node " , private_data ) ;
}
return 0 ;
}
2007-05-05 08:33:35 +10:00
/* the state is made a child of private_data if possible. This means any reply
will be discarded if the private_data goes away */
state = talloc ( private_data ? private_data : ctdb , struct ctdb_control_state ) ;
2007-04-26 14:27:49 +02:00
CTDB_NO_MEMORY ( ctdb , state ) ;
2015-03-17 14:30:18 +11:00
state - > reqid = reqid_new ( ctdb - > idr , state ) ;
2007-04-26 14:27:49 +02:00
state - > callback = callback ;
state - > private_data = private_data ;
state - > ctdb = ctdb ;
2007-05-17 14:10:38 +10:00
state - > flags = flags ;
2007-04-26 14:27:49 +02:00
talloc_set_destructor ( state , ctdb_control_destructor ) ;
2015-10-29 16:42:05 +11:00
len = offsetof ( struct ctdb_req_control_old , data ) + data . dsize ;
2007-04-28 10:50:32 +02:00
c = ctdb_transport_allocate ( ctdb , state , CTDB_REQ_CONTROL , len ,
2015-10-29 16:42:05 +11:00
struct ctdb_req_control_old ) ;
2007-04-26 14:27:49 +02:00
CTDB_NO_MEMORY ( ctdb , c ) ;
talloc_set_name_const ( c , " ctdb_req_control packet " ) ;
c - > hdr . destnode = destnode ;
c - > hdr . reqid = state - > reqid ;
c - > opcode = opcode ;
2007-05-04 11:41:29 +10:00
c - > client_id = client_id ;
2007-04-30 15:31:40 +02:00
c - > flags = flags ;
2007-04-26 14:27:49 +02:00
c - > srvid = srvid ;
c - > datalen = data . dsize ;
if ( data . dsize ) {
memcpy ( & c - > data [ 0 ] , data . dptr , data . dsize ) ;
}
2007-04-30 15:31:40 +02:00
2007-04-26 14:27:49 +02:00
ctdb_queue_packet ( ctdb , & c - > hdr ) ;
2007-04-30 15:31:40 +02:00
if ( flags & CTDB_CTRL_FLAG_NOREPLY ) {
talloc_free ( state ) ;
return 0 ;
}
2007-06-04 17:46:37 +10:00
if ( ctdb - > tunable . control_timeout ) {
2015-10-26 16:50:09 +11:00
tevent_add_timer ( ctdb - > ev , state ,
timeval_current_ofs ( ctdb - > tunable . control_timeout , 0 ) ,
ctdb_control_timeout , state ) ;
2007-06-04 17:46:37 +10:00
}
2007-04-26 14:27:49 +02:00
talloc_free ( c ) ;
return 0 ;
}