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