4 Copyright (C) Andrew Tridgell 2006
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program 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
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #define CTDB_IMMEDIATE_MIGRATION 0x00000001
34 structure passed to a ctdb call backend function
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 */
45 #define CTDB_ERR_INVALID 1
46 #define CTDB_ERR_NOMEM 2
51 #define CTDB_FLAG_TORTURE (1<<1)
54 a message handler ID meaning "give me all messages"
56 #define CTDB_SRVID_ALL (~(uint64_t)0)
61 #define CTDB_SRVID_RECOVERY 0xF100000000000000LL
64 a message handler ID meaning that the cluster has been reconfigured
66 #define CTDB_SRVID_RECONFIGURE 0xF200000000000000LL
69 a message handler ID meaning that an IP address has been released
71 #define CTDB_SRVID_RELEASE_IP 0xF300000000000000LL
74 a message ID meaning that a nodes flags have changed
76 #define CTDB_SRVID_NODE_FLAGS_CHANGED 0xF400000000000000LL
79 a message ID meaning that a node should be banned
81 #define CTDB_SRVID_BAN_NODE 0xF500000000000000LL
84 a message ID meaning that a node should be unbanned
86 #define CTDB_SRVID_UNBAN_NODE 0xF600000000000000LL
89 a message to tell the recovery daemon to fetch a set of records
91 #define CTDB_SRVID_VACUUM_FETCH 0xF700000000000000LL
94 a message to tell the recovery daemon to write a talloc memdump
97 #define CTDB_SRVID_MEM_DUMP 0xF800000000000000LL
100 /* used on the domain socket, send a pdu to the local daemon */
101 #define CTDB_CURRENT_NODE 0xF0000001
102 /* send a broadcast to all nodes in the cluster, active or not */
103 #define CTDB_BROADCAST_ALL 0xF0000002
104 /* send a broadcast to all nodes in the current vnn map */
105 #define CTDB_BROADCAST_VNNMAP 0xF0000003
106 /* send a broadcast to all connected nodes */
107 #define CTDB_BROADCAST_CONNECTED 0xF0000004
110 enum control_state {CTDB_CONTROL_WAIT, CTDB_CONTROL_DONE, CTDB_CONTROL_ERROR, CTDB_CONTROL_TIMEOUT};
112 struct ctdb_client_control_state {
113 struct ctdb_context *ctdb;
117 enum control_state state;
119 struct ctdb_req_control *c;
121 /* if we have a callback registered for the completion (or failure) of
123 if a callback is used, it MUST talloc_free the cb_data passed to it
126 void (*fn)(struct ctdb_client_control_state *);
132 struct event_context;
135 initialise ctdb subsystem
137 struct ctdb_context *ctdb_init(struct event_context *ev);
142 int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport);
145 set the directory for the local databases
147 int ctdb_set_tdb_dir(struct ctdb_context *ctdb, const char *dir);
148 int ctdb_set_tdb_dir_persistent(struct ctdb_context *ctdb, const char *dir);
153 void ctdb_set_flags(struct ctdb_context *ctdb, unsigned flags);
156 set max acess count before a dmaster migration
158 void ctdb_set_max_lacount(struct ctdb_context *ctdb, unsigned count);
161 tell ctdb what address to listen on, in transport specific format
163 int ctdb_set_address(struct ctdb_context *ctdb, const char *address);
165 int ctdb_set_socketname(struct ctdb_context *ctdb, const char *socketname);
168 tell ctdb what nodes are available. This takes a filename, which will contain
169 1 node address per line, in a transport specific format
171 int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist);
174 Check that a specific ip address exists in the node list and returns
175 the id for the node or -1
177 int ctdb_ip_to_nodeid(struct ctdb_context *ctdb, const char *nodeip);
180 start the ctdb protocol
182 int ctdb_start(struct ctdb_context *ctdb);
183 int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork);
186 attach to a ctdb database
188 struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb, const char *name, bool persistent);
191 find an attached ctdb_db handle given a name
193 struct ctdb_db_context *ctdb_db_handle(struct ctdb_context *ctdb, const char *name);
196 error string for last ctdb error
198 const char *ctdb_errstr(struct ctdb_context *);
200 /* a ctdb call function */
201 typedef int (*ctdb_fn_t)(struct ctdb_call_info *);
204 setup a ctdb call function
206 int ctdb_set_call(struct ctdb_db_context *ctdb_db, ctdb_fn_t fn, uint32_t id);
211 make a ctdb call. The associated ctdb call function will be called on the DMASTER
214 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
217 initiate an ordered ctdb cluster shutdown
218 this function will never return
220 void ctdb_shutdown(struct ctdb_context *ctdb);
222 /* return pnn of this node */
223 uint32_t ctdb_get_pnn(struct ctdb_context *ctdb);
226 return the number of nodes
228 uint32_t ctdb_get_num_nodes(struct ctdb_context *ctdb);
230 /* setup a handler for ctdb messages */
231 typedef void (*ctdb_message_fn_t)(struct ctdb_context *, uint64_t srvid,
232 TDB_DATA data, void *);
233 int ctdb_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
234 ctdb_message_fn_t handler,
238 int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
239 struct ctdb_client_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
240 int ctdb_call_recv(struct ctdb_client_call_state *state, struct ctdb_call *call);
242 /* send a ctdb message */
243 int ctdb_send_message(struct ctdb_context *ctdb, uint32_t pnn,
244 uint64_t srvid, TDB_DATA data);
248 Fetch a ctdb record from a remote node
249 . Underneath this will force the
250 dmaster for the record to be moved to the local node.
252 struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx,
253 TDB_DATA key, TDB_DATA *data);
255 int ctdb_record_store(struct ctdb_record_handle *h, TDB_DATA data);
257 int ctdb_fetch(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx,
258 TDB_DATA key, TDB_DATA *data);
260 int ctdb_register_message_handler(struct ctdb_context *ctdb,
263 ctdb_message_fn_t handler,
266 struct ctdb_db_context *find_ctdb_db(struct ctdb_context *ctdb, uint32_t id);
269 struct ctdb_context *ctdb_cmdline_client(struct event_context *ev);
271 struct ctdb_statistics;
272 int ctdb_ctrl_statistics(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_statistics *status);
274 int ctdb_ctrl_shutdown(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
277 int ctdb_ctrl_getvnnmap(struct ctdb_context *ctdb,
278 struct timeval timeout, uint32_t destnode,
279 TALLOC_CTX *mem_ctx, struct ctdb_vnn_map **vnnmap);
280 int ctdb_ctrl_setvnnmap(struct ctdb_context *ctdb,
281 struct timeval timeout, uint32_t destnode,
282 TALLOC_CTX *mem_ctx, struct ctdb_vnn_map *vnnmap);
284 /* table that contains a list of all dbids on a node
286 struct ctdb_dbid_map {
293 int ctdb_ctrl_getdbmap(struct ctdb_context *ctdb,
294 struct timeval timeout, uint32_t destnode,
295 TALLOC_CTX *mem_ctx, struct ctdb_dbid_map **dbmap);
298 struct ctdb_node_map;
300 int ctdb_ctrl_getnodemap(struct ctdb_context *ctdb,
301 struct timeval timeout, uint32_t destnode,
302 TALLOC_CTX *mem_ctx, struct ctdb_node_map **nodemap);
304 int ctdb_ctrl_reload_nodes_file(struct ctdb_context *ctdb,
305 struct timeval timeout, uint32_t destnode);
307 struct ctdb_key_list {
311 struct ctdb_ltdb_header *headers;
315 int ctdb_ctrl_pulldb(
316 struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid,
317 uint32_t lmaster, TALLOC_CTX *mem_ctx,
318 struct timeval timeout, TDB_DATA *outdata);
320 struct ctdb_client_control_state *ctdb_ctrl_pulldb_send(
321 struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid,
322 uint32_t lmaster, TALLOC_CTX *mem_ctx, struct timeval timeout);
324 int ctdb_ctrl_pulldb_recv(
325 struct ctdb_context *ctdb,
326 TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state,
329 int ctdb_ctrl_pushdb(
330 struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid,
332 struct timeval timeout, TDB_DATA indata);
334 struct ctdb_client_control_state *ctdb_ctrl_pushdb_send(
335 struct ctdb_context *ctdb, uint32_t destnode, uint32_t dbid,
336 TALLOC_CTX *mem_ctx, struct timeval timeout,
339 int ctdb_ctrl_pushdb_recv(
340 struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
341 struct ctdb_client_control_state *state);
344 int ctdb_ctrl_copydb(struct ctdb_context *ctdb,
345 struct timeval timeout, uint32_t sourcenode,
346 uint32_t destnode, uint32_t dbid, uint32_t lmaster,
347 TALLOC_CTX *mem_ctx);
349 int ctdb_ctrl_getdbpath(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **path);
350 int ctdb_ctrl_getdbname(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **name);
351 int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, TALLOC_CTX *mem_ctx, const char *name, bool persistent);
353 int ctdb_ctrl_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid);
355 int ctdb_ctrl_ping(struct ctdb_context *ctdb, uint32_t destnode);
357 int ctdb_ctrl_get_config(struct ctdb_context *ctdb);
359 int ctdb_ctrl_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, int32_t *level);
360 int ctdb_ctrl_set_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, int32_t level);
363 change dmaster for all keys in the database to the new value
365 int ctdb_ctrl_setdmaster(struct ctdb_context *ctdb,
366 struct timeval timeout, uint32_t destnode,
367 TALLOC_CTX *mem_ctx, uint32_t dbid, uint32_t dmaster);
370 write a record on a specific db (this implicitely updates dmaster of the record to locally be the vnn of the node where the control is executed on)
372 int ctdb_ctrl_write_record(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, uint32_t dbid, TDB_DATA key, TDB_DATA data);
374 #define CTDB_RECOVERY_NORMAL 0
375 #define CTDB_RECOVERY_ACTIVE 1
378 get the recovery mode of a remote node
380 int ctdb_ctrl_getrecmode(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode, uint32_t *recmode);
382 struct ctdb_client_control_state *ctdb_ctrl_getrecmode_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode);
384 int ctdb_ctrl_getrecmode_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, uint32_t *recmode);
388 set the recovery mode of a remote node
390 int ctdb_ctrl_setrecmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t recmode);
392 get the monitoring mode of a remote node
394 int ctdb_ctrl_getmonmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *monmode);
397 set the monitoring mode of a remote node to active
399 int ctdb_ctrl_enable_monmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
402 set the monitoring mode of a remote node to disabled
404 int ctdb_ctrl_disable_monmode(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
408 get the recovery master of a remote node
410 int ctdb_ctrl_getrecmaster(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode, uint32_t *recmaster);
412 struct ctdb_client_control_state *ctdb_ctrl_getrecmaster_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode);
414 int ctdb_ctrl_getrecmaster_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, uint32_t *recmaster);
419 set the recovery master of a remote node
421 int ctdb_ctrl_setrecmaster(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t recmaster);
423 uint32_t *ctdb_get_connected_nodes(struct ctdb_context *ctdb,
424 struct timeval timeout,
426 uint32_t *num_nodes);
428 int ctdb_statistics_reset(struct ctdb_context *ctdb, uint32_t destnode);
430 int ctdb_set_logfile(struct ctdb_context *ctdb, const char *logfile, bool use_syslog);
432 typedef int (*ctdb_traverse_func)(struct ctdb_context *, TDB_DATA, TDB_DATA, void *);
433 int ctdb_traverse(struct ctdb_db_context *ctdb_db, ctdb_traverse_func fn, void *private_data);
435 int ctdb_dump_db(struct ctdb_db_context *ctdb_db, FILE *f);
438 get the pid of a ctdb daemon
440 int ctdb_ctrl_getpid(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode, uint32_t *pid);
442 int ctdb_ctrl_freeze(struct ctdb_context *ctdb, struct timeval timeout,
445 struct ctdb_client_control_state *
446 ctdb_ctrl_freeze_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
447 struct timeval timeout, uint32_t destnode);
449 int ctdb_ctrl_freeze_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
450 struct ctdb_client_control_state *state);
452 int ctdb_ctrl_thaw(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
454 int ctdb_ctrl_getpnn(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
456 int ctdb_ctrl_get_tunable(struct ctdb_context *ctdb,
457 struct timeval timeout,
459 const char *name, uint32_t *value);
461 int ctdb_ctrl_set_tunable(struct ctdb_context *ctdb,
462 struct timeval timeout,
464 const char *name, uint32_t value);
466 int ctdb_ctrl_list_tunables(struct ctdb_context *ctdb,
467 struct timeval timeout,
470 const char ***list, uint32_t *count);
472 int ctdb_ctrl_modflags(struct ctdb_context *ctdb,
473 struct timeval timeout,
475 uint32_t set, uint32_t clear);
477 enum ctdb_server_id_type { SERVER_TYPE_SAMBA=1 };
479 struct ctdb_server_id {
480 enum ctdb_server_id_type type;
485 struct ctdb_server_id_list {
487 struct ctdb_server_id server_ids[1];
491 int ctdb_ctrl_register_server_id(struct ctdb_context *ctdb,
492 struct timeval timeout,
493 struct ctdb_server_id *id);
494 int ctdb_ctrl_unregister_server_id(struct ctdb_context *ctdb,
495 struct timeval timeout,
496 struct ctdb_server_id *id);
497 int ctdb_ctrl_check_server_id(struct ctdb_context *ctdb,
498 struct timeval timeout, uint32_t destnode,
499 struct ctdb_server_id *id, uint32_t *status);
500 int ctdb_ctrl_get_server_id_list(struct ctdb_context *ctdb,
502 struct timeval timeout, uint32_t destnode,
503 struct ctdb_server_id_list **svid_list);
506 struct timeval current_time;
507 struct timeval ctdbd_start_time;
508 struct timeval last_recovery_time;
511 int ctdb_socket_connect(struct ctdb_context *ctdb);
514 get the uptime of a remote node
516 int ctdb_ctrl_uptime(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode, struct ctdb_uptime **uptime);
518 struct ctdb_client_control_state *ctdb_ctrl_uptime_send(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct timeval timeout, uint32_t destnode);
520 int ctdb_ctrl_uptime_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, struct ctdb_client_control_state *state, struct ctdb_uptime **uptime);
522 int ctdb_ctrl_end_recovery(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode);
524 int ctdb_ctrl_getreclock(struct ctdb_context *ctdb,
525 struct timeval timeout, uint32_t destnode,
526 TALLOC_CTX *mem_ctx, const char **reclock);
528 uint32_t *list_of_active_nodes(struct ctdb_context *ctdb,
529 struct ctdb_node_map *node_map,
532 uint32_t *list_of_vnnmap_nodes(struct ctdb_context *ctdb,
533 struct ctdb_vnn_map *vnn_map,
537 int ctdb_read_pnn_lock(int fd, int32_t pnn);