2007-01-10 11:16:11 +00: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 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2007-01-10 11:16:11 +00: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 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2007-01-10 11:16:11 +00:00
*/
# include "includes.h"
# include "cluster/cluster.h"
2007-01-19 03:53:37 +00:00
# include "cluster/cluster_private.h"
static struct cluster_ops * ops ;
/* set cluster operations */
void cluster_set_ops ( struct cluster_ops * new_ops )
{
ops = new_ops ;
}
/*
2007-02-08 00:58:17 +00:00
an ugly way of getting at the backend handle ( eg . ctdb context ) via the cluster API
2007-01-19 03:53:37 +00:00
*/
2007-02-08 00:58:17 +00:00
void * cluster_backend_handle ( void )
2007-01-19 03:53:37 +00:00
{
2007-02-08 00:58:17 +00:00
return ops - > backend_handle ( ops ) ;
2007-01-19 03:53:37 +00:00
}
/* by default use the local ops */
static void cluster_init ( void )
{
if ( ops = = NULL ) cluster_local_init ( ) ;
}
2007-01-10 11:16:11 +00:00
/*
server a server_id for the local node
*/
struct server_id cluster_id ( uint32_t id )
{
2007-01-19 03:53:37 +00:00
cluster_init ( ) ;
return ops - > cluster_id ( ops , id ) ;
2007-01-10 11:16:11 +00:00
}
/*
return a server_id as a string
*/
const char * cluster_id_string ( TALLOC_CTX * mem_ctx , struct server_id id )
{
2007-01-19 03:53:37 +00:00
cluster_init ( ) ;
return ops - > cluster_id_string ( ops , mem_ctx , id ) ;
2007-01-10 11:16:11 +00:00
}
2007-01-20 00:48:31 +00:00
/*
open a temporary tdb in a cluster friendly manner
*/
struct tdb_wrap * cluster_tdb_tmp_open ( TALLOC_CTX * mem_ctx , const char * dbname , int flags )
{
cluster_init ( ) ;
return ops - > cluster_tdb_tmp_open ( ops , mem_ctx , dbname , flags ) ;
}
2007-02-08 00:58:17 +00:00
/*
register a callback function for a messaging endpoint
*/
NTSTATUS cluster_message_init ( struct messaging_context * msg , struct server_id server ,
2007-02-08 02:59:58 +00:00
cluster_message_fn_t handler )
2007-02-08 00:58:17 +00:00
{
cluster_init ( ) ;
return ops - > message_init ( ops , msg , server , handler ) ;
}
/*
send a message to another node in the cluster
*/
2007-02-09 01:52:13 +00:00
NTSTATUS cluster_message_send ( struct server_id server , DATA_BLOB * data )
2007-02-08 00:58:17 +00:00
{
cluster_init ( ) ;
2007-02-09 01:52:13 +00:00
return ops - > message_send ( ops , server , data ) ;
2007-02-08 00:58:17 +00:00
}