pytest:dsdb: check that there is a gkdi root key
[samba.git] / ctdb / protocol / protocol_control.c
blobe4491159937ed1b9c27f1d18691030ad85655564
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;
423 return len;
426 static void ctdb_req_control_data_push(struct ctdb_req_control_data *cd,
427 uint8_t *buf, size_t *npush)
429 size_t np = 0, offset;
430 uint32_t u32;
432 switch (cd->opcode) {
433 case CTDB_CONTROL_PROCESS_EXISTS:
434 ctdb_pid_push(&cd->data.pid, buf, &np);
435 break;
437 case CTDB_CONTROL_GETDBPATH:
438 ctdb_uint32_push(&cd->data.db_id, buf, &np);
439 break;
441 case CTDB_CONTROL_SETVNNMAP:
442 ctdb_vnn_map_push(cd->data.vnnmap, buf, &np);
443 break;
445 case CTDB_CONTROL_SET_DEBUG:
446 ctdb_uint32_push(&cd->data.loglevel, buf, &np);
447 break;
449 case CTDB_CONTROL_SET_RECMODE:
450 ctdb_uint32_push(&cd->data.recmode, buf, &np);
451 break;
453 case CTDB_CONTROL_DB_ATTACH:
454 ctdb_string_push(&cd->data.db_name, buf, &np);
455 break;
457 case CTDB_CONTROL_TRAVERSE_START:
458 ctdb_traverse_start_push(cd->data.traverse_start, buf, &np);
459 break;
461 case CTDB_CONTROL_TRAVERSE_ALL:
462 ctdb_traverse_all_push(cd->data.traverse_all, buf, &np);
463 break;
465 case CTDB_CONTROL_TRAVERSE_DATA:
466 ctdb_rec_data_push(cd->data.rec_data, buf, &np);
467 break;
469 case CTDB_CONTROL_GET_DBNAME:
470 ctdb_uint32_push(&cd->data.db_id, buf, &np);
471 break;
473 case CTDB_CONTROL_ENABLE_SEQNUM:
474 ctdb_uint32_push(&cd->data.db_id, buf, &np);
475 break;
477 case CTDB_CONTROL_UPDATE_SEQNUM:
478 ctdb_uint32_push(&cd->data.db_id, buf, &np);
479 break;
481 case CTDB_CONTROL_TCP_CLIENT:
482 ctdb_connection_push(cd->data.conn, buf, &np);
483 break;
485 case CTDB_CONTROL_TCP_ADD:
486 ctdb_connection_push(cd->data.conn, buf, &np);
487 break;
489 case CTDB_CONTROL_TCP_REMOVE:
490 ctdb_connection_push(cd->data.conn, buf, &np);
491 break;
493 case CTDB_CONTROL_SET_TUNABLE:
494 ctdb_tunable_push(cd->data.tunable, buf, &np);
495 break;
497 case CTDB_CONTROL_GET_TUNABLE:
498 ctdb_stringn_push(&cd->data.tun_var, buf, &np);
499 break;
501 case CTDB_CONTROL_MODIFY_FLAGS:
502 ctdb_node_flag_change_push(cd->data.flag_change, buf, &np);
503 break;
505 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
506 ctdb_sock_addr_push(cd->data.addr, buf, &np);
507 break;
509 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
510 ctdb_tickle_list_push(cd->data.tickles, buf, &np);
511 break;
513 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
514 ctdb_string_push(&cd->data.db_name, buf, &np);
515 break;
517 case CTDB_CONTROL_UPDATE_RECORD:
518 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
519 break;
521 case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
522 ctdb_addr_info_push(cd->data.addr_info, buf, &np);
523 break;
525 case CTDB_CONTROL_WIPE_DATABASE:
526 ctdb_transdb_push(cd->data.transdb, buf, &np);
527 break;
529 case CTDB_CONTROL_TRY_DELETE_RECORDS:
530 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
531 break;
533 case CTDB_CONTROL_ADD_PUBLIC_IP:
534 ctdb_addr_info_push(cd->data.addr_info, buf, &np);
535 break;
537 case CTDB_CONTROL_DEL_PUBLIC_IP:
538 ctdb_addr_info_push(cd->data.addr_info, buf, &np);
539 break;
541 case CTDB_CONTROL_RELEASE_IP:
542 ctdb_public_ip_push(cd->data.pubip, buf, &np);
543 break;
545 case CTDB_CONTROL_TAKEOVER_IP:
546 ctdb_public_ip_push(cd->data.pubip, buf, &np);
547 break;
549 case CTDB_CONTROL_TRAVERSE_KILL:
550 ctdb_traverse_start_push(cd->data.traverse_start, buf, &np);
551 break;
553 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
554 ctdb_double_push(&cd->data.reclock_latency, buf, &np);
555 break;
557 case CTDB_CONTROL_SET_LMASTERROLE:
558 ctdb_uint32_push(&cd->data.role, buf, &np);
559 break;
561 case CTDB_CONTROL_SET_RECMASTERROLE:
562 ctdb_uint32_push(&cd->data.role, buf, &np);
563 break;
565 case CTDB_CONTROL_SET_BAN_STATE:
566 ctdb_ban_state_push(cd->data.ban_state, buf, &np);
567 break;
569 case CTDB_CONTROL_REGISTER_NOTIFY:
570 ctdb_notify_data_push(cd->data.notify, buf, &np);
571 break;
573 case CTDB_CONTROL_DEREGISTER_NOTIFY:
574 ctdb_uint64_push(&cd->data.srvid, buf, &np);
575 break;
577 case CTDB_CONTROL_TRANS3_COMMIT:
578 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
579 break;
581 case CTDB_CONTROL_GET_DB_SEQNUM:
582 u32 = 0;
583 offset = 0;
584 ctdb_uint32_push(&cd->data.db_id, buf, &np);
585 offset += np;
586 ctdb_uint32_push(&u32, buf+offset, &np);
587 offset += np;
588 np = offset;
589 break;
591 case CTDB_CONTROL_DB_SET_HEALTHY:
592 ctdb_uint32_push(&cd->data.db_id, buf, &np);
593 break;
595 case CTDB_CONTROL_DB_GET_HEALTH:
596 ctdb_uint32_push(&cd->data.db_id, buf, &np);
597 break;
599 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
600 ctdb_sock_addr_push(cd->data.addr, buf, &np);
601 break;
603 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
604 ctdb_iface_push(cd->data.iface, buf, &np);
605 break;
607 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
608 ctdb_connection_push(cd->data.conn, buf, &np);
609 break;
611 case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
612 ctdb_key_data_push(cd->data.key, buf, &np);
613 break;
615 case CTDB_CONTROL_SET_DB_READONLY:
616 ctdb_uint32_push(&cd->data.db_id, buf, &np);
617 break;
619 case CTDB_CONTROL_TRAVERSE_START_EXT:
620 ctdb_traverse_start_ext_push(cd->data.traverse_start_ext, buf,
621 &np);
622 break;
624 case CTDB_CONTROL_GET_DB_STATISTICS:
625 ctdb_uint32_push(&cd->data.db_id, buf, &np);
626 break;
628 case CTDB_CONTROL_SET_DB_STICKY:
629 ctdb_uint32_push(&cd->data.db_id, buf, &np);
630 break;
632 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
633 ctdb_traverse_all_ext_push(cd->data.traverse_all_ext, buf,
634 &np);
635 break;
637 case CTDB_CONTROL_DB_DETACH:
638 ctdb_uint32_push(&cd->data.db_id, buf, &np);
639 break;
641 case CTDB_CONTROL_DB_FREEZE:
642 ctdb_uint32_push(&cd->data.db_id, buf, &np);
643 break;
645 case CTDB_CONTROL_DB_THAW:
646 ctdb_uint32_push(&cd->data.db_id, buf, &np);
647 break;
649 case CTDB_CONTROL_DB_TRANSACTION_START:
650 ctdb_transdb_push(cd->data.transdb, buf, &np);
651 break;
653 case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
654 ctdb_transdb_push(cd->data.transdb, buf, &np);
655 break;
657 case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
658 ctdb_uint32_push(&cd->data.db_id, buf, &np);
659 break;
661 case CTDB_CONTROL_DB_PULL:
662 ctdb_pulldb_ext_push(cd->data.pulldb_ext, buf, &np);
663 break;
665 case CTDB_CONTROL_DB_PUSH_START:
666 ctdb_pulldb_ext_push(cd->data.pulldb_ext, buf, &np);
667 break;
669 case CTDB_CONTROL_DB_PUSH_CONFIRM:
670 ctdb_uint32_push(&cd->data.db_id, buf, &np);
671 break;
673 case CTDB_CONTROL_DB_OPEN_FLAGS:
674 ctdb_uint32_push(&cd->data.db_id, buf, &np);
675 break;
677 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
678 ctdb_string_push(&cd->data.db_name, buf, &np);
679 break;
681 case CTDB_CONTROL_CHECK_PID_SRVID:
682 ctdb_pid_srvid_push(cd->data.pid_srvid, buf, &np);
683 break;
685 case CTDB_CONTROL_VACUUM_FETCH:
686 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
687 break;
689 case CTDB_CONTROL_DB_VACUUM:
690 ctdb_db_vacuum_push(cd->data.db_vacuum, buf, &np);
691 break;
693 case CTDB_CONTROL_ECHO_DATA:
694 ctdb_echo_data_push(cd->data.echo_data, buf, &np);
695 break;
697 case CTDB_CONTROL_TCP_CLIENT_DISCONNECTED:
698 ctdb_connection_push(cd->data.conn, buf, &np);
699 break;
701 case CTDB_CONTROL_TCP_CLIENT_PASSED:
702 ctdb_connection_push(cd->data.conn, buf, &np);
703 break;
706 *npush = np;
709 static int ctdb_req_control_data_pull(uint8_t *buf, size_t buflen,
710 uint32_t opcode,
711 TALLOC_CTX *mem_ctx,
712 struct ctdb_req_control_data *cd,
713 size_t *npull)
715 size_t np = 0, offset;
716 uint32_t u32;
717 int ret = 0;
719 cd->opcode = opcode;
721 switch (opcode) {
722 case CTDB_CONTROL_PROCESS_EXISTS:
723 ret = ctdb_pid_pull(buf, buflen, &cd->data.pid, &np);
724 break;
726 case CTDB_CONTROL_GETDBPATH:
727 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
728 break;
730 case CTDB_CONTROL_SETVNNMAP:
731 ret = ctdb_vnn_map_pull(buf, buflen, mem_ctx,
732 &cd->data.vnnmap, &np);
733 break;
735 case CTDB_CONTROL_SET_DEBUG:
736 ret = ctdb_uint32_pull(buf, buflen, &cd->data.loglevel, &np);
737 break;
739 case CTDB_CONTROL_SET_RECMODE:
740 ret = ctdb_uint32_pull(buf, buflen, &cd->data.recmode, &np);
741 break;
743 case CTDB_CONTROL_DB_ATTACH:
744 ret = ctdb_string_pull(buf, buflen, mem_ctx,
745 &cd->data.db_name, &np);
746 break;
748 case CTDB_CONTROL_TRAVERSE_START:
749 ret = ctdb_traverse_start_pull(buf, buflen, mem_ctx,
750 &cd->data.traverse_start, &np);
751 break;
753 case CTDB_CONTROL_TRAVERSE_ALL:
754 ret = ctdb_traverse_all_pull(buf, buflen, mem_ctx,
755 &cd->data.traverse_all, &np);
756 break;
758 case CTDB_CONTROL_TRAVERSE_DATA:
759 ret = ctdb_rec_data_pull(buf, buflen, mem_ctx,
760 &cd->data.rec_data, &np);
761 break;
763 case CTDB_CONTROL_GET_DBNAME:
764 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
765 break;
767 case CTDB_CONTROL_ENABLE_SEQNUM:
768 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
769 break;
771 case CTDB_CONTROL_UPDATE_SEQNUM:
772 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
773 break;
775 case CTDB_CONTROL_TCP_CLIENT:
776 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
777 &cd->data.conn, &np);
778 break;
780 case CTDB_CONTROL_TCP_ADD:
781 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
782 &cd->data.conn, &np);
783 break;
785 case CTDB_CONTROL_TCP_REMOVE:
786 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
787 &cd->data.conn, &np);
788 break;
790 case CTDB_CONTROL_SET_TUNABLE:
791 ret = ctdb_tunable_pull(buf, buflen, mem_ctx,
792 &cd->data.tunable, &np);
793 break;
795 case CTDB_CONTROL_GET_TUNABLE:
796 ret = ctdb_stringn_pull(buf, buflen, mem_ctx,
797 &cd->data.tun_var, &np);
798 break;
800 case CTDB_CONTROL_MODIFY_FLAGS:
801 ret = ctdb_node_flag_change_pull(buf, buflen, mem_ctx,
802 &cd->data.flag_change, &np);
803 break;
805 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
806 ret = ctdb_sock_addr_pull(buf, buflen, mem_ctx,
807 &cd->data.addr, &np);
808 break;
810 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
811 ret = ctdb_tickle_list_pull(buf, buflen, mem_ctx,
812 &cd->data.tickles, &np);
813 break;
815 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
816 ret = ctdb_string_pull(buf, buflen, mem_ctx,
817 &cd->data.db_name, &np);
818 break;
820 case CTDB_CONTROL_UPDATE_RECORD:
821 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
822 &cd->data.recbuf, &np);
823 break;
825 case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
826 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
827 &cd->data.addr_info, &np);
828 break;
830 case CTDB_CONTROL_WIPE_DATABASE:
831 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
832 &cd->data.transdb, &np);
833 break;
835 case CTDB_CONTROL_TRY_DELETE_RECORDS:
836 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
837 &cd->data.recbuf, &np);
838 break;
840 case CTDB_CONTROL_ADD_PUBLIC_IP:
841 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
842 &cd->data.addr_info, &np);
843 break;
845 case CTDB_CONTROL_DEL_PUBLIC_IP:
846 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
847 &cd->data.addr_info, &np);
848 break;
850 case CTDB_CONTROL_RELEASE_IP:
851 ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
852 &cd->data.pubip, &np);
853 break;
855 case CTDB_CONTROL_TAKEOVER_IP:
856 ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
857 &cd->data.pubip, &np);
858 break;
860 case CTDB_CONTROL_TRAVERSE_KILL:
861 ret = ctdb_traverse_start_pull(buf, buflen, mem_ctx,
862 &cd->data.traverse_start, &np);
863 break;
865 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
866 ret = ctdb_double_pull(buf, buflen, &cd->data.reclock_latency,
867 &np);
868 break;
870 case CTDB_CONTROL_SET_LMASTERROLE:
871 ret = ctdb_uint32_pull(buf, buflen, &cd->data.role, &np);
872 break;
874 case CTDB_CONTROL_SET_RECMASTERROLE:
875 ret = ctdb_uint32_pull(buf, buflen, &cd->data.role, &np);
876 break;
878 case CTDB_CONTROL_SET_BAN_STATE:
879 ret = ctdb_ban_state_pull(buf, buflen, mem_ctx,
880 &cd->data.ban_state, &np);
881 break;
883 case CTDB_CONTROL_REGISTER_NOTIFY:
884 ret = ctdb_notify_data_pull(buf, buflen, mem_ctx,
885 &cd->data.notify, &np);
886 break;
888 case CTDB_CONTROL_DEREGISTER_NOTIFY:
889 ret = ctdb_uint64_pull(buf, buflen, &cd->data.srvid, &np);
890 break;
892 case CTDB_CONTROL_TRANS3_COMMIT:
893 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
894 &cd->data.recbuf, &np);
895 break;
897 case CTDB_CONTROL_GET_DB_SEQNUM:
898 offset = 0;
899 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
900 if (ret != 0) {
901 break;
903 offset += np;
904 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
905 offset += np;
906 np = offset;
907 break;
909 case CTDB_CONTROL_DB_SET_HEALTHY:
910 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
911 break;
913 case CTDB_CONTROL_DB_GET_HEALTH:
914 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
915 break;
917 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
918 ret = ctdb_sock_addr_pull(buf, buflen, mem_ctx,
919 &cd->data.addr, &np);
920 break;
922 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
923 ret = ctdb_iface_pull(buf, buflen, mem_ctx,
924 &cd->data.iface, &np);
925 break;
927 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
928 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
929 &cd->data.conn, &np);
930 break;
932 case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
933 ret = ctdb_key_data_pull(buf, buflen, mem_ctx,
934 &cd->data.key, &np);
935 break;
937 case CTDB_CONTROL_SET_DB_READONLY:
938 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
939 break;
941 case CTDB_CONTROL_TRAVERSE_START_EXT:
942 ret = ctdb_traverse_start_ext_pull(buf, buflen, mem_ctx,
943 &cd->data.traverse_start_ext,
944 &np);
945 break;
947 case CTDB_CONTROL_GET_DB_STATISTICS:
948 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
949 break;
951 case CTDB_CONTROL_SET_DB_STICKY:
952 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
953 break;
955 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
956 ret = ctdb_traverse_all_ext_pull(buf, buflen, mem_ctx,
957 &cd->data.traverse_all_ext,
958 &np);
959 break;
961 case CTDB_CONTROL_DB_DETACH:
962 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
963 break;
965 case CTDB_CONTROL_DB_FREEZE:
966 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
967 break;
969 case CTDB_CONTROL_DB_THAW:
970 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
971 break;
973 case CTDB_CONTROL_DB_TRANSACTION_START:
974 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
975 &cd->data.transdb, &np);
976 break;
978 case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
979 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
980 &cd->data.transdb, &np);
981 break;
983 case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
984 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
985 break;
987 case CTDB_CONTROL_DB_PULL:
988 ret = ctdb_pulldb_ext_pull(buf, buflen, mem_ctx,
989 &cd->data.pulldb_ext, &np);
990 break;
992 case CTDB_CONTROL_DB_PUSH_START:
993 ret = ctdb_pulldb_ext_pull(buf, buflen, mem_ctx,
994 &cd->data.pulldb_ext, &np);
995 break;
997 case CTDB_CONTROL_DB_PUSH_CONFIRM:
998 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
999 break;
1001 case CTDB_CONTROL_DB_OPEN_FLAGS:
1002 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1003 break;
1005 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1006 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1007 &cd->data.db_name, &np);
1008 break;
1010 case CTDB_CONTROL_CHECK_PID_SRVID:
1011 ret = ctdb_pid_srvid_pull(buf, buflen, mem_ctx,
1012 &cd->data.pid_srvid, &np);
1013 break;
1015 case CTDB_CONTROL_VACUUM_FETCH:
1016 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
1017 &cd->data.recbuf, &np);
1018 break;
1020 case CTDB_CONTROL_DB_VACUUM:
1021 ret = ctdb_db_vacuum_pull(buf,
1022 buflen,
1023 mem_ctx,
1024 &cd->data.db_vacuum,
1025 &np);
1026 break;
1028 case CTDB_CONTROL_ECHO_DATA:
1029 ret = ctdb_echo_data_pull(buf,
1030 buflen,
1031 mem_ctx,
1032 &cd->data.echo_data,
1033 &np);
1034 break;
1036 case CTDB_CONTROL_TCP_CLIENT_DISCONNECTED:
1037 ret = ctdb_connection_pull(buf,
1038 buflen,
1039 mem_ctx,
1040 &cd->data.conn,
1041 &np);
1042 break;
1044 case CTDB_CONTROL_TCP_CLIENT_PASSED:
1045 ret = ctdb_connection_pull(buf,
1046 buflen,
1047 mem_ctx,
1048 &cd->data.conn,
1049 &np);
1050 break;
1053 if (ret != 0) {
1054 return ret;
1057 *npull = np;
1058 return 0;
1061 static size_t ctdb_reply_control_data_len(struct ctdb_reply_control_data *cd)
1063 size_t len = 0;
1065 if (cd == NULL) {
1066 return 0;
1069 switch (cd->opcode) {
1070 case CTDB_CONTROL_PROCESS_EXISTS:
1071 break;
1073 case CTDB_CONTROL_STATISTICS:
1074 len = ctdb_statistics_len(cd->data.stats);
1075 break;
1077 case CTDB_CONTROL_PING:
1078 break;
1080 case CTDB_CONTROL_GETDBPATH:
1081 len = ctdb_string_len(&cd->data.db_path);
1082 break;
1084 case CTDB_CONTROL_GETVNNMAP:
1085 len = ctdb_vnn_map_len(cd->data.vnnmap);
1086 break;
1088 case CTDB_CONTROL_SETVNNMAP:
1089 break;
1091 case CTDB_CONTROL_GET_DEBUG:
1092 len = ctdb_uint32_len(&cd->data.loglevel);
1093 break;
1095 case CTDB_CONTROL_SET_DEBUG:
1096 break;
1098 case CTDB_CONTROL_GET_DBMAP:
1099 len = ctdb_dbid_map_len(cd->data.dbmap);
1100 break;
1102 case CTDB_CONTROL_GET_RECMODE:
1103 break;
1105 case CTDB_CONTROL_SET_RECMODE:
1106 break;
1108 case CTDB_CONTROL_STATISTICS_RESET:
1109 break;
1111 case CTDB_CONTROL_DB_ATTACH:
1112 len = ctdb_uint32_len(&cd->data.db_id);
1113 break;
1115 case CTDB_CONTROL_TRAVERSE_START:
1116 break;
1118 case CTDB_CONTROL_TRAVERSE_ALL:
1119 break;
1121 case CTDB_CONTROL_TRAVERSE_DATA:
1122 break;
1124 case CTDB_CONTROL_REGISTER_SRVID:
1125 break;
1127 case CTDB_CONTROL_DEREGISTER_SRVID:
1128 break;
1130 case CTDB_CONTROL_GET_DBNAME:
1131 len = ctdb_string_len(&cd->data.db_name);
1132 break;
1134 case CTDB_CONTROL_ENABLE_SEQNUM:
1135 break;
1137 case CTDB_CONTROL_UPDATE_SEQNUM:
1138 break;
1140 case CTDB_CONTROL_DUMP_MEMORY:
1141 len = ctdb_string_len(&cd->data.mem_str);
1142 break;
1144 case CTDB_CONTROL_GET_PID:
1145 break;
1147 case CTDB_CONTROL_FREEZE:
1148 break;
1150 case CTDB_CONTROL_GET_PNN:
1151 break;
1153 case CTDB_CONTROL_SHUTDOWN:
1154 break;
1156 case CTDB_CONTROL_TCP_CLIENT:
1157 break;
1159 case CTDB_CONTROL_TCP_ADD:
1160 break;
1162 case CTDB_CONTROL_TCP_REMOVE:
1163 break;
1165 case CTDB_CONTROL_STARTUP:
1166 break;
1168 case CTDB_CONTROL_SET_TUNABLE:
1169 break;
1171 case CTDB_CONTROL_GET_TUNABLE:
1172 len = ctdb_uint32_len(&cd->data.tun_value);
1173 break;
1175 case CTDB_CONTROL_LIST_TUNABLES:
1176 len = ctdb_var_list_len(cd->data.tun_var_list);
1177 break;
1179 case CTDB_CONTROL_MODIFY_FLAGS:
1180 break;
1182 case CTDB_CONTROL_GET_ALL_TUNABLES:
1183 len = ctdb_tunable_list_len(cd->data.tun_list);
1184 break;
1186 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1187 len = ctdb_tickle_list_len(cd->data.tickles);
1188 break;
1190 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
1191 break;
1193 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1194 len = ctdb_uint32_len(&cd->data.db_id);
1195 break;
1197 case CTDB_CONTROL_UPDATE_RECORD:
1198 break;
1200 case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
1201 break;
1203 case CTDB_CONTROL_WIPE_DATABASE:
1204 break;
1206 case CTDB_CONTROL_UPTIME:
1207 len = ctdb_uptime_len(cd->data.uptime);
1208 break;
1210 case CTDB_CONTROL_START_RECOVERY:
1211 break;
1213 case CTDB_CONTROL_END_RECOVERY:
1214 break;
1216 case CTDB_CONTROL_RELOAD_NODES_FILE:
1217 break;
1219 case CTDB_CONTROL_TRY_DELETE_RECORDS:
1220 len = ctdb_rec_buffer_len(cd->data.recbuf);
1221 break;
1223 case CTDB_CONTROL_ADD_PUBLIC_IP:
1224 break;
1226 case CTDB_CONTROL_DEL_PUBLIC_IP:
1227 break;
1229 case CTDB_CONTROL_GET_CAPABILITIES:
1230 len = ctdb_uint32_len(&cd->data.caps);
1231 break;
1233 case CTDB_CONTROL_RECD_PING:
1234 break;
1236 case CTDB_CONTROL_RELEASE_IP:
1237 break;
1239 case CTDB_CONTROL_TAKEOVER_IP:
1240 break;
1242 case CTDB_CONTROL_GET_PUBLIC_IPS:
1243 len = ctdb_public_ip_list_len(cd->data.pubip_list);
1244 break;
1246 case CTDB_CONTROL_GET_NODEMAP:
1247 len = ctdb_node_map_len(cd->data.nodemap);
1248 break;
1250 case CTDB_CONTROL_TRAVERSE_KILL:
1251 break;
1253 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
1254 break;
1256 case CTDB_CONTROL_GET_RECLOCK_FILE:
1257 len = ctdb_string_len(&cd->data.reclock_file);
1258 break;
1260 case CTDB_CONTROL_STOP_NODE:
1261 break;
1263 case CTDB_CONTROL_CONTINUE_NODE:
1264 break;
1266 case CTDB_CONTROL_SET_LMASTERROLE:
1267 break;
1269 case CTDB_CONTROL_SET_RECMASTERROLE:
1270 break;
1272 case CTDB_CONTROL_SET_BAN_STATE:
1273 break;
1275 case CTDB_CONTROL_GET_BAN_STATE:
1276 len = ctdb_ban_state_len(cd->data.ban_state);
1277 break;
1279 case CTDB_CONTROL_REGISTER_NOTIFY:
1280 break;
1282 case CTDB_CONTROL_DEREGISTER_NOTIFY:
1283 break;
1285 case CTDB_CONTROL_TRANS3_COMMIT:
1286 break;
1288 case CTDB_CONTROL_GET_DB_SEQNUM:
1289 len = ctdb_uint64_len(&cd->data.seqnum);
1290 break;
1292 case CTDB_CONTROL_DB_SET_HEALTHY:
1293 break;
1295 case CTDB_CONTROL_DB_GET_HEALTH:
1296 len = ctdb_string_len(&cd->data.reason);
1297 break;
1299 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1300 len = ctdb_public_ip_info_len(cd->data.ipinfo);
1301 break;
1303 case CTDB_CONTROL_GET_IFACES:
1304 len = ctdb_iface_list_len(cd->data.iface_list);
1305 break;
1307 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
1308 break;
1310 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
1311 break;
1313 case CTDB_CONTROL_GET_STAT_HISTORY:
1314 len = ctdb_statistics_list_len(cd->data.stats_list);
1315 break;
1317 case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
1318 break;
1320 case CTDB_CONTROL_SET_DB_READONLY:
1321 break;
1323 case CTDB_CONTROL_TRAVERSE_START_EXT:
1324 break;
1326 case CTDB_CONTROL_GET_DB_STATISTICS:
1327 len = ctdb_db_statistics_len(cd->data.dbstats);
1328 break;
1330 case CTDB_CONTROL_SET_DB_STICKY:
1331 break;
1333 case CTDB_CONTROL_RELOAD_PUBLIC_IPS:
1334 break;
1336 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
1337 break;
1339 case CTDB_CONTROL_IPREALLOCATED:
1340 break;
1342 case CTDB_CONTROL_GET_RUNSTATE:
1343 len = ctdb_uint32_len(&cd->data.runstate);
1344 break;
1346 case CTDB_CONTROL_DB_DETACH:
1347 break;
1349 case CTDB_CONTROL_GET_NODES_FILE:
1350 len = ctdb_node_map_len(cd->data.nodemap);
1351 break;
1353 case CTDB_CONTROL_DB_FREEZE:
1354 break;
1356 case CTDB_CONTROL_DB_THAW:
1357 break;
1359 case CTDB_CONTROL_DB_TRANSACTION_START:
1360 break;
1362 case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
1363 break;
1365 case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
1366 break;
1368 case CTDB_CONTROL_DB_PULL:
1369 len = ctdb_uint32_len(&cd->data.num_records);
1370 break;
1372 case CTDB_CONTROL_DB_PUSH_START:
1373 break;
1375 case CTDB_CONTROL_DB_PUSH_CONFIRM:
1376 len = ctdb_uint32_len(&cd->data.num_records);
1377 break;
1379 case CTDB_CONTROL_DB_OPEN_FLAGS:
1380 len = ctdb_int32_len(&cd->data.tdb_flags);
1381 break;
1383 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1384 len = ctdb_uint32_len(&cd->data.db_id);
1385 break;
1387 case CTDB_CONTROL_CHECK_PID_SRVID:
1388 break;
1390 case CTDB_CONTROL_TUNNEL_REGISTER:
1391 break;
1393 case CTDB_CONTROL_TUNNEL_DEREGISTER:
1394 break;
1396 case CTDB_CONTROL_VACUUM_FETCH:
1397 break;
1399 case CTDB_CONTROL_DB_VACUUM:
1400 break;
1402 case CTDB_CONTROL_ECHO_DATA:
1403 len = ctdb_echo_data_len(cd->data.echo_data);
1404 break;
1406 case CTDB_CONTROL_DISABLE_NODE:
1407 break;
1409 case CTDB_CONTROL_ENABLE_NODE:
1410 break;
1412 case CTDB_CONTROL_TCP_CLIENT_DISCONNECTED:
1413 break;
1415 case CTDB_CONTROL_TCP_CLIENT_PASSED:
1416 break;
1419 return len;
1422 static void ctdb_reply_control_data_push(struct ctdb_reply_control_data *cd,
1423 uint8_t *buf, size_t *npush)
1425 size_t np = 0;
1427 switch (cd->opcode) {
1428 case CTDB_CONTROL_STATISTICS:
1429 ctdb_statistics_push(cd->data.stats, buf, &np);
1430 break;
1432 case CTDB_CONTROL_GETDBPATH:
1433 ctdb_string_push(&cd->data.db_path, buf, &np);
1434 break;
1436 case CTDB_CONTROL_GETVNNMAP:
1437 ctdb_vnn_map_push(cd->data.vnnmap, buf, &np);
1438 break;
1440 case CTDB_CONTROL_GET_DEBUG:
1441 ctdb_uint32_push(&cd->data.loglevel, buf, &np);
1442 break;
1444 case CTDB_CONTROL_GET_DBMAP:
1445 ctdb_dbid_map_push(cd->data.dbmap, buf, &np);
1446 break;
1448 case CTDB_CONTROL_DB_ATTACH:
1449 ctdb_uint32_push(&cd->data.db_id, buf, &np);
1450 break;
1452 case CTDB_CONTROL_GET_DBNAME:
1453 ctdb_string_push(&cd->data.db_name, buf, &np);
1454 break;
1456 case CTDB_CONTROL_DUMP_MEMORY:
1457 ctdb_string_push(&cd->data.mem_str, buf, &np);
1458 break;
1460 case CTDB_CONTROL_GET_PID:
1461 break;
1463 case CTDB_CONTROL_GET_TUNABLE:
1464 ctdb_uint32_push(&cd->data.tun_value, buf, &np);
1465 break;
1467 case CTDB_CONTROL_LIST_TUNABLES:
1468 ctdb_var_list_push(cd->data.tun_var_list, buf, &np);
1469 break;
1471 case CTDB_CONTROL_GET_ALL_TUNABLES:
1472 ctdb_tunable_list_push(cd->data.tun_list, buf, &np);
1473 break;
1475 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1476 ctdb_tickle_list_push(cd->data.tickles, buf, &np);
1477 break;
1479 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1480 ctdb_uint32_push(&cd->data.db_id, buf, &np);
1481 break;
1483 case CTDB_CONTROL_UPTIME:
1484 ctdb_uptime_push(cd->data.uptime, buf, &np);
1485 break;
1487 case CTDB_CONTROL_TRY_DELETE_RECORDS:
1488 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
1489 break;
1491 case CTDB_CONTROL_GET_CAPABILITIES:
1492 ctdb_uint32_push(&cd->data.caps, buf, &np);
1493 break;
1495 case CTDB_CONTROL_GET_PUBLIC_IPS:
1496 ctdb_public_ip_list_push(cd->data.pubip_list, buf, &np);
1497 break;
1499 case CTDB_CONTROL_GET_NODEMAP:
1500 ctdb_node_map_push(cd->data.nodemap, buf, &np);
1501 break;
1503 case CTDB_CONTROL_GET_RECLOCK_FILE:
1504 ctdb_string_push(&cd->data.reclock_file, buf, &np);
1505 break;
1507 case CTDB_CONTROL_GET_BAN_STATE:
1508 ctdb_ban_state_push(cd->data.ban_state, buf, &np);
1509 break;
1511 case CTDB_CONTROL_GET_DB_SEQNUM:
1512 ctdb_uint64_push(&cd->data.seqnum, buf, &np);
1513 break;
1515 case CTDB_CONTROL_DB_GET_HEALTH:
1516 ctdb_string_push(&cd->data.reason, buf, &np);
1517 break;
1519 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1520 ctdb_public_ip_info_push(cd->data.ipinfo, buf, &np);
1521 break;
1523 case CTDB_CONTROL_GET_IFACES:
1524 ctdb_iface_list_push(cd->data.iface_list, buf, &np);
1525 break;
1527 case CTDB_CONTROL_GET_STAT_HISTORY:
1528 ctdb_statistics_list_push(cd->data.stats_list, buf, &np);
1529 break;
1531 case CTDB_CONTROL_GET_DB_STATISTICS:
1532 ctdb_db_statistics_push(cd->data.dbstats, buf, &np);
1533 break;
1535 case CTDB_CONTROL_GET_RUNSTATE:
1536 ctdb_uint32_push(&cd->data.runstate, buf, &np);
1537 break;
1539 case CTDB_CONTROL_GET_NODES_FILE:
1540 ctdb_node_map_push(cd->data.nodemap, buf, &np);
1541 break;
1543 case CTDB_CONTROL_DB_PULL:
1544 ctdb_uint32_push(&cd->data.num_records, buf, &np);
1545 break;
1547 case CTDB_CONTROL_DB_PUSH_CONFIRM:
1548 ctdb_uint32_push(&cd->data.num_records, buf, &np);
1549 break;
1551 case CTDB_CONTROL_DB_OPEN_FLAGS:
1552 ctdb_int32_push(&cd->data.tdb_flags, buf, &np);
1553 break;
1555 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1556 ctdb_uint32_push(&cd->data.db_id, buf, &np);
1557 break;
1559 case CTDB_CONTROL_CHECK_PID_SRVID:
1560 break;
1562 case CTDB_CONTROL_VACUUM_FETCH:
1563 break;
1565 case CTDB_CONTROL_DB_VACUUM:
1566 break;
1568 case CTDB_CONTROL_ECHO_DATA:
1569 ctdb_echo_data_push(cd->data.echo_data, buf, &np);
1570 break;
1573 *npush = np;
1576 static int ctdb_reply_control_data_pull(uint8_t *buf, size_t buflen,
1577 uint32_t opcode, TALLOC_CTX *mem_ctx,
1578 struct ctdb_reply_control_data *cd,
1579 size_t *npull)
1581 size_t np = 0;
1582 int ret = 0;
1584 cd->opcode = opcode;
1586 switch (opcode) {
1587 case CTDB_CONTROL_STATISTICS:
1588 ret = ctdb_statistics_pull(buf, buflen, mem_ctx,
1589 &cd->data.stats, &np);
1590 break;
1592 case CTDB_CONTROL_GETDBPATH:
1593 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1594 &cd->data.db_path, &np);
1595 break;
1597 case CTDB_CONTROL_GETVNNMAP:
1598 ret = ctdb_vnn_map_pull(buf, buflen, mem_ctx,
1599 &cd->data.vnnmap, &np);
1600 break;
1602 case CTDB_CONTROL_GET_DEBUG:
1603 ret = ctdb_uint32_pull(buf, buflen, &cd->data.loglevel, &np);
1604 break;
1606 case CTDB_CONTROL_GET_DBMAP:
1607 ret = ctdb_dbid_map_pull(buf, buflen, mem_ctx,
1608 &cd->data.dbmap, &np);
1609 break;
1611 case CTDB_CONTROL_DB_ATTACH:
1612 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1613 break;
1615 case CTDB_CONTROL_GET_DBNAME:
1616 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1617 &cd->data.db_name, &np);
1618 break;
1620 case CTDB_CONTROL_DUMP_MEMORY:
1621 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1622 &cd->data.mem_str, &np);
1623 break;
1625 case CTDB_CONTROL_GET_PID:
1626 break;
1628 case CTDB_CONTROL_GET_TUNABLE:
1629 ret = ctdb_uint32_pull(buf, buflen, &cd->data.tun_value,
1630 &np);
1631 break;
1633 case CTDB_CONTROL_LIST_TUNABLES:
1634 ret = ctdb_var_list_pull(buf, buflen, mem_ctx,
1635 &cd->data.tun_var_list, &np);
1636 break;
1638 case CTDB_CONTROL_GET_ALL_TUNABLES:
1639 ret = ctdb_tunable_list_pull(buf, buflen, mem_ctx,
1640 &cd->data.tun_list, &np);
1641 break;
1643 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1644 ret = ctdb_tickle_list_pull(buf, buflen, mem_ctx,
1645 &cd->data.tickles, &np);
1646 break;
1648 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1649 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1650 break;
1652 case CTDB_CONTROL_UPTIME:
1653 ret = ctdb_uptime_pull(buf, buflen, mem_ctx,
1654 &cd->data.uptime, &np);
1655 break;
1657 case CTDB_CONTROL_TRY_DELETE_RECORDS:
1658 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
1659 &cd->data.recbuf, &np);
1660 break;
1662 case CTDB_CONTROL_GET_CAPABILITIES:
1663 ret = ctdb_uint32_pull(buf, buflen, &cd->data.caps, &np);
1664 break;
1666 case CTDB_CONTROL_GET_PUBLIC_IPS:
1667 ret = ctdb_public_ip_list_pull(buf, buflen, mem_ctx,
1668 &cd->data.pubip_list, &np);
1669 break;
1671 case CTDB_CONTROL_GET_NODEMAP:
1672 ret = ctdb_node_map_pull(buf, buflen, mem_ctx,
1673 &cd->data.nodemap, &np);
1674 break;
1676 case CTDB_CONTROL_GET_RECLOCK_FILE:
1677 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1678 &cd->data.reclock_file, &np);
1679 break;
1681 case CTDB_CONTROL_GET_BAN_STATE:
1682 ret = ctdb_ban_state_pull(buf, buflen, mem_ctx,
1683 &cd->data.ban_state, &np);
1684 break;
1686 case CTDB_CONTROL_GET_DB_SEQNUM:
1687 ret = ctdb_uint64_pull(buf, buflen, &cd->data.seqnum, &np);
1688 break;
1690 case CTDB_CONTROL_DB_GET_HEALTH:
1691 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1692 &cd->data.reason, &np);
1693 break;
1695 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1696 ret = ctdb_public_ip_info_pull(buf, buflen, mem_ctx,
1697 &cd->data.ipinfo, &np);
1698 break;
1700 case CTDB_CONTROL_GET_IFACES:
1701 ret = ctdb_iface_list_pull(buf, buflen, mem_ctx,
1702 &cd->data.iface_list, &np);
1703 break;
1705 case CTDB_CONTROL_GET_STAT_HISTORY:
1706 ret = ctdb_statistics_list_pull(buf, buflen, mem_ctx,
1707 &cd->data.stats_list, &np);
1708 break;
1710 case CTDB_CONTROL_GET_DB_STATISTICS:
1711 ret = ctdb_db_statistics_pull(buf, buflen, mem_ctx,
1712 &cd->data.dbstats, &np);
1713 break;
1715 case CTDB_CONTROL_GET_RUNSTATE:
1716 ret = ctdb_uint32_pull(buf, buflen, &cd->data.runstate, &np);
1717 break;
1719 case CTDB_CONTROL_GET_NODES_FILE:
1720 ret = ctdb_node_map_pull(buf, buflen, mem_ctx,
1721 &cd->data.nodemap, &np);
1722 break;
1724 case CTDB_CONTROL_DB_PULL:
1725 ret = ctdb_uint32_pull(buf, buflen, &cd->data.num_records,
1726 &np);
1727 break;
1729 case CTDB_CONTROL_DB_PUSH_CONFIRM:
1730 ret = ctdb_uint32_pull(buf, buflen, &cd->data.num_records,
1731 &np);
1732 break;
1734 case CTDB_CONTROL_DB_OPEN_FLAGS:
1735 ret = ctdb_int32_pull(buf, buflen, &cd->data.tdb_flags, &np);
1736 break;
1738 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1739 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1740 break;
1742 case CTDB_CONTROL_CHECK_PID_SRVID:
1743 break;
1745 case CTDB_CONTROL_VACUUM_FETCH:
1746 break;
1748 case CTDB_CONTROL_DB_VACUUM:
1749 break;
1751 case CTDB_CONTROL_ECHO_DATA:
1752 ret = ctdb_echo_data_pull(buf,
1753 buflen,
1754 mem_ctx,
1755 &cd->data.echo_data,
1756 &np);
1757 break;
1760 if (ret != 0) {
1761 return ret;
1764 *npull = np;
1765 return 0;
1768 size_t ctdb_req_control_len(struct ctdb_req_header *h,
1769 struct ctdb_req_control *c)
1771 uint32_t u32 = 0;
1773 return ctdb_req_header_len(h) +
1774 ctdb_uint32_len(&c->opcode) +
1775 ctdb_uint32_len(&c->pad) +
1776 ctdb_uint64_len(&c->srvid) +
1777 ctdb_uint32_len(&c->client_id) +
1778 ctdb_uint32_len(&c->flags) +
1779 ctdb_uint32_len(&u32) +
1780 ctdb_req_control_data_len(&c->rdata);
1783 int ctdb_req_control_push(struct ctdb_req_header *h,
1784 struct ctdb_req_control *c,
1785 uint8_t *buf, size_t *buflen)
1787 size_t offset = 0, np;
1788 size_t length;
1789 uint32_t u32;
1791 length = ctdb_req_control_len(h, c);
1792 if (*buflen < length) {
1793 *buflen = length;
1794 return EMSGSIZE;
1797 h->length = *buflen;
1798 ctdb_req_header_push(h, buf+offset, &np);
1799 offset += np;
1801 ctdb_uint32_push(&c->opcode, buf+offset, &np);
1802 offset += np;
1804 ctdb_uint32_push(&c->pad, buf+offset, &np);
1805 offset += np;
1807 ctdb_uint64_push(&c->srvid, buf+offset, &np);
1808 offset += np;
1810 ctdb_uint32_push(&c->client_id, buf+offset, &np);
1811 offset += np;
1813 ctdb_uint32_push(&c->flags, buf+offset, &np);
1814 offset += np;
1816 u32 = ctdb_req_control_data_len(&c->rdata);
1817 ctdb_uint32_push(&u32, buf+offset, &np);
1818 offset += np;
1820 ctdb_req_control_data_push(&c->rdata, buf+offset, &np);
1821 offset += np;
1823 if (offset > *buflen) {
1824 return EMSGSIZE;
1827 return 0;
1830 int ctdb_req_control_pull(uint8_t *buf, size_t buflen,
1831 struct ctdb_req_header *h,
1832 TALLOC_CTX *mem_ctx,
1833 struct ctdb_req_control *c)
1835 struct ctdb_req_header header;
1836 size_t offset = 0, np;
1837 uint32_t u32;
1838 int ret;
1840 ret = ctdb_req_header_pull(buf+offset, buflen-offset, &header, &np);
1841 if (ret != 0) {
1842 return ret;
1844 offset += np;
1846 if (h != NULL) {
1847 *h = header;
1850 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->opcode, &np);
1851 if (ret != 0) {
1852 return ret;
1854 offset += np;
1856 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->pad, &np);
1857 if (ret != 0) {
1858 return ret;
1860 offset += np;
1862 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &c->srvid, &np);
1863 if (ret != 0) {
1864 return ret;
1866 offset += np;
1868 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->client_id, &np);
1869 if (ret != 0) {
1870 return ret;
1872 offset += np;
1874 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->flags, &np);
1875 if (ret != 0) {
1876 return ret;
1878 offset += np;
1880 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
1881 if (ret != 0) {
1882 return ret;
1884 offset += np;
1886 if (u32 > buflen-offset) {
1887 return EMSGSIZE;
1890 ret = ctdb_req_control_data_pull(buf+offset, u32, c->opcode, mem_ctx,
1891 &c->rdata, &np);
1892 if (ret != 0) {
1893 return ret;
1895 offset += np;
1897 if (offset > buflen) {
1898 return EMSGSIZE;
1901 return 0;
1904 size_t ctdb_reply_control_len(struct ctdb_req_header *h,
1905 struct ctdb_reply_control *c)
1907 uint32_t dsize, esize;
1909 if (c->status == 0) {
1910 dsize = ctdb_reply_control_data_len(&c->rdata);
1911 esize = 0;
1912 } else {
1913 dsize = 0;
1914 esize = ctdb_string_len(&c->errmsg);
1917 return ctdb_req_header_len(h) +
1918 ctdb_int32_len(&c->status) +
1919 ctdb_uint32_len(&dsize) +
1920 ctdb_uint32_len(&esize) +
1921 dsize + esize;
1924 int ctdb_reply_control_push(struct ctdb_req_header *h,
1925 struct ctdb_reply_control *c,
1926 uint8_t *buf, size_t *buflen)
1928 size_t offset = 0, np;
1929 size_t length;
1930 uint32_t dsize, esize;
1932 length = ctdb_reply_control_len(h, c);
1933 if (*buflen < length) {
1934 *buflen = length;
1935 return EMSGSIZE;
1938 h->length = *buflen;
1939 ctdb_req_header_push(h, buf+offset, &np);
1940 offset += np;
1942 ctdb_int32_push(&c->status, buf+offset, &np);
1943 offset += np;
1945 if (c->status == 0) {
1946 dsize = ctdb_reply_control_data_len(&c->rdata);
1947 esize = 0;
1948 } else {
1949 dsize = 0;
1950 esize = ctdb_string_len(&c->errmsg);
1953 ctdb_uint32_push(&dsize, buf+offset, &np);
1954 offset += np;
1956 ctdb_uint32_push(&esize, buf+offset, &np);
1957 offset += np;
1959 if (c->status == 0) {
1960 ctdb_reply_control_data_push(&c->rdata, buf+offset, &np);
1961 } else {
1962 ctdb_string_push(&c->errmsg, buf+offset, &np);
1964 offset += np;
1966 return 0;
1969 int ctdb_reply_control_pull(uint8_t *buf, size_t buflen, uint32_t opcode,
1970 struct ctdb_req_header *h,
1971 TALLOC_CTX *mem_ctx,
1972 struct ctdb_reply_control *c)
1974 struct ctdb_req_header header;
1975 size_t offset = 0, np;
1976 uint32_t dsize, esize;
1977 int ret;
1979 ret = ctdb_req_header_pull(buf+offset, buflen-offset, &header, &np);
1980 if (ret != 0) {
1981 return ret;
1983 offset += np;
1985 if (h != NULL) {
1986 *h = header;
1989 ret = ctdb_int32_pull(buf+offset, buflen-offset, &c->status, &np);
1990 if (ret != 0) {
1991 return ret;
1993 offset += np;
1995 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &dsize, &np);
1996 if (ret != 0) {
1997 return ret;
1999 offset += np;
2001 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &esize, &np);
2002 if (ret != 0) {
2003 return ret;
2005 offset += np;
2007 c->errmsg = NULL;
2009 if (c->status == 0) {
2010 if (buflen-offset < dsize) {
2011 return EMSGSIZE;
2014 ret = ctdb_reply_control_data_pull(buf+offset, dsize,
2015 opcode, mem_ctx, &c->rdata,
2016 &np);
2017 if (ret != 0) {
2018 return ret;
2020 offset += np;
2022 } else {
2023 if (buflen-offset < esize) {
2024 return EMSGSIZE;
2027 ret = ctdb_string_pull(buf+offset, esize, mem_ctx, &c->errmsg,
2028 &np);
2029 if (ret != 0) {
2030 return ret;
2032 offset += np;
2035 return 0;