tools/ctdb: Do not use libctdb for commandline tool
[ctdb.git] / include / ctdb_protocol.h
1 /*
2    ctdb database library
3
4    Copyright (C) Andrew Tridgell  2006
5
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.
10
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.
15
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/>.
18 */
19
20 #ifndef _CTDB_PROTOCOL_H
21 #define _CTDB_PROTOCOL_H
22
23 /* location of daemon socket, set at configure time */
24 #ifdef SOCKPATH
25 #define CTDB_PATH       SOCKPATH
26 #else
27 #define CTDB_PATH       "/tmp/ctdb.socket"
28 #endif
29
30 /* default ctdb port number */
31 #define CTDB_PORT 4379
32
33 /* we must align packets to ensure ctdb works on all architectures (eg. sparc) */
34 #define CTDB_DS_ALIGNMENT 8
35
36
37 #define CTDB_NULL_FUNC                  0xFF000001
38 #define CTDB_FETCH_FUNC                 0xFF000002
39 #define CTDB_FETCH_WITH_HEADER_FUNC     0xFF000003
40
41
42 struct ctdb_call {
43         int call_id;
44         TDB_DATA key;
45         TDB_DATA call_data;
46         TDB_DATA reply_data;
47         uint32_t status;
48 #define CTDB_IMMEDIATE_MIGRATION                0x00000001
49 #define CTDB_CALL_FLAG_VACUUM_MIGRATION         0x00000002
50 #define CTDB_WANT_READONLY                      0x00000004
51         uint32_t flags;
52 };
53
54 /*
55   structure passed to a ctdb call backend function
56 */
57 struct ctdb_call_info {
58         TDB_DATA key;          /* record key */
59         struct ctdb_ltdb_header *header;
60         TDB_DATA record_data;  /* current data in the record */
61         TDB_DATA *new_data;    /* optionally updated record data */
62         TDB_DATA *call_data;   /* optionally passed from caller */
63         TDB_DATA *reply_data;  /* optionally returned by function */
64         uint32_t status;       /* optional reply status - defaults to zero */
65 };
66
67 #define CTDB_ERR_INVALID 1
68 #define CTDB_ERR_NOMEM 2
69
70 /*
71   ctdb flags
72 */
73 #define CTDB_FLAG_TORTURE      (1<<1)
74
75 /*
76    a message handler ID meaning "give me all messages"
77  */
78 #define CTDB_SRVID_ALL (~(uint64_t)0)
79
80 /*
81   srvid type : RECOVERY
82 */
83 #define CTDB_SRVID_RECOVERY     0xF100000000000000LL
84
85 /*
86    a message handler ID meaning that the cluster has been reconfigured
87  */
88 #define CTDB_SRVID_RECONFIGURE 0xF200000000000000LL
89
90 /*
91    a message handler ID meaning that an IP address has been released
92  */
93 #define CTDB_SRVID_RELEASE_IP 0xF300000000000000LL
94
95 /*
96    a message handler ID meaning that an IP address has been taken
97  */
98 #define CTDB_SRVID_TAKE_IP 0xF301000000000000LL
99
100 /*
101    a message ID to set the node flags in the recovery daemon
102  */
103 #define CTDB_SRVID_SET_NODE_FLAGS 0xF400000000000000LL
104
105 /*
106    a message ID to ask the recovery daemon to update the expected node
107    assignment for a public ip
108  */
109 #define CTDB_SRVID_RECD_UPDATE_IP 0xF500000000000000LL
110
111 /*
112   a message to tell the recovery daemon to fetch a set of records
113  */
114 #define CTDB_SRVID_VACUUM_FETCH 0xF700000000000000LL
115
116 /*
117   a message to tell the recovery daemon to write a talloc memdump
118   to the log
119  */
120 #define CTDB_SRVID_MEM_DUMP 0xF800000000000000LL
121
122 /* A message id used to ask the recover daemon to send logs
123 */
124 #define CTDB_SRVID_GETLOG  0xF801000000000000LL
125
126 /* A message id used to ask the recover daemon to send logs
127 */
128 #define CTDB_SRVID_CLEARLOG  0xF802000000000000LL
129
130 /*
131    a message ID to get the recovery daemon to push the node flags out
132  */
133 #define CTDB_SRVID_PUSH_NODE_FLAGS 0xF900000000000000LL
134
135 /*
136    a message ID to get the recovery daemon to reload the nodes file
137  */
138 #define CTDB_SRVID_RELOAD_NODES 0xFA00000000000000LL
139
140 /*
141    a message ID to get the recovery daemon to perform a takeover run
142  */
143 #define CTDB_SRVID_TAKEOVER_RUN 0xFB00000000000000LL
144
145 /* request recovery daemon to rebalance ips for a node.
146    input is uint32_t for the node id.
147 */
148 #define CTDB_SRVID_REBALANCE_NODE 0xFB01000000000000LL
149
150 /* A message handler ID to stop takeover runs from occurring */
151 #define CTDB_SRVID_DISABLE_TAKEOVER_RUNS 0xFB03000000000000LL
152
153 /* A message id to ask the recovery daemon to temporarily disable the
154    public ip checks
155 */
156 #define CTDB_SRVID_DISABLE_IP_CHECK  0xFC00000000000000LL
157
158 /* A dummy port used for sending back ipreallocate resposnes to the main
159    daemon
160 */
161 #define CTDB_SRVID_TAKEOVER_RUN_RESPONSE  0xFD00000000000000LL
162
163 /* A range of ports reserved for registering a PID (top 8 bits)
164  * All ports matching the 8 top bits are reserved for exclusive use by
165  * registering a SRVID that matches the process-id of the requesting process
166  */
167 #define CTDB_SRVID_PID_RANGE   0x0000000000000000LL
168
169 /* A range of ports reserved for samba (top 8 bits)
170  * All ports matching the 8 top bits are reserved for exclusive use by
171  * CIFS server
172  */
173 #define CTDB_SRVID_SAMBA_NOTIFY  0xFE00000000000000LL
174 #define CTDB_SRVID_SAMBA_RANGE   0xFE00000000000000LL
175
176 /* A range of ports reserved for a CTDB NFS server (top 8 bits)
177  * All ports matching the 8 top bits are reserved for exclusive use by
178  * NFS server
179  */
180 #define CTDB_SRVID_NFSD_RANGE  0xEE00000000000000LL
181
182 /* A range of ports reserved for a CTDB ISCSI server (top 8 bits)
183  * All ports matching the 8 top bits are reserved for exclusive use by
184  * ISCSI server
185  */
186 #define CTDB_SRVID_ISCSID_RANGE  0xDE00000000000000LL
187
188 /* A range of ports reserved for testing (top 8 bits)
189  * All ports matching the 8 top bits are reserved for exclusive use by
190  * test applications
191  */
192 #define CTDB_SRVID_TEST_RANGE  0xCE00000000000000LL
193
194 /* Range of ports reserved for traversals */
195 #define CTDB_SRVID_TRAVERSE_RANGE  0xBE00000000000000LL
196
197 /* used on the domain socket, send a pdu to the local daemon */
198 #define CTDB_CURRENT_NODE     0xF0000001
199 /* send a broadcast to all nodes in the cluster, active or not */
200 #define CTDB_BROADCAST_ALL    0xF0000002
201 /* send a broadcast to all nodes in the current vnn map */
202 #define CTDB_BROADCAST_VNNMAP 0xF0000003
203 /* send a broadcast to all connected nodes */
204 #define CTDB_BROADCAST_CONNECTED 0xF0000004
205 /* send a broadcast to selected connected nodes */
206 #define CTDB_MULTICAST 0xF0000005
207
208 /* the key used for transaction locking on persistent databases */
209 #define CTDB_TRANSACTION_LOCK_KEY "__transaction_lock__"
210
211 /* the key used to store persistent db sequence number */
212 #define CTDB_DB_SEQNUM_KEY "__db_sequence_number__"
213
214 #define MONITOR_SCRIPT_OK      0
215 #define MONITOR_SCRIPT_TIMEOUT 1
216
217 #define MAX_SCRIPT_NAME 31
218 #define MAX_SCRIPT_OUTPUT 511
219 struct ctdb_script_wire {
220         char name[MAX_SCRIPT_NAME+1];
221         struct timeval start;
222         struct timeval finished;
223         int32_t status;
224         char output[MAX_SCRIPT_OUTPUT+1];
225 };
226
227 struct ctdb_scripts_wire {
228         uint32_t num_scripts;
229         struct ctdb_script_wire scripts[1];
230 };
231
232 /* different calls to event scripts. */
233 enum ctdb_eventscript_call {
234         CTDB_EVENT_INIT,                /* CTDB starting up: no args */
235         CTDB_EVENT_SETUP,               /* CTDB starting up after transport is readdy: no args. */
236         CTDB_EVENT_STARTUP,             /* CTDB starting up after initial recovery: no args. */
237         CTDB_EVENT_START_RECOVERY,      /* CTDB recovery starting: no args. */
238         CTDB_EVENT_RECOVERED,           /* CTDB recovery finished: no args. */
239         CTDB_EVENT_TAKE_IP,             /* IP taken: interface, IP address, netmask bits. */
240         CTDB_EVENT_RELEASE_IP,          /* IP released: interface, IP address, netmask bits. */
241         CTDB_EVENT_STOPPED,             /* Deprecated, do not use. */
242         CTDB_EVENT_MONITOR,             /* Please check if service is healthy: no args. */
243         CTDB_EVENT_STATUS,              /* Report service status: no args. */
244         CTDB_EVENT_SHUTDOWN,            /* CTDB shutting down: no args. */
245         CTDB_EVENT_RELOAD,              /* magic */
246         CTDB_EVENT_UPDATE_IP,           /* IP updating: old interface, new interface, IP address, netmask bits. */
247         CTDB_EVENT_IPREALLOCATED,       /* when a takeover_run() completes */
248         CTDB_EVENT_MAX
249 };
250
251 /* Mapping from enum to names. */
252 extern const char *ctdb_eventscript_call_names[];
253
254 /*
255   operation IDs
256 */
257 enum ctdb_operation {
258         CTDB_REQ_CALL           = 0,
259         CTDB_REPLY_CALL         = 1,
260         CTDB_REQ_DMASTER        = 2,
261         CTDB_REPLY_DMASTER      = 3,
262         CTDB_REPLY_ERROR        = 4,
263         CTDB_REQ_MESSAGE        = 5,
264         /* #6 removed */
265         CTDB_REQ_CONTROL        = 7,
266         CTDB_REPLY_CONTROL      = 8,
267         CTDB_REQ_KEEPALIVE      = 9,
268 };
269
270 #define CTDB_MAGIC 0x43544442 /* CTDB */
271 #define CTDB_VERSION 1
272
273 enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS          = 0,
274                     CTDB_CONTROL_STATISTICS              = 1,
275                     /* #2 removed */
276                     CTDB_CONTROL_PING                    = 3,
277                     CTDB_CONTROL_GETDBPATH               = 4,
278                     CTDB_CONTROL_GETVNNMAP               = 5,
279                     CTDB_CONTROL_SETVNNMAP               = 6,
280                     CTDB_CONTROL_GET_DEBUG               = 7,
281                     CTDB_CONTROL_SET_DEBUG               = 8,
282                     CTDB_CONTROL_GET_DBMAP               = 9,
283                     CTDB_CONTROL_GET_NODEMAPv4           = 10, /* obsolete */
284                     CTDB_CONTROL_SET_DMASTER             = 11, /* obsolete */
285                     /* #12 removed */
286                     CTDB_CONTROL_PULL_DB                 = 13,
287                     CTDB_CONTROL_PUSH_DB                 = 14,
288                     CTDB_CONTROL_GET_RECMODE             = 15,
289                     CTDB_CONTROL_SET_RECMODE             = 16,
290                     CTDB_CONTROL_STATISTICS_RESET        = 17,
291                     CTDB_CONTROL_DB_ATTACH               = 18,
292                     CTDB_CONTROL_SET_CALL                = 19,
293                     CTDB_CONTROL_TRAVERSE_START          = 20,
294                     CTDB_CONTROL_TRAVERSE_ALL            = 21,
295                     CTDB_CONTROL_TRAVERSE_DATA           = 22,
296                     CTDB_CONTROL_REGISTER_SRVID          = 23,
297                     CTDB_CONTROL_DEREGISTER_SRVID        = 24,
298                     CTDB_CONTROL_GET_DBNAME              = 25,
299                     CTDB_CONTROL_ENABLE_SEQNUM           = 26,
300                     CTDB_CONTROL_UPDATE_SEQNUM           = 27,
301                     /* #28 removed */
302                     CTDB_CONTROL_DUMP_MEMORY             = 29,
303                     CTDB_CONTROL_GET_PID                 = 30,
304                     CTDB_CONTROL_GET_RECMASTER           = 31,
305                     CTDB_CONTROL_SET_RECMASTER           = 32,
306                     CTDB_CONTROL_FREEZE                  = 33,
307                     CTDB_CONTROL_THAW                    = 34,
308                     CTDB_CONTROL_GET_PNN                 = 35,
309                     CTDB_CONTROL_SHUTDOWN                = 36,
310                     CTDB_CONTROL_GET_MONMODE             = 37,
311                     /* #38 removed */
312                     /* #39 removed */
313                     /* #40 removed */
314                     /* #41 removed */
315                     CTDB_CONTROL_TAKEOVER_IPv4           = 42, /* obsolete */
316                     CTDB_CONTROL_RELEASE_IPv4            = 43, /* obsolete */
317                     CTDB_CONTROL_TCP_CLIENT              = 44,
318                     CTDB_CONTROL_TCP_ADD                 = 45,
319                     CTDB_CONTROL_TCP_REMOVE              = 46,
320                     CTDB_CONTROL_STARTUP                 = 47,
321                     CTDB_CONTROL_SET_TUNABLE             = 48,
322                     CTDB_CONTROL_GET_TUNABLE             = 49,
323                     CTDB_CONTROL_LIST_TUNABLES           = 50,
324                     CTDB_CONTROL_GET_PUBLIC_IPSv4        = 51, /* obsolete */
325                     CTDB_CONTROL_MODIFY_FLAGS            = 52,
326                     CTDB_CONTROL_GET_ALL_TUNABLES        = 53,
327                     CTDB_CONTROL_KILL_TCP                = 54,
328                     CTDB_CONTROL_GET_TCP_TICKLE_LIST     = 55,
329                     CTDB_CONTROL_SET_TCP_TICKLE_LIST     = 56,
330                     CTDB_CONTROL_REGISTER_SERVER_ID      = 57,
331                     CTDB_CONTROL_UNREGISTER_SERVER_ID    = 58,
332                     CTDB_CONTROL_CHECK_SERVER_ID         = 59,
333                     CTDB_CONTROL_GET_SERVER_ID_LIST      = 60,
334                     CTDB_CONTROL_DB_ATTACH_PERSISTENT    = 61,
335                     CTDB_CONTROL_PERSISTENT_STORE        = 62,
336                     CTDB_CONTROL_UPDATE_RECORD           = 63,
337                     CTDB_CONTROL_SEND_GRATIOUS_ARP       = 64,
338                     CTDB_CONTROL_TRANSACTION_START       = 65,
339                     CTDB_CONTROL_TRANSACTION_COMMIT      = 66,
340                     CTDB_CONTROL_WIPE_DATABASE           = 67,
341                     /* #68 removed */
342                     CTDB_CONTROL_UPTIME                  = 69,
343                     CTDB_CONTROL_START_RECOVERY          = 70,
344                     CTDB_CONTROL_END_RECOVERY            = 71,
345                     CTDB_CONTROL_RELOAD_NODES_FILE       = 72,
346                     /* #73 removed */
347                     CTDB_CONTROL_TRY_DELETE_RECORDS      = 74,
348                     CTDB_CONTROL_ENABLE_MONITOR          = 75,
349                     CTDB_CONTROL_DISABLE_MONITOR         = 76,
350                     CTDB_CONTROL_ADD_PUBLIC_IP           = 77,
351                     CTDB_CONTROL_DEL_PUBLIC_IP           = 78,
352                     CTDB_CONTROL_RUN_EVENTSCRIPTS        = 79,
353                     CTDB_CONTROL_GET_CAPABILITIES        = 80,
354                     CTDB_CONTROL_START_PERSISTENT_UPDATE = 81,
355                     CTDB_CONTROL_CANCEL_PERSISTENT_UPDATE= 82,
356                     CTDB_CONTROL_TRANS2_COMMIT           = 83,
357                     CTDB_CONTROL_TRANS2_FINISHED         = 84,
358                     CTDB_CONTROL_TRANS2_ERROR            = 85,
359                     CTDB_CONTROL_TRANS2_COMMIT_RETRY     = 86,
360                     CTDB_CONTROL_RECD_PING               = 87,
361                     CTDB_CONTROL_RELEASE_IP              = 88,
362                     CTDB_CONTROL_TAKEOVER_IP             = 89,
363                     CTDB_CONTROL_GET_PUBLIC_IPS          = 90,
364                     CTDB_CONTROL_GET_NODEMAP             = 91,
365                     CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS = 96,
366                     CTDB_CONTROL_TRAVERSE_KILL           = 97,
367                     CTDB_CONTROL_RECD_RECLOCK_LATENCY    = 98,
368                     CTDB_CONTROL_GET_RECLOCK_FILE        = 99,
369                     CTDB_CONTROL_SET_RECLOCK_FILE        = 100,
370                     CTDB_CONTROL_STOP_NODE               = 101,
371                     CTDB_CONTROL_CONTINUE_NODE           = 102,
372                     CTDB_CONTROL_SET_NATGWSTATE          = 103,
373                     CTDB_CONTROL_SET_LMASTERROLE         = 104,
374                     CTDB_CONTROL_SET_RECMASTERROLE       = 105,
375                     CTDB_CONTROL_ENABLE_SCRIPT           = 107,
376                     CTDB_CONTROL_DISABLE_SCRIPT          = 108,
377                     CTDB_CONTROL_SET_BAN_STATE           = 109,
378                     CTDB_CONTROL_GET_BAN_STATE           = 110,
379                     CTDB_CONTROL_SET_DB_PRIORITY         = 111,
380                     CTDB_CONTROL_GET_DB_PRIORITY         = 112,
381                     CTDB_CONTROL_TRANSACTION_CANCEL      = 113,
382                     CTDB_CONTROL_REGISTER_NOTIFY         = 114,
383                     CTDB_CONTROL_DEREGISTER_NOTIFY       = 115,
384                     CTDB_CONTROL_TRANS2_ACTIVE           = 116,
385                     CTDB_CONTROL_GET_LOG                 = 117,
386                     CTDB_CONTROL_CLEAR_LOG               = 118,
387                     CTDB_CONTROL_TRANS3_COMMIT           = 119,
388                     CTDB_CONTROL_GET_DB_SEQNUM           = 120,
389                     CTDB_CONTROL_DB_SET_HEALTHY          = 121,
390                     CTDB_CONTROL_DB_GET_HEALTH           = 122,
391                     CTDB_CONTROL_GET_PUBLIC_IP_INFO      = 123,
392                     CTDB_CONTROL_GET_IFACES              = 124,
393                     CTDB_CONTROL_SET_IFACE_LINK_STATE    = 125,
394                     CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE  = 126,
395                     CTDB_CONTROL_GET_STAT_HISTORY        = 127,
396                     CTDB_CONTROL_SCHEDULE_FOR_DELETION   = 128,
397                     CTDB_CONTROL_SET_DB_READONLY         = 129,
398                     CTDB_CONTROL_CHECK_SRVIDS            = 130,
399                     CTDB_CONTROL_TRAVERSE_START_EXT      = 131,
400                     CTDB_CONTROL_GET_DB_STATISTICS       = 132,
401                     CTDB_CONTROL_SET_DB_STICKY           = 133,
402                     CTDB_CONTROL_RELOAD_PUBLIC_IPS       = 134,
403                     CTDB_CONTROL_TRAVERSE_ALL_EXT        = 135,
404                     CTDB_CONTROL_RECEIVE_RECORDS         = 136,
405                     CTDB_CONTROL_IPREALLOCATED           = 137,
406                     CTDB_CONTROL_GET_RUNSTATE            = 138,
407 };
408
409 /*
410   packet structures
411 */
412 struct ctdb_req_header {
413         uint32_t length;
414         uint32_t ctdb_magic;
415         uint32_t ctdb_version;
416         uint32_t generation;
417         uint32_t operation;
418         uint32_t destnode;
419         uint32_t srcnode;
420         uint32_t reqid;
421 };
422
423 struct ctdb_req_call {
424         struct ctdb_req_header hdr;
425         uint32_t flags;
426         uint32_t db_id;
427         uint32_t callid;
428         uint32_t hopcount;
429         uint32_t keylen;
430         uint32_t calldatalen;
431         uint8_t data[1]; /* key[] followed by calldata[] */
432 };
433
434 struct ctdb_reply_call {
435         struct ctdb_req_header hdr;
436         uint32_t status;
437         uint32_t datalen;
438         uint8_t  data[1];
439 };
440
441 struct ctdb_reply_error {
442         struct ctdb_req_header hdr;
443         uint32_t status;
444         uint32_t msglen;
445         uint8_t  msg[1];
446 };
447
448 struct ctdb_req_dmaster {
449         struct ctdb_req_header hdr;
450         uint32_t db_id;
451         uint64_t rsn;
452         uint32_t dmaster;
453         uint32_t keylen;
454         uint32_t datalen;
455         uint8_t  data[1];
456 };
457
458 struct ctdb_reply_dmaster {
459         struct ctdb_req_header hdr;
460         uint32_t db_id;
461         uint64_t rsn;
462         uint32_t keylen;
463         uint32_t datalen;
464         uint8_t  data[1];
465 };
466
467 struct ctdb_req_message {
468         struct ctdb_req_header hdr;
469         uint64_t srvid;
470         uint32_t datalen;
471         uint8_t data[1];
472 };
473
474 struct ctdb_req_getdbpath {
475         struct ctdb_req_header hdr;
476         uint32_t db_id;
477 };
478
479 struct ctdb_reply_getdbpath {
480         struct ctdb_req_header hdr;
481         uint32_t datalen;
482         uint8_t data[1];
483 };
484
485 struct ctdb_req_control {
486         struct ctdb_req_header hdr;
487         uint32_t opcode;
488         uint32_t pad;
489         uint64_t srvid;
490         uint32_t client_id;
491 #define CTDB_CTRL_FLAG_NOREPLY   1
492 #define CTDB_CTRL_FLAG_OPCODE_SPECIFIC   0xFFFF0000
493         uint32_t flags;
494         uint32_t datalen;
495         uint8_t data[1];
496 };
497
498 struct ctdb_reply_control {
499         struct ctdb_req_header hdr;
500         int32_t  status;
501         uint32_t datalen;
502         uint32_t errorlen;
503         uint8_t data[1];
504 };
505
506 struct ctdb_req_keepalive {
507         struct ctdb_req_header hdr;
508 };
509
510
511 /* types of failures possible from TRANS2_COMMIT */
512 enum ctdb_trans2_commit_error {
513         CTDB_TRANS2_COMMIT_SUCCESS=0, /* all nodes committed successfully */
514         CTDB_TRANS2_COMMIT_TIMEOUT=1, /* at least one node timed out */
515         CTDB_TRANS2_COMMIT_ALLFAIL=2, /* all nodes failed the commit */
516         CTDB_TRANS2_COMMIT_SOMEFAIL=3 /* some nodes failed the commit, some allowed it */
517 };
518
519 /*
520   the extended header for records in the ltdb
521 */
522 struct ctdb_ltdb_header {
523         uint64_t rsn;
524         uint32_t dmaster;
525         uint32_t reserved1;
526 #define CTDB_REC_FLAG_DEFAULT                   0x00000000
527 #define CTDB_REC_FLAG_MIGRATED_WITH_DATA        0x00010000
528 #define CTDB_REC_FLAG_VACUUM_MIGRATED           0x00020000
529 #define CTDB_REC_FLAG_AUTOMATIC                 0x00040000
530 #define CTDB_REC_RO_HAVE_DELEGATIONS            0x01000000
531 #define CTDB_REC_RO_HAVE_READONLY               0x02000000
532 #define CTDB_REC_RO_REVOKING_READONLY           0x04000000
533 #define CTDB_REC_RO_REVOKE_COMPLETE             0x08000000
534 #define CTDB_REC_RO_FLAGS                       (CTDB_REC_RO_HAVE_DELEGATIONS|\
535                                                  CTDB_REC_RO_HAVE_READONLY|\
536                                                  CTDB_REC_RO_REVOKING_READONLY|\
537                                                  CTDB_REC_RO_REVOKE_COMPLETE)
538         uint32_t flags;
539 };
540
541
542 /*
543   definitions for different socket structures
544  */
545 typedef struct sockaddr_in ctdb_addr_in;
546 typedef struct sockaddr_in6 ctdb_addr_in6;
547 typedef union {
548         struct sockaddr sa;
549         ctdb_addr_in    ip;
550         ctdb_addr_in6   ip6;
551 } ctdb_sock_addr;
552
553 /*
554    A structure describing a single node, its flags and its address
555 */
556 struct ctdb_node_and_flags {
557         uint32_t pnn;
558         uint32_t flags;
559         ctdb_sock_addr addr;
560 };
561
562
563 /*
564    Structure used for a nodemap. 
565    The nodemap is the structure containing a list of all nodes
566    known to the cluster and their associated flags.
567 */
568 struct ctdb_node_map {
569         uint32_t num;
570         struct ctdb_node_and_flags nodes[1];
571 };
572
573 /*
574  * Node flags
575  */
576 #define NODE_FLAGS_DISCONNECTED         0x00000001 /* node isn't connected */
577 #define NODE_FLAGS_UNHEALTHY            0x00000002 /* monitoring says node is unhealthy */
578 #define NODE_FLAGS_PERMANENTLY_DISABLED 0x00000004 /* administrator has disabled node */
579 #define NODE_FLAGS_BANNED               0x00000008 /* recovery daemon has banned the node */
580 #define NODE_FLAGS_DELETED              0x00000010 /* this node has been deleted */
581 #define NODE_FLAGS_STOPPED              0x00000020 /* this node has been stopped */
582 #define NODE_FLAGS_DISABLED             (NODE_FLAGS_UNHEALTHY|NODE_FLAGS_PERMANENTLY_DISABLED)
583 #define NODE_FLAGS_INACTIVE             (NODE_FLAGS_DELETED|NODE_FLAGS_DISCONNECTED|NODE_FLAGS_BANNED|NODE_FLAGS_STOPPED)
584
585 /*
586  * Node capabilities
587  */
588 #define CTDB_CAP_RECMASTER              0x00000001
589 #define CTDB_CAP_LMASTER                0x00000002
590 /* This capability is set if CTDB_LVS_PUBLIC_IP is set */
591 #define CTDB_CAP_LVS                    0x00000004
592 /* This capability is set if NATGW is enabled */
593 #define CTDB_CAP_NATGW                  0x00000008
594
595
596 struct ctdb_public_ip {
597         uint32_t pnn;
598         ctdb_sock_addr addr;
599 };
600
601 struct ctdb_all_public_ips {
602         uint32_t num;
603         struct ctdb_public_ip ips[1];
604 };
605
606
607 struct latency_counter {
608         int num;
609         double min;
610         double max;
611         double total;
612 };
613
614 /*
615   structure used to pass record data between the child and parent
616  */
617 struct ctdb_rec_data {
618         uint32_t length;
619         uint32_t reqid;
620         uint32_t keylen;
621         uint32_t datalen;
622         uint8_t  data[1];
623 };
624
625 struct ctdb_traverse_start {
626         uint32_t db_id;
627         uint32_t reqid;
628         uint64_t srvid;
629 };
630
631 struct ctdb_traverse_start_ext {
632         uint32_t db_id;
633         uint32_t reqid;
634         uint64_t srvid;
635         bool withemptyrecords;
636 };
637
638 /*
639   ctdb statistics information
640  */
641 #define MAX_COUNT_BUCKETS 16
642 #define MAX_HOT_KEYS      10
643
644 struct ctdb_statistics {
645         uint32_t num_clients;
646         uint32_t frozen;
647         uint32_t recovering;
648         uint32_t client_packets_sent;
649         uint32_t client_packets_recv;
650         uint32_t node_packets_sent;
651         uint32_t node_packets_recv;
652         uint32_t keepalive_packets_sent;
653         uint32_t keepalive_packets_recv;
654         struct {
655                 uint32_t req_call;
656                 uint32_t reply_call;
657                 uint32_t req_dmaster;
658                 uint32_t reply_dmaster;
659                 uint32_t reply_error;
660                 uint32_t req_message;
661                 uint32_t req_control;
662                 uint32_t reply_control;
663         } node;
664         struct {
665                 uint32_t req_call;
666                 uint32_t req_message;
667                 uint32_t req_control;
668         } client;
669         struct {
670                 uint32_t call;
671                 uint32_t control;
672                 uint32_t traverse;
673         } timeouts;
674         struct {
675                 struct latency_counter ctdbd;
676                 struct latency_counter recd;
677         } reclock;
678         struct {
679                 uint32_t num_calls;
680                 uint32_t num_current;
681                 uint32_t num_pending;
682                 uint32_t num_failed;
683                 struct latency_counter latency;
684                 uint32_t buckets[MAX_COUNT_BUCKETS];
685         } locks;
686         uint32_t total_calls;
687         uint32_t pending_calls;
688         uint32_t childwrite_calls;
689         uint32_t pending_childwrite_calls;
690         uint32_t memory_used;
691         uint32_t __last_counter; /* hack for control_statistics_all */
692         uint32_t max_hop_count;
693         uint32_t hop_count_bucket[MAX_COUNT_BUCKETS];
694         struct latency_counter call_latency;
695         struct latency_counter childwrite_latency;
696         uint32_t num_recoveries;
697         struct timeval statistics_start_time;
698         struct timeval statistics_current_time;
699         uint32_t total_ro_delegations;
700         uint32_t total_ro_revokes;
701 };
702
703 /*
704  * wire format for statistics history
705  */
706 struct ctdb_statistics_wire {
707         uint32_t num;
708         struct ctdb_statistics stats[1];
709 };
710
711 /*
712  * db statistics
713  */
714 struct ctdb_db_statistics {
715         struct {
716                 uint32_t num_calls;
717                 uint32_t num_current;
718                 uint32_t num_pending;
719                 uint32_t num_failed;
720                 struct latency_counter latency;
721                 uint32_t buckets[MAX_COUNT_BUCKETS];
722         } locks;
723         uint32_t db_ro_delegations;
724         uint32_t db_ro_revokes;
725         uint32_t hop_count_bucket[MAX_COUNT_BUCKETS];
726         uint32_t num_hot_keys;
727         struct {
728                 uint32_t count;
729                 TDB_DATA key;
730         } hot_keys[MAX_HOT_KEYS];
731         char hot_keys_wire[1];
732 };
733
734 /*
735  * wire format for interface list
736  */
737 #ifdef IFNAMSIZ
738 #define CTDB_IFACE_SIZE IFNAMSIZ
739 #else
740 #define CTDB_IFACE_SIZE 16
741 #endif
742
743 struct ctdb_iface_info {
744         char name[CTDB_IFACE_SIZE+2];
745         uint16_t link_state;
746         uint32_t references;
747 };
748
749 struct ctdb_ifaces_list {
750         uint32_t num;
751         struct ctdb_iface_info ifaces[1];
752 };
753
754 #define INVALID_GENERATION 1
755 /* table that contains the mapping between a hash value and lmaster
756  */
757 struct ctdb_vnn_map {
758         uint32_t generation;
759         uint32_t size;
760         uint32_t *map;
761 };
762
763 /* 
764    a wire representation of the vnn map
765  */
766 struct ctdb_vnn_map_wire {
767         uint32_t generation;
768         uint32_t size;
769         uint32_t map[1];
770 };
771
772 #endif