ldb:wscript: provide LDB_VERSION_{MAJOR,MINOR,RELEASE} in ldb_version.h
[Samba.git] / ctdb / protocol / protocol_control.c
blob3c5c7ce93cfd6b20912315930891a84a877d9d5f
1 /*
2 CTDB protocol marshalling
4 Copyright (C) Amitay Isaacs 2015
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.
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.
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/>.
20 #include "replace.h"
21 #include "system/network.h"
23 #include <talloc.h>
24 #include <tdb.h>
26 #include "protocol.h"
27 #include "protocol_api.h"
28 #include "protocol_private.h"
30 struct ctdb_req_control_wire {
31 struct ctdb_req_header hdr;
32 uint32_t opcode;
33 uint32_t pad;
34 uint64_t srvid;
35 uint32_t client_id;
36 uint32_t flags;
37 uint32_t datalen;
38 uint8_t data[1];
41 struct ctdb_reply_control_wire {
42 struct ctdb_req_header hdr;
43 int32_t status;
44 uint32_t datalen;
45 uint32_t errorlen;
46 uint8_t data[1];
49 static size_t ctdb_req_control_data_len(struct ctdb_req_control_data *cd)
51 size_t len = 0;
53 if (cd == NULL) {
54 return 0;
57 switch (cd->opcode) {
58 case CTDB_CONTROL_PROCESS_EXISTS:
59 len = ctdb_pid_len(cd->data.pid);
60 break;
62 case CTDB_CONTROL_STATISTICS:
63 break;
65 case CTDB_CONTROL_PING:
66 break;
68 case CTDB_CONTROL_GETDBPATH:
69 len = ctdb_uint32_len(cd->data.db_id);
70 break;
72 case CTDB_CONTROL_GETVNNMAP:
73 break;
75 case CTDB_CONTROL_SETVNNMAP:
76 len = ctdb_vnn_map_len(cd->data.vnnmap);
77 break;
79 case CTDB_CONTROL_GET_DEBUG:
80 break;
82 case CTDB_CONTROL_SET_DEBUG:
83 len = ctdb_uint32_len(cd->data.loglevel);
84 break;
86 case CTDB_CONTROL_GET_DBMAP:
87 break;
89 case CTDB_CONTROL_PULL_DB:
90 len = ctdb_pulldb_len(cd->data.pulldb);
91 break;
93 case CTDB_CONTROL_PUSH_DB:
94 len = ctdb_rec_buffer_len(cd->data.recbuf);
95 break;
97 case CTDB_CONTROL_GET_RECMODE:
98 break;
100 case CTDB_CONTROL_SET_RECMODE:
101 len = ctdb_uint32_len(cd->data.recmode);
102 break;
104 case CTDB_CONTROL_STATISTICS_RESET:
105 break;
107 case CTDB_CONTROL_DB_ATTACH:
108 len = ctdb_string_len(cd->data.db_name);
109 break;
111 case CTDB_CONTROL_SET_CALL:
112 break;
114 case CTDB_CONTROL_TRAVERSE_START:
115 len = ctdb_traverse_start_len(cd->data.traverse_start);
116 break;
118 case CTDB_CONTROL_TRAVERSE_ALL:
119 len = ctdb_traverse_all_len(cd->data.traverse_all);
120 break;
122 case CTDB_CONTROL_TRAVERSE_DATA:
123 len = ctdb_rec_data_len(cd->data.rec_data);
124 break;
126 case CTDB_CONTROL_REGISTER_SRVID:
127 break;
129 case CTDB_CONTROL_DEREGISTER_SRVID:
130 break;
132 case CTDB_CONTROL_GET_DBNAME:
133 len = ctdb_uint32_len(cd->data.db_id);
134 break;
136 case CTDB_CONTROL_ENABLE_SEQNUM:
137 len = ctdb_uint32_len(cd->data.db_id);
138 break;
140 case CTDB_CONTROL_UPDATE_SEQNUM:
141 len = ctdb_uint32_len(cd->data.db_id);
142 break;
144 case CTDB_CONTROL_DUMP_MEMORY:
145 break;
147 case CTDB_CONTROL_GET_PID:
148 break;
150 case CTDB_CONTROL_GET_RECMASTER:
151 break;
153 case CTDB_CONTROL_SET_RECMASTER:
154 len = ctdb_uint32_len(cd->data.recmaster);
155 break;
157 case CTDB_CONTROL_FREEZE:
158 break;
160 case CTDB_CONTROL_GET_PNN:
161 break;
163 case CTDB_CONTROL_SHUTDOWN:
164 break;
166 case CTDB_CONTROL_GET_MONMODE:
167 break;
169 case CTDB_CONTROL_TCP_CLIENT:
170 len = ctdb_connection_len(cd->data.conn);
171 break;
173 case CTDB_CONTROL_TCP_ADD:
174 len = ctdb_connection_len(cd->data.conn);
175 break;
177 case CTDB_CONTROL_TCP_REMOVE:
178 len = ctdb_connection_len(cd->data.conn);
179 break;
181 case CTDB_CONTROL_STARTUP:
182 break;
184 case CTDB_CONTROL_SET_TUNABLE:
185 len = ctdb_tunable_len(cd->data.tunable);
186 break;
188 case CTDB_CONTROL_GET_TUNABLE:
189 len = ctdb_stringn_len(cd->data.tun_var);
190 break;
192 case CTDB_CONTROL_LIST_TUNABLES:
193 break;
195 case CTDB_CONTROL_MODIFY_FLAGS:
196 len = ctdb_node_flag_change_len(cd->data.flag_change);
197 break;
199 case CTDB_CONTROL_GET_ALL_TUNABLES:
200 break;
202 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
203 len = ctdb_sock_addr_len(cd->data.addr);
204 break;
206 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
207 len = ctdb_tickle_list_len(cd->data.tickles);
208 break;
210 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
211 len = ctdb_string_len(cd->data.db_name);
212 break;
214 case CTDB_CONTROL_UPDATE_RECORD:
215 len = ctdb_rec_buffer_len(cd->data.recbuf);
216 break;
218 case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
219 len = ctdb_addr_info_len(cd->data.addr_info);
220 break;
222 case CTDB_CONTROL_WIPE_DATABASE:
223 len = ctdb_transdb_len(cd->data.transdb);
224 break;
226 case CTDB_CONTROL_UPTIME:
227 break;
229 case CTDB_CONTROL_START_RECOVERY:
230 break;
232 case CTDB_CONTROL_END_RECOVERY:
233 break;
235 case CTDB_CONTROL_RELOAD_NODES_FILE:
236 break;
238 case CTDB_CONTROL_TRY_DELETE_RECORDS:
239 len = ctdb_rec_buffer_len(cd->data.recbuf);
240 break;
242 case CTDB_CONTROL_ENABLE_MONITOR:
243 break;
245 case CTDB_CONTROL_DISABLE_MONITOR:
246 break;
248 case CTDB_CONTROL_ADD_PUBLIC_IP:
249 len = ctdb_addr_info_len(cd->data.addr_info);
250 break;
252 case CTDB_CONTROL_DEL_PUBLIC_IP:
253 len = ctdb_addr_info_len(cd->data.addr_info);
254 break;
256 case CTDB_CONTROL_GET_CAPABILITIES:
257 break;
259 case CTDB_CONTROL_RECD_PING:
260 break;
262 case CTDB_CONTROL_RELEASE_IP:
263 len = ctdb_public_ip_len(cd->data.pubip);
264 break;
266 case CTDB_CONTROL_TAKEOVER_IP:
267 len = ctdb_public_ip_len(cd->data.pubip);
268 break;
270 case CTDB_CONTROL_GET_PUBLIC_IPS:
271 break;
273 case CTDB_CONTROL_GET_NODEMAP:
274 break;
276 case CTDB_CONTROL_TRAVERSE_KILL:
277 len = ctdb_traverse_start_len(cd->data.traverse_start);
278 break;
280 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
281 len = ctdb_double_len(cd->data.reclock_latency);
282 break;
284 case CTDB_CONTROL_GET_RECLOCK_FILE:
285 break;
287 case CTDB_CONTROL_STOP_NODE:
288 break;
290 case CTDB_CONTROL_CONTINUE_NODE:
291 break;
293 case CTDB_CONTROL_SET_LMASTERROLE:
294 len = ctdb_uint32_len(cd->data.role);
295 break;
297 case CTDB_CONTROL_SET_RECMASTERROLE:
298 len = ctdb_uint32_len(cd->data.role);
299 break;
301 case CTDB_CONTROL_SET_BAN_STATE:
302 len = ctdb_ban_state_len(cd->data.ban_state);
303 break;
305 case CTDB_CONTROL_GET_BAN_STATE:
306 break;
308 case CTDB_CONTROL_REGISTER_NOTIFY:
309 len = ctdb_notify_data_len(cd->data.notify);
310 break;
312 case CTDB_CONTROL_DEREGISTER_NOTIFY:
313 len = ctdb_uint64_len(cd->data.srvid);
314 break;
316 case CTDB_CONTROL_TRANS3_COMMIT:
317 len = ctdb_rec_buffer_len(cd->data.recbuf);
318 break;
320 case CTDB_CONTROL_GET_DB_SEQNUM:
321 len = ctdb_uint64_len((uint64_t)cd->data.db_id);
322 break;
324 case CTDB_CONTROL_DB_SET_HEALTHY:
325 len = ctdb_uint32_len(cd->data.db_id);
326 break;
328 case CTDB_CONTROL_DB_GET_HEALTH:
329 len = ctdb_uint32_len(cd->data.db_id);
330 break;
332 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
333 len = ctdb_sock_addr_len(cd->data.addr);
334 break;
336 case CTDB_CONTROL_GET_IFACES:
337 break;
339 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
340 len = ctdb_iface_len(cd->data.iface);
341 break;
343 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
344 len = ctdb_connection_len(cd->data.conn);
345 break;
347 case CTDB_CONTROL_GET_STAT_HISTORY:
348 break;
350 case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
351 len = ctdb_key_data_len(cd->data.key);
352 break;
354 case CTDB_CONTROL_SET_DB_READONLY:
355 len = ctdb_uint32_len(cd->data.db_id);
356 break;
358 case CTDB_CONTROL_CHECK_SRVIDS:
359 len = ctdb_uint64_array_len(cd->data.u64_array);
360 break;
362 case CTDB_CONTROL_TRAVERSE_START_EXT:
363 len = ctdb_traverse_start_ext_len(cd->data.traverse_start_ext);
364 break;
366 case CTDB_CONTROL_GET_DB_STATISTICS:
367 len = ctdb_uint32_len(cd->data.db_id);
368 break;
370 case CTDB_CONTROL_SET_DB_STICKY:
371 len = ctdb_uint32_len(cd->data.db_id);
372 break;
374 case CTDB_CONTROL_RELOAD_PUBLIC_IPS:
375 break;
377 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
378 len = ctdb_traverse_all_ext_len(cd->data.traverse_all_ext);
379 break;
381 case CTDB_CONTROL_RECEIVE_RECORDS:
382 len = ctdb_rec_buffer_len(cd->data.recbuf);
383 break;
385 case CTDB_CONTROL_IPREALLOCATED:
386 break;
388 case CTDB_CONTROL_GET_RUNSTATE:
389 break;
391 case CTDB_CONTROL_DB_DETACH:
392 len = ctdb_uint32_len(cd->data.db_id);
393 break;
395 case CTDB_CONTROL_GET_NODES_FILE:
396 break;
398 case CTDB_CONTROL_DB_FREEZE:
399 len = ctdb_uint32_len(cd->data.db_id);
400 break;
402 case CTDB_CONTROL_DB_THAW:
403 len = ctdb_uint32_len(cd->data.db_id);
404 break;
406 case CTDB_CONTROL_DB_TRANSACTION_START:
407 len = ctdb_transdb_len(cd->data.transdb);
408 break;
410 case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
411 len = ctdb_transdb_len(cd->data.transdb);
412 break;
414 case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
415 len = ctdb_uint32_len(cd->data.db_id);
416 break;
418 case CTDB_CONTROL_DB_PULL:
419 len = ctdb_pulldb_ext_len(cd->data.pulldb_ext);
420 break;
422 case CTDB_CONTROL_DB_PUSH_START:
423 len = ctdb_pulldb_ext_len(cd->data.pulldb_ext);
424 break;
426 case CTDB_CONTROL_DB_PUSH_CONFIRM:
427 len = ctdb_uint32_len(cd->data.db_id);
428 break;
430 case CTDB_CONTROL_DB_OPEN_FLAGS:
431 len = ctdb_uint32_len(cd->data.db_id);
432 break;
434 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
435 len = ctdb_string_len(cd->data.db_name);
436 break;
439 return len;
442 static void ctdb_req_control_data_push(struct ctdb_req_control_data *cd,
443 uint8_t *buf)
445 switch (cd->opcode) {
446 case CTDB_CONTROL_PROCESS_EXISTS:
447 ctdb_pid_push(cd->data.pid, buf);
448 break;
450 case CTDB_CONTROL_GETDBPATH:
451 ctdb_uint32_push(cd->data.db_id, buf);
452 break;
454 case CTDB_CONTROL_SETVNNMAP:
455 ctdb_vnn_map_push(cd->data.vnnmap, buf);
456 break;
458 case CTDB_CONTROL_SET_DEBUG:
459 ctdb_uint32_push(cd->data.loglevel, buf);
460 break;
462 case CTDB_CONTROL_PULL_DB:
463 ctdb_pulldb_push(cd->data.pulldb, buf);
464 break;
466 case CTDB_CONTROL_PUSH_DB:
467 ctdb_rec_buffer_push(cd->data.recbuf, buf);
468 break;
470 case CTDB_CONTROL_SET_RECMODE:
471 ctdb_uint32_push(cd->data.recmode, buf);
472 break;
474 case CTDB_CONTROL_DB_ATTACH:
475 ctdb_string_push(cd->data.db_name, buf);
476 break;
478 case CTDB_CONTROL_SET_CALL:
479 break;
481 case CTDB_CONTROL_TRAVERSE_START:
482 ctdb_traverse_start_push(cd->data.traverse_start, buf);
483 break;
485 case CTDB_CONTROL_TRAVERSE_ALL:
486 ctdb_traverse_all_push(cd->data.traverse_all, buf);
487 break;
489 case CTDB_CONTROL_TRAVERSE_DATA:
490 ctdb_rec_data_push(cd->data.rec_data, buf);
491 break;
493 case CTDB_CONTROL_GET_DBNAME:
494 ctdb_uint32_push(cd->data.db_id, buf);
495 break;
497 case CTDB_CONTROL_ENABLE_SEQNUM:
498 ctdb_uint32_push(cd->data.db_id, buf);
499 break;
501 case CTDB_CONTROL_UPDATE_SEQNUM:
502 ctdb_uint32_push(cd->data.db_id, buf);
503 break;
505 case CTDB_CONTROL_SET_RECMASTER:
506 ctdb_uint32_push(cd->data.recmaster, buf);
507 break;
509 case CTDB_CONTROL_TCP_CLIENT:
510 ctdb_connection_push(cd->data.conn, buf);
511 break;
513 case CTDB_CONTROL_TCP_ADD:
514 ctdb_connection_push(cd->data.conn, buf);
515 break;
517 case CTDB_CONTROL_TCP_REMOVE:
518 ctdb_connection_push(cd->data.conn, buf);
519 break;
521 case CTDB_CONTROL_SET_TUNABLE:
522 ctdb_tunable_push(cd->data.tunable, buf);
523 break;
525 case CTDB_CONTROL_GET_TUNABLE:
526 ctdb_stringn_push(cd->data.tun_var, buf);
527 break;
529 case CTDB_CONTROL_MODIFY_FLAGS:
530 ctdb_node_flag_change_push(cd->data.flag_change, buf);
531 break;
533 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
534 ctdb_sock_addr_push(cd->data.addr, buf);
535 break;
537 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
538 ctdb_tickle_list_push(cd->data.tickles, buf);
539 break;
541 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
542 ctdb_string_push(cd->data.db_name, buf);
543 break;
545 case CTDB_CONTROL_UPDATE_RECORD:
546 ctdb_rec_buffer_push(cd->data.recbuf, buf);
547 break;
549 case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
550 ctdb_addr_info_push(cd->data.addr_info, buf);
551 break;
553 case CTDB_CONTROL_WIPE_DATABASE:
554 ctdb_transdb_push(cd->data.transdb, buf);
555 break;
557 case CTDB_CONTROL_TRY_DELETE_RECORDS:
558 ctdb_rec_buffer_push(cd->data.recbuf, buf);
559 break;
561 case CTDB_CONTROL_ADD_PUBLIC_IP:
562 ctdb_addr_info_push(cd->data.addr_info, buf);
563 break;
565 case CTDB_CONTROL_DEL_PUBLIC_IP:
566 ctdb_addr_info_push(cd->data.addr_info, buf);
567 break;
569 case CTDB_CONTROL_RELEASE_IP:
570 ctdb_public_ip_push(cd->data.pubip, buf);
571 break;
573 case CTDB_CONTROL_TAKEOVER_IP:
574 ctdb_public_ip_push(cd->data.pubip, buf);
575 break;
577 case CTDB_CONTROL_TRAVERSE_KILL:
578 ctdb_traverse_start_push(cd->data.traverse_start, buf);
579 break;
581 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
582 ctdb_double_push(cd->data.reclock_latency, buf);
583 break;
585 case CTDB_CONTROL_SET_LMASTERROLE:
586 ctdb_uint32_push(cd->data.role, buf);
587 break;
589 case CTDB_CONTROL_SET_RECMASTERROLE:
590 ctdb_uint32_push(cd->data.role, buf);
591 break;
593 case CTDB_CONTROL_SET_BAN_STATE:
594 ctdb_ban_state_push(cd->data.ban_state, buf);
595 break;
597 case CTDB_CONTROL_REGISTER_NOTIFY:
598 ctdb_notify_data_push(cd->data.notify, buf);
599 break;
601 case CTDB_CONTROL_DEREGISTER_NOTIFY:
602 ctdb_uint64_push(cd->data.srvid, buf);
603 break;
605 case CTDB_CONTROL_TRANS3_COMMIT:
606 ctdb_rec_buffer_push(cd->data.recbuf, buf);
607 break;
609 case CTDB_CONTROL_GET_DB_SEQNUM:
610 ctdb_uint32_push(cd->data.db_id, buf);
611 break;
613 case CTDB_CONTROL_DB_SET_HEALTHY:
614 ctdb_uint32_push(cd->data.db_id, buf);
615 break;
617 case CTDB_CONTROL_DB_GET_HEALTH:
618 ctdb_uint32_push(cd->data.db_id, buf);
619 break;
621 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
622 ctdb_sock_addr_push(cd->data.addr, buf);
623 break;
625 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
626 ctdb_iface_push(cd->data.iface, buf);
627 break;
629 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
630 ctdb_connection_push(cd->data.conn, buf);
631 break;
633 case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
634 ctdb_key_data_push(cd->data.key, buf);
635 break;
637 case CTDB_CONTROL_SET_DB_READONLY:
638 ctdb_uint32_push(cd->data.db_id, buf);
639 break;
641 case CTDB_CONTROL_CHECK_SRVIDS:
642 ctdb_uint64_array_push(cd->data.u64_array, buf);
643 break;
645 case CTDB_CONTROL_TRAVERSE_START_EXT:
646 ctdb_traverse_start_ext_push(cd->data.traverse_start_ext, buf);
647 break;
649 case CTDB_CONTROL_GET_DB_STATISTICS:
650 ctdb_uint32_push(cd->data.db_id, buf);
651 break;
653 case CTDB_CONTROL_SET_DB_STICKY:
654 ctdb_uint32_push(cd->data.db_id, buf);
655 break;
657 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
658 ctdb_traverse_all_ext_push(cd->data.traverse_all_ext, buf);
659 break;
661 case CTDB_CONTROL_RECEIVE_RECORDS:
662 ctdb_rec_buffer_push(cd->data.recbuf, buf);
663 break;
665 case CTDB_CONTROL_DB_DETACH:
666 ctdb_uint32_push(cd->data.db_id, buf);
667 break;
669 case CTDB_CONTROL_DB_FREEZE:
670 ctdb_uint32_push(cd->data.db_id, buf);
671 break;
673 case CTDB_CONTROL_DB_THAW:
674 ctdb_uint32_push(cd->data.db_id, buf);
675 break;
677 case CTDB_CONTROL_DB_TRANSACTION_START:
678 ctdb_transdb_push(cd->data.transdb, buf);
679 break;
681 case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
682 ctdb_transdb_push(cd->data.transdb, buf);
683 break;
685 case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
686 ctdb_uint32_push(cd->data.db_id, buf);
687 break;
689 case CTDB_CONTROL_DB_PULL:
690 ctdb_pulldb_ext_push(cd->data.pulldb_ext, buf);
691 break;
693 case CTDB_CONTROL_DB_PUSH_START:
694 ctdb_pulldb_ext_push(cd->data.pulldb_ext, buf);
695 break;
697 case CTDB_CONTROL_DB_PUSH_CONFIRM:
698 ctdb_uint32_push(cd->data.db_id, buf);
699 break;
701 case CTDB_CONTROL_DB_OPEN_FLAGS:
702 ctdb_uint32_push(cd->data.db_id, buf);
703 break;
705 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
706 ctdb_string_push(cd->data.db_name, buf);
707 break;
711 static int ctdb_req_control_data_pull(uint8_t *buf, size_t buflen,
712 uint32_t opcode,
713 TALLOC_CTX *mem_ctx,
714 struct ctdb_req_control_data *cd)
716 int ret = 0;
718 cd->opcode = opcode;
720 switch (opcode) {
721 case CTDB_CONTROL_PROCESS_EXISTS:
722 ret = ctdb_pid_pull(buf, buflen, mem_ctx,
723 &cd->data.pid);
724 break;
726 case CTDB_CONTROL_GETDBPATH:
727 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
728 &cd->data.db_id);
729 break;
731 case CTDB_CONTROL_SETVNNMAP:
732 ret = ctdb_vnn_map_pull(buf, buflen, mem_ctx,
733 &cd->data.vnnmap);
734 break;
736 case CTDB_CONTROL_SET_DEBUG:
737 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
738 &cd->data.loglevel);
739 break;
741 case CTDB_CONTROL_PULL_DB:
742 ret = ctdb_pulldb_pull(buf, buflen, mem_ctx,
743 &cd->data.pulldb);
744 break;
746 case CTDB_CONTROL_PUSH_DB:
747 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
748 &cd->data.recbuf);
749 break;
751 case CTDB_CONTROL_SET_RECMODE:
752 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
753 &cd->data.recmode);
754 break;
756 case CTDB_CONTROL_DB_ATTACH:
757 ret = ctdb_string_pull(buf, buflen, mem_ctx,
758 &cd->data.db_name);
759 break;
761 case CTDB_CONTROL_SET_CALL:
762 break;
764 case CTDB_CONTROL_TRAVERSE_START:
765 ret = ctdb_traverse_start_pull(buf, buflen, mem_ctx,
766 &cd->data.traverse_start);
767 break;
769 case CTDB_CONTROL_TRAVERSE_ALL:
770 ret = ctdb_traverse_all_pull(buf, buflen, mem_ctx,
771 &cd->data.traverse_all);
772 break;
774 case CTDB_CONTROL_TRAVERSE_DATA:
775 ret = ctdb_rec_data_pull(buf, buflen, mem_ctx,
776 &cd->data.rec_data);
777 break;
779 case CTDB_CONTROL_GET_DBNAME:
780 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
781 &cd->data.db_id);
782 break;
784 case CTDB_CONTROL_ENABLE_SEQNUM:
785 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
786 &cd->data.db_id);
787 break;
789 case CTDB_CONTROL_UPDATE_SEQNUM:
790 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
791 &cd->data.db_id);
792 break;
794 case CTDB_CONTROL_SET_RECMASTER:
795 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
796 &cd->data.recmaster);
797 break;
799 case CTDB_CONTROL_TCP_CLIENT:
800 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
801 &cd->data.conn);
802 break;
804 case CTDB_CONTROL_TCP_ADD:
805 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
806 &cd->data.conn);
807 break;
809 case CTDB_CONTROL_TCP_REMOVE:
810 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
811 &cd->data.conn);
812 break;
814 case CTDB_CONTROL_SET_TUNABLE:
815 ret = ctdb_tunable_pull(buf, buflen, mem_ctx,
816 &cd->data.tunable);
817 break;
819 case CTDB_CONTROL_GET_TUNABLE:
820 ret = ctdb_stringn_pull(buf, buflen, mem_ctx,
821 &cd->data.tun_var);
822 break;
824 case CTDB_CONTROL_MODIFY_FLAGS:
825 ret = ctdb_node_flag_change_pull(buf, buflen, mem_ctx,
826 &cd->data.flag_change);
827 break;
829 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
830 ret = ctdb_sock_addr_pull(buf, buflen, mem_ctx,
831 &cd->data.addr);
832 break;
834 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
835 ret = ctdb_tickle_list_pull(buf, buflen, mem_ctx,
836 &cd->data.tickles);
837 break;
839 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
840 ret = ctdb_string_pull(buf, buflen, mem_ctx,
841 &cd->data.db_name);
842 break;
844 case CTDB_CONTROL_UPDATE_RECORD:
845 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
846 &cd->data.recbuf);
847 break;
849 case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
850 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
851 &cd->data.addr_info);
852 break;
854 case CTDB_CONTROL_WIPE_DATABASE:
855 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
856 &cd->data.transdb);
857 break;
859 case CTDB_CONTROL_TRY_DELETE_RECORDS:
860 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
861 &cd->data.recbuf);
862 break;
864 case CTDB_CONTROL_ADD_PUBLIC_IP:
865 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
866 &cd->data.addr_info);
867 break;
869 case CTDB_CONTROL_DEL_PUBLIC_IP:
870 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
871 &cd->data.addr_info);
872 break;
874 case CTDB_CONTROL_RELEASE_IP:
875 ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
876 &cd->data.pubip);
877 break;
879 case CTDB_CONTROL_TAKEOVER_IP:
880 ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
881 &cd->data.pubip);
882 break;
884 case CTDB_CONTROL_TRAVERSE_KILL:
885 ret = ctdb_traverse_start_pull(buf, buflen, mem_ctx,
886 &cd->data.traverse_start);
887 break;
889 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
890 ret = ctdb_double_pull(buf, buflen, mem_ctx,
891 &cd->data.reclock_latency);
892 break;
894 case CTDB_CONTROL_SET_LMASTERROLE:
895 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
896 &cd->data.role);
897 break;
899 case CTDB_CONTROL_SET_RECMASTERROLE:
900 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
901 &cd->data.role);
902 break;
904 case CTDB_CONTROL_SET_BAN_STATE:
905 ret = ctdb_ban_state_pull(buf, buflen, mem_ctx,
906 &cd->data.ban_state);
907 break;
909 case CTDB_CONTROL_REGISTER_NOTIFY:
910 ret = ctdb_notify_data_pull(buf, buflen, mem_ctx,
911 &cd->data.notify);
912 break;
914 case CTDB_CONTROL_DEREGISTER_NOTIFY:
915 ctdb_uint64_pull(buf, buflen, mem_ctx,
916 &cd->data.srvid);
917 break;
919 case CTDB_CONTROL_TRANS3_COMMIT:
920 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
921 &cd->data.recbuf);
922 break;
924 case CTDB_CONTROL_GET_DB_SEQNUM:
925 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
926 &cd->data.db_id);
927 break;
929 case CTDB_CONTROL_DB_SET_HEALTHY:
930 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
931 &cd->data.db_id);
932 break;
934 case CTDB_CONTROL_DB_GET_HEALTH:
935 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
936 &cd->data.db_id);
937 break;
939 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
940 ret = ctdb_sock_addr_pull(buf, buflen, mem_ctx,
941 &cd->data.addr);
942 break;
944 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
945 ret = ctdb_iface_pull(buf, buflen, mem_ctx,
946 &cd->data.iface);
947 break;
949 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
950 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
951 &cd->data.conn);
952 break;
954 case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
955 ret = ctdb_key_data_pull(buf, buflen, mem_ctx,
956 &cd->data.key);
957 break;
959 case CTDB_CONTROL_SET_DB_READONLY:
960 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
961 &cd->data.db_id);
962 break;
964 case CTDB_CONTROL_CHECK_SRVIDS:
965 ret = ctdb_uint64_array_pull(buf, buflen, mem_ctx,
966 &cd->data.u64_array);
967 break;
969 case CTDB_CONTROL_TRAVERSE_START_EXT:
970 ret = ctdb_traverse_start_ext_pull(buf, buflen, mem_ctx,
971 &cd->data.traverse_start_ext);
972 break;
974 case CTDB_CONTROL_GET_DB_STATISTICS:
975 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
976 &cd->data.db_id);
977 break;
979 case CTDB_CONTROL_SET_DB_STICKY:
980 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
981 &cd->data.db_id);
982 break;
984 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
985 ret = ctdb_traverse_all_ext_pull(buf, buflen, mem_ctx,
986 &cd->data.traverse_all_ext);
987 break;
989 case CTDB_CONTROL_RECEIVE_RECORDS:
990 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
991 &cd->data.recbuf);
992 break;
994 case CTDB_CONTROL_DB_DETACH:
995 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
996 &cd->data.db_id);
997 break;
999 case CTDB_CONTROL_DB_FREEZE:
1000 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
1001 &cd->data.db_id);
1002 break;
1004 case CTDB_CONTROL_DB_THAW:
1005 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
1006 &cd->data.db_id);
1007 break;
1009 case CTDB_CONTROL_DB_TRANSACTION_START:
1010 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
1011 &cd->data.transdb);
1012 break;
1014 case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
1015 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
1016 &cd->data.transdb);
1017 break;
1019 case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
1020 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
1021 &cd->data.db_id);
1022 break;
1024 case CTDB_CONTROL_DB_PULL:
1025 ret = ctdb_pulldb_ext_pull(buf, buflen, mem_ctx,
1026 &cd->data.pulldb_ext);
1027 break;
1029 case CTDB_CONTROL_DB_PUSH_START:
1030 ret = ctdb_pulldb_ext_pull(buf, buflen, mem_ctx,
1031 &cd->data.pulldb_ext);
1032 break;
1034 case CTDB_CONTROL_DB_PUSH_CONFIRM:
1035 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
1036 &cd->data.db_id);
1037 break;
1039 case CTDB_CONTROL_DB_OPEN_FLAGS:
1040 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
1041 &cd->data.db_id);
1042 break;
1044 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1045 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1046 &cd->data.db_name);
1047 break;
1050 return ret;
1053 static size_t ctdb_reply_control_data_len(struct ctdb_reply_control_data *cd)
1055 size_t len = 0;
1057 if (cd == NULL) {
1058 return 0;
1061 switch (cd->opcode) {
1062 case CTDB_CONTROL_PROCESS_EXISTS:
1063 break;
1065 case CTDB_CONTROL_STATISTICS:
1066 len = ctdb_statistics_len(cd->data.stats);
1067 break;
1069 case CTDB_CONTROL_PING:
1070 break;
1072 case CTDB_CONTROL_GETDBPATH:
1073 len = ctdb_string_len(cd->data.db_path);
1074 break;
1076 case CTDB_CONTROL_GETVNNMAP:
1077 len = ctdb_vnn_map_len(cd->data.vnnmap);
1078 break;
1080 case CTDB_CONTROL_SETVNNMAP:
1081 break;
1083 case CTDB_CONTROL_GET_DEBUG:
1084 len = ctdb_uint32_len(cd->data.loglevel);
1085 break;
1087 case CTDB_CONTROL_SET_DEBUG:
1088 break;
1090 case CTDB_CONTROL_GET_DBMAP:
1091 len = ctdb_dbid_map_len(cd->data.dbmap);
1092 break;
1094 case CTDB_CONTROL_PULL_DB:
1095 len = ctdb_rec_buffer_len(cd->data.recbuf);
1096 break;
1098 case CTDB_CONTROL_PUSH_DB:
1099 break;
1101 case CTDB_CONTROL_GET_RECMODE:
1102 break;
1104 case CTDB_CONTROL_SET_RECMODE:
1105 break;
1107 case CTDB_CONTROL_STATISTICS_RESET:
1108 break;
1110 case CTDB_CONTROL_DB_ATTACH:
1111 len = ctdb_uint32_len(cd->data.db_id);
1112 break;
1114 case CTDB_CONTROL_SET_CALL:
1115 break;
1117 case CTDB_CONTROL_TRAVERSE_START:
1118 break;
1120 case CTDB_CONTROL_TRAVERSE_ALL:
1121 break;
1123 case CTDB_CONTROL_TRAVERSE_DATA:
1124 break;
1126 case CTDB_CONTROL_REGISTER_SRVID:
1127 break;
1129 case CTDB_CONTROL_DEREGISTER_SRVID:
1130 break;
1132 case CTDB_CONTROL_GET_DBNAME:
1133 len = ctdb_string_len(cd->data.db_name);
1134 break;
1136 case CTDB_CONTROL_ENABLE_SEQNUM:
1137 break;
1139 case CTDB_CONTROL_UPDATE_SEQNUM:
1140 break;
1142 case CTDB_CONTROL_DUMP_MEMORY:
1143 len = ctdb_string_len(cd->data.mem_str);
1144 break;
1146 case CTDB_CONTROL_GET_PID:
1147 break;
1149 case CTDB_CONTROL_GET_RECMASTER:
1150 break;
1152 case CTDB_CONTROL_SET_RECMASTER:
1153 break;
1155 case CTDB_CONTROL_FREEZE:
1156 break;
1158 case CTDB_CONTROL_GET_PNN:
1159 break;
1161 case CTDB_CONTROL_SHUTDOWN:
1162 break;
1164 case CTDB_CONTROL_GET_MONMODE:
1165 break;
1167 case CTDB_CONTROL_TCP_CLIENT:
1168 break;
1170 case CTDB_CONTROL_TCP_ADD:
1171 break;
1173 case CTDB_CONTROL_TCP_REMOVE:
1174 break;
1176 case CTDB_CONTROL_STARTUP:
1177 break;
1179 case CTDB_CONTROL_SET_TUNABLE:
1180 break;
1182 case CTDB_CONTROL_GET_TUNABLE:
1183 len = ctdb_uint32_len(cd->data.tun_value);
1184 break;
1186 case CTDB_CONTROL_LIST_TUNABLES:
1187 len = ctdb_var_list_len(cd->data.tun_var_list);
1188 break;
1190 case CTDB_CONTROL_MODIFY_FLAGS:
1191 break;
1193 case CTDB_CONTROL_GET_ALL_TUNABLES:
1194 len = ctdb_tunable_list_len(cd->data.tun_list);
1195 break;
1197 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1198 len = ctdb_tickle_list_len(cd->data.tickles);
1199 break;
1201 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
1202 break;
1204 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1205 len = ctdb_uint32_len(cd->data.db_id);
1206 break;
1208 case CTDB_CONTROL_UPDATE_RECORD:
1209 break;
1211 case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
1212 break;
1214 case CTDB_CONTROL_WIPE_DATABASE:
1215 break;
1217 case CTDB_CONTROL_UPTIME:
1218 len = ctdb_uptime_len(cd->data.uptime);
1219 break;
1221 case CTDB_CONTROL_START_RECOVERY:
1222 break;
1224 case CTDB_CONTROL_END_RECOVERY:
1225 break;
1227 case CTDB_CONTROL_RELOAD_NODES_FILE:
1228 break;
1230 case CTDB_CONTROL_TRY_DELETE_RECORDS:
1231 len = ctdb_rec_buffer_len(cd->data.recbuf);
1232 break;
1234 case CTDB_CONTROL_ENABLE_MONITOR:
1235 break;
1237 case CTDB_CONTROL_DISABLE_MONITOR:
1238 break;
1240 case CTDB_CONTROL_ADD_PUBLIC_IP:
1241 break;
1243 case CTDB_CONTROL_DEL_PUBLIC_IP:
1244 break;
1246 case CTDB_CONTROL_GET_CAPABILITIES:
1247 len = ctdb_uint32_len(cd->data.caps);
1248 break;
1250 case CTDB_CONTROL_RECD_PING:
1251 break;
1253 case CTDB_CONTROL_RELEASE_IP:
1254 break;
1256 case CTDB_CONTROL_TAKEOVER_IP:
1257 break;
1259 case CTDB_CONTROL_GET_PUBLIC_IPS:
1260 len = ctdb_public_ip_list_len(cd->data.pubip_list);
1261 break;
1263 case CTDB_CONTROL_GET_NODEMAP:
1264 len = ctdb_node_map_len(cd->data.nodemap);
1265 break;
1267 case CTDB_CONTROL_TRAVERSE_KILL:
1268 break;
1270 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
1271 break;
1273 case CTDB_CONTROL_GET_RECLOCK_FILE:
1274 len = ctdb_string_len(cd->data.reclock_file);
1275 break;
1277 case CTDB_CONTROL_STOP_NODE:
1278 break;
1280 case CTDB_CONTROL_CONTINUE_NODE:
1281 break;
1283 case CTDB_CONTROL_SET_LMASTERROLE:
1284 break;
1286 case CTDB_CONTROL_SET_RECMASTERROLE:
1287 break;
1289 case CTDB_CONTROL_SET_BAN_STATE:
1290 break;
1292 case CTDB_CONTROL_GET_BAN_STATE:
1293 len = ctdb_ban_state_len(cd->data.ban_state);
1294 break;
1296 case CTDB_CONTROL_SET_DB_PRIORITY:
1297 break;
1299 case CTDB_CONTROL_GET_DB_PRIORITY:
1300 break;
1302 case CTDB_CONTROL_REGISTER_NOTIFY:
1303 break;
1305 case CTDB_CONTROL_DEREGISTER_NOTIFY:
1306 break;
1308 case CTDB_CONTROL_TRANS3_COMMIT:
1309 break;
1311 case CTDB_CONTROL_GET_DB_SEQNUM:
1312 len = ctdb_uint64_len(cd->data.seqnum);
1313 break;
1315 case CTDB_CONTROL_DB_SET_HEALTHY:
1316 break;
1318 case CTDB_CONTROL_DB_GET_HEALTH:
1319 len = ctdb_string_len(cd->data.reason);
1320 break;
1322 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1323 len = ctdb_public_ip_info_len(cd->data.ipinfo);
1324 break;
1326 case CTDB_CONTROL_GET_IFACES:
1327 len = ctdb_iface_list_len(cd->data.iface_list);
1328 break;
1330 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
1331 break;
1333 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
1334 break;
1336 case CTDB_CONTROL_GET_STAT_HISTORY:
1337 len = ctdb_statistics_list_len(cd->data.stats_list);
1338 break;
1340 case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
1341 break;
1343 case CTDB_CONTROL_SET_DB_READONLY:
1344 break;
1346 case CTDB_CONTROL_CHECK_SRVIDS:
1347 len = ctdb_uint8_array_len(cd->data.u8_array);
1348 break;
1350 case CTDB_CONTROL_TRAVERSE_START_EXT:
1351 break;
1353 case CTDB_CONTROL_GET_DB_STATISTICS:
1354 len = ctdb_db_statistics_len(cd->data.dbstats);
1355 break;
1357 case CTDB_CONTROL_SET_DB_STICKY:
1358 break;
1360 case CTDB_CONTROL_RELOAD_PUBLIC_IPS:
1361 break;
1363 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
1364 break;
1366 case CTDB_CONTROL_RECEIVE_RECORDS:
1367 len = ctdb_rec_buffer_len(cd->data.recbuf);
1368 break;
1370 case CTDB_CONTROL_IPREALLOCATED:
1371 break;
1373 case CTDB_CONTROL_GET_RUNSTATE:
1374 len = ctdb_uint32_len(cd->data.runstate);
1375 break;
1377 case CTDB_CONTROL_DB_DETACH:
1378 break;
1380 case CTDB_CONTROL_GET_NODES_FILE:
1381 len = ctdb_node_map_len(cd->data.nodemap);
1382 break;
1384 case CTDB_CONTROL_DB_FREEZE:
1385 break;
1387 case CTDB_CONTROL_DB_THAW:
1388 break;
1390 case CTDB_CONTROL_DB_TRANSACTION_START:
1391 break;
1393 case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
1394 break;
1396 case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
1397 break;
1399 case CTDB_CONTROL_DB_PULL:
1400 len = ctdb_uint32_len(cd->data.num_records);
1401 break;
1403 case CTDB_CONTROL_DB_PUSH_START:
1404 break;
1406 case CTDB_CONTROL_DB_PUSH_CONFIRM:
1407 len = ctdb_uint32_len(cd->data.num_records);
1408 break;
1410 case CTDB_CONTROL_DB_OPEN_FLAGS:
1411 len = ctdb_int32_len(cd->data.tdb_flags);
1412 break;
1414 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1415 len = ctdb_uint32_len(cd->data.db_id);
1416 break;
1419 return len;
1422 static void ctdb_reply_control_data_push(struct ctdb_reply_control_data *cd,
1423 uint8_t *buf)
1425 switch (cd->opcode) {
1426 case CTDB_CONTROL_STATISTICS:
1427 ctdb_statistics_push(cd->data.stats, buf);
1428 break;
1430 case CTDB_CONTROL_GETDBPATH:
1431 ctdb_string_push(cd->data.db_path, buf);
1432 break;
1434 case CTDB_CONTROL_GETVNNMAP:
1435 ctdb_vnn_map_push(cd->data.vnnmap, buf);
1436 break;
1438 case CTDB_CONTROL_GET_DEBUG:
1439 ctdb_uint32_push(cd->data.loglevel, buf);
1440 break;
1442 case CTDB_CONTROL_GET_DBMAP:
1443 ctdb_dbid_map_push(cd->data.dbmap, buf);
1444 break;
1446 case CTDB_CONTROL_PULL_DB:
1447 ctdb_rec_buffer_push(cd->data.recbuf, buf);
1448 break;
1450 case CTDB_CONTROL_PUSH_DB:
1451 break;
1453 case CTDB_CONTROL_DB_ATTACH:
1454 ctdb_uint32_push(cd->data.db_id, buf);
1455 break;
1457 case CTDB_CONTROL_GET_DBNAME:
1458 ctdb_string_push(cd->data.db_name, buf);
1459 break;
1461 case CTDB_CONTROL_DUMP_MEMORY:
1462 ctdb_string_push(cd->data.mem_str, buf);
1463 break;
1465 case CTDB_CONTROL_GET_PID:
1466 break;
1468 case CTDB_CONTROL_GET_RECMASTER:
1469 break;
1471 case CTDB_CONTROL_GET_TUNABLE:
1472 ctdb_uint32_push(cd->data.tun_value, buf);
1473 break;
1475 case CTDB_CONTROL_LIST_TUNABLES:
1476 ctdb_var_list_push(cd->data.tun_var_list, buf);
1477 break;
1479 case CTDB_CONTROL_GET_ALL_TUNABLES:
1480 ctdb_tunable_list_push(cd->data.tun_list, buf);
1481 break;
1483 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1484 ctdb_tickle_list_push(cd->data.tickles, buf);
1485 break;
1487 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1488 ctdb_uint32_push(cd->data.db_id, buf);
1489 break;
1491 case CTDB_CONTROL_UPTIME:
1492 ctdb_uptime_push(cd->data.uptime, buf);
1493 break;
1495 case CTDB_CONTROL_TRY_DELETE_RECORDS:
1496 ctdb_rec_buffer_push(cd->data.recbuf, buf);
1497 break;
1499 case CTDB_CONTROL_GET_CAPABILITIES:
1500 ctdb_uint32_push(cd->data.caps, buf);
1501 break;
1503 case CTDB_CONTROL_GET_PUBLIC_IPS:
1504 ctdb_public_ip_list_push(cd->data.pubip_list, buf);
1505 break;
1507 case CTDB_CONTROL_GET_NODEMAP:
1508 ctdb_node_map_push(cd->data.nodemap, buf);
1509 break;
1511 case CTDB_CONTROL_GET_RECLOCK_FILE:
1512 ctdb_string_push(cd->data.reclock_file, buf);
1513 break;
1515 case CTDB_CONTROL_GET_BAN_STATE:
1516 ctdb_ban_state_push(cd->data.ban_state, buf);
1517 break;
1519 case CTDB_CONTROL_GET_DB_PRIORITY:
1520 break;
1522 case CTDB_CONTROL_GET_DB_SEQNUM:
1523 ctdb_uint64_push(cd->data.seqnum, buf);
1524 break;
1526 case CTDB_CONTROL_DB_GET_HEALTH:
1527 ctdb_string_push(cd->data.reason, buf);
1528 break;
1530 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1531 ctdb_public_ip_info_push(cd->data.ipinfo, buf);
1532 break;
1534 case CTDB_CONTROL_GET_IFACES:
1535 ctdb_iface_list_push(cd->data.iface_list, buf);
1536 break;
1538 case CTDB_CONTROL_GET_STAT_HISTORY:
1539 ctdb_statistics_list_push(cd->data.stats_list, buf);
1540 break;
1542 case CTDB_CONTROL_CHECK_SRVIDS:
1543 ctdb_uint8_array_push(cd->data.u8_array, buf);
1544 break;
1546 case CTDB_CONTROL_GET_DB_STATISTICS:
1547 ctdb_db_statistics_push(cd->data.dbstats, buf);
1548 break;
1550 case CTDB_CONTROL_RECEIVE_RECORDS:
1551 ctdb_rec_buffer_push(cd->data.recbuf, buf);
1552 break;
1554 case CTDB_CONTROL_GET_RUNSTATE:
1555 ctdb_uint32_push(cd->data.runstate, buf);
1556 break;
1558 case CTDB_CONTROL_GET_NODES_FILE:
1559 ctdb_node_map_push(cd->data.nodemap, buf);
1560 break;
1562 case CTDB_CONTROL_DB_PULL:
1563 ctdb_uint32_push(cd->data.num_records, buf);
1564 break;
1566 case CTDB_CONTROL_DB_PUSH_CONFIRM:
1567 ctdb_uint32_push(cd->data.num_records, buf);
1568 break;
1570 case CTDB_CONTROL_DB_OPEN_FLAGS:
1571 ctdb_int32_push(cd->data.tdb_flags, buf);
1572 break;
1574 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1575 ctdb_uint32_push(cd->data.db_id, buf);
1576 break;
1580 static int ctdb_reply_control_data_pull(uint8_t *buf, size_t buflen,
1581 uint32_t opcode, TALLOC_CTX *mem_ctx,
1582 struct ctdb_reply_control_data *cd)
1584 int ret = 0;
1585 cd->opcode = opcode;
1587 switch (opcode) {
1588 case CTDB_CONTROL_STATISTICS:
1589 ret = ctdb_statistics_pull(buf, buflen, mem_ctx,
1590 &cd->data.stats);
1591 break;
1593 case CTDB_CONTROL_GETDBPATH:
1594 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1595 &cd->data.db_path);
1596 break;
1598 case CTDB_CONTROL_GETVNNMAP:
1599 ret = ctdb_vnn_map_pull(buf, buflen, mem_ctx,
1600 &cd->data.vnnmap);
1601 break;
1603 case CTDB_CONTROL_GET_DEBUG:
1604 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
1605 &cd->data.loglevel);
1606 break;
1608 case CTDB_CONTROL_GET_DBMAP:
1609 ret = ctdb_dbid_map_pull(buf, buflen, mem_ctx,
1610 &cd->data.dbmap);
1611 break;
1613 case CTDB_CONTROL_PULL_DB:
1614 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
1615 &cd->data.recbuf);
1616 break;
1618 case CTDB_CONTROL_PUSH_DB:
1619 break;
1621 case CTDB_CONTROL_DB_ATTACH:
1622 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
1623 &cd->data.db_id);
1624 break;
1626 case CTDB_CONTROL_GET_DBNAME:
1627 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1628 &cd->data.db_name);
1629 break;
1631 case CTDB_CONTROL_DUMP_MEMORY:
1632 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1633 &cd->data.mem_str);
1634 break;
1636 case CTDB_CONTROL_GET_PID:
1637 break;
1639 case CTDB_CONTROL_GET_RECMASTER:
1640 break;
1642 case CTDB_CONTROL_GET_TUNABLE:
1643 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
1644 &cd->data.tun_value);
1645 break;
1647 case CTDB_CONTROL_LIST_TUNABLES:
1648 ret = ctdb_var_list_pull(buf, buflen, mem_ctx,
1649 &cd->data.tun_var_list);
1650 break;
1652 case CTDB_CONTROL_GET_ALL_TUNABLES:
1653 ret = ctdb_tunable_list_pull(buf, buflen, mem_ctx,
1654 &cd->data.tun_list);
1655 break;
1657 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1658 ret = ctdb_tickle_list_pull(buf, buflen, mem_ctx,
1659 &cd->data.tickles);
1660 break;
1662 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1663 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
1664 &cd->data.db_id);
1665 break;
1667 case CTDB_CONTROL_UPTIME:
1668 ret = ctdb_uptime_pull(buf, buflen, mem_ctx,
1669 &cd->data.uptime);
1670 break;
1672 case CTDB_CONTROL_TRY_DELETE_RECORDS:
1673 ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
1674 &cd->data.recbuf);
1675 break;
1677 case CTDB_CONTROL_GET_CAPABILITIES:
1678 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
1679 &cd->data.caps);
1680 break;
1682 case CTDB_CONTROL_GET_PUBLIC_IPS:
1683 ret = ctdb_public_ip_list_pull(buf, buflen, mem_ctx,
1684 &cd->data.pubip_list);
1685 break;
1687 case CTDB_CONTROL_GET_NODEMAP:
1688 ret = ctdb_node_map_pull(buf, buflen, mem_ctx,
1689 &cd->data.nodemap);
1690 break;
1692 case CTDB_CONTROL_GET_RECLOCK_FILE:
1693 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1694 &cd->data.reclock_file);
1695 break;
1697 case CTDB_CONTROL_GET_BAN_STATE:
1698 ret = ctdb_ban_state_pull(buf, buflen, mem_ctx,
1699 &cd->data.ban_state);
1700 break;
1702 case CTDB_CONTROL_GET_DB_PRIORITY:
1703 break;
1705 case CTDB_CONTROL_GET_DB_SEQNUM:
1706 ret = ctdb_uint64_pull(buf, buflen, mem_ctx,
1707 &cd->data.seqnum);
1708 break;
1710 case CTDB_CONTROL_DB_GET_HEALTH:
1711 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1712 &cd->data.reason);
1713 break;
1715 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1716 ret = ctdb_public_ip_info_pull(buf, buflen, mem_ctx,
1717 &cd->data.ipinfo);
1718 break;
1720 case CTDB_CONTROL_GET_IFACES:
1721 ret = ctdb_iface_list_pull(buf, buflen, mem_ctx,
1722 &cd->data.iface_list);
1723 break;
1725 case CTDB_CONTROL_GET_STAT_HISTORY:
1726 ret = ctdb_statistics_list_pull(buf, buflen, mem_ctx,
1727 &cd->data.stats_list);
1728 break;
1730 case CTDB_CONTROL_CHECK_SRVIDS:
1731 ret = ctdb_uint8_array_pull(buf, buflen, mem_ctx,
1732 &cd->data.u8_array);
1733 break;
1735 case CTDB_CONTROL_GET_DB_STATISTICS:
1736 ret = ctdb_db_statistics_pull(buf, buflen, mem_ctx,
1737 &cd->data.dbstats);
1738 break;
1740 case CTDB_CONTROL_RECEIVE_RECORDS:
1741 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
1742 &cd->data.recbuf);
1743 break;
1745 case CTDB_CONTROL_GET_RUNSTATE:
1746 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
1747 &cd->data.runstate);
1748 break;
1750 case CTDB_CONTROL_GET_NODES_FILE:
1751 ret = ctdb_node_map_pull(buf, buflen, mem_ctx,
1752 &cd->data.nodemap);
1753 break;
1755 case CTDB_CONTROL_DB_PULL:
1756 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
1757 &cd->data.num_records);
1758 break;
1760 case CTDB_CONTROL_DB_PUSH_CONFIRM:
1761 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
1762 &cd->data.num_records);
1763 break;
1765 case CTDB_CONTROL_DB_OPEN_FLAGS:
1766 ret = ctdb_int32_pull(buf, buflen, mem_ctx,
1767 &cd->data.tdb_flags);
1768 break;
1770 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1771 ret = ctdb_uint32_pull(buf, buflen, mem_ctx,
1772 &cd->data.db_id);
1773 break;
1776 return ret;
1779 size_t ctdb_req_control_len(struct ctdb_req_header *h,
1780 struct ctdb_req_control *c)
1782 return offsetof(struct ctdb_req_control_wire, data) +
1783 ctdb_req_control_data_len(&c->rdata);
1786 int ctdb_req_control_push(struct ctdb_req_header *h,
1787 struct ctdb_req_control *request,
1788 uint8_t *buf, size_t *buflen)
1790 struct ctdb_req_control_wire *wire =
1791 (struct ctdb_req_control_wire *)buf;
1792 size_t length;
1794 length = ctdb_req_control_len(h, request);
1795 if (*buflen < length) {
1796 *buflen = length;
1797 return EMSGSIZE;
1800 h->length = *buflen;
1801 ctdb_req_header_push(h, (uint8_t *)&wire->hdr);
1803 wire->opcode = request->opcode;
1804 wire->pad = request->pad;
1805 wire->srvid = request->srvid;
1806 wire->client_id = request->client_id;
1807 wire->flags = request->flags;
1809 wire->datalen = ctdb_req_control_data_len(&request->rdata);
1810 ctdb_req_control_data_push(&request->rdata, wire->data);
1812 return 0;
1815 int ctdb_req_control_pull(uint8_t *buf, size_t buflen,
1816 struct ctdb_req_header *h,
1817 TALLOC_CTX *mem_ctx,
1818 struct ctdb_req_control *c)
1820 struct ctdb_req_control_wire *wire =
1821 (struct ctdb_req_control_wire *)buf;
1822 size_t length;
1823 int ret;
1825 length = offsetof(struct ctdb_req_control_wire, data);
1826 if (buflen < length) {
1827 return EMSGSIZE;
1829 if (wire->datalen > buflen) {
1830 return EMSGSIZE;
1832 if (length + wire->datalen < length) {
1833 return EMSGSIZE;
1835 if (buflen < length + wire->datalen) {
1836 return EMSGSIZE;
1839 if (h != NULL) {
1840 ret = ctdb_req_header_pull((uint8_t *)&wire->hdr, buflen, h);
1841 if (ret != 0) {
1842 return ret;
1846 c->opcode = wire->opcode;
1847 c->pad = wire->pad;
1848 c->srvid = wire->srvid;
1849 c->client_id = wire->client_id;
1850 c->flags = wire->flags;
1852 ret = ctdb_req_control_data_pull(wire->data, wire->datalen,
1853 c->opcode, mem_ctx, &c->rdata);
1854 if (ret != 0) {
1855 return ret;
1858 return 0;
1861 size_t ctdb_reply_control_len(struct ctdb_req_header *h,
1862 struct ctdb_reply_control *c)
1864 return offsetof(struct ctdb_reply_control_wire, data) +
1865 (c->status == 0 ?
1866 ctdb_reply_control_data_len(&c->rdata) :
1867 ctdb_string_len(c->errmsg));
1870 int ctdb_reply_control_push(struct ctdb_req_header *h,
1871 struct ctdb_reply_control *reply,
1872 uint8_t *buf, size_t *buflen)
1874 struct ctdb_reply_control_wire *wire =
1875 (struct ctdb_reply_control_wire *)buf;
1876 size_t length;
1878 length = ctdb_reply_control_len(h, reply);
1879 if (*buflen < length) {
1880 *buflen = length;
1881 return EMSGSIZE;
1884 h->length = *buflen;
1885 ctdb_req_header_push(h, (uint8_t *)&wire->hdr);
1887 wire->status = reply->status;
1889 if (reply->status == 0) {
1890 wire->datalen = ctdb_reply_control_data_len(&reply->rdata);
1891 wire->errorlen = 0;
1892 ctdb_reply_control_data_push(&reply->rdata, wire->data);
1893 } else {
1894 wire->datalen = 0;
1895 wire->errorlen = ctdb_string_len(reply->errmsg);
1896 ctdb_string_push(reply->errmsg, wire->data + wire->datalen);
1899 return 0;
1902 int ctdb_reply_control_pull(uint8_t *buf, size_t buflen, uint32_t opcode,
1903 struct ctdb_req_header *h,
1904 TALLOC_CTX *mem_ctx,
1905 struct ctdb_reply_control *c)
1907 struct ctdb_reply_control_wire *wire =
1908 (struct ctdb_reply_control_wire *)buf;
1909 size_t length;
1910 int ret;
1912 length = offsetof(struct ctdb_reply_control_wire, data);
1913 if (buflen < length) {
1914 return EMSGSIZE;
1916 if (wire->datalen > buflen || wire->errorlen > buflen) {
1917 return EMSGSIZE;
1919 if (length + wire->datalen < length) {
1920 return EMSGSIZE;
1922 if (length + wire->datalen + wire->errorlen < length) {
1923 return EMSGSIZE;
1925 if (buflen < length + wire->datalen + wire->errorlen) {
1926 return EMSGSIZE;
1929 if (h != NULL) {
1930 ret = ctdb_req_header_pull((uint8_t *)&wire->hdr, buflen, h);
1931 if (ret != 0) {
1932 return ret;
1936 c->status = wire->status;
1938 if (c->status != -1) {
1939 ret = ctdb_reply_control_data_pull(wire->data, wire->datalen,
1940 opcode, mem_ctx,
1941 &c->rdata);
1942 if (ret != 0) {
1943 return ret;
1947 ret = ctdb_string_pull(wire->data + wire->datalen, wire->errorlen,
1948 mem_ctx, &c->errmsg);
1949 if (ret != 0) {
1950 return ret;
1953 return 0;