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