2007-06-10 21:02:09 +04:00
/*
Unix SMB / CIFS implementation .
Samba internal messaging functions
Copyright ( C ) 2007 by Volker Lendecke
2011-06-25 17:14:25 +04:00
2007-06-10 21:02:09 +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-09 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
2007-06-10 21:02:09 +04:00
( at your option ) any later version .
2011-06-25 17:14:25 +04:00
2007-06-10 21:02:09 +04:00
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
2011-06-25 17:14:25 +04:00
2007-06-10 21:02:09 +04:00
You should have received a copy of the GNU General Public License
2007-07-10 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2007-06-10 21:02:09 +04:00
*/
# include "includes.h"
2011-03-24 17:31:06 +03:00
# include "messages.h"
2011-05-05 13:25:29 +04:00
# include "util_tdb.h"
2007-06-10 21:02:09 +04:00
# ifdef CLUSTER_SUPPORT
2011-08-30 19:02:54 +04:00
/*
* It is not possible to include ctdb . h and tdb_compat . h ( included via
* some other include above ) without warnings . This fixes those
* warnings .
*/
# ifdef typesafe_cb
# undef typesafe_cb
# endif
# ifdef typesafe_cb_preargs
# undef typesafe_cb_preargs
# endif
# ifdef typesafe_cb_postargs
# undef typesafe_cb_postargs
# endif
2008-01-16 12:09:48 +03:00
# include "ctdb.h"
# include "ctdb_private.h"
# include "ctdbd_conn.h"
2007-06-10 21:02:09 +04:00
struct messaging_ctdbd_context {
struct ctdbd_connection * conn ;
} ;
/*
* This is a Samba3 hack / optimization . Routines like process_exists need to
* talk to ctdbd , and they don ' t get handed a messaging context .
*/
2008-04-15 03:18:06 +04:00
static struct ctdbd_connection * global_ctdbd_connection ;
static int global_ctdb_connection_pid ;
2007-06-10 21:02:09 +04:00
2010-08-31 18:52:56 +04:00
struct ctdbd_connection * messaging_ctdbd_connection ( void )
2007-06-10 21:02:09 +04:00
{
2012-04-04 13:27:08 +04:00
if ( ! lp_clustering ( ) ) {
return NULL ;
}
2008-04-15 03:18:50 +04:00
if ( global_ctdb_connection_pid = = 0 & &
global_ctdbd_connection = = NULL ) {
struct event_context * ev ;
struct messaging_context * msg ;
ev = event_context_init ( NULL ) ;
2008-04-19 19:04:46 +04:00
if ( ! ev ) {
2008-04-15 03:18:50 +04:00
DEBUG ( 0 , ( " event_context_init failed \n " ) ) ;
}
2011-12-12 17:55:54 +04:00
msg = messaging_init ( NULL , ev ) ;
2008-04-15 03:18:50 +04:00
if ( ! msg ) {
DEBUG ( 0 , ( " messaging_init failed \n " ) ) ;
2008-06-13 14:01:31 +04:00
return NULL ;
2008-04-15 03:18:50 +04:00
}
}
2008-04-15 03:18:06 +04:00
if ( global_ctdb_connection_pid ! = getpid ( ) ) {
DEBUG ( 0 , ( " messaging_ctdbd_connection(): "
" valid for pid[%d] but it's [%d] \n " ,
global_ctdb_connection_pid , getpid ( ) ) ) ;
smb_panic ( " messaging_ctdbd_connection() invalid process \n " ) ;
}
2007-06-10 21:02:09 +04:00
return global_ctdbd_connection ;
}
static NTSTATUS messaging_ctdb_send ( struct messaging_context * msg_ctx ,
struct server_id pid , int msg_type ,
const DATA_BLOB * data ,
struct messaging_backend * backend )
{
struct messaging_ctdbd_context * ctx = talloc_get_type_abort (
backend - > private_data , struct messaging_ctdbd_context ) ;
struct messaging_rec msg ;
msg . msg_version = MESSAGE_VERSION ;
msg . msg_type = msg_type ;
msg . dest = pid ;
2010-07-04 18:41:51 +04:00
msg . src = msg_ctx - > id ;
2007-06-10 21:02:09 +04:00
msg . buf = * data ;
return ctdbd_messaging_send ( ctx - > conn , pid . vnn , pid . pid , & msg ) ;
}
static int messaging_ctdbd_destructor ( struct messaging_ctdbd_context * ctx )
{
/*
* The global connection just went away
*/
2008-04-15 03:18:06 +04:00
global_ctdb_connection_pid = 0 ;
2007-06-10 21:02:09 +04:00
global_ctdbd_connection = NULL ;
return 0 ;
}
NTSTATUS messaging_ctdbd_init ( struct messaging_context * msg_ctx ,
TALLOC_CTX * mem_ctx ,
struct messaging_backend * * presult )
{
struct messaging_backend * result ;
struct messaging_ctdbd_context * ctx ;
NTSTATUS status ;
2011-06-07 05:38:41 +04:00
if ( ! ( result = talloc ( mem_ctx , struct messaging_backend ) ) ) {
2007-06-10 21:02:09 +04:00
DEBUG ( 0 , ( " talloc failed \n " ) ) ;
return NT_STATUS_NO_MEMORY ;
}
2011-06-07 05:38:41 +04:00
if ( ! ( ctx = talloc ( result , struct messaging_ctdbd_context ) ) ) {
2007-06-10 21:02:09 +04:00
DEBUG ( 0 , ( " talloc failed \n " ) ) ;
TALLOC_FREE ( result ) ;
return NT_STATUS_NO_MEMORY ;
}
status = ctdbd_messaging_connection ( ctx , & ctx - > conn ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2007-08-01 14:03:13 +04:00
DEBUG ( 10 , ( " ctdbd_messaging_connection failed: %s \n " ,
2007-06-10 21:02:09 +04:00
nt_errstr ( status ) ) ) ;
TALLOC_FREE ( result ) ;
return status ;
}
2007-07-24 15:47:37 +04:00
status = ctdbd_register_msg_ctx ( ctx - > conn , msg_ctx ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
DEBUG ( 10 , ( " ctdbd_register_msg_ctx failed: %s \n " ,
nt_errstr ( status ) ) ) ;
TALLOC_FREE ( result ) ;
return status ;
}
2008-04-15 03:18:06 +04:00
global_ctdb_connection_pid = getpid ( ) ;
2007-06-10 21:02:09 +04:00
global_ctdbd_connection = ctx - > conn ;
talloc_set_destructor ( ctx , messaging_ctdbd_destructor ) ;
set_my_vnn ( ctdbd_vnn ( ctx - > conn ) ) ;
result - > send_fn = messaging_ctdb_send ;
result - > private_data = ( void * ) ctx ;
* presult = result ;
return NT_STATUS_OK ;
}
# else
NTSTATUS messaging_ctdbd_init ( struct messaging_context * msg_ctx ,
TALLOC_CTX * mem_ctx ,
struct messaging_backend * * presult )
{
return NT_STATUS_NOT_IMPLEMENTED ;
}
2012-04-04 13:27:08 +04:00
struct ctdbd_connection * messaging_ctdbd_connection ( void )
{
return NULL ;
}
2007-06-10 21:02:09 +04:00
# endif