summaryrefslogtreecommitdiff
path: root/ctdb/include/ctdb_client.h
blob: 323df7f74743a4cb8c23ec34a4d20af060a2a04a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
/*
   ctdb database library: old client interface

   Copyright (C) Andrew Tridgell  2006

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _CTDB_CLIENT_H
#define _CTDB_CLIENT_H

#include "common/srvid.h"
#include "ctdb_protocol.h"

enum control_state {
	CTDB_CONTROL_WAIT,
	CTDB_CONTROL_DONE,
	CTDB_CONTROL_ERROR,
	CTDB_CONTROL_TIMEOUT
};

struct ctdb_client_control_state {
	struct ctdb_context *ctdb;
	uint32_t reqid;
	int32_t status;
	TDB_DATA outdata;
	enum control_state state;
	char *errormsg;
	struct ctdb_req_control_old *c;

	/* if we have a callback registered for the completion (or failure) of
	   this control
	   if a callback is used, it MUST talloc_free the cb_data passed to it
	*/
	struct {
		void (*fn)(struct ctdb_client_control_state *);
		void *private_data;
	} async;
};

struct tevent_context;
struct ctdb_db_context;

/*
  allocate a packet for use in client<->daemon communication
 */
struct ctdb_req_header *_ctdbd_allocate_pkt(struct ctdb_context *ctdb,
					    TALLOC_CTX *mem_ctx,
					    enum ctdb_operation operation,
					    size_t length, size_t slength,
					    const char *type);

#define ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, type) \
	(type *)_ctdbd_allocate_pkt(ctdb, mem_ctx, operation, length, \
				    sizeof(type), #type)

int ctdb_call_local(struct ctdb_db_context *ctdb_db, struct ctdb_call *call,
		    struct ctdb_ltdb_header *header, TALLOC_CTX *mem_ctx,
		    TDB_DATA *data, bool updatetdb);

void ctdb_request_message(struct ctdb_context *ctdb,
			  struct ctdb_req_header *hdr);

void ctdb_client_read_cb(uint8_t *data, size_t cnt, void *args);

int ctdb_socket_connect(struct ctdb_context *ctdb);

/*
  make a ctdb call. The associated ctdb call function will be called on the DMASTER
  for the given record
*/
struct ctdb_client_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db,
					      struct ctdb_call *call);
int ctdb_call_recv(struct ctdb_client_call_state *state,
		   struct ctdb_call *call);
int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);

/* setup a handler for ctdb messages */
typedef void (*ctdb_msg_fn_t)(struct ctdb_context *, uint64_t srvid,
			      TDB_DATA data, void *);

int ctdb_client_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
				    srvid_handler_fn handler,
				    void *private_data);
int ctdb_client_remove_message_handler(struct ctdb_context *ctdb,
				       uint64_t srvid, void *private_data);

/* send a ctdb message */
int ctdb_client_send_message(struct ctdb_context *ctdb, uint32_t pnn,
			     uint64_t srvid, TDB_DATA data);

struct ctdb_client_control_state *ctdb_control_send(struct ctdb_context *ctdb,
						    uint32_t destnode,
						    uint64_t srvid,
						    uint32_t opcode,
						    uint32_t flags,
						    TDB_DATA data,
						    TALLOC_CTX *mem_ctx,
						    struct timeval *timeout,
						    char **errormsg);
int ctdb_control_recv(struct ctdb_context *ctdb,
		      struct ctdb_client_control_state *state,
		      TALLOC_CTX *mem_ctx, TDB_DATA *outdata,
		      int32_t *status, char **errormsg);
int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint64_t srvid,
		 uint32_t opcode, uint32_t flags, TDB_DATA data,
		 TALLOC_CTX *mem_ctx, TDB_DATA *outdata, int32_t *status,
		 struct timeval *timeout, char **errormsg);

int ctdb_ctrl_getvnnmap(struct ctdb_context *ctdb, struct timeval timeout,
			uint32_t destnode, TALLOC_CTX *mem_ctx,
			struct ctdb_vnn_map **vnnmap);

/*
  get the recovery mode of a remote node
 */
struct ctdb_client_control_state *ctdb_ctrl_getrecmode_send(
					struct ctdb_context *ctdb,
					TALLOC_CTX *mem_ctx,
					struct timeval timeout,
					uint32_t destnode);
int ctdb_ctrl_getrecmode_recv(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
			      struct ctdb_client_control_state *state,
			      uint32_t *recmode);
int ctdb_ctrl_getrecmode(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
			 struct timeval timeout, uint32_t destnode,
			 uint32_t *recmode);

/*
  set the recovery mode of a remote node
 */
