4 Copyright (C) Ronnie sahlberg 2010
5 Copyright (C) Rusty Russell 2010
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include <sys/types.h>
27 /* All *_send() functions are guaranteed to be non-blocking and fully
28 * asynchronous. The non-_send variants are synchronous. */
31 * Connect to ctdb using the specified domain socket.
32 * Returns a ctdb context if successful or NULL.
34 * Use ctdb_free() to release the returned ctdb_connection when finished.
36 struct ctdb_connection *ctdb_connect(const char *addr);
38 int ctdb_get_fd(struct ctdb_connection *ctdb);
40 int ctdb_which_events(struct ctdb_connection *ctdb);
42 int ctdb_service(struct ctdb_connection *ctdb, int revents);
46 * Special node addresses :
48 /* used on the domain socket, send a pdu to the local daemon */
49 #define CTDB_CURRENT_NODE 0xF0000001
50 /* send a broadcast to all nodes in the cluster, active or not */
51 #define CTDB_BROADCAST_ALL 0xF0000002
52 /* send a broadcast to all nodes in the current vnn map */
53 #define CTDB_BROADCAST_VNNMAP 0xF0000003
54 /* send a broadcast to all connected nodes */
55 #define CTDB_BROADCAST_CONNECTED 0xF0000004
61 * functions to attach to a database
62 * if the database does not exist it will be created.
64 * You have to free the handle with ctdb_detach_db() when finished with it.
68 typedef void (*ctdb_attachdb_cb)(int status, struct ctdb_db *ctdb_db, void *private_data);
71 ctdb_attachdb_send(struct ctdb_connection *ctdb,
72 const char *name, int persistent, uint32_t tdb_flags,
73 ctdb_attachdb_cb callback,
75 struct ctdb_db *ctdb_attachdb(struct ctdb_connection *ctdb,
76 const char *name, int persistent,
82 * functions to read a record from the database
83 * when the callback is invoked, the client will hold an exclusive lock
84 * on the record, the client MUST NOT block during holding this lock and MUST
85 * release it quickly by performing ctdb_release_lock(lock).
87 * When the lock is released, data is freed too, so make sure to copy the data
90 typedef void (*ctdb_readrecordlock_cb)(int status, struct ctdb_lock *lock, TDB_DATA data, void *private_data);
93 ctdb_readrecordlock_send(struct ctdb_db *ctdb_db,
95 ctdb_readrecordlock_cb callback,
97 int ctdb_readrecordlock_recv(struct ctdb_connection *ctdb,
98 struct ctdb_request *handle,
100 int ctdb_readrecordlock(struct ctdb_connection *ctdb,
101 struct ctdb_db *ctdb_db,
108 * Function to write data to a record
109 * This function may ONLY be called while holding a lock to the record
110 * created by ctdb_readrecordlock*
111 * Either from the callback provided to ctdb_readrecordlock_send()
112 * or after calling ctdb_readrecordlock_recv() but before calling
113 * ctdb_release_lock() to release the lock.
115 int ctdb_writerecord(struct ctdb_lock *lock, TDB_DATA data);
118 void ctdb_release_lock(struct ctdb_lock *lock);
121 * messaging functions
122 * these functions provide a messaging layer for applications to communicate
123 * with eachother across
125 typedef void (*ctdb_message_fn_t)(struct ctdb_connection *, uint64_t srvid, TDB_DATA data, void *);
128 * register a message handler and start listening on a service port
130 typedef void (*ctdb_set_message_handler_cb)(int status, void *private_data);
132 struct ctdb_request *
133 ctdb_set_message_handler_send(struct ctdb_connection *ctdb, uint64_t srvid,
134 ctdb_set_message_handler_cb callback,
135 ctdb_message_fn_t handler, void *private_data);
137 int ctdb_set_message_handler_recv(struct ctdb_connection *ctdb,
138 struct ctdb_request *handle);
140 int ctdb_set_message_handler(struct ctdb_connection *ctdb, uint64_t srvid,
141 ctdb_message_fn_t handler, void *private_data);
146 * unregister a message handler and stop listening on teh specified port
148 typedef void (*ctdb_remove_message_handler_cb)(int status, void *private_data);
150 struct ctdb_request *
151 ctdb_remove_message_handler_send(struct ctdb_connection *ctdb, uint64_t srvid,
152 ctdb_remove_message_handler_cb callback,
155 int ctdb_remove_message_handler_recv(struct ctdb_connection *ctdb,
156 struct ctdb_request *handle);
158 int ctdb_remove_message_handler(struct ctdb_connection *ctdb, uint64_t srvid);
163 * send a message to a specific node/port
164 * this function is non-blocking
166 int ctdb_send_message(struct ctdb_connection *ctdb, uint32_t pnn, uint64_t srvid, TDB_DATA data);
171 * functions to read the pnn number of the local node
173 typedef void (*ctdb_getpnn_cb)(int status, uint32_t pnn, void *private_data);
175 struct ctdb_request *
176 ctdb_getpnn_send(struct ctdb_connection *ctdb,
178 ctdb_getpnn_cb callback,
180 int ctdb_getpnn(struct ctdb_connection *ctdb,
188 * functions to read the recovery master of a node
190 typedef void (*ctdb_getrecmaster_cb)(int status,
191 uint32_t recmaster, void *private_data);
193 struct ctdb_request *
194 ctdb_getrecmaster_send(struct ctdb_connection *ctdb,
196 ctdb_getrecmaster_cb callback,
198 int ctdb_getrecmaster_recv(struct ctdb_connection *ctdb,
199 struct ctdb_request *handle,
200 uint32_t *recmaster);
201 int ctdb_getrecmaster(struct ctdb_connection *ctdb,
203 uint32_t *recmaster);
211 int ctdb_cancel(struct ctdb_request *);