dab39c1feaa0f9ba33a93613f6caf3703c513d33
[garming/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 2 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, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 #include "cluster/cluster.h"
25 #include "cluster/cluster_private.h"
26
27 static struct cluster_ops *ops;
28
29 /* set cluster operations */
30 void cluster_set_ops(struct cluster_ops *new_ops)
31 {
32         ops = new_ops;
33 }
34
35 /*
36   an ugly way of getting at the backend handle (eg. ctdb context) via the cluster API
37 */
38 void *cluster_backend_handle(void)
39 {
40         return ops->backend_handle(ops);
41 }
42
43 /* by default use the local ops */
44 static void cluster_init(void)
45 {
46         if (ops == NULL) cluster_local_init();
47 }
48
49 /*
50   server a server_id for the local node
51 */
52 struct server_id cluster_id(uint32_t id)
53 {
54         cluster_init();
55         return ops->cluster_id(ops, id);
56 }
57
58
59 /*
60   return a server_id as a string
61 */
62 const char *cluster_id_string(TALLOC_CTX *mem_ctx, struct server_id id)
63 {
64         cluster_init();
65         return ops->cluster_id_string(ops, mem_ctx, id);
66 }
67
68
69 /*
70   open a temporary tdb in a cluster friendly manner
71 */
72 struct tdb_wrap *cluster_tdb_tmp_open(TALLOC_CTX *mem_ctx, const char *dbname, int flags)
73 {
74         cluster_init();
75         return ops->cluster_tdb_tmp_open(ops, mem_ctx, dbname, flags);
76 }
77
78
79 /*
80   register a callback function for a messaging endpoint
81 */
82 NTSTATUS cluster_message_init(struct messaging_context *msg, struct server_id server,
83                               cluster_message_fn_t handler)
84 {
85         cluster_init();
86         return ops->message_init(ops, msg, server, handler);
87 }
88
89 /*
90   send a message to another node in the cluster
91 */
92 NTSTATUS cluster_message_send(struct server_id server, DATA_BLOB *data)
93 {
94         cluster_init();
95         return ops->message_send(ops, server, data);
96 }