int ctdb_ctrl_setrecmode(struct ctdb_context *ctdb, struct timeval timeout,
			 uint32_t destnode, uint32_t recmode);

/*
  get the recovery master of a remote node
 */
struct ctdb_client_control_state *ctdb_ctrl_getrecmaster_send(
					struct ctdb_context *ctdb,
					TALLOC_CTX *mem_ctx,
					struct timeval timeout,
					uint32_t destnode);
int ctdb_ctrl_getrecmaster_recv(struct ctdb_context *ctdb,
				TALLOC_CTX *mem_ctx,
				struct ctdb_client_control_state *state,
				uint32_t *recmaster);
int ctdb_ctrl_getrecmaster(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
			   struct timeval timeout, uint32_t destnode,
			   uint32_t *recmaster);

/*
  set the recovery master of a remote node
 */
int ctdb_ctrl_setrecmaster(struct ctdb_context *ctdb, struct timeval timeout,
			   uint32_t destnode, uint32_t recmaster);

int ctdb_ctrl_getdbmap(struct ctdb_context *ctdb, struct timeval timeout,
		       uint32_t destnode, TALLOC_CTX *mem_ctx,
		       struct ctdb_dbid_map_old **dbmap);

int ctdb_ctrl_getnodemap(struct ctdb_context *ctdb, struct timeval timeout,
			 uint32_t destnode, TALLOC_CTX *mem_ctx,
			 struct ctdb_node_map_old **nodemap);

int ctdb_ctrl_get_runstate(struct ctdb_context *ctdb, struct timeval timeout,
			   uint32_t destnode, uint32_t *runstate);

int ctdb_ctrl_getdbpath(struct ctdb_context *ctdb, struct timeval timeout,
			uint32_t destnode, uint32_t dbid,
			TALLOC_CTX *mem_ctx, const char **path);
int ctdb_ctrl_getdbname(struct ctdb_context *ctdb, struct timeval timeout,
			uint32_t destnode, uint32_t dbid,
			TALLOC_CTX *mem_ctx, const char **name);

int ctdb_ctrl_createdb(struct ctdb_context *ctdb, struct timeval timeout,
		       uint32_t destnode, TALLOC_CTX *mem_ctx,
		       const char *name, uint8_t db_flags, uint32_t *db_id);

int ctdb_ctrl_get_debuglevel(struct ctdb_context *ctdb, uint32_t destnode,
			     int32_t *level);

/*
  attach to a ctdb database
*/
int ctdb_ctrl_db_open_flags(struct ctdb_context *ctdb, uint32_t db_id,
			    int *tdb_flags);

struct ctdb_db_context *ctdb_attach(struct ctdb_context *ctdb,
				    struct timeval timeout,
				    const char *name,
				    uint8_t db_flags);

/* a ctdb call function */
typedef int (*ctdb_fn_t)(struct ctdb_call_info *);

/*
  setup a ctdb call function
*/
int ctdb_set_call(struct ctdb_db_context *ctdb_db, ctdb_fn_t fn, uint32_t id);

int ctdb_ctrl_freeze(struct ctdb_context *ctdb, struct timeval timeout,
		     uint32_t destnode);

int ctdb_ctrl_getpnn(struct ctdb_context *ctdb, struct timeval timeout,
		     uint32_t destnode);

int ctdb_ctrl_get_public_ips_flags(struct ctdb_context *ctdb,
				   struct timeval timeout, uint32_t destnode,
				   TALLOC_CTX *mem_ctx, uint32_t flags,
				   struct ctdb_public_ip_list_old **ips);
int ctdb_ctrl_get_public_ips(struct ctdb_context *ctdb,
			     struct timeval timeout, uint32_t destnode,
			     TALLOC_CTX *mem_ctx,
			     struct ctdb_public_ip_list_old **ips);

int ctdb_ctrl_get_ifaces(struct ctdb_context *ctdb,
			 struct timeval timeout, uint32_t destnode,
			 TALLOC_CTX *mem_ctx,
			 struct ctdb_iface_list_old **ifaces);

int ctdb_ctrl_modflags(struct ctdb_context *ctdb,
		       struct timeval timeout,
		       uint32_t destnode,
		       uint32_t set, uint32_t clear);

int ctdb_ctrl_get_all_tunables(struct ctdb_context *ctdb,
			       struct timeval timeout, uint32_t destnode,
			       struct ctdb_tunable_list *tunables);

/*
  set some flags
*/
void ctdb_set_flags(struct ctdb_context *ctdb, unsigned flags);

int ctdb_set_socketname(struct ctdb_context *ctdb, const char *socketname);
const char *ctdb_get_socketname(struct ctdb_context *ctdb);

