r23798: updated old Temple Place FSF addresses to new URL
[samba.git] / source4 / cluster / ctdb / include / ctdb.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 3 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, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef _CTDB_H
21 #define _CTDB_H
22
23 #define CTDB_IMMEDIATE_MIGRATION        0x00000001
24 struct ctdb_call {
25         int call_id;
26         TDB_DATA key;
27         TDB_DATA call_data;
28         TDB_DATA reply_data;
29         uint32_t status;
30         uint32_t flags;
31 };
32
33 /*
34   structure passed to a ctdb call backend function
35 */
36 struct ctdb_call_info {
37         TDB_DATA key;          /* record key */
38         TDB_DATA record_data;  /* current data in the record */
39         TDB_DATA *new_data;    /* optionally updated record data */
40         TDB_DATA *call_data;   /* optionally passed from caller */
41         TDB_DATA *reply_data;  /* optionally returned by function */
42         uint32_t status;       /* optional reply status - defaults to zero */
43 };
44
45 #define CTDB_ERR_INVALID 1
46 #define CTDB_ERR_NOMEM 2
47
48 /*
49   ctdb flags
50 */
51 #define CTDB_FLAG_SELF_CONNECT (1<<0)
52 #define CTDB_FLAG_TORTURE      (1<<1)
53
54
55 /* 
56    a message handler ID meaning "give me all messages"
57  */
58 #define CTDB_SRVID_ALL 0xFFFFFFFF
59
60 struct event_context;
61
62 /*
63   initialise ctdb subsystem
64 */
65 struct ctdb_context *ctdb_init(struct event_context *ev);
66
67 /*
68   choose the transport
69 */
70 int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport);
71
72 /*
73   set the directory for the local databases
74 */
75 int ctdb_set_tdb_dir(struct ctdb_context *ctdb, const char *dir);
76
77 /*
78   set some flags
79 */
80 void ctdb_set_flags(struct ctdb_context *ctdb, unsigned flags);
81
82 /*
83   clear some flags
84 */
85 void ctdb_clear_flags(struct ctdb_context *ctdb, unsigned flags);
86
87 /*
88   set max acess count before a dmaster migration
89 */
90 void ctdb_set_max_lacount(struct ctdb_context *ctdb, unsigned count);
91
92 /*
93   tell ctdb what address to listen on, in transport specific format
94 */
95 int ctdb_set_address(struct ctdb_context *ctdb, const char *address);
96
97 /*
98   tell ctdb what nodes are available. This takes a filename, which will contain
99   1 node address per line, in a transport specific format
100 */
101 int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist);
102
103 /*
104   start the ctdb protocol
105 */
106 int ctdb_start(struct ctdb_context *ctdb);
107
108 /*
109   attach to a ctdb database
110 */
111 struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name, int tdb_flags, 
112                                     int open_flags, mode_t mode);
113
114 /*
115   find an attached ctdb_db handle given a name
116  */
117 struct ctdb_db_context *ctdb_db_handle(struct ctdb_context *ctdb, const char *name);
118
119 /*
120   error string for last ctdb error
121 */
122 const char *ctdb_errstr(struct ctdb_context *);
123
124 /* a ctdb call function */
125 typedef int (*ctdb_fn_t)(struct ctdb_call_info *);
126
127 /*
128   setup a ctdb call function
129 */
130 int ctdb_set_call(struct ctdb_db_context *ctdb_db, ctdb_fn_t fn, int id);
131
132
133
134 /*
135   make a ctdb call. The associated ctdb call function will be called on the DMASTER
136   for the given record
137 */
138 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
139
140 /*
141   wait for all nodes to be connected - useful for test code
142 */
143 void ctdb_connect_wait(struct ctdb_context *ctdb);
144
145 /*
146   initiate an ordered ctdb cluster shutdown
147   this function will never return
148 */
149 void ctdb_shutdown(struct ctdb_context *ctdb);
150
151 /* return vnn of this node */
152 uint32_t ctdb_get_vnn(struct ctdb_context *ctdb);
153
154 /*
155   return the number of nodes
156 */
157 uint32_t ctdb_get_num_nodes(struct ctdb_context *ctdb);
158
159 /* setup a handler for ctdb messages */
160 typedef void (*ctdb_message_fn_t)(struct ctdb_context *, uint32_t srvid, 
161                                   TDB_DATA data, void *);
162 int ctdb_set_message_handler(struct ctdb_context *ctdb, uint32_t srvid, 
163                              ctdb_message_fn_t handler,
164                              void *private_data);
165
166
167 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
168 struct ctdb_client_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
169 int ctdb_call_recv(struct ctdb_client_call_state *state, struct ctdb_call *call);
170
171 /* send a ctdb message */
172 int ctdb_send_message(struct ctdb_context *ctdb, uint32_t vnn,
173                       uint32_t srvid, TDB_DATA data);
174
175
176 /* 
177    Fetch a ctdb record from a remote node
178  . Underneath this will force the
179    dmaster for the record to be moved to the local node. 
180
181 */
182 struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx, 
183                                            TDB_DATA key, TDB_DATA *data);
184
185
186 /*
187   do a fetch lock from a client to the local daemon
188 */
189 #define FETCH_LOCK_SUCCESS              0
190 #define FETCH_LOCK_LOCKFAILED           1
191 #define FETCH_LOCK_FETCHFAILED          2
192 #define FETCH_LOCK_DMASTERFAILED        3
193
194 int ctdb_client_fetch_lock(struct ctdb_db_context *ctdb_db, 
195                                                   TALLOC_CTX *mem_ctx, 
196                                                   TDB_DATA key, TDB_DATA *data);
197
198
199 int ctdb_record_store(struct ctdb_record_handle *h, TDB_DATA data);
200
201 int ctdb_register_message_handler(struct ctdb_context *ctdb, 
202                                   TALLOC_CTX *mem_ctx,
203                                   uint32_t srvid,
204                                   ctdb_message_fn_t handler,
205                                   void *private_data);
206
207 struct ctdb_db_context *find_ctdb_db(struct ctdb_context *ctdb, uint32_t id);
208
209
210 struct ctdb_context *ctdb_cmdline_client(struct event_context *ev, const char *ctdb_socket);
211
212 struct ctdb_status;
213 int ctdb_status(struct ctdb_context *ctdb, struct ctdb_status *status);
214
215 #endif