ctdb-protocol: Replace ctdb_event_header with sock_packet_header
[vlendec/samba-autobuild/.git] / ctdb / protocol / protocol.h
1 /*
2    CTDB protocol marshalling
3
4    Copyright (C) Amitay Isaacs  2015
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 <tdb.h>
24
25 #define CTDB_MAGIC      0x43544442 /* CTDB */
26 #define CTDB_PROTOCOL   1
27
28 enum ctdb_operation {
29         CTDB_REQ_CALL           = 0,
30         CTDB_REPLY_CALL         = 1,
31         CTDB_REQ_DMASTER        = 2,
32         CTDB_REPLY_DMASTER      = 3,
33         CTDB_REPLY_ERROR        = 4,
34         CTDB_REQ_MESSAGE        = 5,
35         /* #6 removed */
36         CTDB_REQ_CONTROL        = 7,
37         CTDB_REPLY_CONTROL      = 8,
38         CTDB_REQ_KEEPALIVE      = 9,
39 };
40
41 /* used on the domain socket, send a pdu to the local daemon */
42 #define CTDB_CURRENT_NODE     0xF0000001
43 /* send a broadcast to all nodes in the cluster, active or not */
44 #define CTDB_BROADCAST_ALL    0xF0000002
45 /* send a broadcast to all nodes in the current vnn map */
46 #define CTDB_BROADCAST_VNNMAP 0xF0000003
47 /* send a broadcast to all connected nodes */
48 #define CTDB_BROADCAST_CONNECTED 0xF0000004
49 /* send a broadcast to selected connected nodes */
50 #define CTDB_MULTICAST 0xF0000005
51
52 #define CTDB_UNKNOWN_PNN        0xFFFFFFFF
53
54 /* the key used to store persistent db sequence number */
55 #define CTDB_DB_SEQNUM_KEY "__db_sequence_number__"
56
57 struct ctdb_req_header {
58         uint32_t length;
59         uint32_t ctdb_magic;
60         uint32_t ctdb_version;
61         uint32_t generation;
62         uint32_t operation;
63         uint32_t destnode;
64         uint32_t srcnode;
65         uint32_t reqid;
66 };
67
68 struct ctdb_req_call {
69         uint32_t flags;
70         uint32_t db_id;
71         uint32_t callid;
72         uint32_t hopcount;
73         TDB_DATA key;
74         TDB_DATA calldata;
75 };
76
77 struct ctdb_reply_call {
78         int32_t status;
79         TDB_DATA data;
80 };
81
82 struct ctdb_reply_error {
83         int32_t status;
84         TDB_DATA msg;
85 };
86
87 struct ctdb_req_dmaster {
88         uint32_t db_id;
89         uint64_t rsn;
90         uint32_t dmaster;
91         TDB_DATA key;
92         TDB_DATA data;
93 };
94
95 struct ctdb_reply_dmaster {
96         uint32_t db_id;
97         uint64_t rsn;
98         TDB_DATA key;
99         TDB_DATA data;
100 };
101
102 #define CTDB_NULL_FUNC                  0xFF000001
103 #define CTDB_FETCH_FUNC                 0xFF000002
104 #define CTDB_FETCH_WITH_HEADER_FUNC     0xFF000003
105
106 struct ctdb_call {
107         int call_id;
108         TDB_DATA key;
109         TDB_DATA call_data;
110         TDB_DATA reply_data;
111         uint32_t status;
112 #define CTDB_IMMEDIATE_MIGRATION                0x00000001
113 #define CTDB_CALL_FLAG_VACUUM_MIGRATION         0x00000002
114 #define CTDB_WANT_READONLY                      0x00000004
115         uint32_t flags;
116 };
117
118 /* SRVID to catch all messages */
119 #define CTDB_SRVID_ALL (~(uint64_t)0)
120
121 /* SRVID prefix used during recovery for pulling and pushing databases */
122 #define CTDB_SRVID_RECOVERY     0xF001000000000000LL
123
124 /* SRVID to assign of banning credits */
125 #define CTDB_SRVID_BANNING      0xF002000000000000LL
126
127 /* SRVID to inform of election data */
128 #define CTDB_SRVID_ELECTION     0xF100000000000000LL
129
130 /* SRVID to inform clients that the cluster has been reconfigured */
131 #define CTDB_SRVID_RECONFIGURE 0xF200000000000000LL
132
133 /* SRVID to inform clients an IP address has been released */
134 #define CTDB_SRVID_RELEASE_IP 0xF300000000000000LL
135
136 /* SRVID to inform clients that an IP address has been taken over */
137 #define CTDB_SRVID_TAKE_IP 0xF301000000000000LL
138
139 /* SRVID to inform recovery daemon of the node flags */
140 #define CTDB_SRVID_SET_NODE_FLAGS 0xF400000000000000LL
141
142 /* SRVID to inform recovery daemon to update public ip assignment */
143 #define CTDB_SRVID_RECD_UPDATE_IP 0xF500000000000000LL
144
145 /* SRVID to inform recovery daemon to migrate a set of records */
146 #define CTDB_SRVID_VACUUM_FETCH 0xF700000000000000LL
147
148 /* SRVID to inform recovery daemon to detach a database */
149 #define CTDB_SRVID_DETACH_DATABASE 0xF701000000000000LL
150
151 /* SRVID to inform recovery daemon to dump talloc memdump to the log */
152 #define CTDB_SRVID_MEM_DUMP 0xF800000000000000LL
153
154 /* SRVID to inform recovery daemon to send logs */
155 #define CTDB_SRVID_GETLOG  0xF801000000000000LL
156
157 /* SRVID to inform recovery daemon to clear logs */
158 #define CTDB_SRVID_CLEARLOG  0xF802000000000000LL
159
160 /* SRVID to inform recovery daemon to push the node flags to other nodes */
161 #define CTDB_SRVID_PUSH_NODE_FLAGS 0xF900000000000000LL
162
163 /* SRVID to inform recovery daemon to reload the nodes file */
164 #define CTDB_SRVID_RELOAD_NODES 0xFA00000000000000LL
165
166 /* SRVID to inform recovery daemon to perform a takeover run */
167 #define CTDB_SRVID_TAKEOVER_RUN 0xFB00000000000000LL
168
169 /* SRVID to inform recovery daemon to rebalance ips for a node.  */
170 #define CTDB_SRVID_REBALANCE_NODE 0xFB01000000000000LL
171
172 /* SRVID to inform recovery daemon to stop takeover runs from occurring */
173 #define CTDB_SRVID_DISABLE_TAKEOVER_RUNS 0xFB03000000000000LL
174
175 /* SRVID to inform recovery daemon to stop recoveries from occurring */
176 #define CTDB_SRVID_DISABLE_RECOVERIES 0xFB04000000000000LL
177
178 /* SRVID to inform recovery daemon to disable the public ip checks */
179 #define CTDB_SRVID_DISABLE_IP_CHECK  0xFC00000000000000LL
180
181 /* A range of ports reserved for registering a PID (top 8 bits)
182  * All ports matching the 8 top bits are reserved for exclusive use by
183  * registering a SRVID that matches the process-id of the requesting process
184  */
185 #define CTDB_SRVID_PID_RANGE   0x0000000000000000LL
186
187 /* A range of ports reserved for samba (top 8 bits)
188  * All ports matching the 8 top bits are reserved for exclusive use by
189  * CIFS server
190  */
191 #define CTDB_SRVID_SAMBA_NOTIFY  0xFE00000000000000LL
192 #define CTDB_SRVID_SAMBA_RANGE   0xFE00000000000000LL
193
194 /* A range of ports reserved for a CTDB NFS server (top 8 bits)
195  * All ports matching the 8 top bits are reserved for exclusive use by
196  * NFS server
197  */
198 #define CTDB_SRVID_NFSD_RANGE  0xEE00000000000000LL
199
200 /* A range of ports reserved for a CTDB ISCSI server (top 8 bits)
201  * All ports matching the 8 top bits are reserved for exclusive use by
202  * ISCSI server
203  */
204 #define CTDB_SRVID_ISCSID_RANGE  0xDE00000000000000LL
205
206 /* A range of ports reserved for CTDB tool (top 8 bits)
207  * All ports matching the 8 top bits are reserved for exclusive use by
208  * CTDB tool
209  */
210 #define CTDB_SRVID_TOOL_RANGE  0xCE00000000000000LL
211
212 /* A range of ports reserved by client (top 8 bits)
213  * All ports matching the 8 top bits are reserved for exclusive use by
214  * CTDB client code
215  */
216 #define CTDB_SRVID_CLIENT_RANGE  0xBE00000000000000LL
217
218 /* Range of ports reserved for test applications (top 8 bits)
219  * All ports matching the 8 top bits are reserved for exclusive use by
220  * test applications
221  */
222 #define CTDB_SRVID_TEST_RANGE  0xAE00000000000000LL
223
224
225 enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS          = 0,
226                     CTDB_CONTROL_STATISTICS              = 1,
227                     /* #2 removed */
228                     CTDB_CONTROL_PING                    = 3,
229                     CTDB_CONTROL_GETDBPATH               = 4,
230                     CTDB_CONTROL_GETVNNMAP               = 5,
231                     CTDB_CONTROL_SETVNNMAP               = 6,
232                     CTDB_CONTROL_GET_DEBUG               = 7,
233                     CTDB_CONTROL_SET_DEBUG               = 8,
234                     CTDB_CONTROL_GET_DBMAP               = 9,
235                     CTDB_CONTROL_GET_NODEMAPv4           = 10, /* obsolete */
236                     CTDB_CONTROL_SET_DMASTER             = 11, /* obsolete */
237                     /* #12 removed */
238                     CTDB_CONTROL_PULL_DB                 = 13,
239                     CTDB_CONTROL_PUSH_DB                 = 14,
240                     CTDB_CONTROL_GET_RECMODE             = 15,
241                     CTDB_CONTROL_SET_RECMODE             = 16,
242                     CTDB_CONTROL_STATISTICS_RESET        = 17,
243                     CTDB_CONTROL_DB_ATTACH               = 18,
244                     CTDB_CONTROL_SET_CALL                = 19, /* obsolete */
245                     CTDB_CONTROL_TRAVERSE_START          = 20,
246                     CTDB_CONTROL_TRAVERSE_ALL            = 21,
247                     CTDB_CONTROL_TRAVERSE_DATA           = 22,
248                     CTDB_CONTROL_REGISTER_SRVID          = 23,
249                     CTDB_CONTROL_DEREGISTER_SRVID        = 24,
250                     CTDB_CONTROL_GET_DBNAME              = 25,
251                     CTDB_CONTROL_ENABLE_SEQNUM           = 26,
252                     CTDB_CONTROL_UPDATE_SEQNUM           = 27,
253                     /* #28 removed */
254                     CTDB_CONTROL_DUMP_MEMORY             = 29,
255                     CTDB_CONTROL_GET_PID                 = 30,
256                     CTDB_CONTROL_GET_RECMASTER           = 31,
257                     CTDB_CONTROL_SET_RECMASTER           = 32,
258                     CTDB_CONTROL_FREEZE                  = 33,
259                     CTDB_CONTROL_THAW                    = 34, /* obsolete */
260                     CTDB_CONTROL_GET_PNN                 = 35,
261                     CTDB_CONTROL_SHUTDOWN                = 36,
262                     CTDB_CONTROL_GET_MONMODE             = 37,
263                     /* #38 removed */
264                     /* #39 removed */
265                     /* #40 removed */
266                     /* #41 removed */
267                     CTDB_CONTROL_TAKEOVER_IPv4           = 42, /* obsolete */
268                     CTDB_CONTROL_RELEASE_IPv4            = 43, /* obsolete */
269                     CTDB_CONTROL_TCP_CLIENT              = 44,
270                     CTDB_CONTROL_TCP_ADD                 = 45,
271                     CTDB_CONTROL_TCP_REMOVE              = 46,
272                     CTDB_CONTROL_STARTUP                 = 47,
273                     CTDB_CONTROL_SET_TUNABLE             = 48,
274                     CTDB_CONTROL_GET_TUNABLE             = 49,
275                     CTDB_CONTROL_LIST_TUNABLES           = 50,
276                     CTDB_CONTROL_GET_PUBLIC_IPSv4        = 51, /* obsolete */
277                     CTDB_CONTROL_MODIFY_FLAGS            = 52,
278                     CTDB_CONTROL_GET_ALL_TUNABLES        = 53,
279                     CTDB_CONTROL_KILL_TCP                = 54, /* obsolete */
280                     CTDB_CONTROL_GET_TCP_TICKLE_LIST     = 55,
281                     CTDB_CONTROL_SET_TCP_TICKLE_LIST     = 56,
282                     CTDB_CONTROL_REGISTER_SERVER_ID      = 57, /* obsolete */
283                     CTDB_CONTROL_UNREGISTER_SERVER_ID    = 58, /* obsolete */
284                     CTDB_CONTROL_CHECK_SERVER_ID         = 59, /* obsolete */
285                     CTDB_CONTROL_GET_SERVER_ID_LIST      = 60, /* obsolete */
286                     CTDB_CONTROL_DB_ATTACH_PERSISTENT    = 61,
287                     CTDB_CONTROL_PERSISTENT_STORE        = 62, /* obsolete */
288                     CTDB_CONTROL_UPDATE_RECORD           = 63,
289                     CTDB_CONTROL_SEND_GRATUITOUS_ARP     = 64,
290                     CTDB_CONTROL_TRANSACTION_START       = 65, /* obsolete */
291                     CTDB_CONTROL_TRANSACTION_COMMIT      = 66, /* obsolete */
292                     CTDB_CONTROL_WIPE_DATABASE           = 67,
293                     /* #68 removed */
294                     CTDB_CONTROL_UPTIME                  = 69,
295                     CTDB_CONTROL_START_RECOVERY          = 70,
296                     CTDB_CONTROL_END_RECOVERY            = 71,
297                     CTDB_CONTROL_RELOAD_NODES_FILE       = 72,
298                     /* #73 removed */
299                     CTDB_CONTROL_TRY_DELETE_RECORDS      = 74,
300                     CTDB_CONTROL_ENABLE_MONITOR          = 75,
301                     CTDB_CONTROL_DISABLE_MONITOR         = 76,
302                     CTDB_CONTROL_ADD_PUBLIC_IP           = 77,
303                     CTDB_CONTROL_DEL_PUBLIC_IP           = 78,
304                     CTDB_CONTROL_RUN_EVENTSCRIPTS        = 79, /* obsolete */
305                     CTDB_CONTROL_GET_CAPABILITIES        = 80,
306                     CTDB_CONTROL_START_PERSISTENT_UPDATE = 81, /* obsolete */
307                     CTDB_CONTROL_CANCEL_PERSISTENT_UPDATE= 82, /* obsolete */
308                     CTDB_CONTROL_TRANS2_COMMIT           = 83, /* obsolete */
309                     CTDB_CONTROL_TRANS2_FINISHED         = 84, /* obsolete */
310                     CTDB_CONTROL_TRANS2_ERROR            = 85, /* obsolete */
311                     CTDB_CONTROL_TRANS2_COMMIT_RETRY     = 86, /* obsolete */
312                     CTDB_CONTROL_RECD_PING               = 87,
313                     CTDB_CONTROL_RELEASE_IP              = 88,
314                     CTDB_CONTROL_TAKEOVER_IP             = 89,
315                     CTDB_CONTROL_GET_PUBLIC_IPS          = 90,
316                     CTDB_CONTROL_GET_NODEMAP             = 91,
317                     /* missing */
318                     CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS = 96, /* obsolete */
319                     CTDB_CONTROL_TRAVERSE_KILL           = 97,
320                     CTDB_CONTROL_RECD_RECLOCK_LATENCY    = 98,
321                     CTDB_CONTROL_GET_RECLOCK_FILE        = 99,
322                     CTDB_CONTROL_SET_RECLOCK_FILE        = 100, /* obsolete */
323                     CTDB_CONTROL_STOP_NODE               = 101,
324                     CTDB_CONTROL_CONTINUE_NODE           = 102,
325                     CTDB_CONTROL_SET_NATGWSTATE          = 103, /* obsolete */
326                     CTDB_CONTROL_SET_LMASTERROLE         = 104,
327                     CTDB_CONTROL_SET_RECMASTERROLE       = 105,
328                     CTDB_CONTROL_ENABLE_SCRIPT           = 107, /* obsolete */
329                     CTDB_CONTROL_DISABLE_SCRIPT          = 108, /* obsolete */
330                     CTDB_CONTROL_SET_BAN_STATE           = 109,
331                     CTDB_CONTROL_GET_BAN_STATE           = 110,
332                     CTDB_CONTROL_SET_DB_PRIORITY         = 111, /* obsolete */
333                     CTDB_CONTROL_GET_DB_PRIORITY         = 112, /* obsolete */
334                     CTDB_CONTROL_TRANSACTION_CANCEL      = 113, /* obsolete */
335                     CTDB_CONTROL_REGISTER_NOTIFY         = 114,
336                     CTDB_CONTROL_DEREGISTER_NOTIFY       = 115,
337                     CTDB_CONTROL_TRANS2_ACTIVE           = 116, /* obsolete */
338                     CTDB_CONTROL_GET_LOG                 = 117, /* obsolete */
339                     CTDB_CONTROL_CLEAR_LOG               = 118, /* obsolete */
340                     CTDB_CONTROL_TRANS3_COMMIT           = 119,
341                     CTDB_CONTROL_GET_DB_SEQNUM           = 120,
342                     CTDB_CONTROL_DB_SET_HEALTHY          = 121,
343                     CTDB_CONTROL_DB_GET_HEALTH           = 122,
344                     CTDB_CONTROL_GET_PUBLIC_IP_INFO      = 123,
345                     CTDB_CONTROL_GET_IFACES              = 124,
346                     CTDB_CONTROL_SET_IFACE_LINK_STATE    = 125,
347                     CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE  = 126,
348                     CTDB_CONTROL_GET_STAT_HISTORY        = 127,
349                     CTDB_CONTROL_SCHEDULE_FOR_DELETION   = 128,
350                     CTDB_CONTROL_SET_DB_READONLY         = 129,
351                     CTDB_CONTROL_CHECK_SRVIDS            = 130, /* obsolete */
352                     CTDB_CONTROL_TRAVERSE_START_EXT      = 131,
353                     CTDB_CONTROL_GET_DB_STATISTICS       = 132,
354                     CTDB_CONTROL_SET_DB_STICKY           = 133,
355                     CTDB_CONTROL_RELOAD_PUBLIC_IPS       = 134,
356                     CTDB_CONTROL_TRAVERSE_ALL_EXT        = 135,
357                     CTDB_CONTROL_RECEIVE_RECORDS         = 136,
358                     CTDB_CONTROL_IPREALLOCATED           = 137,
359                     CTDB_CONTROL_GET_RUNSTATE            = 138,
360                     CTDB_CONTROL_DB_DETACH               = 139,
361                     CTDB_CONTROL_GET_NODES_FILE          = 140,
362                     CTDB_CONTROL_DB_FREEZE               = 141,
363                     CTDB_CONTROL_DB_THAW                 = 142,
364                     CTDB_CONTROL_DB_TRANSACTION_START    = 143,
365                     CTDB_CONTROL_DB_TRANSACTION_COMMIT   = 144,
366                     CTDB_CONTROL_DB_TRANSACTION_CANCEL   = 145,
367                     CTDB_CONTROL_DB_PULL                 = 146,
368                     CTDB_CONTROL_DB_PUSH_START           = 147,
369                     CTDB_CONTROL_DB_PUSH_CONFIRM         = 148,
370                     CTDB_CONTROL_DB_OPEN_FLAGS           = 149,
371                     CTDB_CONTROL_DB_ATTACH_REPLICATED    = 150,
372 };
373
374 #define CTDB_MONITORING_ENABLED         0
375 #define CTDB_MONITORING_DISABLED        1
376
377 #define MAX_COUNT_BUCKETS 16
378 #define MAX_HOT_KEYS      10
379
380 struct ctdb_latency_counter {
381         int num;
382         double min;
383         double max;
384         double total;
385 };
386
387 struct ctdb_statistics {
388         uint32_t num_clients;
389         uint32_t frozen;
390         uint32_t recovering;
391         uint32_t client_packets_sent;
392         uint32_t client_packets_recv;
393         uint32_t node_packets_sent;
394         uint32_t node_packets_recv;
395         uint32_t keepalive_packets_sent;
396         uint32_t keepalive_packets_recv;
397         struct {
398                 uint32_t req_call;
399                 uint32_t reply_call;
400                 uint32_t req_dmaster;
401                 uint32_t reply_dmaster;
402                 uint32_t reply_error;
403                 uint32_t req_message;
404                 uint32_t req_control;
405                 uint32_t reply_control;
406         } node;
407         struct {
408                 uint32_t req_call;
409                 uint32_t req_message;
410                 uint32_t req_control;
411         } client;
412         struct {
413                 uint32_t call;
414                 uint32_t control;
415                 uint32_t traverse;
416         } timeouts;
417         struct {
418                 struct ctdb_latency_counter ctdbd;
419                 struct ctdb_latency_counter recd;
420         } reclock;
421         struct {
422                 uint32_t num_calls;
423                 uint32_t num_current;
424                 uint32_t num_pending;
425                 uint32_t num_failed;
426                 struct ctdb_latency_counter latency;
427                 uint32_t buckets[MAX_COUNT_BUCKETS];
428         } locks;
429         uint32_t total_calls;
430         uint32_t pending_calls;
431         uint32_t childwrite_calls;
432         uint32_t pending_childwrite_calls;
433         uint32_t memory_used;
434         uint32_t __last_counter; /* hack */
435         uint32_t max_hop_count;
436         uint32_t hop_count_bucket[MAX_COUNT_BUCKETS];
437         struct ctdb_latency_counter call_latency;
438         struct ctdb_latency_counter childwrite_latency;
439         uint32_t num_recoveries;
440         struct timeval statistics_start_time;
441         struct timeval statistics_current_time;
442         uint32_t total_ro_delegations;
443         uint32_t total_ro_revokes;
444 };
445
446 #define INVALID_GENERATION 1
447 /* table that contains the mapping between a hash value and lmaster
448  */
449 struct ctdb_vnn_map {
450         uint32_t generation;
451         uint32_t size;
452         uint32_t *map;
453 };
454
455 struct ctdb_dbid {
456         uint32_t db_id;
457 #define CTDB_DB_FLAGS_PERSISTENT        0x01
458 #define CTDB_DB_FLAGS_READONLY          0x02
459 #define CTDB_DB_FLAGS_STICKY            0x04
460 #define CTDB_DB_FLAGS_REPLICATED        0x08
461         uint8_t flags;
462 };
463
464 struct ctdb_dbid_map {
465         uint32_t num;
466         struct ctdb_dbid *dbs;
467 };
468
469 struct ctdb_pulldb {
470         uint32_t db_id;
471 #define CTDB_LMASTER_ANY        0xffffffff
472         uint32_t lmaster;
473 };
474
475 struct ctdb_pulldb_ext {
476         uint32_t db_id;
477         uint32_t lmaster;
478         uint64_t srvid;
479 };
480
481 #define CTDB_RECOVERY_NORMAL            0
482 #define CTDB_RECOVERY_ACTIVE            1
483
484 /*
485   the extended header for records in the ltdb
486 */
487 struct ctdb_ltdb_header {
488         uint64_t rsn;
489         uint32_t dmaster;
490         uint32_t reserved1;
491 #define CTDB_REC_FLAG_DEFAULT                   0x00000000
492 #define CTDB_REC_FLAG_MIGRATED_WITH_DATA        0x00010000
493 #define CTDB_REC_FLAG_VACUUM_MIGRATED           0x00020000
494 #define CTDB_REC_FLAG_AUTOMATIC                 0x00040000
495 #define CTDB_REC_RO_HAVE_DELEGATIONS            0x01000000
496 #define CTDB_REC_RO_HAVE_READONLY               0x02000000
497 #define CTDB_REC_RO_REVOKING_READONLY           0x04000000
498 #define CTDB_REC_RO_REVOKE_COMPLETE             0x08000000
499 #define CTDB_REC_RO_FLAGS                       (CTDB_REC_RO_HAVE_DELEGATIONS|\
500                                                  CTDB_REC_RO_HAVE_READONLY|\
501                                                  CTDB_REC_RO_REVOKING_READONLY|\
502                                                  CTDB_REC_RO_REVOKE_COMPLETE)
503         uint32_t flags;
504 };
505
506 struct ctdb_rec_data {
507         uint32_t reqid;
508         struct ctdb_ltdb_header *header;
509         TDB_DATA key, data;
510 };
511
512 struct ctdb_rec_buffer {
513         uint32_t db_id;
514         uint32_t count;
515         uint8_t *buf;
516         size_t buflen;
517 };
518
519 typedef int (*ctdb_rec_parser_func_t)(uint32_t reqid,
520                                       struct ctdb_ltdb_header *header,
521                                       TDB_DATA key, TDB_DATA data,
522                                       void *private_data);
523
524 struct ctdb_traverse_start {
525         uint32_t db_id;
526         uint32_t reqid;
527         uint64_t srvid;
528 };
529
530 struct ctdb_traverse_all {
531         uint32_t db_id;
532         uint32_t reqid;
533         uint32_t pnn;
534         uint32_t client_reqid;
535         uint64_t srvid;
536 };
537
538 struct ctdb_traverse_start_ext {
539         uint32_t db_id;
540         uint32_t reqid;
541         uint64_t srvid;
542         bool withemptyrecords;
543 };
544
545 struct ctdb_traverse_all_ext {
546         uint32_t db_id;
547         uint32_t reqid;
548         uint32_t pnn;
549         uint32_t client_reqid;
550         uint64_t srvid;
551         bool withemptyrecords;
552 };
553
554 typedef union {
555         struct sockaddr sa;
556         struct sockaddr_in ip;
557         struct sockaddr_in6 ip6;
558 } ctdb_sock_addr;
559
560 struct ctdb_connection {
561         ctdb_sock_addr src;
562         ctdb_sock_addr dst;
563 };
564
565 struct ctdb_tunable {
566         const char *name;
567         uint32_t value;
568 };
569
570 struct ctdb_var_list {
571         int count;
572         const char **var;
573 };
574
575 struct ctdb_node_flag_change {
576         uint32_t pnn;
577         uint32_t new_flags;
578         uint32_t old_flags;
579 };
580
581 /* all tunable variables go in here */
582 struct ctdb_tunable_list {
583         uint32_t max_redirect_count;
584         uint32_t seqnum_interval; /* unit is ms */
585         uint32_t control_timeout;
586         uint32_t traverse_timeout;
587         uint32_t keepalive_interval;
588         uint32_t keepalive_limit;
589         uint32_t recover_timeout;
590         uint32_t recover_interval;
591         uint32_t election_timeout;
592         uint32_t takeover_timeout;
593         uint32_t monitor_interval;
594         uint32_t tickle_update_interval;
595         uint32_t script_timeout;
596         uint32_t monitor_timeout_count; /* allow dodgy scripts to hang this many times in a row before we mark the node unhealthy */
597         uint32_t script_unhealthy_on_timeout; /* obsolete */
598         uint32_t recovery_grace_period;
599         uint32_t recovery_ban_period;
600         uint32_t database_hash_size;
601         uint32_t database_max_dead;
602         uint32_t rerecovery_timeout;
603         uint32_t enable_bans;
604         uint32_t deterministic_public_ips;
605         uint32_t reclock_ping_period;
606         uint32_t no_ip_failback;
607         uint32_t disable_ip_failover;
608         uint32_t verbose_memory_names;
609         uint32_t recd_ping_timeout;
610         uint32_t recd_ping_failcount;
611         uint32_t log_latency_ms;
612         uint32_t reclock_latency_ms;
613         uint32_t recovery_drop_all_ips;
614         uint32_t verify_recovery_lock;
615         uint32_t vacuum_interval;
616         uint32_t vacuum_max_run_time;
617         uint32_t repack_limit;
618         uint32_t vacuum_limit;
619         uint32_t max_queue_depth_drop_msg;
620         uint32_t allow_unhealthy_db_read;
621         uint32_t stat_history_interval;
622         uint32_t deferred_attach_timeout;
623         uint32_t vacuum_fast_path_count;
624         uint32_t lcp2_public_ip_assignment;
625         uint32_t allow_client_db_attach;
626         uint32_t recover_pdb_by_seqnum;
627         uint32_t deferred_rebalance_on_node_add;
628         uint32_t fetch_collapse;
629         uint32_t hopcount_make_sticky;
630         uint32_t sticky_duration;
631         uint32_t sticky_pindown;
632         uint32_t no_ip_takeover;
633         uint32_t db_record_count_warn;
634         uint32_t db_record_size_warn;
635         uint32_t db_size_warn;
636         uint32_t pulldb_preallocation_size;
637         uint32_t no_ip_host_on_all_disabled;
638         uint32_t samba3_hack;
639         uint32_t mutex_enabled;
640         uint32_t lock_processes_per_db;
641         uint32_t rec_buffer_size_limit;
642         uint32_t queue_buffer_size;
643         uint32_t ip_alloc_algorithm;
644         uint32_t allow_mixed_versions;
645 };
646
647 struct ctdb_tickle_list {
648         ctdb_sock_addr addr;
649         uint32_t num;
650         struct ctdb_connection *conn;
651 };
652
653 struct ctdb_addr_info {
654         ctdb_sock_addr addr;
655         uint32_t mask;
656         const char *iface;
657 };
658
659 struct ctdb_transdb {
660         uint32_t db_id;
661         uint32_t tid;
662 };
663
664 struct ctdb_uptime {
665         struct timeval current_time;
666         struct timeval ctdbd_start_time;
667         struct timeval last_recovery_started;
668         struct timeval last_recovery_finished;
669 };
670
671 struct ctdb_public_ip {
672         uint32_t pnn;
673         ctdb_sock_addr addr;
674 };
675
676 struct ctdb_public_ip_list {
677         uint32_t num;
678         struct ctdb_public_ip *ip;
679 };
680
681 /*
682  * Node flags
683  */
684 #define NODE_FLAGS_DISCONNECTED         0x00000001 /* node isn't connected */
685 #define NODE_FLAGS_UNHEALTHY            0x00000002 /* monitoring says node is unhealthy */
686 #define NODE_FLAGS_PERMANENTLY_DISABLED 0x00000004 /* administrator has disabled node */
687 #define NODE_FLAGS_BANNED               0x00000008 /* recovery daemon has banned the node */
688 #define NODE_FLAGS_DELETED              0x00000010 /* this node has been deleted */
689 #define NODE_FLAGS_STOPPED              0x00000020 /* this node has been stopped */
690 #define NODE_FLAGS_DISABLED             (NODE_FLAGS_UNHEALTHY|NODE_FLAGS_PERMANENTLY_DISABLED)
691 #define NODE_FLAGS_INACTIVE             (NODE_FLAGS_DELETED|NODE_FLAGS_DISCONNECTED|NODE_FLAGS_BANNED|NODE_FLAGS_STOPPED)
692
693 /*
694  * Node capabilities
695  */
696 #define CTDB_CAP_RECMASTER              0x00000001
697 #define CTDB_CAP_LMASTER                0x00000002
698 #define CTDB_CAP_LVS                    0x00000004 /* obsolete */
699 #define CTDB_CAP_NATGW                  0x00000008 /* obsolete */
700
701 /*
702  * Node features
703  */
704 #define CTDB_CAP_PARALLEL_RECOVERY      0x00010000
705 #define CTDB_CAP_FRAGMENTED_CONTROLS    0x00020000
706
707 #define CTDB_CAP_FEATURES               (CTDB_CAP_PARALLEL_RECOVERY | \
708                                          CTDB_CAP_FRAGMENTED_CONTROLS)
709
710 #define CTDB_CAP_DEFAULT                (CTDB_CAP_RECMASTER | \
711                                          CTDB_CAP_LMASTER   | \
712                                          CTDB_CAP_FEATURES)
713
714 struct ctdb_node_and_flags {
715         uint32_t pnn;
716         uint32_t flags;
717         ctdb_sock_addr addr;
718 };
719
720 struct ctdb_node_map {
721         uint32_t num;
722         struct ctdb_node_and_flags *node;
723 };
724
725 enum ctdb_event {
726         CTDB_EVENT_INIT,                /* CTDB starting up: no args */
727         CTDB_EVENT_SETUP,               /* CTDB starting up after transport is readdy: no args. */
728         CTDB_EVENT_STARTUP,             /* CTDB starting up after initial recovery: no args. */
729         CTDB_EVENT_START_RECOVERY,      /* CTDB recovery starting: no args. */
730         CTDB_EVENT_RECOVERED,           /* CTDB recovery finished: no args. */
731         CTDB_EVENT_TAKE_IP,             /* IP taken: interface, IP address, netmask bits. */
732         CTDB_EVENT_RELEASE_IP,          /* IP released: interface, IP address, netmask bits. */
733         CTDB_EVENT_STOPPED,             /* Deprecated, do not use. */
734         CTDB_EVENT_MONITOR,             /* Please check if service is healthy: no args. */
735         CTDB_EVENT_STATUS,              /* Deprecated, do not use. */
736         CTDB_EVENT_SHUTDOWN,            /* CTDB shutting down: no args. */
737         CTDB_EVENT_RELOAD,              /* Deprecated, do not use */
738         CTDB_EVENT_UPDATE_IP,           /* IP updating: old interface, new interface, IP address, netmask bits. */
739         CTDB_EVENT_IPREALLOCATED,       /* when a takeover_run() completes */
740         CTDB_EVENT_MAX
741 };
742
743 #define MAX_SCRIPT_NAME 31
744 #define MAX_SCRIPT_OUTPUT 511
745
746 struct ctdb_script {
747         char name[MAX_SCRIPT_NAME+1];
748         struct timeval start;
749         struct timeval finished;
750         int32_t status;
751         char output[MAX_SCRIPT_OUTPUT+1];
752 };
753
754 struct ctdb_script_list {
755         uint32_t num_scripts;
756         struct ctdb_script *script;
757 };
758
759 struct ctdb_ban_state {
760         uint32_t pnn;
761         uint32_t time;
762 };
763
764 struct ctdb_notify_data {
765         uint64_t srvid;
766         TDB_DATA data;
767 };
768
769 #ifdef IFNAMSIZ
770 #define CTDB_IFACE_SIZE IFNAMSIZ
771 #else
772 #define CTDB_IFACE_SIZE 16
773 #endif
774
775 struct ctdb_iface {
776         char name[CTDB_IFACE_SIZE+2];
777         uint16_t link_state;
778         uint32_t references;
779 };
780
781 struct ctdb_iface_list {
782         uint32_t num;
783         struct ctdb_iface *iface;
784 };
785
786 struct ctdb_public_ip_info {
787         struct ctdb_public_ip ip;
788         uint32_t active_idx;
789         struct ctdb_iface_list *ifaces;
790 };
791
792 struct ctdb_statistics_list {
793         int num;
794         struct ctdb_statistics *stats;
795 };
796
797 struct ctdb_key_data {
798         uint32_t db_id;
799         struct ctdb_ltdb_header header;
800         TDB_DATA key;
801 };
802
803 struct ctdb_db_statistics {
804         struct {
805                 uint32_t num_calls;
806                 uint32_t num_current;
807                 uint32_t num_pending;
808                 uint32_t num_failed;
809                 struct ctdb_latency_counter latency;
810                 uint32_t buckets[MAX_COUNT_BUCKETS];
811         } locks;
812         struct {
813                 struct ctdb_latency_counter latency;
814         } vacuum;
815         uint32_t db_ro_delegations;
816         uint32_t db_ro_revokes;
817         uint32_t hop_count_bucket[MAX_COUNT_BUCKETS];
818         uint32_t num_hot_keys;
819         struct {
820                 uint32_t count;
821                 TDB_DATA key;
822         } hot_keys[MAX_HOT_KEYS];
823 };
824
825 enum ctdb_runstate {
826         CTDB_RUNSTATE_UNKNOWN,
827         CTDB_RUNSTATE_INIT,
828         CTDB_RUNSTATE_SETUP,
829         CTDB_RUNSTATE_FIRST_RECOVERY,
830         CTDB_RUNSTATE_STARTUP,
831         CTDB_RUNSTATE_RUNNING,
832         CTDB_RUNSTATE_SHUTDOWN,
833 };
834
835 struct ctdb_req_control_data {
836         uint32_t opcode;
837         union {
838                 pid_t pid;
839                 uint32_t db_id;
840                 struct ctdb_vnn_map *vnnmap;
841                 uint32_t loglevel;
842                 struct ctdb_pulldb *pulldb;
843                 struct ctdb_pulldb_ext *pulldb_ext;
844                 struct ctdb_rec_buffer *recbuf;
845                 uint32_t recmode;
846                 const char *db_name;
847                 struct ctdb_traverse_start *traverse_start;
848                 struct ctdb_traverse_all *traverse_all;
849                 struct ctdb_rec_data *rec_data;
850                 uint32_t recmaster;
851                 struct ctdb_connection *conn;
852                 struct ctdb_tunable *tunable;
853                 const char *tun_var;
854                 struct ctdb_node_flag_change *flag_change;
855                 ctdb_sock_addr *addr;
856                 struct ctdb_tickle_list *tickles;
857                 struct ctdb_client_id *cid;
858                 struct ctdb_addr_info *addr_info;
859                 struct ctdb_transdb *transdb;
860                 struct ctdb_public_ip *pubip;
861                 enum ctdb_event event;
862                 double reclock_latency;
863                 uint32_t role;
864                 struct ctdb_ban_state *ban_state;
865                 struct ctdb_notify_data *notify;
866                 uint64_t srvid;
867                 struct ctdb_iface *iface;
868                 struct ctdb_key_data *key;
869                 struct ctdb_traverse_start_ext *traverse_start_ext;
870                 struct ctdb_traverse_all_ext *traverse_all_ext;
871         } data;
872 };
873
874 struct ctdb_reply_control_data {
875         uint32_t opcode;
876         union {
877                 struct ctdb_statistics *stats;
878                 const char *db_path;
879                 struct ctdb_vnn_map *vnnmap;
880                 uint32_t loglevel;
881                 struct ctdb_dbid_map *dbmap;
882                 struct ctdb_rec_buffer *recbuf;
883                 uint32_t db_id;
884                 const char *db_name;
885                 const char *mem_str;
886                 uint32_t tun_value;
887                 struct ctdb_var_list *tun_var_list;
888                 struct ctdb_tunable_list *tun_list;
889                 struct ctdb_tickle_list *tickles;
890                 struct ctdb_client_id_map *cid_map;
891                 struct ctdb_uptime *uptime;
892                 uint32_t caps;
893                 struct ctdb_public_ip_list *pubip_list;
894                 struct ctdb_node_map *nodemap;
895                 const char *reclock_file;
896                 struct ctdb_ban_state *ban_state;
897                 uint64_t seqnum;
898                 const char *reason;
899                 struct ctdb_public_ip_info *ipinfo;
900                 struct ctdb_iface_list *iface_list;
901                 struct ctdb_statistics_list *stats_list;
902                 struct ctdb_db_statistics *dbstats;
903                 enum ctdb_runstate runstate;
904                 uint32_t num_records;
905                 int tdb_flags;
906         } data;
907 };
908
909 struct ctdb_req_control {
910         uint32_t opcode;
911         uint32_t pad;
912         uint64_t srvid;
913         uint32_t client_id;
914 #define CTDB_CTRL_FLAG_NOREPLY   1
915 #define CTDB_CTRL_FLAG_OPCODE_SPECIFIC   0xFFFF0000
916 /* Ugly overloading of this field... */
917 #define CTDB_PUBLIC_IP_FLAGS_ONLY_AVAILABLE 0x00010000
918         uint32_t flags;
919         struct ctdb_req_control_data rdata;
920 };
921
922 struct ctdb_reply_control {
923         int32_t status;
924         const char *errmsg;
925         struct ctdb_reply_control_data rdata;
926 };
927
928 struct ctdb_election_message {
929         uint32_t num_connected;
930         struct timeval priority_time;
931         uint32_t pnn;
932         uint32_t node_flags;
933 };
934
935 struct ctdb_srvid_message {
936         uint32_t pnn;
937         uint64_t srvid;
938 };
939
940 struct ctdb_disable_message {
941         uint32_t pnn;
942         uint64_t srvid;
943         uint32_t timeout;
944 };
945
946 union ctdb_message_data {
947         /* SRVID_ELECTION */
948         struct ctdb_election_message *election;
949         /* SRVID_RELEASE_IP, SRVID_TAKE_IP */
950         const char *ipaddr;
951         /* SRVID_SET_NODE_FLAGS, SERVID_PUSH_NODE_FLAGS */
952         struct ctdb_node_flag_change *flag_change;
953         /* SRVID_RECD_UPDATE_IP */
954         struct ctdb_public_ip *pubip;
955         /* SRVID_VACUUM_FETCH */
956         struct ctdb_rec_buffer *recbuf;
957         /* SRVID_DETACH_DATABASE */
958         uint32_t db_id;
959         /* SRVID_MEM_DUMP, SRVID_TAKEOVER_RUN */
960         struct ctdb_srvid_message *msg;
961         /* SRVID_BANNING, SRVID_REBALANCE_NODE */
962         uint32_t pnn;
963         /* SRVID_DISABLE_TAKEOVER_RUNS, SRVID_DISABLE_RECOVERIES */
964         struct ctdb_disable_message *disable;
965         /* SRVID_DISABLE_IP_CHECK */
966         uint32_t timeout;
967         /* Other */
968         TDB_DATA data;
969 };
970
971 struct ctdb_req_message {
972         uint64_t srvid;
973         union ctdb_message_data data;
974 };
975
976 struct ctdb_req_message_data {
977         uint64_t srvid;
978         TDB_DATA data;
979 };
980
981 struct ctdb_req_keepalive {
982         uint32_t version;
983         uint32_t uptime;
984 };
985
986
987 /* This is equivalent to server_id */
988 struct ctdb_server_id {
989         uint64_t pid;
990         uint32_t task_id;
991         uint32_t vnn;
992         uint64_t unique_id;
993 };
994
995 enum ctdb_g_lock_type {
996         CTDB_G_LOCK_READ = 0,
997         CTDB_G_LOCK_WRITE = 1,
998 };
999
1000 struct ctdb_g_lock {
1001         enum ctdb_g_lock_type type;
1002         struct ctdb_server_id sid;
1003 };
1004
1005 struct ctdb_g_lock_list {
1006         unsigned int num;
1007         struct ctdb_g_lock *lock;
1008 };
1009
1010 /*
1011  * Generic packet header
1012  */
1013
1014 struct sock_packet_header {
1015         uint32_t length;
1016         uint32_t reqid;
1017 };
1018
1019 /*
1020  * Eventd protocol
1021  */
1022
1023 enum ctdb_event_command {
1024         CTDB_EVENT_COMMAND_RUN            = 1,
1025         CTDB_EVENT_COMMAND_STATUS         = 2,
1026         CTDB_EVENT_COMMAND_SCRIPT_LIST    = 3,
1027         CTDB_EVENT_COMMAND_SCRIPT_ENABLE  = 4,
1028         CTDB_EVENT_COMMAND_SCRIPT_DISABLE = 5,
1029 };
1030
1031 enum ctdb_event_status_state {
1032         CTDB_EVENT_LAST_RUN     = 1,
1033         CTDB_EVENT_LAST_PASS    = 2,
1034         CTDB_EVENT_LAST_FAIL    = 3,
1035 };
1036
1037 struct ctdb_event_request_run {
1038         enum ctdb_event event;
1039         uint32_t timeout;
1040         const char *arg_str;
1041 };
1042
1043 struct ctdb_event_request_status {
1044         enum ctdb_event event;
1045         enum ctdb_event_status_state state;
1046 };
1047
1048 struct ctdb_event_request_script_enable {
1049         const char *script_name;
1050 };
1051
1052 struct ctdb_event_request_script_disable {
1053         const char *script_name;
1054 };
1055
1056 struct ctdb_event_request_data {
1057         enum ctdb_event_command command;
1058         union {
1059                 struct ctdb_event_request_run *run;
1060                 struct ctdb_event_request_status *status;
1061                 struct ctdb_event_request_script_enable *script_enable;
1062                 struct ctdb_event_request_script_disable *script_disable;
1063         } data;
1064 };
1065
1066 struct ctdb_event_reply_status {
1067         int status;
1068         struct ctdb_script_list *script_list;
1069 };
1070
1071 struct ctdb_event_reply_script_list {
1072         struct ctdb_script_list *script_list;
1073 };
1074
1075 struct ctdb_event_reply_data {
1076         enum ctdb_event_command command;
1077         int32_t result;
1078         union {
1079                 struct ctdb_event_reply_status *status;
1080                 struct ctdb_event_reply_script_list *script_list;
1081         } data;
1082 };
1083
1084 struct ctdb_event_header {
1085         uint32_t length;
1086         uint32_t reqid;
1087 };
1088
1089 struct ctdb_event_request {
1090         struct sock_packet_header header;
1091         struct ctdb_event_request_data rdata;
1092 };
1093
1094 struct ctdb_event_reply {
1095         struct sock_packet_header header;
1096         struct ctdb_event_reply_data rdata;
1097 };
1098
1099 #endif /* __CTDB_PROTOCOL_H__ */