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