ctdb-include: Move protocol structures from ctdb_private.h to ctdb_protocol.h
[vlendec/samba-autobuild/.git] / ctdb / 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 #include <sys/socket.h>
24
25 /* default ctdb port number */
26 #define CTDB_PORT 4379
27
28 /* we must align packets to ensure ctdb works on all architectures (eg. sparc) */
29 #define CTDB_DS_ALIGNMENT 8
30
31
32 #define CTDB_NULL_FUNC                  0xFF000001
33 #define CTDB_FETCH_FUNC                 0xFF000002
34 #define CTDB_FETCH_WITH_HEADER_FUNC     0xFF000003
35
36
37 struct ctdb_call {
38         int call_id;
39         TDB_DATA key;
40         TDB_DATA call_data;
41         TDB_DATA reply_data;
42         uint32_t status;
43 #define CTDB_IMMEDIATE_MIGRATION                0x00000001
44 #define CTDB_CALL_FLAG_VACUUM_MIGRATION         0x00000002
45 #define CTDB_WANT_READONLY                      0x00000004
46         uint32_t flags;
47 };
48
49 /*
50   structure passed to a ctdb call backend function
51 */
52 struct ctdb_call_info {
53         TDB_DATA key;          /* record key */
54         struct ctdb_ltdb_header *header;
55         TDB_DATA record_data;  /* current data in the record */
56         TDB_DATA *new_data;    /* optionally updated record data */
57         TDB_DATA *call_data;   /* optionally passed from caller */
58         TDB_DATA *reply_data;  /* optionally returned by function */
59         uint32_t status;       /* optional reply status - defaults to zero */
60 };
61
62 #define CTDB_ERR_INVALID 1
63 #define CTDB_ERR_NOMEM 2
64
65 /*
66   ctdb flags
67 */
68 #define CTDB_FLAG_TORTURE      (1<<1)
69
70 /*
71    a message handler ID meaning "give me all messages"
72  */
73 #define CTDB_SRVID_ALL (~(uint64_t)0)
74
75 /*
76   srvid type : RECOVERY
77 */
78 #define CTDB_SRVID_RECOVERY     0xF100000000000000LL
79
80 /*
81    a message handler ID meaning that the cluster has been reconfigured
82  */
83 #define CTDB_SRVID_RECONFIGURE 0xF200000000000000LL
84
85 /*
86    a message handler ID meaning that an IP address has been released
87  */
88 #define CTDB_SRVID_RELEASE_IP 0xF300000000000000LL
89
90 /*
91    a message handler ID meaning that an IP address has been taken
92  */
93 #define CTDB_SRVID_TAKE_IP 0xF301000000000000LL
94
95 /*
96    a message ID to set the node flags in the recovery daemon
97  */
98 #define CTDB_SRVID_SET_NODE_FLAGS 0xF400000000000000LL
99
100 /*
101    a message ID to ask the recovery daemon to update the expected node
102    assignment for a public ip
103  */
104 #define CTDB_SRVID_RECD_UPDATE_IP 0xF500000000000000LL
105
106 /*
107   a message to tell the recovery daemon to fetch a set of records
108  */
109 #define CTDB_SRVID_VACUUM_FETCH 0xF700000000000000LL
110
111 /*
112  * a message to tell recovery daemon to detach a database
113  */
114 #define CTDB_SRVID_DETACH_DATABASE 0xF701000000000000LL
115 /*
116   a message to tell the recovery daemon to write a talloc memdump
117   to the log
118  */
119 #define CTDB_SRVID_MEM_DUMP 0xF800000000000000LL
120
121 /* A message id used to ask the recover daemon to send logs
122 */
123 #define CTDB_SRVID_GETLOG  0xF801000000000000LL
124
125 /* A message id used to ask the recover daemon to send logs
126 */
127 #define CTDB_SRVID_CLEARLOG  0xF802000000000000LL
128
129 /*
130    a message ID to get the recovery daemon to push the node flags out
131  */
132 #define CTDB_SRVID_PUSH_NODE_FLAGS 0xF900000000000000LL
133
134 /*
135    a message ID to get the recovery daemon to reload the nodes file
136  */
137 #define CTDB_SRVID_RELOAD_NODES 0xFA00000000000000LL
138
139 /*
140    a message ID to get the recovery daemon to perform a takeover run
141  */
142 #define CTDB_SRVID_TAKEOVER_RUN 0xFB00000000000000LL
143
144 /* request recovery daemon to rebalance ips for a node.
145    input is uint32_t for the node id.
146 */
147 #define CTDB_SRVID_REBALANCE_NODE 0xFB01000000000000LL
148
149 /* A message handler ID to stop takeover runs from occurring */
150 #define CTDB_SRVID_DISABLE_TAKEOVER_RUNS 0xFB03000000000000LL
151
152 /* A message handler ID to stop recoveries from occurring */
153 #define CTDB_SRVID_DISABLE_RECOVERIES 0xFB04000000000000LL
154
155 /* A message id to ask the recovery daemon to temporarily disable the
156    public ip checks
157 */
158 #define CTDB_SRVID_DISABLE_IP_CHECK  0xFC00000000000000LL
159
160 /* A dummy port used for sending back ipreallocate resposnes to the main
161    daemon
162 */
163 #define CTDB_SRVID_TAKEOVER_RUN_RESPONSE  0xFD00000000000000LL
164
165 /* A range of ports reserved for registering a PID (top 8 bits)
166  * All ports matching the 8 top bits are reserved for exclusive use by
167  * registering a SRVID that matches the process-id of the requesting process
168  */
169 #define CTDB_SRVID_PID_RANGE   0x0000000000000000LL
170
171 /* A range of ports reserved for samba (top 8 bits)
172  * All ports matching the 8 top bits are reserved for exclusive use by
173  * CIFS server
174  */
175 #define CTDB_SRVID_SAMBA_NOTIFY  0xFE00000000000000LL
176 #define CTDB_SRVID_SAMBA_RANGE   0xFE00000000000000LL
177
178 /* A range of ports reserved for a CTDB NFS server (top 8 bits)
179  * All ports matching the 8 top bits are reserved for exclusive use by
180  * NFS server
181  */
182 #define CTDB_SRVID_NFSD_RANGE  0xEE00000000000000LL
183
184 /* A range of ports reserved for a CTDB ISCSI server (top 8 bits)
185  * All ports matching the 8 top bits are reserved for exclusive use by
186  * ISCSI server
187  */
188 #define CTDB_SRVID_ISCSID_RANGE  0xDE00000000000000LL
189
190 /* A range of ports reserved for testing (top 8 bits)
191  * All ports matching the 8 top bits are reserved for exclusive use by
192  * test applications
193  */
194 #define CTDB_SRVID_TEST_RANGE  0xCE00000000000000LL
195
196 /* Range of ports reserved for traversals */
197 #define CTDB_SRVID_TRAVERSE_RANGE  0xBE00000000000000LL
198
199 /* used on the domain socket, send a pdu to the local daemon */
200 #define CTDB_CURRENT_NODE     0xF0000001
201 /* send a broadcast to all nodes in the cluster, active or not */
202 #define CTDB_BROADCAST_ALL    0xF0000002
203 /* send a broadcast to all nodes in the current vnn map */
204 #define CTDB_BROADCAST_VNNMAP 0xF0000003
205 /* send a broadcast to all connected nodes */
206 #define CTDB_BROADCAST_CONNECTED 0xF0000004
207 /* send a broadcast to selected connected nodes */
208 #define CTDB_MULTICAST 0xF0000005
209
210 /* the key used for transaction locking on persistent databases */
211 #define CTDB_TRANSACTION_LOCK_KEY "__transaction_lock__"
212
213 /* the key used to store persistent db sequence number */
214 #define CTDB_DB_SEQNUM_KEY "__db_sequence_number__"
215
216 #define MONITOR_SCRIPT_OK      0
217 #define MONITOR_SCRIPT_TIMEOUT 1
218
219 #define MAX_SCRIPT_NAME 31
220 #define MAX_SCRIPT_OUTPUT 511
221 struct ctdb_script_wire {
222         char name[MAX_SCRIPT_NAME+1];
223         struct timeval start;
224         struct timeval finished;
225         int32_t status;
226         char output[MAX_SCRIPT_OUTPUT+1];
227 };
228
229 struct ctdb_scripts_wire {
230         uint32_t num_scripts;
231         struct ctdb_script_wire scripts[1];
232 };
233
234 /* different calls to event scripts. */
235 enum ctdb_eventscript_call {
236         CTDB_EVENT_INIT,                /* CTDB starting up: no args */
237         CTDB_EVENT_SETUP,               /* CTDB starting up after transport is readdy: no args. */
238         CTDB_EVENT_STARTUP,             /* CTDB starting up after initial recovery: no args. */
239         CTDB_EVENT_START_RECOVERY,      /* CTDB recovery starting: no args. */
240         CTDB_EVENT_RECOVERED,           /* CTDB recovery finished: no args. */
241         CTDB_EVENT_TAKE_IP,             /* IP taken: interface, IP address, netmask bits. */
242         CTDB_EVENT_RELEASE_IP,          /* IP released: interface, IP address, netmask bits. */
243         CTDB_EVENT_STOPPED,             /* Deprecated, do not use. */
244         CTDB_EVENT_MONITOR,             /* Please check if service is healthy: no args. */
245         CTDB_EVENT_STATUS,              /* Deprecated, do not use. */
246         CTDB_EVENT_SHUTDOWN,            /* CTDB shutting down: no args. */
247         CTDB_EVENT_RELOAD,              /* Deprecated, do not use */
248         CTDB_EVENT_UPDATE_IP,           /* IP updating: old interface, new interface, IP address, netmask bits. */
249         CTDB_EVENT_IPREALLOCATED,       /* when a takeover_run() completes */
250         CTDB_EVENT_MAX
251 };
252
253 /* Mapping from enum to names. */
254 extern const char *ctdb_eventscript_call_names[];
255
256 /*
257   operation IDs
258 */
259 enum ctdb_operation {
260         CTDB_REQ_CALL           = 0,
261         CTDB_REPLY_CALL         = 1,
262         CTDB_REQ_DMASTER        = 2,
263         CTDB_REPLY_DMASTER      = 3,
264         CTDB_REPLY_ERROR        = 4,
265         CTDB_REQ_MESSAGE        = 5,
266         /* #6 removed */
267         CTDB_REQ_CONTROL        = 7,
268         CTDB_REPLY_CONTROL      = 8,
269         CTDB_REQ_KEEPALIVE      = 9,
270 };
271
272 #define CTDB_MAGIC 0x43544442 /* CTDB */
273 #define CTDB_PROTOCOL 1
274
275 enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS          = 0,
276                     CTDB_CONTROL_STATISTICS              = 1,
277                     /* #2 removed */
278                     CTDB_CONTROL_PING                    = 3,
279                     CTDB_CONTROL_GETDBPATH               = 4,
280                     CTDB_CONTROL_GETVNNMAP               = 5,
281                     CTDB_CONTROL_SETVNNMAP               = 6,
282                     CTDB_CONTROL_GET_DEBUG               = 7,
283                     CTDB_CONTROL_SET_DEBUG               = 8,
284                     CTDB_CONTROL_GET_DBMAP               = 9,
285                     CTDB_CONTROL_GET_NODEMAPv4           = 10, /* obsolete */
286                     CTDB_CONTROL_SET_DMASTER             = 11, /* obsolete */
287                     /* #12 removed */
288                     CTDB_CONTROL_PULL_DB                 = 13,
289                     CTDB_CONTROL_PUSH_DB                 = 14,
290                     CTDB_CONTROL_GET_RECMODE             = 15,
291                     CTDB_CONTROL_SET_RECMODE             = 16,
292                     CTDB_CONTROL_STATISTICS_RESET        = 17,
293                     CTDB_CONTROL_DB_ATTACH               = 18,
294                     CTDB_CONTROL_SET_CALL                = 19, /* obsolete */
295                     CTDB_CONTROL_TRAVERSE_START          = 20,
296                     CTDB_CONTROL_TRAVERSE_ALL            = 21,
297                     CTDB_CONTROL_TRAVERSE_DATA           = 22,
298                     CTDB_CONTROL_REGISTER_SRVID          = 23,
299                     CTDB_CONTROL_DEREGISTER_SRVID        = 24,
300                     CTDB_CONTROL_GET_DBNAME              = 25,
301                     CTDB_CONTROL_ENABLE_SEQNUM           = 26,
302                     CTDB_CONTROL_UPDATE_SEQNUM           = 27,
303                     /* #28 removed */
304                     CTDB_CONTROL_DUMP_MEMORY             = 29,
305                     CTDB_CONTROL_GET_PID                 = 30,
306                     CTDB_CONTROL_GET_RECMASTER           = 31,
307                     CTDB_CONTROL_SET_RECMASTER           = 32,
308                     CTDB_CONTROL_FREEZE                  = 33,
309                     CTDB_CONTROL_THAW                    = 34,
310                     CTDB_CONTROL_GET_PNN                 = 35,
311                     CTDB_CONTROL_SHUTDOWN                = 36,
312                     CTDB_CONTROL_GET_MONMODE             = 37,
313                     /* #38 removed */
314                     /* #39 removed */
315                     /* #40 removed */
316                     /* #41 removed */
317                     CTDB_CONTROL_TAKEOVER_IPv4           = 42, /* obsolete */
318                     CTDB_CONTROL_RELEASE_IPv4            = 43, /* obsolete */
319                     CTDB_CONTROL_TCP_CLIENT              = 44,
320                     CTDB_CONTROL_TCP_ADD                 = 45,
321                     CTDB_CONTROL_TCP_REMOVE              = 46,
322                     CTDB_CONTROL_STARTUP                 = 47,
323                     CTDB_CONTROL_SET_TUNABLE             = 48,
324                     CTDB_CONTROL_GET_TUNABLE             = 49,
325                     CTDB_CONTROL_LIST_TUNABLES           = 50,
326                     CTDB_CONTROL_GET_PUBLIC_IPSv4        = 51, /* obsolete */
327                     CTDB_CONTROL_MODIFY_FLAGS            = 52,
328                     CTDB_CONTROL_GET_ALL_TUNABLES        = 53,
329                     CTDB_CONTROL_KILL_TCP                = 54,
330                     CTDB_CONTROL_GET_TCP_TICKLE_LIST     = 55,
331                     CTDB_CONTROL_SET_TCP_TICKLE_LIST     = 56,
332                     CTDB_CONTROL_REGISTER_SERVER_ID      = 57,
333                     CTDB_CONTROL_UNREGISTER_SERVER_ID    = 58,
334                     CTDB_CONTROL_CHECK_SERVER_ID         = 59,
335                     CTDB_CONTROL_GET_SERVER_ID_LIST      = 60,
336                     CTDB_CONTROL_DB_ATTACH_PERSISTENT    = 61,
337                     CTDB_CONTROL_PERSISTENT_STORE        = 62, /* obsolete */
338                     CTDB_CONTROL_UPDATE_RECORD           = 63,
339                     CTDB_CONTROL_SEND_GRATIOUS_ARP       = 64,
340                     CTDB_CONTROL_TRANSACTION_START       = 65,
341                     CTDB_CONTROL_TRANSACTION_COMMIT      = 66,
342                     CTDB_CONTROL_WIPE_DATABASE           = 67,
343                     /* #68 removed */
344                     CTDB_CONTROL_UPTIME                  = 69,
345                     CTDB_CONTROL_START_RECOVERY          = 70,
346                     CTDB_CONTROL_END_RECOVERY            = 71,
347                     CTDB_CONTROL_RELOAD_NODES_FILE       = 72,
348                     /* #73 removed */
349                     CTDB_CONTROL_TRY_DELETE_RECORDS      = 74,
350                     CTDB_CONTROL_ENABLE_MONITOR          = 75,
351                     CTDB_CONTROL_DISABLE_MONITOR         = 76,
352                     CTDB_CONTROL_ADD_PUBLIC_IP           = 77,
353                     CTDB_CONTROL_DEL_PUBLIC_IP           = 78,
354                     CTDB_CONTROL_RUN_EVENTSCRIPTS        = 79,
355                     CTDB_CONTROL_GET_CAPABILITIES        = 80,
356                     CTDB_CONTROL_START_PERSISTENT_UPDATE = 81,
357                     CTDB_CONTROL_CANCEL_PERSISTENT_UPDATE= 82,
358                     CTDB_CONTROL_TRANS2_COMMIT           = 83, /* obsolete */
359                     CTDB_CONTROL_TRANS2_FINISHED         = 84, /* obsolete */
360                     CTDB_CONTROL_TRANS2_ERROR            = 85, /* obsolete */
361                     CTDB_CONTROL_TRANS2_COMMIT_RETRY     = 86, /* obsolete */
362                     CTDB_CONTROL_RECD_PING               = 87,
363                     CTDB_CONTROL_RELEASE_IP              = 88,
364                     CTDB_CONTROL_TAKEOVER_IP             = 89,
365                     CTDB_CONTROL_GET_PUBLIC_IPS          = 90,
366                     CTDB_CONTROL_GET_NODEMAP             = 91,
367                     CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS = 96,
368                     CTDB_CONTROL_TRAVERSE_KILL           = 97,
369                     CTDB_CONTROL_RECD_RECLOCK_LATENCY    = 98,
370                     CTDB_CONTROL_GET_RECLOCK_FILE        = 99,
371                     CTDB_CONTROL_SET_RECLOCK_FILE        = 100,
372                     CTDB_CONTROL_STOP_NODE               = 101,
373                     CTDB_CONTROL_CONTINUE_NODE           = 102,
374                     CTDB_CONTROL_SET_NATGWSTATE          = 103,
375                     CTDB_CONTROL_SET_LMASTERROLE         = 104,
376                     CTDB_CONTROL_SET_RECMASTERROLE       = 105,
377                     CTDB_CONTROL_ENABLE_SCRIPT           = 107,
378                     CTDB_CONTROL_DISABLE_SCRIPT          = 108,
379                     CTDB_CONTROL_SET_BAN_STATE           = 109,
380                     CTDB_CONTROL_GET_BAN_STATE           = 110,
381                     CTDB_CONTROL_SET_DB_PRIORITY         = 111,
382                     CTDB_CONTROL_GET_DB_PRIORITY         = 112,
383                     CTDB_CONTROL_TRANSACTION_CANCEL      = 113,
384                     CTDB_CONTROL_REGISTER_NOTIFY         = 114,
385                     CTDB_CONTROL_DEREGISTER_NOTIFY       = 115,
386                     CTDB_CONTROL_TRANS2_ACTIVE           = 116, /* obsolete */
387                     CTDB_CONTROL_GET_LOG                 = 117, /* obsolete */
388                     CTDB_CONTROL_CLEAR_LOG               = 118, /* obsolete */
389                     CTDB_CONTROL_TRANS3_COMMIT           = 119,
390                     CTDB_CONTROL_GET_DB_SEQNUM           = 120,
391                     CTDB_CONTROL_DB_SET_HEALTHY          = 121,
392                     CTDB_CONTROL_DB_GET_HEALTH           = 122,
393                     CTDB_CONTROL_GET_PUBLIC_IP_INFO      = 123,
394                     CTDB_CONTROL_GET_IFACES              = 124,
395                     CTDB_CONTROL_SET_IFACE_LINK_STATE    = 125,
396                     CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE  = 126,
397                     CTDB_CONTROL_GET_STAT_HISTORY        = 127,
398                     CTDB_CONTROL_SCHEDULE_FOR_DELETION   = 128,
399                     CTDB_CONTROL_SET_DB_READONLY         = 129,
400                     CTDB_CONTROL_CHECK_SRVIDS            = 130,
401                     CTDB_CONTROL_TRAVERSE_START_EXT      = 131,
402                     CTDB_CONTROL_GET_DB_STATISTICS       = 132,
403                     CTDB_CONTROL_SET_DB_STICKY           = 133,
404                     CTDB_CONTROL_RELOAD_PUBLIC_IPS       = 134,
405                     CTDB_CONTROL_TRAVERSE_ALL_EXT        = 135,
406                     CTDB_CONTROL_RECEIVE_RECORDS         = 136,
407                     CTDB_CONTROL_IPREALLOCATED           = 137,
408                     CTDB_CONTROL_GET_RUNSTATE            = 138,
409                     CTDB_CONTROL_DB_DETACH               = 139,
410                     CTDB_CONTROL_GET_NODES_FILE          = 140,
411                     CTDB_CONTROL_DB_FREEZE               = 141,
412                     CTDB_CONTROL_DB_THAW                 = 142,
413                     CTDB_CONTROL_DB_TRANSACTION_START    = 143,
414                     CTDB_CONTROL_DB_TRANSACTION_COMMIT   = 144,
415                     CTDB_CONTROL_DB_TRANSACTION_CANCEL   = 145,
416 };
417
418 /*
419   packet structures
420 */
421 struct ctdb_req_header {
422         uint32_t length;
423         uint32_t ctdb_magic;
424         uint32_t ctdb_version;
425         uint32_t generation;
426         uint32_t operation;
427         uint32_t destnode;
428         uint32_t srcnode;
429         uint32_t reqid;
430 };
431
432 struct ctdb_req_call {
433         struct ctdb_req_header hdr;
434         uint32_t flags;
435         uint32_t db_id;
436         uint32_t callid;
437         uint32_t hopcount;
438         uint32_t keylen;
439         uint32_t calldatalen;
440         uint8_t data[1]; /* key[] followed by calldata[] */
441 };
442
443 struct ctdb_reply_call {
444         struct ctdb_req_header hdr;
445         uint32_t status;
446         uint32_t datalen;
447         uint8_t  data[1];
448 };
449
450 struct ctdb_reply_error {
451         struct ctdb_req_header hdr;
452         uint32_t status;
453         uint32_t msglen;
454         uint8_t  msg[1];
455 };
456
457 struct ctdb_req_dmaster {
458         struct ctdb_req_header hdr;
459         uint32_t db_id;
460         uint64_t rsn;
461         uint32_t dmaster;
462         uint32_t keylen;
463         uint32_t datalen;
464         uint8_t  data[1];
465 };
466
467 struct ctdb_reply_dmaster {
468         struct ctdb_req_header hdr;
469         uint32_t db_id;
470         uint64_t rsn;
471         uint32_t keylen;
472         uint32_t datalen;
473         uint8_t  data[1];
474 };
475
476 struct ctdb_req_message {
477         struct ctdb_req_header hdr;
478         uint64_t srvid;
479         uint32_t datalen;
480         uint8_t data[1];
481 };
482
483 struct ctdb_req_control {
484         struct ctdb_req_header hdr;
485         uint32_t opcode;
486         uint32_t pad;
487         uint64_t srvid;
488         uint32_t client_id;
489 #define CTDB_CTRL_FLAG_NOREPLY   1
490 #define CTDB_CTRL_FLAG_OPCODE_SPECIFIC   0xFFFF0000
491         uint32_t flags;
492         uint32_t datalen;
493         uint8_t data[1];
494 };
495
496 struct ctdb_reply_control {
497         struct ctdb_req_header hdr;
498         int32_t  status;
499         uint32_t datalen;
500         uint32_t errorlen;
501         uint8_t data[1];
502 };
503
504 struct ctdb_req_keepalive {
505         struct ctdb_req_header hdr;
506 };
507
508
509 /*
510   the extended header for records in the ltdb
511 */
512 struct ctdb_ltdb_header {
513         uint64_t rsn;
514         uint32_t dmaster;
515         uint32_t reserved1;
516 #define CTDB_REC_FLAG_DEFAULT                   0x00000000
517 #define CTDB_REC_FLAG_MIGRATED_WITH_DATA        0x00010000
518 #define CTDB_REC_FLAG_VACUUM_MIGRATED           0x00020000
519 #define CTDB_REC_FLAG_AUTOMATIC                 0x00040000
520 #define CTDB_REC_RO_HAVE_DELEGATIONS            0x01000000
521 #define CTDB_REC_RO_HAVE_READONLY               0x02000000
522 #define CTDB_REC_RO_REVOKING_READONLY           0x04000000
523 #define CTDB_REC_RO_REVOKE_COMPLETE             0x08000000
524 #define CTDB_REC_RO_FLAGS                       (CTDB_REC_RO_HAVE_DELEGATIONS|\
525                                                  CTDB_REC_RO_HAVE_READONLY|\
526                                                  CTDB_REC_RO_REVOKING_READONLY|\
527                                                  CTDB_REC_RO_REVOKE_COMPLETE)
528         uint32_t flags;
529 };
530
531
532 /*
533   definitions for different socket structures
534  */
535 typedef struct sockaddr_in ctdb_addr_in;
536 typedef struct sockaddr_in6 ctdb_addr_in6;
537 typedef union {
538         struct sockaddr sa;
539         ctdb_addr_in    ip;
540         ctdb_addr_in6   ip6;
541 } ctdb_sock_addr;
542
543 /*
544    A structure describing a single node, its flags and its address
545 */
546 struct ctdb_node_and_flags {
547         uint32_t pnn;
548         uint32_t flags;
549         ctdb_sock_addr addr;
550 };
551
552
553 /*
554    Structure used for a nodemap. 
555    The nodemap is the structure containing a list of all nodes
556    known to the cluster and their associated flags.
557 */
558 struct ctdb_node_map {
559         uint32_t num;
560         struct ctdb_node_and_flags nodes[1];
561 };
562
563 /*
564  * Node flags
565  */
566 #define NODE_FLAGS_DISCONNECTED         0x00000001 /* node isn't connected */
567 #define NODE_FLAGS_UNHEALTHY            0x00000002 /* monitoring says node is unhealthy */
568 #define NODE_FLAGS_PERMANENTLY_DISABLED 0x00000004 /* administrator has disabled node */
569 #define NODE_FLAGS_BANNED               0x00000008 /* recovery daemon has banned the node */
570 #define NODE_FLAGS_DELETED              0x00000010 /* this node has been deleted */
571 #define NODE_FLAGS_STOPPED              0x00000020 /* this node has been stopped */
572 #define NODE_FLAGS_DISABLED             (NODE_FLAGS_UNHEALTHY|NODE_FLAGS_PERMANENTLY_DISABLED)
573 #define NODE_FLAGS_INACTIVE             (NODE_FLAGS_DELETED|NODE_FLAGS_DISCONNECTED|NODE_FLAGS_BANNED|NODE_FLAGS_STOPPED)
574
575 /*
576  * Node capabilities
577  */
578 #define CTDB_CAP_RECMASTER              0x00000001
579 #define CTDB_CAP_LMASTER                0x00000002
580 /* This capability is set if CTDB_LVS_PUBLIC_IP is set */
581 #define CTDB_CAP_LVS                    0x00000004
582 /* This capability is set if NATGW is enabled */
583 #define CTDB_CAP_NATGW                  0x00000008
584
585 /*
586  * Node features
587  */
588 #define CTDB_CAP_PARALLEL_RECOVERY      0x00010000
589
590 #define CTDB_CAP_FEATURES               (CTDB_CAP_PARALLEL_RECOVERY)
591
592 #define CTDB_CAP_DEFAULT                (CTDB_CAP_RECMASTER | \
593                                          CTDB_CAP_LMASTER   | \
594                                          CTDB_CAP_FEATURES)
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         struct {
724                 struct latency_counter latency;
725         } vacuum;
726         uint32_t db_ro_delegations;
727         uint32_t db_ro_revokes;
728         uint32_t hop_count_bucket[MAX_COUNT_BUCKETS];
729         uint32_t num_hot_keys;
730         struct {
731                 uint32_t count;
732                 TDB_DATA key;
733         } hot_keys[MAX_HOT_KEYS];
734         char hot_keys_wire[1];
735 };
736
737 /*
738  * wire format for interface list
739  */
740 #ifdef IFNAMSIZ
741 #define CTDB_IFACE_SIZE IFNAMSIZ
742 #else
743 #define CTDB_IFACE_SIZE 16
744 #endif
745
746 struct ctdb_iface_info {
747         char name[CTDB_IFACE_SIZE+2];
748         uint16_t link_state;
749         uint32_t references;
750 };
751
752 struct ctdb_ifaces_list {
753         uint32_t num;
754         struct ctdb_iface_info ifaces[1];
755 };
756
757 #define INVALID_GENERATION 1
758 /* table that contains the mapping between a hash value and lmaster
759  */
760 struct ctdb_vnn_map {
761         uint32_t generation;
762         uint32_t size;
763         uint32_t *map;
764 };
765
766 /* 
767    a wire representation of the vnn map
768  */
769 struct ctdb_vnn_map_wire {
770         uint32_t generation;
771         uint32_t size;
772         uint32_t map[1];
773 };
774
775 struct ctdb_client_notify_register {
776         uint64_t srvid;
777         uint32_t len;
778         uint8_t notify_data[1];
779 };
780
781 struct ctdb_client_notify_deregister {
782         uint64_t srvid;
783 };
784
785 /* table that contains a list of all dbids on a node
786  */
787 struct ctdb_dbid_map {
788         uint32_t num;
789         struct ctdb_dbid {
790                 uint32_t dbid;
791 #define CTDB_DB_FLAGS_PERSISTENT        0x01
792 #define CTDB_DB_FLAGS_READONLY          0x02
793 #define CTDB_DB_FLAGS_STICKY            0x04
794                 uint8_t flags;
795         } dbs[1];
796 };
797
798 #define CTDB_RECOVERY_NORMAL            0
799 #define CTDB_RECOVERY_ACTIVE            1
800
801 enum ctdb_server_id_type {
802         SERVER_TYPE_SAMBA=1,
803         SERVER_TYPE_NFSD=2,
804         SERVER_TYPE_ISCSID=3
805 };
806
807 struct ctdb_server_id {
808         enum ctdb_server_id_type type;
809         uint32_t pnn;
810         uint32_t server_id;
811 };
812
813 struct ctdb_server_id_list {
814         uint32_t num;
815         struct ctdb_server_id server_ids[1];
816 };
817
818 struct ctdb_uptime {
819         struct timeval current_time;
820         struct timeval ctdbd_start_time;
821         struct timeval last_recovery_started;
822         struct timeval last_recovery_finished;
823 };
824
825 struct ctdb_control_tcp_addr {
826         ctdb_sock_addr src;
827         ctdb_sock_addr dest;
828 };
829
830 struct ctdb_ban_time {
831         uint32_t pnn;
832         uint32_t time;
833 };
834
835 struct ctdb_db_priority {
836         uint32_t db_id;
837         uint32_t priority;
838 };
839
840 /*
841  * Structures to support SRVID requests and replies
842  */
843 struct srvid_request {
844         uint32_t pnn;
845         uint64_t srvid;
846 };
847
848 struct srvid_request_data {
849         uint32_t pnn;
850         uint64_t srvid;
851         uint32_t data;
852 };
853
854 /*
855   a tcp connection description
856   also used by tcp_add and tcp_remove controls
857  */
858 struct ctdb_tcp_connection {
859         ctdb_sock_addr src_addr;
860         ctdb_sock_addr dst_addr;
861 };
862
863 /* the wire representation for a tcp tickle array */
864 struct ctdb_tcp_wire_array {
865         uint32_t num;
866         struct ctdb_tcp_connection connections[1];
867 };
868
869 /* the list of tcp tickles used by get/set tcp tickle list */
870 struct ctdb_control_tcp_tickle_list {
871         ctdb_sock_addr addr;
872         struct ctdb_tcp_wire_array tickles;
873 };
874
875 /* all tunable variables go in here */
876 struct ctdb_tunable {
877         uint32_t max_redirect_count;
878         uint32_t seqnum_interval; /* unit is ms */
879         uint32_t control_timeout;
880         uint32_t traverse_timeout;
881         uint32_t keepalive_interval;
882         uint32_t keepalive_limit;
883         uint32_t recover_timeout;
884         uint32_t recover_interval;
885         uint32_t election_timeout;
886         uint32_t takeover_timeout;
887         uint32_t monitor_interval;
888         uint32_t tickle_update_interval;
889         uint32_t script_timeout;
890         uint32_t script_timeout_count; /* allow dodgy scripts to hang this many times in a row before we mark the node unhealthy */
891         uint32_t script_unhealthy_on_timeout; /* obsolete */
892         uint32_t recovery_grace_period;
893         uint32_t recovery_ban_period;
894         uint32_t database_hash_size;
895         uint32_t database_max_dead;
896         uint32_t rerecovery_timeout;
897         uint32_t enable_bans;
898         uint32_t deterministic_public_ips;
899         uint32_t reclock_ping_period;
900         uint32_t no_ip_failback;
901         uint32_t disable_ip_failover;
902         uint32_t verbose_memory_names;
903         uint32_t recd_ping_timeout;
904         uint32_t recd_ping_failcount;
905         uint32_t log_latency_ms;
906         uint32_t reclock_latency_ms;
907         uint32_t recovery_drop_all_ips;
908         uint32_t verify_recovery_lock;
909         uint32_t vacuum_interval;
910         uint32_t vacuum_max_run_time;
911         uint32_t repack_limit;
912         uint32_t vacuum_limit;
913         uint32_t max_queue_depth_drop_msg;
914         uint32_t allow_unhealthy_db_read;
915         uint32_t stat_history_interval;
916         uint32_t deferred_attach_timeout;
917         uint32_t vacuum_fast_path_count;
918         uint32_t lcp2_public_ip_assignment;
919         uint32_t allow_client_db_attach;
920         uint32_t recover_pdb_by_seqnum;
921         uint32_t deferred_rebalance_on_node_add;
922         uint32_t fetch_collapse;
923         uint32_t hopcount_make_sticky;
924         uint32_t sticky_duration;
925         uint32_t sticky_pindown;
926         uint32_t no_ip_takeover;
927         uint32_t db_record_count_warn;
928         uint32_t db_record_size_warn;
929         uint32_t db_size_warn;
930         uint32_t pulldb_preallocation_size;
931         uint32_t no_ip_host_on_all_disabled;
932         uint32_t samba3_hack;
933         uint32_t mutex_enabled;
934         uint32_t lock_processes_per_db;
935 };
936
937 enum ctdb_runstate {
938         CTDB_RUNSTATE_UNKNOWN,
939         CTDB_RUNSTATE_INIT,
940         CTDB_RUNSTATE_SETUP,
941         CTDB_RUNSTATE_FIRST_RECOVERY,
942         CTDB_RUNSTATE_STARTUP,
943         CTDB_RUNSTATE_RUNNING,
944         CTDB_RUNSTATE_SHUTDOWN,
945 };
946
947 #define CTDB_MONITORING_ACTIVE          0
948 #define CTDB_MONITORING_DISABLED        1
949
950 /*
951   struct holding a ctdb_sock_addr and an interface name,
952   used to add/remove public addresses
953  */
954 struct ctdb_control_ip_iface {
955         ctdb_sock_addr addr;
956         uint32_t mask;
957         uint32_t len;
958         char iface[1];
959 };
960
961 /*
962   struct holding a ctdb_sock_addr and an interface name,
963   used for send_gratious_arp
964  */
965 struct ctdb_control_gratious_arp {
966         ctdb_sock_addr addr;
967         uint32_t mask;
968         uint32_t len;
969         char iface[1];
970 };
971
972 /*
973   structure used for CTDB_SRVID_NODE_FLAGS_CHANGED
974  */
975 struct ctdb_node_flag_change {
976         uint32_t pnn;
977         uint32_t new_flags;
978         uint32_t old_flags;
979 };
980
981 #define CTDB_LMASTER_ANY        0xffffffff
982
983 /* structure used for pulldb control */
984 struct ctdb_control_pulldb {
985         uint32_t db_id;
986         uint32_t lmaster;
987 };
988
989 /* structure used for sending lists of records */
990 struct ctdb_marshall_buffer {
991         uint32_t db_id;
992         uint32_t count;
993         uint8_t data[1];
994 };
995
996 /*
997   structure for setting a tunable
998  */
999 struct ctdb_control_set_tunable {
1000         uint32_t value;
1001         uint32_t length;
1002         uint8_t  name[1];
1003 };
1004
1005 /*
1006   structure for getting a tunable
1007  */
1008 struct ctdb_control_get_tunable {
1009         uint32_t length;
1010         uint8_t  name[1];
1011 };
1012
1013 /*
1014   structure for listing tunables
1015  */
1016 struct ctdb_control_list_tunable {
1017         uint32_t length;
1018         /* returns a : separated list of tunable names */
1019         uint8_t  data[1];
1020 };
1021
1022
1023 struct ctdb_control_transdb {
1024         uint32_t db_id;
1025         uint32_t transaction_id;
1026 };
1027
1028 #define CTDB_PUBLIC_IP_FLAGS_ONLY_AVAILABLE 0x00010000
1029
1030 struct ctdb_control_iface_info {
1031         char name[CTDB_IFACE_SIZE+2];
1032         uint16_t link_state;
1033         uint32_t references;
1034 };
1035
1036 struct ctdb_control_public_ip_info {
1037         struct ctdb_public_ip ip;
1038         uint32_t active_idx;
1039         uint32_t num;
1040         struct ctdb_control_iface_info ifaces[1];
1041 };
1042
1043 struct ctdb_control_get_ifaces {
1044         uint32_t num;
1045         struct ctdb_control_iface_info ifaces[1];
1046 };
1047
1048 /**
1049  * structure to pass to a schedule_for_deletion_control
1050  */
1051 struct ctdb_control_schedule_for_deletion {
1052         uint32_t db_id;
1053         struct ctdb_ltdb_header hdr;
1054         uint32_t keylen;
1055         uint8_t key[1]; /* key[] */
1056 };
1057
1058 #endif