a9f6249d617788c73d1530556ac679fbdb49a3f5
[metze/ctdb/wip.git] / include / ctdb_protocol.h
1 /*
2    ctdb database library
3
4    Copyright (C) Andrew Tridgell  2006
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef _CTDB_PROTOCOL_H
21 #define _CTDB_PROTOCOL_H
22
23 /* location of daemon socket */
24 #define CTDB_PATH       "/tmp/ctdb.socket"
25
26 /* default ctdb port number */
27 #define CTDB_PORT 4379
28
29 /* we must align packets to ensure ctdb works on all architectures (eg. sparc) */
30 #define CTDB_DS_ALIGNMENT 8
31
32
33 #define CTDB_NULL_FUNC      0xFF000001
34 #define CTDB_FETCH_FUNC     0xFF000002
35
36
37 #define CTDB_IMMEDIATE_MIGRATION        0x00000001
38 struct ctdb_call {
39         int call_id;
40         TDB_DATA key;
41         TDB_DATA call_data;
42         TDB_DATA reply_data;
43         uint32_t status;
44         uint32_t flags;
45 };
46
47 /*
48   structure passed to a ctdb call backend function
49 */
50 struct ctdb_call_info {
51         TDB_DATA key;          /* record key */
52         TDB_DATA record_data;  /* current data in the record */
53         TDB_DATA *new_data;    /* optionally updated record data */
54         TDB_DATA *call_data;   /* optionally passed from caller */
55         TDB_DATA *reply_data;  /* optionally returned by function */
56         uint32_t status;       /* optional reply status - defaults to zero */
57 };
58
59 #define CTDB_ERR_INVALID 1
60 #define CTDB_ERR_NOMEM 2
61
62 /*
63   ctdb flags
64 */
65 #define CTDB_FLAG_TORTURE      (1<<1)
66
67 /*
68    a message handler ID meaning "give me all messages"
69  */
70 #define CTDB_SRVID_ALL (~(uint64_t)0)
71
72 /*
73   srvid type : RECOVERY
74 */
75 #define CTDB_SRVID_RECOVERY     0xF100000000000000LL
76
77 /*
78    a message handler ID meaning that the cluster has been reconfigured
79  */
80 #define CTDB_SRVID_RECONFIGURE 0xF200000000000000LL
81
82 /*
83    a message handler ID meaning that an IP address has been released
84  */
85 #define CTDB_SRVID_RELEASE_IP 0xF300000000000000LL
86
87 /*
88    a message handler ID meaning that an IP address has been taken
89  */
90 #define CTDB_SRVID_TAKE_IP 0xF301000000000000LL
91
92 /*
93    a message ID to set the node flags in the recovery daemon
94  */
95 #define CTDB_SRVID_SET_NODE_FLAGS 0xF400000000000000LL
96
97 /*
98    a message ID to ask the recovery daemon to update the expected node
99    assignment for a public ip
100  */
101 #define CTDB_SRVID_RECD_UPDATE_IP 0xF500000000000000LL
102
103 /*
104   a message to tell the recovery daemon to fetch a set of records
105  */
106 #define CTDB_SRVID_VACUUM_FETCH 0xF700000000000000LL
107
108 /*
109   a message to tell the recovery daemon to write a talloc memdump
110   to the log
111  */
112 #define CTDB_SRVID_MEM_DUMP 0xF800000000000000LL
113
114 /*
115    a message ID to get the recovery daemon to push the node flags out
116  */
117 #define CTDB_SRVID_PUSH_NODE_FLAGS 0xF900000000000000LL
118
119 /*
120    a message ID to get the recovery daemon to reload the nodes file
121  */
122 #define CTDB_SRVID_RELOAD_NODES 0xFA00000000000000LL
123
124 /*
125    a message ID to get the recovery daemon to perform a takeover run
126  */
127 #define CTDB_SRVID_TAKEOVER_RUN 0xFB00000000000000LL
128
129 /* A message id to ask the recovery daemon to temporarily disable the
130    public ip checks
131 */
132 #define CTDB_SRVID_DISABLE_IP_CHECK  0xFC00000000000000LL
133
134 /* A dummy port used for sending back ipreallocate resposnes to the main
135    daemon
136 */
137 #define CTDB_SRVID_TAKEOVER_RUN_RESPONSE  0xFD00000000000000LL
138
139 /* A range of ports reserved for samba (top 32 bits)
140  * All ports matching the 32 top bits are reserved for exclusive use by
141  * CIFS server
142  */
143 #define CTDB_SRVID_SAMBA_NOTIFY  0xFE00000000000000LL
144 #define CTDB_SRVID_SAMBA_RANGE   0xFE00000000000000LL
145
146 /* A range of ports reserved for a CTDB NFS server (top 32 bits)
147  * All ports matching the 32 top bits are reserved for exclusive use by
148  * NFS server
149  */
150 #define CTDB_SRVID_NFSD_RANGE  0xFE01000000000000LL
151
152 /* A range of ports reserved for a CTDB ISCSI server (top 32 bits)
153  * All ports matching the 32 top bits are reserved for exclusive use by
154  * ISCSI server
155  */
156 #define CTDB_SRVID_ISCSID_RANGE  0xFE02000000000000LL
157
158 /* used on the domain socket, send a pdu to the local daemon */
159 #define CTDB_CURRENT_NODE     0xF0000001
160 /* send a broadcast to all nodes in the cluster, active or not */
161 #define CTDB_BROADCAST_ALL    0xF0000002
162 /* send a broadcast to all nodes in the current vnn map */
163 #define CTDB_BROADCAST_VNNMAP 0xF0000003
164 /* send a broadcast to all connected nodes */
165 #define CTDB_BROADCAST_CONNECTED 0xF0000004
166
167 /* the key used for transaction locking on persistent databases */
168 #define CTDB_TRANSACTION_LOCK_KEY "__transaction_lock__"
169
170 /* the key used to store persistent db sequence number */
171 #define CTDB_DB_SEQNUM_KEY "__db_sequence_number__"
172
173 #define MONITOR_SCRIPT_OK      0
174 #define MONITOR_SCRIPT_TIMEOUT 1
175
176 #define MAX_SCRIPT_NAME 31
177 #define MAX_SCRIPT_OUTPUT 511
178 struct ctdb_script_wire {
179         char name[MAX_SCRIPT_NAME+1];
180         struct timeval start;
181         struct timeval finished;
182         int32_t status;
183         char output[MAX_SCRIPT_OUTPUT+1];
184 };
185
186 struct ctdb_scripts_wire {
187         uint32_t num_scripts;
188         struct ctdb_script_wire scripts[1];
189 };
190
191 /* different calls to event scripts. */
192 enum ctdb_eventscript_call {
193         CTDB_EVENT_INIT,                /* CTDB starting up: no args */
194         CTDB_EVENT_SETUP,               /* CTDB starting up after transport is readdy: no args. */
195         CTDB_EVENT_STARTUP,             /* CTDB starting up after initial recovery: no args. */
196         CTDB_EVENT_START_RECOVERY,      /* CTDB recovery starting: no args. */
197         CTDB_EVENT_RECOVERED,           /* CTDB recovery finished: no args. */
198         CTDB_EVENT_TAKE_IP,             /* IP taken: interface, IP address, netmask bits. */
199         CTDB_EVENT_RELEASE_IP,          /* IP released: interface, IP address, netmask bits. */
200         CTDB_EVENT_STOPPED,             /* This node is stopped: no args. */
201         CTDB_EVENT_MONITOR,             /* Please check if service is healthy: no args. */
202         CTDB_EVENT_STATUS,              /* Report service status: no args. */
203         CTDB_EVENT_SHUTDOWN,            /* CTDB shutting down: no args. */
204         CTDB_EVENT_RELOAD,              /* magic */
205         CTDB_EVENT_UPDATE_IP,           /* IP updating: old interface, new interface, IP address, netmask bits. */
206         CTDB_EVENT_IPREALLOCATED,       /* when a takeover_run() completes */
207         CTDB_EVENT_MAX
208 };
209
210 /* Mapping from enum to names. */
211 extern const char *ctdb_eventscript_call_names[];
212
213 /*
214   operation IDs
215 */
216 enum ctdb_operation {
217         CTDB_REQ_CALL           = 0,
218         CTDB_REPLY_CALL         = 1,
219         CTDB_REQ_DMASTER        = 2,
220         CTDB_REPLY_DMASTER      = 3,
221         CTDB_REPLY_ERROR        = 4,
222         CTDB_REQ_MESSAGE        = 5,
223         /* #6 removed */
224         CTDB_REQ_CONTROL        = 7,
225         CTDB_REPLY_CONTROL      = 8,
226         CTDB_REQ_KEEPALIVE      = 9,
227 };
228
229 #define CTDB_MAGIC 0x43544442 /* CTDB */
230 #define CTDB_VERSION 1
231
232 enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS          = 0,
233                     CTDB_CONTROL_STATISTICS              = 1,
234                     /* #2 removed */
235                     CTDB_CONTROL_PING                    = 3,
236                     CTDB_CONTROL_GETDBPATH               = 4,
237                     CTDB_CONTROL_GETVNNMAP               = 5,
238                     CTDB_CONTROL_SETVNNMAP               = 6,
239                     CTDB_CONTROL_GET_DEBUG               = 7,
240                     CTDB_CONTROL_SET_DEBUG               = 8,
241                     CTDB_CONTROL_GET_DBMAP               = 9,
242                     CTDB_CONTROL_GET_NODEMAPv4           = 10, /* obsolete */
243                     CTDB_CONTROL_SET_DMASTER             = 11,
244                     /* #12 removed */
245                     CTDB_CONTROL_PULL_DB                 = 13,
246                     CTDB_CONTROL_PUSH_DB                 = 14,
247                     CTDB_CONTROL_GET_RECMODE             = 15,
248                     CTDB_CONTROL_SET_RECMODE             = 16,
249                     CTDB_CONTROL_STATISTICS_RESET        = 17,
250                     CTDB_CONTROL_DB_ATTACH               = 18,
251                     CTDB_CONTROL_SET_CALL                = 19,
252                     CTDB_CONTROL_TRAVERSE_START          = 20,
253                     CTDB_CONTROL_TRAVERSE_ALL            = 21,
254                     CTDB_CONTROL_TRAVERSE_DATA           = 22,
255                     CTDB_CONTROL_REGISTER_SRVID          = 23,
256                     CTDB_CONTROL_DEREGISTER_SRVID        = 24,
257                     CTDB_CONTROL_GET_DBNAME              = 25,
258                     CTDB_CONTROL_ENABLE_SEQNUM           = 26,
259                     CTDB_CONTROL_UPDATE_SEQNUM           = 27,
260                     /* #28 removed */
261                     CTDB_CONTROL_DUMP_MEMORY             = 29,
262                     CTDB_CONTROL_GET_PID                 = 30,
263                     CTDB_CONTROL_GET_RECMASTER           = 31,
264                     CTDB_CONTROL_SET_RECMASTER           = 32,
265                     CTDB_CONTROL_FREEZE                  = 33,
266                     CTDB_CONTROL_THAW                    = 34,
267                     CTDB_CONTROL_GET_PNN                 = 35,
268                     CTDB_CONTROL_SHUTDOWN                = 36,
269                     CTDB_CONTROL_GET_MONMODE             = 37,
270                     /* #38 removed */
271                     /* #39 removed */
272                     /* #40 removed */
273                     /* #41 removed */
274                     CTDB_CONTROL_TAKEOVER_IPv4           = 42, /* obsolete */
275                     CTDB_CONTROL_RELEASE_IPv4            = 43, /* obsolete */
276                     CTDB_CONTROL_TCP_CLIENT              = 44,
277                     CTDB_CONTROL_TCP_ADD                 = 45,
278                     CTDB_CONTROL_TCP_REMOVE              = 46,
279                     CTDB_CONTROL_STARTUP                 = 47,
280                     CTDB_CONTROL_SET_TUNABLE             = 48,
281                     CTDB_CONTROL_GET_TUNABLE             = 49,
282                     CTDB_CONTROL_LIST_TUNABLES           = 50,
283                     CTDB_CONTROL_GET_PUBLIC_IPSv4        = 51, /* obsolete */
284                     CTDB_CONTROL_MODIFY_FLAGS            = 52,
285                     CTDB_CONTROL_GET_ALL_TUNABLES        = 53,
286                     CTDB_CONTROL_KILL_TCP                = 54,
287                     CTDB_CONTROL_GET_TCP_TICKLE_LIST     = 55,
288                     CTDB_CONTROL_SET_TCP_TICKLE_LIST     = 56,
289                     CTDB_CONTROL_REGISTER_SERVER_ID      = 57,
290                     CTDB_CONTROL_UNREGISTER_SERVER_ID    = 58,
291                     CTDB_CONTROL_CHECK_SERVER_ID         = 59,
292                     CTDB_CONTROL_GET_SERVER_ID_LIST      = 60,
293                     CTDB_CONTROL_DB_ATTACH_PERSISTENT    = 61,
294                     CTDB_CONTROL_PERSISTENT_STORE        = 62,
295                     CTDB_CONTROL_UPDATE_RECORD           = 63,
296                     CTDB_CONTROL_SEND_GRATIOUS_ARP       = 64,
297                     CTDB_CONTROL_TRANSACTION_START       = 65,
298                     CTDB_CONTROL_TRANSACTION_COMMIT      = 66,
299                     CTDB_CONTROL_WIPE_DATABASE           = 67,
300                     /* #68 removed */
301                     CTDB_CONTROL_UPTIME                  = 69,
302                     CTDB_CONTROL_START_RECOVERY          = 70,
303                     CTDB_CONTROL_END_RECOVERY            = 71,
304                     CTDB_CONTROL_RELOAD_NODES_FILE       = 72,
305                     /* #73 removed */
306                     CTDB_CONTROL_TRY_DELETE_RECORDS      = 74,
307                     CTDB_CONTROL_ENABLE_MONITOR          = 75,
308                     CTDB_CONTROL_DISABLE_MONITOR         = 76,
309                     CTDB_CONTROL_ADD_PUBLIC_IP           = 77,
310                     CTDB_CONTROL_DEL_PUBLIC_IP           = 78,
311                     CTDB_CONTROL_RUN_EVENTSCRIPTS        = 79,
312                     CTDB_CONTROL_GET_CAPABILITIES        = 80,
313                     CTDB_CONTROL_START_PERSISTENT_UPDATE = 81,
314                     CTDB_CONTROL_CANCEL_PERSISTENT_UPDATE= 82,
315                     CTDB_CONTROL_TRANS2_COMMIT           = 83,
316                     CTDB_CONTROL_TRANS2_FINISHED         = 84,
317                     CTDB_CONTROL_TRANS2_ERROR            = 85,
318                     CTDB_CONTROL_TRANS2_COMMIT_RETRY     = 86,
319                     CTDB_CONTROL_RECD_PING               = 87,
320                     CTDB_CONTROL_RELEASE_IP              = 88,
321                     CTDB_CONTROL_TAKEOVER_IP             = 89,
322                     CTDB_CONTROL_GET_PUBLIC_IPS          = 90,
323                     CTDB_CONTROL_GET_NODEMAP             = 91,
324                     CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS = 96,
325                     CTDB_CONTROL_TRAVERSE_KILL           = 97,
326                     CTDB_CONTROL_RECD_RECLOCK_LATENCY    = 98,
327                     CTDB_CONTROL_GET_RECLOCK_FILE        = 99,
328                     CTDB_CONTROL_SET_RECLOCK_FILE        = 100,
329                     CTDB_CONTROL_STOP_NODE               = 101,
330                     CTDB_CONTROL_CONTINUE_NODE           = 102,
331                     CTDB_CONTROL_SET_NATGWSTATE          = 103,
332                     CTDB_CONTROL_SET_LMASTERROLE         = 104,
333                     CTDB_CONTROL_SET_RECMASTERROLE       = 105,
334                     CTDB_CONTROL_ENABLE_SCRIPT           = 107,
335                     CTDB_CONTROL_DISABLE_SCRIPT          = 108,
336                     CTDB_CONTROL_SET_BAN_STATE           = 109,
337                     CTDB_CONTROL_GET_BAN_STATE           = 110,
338                     CTDB_CONTROL_SET_DB_PRIORITY         = 111,
339                     CTDB_CONTROL_GET_DB_PRIORITY         = 112,
340                     CTDB_CONTROL_TRANSACTION_CANCEL      = 113,
341                     CTDB_CONTROL_REGISTER_NOTIFY         = 114,
342                     CTDB_CONTROL_DEREGISTER_NOTIFY       = 115,
343                     CTDB_CONTROL_TRANS2_ACTIVE           = 116,
344                     CTDB_CONTROL_GET_LOG                 = 117,
345                     CTDB_CONTROL_CLEAR_LOG               = 118,
346                     CTDB_CONTROL_TRANS3_COMMIT           = 119,
347                     CTDB_CONTROL_GET_DB_SEQNUM           = 120,
348                     CTDB_CONTROL_DB_SET_HEALTHY          = 121,
349                     CTDB_CONTROL_DB_GET_HEALTH           = 122,
350                     CTDB_CONTROL_GET_PUBLIC_IP_INFO      = 123,
351                     CTDB_CONTROL_GET_IFACES              = 124,
352                     CTDB_CONTROL_SET_IFACE_LINK_STATE    = 125,
353                     CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE  = 126,
354 };
355
356 /*
357   packet structures
358 */
359 struct ctdb_req_header {
360         uint32_t length;
361         uint32_t ctdb_magic;
362         uint32_t ctdb_version;
363         uint32_t generation;
364         uint32_t operation;
365         uint32_t destnode;
366         uint32_t srcnode;
367         uint32_t reqid;
368 };
369
370 struct ctdb_req_call {
371         struct ctdb_req_header hdr;
372         uint32_t flags;
373         uint32_t db_id;
374         uint32_t callid;
375         uint32_t hopcount;
376         uint32_t keylen;
377         uint32_t calldatalen;
378         uint8_t data[1]; /* key[] followed by calldata[] */
379 };
380
381 struct ctdb_reply_call {
382         struct ctdb_req_header hdr;
383         uint32_t status;
384         uint32_t datalen;
385         uint8_t  data[1];
386 };
387
388 struct ctdb_reply_error {
389         struct ctdb_req_header hdr;
390         uint32_t status;
391         uint32_t msglen;
392         uint8_t  msg[1];
393 };
394
395 struct ctdb_req_dmaster {
396         struct ctdb_req_header hdr;
397         uint32_t db_id;
398         uint64_t rsn;
399         uint32_t dmaster;
400         uint32_t keylen;
401         uint32_t datalen;
402         uint8_t  data[1];
403 };
404
405 struct ctdb_reply_dmaster {
406         struct ctdb_req_header hdr;
407         uint32_t db_id;
408         uint64_t rsn;
409         uint32_t keylen;
410         uint32_t datalen;
411         uint8_t  data[1];
412 };
413
414 struct ctdb_req_message {
415         struct ctdb_req_header hdr;
416         uint64_t srvid;
417         uint32_t datalen;
418         uint8_t data[1];
419 };
420
421 struct ctdb_req_getdbpath {
422         struct ctdb_req_header hdr;
423         uint32_t db_id;
424 };
425
426 struct ctdb_reply_getdbpath {
427         struct ctdb_req_header hdr;
428         uint32_t datalen;
429         uint8_t data[1];
430 };
431
432 struct ctdb_req_control {
433         struct ctdb_req_header hdr;
434         uint32_t opcode;
435         uint32_t pad;
436         uint64_t srvid;
437         uint32_t client_id;
438 #define CTDB_CTRL_FLAG_NOREPLY   1
439 #define CTDB_CTRL_FLAG_OPCODE_SPECIFIC   0xFFFF0000
440         uint32_t flags;
441         uint32_t datalen;
442         uint8_t data[1];
443 };
444
445 struct ctdb_reply_control {
446         struct ctdb_req_header hdr;
447         int32_t  status;
448         uint32_t datalen;
449         uint32_t errorlen;
450         uint8_t data[1];
451 };
452
453 struct ctdb_req_keepalive {
454         struct ctdb_req_header hdr;
455 };
456
457
458 /* types of failures possible from TRANS2_COMMIT */
459 enum ctdb_trans2_commit_error {
460         CTDB_TRANS2_COMMIT_SUCCESS=0, /* all nodes committed successfully */
461         CTDB_TRANS2_COMMIT_TIMEOUT=1, /* at least one node timed out */
462         CTDB_TRANS2_COMMIT_ALLFAIL=2, /* all nodes failed the commit */
463         CTDB_TRANS2_COMMIT_SOMEFAIL=3 /* some nodes failed the commit, some allowed it */
464 };
465
466 /*
467   the extended header for records in the ltdb
468 */
469 struct ctdb_ltdb_header {
470         uint64_t rsn;
471         uint32_t dmaster;
472         uint32_t laccessor;
473         uint32_t lacount;
474 };
475
476
477 /*
478   definitions for different socket structures
479  */
480 typedef struct sockaddr_in ctdb_addr_in;
481 typedef struct sockaddr_in6 ctdb_addr_in6;
482 typedef union {
483         struct sockaddr sa;
484         ctdb_addr_in    ip;
485         ctdb_addr_in6   ip6;
486 } ctdb_sock_addr;
487
488 /*
489    A structure describing a single node, its flags and its address
490 */
491 struct ctdb_node_and_flags {
492         uint32_t pnn;
493         uint32_t flags;
494         ctdb_sock_addr addr;
495 };
496
497
498 /*
499    Structure used for a nodemap. 
500    The nodemap is the structure containing a list of all nodes
501    known to the cluster and their associated flags.
502 */
503 struct ctdb_node_map {
504         uint32_t num;
505         struct ctdb_node_and_flags nodes[1];
506 };
507
508 /*
509  * Node flags
510  */
511 #define NODE_FLAGS_DISCONNECTED         0x00000001 /* node isn't connected */
512 #define NODE_FLAGS_UNHEALTHY            0x00000002 /* monitoring says node is unhealthy */
513 #define NODE_FLAGS_PERMANENTLY_DISABLED 0x00000004 /* administrator has disabled node */
514 #define NODE_FLAGS_BANNED               0x00000008 /* recovery daemon has banned the node */
515 #define NODE_FLAGS_DELETED              0x00000010 /* this node has been deleted */
516 #define NODE_FLAGS_STOPPED              0x00000020 /* this node has been stopped */
517 #define NODE_FLAGS_DISABLED             (NODE_FLAGS_UNHEALTHY|NODE_FLAGS_PERMANENTLY_DISABLED)
518 #define NODE_FLAGS_INACTIVE             (NODE_FLAGS_DELETED|NODE_FLAGS_DISCONNECTED|NODE_FLAGS_BANNED|NODE_FLAGS_STOPPED)
519
520
521 #endif