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