2007-01-10 14:16:11 +03:00
/*
Unix SMB / CIFS implementation .
core clustering code
Copyright ( C ) Andrew Tridgell 2006
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 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2007-01-10 14:16:11 +03:00
( at your option ) any later version .
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 .
You should have received a copy of the GNU General Public License
2007-07-10 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2007-01-10 14:16:11 +03:00
*/
# include "includes.h"
# include "cluster/cluster.h"
2007-01-19 06:53:37 +03:00
# include "cluster/cluster_private.h"
2007-09-24 01:35:03 +04:00
# include "librpc/gen_ndr/misc.h"
2011-02-18 02:10:30 +03:00
# include "librpc/gen_ndr/server_id4.h"
2007-01-19 06:53:37 +03:00
static struct cluster_ops * ops ;
/* set cluster operations */
void cluster_set_ops ( struct cluster_ops * new_ops )
{
ops = new_ops ;
}
/*
2007-02-08 03:58:17 +03:00
an ugly way of getting at the backend handle ( eg . ctdb context ) via the cluster API
2007-01-19 06:53:37 +03:00
*/
2007-02-08 03:58:17 +03:00
void * cluster_backend_handle ( void )
2007-01-19 06:53:37 +03:00
{
2007-02-08 03:58:17 +03:00
return ops - > backend_handle ( ops ) ;
2007-01-19 06:53:37 +03:00
}
/* by default use the local ops */
static void cluster_init ( void )
{
if ( ops = = NULL ) cluster_local_init ( ) ;
}
2007-01-10 14:16:11 +03:00
/*
2008-02-04 09:51:38 +03:00
create a server_id for the local node
2007-01-10 14:16:11 +03:00
*/
2008-02-04 09:51:38 +03:00
struct server_id cluster_id ( uint64_t id , uint32_t id2 )
2007-01-10 14:16:11 +03:00
{
2007-01-19 06:53:37 +03:00
cluster_init ( ) ;
2008-02-04 09:51:38 +03:00
return ops - > cluster_id ( ops , id , id2 ) ;
2007-01-10 14:16:11 +03:00
}
/*
return a server_id as a string
*/
2011-05-02 04:06:56 +04:00
char * cluster_id_string ( TALLOC_CTX * mem_ctx , struct server_id id )
2007-01-10 14:16:11 +03:00
{
2007-01-19 06:53:37 +03:00
cluster_init ( ) ;
return ops - > cluster_id_string ( ops , mem_ctx , id ) ;
2007-01-10 14:16:11 +03:00
}
2007-01-20 03:48:31 +03:00
/*
open a temporary tdb in a cluster friendly manner
*/
2007-12-14 00:46:23 +03:00
struct tdb_wrap * cluster_tdb_tmp_open ( TALLOC_CTX * mem_ctx , struct loadparm_context * lp_ctx , const char * dbname , int flags )
2007-01-20 03:48:31 +03:00
{
cluster_init ( ) ;
2007-12-14 00:46:23 +03:00
return ops - > cluster_tdb_tmp_open ( ops , mem_ctx , lp_ctx , dbname , flags ) ;
2007-01-20 03:48:31 +03:00
}
2007-02-08 03:58:17 +03:00
/*
register a callback function for a messaging endpoint
*/
2011-05-03 04:40:33 +04:00
NTSTATUS cluster_message_init ( struct imessaging_context * msg , struct server_id server ,
2007-02-08 05:59:58 +03:00
cluster_message_fn_t handler )
2007-02-08 03:58:17 +03:00
{
cluster_init ( ) ;
return ops - > message_init ( ops , msg , server , handler ) ;
}
/*
send a message to another node in the cluster
*/
2007-02-09 04:52:13 +03:00
NTSTATUS cluster_message_send ( struct server_id server , DATA_BLOB * data )
2007-02-08 03:58:17 +03:00
{
cluster_init ( ) ;
2007-02-09 04:52:13 +03:00
return ops - > message_send ( ops , server , data ) ;
2007-02-08 03:58:17 +03:00
}