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>
28 /* All *_send() functions are guaranteed to be non-blocking and fully
29 * asynchronous. The non-_send variants are synchronous. */
32 * Connect to ctdb using the specified domain socket.
33 * Returns a ctdb context if successful or NULL.
35 * Use ctdb_free() to release the returned ctdb_connection when finished.
37 struct ctdb_connection *ctdb_connect(const char *addr);
39 int ctdb_get_fd(struct ctdb_connection *ctdb);
41 int ctdb_which_events(struct ctdb_connection *ctdb);
43 int ctdb_service(struct ctdb_connection *ctdb, int revents);
47 void ctdb_request_free(struct ctdb_request *req);
50 * Callback for completed requests: it would normally unpack the request
51 * using ctdb_*_recv(). You must free the request using ctdb_request_free().
53 * Note that due to macro magic, your callback doesn't have to take void *,
54 * it can take a type which matches the actual private parameter.
56 typedef void (*ctdb_callback_t)(struct ctdb_connection *ctdb,
57 struct ctdb_request *req, void *private);
60 * Special node addresses :
62 /* used on the domain socket, send a pdu to the local daemon */
63 #define CTDB_CURRENT_NODE 0xF0000001
64 /* send a broadcast to all nodes in the cluster, active or not */
65 #define CTDB_BROADCAST_ALL 0xF0000002
66 /* send a broadcast to all nodes in the current vnn map */
67 #define CTDB_BROADCAST_VNNMAP 0xF0000003
68 /* send a broadcast to all connected nodes */
69 #define CTDB_BROADCAST_CONNECTED 0xF0000004
73 * functions to attach to a database
74 * if the database does not exist it will be created.
76 * You have to free the handle with ctdb_detach_db() when finished with it.
81 ctdb_attachdb_send(struct ctdb_connection *ctdb,
82 const char *name, int persistent, uint32_t tdb_flags,
83 ctdb_callback_t callback, void *private_data);
85 struct ctdb_db *ctdb_attachdb_recv(struct ctdb_request *req);
87 struct ctdb_db *ctdb_attachdb(struct ctdb_connection *ctdb,
88 const char *name, int persistent,
94 * functions to read a record from the database
95 * when the callback is invoked, the client will hold an exclusive lock
96 * on the record, the client MUST NOT block during holding this lock and MUST
97 * release it quickly by performing ctdb_release_lock(lock).
99 * When the lock is released, data is freed too, so make sure to copy the data
102 * This returns true on success, and req will be non-NULL if a request was
103 * actually sent, otherwise callback will have already been called.
106 ctdb_readrecordlock_send(struct ctdb_db *ctdb_db, TDB_DATA key,
107 struct ctdb_request **req,
108 ctdb_callback_t callback, void *private_data);
109 struct ctdb_lock *ctdb_readrecordlock_recv(struct ctdb_db *ctdb_db,
110 struct ctdb_request *handle,
113 /* Returns null on failure. */
114 struct ctdb_lock *ctdb_readrecordlock(struct ctdb_db *ctdb_db, TDB_DATA key,
118 * Function to write data to a record
119 * This function may ONLY be called while holding a lock to the record
120 * created by ctdb_readrecordlock*
121 * Either from the callback provided to ctdb_readrecordlock_send()
122 * or after calling ctdb_readrecordlock_recv() but before calling
123 * ctdb_release_lock() to release the lock.
125 int ctdb_writerecord(struct ctdb_lock *lock, TDB_DATA data);
128 void ctdb_release_lock(struct ctdb_lock *lock);
131 * messaging functions
132 * these functions provide a messaging layer for applications to communicate
133 * with eachother across
135 typedef void (*ctdb_message_fn_t)(struct ctdb_connection *, uint64_t srvid, TDB_DATA data, void *);
137 struct ctdb_request *
138 ctdb_set_message_handler_send(struct ctdb_connection *ctdb, uint64_t srvid,
139 ctdb_message_fn_t handler,
140 ctdb_callback_t callback,
143 int ctdb_set_message_handler_recv(struct ctdb_connection *ctdb,
144 struct ctdb_request *handle);
146 int ctdb_set_message_handler(struct ctdb_connection *ctdb, uint64_t srvid,
147 ctdb_message_fn_t handler, void *private_data);
152 * unregister a message handler and stop listening on teh specified port
154 struct ctdb_request *
155 ctdb_remove_message_handler_send(struct ctdb_connection *ctdb, uint64_t srvid,
156 ctdb_callback_t callback,
159 int ctdb_remove_message_handler_recv(struct ctdb_request *handle);
161 int ctdb_remove_message_handler(struct ctdb_connection *ctdb, uint64_t srvid);
166 * send a message to a specific node/port
167 * this function is non-blocking
169 int ctdb_send_message(struct ctdb_connection *ctdb, uint32_t pnn, uint64_t srvid, TDB_DATA data);
174 * functions to read the pnn number of the local node
176 struct ctdb_request *
177 ctdb_getpnn_send(struct ctdb_connection *ctdb,
179 ctdb_callback_t callback,
181 int ctdb_getpnn_recv(struct ctdb_request *req, uint32_t *pnn);
183 int ctdb_getpnn(struct ctdb_connection *ctdb,
191 * functions to read the recovery master of a node
193 struct ctdb_request *
194 ctdb_getrecmaster_send(struct ctdb_connection *ctdb,
196 ctdb_callback_t callback,
198 int ctdb_getrecmaster_recv(struct ctdb_request *handle,
199 uint32_t *recmaster);
200 int ctdb_getrecmaster(struct ctdb_connection *ctdb,
202 uint32_t *recmaster);
210 int ctdb_cancel(struct ctdb_request *);
213 /* These ugly macro wrappers make the callbacks typesafe. */
214 #include <ctdb_typesafe_cb.h>
215 #define ctdb_sendcb(cb, cbdata) \
216 typesafe_cb_preargs(void, (cb), (cbdata), \
217 struct ctdb_connection *, struct ctdb_request *)
219 #define ctdb_attachdb_send(ctdb, name, persistent, tdb_flags, cb, cbdata) \
220 ctdb_attachdb_send((ctdb), (name), (persistent), (tdb_flags), \
221 ctdb_sendcb((cb), (cbdata)), (cbdata))
223 #define ctdb_readrecordlock_send(ctdb_db, key, reqp, cb, cbdata) \
224 ctdb_readrecordlock_send((ctdb_db), (key), (reqp), \
225 ctdb_sendcb((cb), (cbdata)), (cbdata))
227 #define ctdb_set_message_handler_send(ctdb, srvid, handler, cb, cbdata) \
228 ctdb_set_message_handler_send((ctdb), (srvid), (handler), \
229 ctdb_sendcb((cb), (cbdata)), (cbdata))
231 #define ctdb_remove_message_handler_send(ctdb, srvid, cb, cbdata) \
232 ctdb_remove_message_handler_send((ctdb), (srvid), \
233 ctdb_sendcb((cb), (cbdata)), (cbdata))
235 #define ctdb_getpnn_send(ctdb, destnode, cb, cbdata) \
236 ctdb_getpnn_send((ctdb), (destnode), \
237 ctdb_sendcb((cb), (cbdata)), (cbdata))
239 #define ctdb_getrecmaster_send(ctdb, destnode, cb, cbdata) \
240 ctdb_getrecmaster_send((ctdb), (destnode), \
241 ctdb_sendcb((cb), (cbdata)), (cbdata))