merge from ab
[vlendec/samba-autobuild/.git] / ctdb / include / ctdb_private.h
1 /* 
2    ctdb database library
3
4    Copyright (C) Andrew Tridgell  2006
5
6    This library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2 of the License, or (at your option) any later version.
10
11    This library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with this library; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21
22 /*
23   an installed ctdb remote call
24 */
25 struct ctdb_registered_call {
26         struct ctdb_registered_call *next, *prev;
27         uint32_t id;
28         ctdb_fn_t fn;
29 };
30
31 /*
32   this address structure might need to be generalised later for some
33   transports
34 */
35 struct ctdb_address {
36         const char *address;
37         int port;
38 };
39
40 /*
41   state associated with one node
42 */
43 struct ctdb_node {
44         struct ctdb_context *ctdb;
45         struct ctdb_node *next, *prev;
46         struct ctdb_address address;
47         void *private; /* private to transport */
48 };
49
50 /*
51   transport specific methods
52 */
53 struct ctdb_methods {
54         int (*start)(struct ctdb_context *); /* start protocol processing */    
55         int (*add_node)(struct ctdb_node *); /* setup a new node */     
56 };
57
58 /* main state of the ctdb daemon */
59 struct ctdb_context {
60         struct event_context *ev;
61         struct ctdb_address address;
62         struct ctdb_node *nodes; /* list of nodes in the cluster */
63         struct ctdb_registered_call *calls; /* list of registered calls */
64         char *err_msg;
65         struct tdb_context *ltdb;
66         const struct ctdb_methods *methods; /* transport methods */
67         void *private; /* private to transport */
68 };
69
70 #define CTDB_NO_MEMORY(ctdb, p) do { if (!(p)) { \
71           ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
72           return -1; }} while (0)
73
74
75 /* internal prototypes */
76 void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...);
77 bool ctdb_same_address(struct ctdb_address *a1, struct ctdb_address *a2);
78
79