2 ctdb database library: old client interface
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/>.
20 #ifndef _CTDB_CLIENT_H
21 #define _CTDB_CLIENT_H
23 #include "common/srvid.h"
24 #include "ctdb_protocol.h"
33 struct ctdb_client_control_state
{
34 struct ctdb_context
*ctdb
;
38 enum control_state state
;
40 struct ctdb_req_control_old
*c
;
42 /* if we have a callback registered for the completion (or failure) of
44 if a callback is used, it MUST talloc_free the cb_data passed to it
47 void (*fn
)(struct ctdb_client_control_state
*);
52 struct tevent_context
;
53 struct ctdb_db_context
;
56 allocate a packet for use in client<->daemon communication
58 struct ctdb_req_header
*_ctdbd_allocate_pkt(struct ctdb_context
*ctdb
,
60 enum ctdb_operation operation
,
61 size_t length
, size_t slength
,
64 #define ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, type) \
65 (type *)_ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, \
68 int ctdb_call_local(struct ctdb_db_context
*ctdb_db
, struct ctdb_call
*call
,
69 struct ctdb_ltdb_header
*header
, TALLOC_CTX
*mem_ctx
,
70 TDB_DATA
*data
, bool updatetdb
);
72 void ctdb_request_message(struct ctdb_context
*ctdb
,
73 struct ctdb_req_header
*hdr
);
75 void ctdb_client_read_cb(uint8_t *data
, size_t cnt
, void *args
);
77 int ctdb_socket_connect(struct ctdb_context
*ctdb
);
80 make a ctdb call. The associated ctdb call function will be called on the DMASTER
83 struct ctdb_client_call_state
*ctdb_call_send(struct ctdb_db_context
*ctdb_db
,
84 struct ctdb_call
*call
);
85 int ctdb_call_recv(struct ctdb_client_call_state
*state
,
86 struct ctdb_call
*call
);
87 int ctdb_call(struct ctdb_db_context
*ctdb_db
, struct ctdb_call
*call
);
89 /* setup a handler for ctdb messages */
90 typedef void (*ctdb_msg_fn_t
)(struct ctdb_context
*, uint64_t srvid
,
91 TDB_DATA data
, void *);
93 int ctdb_client_set_message_handler(struct ctdb_context
*ctdb
, uint64_t srvid
,
94 srvid_handler_fn handler
,
96 int ctdb_client_remove_message_handler(struct ctdb_context
*ctdb
,
97 uint64_t srvid
, void *private_data
);
99 /* send a ctdb message */
100 int ctdb_client_send_message(struct ctdb_context
*ctdb
, uint32_t pnn
,
101 uint64_t srvid
, TDB_DATA data
);
103 struct ctdb_client_control_state
*ctdb_control_send(struct ctdb_context
*ctdb
,
110 struct timeval
*timeout
,
112 int ctdb_control_recv(struct ctdb_context
*ctdb
,
113 struct ctdb_client_control_state
*state
,
114 TALLOC_CTX
*mem_ctx
, TDB_DATA
*outdata
,
115 int32_t *status
, char **errormsg
);
116 int ctdb_control(struct ctdb_context
*ctdb
, uint32_t destnode
, uint64_t srvid
,
117 uint32_t opcode
, uint32_t flags
, TDB_DATA data
,
118 TALLOC_CTX
*mem_ctx
, TDB_DATA
*outdata
, int32_t *status
,
119 struct timeval
*timeout
, char **errormsg
);
121 int ctdb_ctrl_getvnnmap(struct ctdb_context
*ctdb
, struct timeval timeout
,
122 uint32_t destnode
, TALLOC_CTX
*mem_ctx
,
123 struct ctdb_vnn_map
**vnnmap
);
126 get the recovery mode of a remote node
128 struct ctdb_client_control_state
*ctdb_ctrl_getrecmode_send(
129 struct ctdb_context
*ctdb
,
131 struct timeval timeout
,
133 int ctdb_ctrl_getrecmode_recv(struct ctdb_context
*ctdb
, TALLOC_CTX
*mem_ctx
,
134 struct ctdb_client_control_state
*state
,
136 int ctdb_ctrl_getrecmode(struct ctdb_context
*ctdb
, TALLOC_CTX
*mem_ctx
,
137 struct timeval timeout
, uint32_t destnode
,
141 set the recovery mode of a remote node
143 int ctdb_ctrl_setrecmode(struct ctdb_context
*ctdb
, struct timeval timeout
,
144 uint32_t destnode
, uint32_t recmode
);
146 int ctdb_ctrl_getnodemap(struct ctdb_context
*ctdb
, struct timeval timeout
,
147 uint32_t destnode
, TALLOC_CTX
*mem_ctx
,
148 struct ctdb_node_map_old
**nodemap
);
150 int ctdb_ctrl_get_runstate(struct ctdb_context
*ctdb
, struct timeval timeout
,
151 uint32_t destnode
, uint32_t *runstate
);
153 int ctdb_ctrl_get_debuglevel(struct ctdb_context
*ctdb
, uint32_t destnode
,
156 int ctdb_ctrl_freeze(struct ctdb_context
*ctdb
, struct timeval timeout
,
159 int ctdb_ctrl_getpnn(struct ctdb_context
*ctdb
, struct timeval timeout
,
162 int ctdb_ctrl_get_public_ips_flags(struct ctdb_context
*ctdb
,
163 struct timeval timeout
, uint32_t destnode
,
164 TALLOC_CTX
*mem_ctx
, uint32_t flags
,
165 struct ctdb_public_ip_list_old
**ips
);
166 int ctdb_ctrl_get_public_ips(struct ctdb_context
*ctdb
,
167 struct timeval timeout
, uint32_t destnode
,
169 struct ctdb_public_ip_list_old
**ips
);
171 int ctdb_ctrl_get_ifaces(struct ctdb_context
*ctdb
,
172 struct timeval timeout
, uint32_t destnode
,
174 struct ctdb_iface_list_old
**ifaces
);
176 int ctdb_ctrl_get_all_tunables(struct ctdb_context
*ctdb
,
177 struct timeval timeout
, uint32_t destnode
,
178 struct ctdb_tunable_list
*tunables
);
183 void ctdb_set_flags(struct ctdb_context
*ctdb
, unsigned flags
);
185 const char *ctdb_get_socketname(struct ctdb_context
*ctdb
);
187 /* return pnn of this node */
188 uint32_t ctdb_get_pnn(struct ctdb_context
*ctdb
);
190 typedef void (*client_async_callback
)(struct ctdb_context
*ctdb
,
191 uint32_t node_pnn
, int32_t res
,
192 TDB_DATA outdata
, void *callback_data
);
194 struct client_async_data
{
195 enum ctdb_controls opcode
;
196 bool dont_log_errors
;
199 client_async_callback callback
;
200 client_async_callback fail_callback
;
204 void ctdb_client_async_add(struct client_async_data
*data
,
205 struct ctdb_client_control_state
*state
);
206 int ctdb_client_async_wait(struct ctdb_context
*ctdb
,
207 struct client_async_data
*data
);
208 int ctdb_client_async_control(struct ctdb_context
*ctdb
,
209 enum ctdb_controls opcode
, uint32_t *nodes
,
210 uint64_t srvid
, struct timeval timeout
,
211 bool dont_log_errors
, TDB_DATA data
,
212 client_async_callback client_callback
,
213 client_async_callback fail_callback
,
214 void *callback_data
);
216 uint32_t *list_of_vnnmap_nodes(struct ctdb_context
*ctdb
,
217 struct ctdb_vnn_map
*vnn_map
,
218 TALLOC_CTX
*mem_ctx
, bool include_self
);
220 uint32_t *list_of_active_nodes(struct ctdb_context
*ctdb
,
221 struct ctdb_node_map_old
*node_map
,
222 TALLOC_CTX
*mem_ctx
, bool include_self
);
223 uint32_t *list_of_connected_nodes(struct ctdb_context
*ctdb
,
224 struct ctdb_node_map_old
*node_map
,
225 TALLOC_CTX
*mem_ctx
, bool include_self
);
228 get capabilities of a remote node
231 struct ctdb_client_control_state
*ctdb_ctrl_getcapabilities_send(
232 struct ctdb_context
*ctdb
,
234 struct timeval timeout
,
236 int ctdb_ctrl_getcapabilities_recv(struct ctdb_context
*ctdb
,
238 struct ctdb_client_control_state
*state
,
239 uint32_t *capabilities
);
240 int ctdb_ctrl_getcapabilities(struct ctdb_context
*ctdb
,
241 struct timeval timeout
, uint32_t destnode
,
242 uint32_t *capabilities
);
244 struct ctdb_node_capabilities
{
246 uint32_t capabilities
;
249 /* Retrieve capabilities for all connected nodes. The length of the
250 * returned array can be calculated using talloc_array_length(). */
251 struct ctdb_node_capabilities
*ctdb_get_capabilities(
252 struct ctdb_context
*ctdb
,
254 struct timeval timeout
,
255 struct ctdb_node_map_old
*nodemap
);
257 /* Get capabilities for specified node, NULL if not found */
258 uint32_t *ctdb_get_node_capabilities(struct ctdb_node_capabilities
*caps
,
261 /* True if the given node has all of the required capabilities */
262 bool ctdb_node_has_capabilities(struct ctdb_node_capabilities
*caps
,
263 uint32_t pnn
, uint32_t capabilities_required
);
265 int ctdb_ctrl_recd_ping(struct ctdb_context
*ctdb
);
267 int ctdb_ctrl_report_recd_lock_latency(struct ctdb_context
*ctdb
,
268 struct timeval timeout
, double latency
);
270 int ctdb_ctrl_set_ban(struct ctdb_context
*ctdb
, struct timeval timeout
,
271 uint32_t destnode
, struct ctdb_ban_state
*bantime
);
273 struct ctdb_client_control_state
*ctdb_ctrl_updaterecord_send(
274 struct ctdb_context
*ctdb
,
276 struct timeval timeout
,
278 struct ctdb_db_context
*ctdb_db
,
280 struct ctdb_ltdb_header
*header
,
282 int ctdb_ctrl_updaterecord_recv(struct ctdb_context
*ctdb
,
283 struct ctdb_client_control_state
*state
);
284 int ctdb_ctrl_updaterecord(struct ctdb_context
*ctdb
, TALLOC_CTX
*mem_ctx
,
285 struct timeval timeout
, uint32_t destnode
,
286 struct ctdb_db_context
*ctdb_db
, TDB_DATA key
,
287 struct ctdb_ltdb_header
*header
, TDB_DATA data
);
289 #endif /* _CTDB_CLIENT_H */