pytest/dns_aging: use correct variable names
[Samba.git] / ctdb / protocol / protocol_control.c
blobf64a1a90e105e15fdbb933cc341191376620a41f
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 static size_t ctdb_req_control_data_len(struct ctdb_req_control_data *cd)
32 size_t len = 0;
33 uint32_t u32;
35 if (cd == NULL) {
36 return 0;
39 switch (cd->opcode) {
40 case CTDB_CONTROL_PROCESS_EXISTS:
41 len = ctdb_pid_len(&cd->data.pid);
42 break;
44 case CTDB_CONTROL_STATISTICS:
45 break;
47 case CTDB_CONTROL_PING:
48 break;
50 case CTDB_CONTROL_GETDBPATH:
51 len = ctdb_uint32_len(&cd->data.db_id);
52 break;
54 case CTDB_CONTROL_GETVNNMAP:
55 break;
57 case CTDB_CONTROL_SETVNNMAP:
58 len = ctdb_vnn_map_len(cd->data.vnnmap);
59 break;
61 case CTDB_CONTROL_GET_DEBUG:
62 break;
64 case CTDB_CONTROL_SET_DEBUG:
65 len = ctdb_uint32_len(&cd->data.loglevel);
66 break;
68 case CTDB_CONTROL_GET_DBMAP:
69 break;
71 case CTDB_CONTROL_GET_RECMODE:
72 break;
74 case CTDB_CONTROL_SET_RECMODE:
75 len = ctdb_uint32_len(&cd->data.recmode);
76 break;
78 case CTDB_CONTROL_STATISTICS_RESET:
79 break;
81 case CTDB_CONTROL_DB_ATTACH:
82 len = ctdb_string_len(&cd->data.db_name);
83 break;
85 case CTDB_CONTROL_TRAVERSE_START:
86 len = ctdb_traverse_start_len(cd->data.traverse_start);
87 break;
89 case CTDB_CONTROL_TRAVERSE_ALL:
90 len = ctdb_traverse_all_len(cd->data.traverse_all);
91 break;
93 case CTDB_CONTROL_TRAVERSE_DATA:
94 len = ctdb_rec_data_len(cd->data.rec_data);
95 break;
97 case CTDB_CONTROL_REGISTER_SRVID:
98 break;
100 case CTDB_CONTROL_DEREGISTER_SRVID:
101 break;
103 case CTDB_CONTROL_GET_DBNAME:
104 len = ctdb_uint32_len(&cd->data.db_id);
105 break;
107 case CTDB_CONTROL_ENABLE_SEQNUM:
108 len = ctdb_uint32_len(&cd->data.db_id);
109 break;
111 case CTDB_CONTROL_UPDATE_SEQNUM:
112 len = ctdb_uint32_len(&cd->data.db_id);
113 break;
115 case CTDB_CONTROL_DUMP_MEMORY:
116 break;
118 case CTDB_CONTROL_GET_PID:
119 break;
121 case CTDB_CONTROL_GET_RECMASTER:
122 break;
124 case CTDB_CONTROL_SET_RECMASTER:
125 len = ctdb_uint32_len(&cd->data.recmaster);
126 break;
128 case CTDB_CONTROL_FREEZE:
129 break;
131 case CTDB_CONTROL_GET_PNN:
132 break;
134 case CTDB_CONTROL_SHUTDOWN:
135 break;
137 case CTDB_CONTROL_TCP_CLIENT:
138 len = ctdb_connection_len(cd->data.conn);
139 break;
141 case CTDB_CONTROL_TCP_ADD:
142 len = ctdb_connection_len(cd->data.conn);
143 break;
145 case CTDB_CONTROL_TCP_REMOVE:
146 len = ctdb_connection_len(cd->data.conn);
147 break;
149 case CTDB_CONTROL_STARTUP:
150 break;
152 case CTDB_CONTROL_SET_TUNABLE:
153 len = ctdb_tunable_len(cd->data.tunable);
154 break;
156 case CTDB_CONTROL_GET_TUNABLE:
157 len = ctdb_stringn_len(&cd->data.tun_var);
158 break;
160 case CTDB_CONTROL_LIST_TUNABLES:
161 break;
163 case CTDB_CONTROL_MODIFY_FLAGS:
164 len = ctdb_node_flag_change_len(cd->data.flag_change);
165 break;
167 case CTDB_CONTROL_GET_ALL_TUNABLES:
168 break;
170 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
171 len = ctdb_sock_addr_len(cd->data.addr);
172 break;
174 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
175 len = ctdb_tickle_list_len(cd->data.tickles);
176 break;
178 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
179 len = ctdb_string_len(&cd->data.db_name);
180 break;
182 case CTDB_CONTROL_UPDATE_RECORD:
183 len = ctdb_rec_buffer_len(cd->data.recbuf);
184 break;
186 case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
187 len = ctdb_addr_info_len(cd->data.addr_info);
188 break;
190 case CTDB_CONTROL_WIPE_DATABASE:
191 len = ctdb_transdb_len(cd->data.transdb);
192 break;
194 case CTDB_CONTROL_UPTIME:
195 break;
197 case CTDB_CONTROL_START_RECOVERY:
198 break;
200 case CTDB_CONTROL_END_RECOVERY:
201 break;
203 case CTDB_CONTROL_RELOAD_NODES_FILE:
204 break;
206 case CTDB_CONTROL_TRY_DELETE_RECORDS:
207 len = ctdb_rec_buffer_len(cd->data.recbuf);
208 break;
210 case CTDB_CONTROL_ADD_PUBLIC_IP:
211 len = ctdb_addr_info_len(cd->data.addr_info);
212 break;
214 case CTDB_CONTROL_DEL_PUBLIC_IP:
215 len = ctdb_addr_info_len(cd->data.addr_info);
216 break;
218 case CTDB_CONTROL_GET_CAPABILITIES:
219 break;
221 case CTDB_CONTROL_RECD_PING:
222 break;
224 case CTDB_CONTROL_RELEASE_IP:
225 len = ctdb_public_ip_len(cd->data.pubip);
226 break;
228 case CTDB_CONTROL_TAKEOVER_IP:
229 len = ctdb_public_ip_len(cd->data.pubip);
230 break;
232 case CTDB_CONTROL_GET_PUBLIC_IPS:
233 break;
235 case CTDB_CONTROL_GET_NODEMAP:
236 break;
238 case CTDB_CONTROL_TRAVERSE_KILL:
239 len = ctdb_traverse_start_len(cd->data.traverse_start);
240 break;
242 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
243 len = ctdb_double_len(&cd->data.reclock_latency);
244 break;
246 case CTDB_CONTROL_GET_RECLOCK_FILE:
247 break;
249 case CTDB_CONTROL_STOP_NODE:
250 break;
252 case CTDB_CONTROL_CONTINUE_NODE:
253 break;
255 case CTDB_CONTROL_SET_LMASTERROLE:
256 len = ctdb_uint32_len(&cd->data.role);
257 break;
259 case CTDB_CONTROL_SET_RECMASTERROLE:
260 len = ctdb_uint32_len(&cd->data.role);
261 break;
263 case CTDB_CONTROL_SET_BAN_STATE:
264 len = ctdb_ban_state_len(cd->data.ban_state);
265 break;
267 case CTDB_CONTROL_GET_BAN_STATE:
268 break;
270 case CTDB_CONTROL_REGISTER_NOTIFY:
271 len = ctdb_notify_data_len(cd->data.notify);
272 break;
274 case CTDB_CONTROL_DEREGISTER_NOTIFY:
275 len = ctdb_uint64_len(&cd->data.srvid);
276 break;
278 case CTDB_CONTROL_TRANS3_COMMIT:
279 len = ctdb_rec_buffer_len(cd->data.recbuf);
280 break;
282 case CTDB_CONTROL_GET_DB_SEQNUM:
283 u32 = 0;
284 len = ctdb_uint32_len(&cd->data.db_id) + ctdb_uint32_len(&u32);
285 break;
287 case CTDB_CONTROL_DB_SET_HEALTHY:
288 len = ctdb_uint32_len(&cd->data.db_id);
289 break;
291 case CTDB_CONTROL_DB_GET_HEALTH:
292 len = ctdb_uint32_len(&cd->data.db_id);
293 break;
295 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
296 len = ctdb_sock_addr_len(cd->data.addr);
297 break;
299 case CTDB_CONTROL_GET_IFACES:
300 break;
302 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
303 len = ctdb_iface_len(cd->data.iface);
304 break;
306 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
307 len = ctdb_connection_len(cd->data.conn);
308 break;
310 case CTDB_CONTROL_GET_STAT_HISTORY:
311 break;
313 case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
314 len = ctdb_key_data_len(cd->data.key);
315 break;
317 case CTDB_CONTROL_SET_DB_READONLY:
318 len = ctdb_uint32_len(&cd->data.db_id);
319 break;
321 case CTDB_CONTROL_TRAVERSE_START_EXT:
322 len = ctdb_traverse_start_ext_len(cd->data.traverse_start_ext);
323 break;
325 case CTDB_CONTROL_GET_DB_STATISTICS:
326 len = ctdb_uint32_len(&cd->data.db_id);
327 break;
329 case CTDB_CONTROL_SET_DB_STICKY:
330 len = ctdb_uint32_len(&cd->data.db_id);
331 break;
333 case CTDB_CONTROL_RELOAD_PUBLIC_IPS:
334 break;
336 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
337 len = ctdb_traverse_all_ext_len(cd->data.traverse_all_ext);
338 break;
340 case CTDB_CONTROL_IPREALLOCATED:
341 break;
343 case CTDB_CONTROL_GET_RUNSTATE:
344 break;
346 case CTDB_CONTROL_DB_DETACH:
347 len = ctdb_uint32_len(&cd->data.db_id);
348 break;
350 case CTDB_CONTROL_GET_NODES_FILE:
351 break;
353 case CTDB_CONTROL_DB_FREEZE:
354 len = ctdb_uint32_len(&cd->data.db_id);
355 break;
357 case CTDB_CONTROL_DB_THAW:
358 len = ctdb_uint32_len(&cd->data.db_id);
359 break;
361 case CTDB_CONTROL_DB_TRANSACTION_START:
362 len = ctdb_transdb_len(cd->data.transdb);
363 break;
365 case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
366 len = ctdb_transdb_len(cd->data.transdb);
367 break;
369 case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
370 len = ctdb_uint32_len(&cd->data.db_id);
371 break;
373 case CTDB_CONTROL_DB_PULL:
374 len = ctdb_pulldb_ext_len(cd->data.pulldb_ext);
375 break;
377 case CTDB_CONTROL_DB_PUSH_START:
378 len = ctdb_pulldb_ext_len(cd->data.pulldb_ext);
379 break;
381 case CTDB_CONTROL_DB_PUSH_CONFIRM:
382 len = ctdb_uint32_len(&cd->data.db_id);
383 break;
385 case CTDB_CONTROL_DB_OPEN_FLAGS:
386 len = ctdb_uint32_len(&cd->data.db_id);
387 break;
389 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
390 len = ctdb_string_len(&cd->data.db_name);
391 break;
393 case CTDB_CONTROL_CHECK_PID_SRVID:
394 len = ctdb_pid_srvid_len(cd->data.pid_srvid);
395 break;
397 case CTDB_CONTROL_TUNNEL_REGISTER:
398 break;
400 case CTDB_CONTROL_TUNNEL_DEREGISTER:
401 break;
403 case CTDB_CONTROL_VACUUM_FETCH:
404 len = ctdb_rec_buffer_len(cd->data.recbuf);
405 break;
407 case CTDB_CONTROL_DB_VACUUM:
408 len = ctdb_db_vacuum_len(cd->data.db_vacuum);
409 break;
411 case CTDB_CONTROL_ECHO_DATA:
412 len = ctdb_echo_data_len(cd->data.echo_data);
413 break;
415 case CTDB_CONTROL_DISABLE_NODE:
416 break;
418 case CTDB_CONTROL_ENABLE_NODE:
419 break;
422 return len;
425 static void ctdb_req_control_data_push(struct ctdb_req_control_data *cd,
426 uint8_t *buf, size_t *npush)
428 size_t np = 0, offset;
429 uint32_t u32;
431 switch (cd->opcode) {
432 case CTDB_CONTROL_PROCESS_EXISTS:
433 ctdb_pid_push(&cd->data.pid, buf, &np);
434 break;
436 case CTDB_CONTROL_GETDBPATH:
437 ctdb_uint32_push(&cd->data.db_id, buf, &np);
438 break;
440 case CTDB_CONTROL_SETVNNMAP:
441 ctdb_vnn_map_push(cd->data.vnnmap, buf, &np);
442 break;
444 case CTDB_CONTROL_SET_DEBUG:
445 ctdb_uint32_push(&cd->data.loglevel, buf, &np);
446 break;
448 case CTDB_CONTROL_SET_RECMODE:
449 ctdb_uint32_push(&cd->data.recmode, buf, &np);
450 break;
452 case CTDB_CONTROL_DB_ATTACH:
453 ctdb_string_push(&cd->data.db_name, buf, &np);
454 break;
456 case CTDB_CONTROL_TRAVERSE_START:
457 ctdb_traverse_start_push(cd->data.traverse_start, buf, &np);
458 break;
460 case CTDB_CONTROL_TRAVERSE_ALL:
461 ctdb_traverse_all_push(cd->data.traverse_all, buf, &np);
462 break;
464 case CTDB_CONTROL_TRAVERSE_DATA:
465 ctdb_rec_data_push(cd->data.rec_data, buf, &np);
466 break;
468 case CTDB_CONTROL_GET_DBNAME:
469 ctdb_uint32_push(&cd->data.db_id, buf, &np);
470 break;
472 case CTDB_CONTROL_ENABLE_SEQNUM:
473 ctdb_uint32_push(&cd->data.db_id, buf, &np);
474 break;
476 case CTDB_CONTROL_UPDATE_SEQNUM:
477 ctdb_uint32_push(&cd->data.db_id, buf, &np);
478 break;
480 case CTDB_CONTROL_SET_RECMASTER:
481 ctdb_uint32_push(&cd->data.recmaster, buf, &np);
482 break;
484 case CTDB_CONTROL_TCP_CLIENT:
485 ctdb_connection_push(cd->data.conn, buf, &np);
486 break;
488 case CTDB_CONTROL_TCP_ADD:
489 ctdb_connection_push(cd->data.conn, buf, &np);
490 break;
492 case CTDB_CONTROL_TCP_REMOVE:
493 ctdb_connection_push(cd->data.conn, buf, &np);
494 break;
496 case CTDB_CONTROL_SET_TUNABLE:
497 ctdb_tunable_push(cd->data.tunable, buf, &np);
498 break;
500 case CTDB_CONTROL_GET_TUNABLE:
501 ctdb_stringn_push(&cd->data.tun_var, buf, &np);
502 break;
504 case CTDB_CONTROL_MODIFY_FLAGS:
505 ctdb_node_flag_change_push(cd->data.flag_change, buf, &np);
506 break;
508 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
509 ctdb_sock_addr_push(cd->data.addr, buf, &np);
510 break;
512 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
513 ctdb_tickle_list_push(cd->data.tickles, buf, &np);
514 break;
516 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
517 ctdb_string_push(&cd->data.db_name, buf, &np);
518 break;
520 case CTDB_CONTROL_UPDATE_RECORD:
521 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
522 break;
524 case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
525 ctdb_addr_info_push(cd->data.addr_info, buf, &np);
526 break;
528 case CTDB_CONTROL_WIPE_DATABASE:
529 ctdb_transdb_push(cd->data.transdb, buf, &np);
530 break;
532 case CTDB_CONTROL_TRY_DELETE_RECORDS:
533 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
534 break;
536 case CTDB_CONTROL_ADD_PUBLIC_IP:
537 ctdb_addr_info_push(cd->data.addr_info, buf, &np);
538 break;
540 case CTDB_CONTROL_DEL_PUBLIC_IP:
541 ctdb_addr_info_push(cd->data.addr_info, buf, &np);
542 break;
544 case CTDB_CONTROL_RELEASE_IP:
545 ctdb_public_ip_push(cd->data.pubip, buf, &np);
546 break;
548 case CTDB_CONTROL_TAKEOVER_IP:
549 ctdb_public_ip_push(cd->data.pubip, buf, &np);
550 break;
552 case CTDB_CONTROL_TRAVERSE_KILL:
553 ctdb_traverse_start_push(cd->data.traverse_start, buf, &np);
554 break;
556 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
557 ctdb_double_push(&cd->data.reclock_latency, buf, &np);
558 break;
560 case CTDB_CONTROL_SET_LMASTERROLE:
561 ctdb_uint32_push(&cd->data.role, buf, &np);
562 break;
564 case CTDB_CONTROL_SET_RECMASTERROLE:
565 ctdb_uint32_push(&cd->data.role, buf, &np);
566 break;
568 case CTDB_CONTROL_SET_BAN_STATE:
569 ctdb_ban_state_push(cd->data.ban_state, buf, &np);
570 break;
572 case CTDB_CONTROL_REGISTER_NOTIFY:
573 ctdb_notify_data_push(cd->data.notify, buf, &np);
574 break;
576 case CTDB_CONTROL_DEREGISTER_NOTIFY:
577 ctdb_uint64_push(&cd->data.srvid, buf, &np);
578 break;
580 case CTDB_CONTROL_TRANS3_COMMIT:
581 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
582 break;
584 case CTDB_CONTROL_GET_DB_SEQNUM:
585 u32 = 0;
586 offset = 0;
587 ctdb_uint32_push(&cd->data.db_id, buf, &np);
588 offset += np;
589 ctdb_uint32_push(&u32, buf+offset, &np);
590 offset += np;
591 np = offset;
592 break;
594 case CTDB_CONTROL_DB_SET_HEALTHY:
595 ctdb_uint32_push(&cd->data.db_id, buf, &np);
596 break;
598 case CTDB_CONTROL_DB_GET_HEALTH:
599 ctdb_uint32_push(&cd->data.db_id, buf, &np);
600 break;
602 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
603 ctdb_sock_addr_push(cd->data.addr, buf, &np);
604 break;
606 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
607 ctdb_iface_push(cd->data.iface, buf, &np);
608 break;
610 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
611 ctdb_connection_push(cd->data.conn, buf, &np);
612 break;
614 case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
615 ctdb_key_data_push(cd->data.key, buf, &np);
616 break;
618 case CTDB_CONTROL_SET_DB_READONLY:
619 ctdb_uint32_push(&cd->data.db_id, buf, &np);
620 break;
622 case CTDB_CONTROL_TRAVERSE_START_EXT:
623 ctdb_traverse_start_ext_push(cd->data.traverse_start_ext, buf,
624 &np);
625 break;
627 case CTDB_CONTROL_GET_DB_STATISTICS:
628 ctdb_uint32_push(&cd->data.db_id, buf, &np);
629 break;
631 case CTDB_CONTROL_SET_DB_STICKY:
632 ctdb_uint32_push(&cd->data.db_id, buf, &np);
633 break;
635 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
636 ctdb_traverse_all_ext_push(cd->data.traverse_all_ext, buf,
637 &np);
638 break;
640 case CTDB_CONTROL_DB_DETACH:
641 ctdb_uint32_push(&cd->data.db_id, buf, &np);
642 break;
644 case CTDB_CONTROL_DB_FREEZE:
645 ctdb_uint32_push(&cd->data.db_id, buf, &np);
646 break;
648 case CTDB_CONTROL_DB_THAW:
649 ctdb_uint32_push(&cd->data.db_id, buf, &np);
650 break;
652 case CTDB_CONTROL_DB_TRANSACTION_START:
653 ctdb_transdb_push(cd->data.transdb, buf, &np);
654 break;
656 case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
657 ctdb_transdb_push(cd->data.transdb, buf, &np);
658 break;
660 case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
661 ctdb_uint32_push(&cd->data.db_id, buf, &np);
662 break;
664 case CTDB_CONTROL_DB_PULL:
665 ctdb_pulldb_ext_push(cd->data.pulldb_ext, buf, &np);
666 break;
668 case CTDB_CONTROL_DB_PUSH_START:
669 ctdb_pulldb_ext_push(cd->data.pulldb_ext, buf, &np);
670 break;
672 case CTDB_CONTROL_DB_PUSH_CONFIRM:
673 ctdb_uint32_push(&cd->data.db_id, buf, &np);
674 break;
676 case CTDB_CONTROL_DB_OPEN_FLAGS:
677 ctdb_uint32_push(&cd->data.db_id, buf, &np);
678 break;
680 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
681 ctdb_string_push(&cd->data.db_name, buf, &np);
682 break;
684 case CTDB_CONTROL_CHECK_PID_SRVID:
685 ctdb_pid_srvid_push(cd->data.pid_srvid, buf, &np);
686 break;
688 case CTDB_CONTROL_VACUUM_FETCH:
689 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
690 break;
692 case CTDB_CONTROL_DB_VACUUM:
693 ctdb_db_vacuum_push(cd->data.db_vacuum, buf, &np);
694 break;
696 case CTDB_CONTROL_ECHO_DATA:
697 ctdb_echo_data_push(cd->data.echo_data, buf, &np);
698 break;
701 *npush = np;
704 static int ctdb_req_control_data_pull(uint8_t *buf, size_t buflen,
705 uint32_t opcode,
706 TALLOC_CTX *mem_ctx,
707 struct ctdb_req_control_data *cd,
708 size_t *npull)
710 size_t np = 0, offset;
711 uint32_t u32;
712 int ret = 0;
714 cd->opcode = opcode;
716 switch (opcode) {
717 case CTDB_CONTROL_PROCESS_EXISTS:
718 ret = ctdb_pid_pull(buf, buflen, &cd->data.pid, &np);
719 break;
721 case CTDB_CONTROL_GETDBPATH:
722 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
723 break;
725 case CTDB_CONTROL_SETVNNMAP:
726 ret = ctdb_vnn_map_pull(buf, buflen, mem_ctx,
727 &cd->data.vnnmap, &np);
728 break;
730 case CTDB_CONTROL_SET_DEBUG:
731 ret = ctdb_uint32_pull(buf, buflen, &cd->data.loglevel, &np);
732 break;
734 case CTDB_CONTROL_SET_RECMODE:
735 ret = ctdb_uint32_pull(buf, buflen, &cd->data.recmode, &np);
736 break;
738 case CTDB_CONTROL_DB_ATTACH:
739 ret = ctdb_string_pull(buf, buflen, mem_ctx,
740 &cd->data.db_name, &np);
741 break;
743 case CTDB_CONTROL_TRAVERSE_START:
744 ret = ctdb_traverse_start_pull(buf, buflen, mem_ctx,
745 &cd->data.traverse_start, &np);
746 break;
748 case CTDB_CONTROL_TRAVERSE_ALL:
749 ret = ctdb_traverse_all_pull(buf, buflen, mem_ctx,
750 &cd->data.traverse_all, &np);
751 break;
753 case CTDB_CONTROL_TRAVERSE_DATA:
754 ret = ctdb_rec_data_pull(buf, buflen, mem_ctx,
755 &cd->data.rec_data, &np);
756 break;
758 case CTDB_CONTROL_GET_DBNAME:
759 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
760 break;
762 case CTDB_CONTROL_ENABLE_SEQNUM:
763 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
764 break;
766 case CTDB_CONTROL_UPDATE_SEQNUM:
767 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
768 break;
770 case CTDB_CONTROL_SET_RECMASTER:
771 ret = ctdb_uint32_pull(buf, buflen, &cd->data.recmaster, &np);
772 break;
774 case CTDB_CONTROL_TCP_CLIENT:
775 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
776 &cd->data.conn, &np);
777 break;
779 case CTDB_CONTROL_TCP_ADD:
780 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
781 &cd->data.conn, &np);
782 break;
784 case CTDB_CONTROL_TCP_REMOVE:
785 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
786 &cd->data.conn, &np);
787 break;
789 case CTDB_CONTROL_SET_TUNABLE:
790 ret = ctdb_tunable_pull(buf, buflen, mem_ctx,
791 &cd->data.tunable, &np);
792 break;
794 case CTDB_CONTROL_GET_TUNABLE:
795 ret = ctdb_stringn_pull(buf, buflen, mem_ctx,
796 &cd->data.tun_var, &np);
797 break;
799 case CTDB_CONTROL_MODIFY_FLAGS:
800 ret = ctdb_node_flag_change_pull(buf, buflen, mem_ctx,
801 &cd->data.flag_change, &np);
802 break;
804 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
805 ret = ctdb_sock_addr_pull(buf, buflen, mem_ctx,
806 &cd->data.addr, &np);
807 break;
809 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
810 ret = ctdb_tickle_list_pull(buf, buflen, mem_ctx,
811 &cd->data.tickles, &np);
812 break;
814 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
815 ret = ctdb_string_pull(buf, buflen, mem_ctx,
816 &cd->data.db_name, &np);
817 break;
819 case CTDB_CONTROL_UPDATE_RECORD:
820 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
821 &cd->data.recbuf, &np);
822 break;
824 case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
825 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
826 &cd->data.addr_info, &np);
827 break;
829 case CTDB_CONTROL_WIPE_DATABASE:
830 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
831 &cd->data.transdb, &np);
832 break;
834 case CTDB_CONTROL_TRY_DELETE_RECORDS:
835 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
836 &cd->data.recbuf, &np);
837 break;
839 case CTDB_CONTROL_ADD_PUBLIC_IP:
840 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
841 &cd->data.addr_info, &np);
842 break;
844 case CTDB_CONTROL_DEL_PUBLIC_IP:
845 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
846 &cd->data.addr_info, &np);
847 break;
849 case CTDB_CONTROL_RELEASE_IP:
850 ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
851 &cd->data.pubip, &np);
852 break;
854 case CTDB_CONTROL_TAKEOVER_IP:
855 ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
856 &cd->data.pubip, &np);
857 break;
859 case CTDB_CONTROL_TRAVERSE_KILL:
860 ret = ctdb_traverse_start_pull(buf, buflen, mem_ctx,
861 &cd->data.traverse_start, &np);
862 break;
864 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
865 ret = ctdb_double_pull(buf, buflen, &cd->data.reclock_latency,
866 &np);
867 break;
869 case CTDB_CONTROL_SET_LMASTERROLE:
870 ret = ctdb_uint32_pull(buf, buflen, &cd->data.role, &np);
871 break;
873 case CTDB_CONTROL_SET_RECMASTERROLE:
874 ret = ctdb_uint32_pull(buf, buflen, &cd->data.role, &np);
875 break;
877 case CTDB_CONTROL_SET_BAN_STATE:
878 ret = ctdb_ban_state_pull(buf, buflen, mem_ctx,
879 &cd->data.ban_state, &np);
880 break;
882 case CTDB_CONTROL_REGISTER_NOTIFY:
883 ret = ctdb_notify_data_pull(buf, buflen, mem_ctx,
884 &cd->data.notify, &np);
885 break;
887 case CTDB_CONTROL_DEREGISTER_NOTIFY:
888 ret = ctdb_uint64_pull(buf, buflen, &cd->data.srvid, &np);
889 break;
891 case CTDB_CONTROL_TRANS3_COMMIT:
892 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
893 &cd->data.recbuf, &np);
894 break;
896 case CTDB_CONTROL_GET_DB_SEQNUM:
897 offset = 0;
898 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
899 if (ret != 0) {
900 break;
902 offset += np;
903 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
904 offset += np;
905 np = offset;
906 break;
908 case CTDB_CONTROL_DB_SET_HEALTHY:
909 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
910 break;
912 case CTDB_CONTROL_DB_GET_HEALTH:
913 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
914 break;
916 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
917 ret = ctdb_sock_addr_pull(buf, buflen, mem_ctx,
918 &cd->data.addr, &np);
919 break;
921 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
922 ret = ctdb_iface_pull(buf, buflen, mem_ctx,
923 &cd->data.iface, &np);
924 break;
926 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
927 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
928 &cd->data.conn, &np);
929 break;
931 case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
932 ret = ctdb_key_data_pull(buf, buflen, mem_ctx,
933 &cd->data.key, &np);
934 break;
936 case CTDB_CONTROL_SET_DB_READONLY:
937 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
938 break;
940 case CTDB_CONTROL_TRAVERSE_START_EXT:
941 ret = ctdb_traverse_start_ext_pull(buf, buflen, mem_ctx,
942 &cd->data.traverse_start_ext,
943 &np);
944 break;
946 case CTDB_CONTROL_GET_DB_STATISTICS:
947 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
948 break;
950 case CTDB_CONTROL_SET_DB_STICKY:
951 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
952 break;
954 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
955 ret = ctdb_traverse_all_ext_pull(buf, buflen, mem_ctx,
956 &cd->data.traverse_all_ext,
957 &np);
958 break;
960 case CTDB_CONTROL_DB_DETACH:
961 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
962 break;
964 case CTDB_CONTROL_DB_FREEZE:
965 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
966 break;
968 case CTDB_CONTROL_DB_THAW:
969 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
970 break;
972 case CTDB_CONTROL_DB_TRANSACTION_START:
973 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
974 &cd->data.transdb, &np);
975 break;
977 case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
978 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
979 &cd->data.transdb, &np);
980 break;
982 case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
983 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
984 break;
986 case CTDB_CONTROL_DB_PULL:
987 ret = ctdb_pulldb_ext_pull(buf, buflen, mem_ctx,
988 &cd->data.pulldb_ext, &np);
989 break;
991 case CTDB_CONTROL_DB_PUSH_START:
992 ret = ctdb_pulldb_ext_pull(buf, buflen, mem_ctx,
993 &cd->data.pulldb_ext, &np);
994 break;
996 case CTDB_CONTROL_DB_PUSH_CONFIRM:
997 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
998 break;
1000 case CTDB_CONTROL_DB_OPEN_FLAGS:
1001 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1002 break;
1004 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1005 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1006 &cd->data.db_name, &np);
1007 break;
1009 case CTDB_CONTROL_CHECK_PID_SRVID:
1010 ret = ctdb_pid_srvid_pull(buf, buflen, mem_ctx,
1011 &cd->data.pid_srvid, &np);
1012 break;
1014 case CTDB_CONTROL_VACUUM_FETCH:
1015 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
1016 &cd->data.recbuf, &np);
1017 break;
1019 case CTDB_CONTROL_DB_VACUUM:
1020 ret = ctdb_db_vacuum_pull(buf,
1021 buflen,
1022 mem_ctx,
1023 &cd->data.db_vacuum,
1024 &np);
1025 break;
1027 case CTDB_CONTROL_ECHO_DATA:
1028 ret = ctdb_echo_data_pull(buf,
1029 buflen,
1030 mem_ctx,
1031 &cd->data.echo_data,
1032 &np);
1033 break;
1036 if (ret != 0) {
1037 return ret;
1040 *npull = np;
1041 return 0;
1044 static size_t ctdb_reply_control_data_len(struct ctdb_reply_control_data *cd)
1046 size_t len = 0;
1048 if (cd == NULL) {
1049 return 0;
1052 switch (cd->opcode) {
1053 case CTDB_CONTROL_PROCESS_EXISTS:
1054 break;
1056 case CTDB_CONTROL_STATISTICS:
1057 len = ctdb_statistics_len(cd->data.stats);
1058 break;
1060 case CTDB_CONTROL_PING:
1061 break;
1063 case CTDB_CONTROL_GETDBPATH:
1064 len = ctdb_string_len(&cd->data.db_path);
1065 break;
1067 case CTDB_CONTROL_GETVNNMAP:
1068 len = ctdb_vnn_map_len(cd->data.vnnmap);
1069 break;
1071 case CTDB_CONTROL_SETVNNMAP:
1072 break;
1074 case CTDB_CONTROL_GET_DEBUG:
1075 len = ctdb_uint32_len(&cd->data.loglevel);
1076 break;
1078 case CTDB_CONTROL_SET_DEBUG:
1079 break;
1081 case CTDB_CONTROL_GET_DBMAP:
1082 len = ctdb_dbid_map_len(cd->data.dbmap);
1083 break;
1085 case CTDB_CONTROL_GET_RECMODE:
1086 break;
1088 case CTDB_CONTROL_SET_RECMODE:
1089 break;
1091 case CTDB_CONTROL_STATISTICS_RESET:
1092 break;
1094 case CTDB_CONTROL_DB_ATTACH:
1095 len = ctdb_uint32_len(&cd->data.db_id);
1096 break;
1098 case CTDB_CONTROL_TRAVERSE_START:
1099 break;
1101 case CTDB_CONTROL_TRAVERSE_ALL:
1102 break;
1104 case CTDB_CONTROL_TRAVERSE_DATA:
1105 break;
1107 case CTDB_CONTROL_REGISTER_SRVID:
1108 break;
1110 case CTDB_CONTROL_DEREGISTER_SRVID:
1111 break;
1113 case CTDB_CONTROL_GET_DBNAME:
1114 len = ctdb_string_len(&cd->data.db_name);
1115 break;
1117 case CTDB_CONTROL_ENABLE_SEQNUM:
1118 break;
1120 case CTDB_CONTROL_UPDATE_SEQNUM:
1121 break;
1123 case CTDB_CONTROL_DUMP_MEMORY:
1124 len = ctdb_string_len(&cd->data.mem_str);
1125 break;
1127 case CTDB_CONTROL_GET_PID:
1128 break;
1130 case CTDB_CONTROL_GET_RECMASTER:
1131 break;
1133 case CTDB_CONTROL_SET_RECMASTER:
1134 break;
1136 case CTDB_CONTROL_FREEZE:
1137 break;
1139 case CTDB_CONTROL_GET_PNN:
1140 break;
1142 case CTDB_CONTROL_SHUTDOWN:
1143 break;
1145 case CTDB_CONTROL_TCP_CLIENT:
1146 break;
1148 case CTDB_CONTROL_TCP_ADD:
1149 break;
1151 case CTDB_CONTROL_TCP_REMOVE:
1152 break;
1154 case CTDB_CONTROL_STARTUP:
1155 break;
1157 case CTDB_CONTROL_SET_TUNABLE:
1158 break;
1160 case CTDB_CONTROL_GET_TUNABLE:
1161 len = ctdb_uint32_len(&cd->data.tun_value);
1162 break;
1164 case CTDB_CONTROL_LIST_TUNABLES:
1165 len = ctdb_var_list_len(cd->data.tun_var_list);
1166 break;
1168 case CTDB_CONTROL_MODIFY_FLAGS:
1169 break;
1171 case CTDB_CONTROL_GET_ALL_TUNABLES:
1172 len = ctdb_tunable_list_len(cd->data.tun_list);
1173 break;
1175 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1176 len = ctdb_tickle_list_len(cd->data.tickles);
1177 break;
1179 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
1180 break;
1182 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1183 len = ctdb_uint32_len(&cd->data.db_id);
1184 break;
1186 case CTDB_CONTROL_UPDATE_RECORD:
1187 break;
1189 case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
1190 break;
1192 case CTDB_CONTROL_WIPE_DATABASE:
1193 break;
1195 case CTDB_CONTROL_UPTIME:
1196 len = ctdb_uptime_len(cd->data.uptime);
1197 break;
1199 case CTDB_CONTROL_START_RECOVERY:
1200 break;
1202 case CTDB_CONTROL_END_RECOVERY:
1203 break;
1205 case CTDB_CONTROL_RELOAD_NODES_FILE:
1206 break;
1208 case CTDB_CONTROL_TRY_DELETE_RECORDS:
1209 len = ctdb_rec_buffer_len(cd->data.recbuf);
1210 break;
1212 case CTDB_CONTROL_ADD_PUBLIC_IP:
1213 break;
1215 case CTDB_CONTROL_DEL_PUBLIC_IP:
1216 break;
1218 case CTDB_CONTROL_GET_CAPABILITIES:
1219 len = ctdb_uint32_len(&cd->data.caps);
1220 break;
1222 case CTDB_CONTROL_RECD_PING:
1223 break;
1225 case CTDB_CONTROL_RELEASE_IP:
1226 break;
1228 case CTDB_CONTROL_TAKEOVER_IP:
1229 break;
1231 case CTDB_CONTROL_GET_PUBLIC_IPS:
1232 len = ctdb_public_ip_list_len(cd->data.pubip_list);
1233 break;
1235 case CTDB_CONTROL_GET_NODEMAP:
1236 len = ctdb_node_map_len(cd->data.nodemap);
1237 break;
1239 case CTDB_CONTROL_TRAVERSE_KILL:
1240 break;
1242 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
1243 break;
1245 case CTDB_CONTROL_GET_RECLOCK_FILE:
1246 len = ctdb_string_len(&cd->data.reclock_file);
1247 break;
1249 case CTDB_CONTROL_STOP_NODE:
1250 break;
1252 case CTDB_CONTROL_CONTINUE_NODE:
1253 break;
1255 case CTDB_CONTROL_SET_LMASTERROLE:
1256 break;
1258 case CTDB_CONTROL_SET_RECMASTERROLE:
1259 break;
1261 case CTDB_CONTROL_SET_BAN_STATE:
1262 break;
1264 case CTDB_CONTROL_GET_BAN_STATE:
1265 len = ctdb_ban_state_len(cd->data.ban_state);
1266 break;
1268 case CTDB_CONTROL_REGISTER_NOTIFY:
1269 break;
1271 case CTDB_CONTROL_DEREGISTER_NOTIFY:
1272 break;
1274 case CTDB_CONTROL_TRANS3_COMMIT:
1275 break;
1277 case CTDB_CONTROL_GET_DB_SEQNUM:
1278 len = ctdb_uint64_len(&cd->data.seqnum);
1279 break;
1281 case CTDB_CONTROL_DB_SET_HEALTHY:
1282 break;
1284 case CTDB_CONTROL_DB_GET_HEALTH:
1285 len = ctdb_string_len(&cd->data.reason);
1286 break;
1288 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1289 len = ctdb_public_ip_info_len(cd->data.ipinfo);
1290 break;
1292 case CTDB_CONTROL_GET_IFACES:
1293 len = ctdb_iface_list_len(cd->data.iface_list);
1294 break;
1296 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
1297 break;
1299 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
1300 break;
1302 case CTDB_CONTROL_GET_STAT_HISTORY:
1303 len = ctdb_statistics_list_len(cd->data.stats_list);
1304 break;
1306 case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
1307 break;
1309 case CTDB_CONTROL_SET_DB_READONLY:
1310 break;
1312 case CTDB_CONTROL_TRAVERSE_START_EXT:
1313 break;
1315 case CTDB_CONTROL_GET_DB_STATISTICS:
1316 len = ctdb_db_statistics_len(cd->data.dbstats);
1317 break;
1319 case CTDB_CONTROL_SET_DB_STICKY:
1320 break;
1322 case CTDB_CONTROL_RELOAD_PUBLIC_IPS:
1323 break;
1325 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
1326 break;
1328 case CTDB_CONTROL_IPREALLOCATED:
1329 break;
1331 case CTDB_CONTROL_GET_RUNSTATE:
1332 len = ctdb_uint32_len(&cd->data.runstate);
1333 break;
1335 case CTDB_CONTROL_DB_DETACH:
1336 break;
1338 case CTDB_CONTROL_GET_NODES_FILE:
1339 len = ctdb_node_map_len(cd->data.nodemap);
1340 break;
1342 case CTDB_CONTROL_DB_FREEZE:
1343 break;
1345 case CTDB_CONTROL_DB_THAW:
1346 break;
1348 case CTDB_CONTROL_DB_TRANSACTION_START:
1349 break;
1351 case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
1352 break;
1354 case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
1355 break;
1357 case CTDB_CONTROL_DB_PULL:
1358 len = ctdb_uint32_len(&cd->data.num_records);
1359 break;
1361 case CTDB_CONTROL_DB_PUSH_START:
1362 break;
1364 case CTDB_CONTROL_DB_PUSH_CONFIRM:
1365 len = ctdb_uint32_len(&cd->data.num_records);
1366 break;
1368 case CTDB_CONTROL_DB_OPEN_FLAGS:
1369 len = ctdb_int32_len(&cd->data.tdb_flags);
1370 break;
1372 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1373 len = ctdb_uint32_len(&cd->data.db_id);
1374 break;
1376 case CTDB_CONTROL_CHECK_PID_SRVID:
1377 break;
1379 case CTDB_CONTROL_TUNNEL_REGISTER:
1380 break;
1382 case CTDB_CONTROL_TUNNEL_DEREGISTER:
1383 break;
1385 case CTDB_CONTROL_VACUUM_FETCH:
1386 break;
1388 case CTDB_CONTROL_DB_VACUUM:
1389 break;
1391 case CTDB_CONTROL_ECHO_DATA:
1392 len = ctdb_echo_data_len(cd->data.echo_data);
1393 break;
1395 case CTDB_CONTROL_DISABLE_NODE:
1396 break;
1398 case CTDB_CONTROL_ENABLE_NODE:
1399 break;
1402 return len;
1405 static void ctdb_reply_control_data_push(struct ctdb_reply_control_data *cd,
1406 uint8_t *buf, size_t *npush)
1408 size_t np = 0;
1410 switch (cd->opcode) {
1411 case CTDB_CONTROL_STATISTICS:
1412 ctdb_statistics_push(cd->data.stats, buf, &np);
1413 break;
1415 case CTDB_CONTROL_GETDBPATH:
1416 ctdb_string_push(&cd->data.db_path, buf, &np);
1417 break;
1419 case CTDB_CONTROL_GETVNNMAP:
1420 ctdb_vnn_map_push(cd->data.vnnmap, buf, &np);
1421 break;
1423 case CTDB_CONTROL_GET_DEBUG:
1424 ctdb_uint32_push(&cd->data.loglevel, buf, &np);
1425 break;
1427 case CTDB_CONTROL_GET_DBMAP:
1428 ctdb_dbid_map_push(cd->data.dbmap, buf, &np);
1429 break;
1431 case CTDB_CONTROL_DB_ATTACH:
1432 ctdb_uint32_push(&cd->data.db_id, buf, &np);
1433 break;
1435 case CTDB_CONTROL_GET_DBNAME:
1436 ctdb_string_push(&cd->data.db_name, buf, &np);
1437 break;
1439 case CTDB_CONTROL_DUMP_MEMORY:
1440 ctdb_string_push(&cd->data.mem_str, buf, &np);
1441 break;
1443 case CTDB_CONTROL_GET_PID:
1444 break;
1446 case CTDB_CONTROL_GET_RECMASTER:
1447 break;
1449 case CTDB_CONTROL_GET_TUNABLE:
1450 ctdb_uint32_push(&cd->data.tun_value, buf, &np);
1451 break;
1453 case CTDB_CONTROL_LIST_TUNABLES:
1454 ctdb_var_list_push(cd->data.tun_var_list, buf, &np);
1455 break;
1457 case CTDB_CONTROL_GET_ALL_TUNABLES:
1458 ctdb_tunable_list_push(cd->data.tun_list, buf, &np);
1459 break;
1461 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1462 ctdb_tickle_list_push(cd->data.tickles, buf, &np);
1463 break;
1465 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1466 ctdb_uint32_push(&cd->data.db_id, buf, &np);
1467 break;
1469 case CTDB_CONTROL_UPTIME:
1470 ctdb_uptime_push(cd->data.uptime, buf, &np);
1471 break;
1473 case CTDB_CONTROL_TRY_DELETE_RECORDS:
1474 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
1475 break;
1477 case CTDB_CONTROL_GET_CAPABILITIES:
1478 ctdb_uint32_push(&cd->data.caps, buf, &np);
1479 break;
1481 case CTDB_CONTROL_GET_PUBLIC_IPS:
1482 ctdb_public_ip_list_push(cd->data.pubip_list, buf, &np);
1483 break;
1485 case CTDB_CONTROL_GET_NODEMAP:
1486 ctdb_node_map_push(cd->data.nodemap, buf, &np);
1487 break;
1489 case CTDB_CONTROL_GET_RECLOCK_FILE:
1490 ctdb_string_push(&cd->data.reclock_file, buf, &np);
1491 break;
1493 case CTDB_CONTROL_GET_BAN_STATE:
1494 ctdb_ban_state_push(cd->data.ban_state, buf, &np);
1495 break;
1497 case CTDB_CONTROL_GET_DB_SEQNUM:
1498 ctdb_uint64_push(&cd->data.seqnum, buf, &np);
1499 break;
1501 case CTDB_CONTROL_DB_GET_HEALTH:
1502 ctdb_string_push(&cd->data.reason, buf, &np);
1503 break;
1505 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1506 ctdb_public_ip_info_push(cd->data.ipinfo, buf, &np);
1507 break;
1509 case CTDB_CONTROL_GET_IFACES:
1510 ctdb_iface_list_push(cd->data.iface_list, buf, &np);
1511 break;
1513 case CTDB_CONTROL_GET_STAT_HISTORY:
1514 ctdb_statistics_list_push(cd->data.stats_list, buf, &np);
1515 break;
1517 case CTDB_CONTROL_GET_DB_STATISTICS:
1518 ctdb_db_statistics_push(cd->data.dbstats, buf, &np);
1519 break;
1521 case CTDB_CONTROL_GET_RUNSTATE:
1522 ctdb_uint32_push(&cd->data.runstate, buf, &np);
1523 break;
1525 case CTDB_CONTROL_GET_NODES_FILE:
1526 ctdb_node_map_push(cd->data.nodemap, buf, &np);
1527 break;
1529 case CTDB_CONTROL_DB_PULL:
1530 ctdb_uint32_push(&cd->data.num_records, buf, &np);
1531 break;
1533 case CTDB_CONTROL_DB_PUSH_CONFIRM:
1534 ctdb_uint32_push(&cd->data.num_records, buf, &np);
1535 break;
1537 case CTDB_CONTROL_DB_OPEN_FLAGS:
1538 ctdb_int32_push(&cd->data.tdb_flags, buf, &np);
1539 break;
1541 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1542 ctdb_uint32_push(&cd->data.db_id, buf, &np);
1543 break;
1545 case CTDB_CONTROL_CHECK_PID_SRVID:
1546 break;
1548 case CTDB_CONTROL_VACUUM_FETCH:
1549 break;
1551 case CTDB_CONTROL_DB_VACUUM:
1552 break;
1554 case CTDB_CONTROL_ECHO_DATA:
1555 ctdb_echo_data_push(cd->data.echo_data, buf, &np);
1556 break;
1559 *npush = np;
1562 static int ctdb_reply_control_data_pull(uint8_t *buf, size_t buflen,
1563 uint32_t opcode, TALLOC_CTX *mem_ctx,
1564 struct ctdb_reply_control_data *cd,
1565 size_t *npull)
1567 size_t np = 0;
1568 int ret = 0;
1570 cd->opcode = opcode;
1572 switch (opcode) {
1573 case CTDB_CONTROL_STATISTICS:
1574 ret = ctdb_statistics_pull(buf, buflen, mem_ctx,
1575 &cd->data.stats, &np);
1576 break;
1578 case CTDB_CONTROL_GETDBPATH:
1579 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1580 &cd->data.db_path, &np);
1581 break;
1583 case CTDB_CONTROL_GETVNNMAP:
1584 ret = ctdb_vnn_map_pull(buf, buflen, mem_ctx,
1585 &cd->data.vnnmap, &np);
1586 break;
1588 case CTDB_CONTROL_GET_DEBUG:
1589 ret = ctdb_uint32_pull(buf, buflen, &cd->data.loglevel, &np);
1590 break;
1592 case CTDB_CONTROL_GET_DBMAP:
1593 ret = ctdb_dbid_map_pull(buf, buflen, mem_ctx,
1594 &cd->data.dbmap, &np);
1595 break;
1597 case CTDB_CONTROL_DB_ATTACH:
1598 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1599 break;
1601 case CTDB_CONTROL_GET_DBNAME:
1602 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1603 &cd->data.db_name, &np);
1604 break;
1606 case CTDB_CONTROL_DUMP_MEMORY:
1607 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1608 &cd->data.mem_str, &np);
1609 break;
1611 case CTDB_CONTROL_GET_PID:
1612 break;
1614 case CTDB_CONTROL_GET_RECMASTER:
1615 break;
1617 case CTDB_CONTROL_GET_TUNABLE:
1618 ret = ctdb_uint32_pull(buf, buflen, &cd->data.tun_value,
1619 &np);
1620 break;
1622 case CTDB_CONTROL_LIST_TUNABLES:
1623 ret = ctdb_var_list_pull(buf, buflen, mem_ctx,
1624 &cd->data.tun_var_list, &np);
1625 break;
1627 case CTDB_CONTROL_GET_ALL_TUNABLES:
1628 ret = ctdb_tunable_list_pull(buf, buflen, mem_ctx,
1629 &cd->data.tun_list, &np);
1630 break;
1632 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1633 ret = ctdb_tickle_list_pull(buf, buflen, mem_ctx,
1634 &cd->data.tickles, &np);
1635 break;
1637 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1638 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1639 break;
1641 case CTDB_CONTROL_UPTIME:
1642 ret = ctdb_uptime_pull(buf, buflen, mem_ctx,
1643 &cd->data.uptime, &np);
1644 break;
1646 case CTDB_CONTROL_TRY_DELETE_RECORDS:
1647 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
1648 &cd->data.recbuf, &np);
1649 break;
1651 case CTDB_CONTROL_GET_CAPABILITIES:
1652 ret = ctdb_uint32_pull(buf, buflen, &cd->data.caps, &np);
1653 break;
1655 case CTDB_CONTROL_GET_PUBLIC_IPS:
1656 ret = ctdb_public_ip_list_pull(buf, buflen, mem_ctx,
1657 &cd->data.pubip_list, &np);
1658 break;
1660 case CTDB_CONTROL_GET_NODEMAP:
1661 ret = ctdb_node_map_pull(buf, buflen, mem_ctx,
1662 &cd->data.nodemap, &np);
1663 break;
1665 case CTDB_CONTROL_GET_RECLOCK_FILE:
1666 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1667 &cd->data.reclock_file, &np);
1668 break;
1670 case CTDB_CONTROL_GET_BAN_STATE:
1671 ret = ctdb_ban_state_pull(buf, buflen, mem_ctx,
1672 &cd->data.ban_state, &np);
1673 break;
1675 case CTDB_CONTROL_GET_DB_SEQNUM:
1676 ret = ctdb_uint64_pull(buf, buflen, &cd->data.seqnum, &np);
1677 break;
1679 case CTDB_CONTROL_DB_GET_HEALTH:
1680 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1681 &cd->data.reason, &np);
1682 break;
1684 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1685 ret = ctdb_public_ip_info_pull(buf, buflen, mem_ctx,
1686 &cd->data.ipinfo, &np);
1687 break;
1689 case CTDB_CONTROL_GET_IFACES:
1690 ret = ctdb_iface_list_pull(buf, buflen, mem_ctx,
1691 &cd->data.iface_list, &np);
1692 break;
1694 case CTDB_CONTROL_GET_STAT_HISTORY:
1695 ret = ctdb_statistics_list_pull(buf, buflen, mem_ctx,
1696 &cd->data.stats_list, &np);
1697 break;
1699 case CTDB_CONTROL_GET_DB_STATISTICS:
1700 ret = ctdb_db_statistics_pull(buf, buflen, mem_ctx,
1701 &cd->data.dbstats, &np);
1702 break;
1704 case CTDB_CONTROL_GET_RUNSTATE:
1705 ret = ctdb_uint32_pull(buf, buflen, &cd->data.runstate, &np);
1706 break;
1708 case CTDB_CONTROL_GET_NODES_FILE:
1709 ret = ctdb_node_map_pull(buf, buflen, mem_ctx,
1710 &cd->data.nodemap, &np);
1711 break;
1713 case CTDB_CONTROL_DB_PULL:
1714 ret = ctdb_uint32_pull(buf, buflen, &cd->data.num_records,
1715 &np);
1716 break;
1718 case CTDB_CONTROL_DB_PUSH_CONFIRM:
1719 ret = ctdb_uint32_pull(buf, buflen, &cd->data.num_records,
1720 &np);
1721 break;
1723 case CTDB_CONTROL_DB_OPEN_FLAGS:
1724 ret = ctdb_int32_pull(buf, buflen, &cd->data.tdb_flags, &np);
1725 break;
1727 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1728 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1729 break;
1731 case CTDB_CONTROL_CHECK_PID_SRVID:
1732 break;
1734 case CTDB_CONTROL_VACUUM_FETCH:
1735 break;
1737 case CTDB_CONTROL_DB_VACUUM:
1738 break;
1740 case CTDB_CONTROL_ECHO_DATA:
1741 ret = ctdb_echo_data_pull(buf,
1742 buflen,
1743 mem_ctx,
1744 &cd->data.echo_data,
1745 &np);
1746 break;
1749 if (ret != 0) {
1750 return ret;
1753 *npull = np;
1754 return 0;
1757 size_t ctdb_req_control_len(struct ctdb_req_header *h,
1758 struct ctdb_req_control *c)
1760 uint32_t u32 = 0;
1762 return ctdb_req_header_len(h) +
1763 ctdb_uint32_len(&c->opcode) +
1764 ctdb_uint32_len(&c->pad) +
1765 ctdb_uint64_len(&c->srvid) +
1766 ctdb_uint32_len(&c->client_id) +
1767 ctdb_uint32_len(&c->flags) +
1768 ctdb_uint32_len(&u32) +
1769 ctdb_req_control_data_len(&c->rdata);
1772 int ctdb_req_control_push(struct ctdb_req_header *h,
1773 struct ctdb_req_control *c,
1774 uint8_t *buf, size_t *buflen)
1776 size_t offset = 0, np;
1777 size_t length;
1778 uint32_t u32;
1780 length = ctdb_req_control_len(h, c);
1781 if (*buflen < length) {
1782 *buflen = length;
1783 return EMSGSIZE;
1786 h->length = *buflen;
1787 ctdb_req_header_push(h, buf+offset, &np);
1788 offset += np;
1790 ctdb_uint32_push(&c->opcode, buf+offset, &np);
1791 offset += np;
1793 ctdb_uint32_push(&c->pad, buf+offset, &np);
1794 offset += np;
1796 ctdb_uint64_push(&c->srvid, buf+offset, &np);
1797 offset += np;
1799 ctdb_uint32_push(&c->client_id, buf+offset, &np);
1800 offset += np;
1802 ctdb_uint32_push(&c->flags, buf+offset, &np);
1803 offset += np;
1805 u32 = ctdb_req_control_data_len(&c->rdata);
1806 ctdb_uint32_push(&u32, buf+offset, &np);
1807 offset += np;
1809 ctdb_req_control_data_push(&c->rdata, buf+offset, &np);
1810 offset += np;
1812 if (offset > *buflen) {
1813 return EMSGSIZE;
1816 return 0;
1819 int ctdb_req_control_pull(uint8_t *buf, size_t buflen,
1820 struct ctdb_req_header *h,
1821 TALLOC_CTX *mem_ctx,
1822 struct ctdb_req_control *c)
1824 struct ctdb_req_header header;
1825 size_t offset = 0, np;
1826 uint32_t u32;
1827 int ret;
1829 ret = ctdb_req_header_pull(buf+offset, buflen-offset, &header, &np);
1830 if (ret != 0) {
1831 return ret;
1833 offset += np;
1835 if (h != NULL) {
1836 *h = header;
1839 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->opcode, &np);
1840 if (ret != 0) {
1841 return ret;
1843 offset += np;
1845 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->pad, &np);
1846 if (ret != 0) {
1847 return ret;
1849 offset += np;
1851 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &c->srvid, &np);
1852 if (ret != 0) {
1853 return ret;
1855 offset += np;
1857 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->client_id, &np);
1858 if (ret != 0) {
1859 return ret;
1861 offset += np;
1863 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->flags, &np);
1864 if (ret != 0) {
1865 return ret;
1867 offset += np;
1869 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
1870 if (ret != 0) {
1871 return ret;
1873 offset += np;
1875 if (u32 > buflen-offset) {
1876 return EMSGSIZE;
1879 ret = ctdb_req_control_data_pull(buf+offset, u32, c->opcode, mem_ctx,
1880 &c->rdata, &np);
1881 if (ret != 0) {
1882 return ret;
1884 offset += np;
1886 if (offset > buflen) {
1887 return EMSGSIZE;
1890 return 0;
1893 size_t ctdb_reply_control_len(struct ctdb_req_header *h,
1894 struct ctdb_reply_control *c)
1896 uint32_t dsize, esize;
1898 if (c->status == 0) {
1899 dsize = ctdb_reply_control_data_len(&c->rdata);
1900 esize = 0;
1901 } else {
1902 dsize = 0;
1903 esize = ctdb_string_len(&c->errmsg);
1906 return ctdb_req_header_len(h) +
1907 ctdb_int32_len(&c->status) +
1908 ctdb_uint32_len(&dsize) +
1909 ctdb_uint32_len(&esize) +
1910 dsize + esize;
1913 int ctdb_reply_control_push(struct ctdb_req_header *h,
1914 struct ctdb_reply_control *c,
1915 uint8_t *buf, size_t *buflen)
1917 size_t offset = 0, np;
1918 size_t length;
1919 uint32_t dsize, esize;
1921 length = ctdb_reply_control_len(h, c);
1922 if (*buflen < length) {
1923 *buflen = length;
1924 return EMSGSIZE;
1927 h->length = *buflen;
1928 ctdb_req_header_push(h, buf+offset, &np);
1929 offset += np;
1931 ctdb_int32_push(&c->status, buf+offset, &np);
1932 offset += np;
1934 if (c->status == 0) {
1935 dsize = ctdb_reply_control_data_len(&c->rdata);
1936 esize = 0;
1937 } else {
1938 dsize = 0;
1939 esize = ctdb_string_len(&c->errmsg);
1942 ctdb_uint32_push(&dsize, buf+offset, &np);
1943 offset += np;
1945 ctdb_uint32_push(&esize, buf+offset, &np);
1946 offset += np;
1948 if (c->status == 0) {
1949 ctdb_reply_control_data_push(&c->rdata, buf+offset, &np);
1950 } else {
1951 ctdb_string_push(&c->errmsg, buf+offset, &np);
1953 offset += np;
1955 return 0;
1958 int ctdb_reply_control_pull(uint8_t *buf, size_t buflen, uint32_t opcode,
1959 struct ctdb_req_header *h,
1960 TALLOC_CTX *mem_ctx,
1961 struct ctdb_reply_control *c)
1963 struct ctdb_req_header header;
1964 size_t offset = 0, np;
1965 uint32_t dsize, esize;
1966 int ret;
1968 ret = ctdb_req_header_pull(buf+offset, buflen-offset, &header, &np);
1969 if (ret != 0) {
1970 return ret;
1972 offset += np;
1974 if (h != NULL) {
1975 *h = header;
1978 ret = ctdb_int32_pull(buf+offset, buflen-offset, &c->status, &np);
1979 if (ret != 0) {
1980 return ret;
1982 offset += np;
1984 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &dsize, &np);
1985 if (ret != 0) {
1986 return ret;
1988 offset += np;
1990 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &esize, &np);
1991 if (ret != 0) {
1992 return ret;
1994 offset += np;
1996 c->errmsg = NULL;
1998 if (c->status == 0) {
1999 if (buflen-offset < dsize) {
2000 return EMSGSIZE;
2003 ret = ctdb_reply_control_data_pull(buf+offset, dsize,
2004 opcode, mem_ctx, &c->rdata,
2005 &np);
2006 if (ret != 0) {
2007 return ret;
2009 offset += np;
2011 } else {
2012 if (buflen-offset < esize) {
2013 return EMSGSIZE;
2016 ret = ctdb_string_pull(buf+offset, esize, mem_ctx, &c->errmsg,
2017 &np);
2018 if (ret != 0) {
2019 return ret;
2021 offset += np;
2024 return 0;