lib:crypto: Fix Coverity build
[Samba.git] / ctdb / protocol / protocol_control.c
blob8b8de1a81e3d17324a3f19c642edbb55dfc492ef
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_FREEZE:
122 break;
124 case CTDB_CONTROL_GET_PNN:
125 break;
127 case CTDB_CONTROL_SHUTDOWN:
128 break;
130 case CTDB_CONTROL_TCP_CLIENT:
131 len = ctdb_connection_len(cd->data.conn);
132 break;
134 case CTDB_CONTROL_TCP_ADD:
135 len = ctdb_connection_len(cd->data.conn);
136 break;
138 case CTDB_CONTROL_TCP_REMOVE:
139 len = ctdb_connection_len(cd->data.conn);
140 break;
142 case CTDB_CONTROL_STARTUP:
143 break;
145 case CTDB_CONTROL_SET_TUNABLE:
146 len = ctdb_tunable_len(cd->data.tunable);
147 break;
149 case CTDB_CONTROL_GET_TUNABLE:
150 len = ctdb_stringn_len(&cd->data.tun_var);
151 break;
153 case CTDB_CONTROL_LIST_TUNABLES:
154 break;
156 case CTDB_CONTROL_MODIFY_FLAGS:
157 len = ctdb_node_flag_change_len(cd->data.flag_change);
158 break;
160 case CTDB_CONTROL_GET_ALL_TUNABLES:
161 break;
163 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
164 len = ctdb_sock_addr_len(cd->data.addr);
165 break;
167 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
168 len = ctdb_tickle_list_len(cd->data.tickles);
169 break;
171 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
172 len = ctdb_string_len(&cd->data.db_name);
173 break;
175 case CTDB_CONTROL_UPDATE_RECORD:
176 len = ctdb_rec_buffer_len(cd->data.recbuf);
177 break;
179 case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
180 len = ctdb_addr_info_len(cd->data.addr_info);
181 break;
183 case CTDB_CONTROL_WIPE_DATABASE:
184 len = ctdb_transdb_len(cd->data.transdb);
185 break;
187 case CTDB_CONTROL_UPTIME:
188 break;
190 case CTDB_CONTROL_START_RECOVERY:
191 break;
193 case CTDB_CONTROL_END_RECOVERY:
194 break;
196 case CTDB_CONTROL_RELOAD_NODES_FILE:
197 break;
199 case CTDB_CONTROL_TRY_DELETE_RECORDS:
200 len = ctdb_rec_buffer_len(cd->data.recbuf);
201 break;
203 case CTDB_CONTROL_ADD_PUBLIC_IP:
204 len = ctdb_addr_info_len(cd->data.addr_info);
205 break;
207 case CTDB_CONTROL_DEL_PUBLIC_IP:
208 len = ctdb_addr_info_len(cd->data.addr_info);
209 break;
211 case CTDB_CONTROL_GET_CAPABILITIES:
212 break;
214 case CTDB_CONTROL_RECD_PING:
215 break;
217 case CTDB_CONTROL_RELEASE_IP:
218 len = ctdb_public_ip_len(cd->data.pubip);
219 break;
221 case CTDB_CONTROL_TAKEOVER_IP:
222 len = ctdb_public_ip_len(cd->data.pubip);
223 break;
225 case CTDB_CONTROL_GET_PUBLIC_IPS:
226 break;
228 case CTDB_CONTROL_GET_NODEMAP:
229 break;
231 case CTDB_CONTROL_TRAVERSE_KILL:
232 len = ctdb_traverse_start_len(cd->data.traverse_start);
233 break;
235 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
236 len = ctdb_double_len(&cd->data.reclock_latency);
237 break;
239 case CTDB_CONTROL_GET_RECLOCK_FILE:
240 break;
242 case CTDB_CONTROL_STOP_NODE:
243 break;
245 case CTDB_CONTROL_CONTINUE_NODE:
246 break;
248 case CTDB_CONTROL_SET_LMASTERROLE:
249 len = ctdb_uint32_len(&cd->data.role);
250 break;
252 case CTDB_CONTROL_SET_RECMASTERROLE:
253 len = ctdb_uint32_len(&cd->data.role);
254 break;
256 case CTDB_CONTROL_SET_BAN_STATE:
257 len = ctdb_ban_state_len(cd->data.ban_state);
258 break;
260 case CTDB_CONTROL_GET_BAN_STATE:
261 break;
263 case CTDB_CONTROL_REGISTER_NOTIFY:
264 len = ctdb_notify_data_len(cd->data.notify);
265 break;
267 case CTDB_CONTROL_DEREGISTER_NOTIFY:
268 len = ctdb_uint64_len(&cd->data.srvid);
269 break;
271 case CTDB_CONTROL_TRANS3_COMMIT:
272 len = ctdb_rec_buffer_len(cd->data.recbuf);
273 break;
275 case CTDB_CONTROL_GET_DB_SEQNUM:
276 u32 = 0;
277 len = ctdb_uint32_len(&cd->data.db_id) + ctdb_uint32_len(&u32);
278 break;
280 case CTDB_CONTROL_DB_SET_HEALTHY:
281 len = ctdb_uint32_len(&cd->data.db_id);
282 break;
284 case CTDB_CONTROL_DB_GET_HEALTH:
285 len = ctdb_uint32_len(&cd->data.db_id);
286 break;
288 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
289 len = ctdb_sock_addr_len(cd->data.addr);
290 break;
292 case CTDB_CONTROL_GET_IFACES:
293 break;
295 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
296 len = ctdb_iface_len(cd->data.iface);
297 break;
299 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
300 len = ctdb_connection_len(cd->data.conn);
301 break;
303 case CTDB_CONTROL_GET_STAT_HISTORY:
304 break;
306 case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
307 len = ctdb_key_data_len(cd->data.key);
308 break;
310 case CTDB_CONTROL_SET_DB_READONLY:
311 len = ctdb_uint32_len(&cd->data.db_id);
312 break;
314 case CTDB_CONTROL_TRAVERSE_START_EXT:
315 len = ctdb_traverse_start_ext_len(cd->data.traverse_start_ext);
316 break;
318 case CTDB_CONTROL_GET_DB_STATISTICS:
319 len = ctdb_uint32_len(&cd->data.db_id);
320 break;
322 case CTDB_CONTROL_SET_DB_STICKY:
323 len = ctdb_uint32_len(&cd->data.db_id);
324 break;
326 case CTDB_CONTROL_RELOAD_PUBLIC_IPS:
327 break;
329 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
330 len = ctdb_traverse_all_ext_len(cd->data.traverse_all_ext);
331 break;
333 case CTDB_CONTROL_IPREALLOCATED:
334 break;
336 case CTDB_CONTROL_GET_RUNSTATE:
337 break;
339 case CTDB_CONTROL_DB_DETACH:
340 len = ctdb_uint32_len(&cd->data.db_id);
341 break;
343 case CTDB_CONTROL_GET_NODES_FILE:
344 break;
346 case CTDB_CONTROL_DB_FREEZE:
347 len = ctdb_uint32_len(&cd->data.db_id);
348 break;
350 case CTDB_CONTROL_DB_THAW:
351 len = ctdb_uint32_len(&cd->data.db_id);
352 break;
354 case CTDB_CONTROL_DB_TRANSACTION_START:
355 len = ctdb_transdb_len(cd->data.transdb);
356 break;
358 case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
359 len = ctdb_transdb_len(cd->data.transdb);
360 break;
362 case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
363 len = ctdb_uint32_len(&cd->data.db_id);
364 break;
366 case CTDB_CONTROL_DB_PULL:
367 len = ctdb_pulldb_ext_len(cd->data.pulldb_ext);
368 break;
370 case CTDB_CONTROL_DB_PUSH_START:
371 len = ctdb_pulldb_ext_len(cd->data.pulldb_ext);
372 break;
374 case CTDB_CONTROL_DB_PUSH_CONFIRM:
375 len = ctdb_uint32_len(&cd->data.db_id);
376 break;
378 case CTDB_CONTROL_DB_OPEN_FLAGS:
379 len = ctdb_uint32_len(&cd->data.db_id);
380 break;
382 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
383 len = ctdb_string_len(&cd->data.db_name);
384 break;
386 case CTDB_CONTROL_CHECK_PID_SRVID:
387 len = ctdb_pid_srvid_len(cd->data.pid_srvid);
388 break;
390 case CTDB_CONTROL_TUNNEL_REGISTER:
391 break;
393 case CTDB_CONTROL_TUNNEL_DEREGISTER:
394 break;
396 case CTDB_CONTROL_VACUUM_FETCH:
397 len = ctdb_rec_buffer_len(cd->data.recbuf);
398 break;
400 case CTDB_CONTROL_DB_VACUUM:
401 len = ctdb_db_vacuum_len(cd->data.db_vacuum);
402 break;
404 case CTDB_CONTROL_ECHO_DATA:
405 len = ctdb_echo_data_len(cd->data.echo_data);
406 break;
408 case CTDB_CONTROL_DISABLE_NODE:
409 break;
411 case CTDB_CONTROL_ENABLE_NODE:
412 break;
414 case CTDB_CONTROL_TCP_CLIENT_DISCONNECTED:
415 len = ctdb_connection_len(cd->data.conn);
416 break;
418 case CTDB_CONTROL_TCP_CLIENT_PASSED:
419 len = ctdb_connection_len(cd->data.conn);
420 break;
422 case CTDB_CONTROL_START_IPREALLOCATE:
423 break;
426 return len;
429 static void ctdb_req_control_data_push(struct ctdb_req_control_data *cd,
430 uint8_t *buf, size_t *npush)
432 size_t np = 0, offset;
433 uint32_t u32;
435 switch (cd->opcode) {
436 case CTDB_CONTROL_PROCESS_EXISTS:
437 ctdb_pid_push(&cd->data.pid, buf, &np);
438 break;
440 case CTDB_CONTROL_GETDBPATH:
441 ctdb_uint32_push(&cd->data.db_id, buf, &np);
442 break;
444 case CTDB_CONTROL_SETVNNMAP:
445 ctdb_vnn_map_push(cd->data.vnnmap, buf, &np);
446 break;
448 case CTDB_CONTROL_SET_DEBUG:
449 ctdb_uint32_push(&cd->data.loglevel, buf, &np);
450 break;
452 case CTDB_CONTROL_SET_RECMODE:
453 ctdb_uint32_push(&cd->data.recmode, buf, &np);
454 break;
456 case CTDB_CONTROL_DB_ATTACH:
457 ctdb_string_push(&cd->data.db_name, buf, &np);
458 break;
460 case CTDB_CONTROL_TRAVERSE_START:
461 ctdb_traverse_start_push(cd->data.traverse_start, buf, &np);
462 break;
464 case CTDB_CONTROL_TRAVERSE_ALL:
465 ctdb_traverse_all_push(cd->data.traverse_all, buf, &np);
466 break;
468 case CTDB_CONTROL_TRAVERSE_DATA:
469 ctdb_rec_data_push(cd->data.rec_data, buf, &np);
470 break;
472 case CTDB_CONTROL_GET_DBNAME:
473 ctdb_uint32_push(&cd->data.db_id, buf, &np);
474 break;
476 case CTDB_CONTROL_ENABLE_SEQNUM:
477 ctdb_uint32_push(&cd->data.db_id, buf, &np);
478 break;
480 case CTDB_CONTROL_UPDATE_SEQNUM:
481 ctdb_uint32_push(&cd->data.db_id, 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;
700 case CTDB_CONTROL_TCP_CLIENT_DISCONNECTED:
701 ctdb_connection_push(cd->data.conn, buf, &np);
702 break;
704 case CTDB_CONTROL_TCP_CLIENT_PASSED:
705 ctdb_connection_push(cd->data.conn, buf, &np);
706 break;
709 *npush = np;
712 static int ctdb_req_control_data_pull(uint8_t *buf, size_t buflen,
713 uint32_t opcode,
714 TALLOC_CTX *mem_ctx,
715 struct ctdb_req_control_data *cd,
716 size_t *npull)
718 size_t np = 0, offset;
719 uint32_t u32;
720 int ret = 0;
722 cd->opcode = opcode;
724 switch (opcode) {
725 case CTDB_CONTROL_PROCESS_EXISTS:
726 ret = ctdb_pid_pull(buf, buflen, &cd->data.pid, &np);
727 break;
729 case CTDB_CONTROL_GETDBPATH:
730 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
731 break;
733 case CTDB_CONTROL_SETVNNMAP:
734 ret = ctdb_vnn_map_pull(buf, buflen, mem_ctx,
735 &cd->data.vnnmap, &np);
736 break;
738 case CTDB_CONTROL_SET_DEBUG:
739 ret = ctdb_uint32_pull(buf, buflen, &cd->data.loglevel, &np);
740 break;
742 case CTDB_CONTROL_SET_RECMODE:
743 ret = ctdb_uint32_pull(buf, buflen, &cd->data.recmode, &np);
744 break;
746 case CTDB_CONTROL_DB_ATTACH:
747 ret = ctdb_string_pull(buf, buflen, mem_ctx,
748 &cd->data.db_name, &np);
749 break;
751 case CTDB_CONTROL_TRAVERSE_START:
752 ret = ctdb_traverse_start_pull(buf, buflen, mem_ctx,
753 &cd->data.traverse_start, &np);
754 break;
756 case CTDB_CONTROL_TRAVERSE_ALL:
757 ret = ctdb_traverse_all_pull(buf, buflen, mem_ctx,
758 &cd->data.traverse_all, &np);
759 break;
761 case CTDB_CONTROL_TRAVERSE_DATA:
762 ret = ctdb_rec_data_pull(buf, buflen, mem_ctx,
763 &cd->data.rec_data, &np);
764 break;
766 case CTDB_CONTROL_GET_DBNAME:
767 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
768 break;
770 case CTDB_CONTROL_ENABLE_SEQNUM:
771 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
772 break;
774 case CTDB_CONTROL_UPDATE_SEQNUM:
775 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
776 break;
778 case CTDB_CONTROL_TCP_CLIENT:
779 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
780 &cd->data.conn, &np);
781 break;
783 case CTDB_CONTROL_TCP_ADD:
784 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
785 &cd->data.conn, &np);
786 break;
788 case CTDB_CONTROL_TCP_REMOVE:
789 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
790 &cd->data.conn, &np);
791 break;
793 case CTDB_CONTROL_SET_TUNABLE:
794 ret = ctdb_tunable_pull(buf, buflen, mem_ctx,
795 &cd->data.tunable, &np);
796 break;
798 case CTDB_CONTROL_GET_TUNABLE:
799 ret = ctdb_stringn_pull(buf, buflen, mem_ctx,
800 &cd->data.tun_var, &np);
801 break;
803 case CTDB_CONTROL_MODIFY_FLAGS:
804 ret = ctdb_node_flag_change_pull(buf, buflen, mem_ctx,
805 &cd->data.flag_change, &np);
806 break;
808 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
809 ret = ctdb_sock_addr_pull(buf, buflen, mem_ctx,
810 &cd->data.addr, &np);
811 break;
813 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
814 ret = ctdb_tickle_list_pull(buf, buflen, mem_ctx,
815 &cd->data.tickles, &np);
816 break;
818 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
819 ret = ctdb_string_pull(buf, buflen, mem_ctx,
820 &cd->data.db_name, &np);
821 break;
823 case CTDB_CONTROL_UPDATE_RECORD:
824 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
825 &cd->data.recbuf, &np);
826 break;
828 case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
829 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
830 &cd->data.addr_info, &np);
831 break;
833 case CTDB_CONTROL_WIPE_DATABASE:
834 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
835 &cd->data.transdb, &np);
836 break;
838 case CTDB_CONTROL_TRY_DELETE_RECORDS:
839 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
840 &cd->data.recbuf, &np);
841 break;
843 case CTDB_CONTROL_ADD_PUBLIC_IP:
844 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
845 &cd->data.addr_info, &np);
846 break;
848 case CTDB_CONTROL_DEL_PUBLIC_IP:
849 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
850 &cd->data.addr_info, &np);
851 break;
853 case CTDB_CONTROL_RELEASE_IP:
854 ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
855 &cd->data.pubip, &np);
856 break;
858 case CTDB_CONTROL_TAKEOVER_IP:
859 ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
860 &cd->data.pubip, &np);
861 break;
863 case CTDB_CONTROL_TRAVERSE_KILL:
864 ret = ctdb_traverse_start_pull(buf, buflen, mem_ctx,
865 &cd->data.traverse_start, &np);
866 break;
868 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
869 ret = ctdb_double_pull(buf, buflen, &cd->data.reclock_latency,
870 &np);
871 break;
873 case CTDB_CONTROL_SET_LMASTERROLE:
874 ret = ctdb_uint32_pull(buf, buflen, &cd->data.role, &np);
875 break;
877 case CTDB_CONTROL_SET_RECMASTERROLE:
878 ret = ctdb_uint32_pull(buf, buflen, &cd->data.role, &np);
879 break;
881 case CTDB_CONTROL_SET_BAN_STATE:
882 ret = ctdb_ban_state_pull(buf, buflen, mem_ctx,
883 &cd->data.ban_state, &np);
884 break;
886 case CTDB_CONTROL_REGISTER_NOTIFY:
887 ret = ctdb_notify_data_pull(buf, buflen, mem_ctx,
888 &cd->data.notify, &np);
889 break;
891 case CTDB_CONTROL_DEREGISTER_NOTIFY:
892 ret = ctdb_uint64_pull(buf, buflen, &cd->data.srvid, &np);
893 break;
895 case CTDB_CONTROL_TRANS3_COMMIT:
896 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
897 &cd->data.recbuf, &np);
898 break;
900 case CTDB_CONTROL_GET_DB_SEQNUM:
901 offset = 0;
902 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
903 if (ret != 0) {
904 break;
906 offset += np;
907 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
908 offset += np;
909 np = offset;
910 break;
912 case CTDB_CONTROL_DB_SET_HEALTHY:
913 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
914 break;
916 case CTDB_CONTROL_DB_GET_HEALTH:
917 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
918 break;
920 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
921 ret = ctdb_sock_addr_pull(buf, buflen, mem_ctx,
922 &cd->data.addr, &np);
923 break;
925 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
926 ret = ctdb_iface_pull(buf, buflen, mem_ctx,
927 &cd->data.iface, &np);
928 break;
930 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
931 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
932 &cd->data.conn, &np);
933 break;
935 case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
936 ret = ctdb_key_data_pull(buf, buflen, mem_ctx,
937 &cd->data.key, &np);
938 break;
940 case CTDB_CONTROL_SET_DB_READONLY:
941 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
942 break;
944 case CTDB_CONTROL_TRAVERSE_START_EXT:
945 ret = ctdb_traverse_start_ext_pull(buf, buflen, mem_ctx,
946 &cd->data.traverse_start_ext,
947 &np);
948 break;
950 case CTDB_CONTROL_GET_DB_STATISTICS:
951 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
952 break;
954 case CTDB_CONTROL_SET_DB_STICKY:
955 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
956 break;
958 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
959 ret = ctdb_traverse_all_ext_pull(buf, buflen, mem_ctx,
960 &cd->data.traverse_all_ext,
961 &np);
962 break;
964 case CTDB_CONTROL_DB_DETACH:
965 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
966 break;
968 case CTDB_CONTROL_DB_FREEZE:
969 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
970 break;
972 case CTDB_CONTROL_DB_THAW:
973 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
974 break;
976 case CTDB_CONTROL_DB_TRANSACTION_START:
977 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
978 &cd->data.transdb, &np);
979 break;
981 case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
982 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
983 &cd->data.transdb, &np);
984 break;
986 case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
987 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
988 break;
990 case CTDB_CONTROL_DB_PULL:
991 ret = ctdb_pulldb_ext_pull(buf, buflen, mem_ctx,
992 &cd->data.pulldb_ext, &np);
993 break;
995 case CTDB_CONTROL_DB_PUSH_START:
996 ret = ctdb_pulldb_ext_pull(buf, buflen, mem_ctx,
997 &cd->data.pulldb_ext, &np);
998 break;
1000 case CTDB_CONTROL_DB_PUSH_CONFIRM:
1001 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1002 break;
1004 case CTDB_CONTROL_DB_OPEN_FLAGS:
1005 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1006 break;
1008 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1009 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1010 &cd->data.db_name, &np);
1011 break;
1013 case CTDB_CONTROL_CHECK_PID_SRVID:
1014 ret = ctdb_pid_srvid_pull(buf, buflen, mem_ctx,
1015 &cd->data.pid_srvid, &np);
1016 break;
1018 case CTDB_CONTROL_VACUUM_FETCH:
1019 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
1020 &cd->data.recbuf, &np);
1021 break;
1023 case CTDB_CONTROL_DB_VACUUM:
1024 ret = ctdb_db_vacuum_pull(buf,
1025 buflen,
1026 mem_ctx,
1027 &cd->data.db_vacuum,
1028 &np);
1029 break;
1031 case CTDB_CONTROL_ECHO_DATA:
1032 ret = ctdb_echo_data_pull(buf,
1033 buflen,
1034 mem_ctx,
1035 &cd->data.echo_data,
1036 &np);
1037 break;
1039 case CTDB_CONTROL_TCP_CLIENT_DISCONNECTED:
1040 ret = ctdb_connection_pull(buf,
1041 buflen,
1042 mem_ctx,
1043 &cd->data.conn,
1044 &np);
1045 break;
1047 case CTDB_CONTROL_TCP_CLIENT_PASSED:
1048 ret = ctdb_connection_pull(buf,
1049 buflen,
1050 mem_ctx,
1051 &cd->data.conn,
1052 &np);
1053 break;
1056 if (ret != 0) {
1057 return ret;
1060 *npull = np;
1061 return 0;
1064 static size_t ctdb_reply_control_data_len(struct ctdb_reply_control_data *cd)
1066 size_t len = 0;
1068 if (cd == NULL) {
1069 return 0;
1072 switch (cd->opcode) {
1073 case CTDB_CONTROL_PROCESS_EXISTS:
1074 break;
1076 case CTDB_CONTROL_STATISTICS:
1077 len = ctdb_statistics_len(cd->data.stats);
1078 break;
1080 case CTDB_CONTROL_PING:
1081 break;
1083 case CTDB_CONTROL_GETDBPATH:
1084 len = ctdb_string_len(&cd->data.db_path);
1085 break;
1087 case CTDB_CONTROL_GETVNNMAP:
1088 len = ctdb_vnn_map_len(cd->data.vnnmap);
1089 break;
1091 case CTDB_CONTROL_SETVNNMAP:
1092 break;
1094 case CTDB_CONTROL_GET_DEBUG:
1095 len = ctdb_uint32_len(&cd->data.loglevel);
1096 break;
1098 case CTDB_CONTROL_SET_DEBUG:
1099 break;
1101 case CTDB_CONTROL_GET_DBMAP:
1102 len = ctdb_dbid_map_len(cd->data.dbmap);
1103 break;
1105 case CTDB_CONTROL_GET_RECMODE:
1106 break;
1108 case CTDB_CONTROL_SET_RECMODE:
1109 break;
1111 case CTDB_CONTROL_STATISTICS_RESET:
1112 break;
1114 case CTDB_CONTROL_DB_ATTACH:
1115 len = ctdb_uint32_len(&cd->data.db_id);
1116 break;
1118 case CTDB_CONTROL_TRAVERSE_START:
1119 break;
1121 case CTDB_CONTROL_TRAVERSE_ALL:
1122 break;
1124 case CTDB_CONTROL_TRAVERSE_DATA:
1125 break;
1127 case CTDB_CONTROL_REGISTER_SRVID:
1128 break;
1130 case CTDB_CONTROL_DEREGISTER_SRVID:
1131 break;
1133 case CTDB_CONTROL_GET_DBNAME:
1134 len = ctdb_string_len(&cd->data.db_name);
1135 break;
1137 case CTDB_CONTROL_ENABLE_SEQNUM:
1138 break;
1140 case CTDB_CONTROL_UPDATE_SEQNUM:
1141 break;
1143 case CTDB_CONTROL_DUMP_MEMORY:
1144 len = ctdb_string_len(&cd->data.mem_str);
1145 break;
1147 case CTDB_CONTROL_GET_PID:
1148 break;
1150 case CTDB_CONTROL_FREEZE:
1151 break;
1153 case CTDB_CONTROL_GET_PNN:
1154 break;
1156 case CTDB_CONTROL_SHUTDOWN:
1157 break;
1159 case CTDB_CONTROL_TCP_CLIENT:
1160 break;
1162 case CTDB_CONTROL_TCP_ADD:
1163 break;
1165 case CTDB_CONTROL_TCP_REMOVE:
1166 break;
1168 case CTDB_CONTROL_STARTUP:
1169 break;
1171 case CTDB_CONTROL_SET_TUNABLE:
1172 break;
1174 case CTDB_CONTROL_GET_TUNABLE:
1175 len = ctdb_uint32_len(&cd->data.tun_value);
1176 break;
1178 case CTDB_CONTROL_LIST_TUNABLES:
1179 len = ctdb_var_list_len(cd->data.tun_var_list);
1180 break;
1182 case CTDB_CONTROL_MODIFY_FLAGS:
1183 break;
1185 case CTDB_CONTROL_GET_ALL_TUNABLES:
1186 len = ctdb_tunable_list_len(cd->data.tun_list);
1187 break;
1189 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1190 len = ctdb_tickle_list_len(cd->data.tickles);
1191 break;
1193 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
1194 break;
1196 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1197 len = ctdb_uint32_len(&cd->data.db_id);
1198 break;
1200 case CTDB_CONTROL_UPDATE_RECORD:
1201 break;
1203 case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
1204 break;
1206 case CTDB_CONTROL_WIPE_DATABASE:
1207 break;
1209 case CTDB_CONTROL_UPTIME:
1210 len = ctdb_uptime_len(cd->data.uptime);
1211 break;
1213 case CTDB_CONTROL_START_RECOVERY:
1214 break;
1216 case CTDB_CONTROL_END_RECOVERY:
1217 break;
1219 case CTDB_CONTROL_RELOAD_NODES_FILE:
1220 break;
1222 case CTDB_CONTROL_TRY_DELETE_RECORDS:
1223 len = ctdb_rec_buffer_len(cd->data.recbuf);
1224 break;
1226 case CTDB_CONTROL_ADD_PUBLIC_IP:
1227 break;
1229 case CTDB_CONTROL_DEL_PUBLIC_IP:
1230 break;
1232 case CTDB_CONTROL_GET_CAPABILITIES:
1233 len = ctdb_uint32_len(&cd->data.caps);
1234 break;
1236 case CTDB_CONTROL_RECD_PING:
1237 break;
1239 case CTDB_CONTROL_RELEASE_IP:
1240 break;
1242 case CTDB_CONTROL_TAKEOVER_IP:
1243 break;
1245 case CTDB_CONTROL_GET_PUBLIC_IPS:
1246 len = ctdb_public_ip_list_len(cd->data.pubip_list);
1247 break;
1249 case CTDB_CONTROL_GET_NODEMAP:
1250 len = ctdb_node_map_len(cd->data.nodemap);
1251 break;
1253 case CTDB_CONTROL_TRAVERSE_KILL:
1254 break;
1256 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
1257 break;
1259 case CTDB_CONTROL_GET_RECLOCK_FILE:
1260 len = ctdb_string_len(&cd->data.reclock_file);
1261 break;
1263 case CTDB_CONTROL_STOP_NODE:
1264 break;
1266 case CTDB_CONTROL_CONTINUE_NODE:
1267 break;
1269 case CTDB_CONTROL_SET_LMASTERROLE:
1270 break;
1272 case CTDB_CONTROL_SET_RECMASTERROLE:
1273 break;
1275 case CTDB_CONTROL_SET_BAN_STATE:
1276 break;
1278 case CTDB_CONTROL_GET_BAN_STATE:
1279 len = ctdb_ban_state_len(cd->data.ban_state);
1280 break;
1282 case CTDB_CONTROL_REGISTER_NOTIFY:
1283 break;
1285 case CTDB_CONTROL_DEREGISTER_NOTIFY:
1286 break;
1288 case CTDB_CONTROL_TRANS3_COMMIT:
1289 break;
1291 case CTDB_CONTROL_GET_DB_SEQNUM:
1292 len = ctdb_uint64_len(&cd->data.seqnum);
1293 break;
1295 case CTDB_CONTROL_DB_SET_HEALTHY:
1296 break;
1298 case CTDB_CONTROL_DB_GET_HEALTH:
1299 len = ctdb_string_len(&cd->data.reason);
1300 break;
1302 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1303 len = ctdb_public_ip_info_len(cd->data.ipinfo);
1304 break;
1306 case CTDB_CONTROL_GET_IFACES:
1307 len = ctdb_iface_list_len(cd->data.iface_list);
1308 break;
1310 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
1311 break;
1313 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
1314 break;
1316 case CTDB_CONTROL_GET_STAT_HISTORY:
1317 len = ctdb_statistics_list_len(cd->data.stats_list);
1318 break;
1320 case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
1321 break;
1323 case CTDB_CONTROL_SET_DB_READONLY:
1324 break;
1326 case CTDB_CONTROL_TRAVERSE_START_EXT:
1327 break;
1329 case CTDB_CONTROL_GET_DB_STATISTICS:
1330 len = ctdb_db_statistics_len(cd->data.dbstats);
1331 break;
1333 case CTDB_CONTROL_SET_DB_STICKY:
1334 break;
1336 case CTDB_CONTROL_RELOAD_PUBLIC_IPS:
1337 break;
1339 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
1340 break;
1342 case CTDB_CONTROL_IPREALLOCATED:
1343 break;
1345 case CTDB_CONTROL_GET_RUNSTATE:
1346 len = ctdb_uint32_len(&cd->data.runstate);
1347 break;
1349 case CTDB_CONTROL_DB_DETACH:
1350 break;
1352 case CTDB_CONTROL_GET_NODES_FILE:
1353 len = ctdb_node_map_len(cd->data.nodemap);
1354 break;
1356 case CTDB_CONTROL_DB_FREEZE:
1357 break;
1359 case CTDB_CONTROL_DB_THAW:
1360 break;
1362 case CTDB_CONTROL_DB_TRANSACTION_START:
1363 break;
1365 case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
1366 break;
1368 case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
1369 break;
1371 case CTDB_CONTROL_DB_PULL:
1372 len = ctdb_uint32_len(&cd->data.num_records);
1373 break;
1375 case CTDB_CONTROL_DB_PUSH_START:
1376 break;
1378 case CTDB_CONTROL_DB_PUSH_CONFIRM:
1379 len = ctdb_uint32_len(&cd->data.num_records);
1380 break;
1382 case CTDB_CONTROL_DB_OPEN_FLAGS:
1383 len = ctdb_int32_len(&cd->data.tdb_flags);
1384 break;
1386 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1387 len = ctdb_uint32_len(&cd->data.db_id);
1388 break;
1390 case CTDB_CONTROL_CHECK_PID_SRVID:
1391 break;
1393 case CTDB_CONTROL_TUNNEL_REGISTER:
1394 break;
1396 case CTDB_CONTROL_TUNNEL_DEREGISTER:
1397 break;
1399 case CTDB_CONTROL_VACUUM_FETCH:
1400 break;
1402 case CTDB_CONTROL_DB_VACUUM:
1403 break;
1405 case CTDB_CONTROL_ECHO_DATA:
1406 len = ctdb_echo_data_len(cd->data.echo_data);
1407 break;
1409 case CTDB_CONTROL_DISABLE_NODE:
1410 break;
1412 case CTDB_CONTROL_ENABLE_NODE:
1413 break;
1415 case CTDB_CONTROL_TCP_CLIENT_DISCONNECTED:
1416 break;
1418 case CTDB_CONTROL_TCP_CLIENT_PASSED:
1419 break;
1421 case CTDB_CONTROL_START_IPREALLOCATE:
1422 break;
1425 return len;
1428 static void ctdb_reply_control_data_push(struct ctdb_reply_control_data *cd,
1429 uint8_t *buf, size_t *npush)
1431 size_t np = 0;
1433 switch (cd->opcode) {
1434 case CTDB_CONTROL_STATISTICS:
1435 ctdb_statistics_push(cd->data.stats, buf, &np);
1436 break;
1438 case CTDB_CONTROL_GETDBPATH:
1439 ctdb_string_push(&cd->data.db_path, buf, &np);
1440 break;
1442 case CTDB_CONTROL_GETVNNMAP:
1443 ctdb_vnn_map_push(cd->data.vnnmap, buf, &np);
1444 break;
1446 case CTDB_CONTROL_GET_DEBUG:
1447 ctdb_uint32_push(&cd->data.loglevel, buf, &np);
1448 break;
1450 case CTDB_CONTROL_GET_DBMAP:
1451 ctdb_dbid_map_push(cd->data.dbmap, buf, &np);
1452 break;
1454 case CTDB_CONTROL_DB_ATTACH:
1455 ctdb_uint32_push(&cd->data.db_id, buf, &np);
1456 break;
1458 case CTDB_CONTROL_GET_DBNAME:
1459 ctdb_string_push(&cd->data.db_name, buf, &np);
1460 break;
1462 case CTDB_CONTROL_DUMP_MEMORY:
1463 ctdb_string_push(&cd->data.mem_str, buf, &np);
1464 break;
1466 case CTDB_CONTROL_GET_PID:
1467 break;
1469 case CTDB_CONTROL_GET_TUNABLE:
1470 ctdb_uint32_push(&cd->data.tun_value, buf, &np);
1471 break;
1473 case CTDB_CONTROL_LIST_TUNABLES:
1474 ctdb_var_list_push(cd->data.tun_var_list, buf, &np);
1475 break;
1477 case CTDB_CONTROL_GET_ALL_TUNABLES:
1478 ctdb_tunable_list_push(cd->data.tun_list, buf, &np);
1479 break;
1481 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1482 ctdb_tickle_list_push(cd->data.tickles, buf, &np);
1483 break;
1485 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1486 ctdb_uint32_push(&cd->data.db_id, buf, &np);
1487 break;
1489 case CTDB_CONTROL_UPTIME:
1490 ctdb_uptime_push(cd->data.uptime, buf, &np);
1491 break;
1493 case CTDB_CONTROL_TRY_DELETE_RECORDS:
1494 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
1495 break;
1497 case CTDB_CONTROL_GET_CAPABILITIES:
1498 ctdb_uint32_push(&cd->data.caps, buf, &np);
1499 break;
1501 case CTDB_CONTROL_GET_PUBLIC_IPS:
1502 ctdb_public_ip_list_push(cd->data.pubip_list, buf, &np);
1503 break;
1505 case CTDB_CONTROL_GET_NODEMAP:
1506 ctdb_node_map_push(cd->data.nodemap, buf, &np);
1507 break;
1509 case CTDB_CONTROL_GET_RECLOCK_FILE:
1510 ctdb_string_push(&cd->data.reclock_file, buf, &np);
1511 break;
1513 case CTDB_CONTROL_GET_BAN_STATE:
1514 ctdb_ban_state_push(cd->data.ban_state, buf, &np);
1515 break;
1517 case CTDB_CONTROL_GET_DB_SEQNUM:
1518 ctdb_uint64_push(&cd->data.seqnum, buf, &np);
1519 break;
1521 case CTDB_CONTROL_DB_GET_HEALTH:
1522 ctdb_string_push(&cd->data.reason, buf, &np);
1523 break;
1525 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1526 ctdb_public_ip_info_push(cd->data.ipinfo, buf, &np);
1527 break;
1529 case CTDB_CONTROL_GET_IFACES:
1530 ctdb_iface_list_push(cd->data.iface_list, buf, &np);
1531 break;
1533 case CTDB_CONTROL_GET_STAT_HISTORY:
1534 ctdb_statistics_list_push(cd->data.stats_list, buf, &np);
1535 break;
1537 case CTDB_CONTROL_GET_DB_STATISTICS:
1538 ctdb_db_statistics_push(cd->data.dbstats, buf, &np);
1539 break;
1541 case CTDB_CONTROL_GET_RUNSTATE:
1542 ctdb_uint32_push(&cd->data.runstate, buf, &np);
1543 break;
1545 case CTDB_CONTROL_GET_NODES_FILE:
1546 ctdb_node_map_push(cd->data.nodemap, buf, &np);
1547 break;
1549 case CTDB_CONTROL_DB_PULL:
1550 ctdb_uint32_push(&cd->data.num_records, buf, &np);
1551 break;
1553 case CTDB_CONTROL_DB_PUSH_CONFIRM:
1554 ctdb_uint32_push(&cd->data.num_records, buf, &np);
1555 break;
1557 case CTDB_CONTROL_DB_OPEN_FLAGS:
1558 ctdb_int32_push(&cd->data.tdb_flags, buf, &np);
1559 break;
1561 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1562 ctdb_uint32_push(&cd->data.db_id, buf, &np);
1563 break;
1565 case CTDB_CONTROL_CHECK_PID_SRVID:
1566 break;
1568 case CTDB_CONTROL_VACUUM_FETCH:
1569 break;
1571 case CTDB_CONTROL_DB_VACUUM:
1572 break;
1574 case CTDB_CONTROL_ECHO_DATA:
1575 ctdb_echo_data_push(cd->data.echo_data, buf, &np);
1576 break;
1579 *npush = np;
1582 static int ctdb_reply_control_data_pull(uint8_t *buf, size_t buflen,
1583 uint32_t opcode, TALLOC_CTX *mem_ctx,
1584 struct ctdb_reply_control_data *cd,
1585 size_t *npull)
1587 size_t np = 0;
1588 int ret = 0;
1590 cd->opcode = opcode;
1592 switch (opcode) {
1593 case CTDB_CONTROL_STATISTICS:
1594 ret = ctdb_statistics_pull(buf, buflen, mem_ctx,
1595 &cd->data.stats, &np);
1596 break;
1598 case CTDB_CONTROL_GETDBPATH:
1599 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1600 &cd->data.db_path, &np);
1601 break;
1603 case CTDB_CONTROL_GETVNNMAP:
1604 ret = ctdb_vnn_map_pull(buf, buflen, mem_ctx,
1605 &cd->data.vnnmap, &np);
1606 break;
1608 case CTDB_CONTROL_GET_DEBUG:
1609 ret = ctdb_uint32_pull(buf, buflen, &cd->data.loglevel, &np);
1610 break;
1612 case CTDB_CONTROL_GET_DBMAP:
1613 ret = ctdb_dbid_map_pull(buf, buflen, mem_ctx,
1614 &cd->data.dbmap, &np);
1615 break;
1617 case CTDB_CONTROL_DB_ATTACH:
1618 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1619 break;
1621 case CTDB_CONTROL_GET_DBNAME:
1622 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1623 &cd->data.db_name, &np);
1624 break;
1626 case CTDB_CONTROL_DUMP_MEMORY:
1627 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1628 &cd->data.mem_str, &np);
1629 break;
1631 case CTDB_CONTROL_GET_PID:
1632 break;
1634 case CTDB_CONTROL_GET_TUNABLE:
1635 ret = ctdb_uint32_pull(buf, buflen, &cd->data.tun_value,
1636 &np);
1637 break;
1639 case CTDB_CONTROL_LIST_TUNABLES:
1640 ret = ctdb_var_list_pull(buf, buflen, mem_ctx,
1641 &cd->data.tun_var_list, &np);
1642 break;
1644 case CTDB_CONTROL_GET_ALL_TUNABLES:
1645 ret = ctdb_tunable_list_pull(buf, buflen, mem_ctx,
1646 &cd->data.tun_list, &np);
1647 break;
1649 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1650 ret = ctdb_tickle_list_pull(buf, buflen, mem_ctx,
1651 &cd->data.tickles, &np);
1652 break;
1654 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1655 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1656 break;
1658 case CTDB_CONTROL_UPTIME:
1659 ret = ctdb_uptime_pull(buf, buflen, mem_ctx,
1660 &cd->data.uptime, &np);
1661 break;
1663 case CTDB_CONTROL_TRY_DELETE_RECORDS:
1664 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
1665 &cd->data.recbuf, &np);
1666 break;
1668 case CTDB_CONTROL_GET_CAPABILITIES:
1669 ret = ctdb_uint32_pull(buf, buflen, &cd->data.caps, &np);
1670 break;
1672 case CTDB_CONTROL_GET_PUBLIC_IPS:
1673 ret = ctdb_public_ip_list_pull(buf, buflen, mem_ctx,
1674 &cd->data.pubip_list, &np);
1675 break;
1677 case CTDB_CONTROL_GET_NODEMAP:
1678 ret = ctdb_node_map_pull(buf, buflen, mem_ctx,
1679 &cd->data.nodemap, &np);
1680 break;
1682 case CTDB_CONTROL_GET_RECLOCK_FILE:
1683 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1684 &cd->data.reclock_file, &np);
1685 break;
1687 case CTDB_CONTROL_GET_BAN_STATE:
1688 ret = ctdb_ban_state_pull(buf, buflen, mem_ctx,
1689 &cd->data.ban_state, &np);
1690 break;
1692 case CTDB_CONTROL_GET_DB_SEQNUM:
1693 ret = ctdb_uint64_pull(buf, buflen, &cd->data.seqnum, &np);
1694 break;
1696 case CTDB_CONTROL_DB_GET_HEALTH:
1697 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1698 &cd->data.reason, &np);
1699 break;
1701 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1702 ret = ctdb_public_ip_info_pull(buf, buflen, mem_ctx,
1703 &cd->data.ipinfo, &np);
1704 break;
1706 case CTDB_CONTROL_GET_IFACES:
1707 ret = ctdb_iface_list_pull(buf, buflen, mem_ctx,
1708 &cd->data.iface_list, &np);
1709 break;
1711 case CTDB_CONTROL_GET_STAT_HISTORY:
1712 ret = ctdb_statistics_list_pull(buf, buflen, mem_ctx,
1713 &cd->data.stats_list, &np);
1714 break;
1716 case CTDB_CONTROL_GET_DB_STATISTICS:
1717 ret = ctdb_db_statistics_pull(buf, buflen, mem_ctx,
1718 &cd->data.dbstats, &np);
1719 break;
1721 case CTDB_CONTROL_GET_RUNSTATE:
1722 ret = ctdb_uint32_pull(buf, buflen, &cd->data.runstate, &np);
1723 break;
1725 case CTDB_CONTROL_GET_NODES_FILE:
1726 ret = ctdb_node_map_pull(buf, buflen, mem_ctx,
1727 &cd->data.nodemap, &np);
1728 break;
1730 case CTDB_CONTROL_DB_PULL:
1731 ret = ctdb_uint32_pull(buf, buflen, &cd->data.num_records,
1732 &np);
1733 break;
1735 case CTDB_CONTROL_DB_PUSH_CONFIRM:
1736 ret = ctdb_uint32_pull(buf, buflen, &cd->data.num_records,
1737 &np);
1738 break;
1740 case CTDB_CONTROL_DB_OPEN_FLAGS:
1741 ret = ctdb_int32_pull(buf, buflen, &cd->data.tdb_flags, &np);
1742 break;
1744 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1745 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1746 break;
1748 case CTDB_CONTROL_CHECK_PID_SRVID:
1749 break;
1751 case CTDB_CONTROL_VACUUM_FETCH:
1752 break;
1754 case CTDB_CONTROL_DB_VACUUM:
1755 break;
1757 case CTDB_CONTROL_ECHO_DATA:
1758 ret = ctdb_echo_data_pull(buf,
1759 buflen,
1760 mem_ctx,
1761 &cd->data.echo_data,
1762 &np);
1763 break;
1766 if (ret != 0) {
1767 return ret;
1770 *npull = np;
1771 return 0;
1774 size_t ctdb_req_control_len(struct ctdb_req_header *h,
1775 struct ctdb_req_control *c)
1777 uint32_t u32 = 0;
1779 return ctdb_req_header_len(h) +
1780 ctdb_uint32_len(&c->opcode) +
1781 ctdb_uint32_len(&c->pad) +
1782 ctdb_uint64_len(&c->srvid) +
1783 ctdb_uint32_len(&c->client_id) +
1784 ctdb_uint32_len(&c->flags) +
1785 ctdb_uint32_len(&u32) +
1786 ctdb_req_control_data_len(&c->rdata);
1789 int ctdb_req_control_push(struct ctdb_req_header *h,
1790 struct ctdb_req_control *c,
1791 uint8_t *buf, size_t *buflen)
1793 size_t offset = 0, np;
1794 size_t length;
1795 uint32_t u32;
1797 length = ctdb_req_control_len(h, c);
1798 if (*buflen < length) {
1799 *buflen = length;
1800 return EMSGSIZE;
1803 h->length = *buflen;
1804 ctdb_req_header_push(h, buf+offset, &np);
1805 offset += np;
1807 ctdb_uint32_push(&c->opcode, buf+offset, &np);
1808 offset += np;
1810 ctdb_uint32_push(&c->pad, buf+offset, &np);
1811 offset += np;
1813 ctdb_uint64_push(&c->srvid, buf+offset, &np);
1814 offset += np;
1816 ctdb_uint32_push(&c->client_id, buf+offset, &np);
1817 offset += np;
1819 ctdb_uint32_push(&c->flags, buf+offset, &np);
1820 offset += np;
1822 u32 = ctdb_req_control_data_len(&c->rdata);
1823 ctdb_uint32_push(&u32, buf+offset, &np);
1824 offset += np;
1826 ctdb_req_control_data_push(&c->rdata, buf+offset, &np);
1827 offset += np;
1829 if (offset > *buflen) {
1830 return EMSGSIZE;
1833 return 0;
1836 int ctdb_req_control_pull(uint8_t *buf, size_t buflen,
1837 struct ctdb_req_header *h,
1838 TALLOC_CTX *mem_ctx,
1839 struct ctdb_req_control *c)
1841 struct ctdb_req_header header;
1842 size_t offset = 0, np;
1843 uint32_t u32;
1844 int ret;
1846 ret = ctdb_req_header_pull(buf+offset, buflen-offset, &header, &np);
1847 if (ret != 0) {
1848 return ret;
1850 offset += np;
1852 if (h != NULL) {
1853 *h = header;
1856 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->opcode, &np);
1857 if (ret != 0) {
1858 return ret;
1860 offset += np;
1862 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->pad, &np);
1863 if (ret != 0) {
1864 return ret;
1866 offset += np;
1868 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &c->srvid, &np);
1869 if (ret != 0) {
1870 return ret;
1872 offset += np;
1874 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->client_id, &np);
1875 if (ret != 0) {
1876 return ret;
1878 offset += np;
1880 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->flags, &np);
1881 if (ret != 0) {
1882 return ret;
1884 offset += np;
1886 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
1887 if (ret != 0) {
1888 return ret;
1890 offset += np;
1892 if (u32 > buflen-offset) {
1893 return EMSGSIZE;
1896 ret = ctdb_req_control_data_pull(buf+offset, u32, c->opcode, mem_ctx,
1897 &c->rdata, &np);
1898 if (ret != 0) {
1899 return ret;
1901 offset += np;
1903 if (offset > buflen) {
1904 return EMSGSIZE;
1907 return 0;
1910 size_t ctdb_reply_control_len(struct ctdb_req_header *h,
1911 struct ctdb_reply_control *c)
1913 uint32_t dsize, esize;
1915 if (c->status == 0) {
1916 dsize = ctdb_reply_control_data_len(&c->rdata);
1917 esize = 0;
1918 } else {
1919 dsize = 0;
1920 esize = ctdb_string_len(&c->errmsg);
1923 return ctdb_req_header_len(h) +
1924 ctdb_int32_len(&c->status) +
1925 ctdb_uint32_len(&dsize) +
1926 ctdb_uint32_len(&esize) +
1927 dsize + esize;
1930 int ctdb_reply_control_push(struct ctdb_req_header *h,
1931 struct ctdb_reply_control *c,
1932 uint8_t *buf, size_t *buflen)
1934 size_t offset = 0, np;
1935 size_t length;
1936 uint32_t dsize, esize;
1938 length = ctdb_reply_control_len(h, c);
1939 if (*buflen < length) {
1940 *buflen = length;
1941 return EMSGSIZE;
1944 h->length = *buflen;
1945 ctdb_req_header_push(h, buf+offset, &np);
1946 offset += np;
1948 ctdb_int32_push(&c->status, buf+offset, &np);
1949 offset += np;
1951 if (c->status == 0) {
1952 dsize = ctdb_reply_control_data_len(&c->rdata);
1953 esize = 0;
1954 } else {
1955 dsize = 0;
1956 esize = ctdb_string_len(&c->errmsg);
1959 ctdb_uint32_push(&dsize, buf+offset, &np);
1960 offset += np;
1962 ctdb_uint32_push(&esize, buf+offset, &np);
1963 offset += np;
1965 if (c->status == 0) {
1966 ctdb_reply_control_data_push(&c->rdata, buf+offset, &np);
1967 } else {
1968 ctdb_string_push(&c->errmsg, buf+offset, &np);
1970 offset += np;
1972 return 0;
1975 int ctdb_reply_control_pull(uint8_t *buf, size_t buflen, uint32_t opcode,
1976 struct ctdb_req_header *h,
1977 TALLOC_CTX *mem_ctx,
1978 struct ctdb_reply_control *c)
1980 struct ctdb_req_header header;
1981 size_t offset = 0, np;
1982 uint32_t dsize, esize;
1983 int ret;
1985 ret = ctdb_req_header_pull(buf+offset, buflen-offset, &header, &np);
1986 if (ret != 0) {
1987 return ret;
1989 offset += np;
1991 if (h != NULL) {
1992 *h = header;
1995 ret = ctdb_int32_pull(buf+offset, buflen-offset, &c->status, &np);
1996 if (ret != 0) {
1997 return ret;
1999 offset += np;
2001 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &dsize, &np);
2002 if (ret != 0) {
2003 return ret;
2005 offset += np;
2007 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &esize, &np);
2008 if (ret != 0) {
2009 return ret;
2011 offset += np;
2013 c->errmsg = NULL;
2015 if (c->status == 0) {
2016 if (buflen-offset < dsize) {
2017 return EMSGSIZE;
2020 ret = ctdb_reply_control_data_pull(buf+offset, dsize,
2021 opcode, mem_ctx, &c->rdata,
2022 &np);
2023 if (ret != 0) {
2024 return ret;
2026 offset += np;
2028 } else {
2029 if (buflen-offset < esize) {
2030 return EMSGSIZE;
2033 ret = ctdb_string_pull(buf+offset, esize, mem_ctx, &c->errmsg,
2034 &np);
2035 if (ret != 0) {
2036 return ret;
2038 offset += np;
2041 return 0;