/* return pnn of this node */
uint32_t ctdb_get_pnn(struct ctdb_context *ctdb);

typedef void (*client_async_callback)(struct ctdb_context *ctdb,
				      uint32_t node_pnn, int32_t res,
				      TDB_DATA outdata, void *callback_data);

struct client_async_data {
	enum ctdb_controls opcode;
	bool dont_log_errors;
	uint32_t count;
	uint32_t fail_count;
	client_async_callback callback;
	client_async_callback fail_callback;
	void *callback_data;
};

void ctdb_client_async_add(struct client_async_data *data,
			   struct ctdb_client_control_state *state);
int ctdb_client_async_wait(struct ctdb_context *ctdb,
			   struct client_async_data *data);
int ctdb_client_async_control(struct ctdb_context *ctdb,
			      enum ctdb_controls opcode, uint32_t *nodes,
			      uint64_t srvid, struct timeval timeout,
			      bool dont_log_errors, TDB_DATA data,
			      client_async_callback client_callback,
			      client_async_callback fail_callback,
			      void *callback_data);

uint32_t *list_of_vnnmap_nodes(struct ctdb_context *ctdb,
			       struct ctdb_vnn_map *vnn_map,
			       TALLOC_CTX *mem_ctx, bool include_self);

uint32_t *list_of_nodes(struct ctdb_context *ctdb,
			struct ctdb_node_map_old *node_map,
			TALLOC_CTX *mem_ctx, uint32_t mask, int exclude_pnn);
uint32_t *list_of_active_nodes(struct ctdb_context *ctdb,
			       struct ctdb_node_map_old *node_map,
			       TALLOC_CTX *mem_ctx, bool include_self);
uint32_t *list_of_connected_nodes(struct ctdb_context *ctdb,
				  struct ctdb_node_map_old *node_map,
				  TALLOC_CTX *mem_ctx, bool include_self);

/*
  get capabilities of a remote node
 */

struct ctdb_client_control_state *ctdb_ctrl_getcapabilities_send(
					struct ctdb_context *ctdb,
					TALLOC_CTX *mem_ctx,
					struct timeval timeout,
					uint32_t destnode);
int ctdb_ctrl_getcapabilities_recv(struct ctdb_context *ctdb,
				   TALLOC_CTX *mem_ctx,
				   struct ctdb_client_control_state *state,
				   uint32_t *capabilities);
int ctdb_ctrl_getcapabilities(struct ctdb_context *ctdb,
			      struct timeval timeout, uint32_t destnode,
			      uint32_t *capabilities);

struct ctdb_node_capabilities {
	bool retrieved;
	uint32_t capabilities;
};

/* Retrieve capabilities for all connected nodes.  The length of the
 * returned array can be calculated using talloc_array_length(). */
struct ctdb_node_capabilities *ctdb_get_capabilities(
					struct ctdb_context *ctdb,
					TALLOC_CTX *mem_ctx,
					struct timeval timeout,
					struct ctdb_node_map_old *nodemap);

/* Get capabilities for specified node, NULL if not found */
uint32_t *ctdb_get_node_capabilities(struct ctdb_node_capabilities *caps,
				     uint32_t pnn);

/* True if the given node has all of the required capabilities */
bool ctdb_node_has_capabilities(struct ctdb_node_capabilities *caps,
				uint32_t pnn, uint32_t capabilities_required);

int ctdb_ctrl_recd_ping(struct ctdb_context *ctdb);

int ctdb_ctrl_report_recd_lock_latency(struct ctdb_context *ctdb,
				       struct timeval timeout, double latency);

int ctdb_ctrl_set_ban(struct ctdb_context *ctdb, struct timeval timeout,
		      uint32_t destnode, struct ctdb_ban_state *bantime);

struct ctdb_client_control_state *ctdb_ctrl_updaterecord_send(
					struct ctdb_context *ctdb,
					TALLOC_CTX *mem_ctx,
					struct timeval timeout,
					uint32_t destnode,
					struct ctdb_db_context *ctdb_db,
					TDB_DATA key,
					struct ctdb_ltdb_header *header,
					TDB_DATA data);
int ctdb_ctrl_updaterecord_recv(struct ctdb_context *ctdb,
				struct ctdb_client_control_state *state);
int ctdb_ctrl_updaterecord(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx,
			   struct timeval timeout, uint32_t destnode,
			   struct ctdb_db_context *ctdb_db, TDB_DATA key,
			   struct ctdb_ltdb_header *header, TDB_DATA data);

#endif /* _CTDB_CLIENT_H */