4 Copyright (C) Ronnie sahlberg 2010
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 /* Functions are not thread safe so all function calls must be wrapped
24 * inside a pthread_mutex for threaded applications.
26 * All *_send() functions are guaranteed to be non-blocking and fully
29 * The return data from a _send() call can be accessed through two different
32 * 1, by calling *_recv() directly on the handle.
33 * This function will block until the response is received so it
35 * The exception is when called from in the registered callback,
36 * in this case the fucntion is guaranteed not to block.
38 * 2, providing an async callback to be invoked when the call completes.
39 * From inside the callback you use the *_recv() function to extract the
42 * After the *_recv() function returns, the handle will have been destroyed.
46 * Connect to ctdb using the specified domain socket.
47 * Returns a ctdb context if successful or NULL.
49 * Use ctdb_free() to release the returned ctdb_context when finished.
51 struct ctdb_context *ctdb_connect(const char *addr);
53 int ctdb_get_fd(struct ctdb_context *ctdb);
55 int ctdb_which_events(struct ctdb_context *ctdb);
57 int ctdb_service(struct ctdb_context *ctdb);
61 * Special node addresses :
63 /* used on the domain socket, send a pdu to the local daemon */
64 #define CTDB_CURRENT_NODE 0xF0000001
65 /* send a broadcast to all nodes in the cluster, active or not */
66 #define CTDB_BROADCAST_ALL 0xF0000002
67 /* send a broadcast to all nodes in the current vnn map */
68 #define CTDB_BROADCAST_VNNMAP 0xF0000003
69 /* send a broadcast to all connected nodes */
70 #define CTDB_BROADCAST_CONNECTED 0xF0000004
77 typedef void ctdb_handle;
80 typedef void (*ctdb_generic_callback)(int32_t status, struct ctdb_context *ctdb, ctdb_handle *, void *private_data);
84 * functions to attach to a database
85 * if the database does not exist it will be created.
87 * You have to free the handle with ctdb_free() when finished with it.
89 struct ctdb_db_context;
91 typedef void (*ctdb_attachdb_cb)(int32_t status, ctdb_handle *, struct ctdb_db_context *ctdb_db, void *private_data);
94 ctdb_attachdb_send(struct ctdb_context *ctdb,
95 const char *name, int persistent, uint32_t tdb_flags,
96 ctdb_attachdb_cb callback,
98 int ctdb_attachdb_recv(struct ctdb_context *ctdb,
99 ctdb_handle *handle, struct ctdb_db_context **);
100 int ctdb_attachdb(struct ctdb_context *ctdb,
101 const char *name, int persistent, uint32_t tdb_flags,
102 struct ctdb_db_context **);
106 * functions to read a record from the database
107 * when the callback is invoked, the client will hold an exclusive lock
108 * on the record, until the handle is ctdb_free()d.
109 * the client MUST NOT block during holding this lock and MUST
110 * release it quickly by performing ctdb_free(handle).
112 * When the handle is freed, data is freed too, so make sure to copy the data
113 * before freeing the handle.
115 typedef void (*ctdb_readrecordlock_cb)(int32_t status, ctdb_handle *handle, TDB_DATA data, void *private_data);
118 ctdb_readrecordlock_send(struct ctdb_context *ctdb,
119 struct ctdb_db_context *ctdb_db_context,
121 ctdb_readrecordlock_cb callback,
123 int ctdb_readrecordlock_recv(struct ctdb_context *ctdb,
126 int ctdb_readrecordlock(struct ctdb_context *ctdb,
127 struct ctdb_db_context *ctdb_db_context,
134 * Function to write data to a record
135 * This function may ONLY be called while holding a lock to the record
136 * created by ctdb_readrecordlock*
137 * Either from the callback provided to ctdb_readrecordlock_send()
138 * or after calling ctdb_readrecordlock_recv() but before calling
139 * ctdb_free() to release the handle.
141 int ctdb_writerecord(ctdb_handle *handle,
148 Messaging serverid ports
151 a message handler ID meaning "give me all messages"
153 #define CTDB_SRVID_ALL (~(uint64_t)0)
156 The top 32 bits of the server id represents the owner of
157 this part of the srvid space
159 #define CTDB_SRVID_MASK 0xFFFFFFFF00000000LL
163 Samba owns all message handler IDs where the top 32 bits are all zero
165 #define CTDB_SRVID_SAMBA 0x0000000000000000
166 #define CTDB_IS_SAMBA_SRVID ((srvid & CTDB_SRVID_MASK) == CTDB_SRVID_SAMBA)
169 Server ids reserved for testing
171 #define CTDB_SRVID_TEST 0x0000000100000000
172 #define CTDB_IS_TEST_SRVID ((srvid & CTDB_SRVID_MASK) == CTDB_SRVID_TEST)
175 srvid type : RECOVERY
177 #define CTDB_SRVID_RECOVERY 0xF100000000000000LL
180 a message handler ID meaning that the cluster has been reconfigured
182 #define CTDB_SRVID_RECONFIGURE 0xF200000000000000LL
185 a message handler ID meaning that an IP address has been released
187 #define CTDB_SRVID_RELEASE_IP 0xF300000000000000LL
190 a message ID to set the node flags in the recovery daemon
192 #define CTDB_SRVID_SET_NODE_FLAGS 0xF400000000000000LL
195 a message ID to ask the recovery daemon to update the expected node
196 assignment for a public ip
198 #define CTDB_SRVID_RECD_UPDATE_IP 0xF500000000000000LL
201 a message to tell the recovery daemon to fetch a set of records
203 #define CTDB_SRVID_VACUUM_FETCH 0xF700000000000000LL
206 a message to tell the recovery daemon to write a talloc memdump
209 #define CTDB_SRVID_MEM_DUMP 0xF800000000000000LL
212 a message ID to get the recovery daemon to push the node flags out
214 #define CTDB_SRVID_PUSH_NODE_FLAGS 0xF900000000000000LL
217 a message ID to get the recovery daemon to reload the nodes file
219 #define CTDB_SRVID_RELOAD_NODES 0xFA00000000000000LL
222 a message ID to get the recovery daemon to perform a takeover run
224 #define CTDB_SRVID_TAKEOVER_RUN 0xFB00000000000000LL
226 /* A message id to ask the recovery daemon to temporarily disable the
229 #define CTDB_SRVID_DISABLE_IP_CHECK 0xFC00000000000000LL
231 /* A dummy port used for sending back ipreallocate resposnes to the main
234 #define CTDB_SRVID_TAKEOVER_RUN_RESPONSE 0xFD00000000000000LL
236 /* A port reserved for samba (top 32 bits)
238 #define CTDB_SRVID_SAMBA_NOTIFY 0xFE00000000000000LL
241 * messaging functions
242 * these functions provide a messaging layer for applications to communicate
243 * with eachother across
245 typedef void (*ctdb_message_fn_t)(struct ctdb_context *, uint64_t srvid, TDB_DATA data, void *);
248 * register a message handler and start listening on a service port
250 typedef void (*ctdb_set_message_handler_cb)(int32_t status, void *private_data);
253 ctdb_set_message_handler_send(struct ctdb_context *ctdb, uint64_t srvid,
254 ctdb_set_message_handler_cb callback,
255 ctdb_message_fn_t handler, void *private_data);
257 int ctdb_set_message_handler_recv(struct ctdb_context *ctdb,
258 ctdb_handle *handle);
260 int ctdb_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
261 ctdb_message_fn_t handler, void *private_data);
266 * unregister a message handler and stop listening on teh specified port
268 typedef void (*ctdb_remove_message_handler_cb)(int32_t status, void *private_data);
271 ctdb_remove_message_handler_send(struct ctdb_context *ctdb, uint64_t srvid,
272 ctdb_remove_message_handler_cb callback,
275 int ctdb_remove_message_handler_recv(struct ctdb_context *ctdb,
276 ctdb_handle *handle);
278 int ctdb_remove_message_handler(struct ctdb_context *ctdb, uint64_t srvid);
283 * send a message to a specific node/port
284 * this function is non-blocking
286 int ctdb_send_message(struct ctdb_context *ctdb, uint32_t pnn, uint64_t srvid, TDB_DATA data);
292 * functions to read the pnn number of the local node
295 ctdb_getpnn_send(struct ctdb_context *ctdb,
297 ctdb_generic_callback callback,
299 int ctdb_getpnn_recv(struct ctdb_context *ctdb,
302 int ctdb_getpnn(struct ctdb_context *ctdb,
310 * functions to read the recovery master of a node
313 ctdb_getrecmaster_send(struct ctdb_context *ctdb,
315 ctdb_generic_callback callback,
317 int ctdb_getrecmaster_recv(struct ctdb_context *ctdb,
319 uint32_t *recmaster);
320 int ctdb_getrecmaster(struct ctdb_context *ctdb,
322 uint32_t *recmaster);
328 * cancel a request/call or release a resource
330 int ctdb_free(ctdb_handle *);