ctdb_req_control contains 4 padding bytes. Create an explicit pad variable here and...
[rusty/ctdb.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 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 port reserved for samba (top 32 bits)
135  */
136 #define CTDB_SRVID_SAMBA_NOTIFY  0xFE00000000000000LL
137
138 /* used on the domain socket, send a pdu to the local daemon */
139 #define CTDB_CURRENT_NODE     0xF0000001
140 /* send a broadcast to all nodes in the cluster, active or not */
141 #define CTDB_BROADCAST_ALL    0xF0000002
142 /* send a broadcast to all nodes in the current vnn map */
143 #define CTDB_BROADCAST_VNNMAP 0xF0000003
144 /* send a broadcast to all connected nodes */
145 #define CTDB_BROADCAST_CONNECTED 0xF0000004
146
147 /* the key used for transaction locking on persistent databases */
148 #define CTDB_TRANSACTION_LOCK_KEY "__transaction_lock__"
149
150 /* the key used to store persistent db sequence number */
151 #define CTDB_DB_SEQNUM_KEY "__db_sequence_number__"
152
153 #define MONITOR_SCRIPT_OK      0
154 #define MONITOR_SCRIPT_TIMEOUT 1
155
156 #define MAX_SCRIPT_NAME 31
157 #define MAX_SCRIPT_OUTPUT 511
158 struct ctdb_script_wire {
159         char name[MAX_SCRIPT_NAME+1];
160         struct timeval start;
161         struct timeval finished;
162         int32_t status;
163         char output[MAX_SCRIPT_OUTPUT+1];
164 };
165
166 struct ctdb_scripts_wire {
167         uint32_t num_scripts;
168         struct ctdb_script_wire scripts[1];
169 };
170
171 /* different calls to event scripts. */
172 enum ctdb_eventscript_call {
173         CTDB_EVENT_INIT,                /* CTDB starting up: no args */
174         CTDB_EVENT_SETUP,               /* CTDB starting up after transport is readdy: no args. */
175         CTDB_EVENT_STARTUP,             /* CTDB starting up after initial recovery: no args. */
176         CTDB_EVENT_START_RECOVERY,      /* CTDB recovery starting: no args. */
177         CTDB_EVENT_RECOVERED,           /* CTDB recovery finished: no args. */
178         CTDB_EVENT_TAKE_IP,             /* IP taken: interface, IP address, netmask bits. */
179         CTDB_EVENT_RELEASE_IP,          /* IP released: interface, IP address, netmask bits. */
180         CTDB_EVENT_STOPPED,             /* This node is stopped: no args. */
181         CTDB_EVENT_MONITOR,             /* Please check if service is healthy: no args. */
182         CTDB_EVENT_STATUS,              /* Report service status: no args. */
183         CTDB_EVENT_SHUTDOWN,            /* CTDB shutting down: no args. */
184         CTDB_EVENT_RELOAD,              /* magic */
185         CTDB_EVENT_UPDATE_IP,           /* IP updating: old interface, new interface, IP address, netmask bits. */
186         CTDB_EVENT_MAX
187 };
188
189 /* Mapping from enum to names. */
190 extern const char *ctdb_eventscript_call_names[];
191
192 /*
193   operation IDs
194 */
195 enum ctdb_operation {
196         CTDB_REQ_CALL           = 0,
197         CTDB_REPLY_CALL         = 1,
198         CTDB_REQ_DMASTER        = 2,
199         CTDB_REPLY_DMASTER      = 3,
200         CTDB_REPLY_ERROR        = 4,
201         CTDB_REQ_MESSAGE        = 5,
202         /* #6 removed */
203         CTDB_REQ_CONTROL        = 7,
204         CTDB_REPLY_CONTROL      = 8,
205         CTDB_REQ_KEEPALIVE      = 9,
206 };
207
208 #define CTDB_MAGIC 0x43544442 /* CTDB */
209 #define CTDB_VERSION 1
210
211 enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS          = 0,
212                     CTDB_CONTROL_STATISTICS              = 1,
213                     /* #2 removed */
214                     CTDB_CONTROL_PING                    = 3,
215                     CTDB_CONTROL_GETDBPATH               = 4,
216                     CTDB_CONTROL_GETVNNMAP               = 5,
217                     CTDB_CONTROL_SETVNNMAP               = 6,
218                     CTDB_CONTROL_GET_DEBUG               = 7,
219                     CTDB_CONTROL_SET_DEBUG               = 8,
220                     CTDB_CONTROL_GET_DBMAP               = 9,
221                     CTDB_CONTROL_GET_NODEMAPv4           = 10, /* obsolete */
222                     CTDB_CONTROL_SET_DMASTER             = 11,
223                     /* #12 removed */
224                     CTDB_CONTROL_PULL_DB                 = 13,
225                     CTDB_CONTROL_PUSH_DB                 = 14,
226                     CTDB_CONTROL_GET_RECMODE             = 15,
227                     CTDB_CONTROL_SET_RECMODE             = 16,
228                     CTDB_CONTROL_STATISTICS_RESET        = 17,
229                     CTDB_CONTROL_DB_ATTACH               = 18,
230                     CTDB_CONTROL_SET_CALL                = 19,
231                     CTDB_CONTROL_TRAVERSE_START          = 20,
232                     CTDB_CONTROL_TRAVERSE_ALL            = 21,
233                     CTDB_CONTROL_TRAVERSE_DATA           = 22,
234                     CTDB_CONTROL_REGISTER_SRVID          = 23,
235                     CTDB_CONTROL_DEREGISTER_SRVID        = 24,
236                     CTDB_CONTROL_GET_DBNAME              = 25,
237                     CTDB_CONTROL_ENABLE_SEQNUM           = 26,
238                     CTDB_CONTROL_UPDATE_SEQNUM           = 27,
239                     /* #28 removed */
240                     CTDB_CONTROL_DUMP_MEMORY             = 29,
241                     CTDB_CONTROL_GET_PID                 = 30,
242                     CTDB_CONTROL_GET_RECMASTER           = 31,
243                     CTDB_CONTROL_SET_RECMASTER           = 32,
244                     CTDB_CONTROL_FREEZE                  = 33,
245                     CTDB_CONTROL_THAW                    = 34,
246                     CTDB_CONTROL_GET_PNN                 = 35,
247                     CTDB_CONTROL_SHUTDOWN                = 36,
248                     CTDB_CONTROL_GET_MONMODE             = 37,
249                     /* #38 removed */
250                     /* #39 removed */
251                     /* #40 removed */
252                     /* #41 removed */
253                     CTDB_CONTROL_TAKEOVER_IPv4           = 42, /* obsolete */
254                     CTDB_CONTROL_RELEASE_IPv4            = 43, /* obsolete */
255                     CTDB_CONTROL_TCP_CLIENT              = 44,
256                     CTDB_CONTROL_TCP_ADD                 = 45,
257                     CTDB_CONTROL_TCP_REMOVE              = 46,
258                     CTDB_CONTROL_STARTUP                 = 47,
259                     CTDB_CONTROL_SET_TUNABLE             = 48,
260                     CTDB_CONTROL_GET_TUNABLE             = 49,
261                     CTDB_CONTROL_LIST_TUNABLES           = 50,
262                     CTDB_CONTROL_GET_PUBLIC_IPSv4        = 51, /* obsolete */
263                     CTDB_CONTROL_MODIFY_FLAGS            = 52,
264                     CTDB_CONTROL_GET_ALL_TUNABLES        = 53,
265                     CTDB_CONTROL_KILL_TCP                = 54,
266                     CTDB_CONTROL_GET_TCP_TICKLE_LIST     = 55,
267                     CTDB_CONTROL_SET_TCP_TICKLE_LIST     = 56,
268                     CTDB_CONTROL_REGISTER_SERVER_ID      = 57,
269                     CTDB_CONTROL_UNREGISTER_SERVER_ID    = 58,
270                     CTDB_CONTROL_CHECK_SERVER_ID         = 59,
271                     CTDB_CONTROL_GET_SERVER_ID_LIST      = 60,
272                     CTDB_CONTROL_DB_ATTACH_PERSISTENT    = 61,
273                     CTDB_CONTROL_PERSISTENT_STORE        = 62,
274                     CTDB_CONTROL_UPDATE_RECORD           = 63,
275                     CTDB_CONTROL_SEND_GRATIOUS_ARP       = 64,
276                     CTDB_CONTROL_TRANSACTION_START       = 65,
277                     CTDB_CONTROL_TRANSACTION_COMMIT      = 66,
278                     CTDB_CONTROL_WIPE_DATABASE           = 67,
279                     /* #68 removed */
280                     CTDB_CONTROL_UPTIME                  = 69,
281                     CTDB_CONTROL_START_RECOVERY          = 70,
282                     CTDB_CONTROL_END_RECOVERY            = 71,
283                     CTDB_CONTROL_RELOAD_NODES_FILE       = 72,
284                     /* #73 removed */
285                     CTDB_CONTROL_TRY_DELETE_RECORDS      = 74,
286                     CTDB_CONTROL_ENABLE_MONITOR          = 75,
287                     CTDB_CONTROL_DISABLE_MONITOR         = 76,
288                     CTDB_CONTROL_ADD_PUBLIC_IP           = 77,
289                     CTDB_CONTROL_DEL_PUBLIC_IP           = 78,
290                     CTDB_CONTROL_RUN_EVENTSCRIPTS        = 79,
291                     CTDB_CONTROL_GET_CAPABILITIES        = 80,
292                     CTDB_CONTROL_START_PERSISTENT_UPDATE = 81,
293                     CTDB_CONTROL_CANCEL_PERSISTENT_UPDATE= 82,
294                     CTDB_CONTROL_TRANS2_COMMIT           = 83,
295                     CTDB_CONTROL_TRANS2_FINISHED         = 84,
296                     CTDB_CONTROL_TRANS2_ERROR            = 85,
297                     CTDB_CONTROL_TRANS2_COMMIT_RETRY     = 86,
298                     CTDB_CONTROL_RECD_PING               = 87,
299                     CTDB_CONTROL_RELEASE_IP              = 88,
300                     CTDB_CONTROL_TAKEOVER_IP             = 89,
301                     CTDB_CONTROL_GET_PUBLIC_IPS          = 90,
302                     CTDB_CONTROL_GET_NODEMAP             = 91,
303                     CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS = 96,
304                     CTDB_CONTROL_TRAVERSE_KILL           = 97,
305                     CTDB_CONTROL_RECD_RECLOCK_LATENCY    = 98,
306                     CTDB_CONTROL_GET_RECLOCK_FILE        = 99,
307                     CTDB_CONTROL_SET_RECLOCK_FILE        = 100,
308                     CTDB_CONTROL_STOP_NODE               = 101,
309                     CTDB_CONTROL_CONTINUE_NODE           = 102,
310                     CTDB_CONTROL_SET_NATGWSTATE          = 103,
311                     CTDB_CONTROL_SET_LMASTERROLE         = 104,
312                     CTDB_CONTROL_SET_RECMASTERROLE       = 105,
313                     CTDB_CONTROL_ENABLE_SCRIPT           = 107,
314                     CTDB_CONTROL_DISABLE_SCRIPT          = 108,
315                     CTDB_CONTROL_SET_BAN_STATE           = 109,
316                     CTDB_CONTROL_GET_BAN_STATE           = 110,
317                     CTDB_CONTROL_SET_DB_PRIORITY         = 111,
318                     CTDB_CONTROL_GET_DB_PRIORITY         = 112,
319                     CTDB_CONTROL_TRANSACTION_CANCEL      = 113,
320                     CTDB_CONTROL_REGISTER_NOTIFY         = 114,
321                     CTDB_CONTROL_DEREGISTER_NOTIFY       = 115,
322                     CTDB_CONTROL_TRANS2_ACTIVE           = 116,
323                     CTDB_CONTROL_GET_LOG                 = 117,
324                     CTDB_CONTROL_CLEAR_LOG               = 118,
325                     CTDB_CONTROL_TRANS3_COMMIT           = 119,
326                     CTDB_CONTROL_GET_DB_SEQNUM           = 120,
327                     CTDB_CONTROL_DB_SET_HEALTHY          = 121,
328                     CTDB_CONTROL_DB_GET_HEALTH           = 122,
329                     CTDB_CONTROL_GET_PUBLIC_IP_INFO      = 123,
330                     CTDB_CONTROL_GET_IFACES              = 124,
331                     CTDB_CONTROL_SET_IFACE_LINK_STATE    = 125,
332 };
333
334 /*
335   packet structures
336 */
337 struct ctdb_req_header {
338         uint32_t length;
339         uint32_t ctdb_magic;
340         uint32_t ctdb_version;
341         uint32_t generation;
342         uint32_t operation;
343         uint32_t destnode;
344         uint32_t srcnode;
345         uint32_t reqid;
346 };
347
348 struct ctdb_req_call {
349         struct ctdb_req_header hdr;
350         uint32_t flags;
351         uint32_t db_id;
352         uint32_t callid;
353         uint32_t hopcount;
354         uint32_t keylen;
355         uint32_t calldatalen;
356         uint8_t data[1]; /* key[] followed by calldata[] */
357 };
358
359 struct ctdb_reply_call {
360         struct ctdb_req_header hdr;
361         uint32_t status;
362         uint32_t datalen;
363         uint8_t  data[1];
364 };
365
366 struct ctdb_reply_error {
367         struct ctdb_req_header hdr;
368         uint32_t status;
369         uint32_t msglen;
370         uint8_t  msg[1];
371 };
372
373 struct ctdb_req_dmaster {
374         struct ctdb_req_header hdr;
375         uint32_t db_id;
376         uint64_t rsn;
377         uint32_t dmaster;
378         uint32_t keylen;
379         uint32_t datalen;
380         uint8_t  data[1];
381 };
382
383 struct ctdb_reply_dmaster {
384         struct ctdb_req_header hdr;
385         uint32_t db_id;
386         uint64_t rsn;
387         uint32_t keylen;
388         uint32_t datalen;
389         uint8_t  data[1];
390 };
391
392 struct ctdb_req_message {
393         struct ctdb_req_header hdr;
394         uint64_t srvid;
395         uint32_t datalen;
396         uint8_t data[1];
397 };
398
399 struct ctdb_req_getdbpath {
400         struct ctdb_req_header hdr;
401         uint32_t db_id;
402 };
403
404 struct ctdb_reply_getdbpath {
405         struct ctdb_req_header hdr;
406         uint32_t datalen;
407         uint8_t data[1];
408 };
409
410 struct ctdb_req_control {
411         struct ctdb_req_header hdr;
412         uint32_t opcode;
413         uint32_t pad;
414         uint64_t srvid;
415         uint32_t client_id;
416 #define CTDB_CTRL_FLAG_NOREPLY   1
417 #define CTDB_CTRL_FLAG_OPCODE_SPECIFIC   0xFFFF0000
418         uint32_t flags;
419         uint32_t datalen;
420         uint8_t data[1];
421 };
422
423 struct ctdb_reply_control {
424         struct ctdb_req_header hdr;
425         int32_t  status;
426         uint32_t datalen;
427         uint32_t errorlen;
428         uint8_t data[1];
429 };
430
431 struct ctdb_req_keepalive {
432         struct ctdb_req_header hdr;
433 };
434
435
436 /* types of failures possible from TRANS2_COMMIT */
437 enum ctdb_trans2_commit_error {
438         CTDB_TRANS2_COMMIT_SUCCESS=0, /* all nodes committed successfully */
439         CTDB_TRANS2_COMMIT_TIMEOUT=1, /* at least one node timed out */
440         CTDB_TRANS2_COMMIT_ALLFAIL=2, /* all nodes failed the commit */
441         CTDB_TRANS2_COMMIT_SOMEFAIL=3 /* some nodes failed the commit, some allowed it */
442 };
443
444 /*
445   the extended header for records in the ltdb
446 */
447 struct ctdb_ltdb_header {
448         uint64_t rsn;
449         uint32_t dmaster;
450         uint32_t laccessor;
451         uint32_t lacount;
452 };
453 #endif