r23792: convert Samba4 to GPLv3
[sfrench/samba-autobuild/.git] / source4 / cluster / cluster.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    core clustering code
5
6    Copyright (C) Andrew Tridgell 2006
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "includes.h"
23 #include "cluster/cluster.h"
24 #include "cluster/cluster_private.h"
25
26 static struct cluster_ops *ops;
27
28 /* set cluster operations */
29 void cluster_set_ops(struct cluster_ops *new_ops)
30 {
31         ops = new_ops;
32 }
33
34 /*
35   an ugly way of getting at the backend handle (eg. ctdb context) via the cluster API
36 */
37 void *cluster_backend_handle(void)
38 {
39         return ops->backend_handle(ops);
40 }
41
42 /* by default use the local ops */
43 static void cluster_init(void)
44 {
45         if (ops == NULL) cluster_local_init();
46 }
47
48 /*
49   server a server_id for the local node
50 */
51 struct server_id cluster_id(uint32_t id)
52 {
53         cluster_init();
54         return ops->cluster_id(ops, id);
55 }
56
57
58 /*
59   return a server_id as a string
60 */
61 const char *cluster_id_string(TALLOC_CTX *mem_ctx, struct server_id id)
62 {
63         cluster_init();
64         return ops->cluster_id_string(ops, mem_ctx, id);
65 }
66
67
68 /*
69   open a temporary tdb in a cluster friendly manner
70 */
71 struct tdb_wrap *cluster_tdb_tmp_open(TALLOC_CTX *mem_ctx, const char *dbname, int flags)
72 {
73         cluster_init();
74         return ops->cluster_tdb_tmp_open(ops, mem_ctx, dbname, flags);
75 }
76
77
78 /*
79   register a callback function for a messaging endpoint
80 */
81 NTSTATUS cluster_message_init(struct messaging_context *msg, struct server_id server,
82                               cluster_message_fn_t handler)
83 {
84         cluster_init();
85         return ops->message_init(ops, msg, server, handler);
86 }
87
88 /*
89   send a message to another node in the cluster
90 */
91 NTSTATUS cluster_message_send(struct server_id server, DATA_BLOB *data)
92 {
93         cluster_init();
94         return ops->message_send(ops, server, data);
95 }