third_party/heimdal_build: Make Heimdal version strings const
[Samba.git] / ctdb / protocol / protocol_control.c
bloba7c797f5dbca2d818d2cf91cab6417b0302860bb
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;
415 return len;
418 static void ctdb_req_control_data_push(struct ctdb_req_control_data *cd,
419 uint8_t *buf, size_t *npush)
421 size_t np = 0, offset;
422 uint32_t u32;
424 switch (cd->opcode) {
425 case CTDB_CONTROL_PROCESS_EXISTS:
426 ctdb_pid_push(&cd->data.pid, buf, &np);
427 break;
429 case CTDB_CONTROL_GETDBPATH:
430 ctdb_uint32_push(&cd->data.db_id, buf, &np);
431 break;
433 case CTDB_CONTROL_SETVNNMAP:
434 ctdb_vnn_map_push(cd->data.vnnmap, buf, &np);
435 break;
437 case CTDB_CONTROL_SET_DEBUG:
438 ctdb_uint32_push(&cd->data.loglevel, buf, &np);
439 break;
441 case CTDB_CONTROL_SET_RECMODE:
442 ctdb_uint32_push(&cd->data.recmode, buf, &np);
443 break;
445 case CTDB_CONTROL_DB_ATTACH:
446 ctdb_string_push(&cd->data.db_name, buf, &np);
447 break;
449 case CTDB_CONTROL_TRAVERSE_START:
450 ctdb_traverse_start_push(cd->data.traverse_start, buf, &np);
451 break;
453 case CTDB_CONTROL_TRAVERSE_ALL:
454 ctdb_traverse_all_push(cd->data.traverse_all, buf, &np);
455 break;
457 case CTDB_CONTROL_TRAVERSE_DATA:
458 ctdb_rec_data_push(cd->data.rec_data, buf, &np);
459 break;
461 case CTDB_CONTROL_GET_DBNAME:
462 ctdb_uint32_push(&cd->data.db_id, buf, &np);
463 break;
465 case CTDB_CONTROL_ENABLE_SEQNUM:
466 ctdb_uint32_push(&cd->data.db_id, buf, &np);
467 break;
469 case CTDB_CONTROL_UPDATE_SEQNUM:
470 ctdb_uint32_push(&cd->data.db_id, buf, &np);
471 break;
473 case CTDB_CONTROL_TCP_CLIENT:
474 ctdb_connection_push(cd->data.conn, buf, &np);
475 break;
477 case CTDB_CONTROL_TCP_ADD:
478 ctdb_connection_push(cd->data.conn, buf, &np);
479 break;
481 case CTDB_CONTROL_TCP_REMOVE:
482 ctdb_connection_push(cd->data.conn, buf, &np);
483 break;
485 case CTDB_CONTROL_SET_TUNABLE:
486 ctdb_tunable_push(cd->data.tunable, buf, &np);
487 break;
489 case CTDB_CONTROL_GET_TUNABLE:
490 ctdb_stringn_push(&cd->data.tun_var, buf, &np);
491 break;
493 case CTDB_CONTROL_MODIFY_FLAGS:
494 ctdb_node_flag_change_push(cd->data.flag_change, buf, &np);
495 break;
497 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
498 ctdb_sock_addr_push(cd->data.addr, buf, &np);
499 break;
501 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
502 ctdb_tickle_list_push(cd->data.tickles, buf, &np);
503 break;
505 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
506 ctdb_string_push(&cd->data.db_name, buf, &np);
507 break;
509 case CTDB_CONTROL_UPDATE_RECORD:
510 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
511 break;
513 case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
514 ctdb_addr_info_push(cd->data.addr_info, buf, &np);
515 break;
517 case CTDB_CONTROL_WIPE_DATABASE:
518 ctdb_transdb_push(cd->data.transdb, buf, &np);
519 break;
521 case CTDB_CONTROL_TRY_DELETE_RECORDS:
522 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
523 break;
525 case CTDB_CONTROL_ADD_PUBLIC_IP:
526 ctdb_addr_info_push(cd->data.addr_info, buf, &np);
527 break;
529 case CTDB_CONTROL_DEL_PUBLIC_IP:
530 ctdb_addr_info_push(cd->data.addr_info, buf, &np);
531 break;
533 case CTDB_CONTROL_RELEASE_IP:
534 ctdb_public_ip_push(cd->data.pubip, buf, &np);
535 break;
537 case CTDB_CONTROL_TAKEOVER_IP:
538 ctdb_public_ip_push(cd->data.pubip, buf, &np);
539 break;
541 case CTDB_CONTROL_TRAVERSE_KILL:
542 ctdb_traverse_start_push(cd->data.traverse_start, buf, &np);
543 break;
545 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
546 ctdb_double_push(&cd->data.reclock_latency, buf, &np);
547 break;
549 case CTDB_CONTROL_SET_LMASTERROLE:
550 ctdb_uint32_push(&cd->data.role, buf, &np);
551 break;
553 case CTDB_CONTROL_SET_RECMASTERROLE:
554 ctdb_uint32_push(&cd->data.role, buf, &np);
555 break;
557 case CTDB_CONTROL_SET_BAN_STATE:
558 ctdb_ban_state_push(cd->data.ban_state, buf, &np);
559 break;
561 case CTDB_CONTROL_REGISTER_NOTIFY:
562 ctdb_notify_data_push(cd->data.notify, buf, &np);
563 break;
565 case CTDB_CONTROL_DEREGISTER_NOTIFY:
566 ctdb_uint64_push(&cd->data.srvid, buf, &np);
567 break;
569 case CTDB_CONTROL_TRANS3_COMMIT:
570 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
571 break;
573 case CTDB_CONTROL_GET_DB_SEQNUM:
574 u32 = 0;
575 offset = 0;
576 ctdb_uint32_push(&cd->data.db_id, buf, &np);
577 offset += np;
578 ctdb_uint32_push(&u32, buf+offset, &np);
579 offset += np;
580 np = offset;
581 break;
583 case CTDB_CONTROL_DB_SET_HEALTHY:
584 ctdb_uint32_push(&cd->data.db_id, buf, &np);
585 break;
587 case CTDB_CONTROL_DB_GET_HEALTH:
588 ctdb_uint32_push(&cd->data.db_id, buf, &np);
589 break;
591 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
592 ctdb_sock_addr_push(cd->data.addr, buf, &np);
593 break;
595 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
596 ctdb_iface_push(cd->data.iface, buf, &np);
597 break;
599 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
600 ctdb_connection_push(cd->data.conn, buf, &np);
601 break;
603 case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
604 ctdb_key_data_push(cd->data.key, buf, &np);
605 break;
607 case CTDB_CONTROL_SET_DB_READONLY:
608 ctdb_uint32_push(&cd->data.db_id, buf, &np);
609 break;
611 case CTDB_CONTROL_TRAVERSE_START_EXT:
612 ctdb_traverse_start_ext_push(cd->data.traverse_start_ext, buf,
613 &np);
614 break;
616 case CTDB_CONTROL_GET_DB_STATISTICS:
617 ctdb_uint32_push(&cd->data.db_id, buf, &np);
618 break;
620 case CTDB_CONTROL_SET_DB_STICKY:
621 ctdb_uint32_push(&cd->data.db_id, buf, &np);
622 break;
624 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
625 ctdb_traverse_all_ext_push(cd->data.traverse_all_ext, buf,
626 &np);
627 break;
629 case CTDB_CONTROL_DB_DETACH:
630 ctdb_uint32_push(&cd->data.db_id, buf, &np);
631 break;
633 case CTDB_CONTROL_DB_FREEZE:
634 ctdb_uint32_push(&cd->data.db_id, buf, &np);
635 break;
637 case CTDB_CONTROL_DB_THAW:
638 ctdb_uint32_push(&cd->data.db_id, buf, &np);
639 break;
641 case CTDB_CONTROL_DB_TRANSACTION_START:
642 ctdb_transdb_push(cd->data.transdb, buf, &np);
643 break;
645 case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
646 ctdb_transdb_push(cd->data.transdb, buf, &np);
647 break;
649 case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
650 ctdb_uint32_push(&cd->data.db_id, buf, &np);
651 break;
653 case CTDB_CONTROL_DB_PULL:
654 ctdb_pulldb_ext_push(cd->data.pulldb_ext, buf, &np);
655 break;
657 case CTDB_CONTROL_DB_PUSH_START:
658 ctdb_pulldb_ext_push(cd->data.pulldb_ext, buf, &np);
659 break;
661 case CTDB_CONTROL_DB_PUSH_CONFIRM:
662 ctdb_uint32_push(&cd->data.db_id, buf, &np);
663 break;
665 case CTDB_CONTROL_DB_OPEN_FLAGS:
666 ctdb_uint32_push(&cd->data.db_id, buf, &np);
667 break;
669 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
670 ctdb_string_push(&cd->data.db_name, buf, &np);
671 break;
673 case CTDB_CONTROL_CHECK_PID_SRVID:
674 ctdb_pid_srvid_push(cd->data.pid_srvid, buf, &np);
675 break;
677 case CTDB_CONTROL_VACUUM_FETCH:
678 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
679 break;
681 case CTDB_CONTROL_DB_VACUUM:
682 ctdb_db_vacuum_push(cd->data.db_vacuum, buf, &np);
683 break;
685 case CTDB_CONTROL_ECHO_DATA:
686 ctdb_echo_data_push(cd->data.echo_data, buf, &np);
687 break;
690 *npush = np;
693 static int ctdb_req_control_data_pull(uint8_t *buf, size_t buflen,
694 uint32_t opcode,
695 TALLOC_CTX *mem_ctx,
696 struct ctdb_req_control_data *cd,
697 size_t *npull)
699 size_t np = 0, offset;
700 uint32_t u32;
701 int ret = 0;
703 cd->opcode = opcode;
705 switch (opcode) {
706 case CTDB_CONTROL_PROCESS_EXISTS:
707 ret = ctdb_pid_pull(buf, buflen, &cd->data.pid, &np);
708 break;
710 case CTDB_CONTROL_GETDBPATH:
711 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
712 break;
714 case CTDB_CONTROL_SETVNNMAP:
715 ret = ctdb_vnn_map_pull(buf, buflen, mem_ctx,
716 &cd->data.vnnmap, &np);
717 break;
719 case CTDB_CONTROL_SET_DEBUG:
720 ret = ctdb_uint32_pull(buf, buflen, &cd->data.loglevel, &np);
721 break;
723 case CTDB_CONTROL_SET_RECMODE:
724 ret = ctdb_uint32_pull(buf, buflen, &cd->data.recmode, &np);
725 break;
727 case CTDB_CONTROL_DB_ATTACH:
728 ret = ctdb_string_pull(buf, buflen, mem_ctx,
729 &cd->data.db_name, &np);
730 break;
732 case CTDB_CONTROL_TRAVERSE_START:
733 ret = ctdb_traverse_start_pull(buf, buflen, mem_ctx,
734 &cd->data.traverse_start, &np);
735 break;
737 case CTDB_CONTROL_TRAVERSE_ALL:
738 ret = ctdb_traverse_all_pull(buf, buflen, mem_ctx,
739 &cd->data.traverse_all, &np);
740 break;
742 case CTDB_CONTROL_TRAVERSE_DATA:
743 ret = ctdb_rec_data_pull(buf, buflen, mem_ctx,
744 &cd->data.rec_data, &np);
745 break;
747 case CTDB_CONTROL_GET_DBNAME:
748 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
749 break;
751 case CTDB_CONTROL_ENABLE_SEQNUM:
752 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
753 break;
755 case CTDB_CONTROL_UPDATE_SEQNUM:
756 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
757 break;
759 case CTDB_CONTROL_TCP_CLIENT:
760 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
761 &cd->data.conn, &np);
762 break;
764 case CTDB_CONTROL_TCP_ADD:
765 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
766 &cd->data.conn, &np);
767 break;
769 case CTDB_CONTROL_TCP_REMOVE:
770 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
771 &cd->data.conn, &np);
772 break;
774 case CTDB_CONTROL_SET_TUNABLE:
775 ret = ctdb_tunable_pull(buf, buflen, mem_ctx,
776 &cd->data.tunable, &np);
777 break;
779 case CTDB_CONTROL_GET_TUNABLE:
780 ret = ctdb_stringn_pull(buf, buflen, mem_ctx,
781 &cd->data.tun_var, &np);
782 break;
784 case CTDB_CONTROL_MODIFY_FLAGS:
785 ret = ctdb_node_flag_change_pull(buf, buflen, mem_ctx,
786 &cd->data.flag_change, &np);
787 break;
789 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
790 ret = ctdb_sock_addr_pull(buf, buflen, mem_ctx,
791 &cd->data.addr, &np);
792 break;
794 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
795 ret = ctdb_tickle_list_pull(buf, buflen, mem_ctx,
796 &cd->data.tickles, &np);
797 break;
799 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
800 ret = ctdb_string_pull(buf, buflen, mem_ctx,
801 &cd->data.db_name, &np);
802 break;
804 case CTDB_CONTROL_UPDATE_RECORD:
805 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
806 &cd->data.recbuf, &np);
807 break;
809 case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
810 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
811 &cd->data.addr_info, &np);
812 break;
814 case CTDB_CONTROL_WIPE_DATABASE:
815 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
816 &cd->data.transdb, &np);
817 break;
819 case CTDB_CONTROL_TRY_DELETE_RECORDS:
820 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
821 &cd->data.recbuf, &np);
822 break;
824 case CTDB_CONTROL_ADD_PUBLIC_IP:
825 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
826 &cd->data.addr_info, &np);
827 break;
829 case CTDB_CONTROL_DEL_PUBLIC_IP:
830 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
831 &cd->data.addr_info, &np);
832 break;
834 case CTDB_CONTROL_RELEASE_IP:
835 ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
836 &cd->data.pubip, &np);
837 break;
839 case CTDB_CONTROL_TAKEOVER_IP:
840 ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
841 &cd->data.pubip, &np);
842 break;
844 case CTDB_CONTROL_TRAVERSE_KILL:
845 ret = ctdb_traverse_start_pull(buf, buflen, mem_ctx,
846 &cd->data.traverse_start, &np);
847 break;
849 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
850 ret = ctdb_double_pull(buf, buflen, &cd->data.reclock_latency,
851 &np);
852 break;
854 case CTDB_CONTROL_SET_LMASTERROLE:
855 ret = ctdb_uint32_pull(buf, buflen, &cd->data.role, &np);
856 break;
858 case CTDB_CONTROL_SET_RECMASTERROLE:
859 ret = ctdb_uint32_pull(buf, buflen, &cd->data.role, &np);
860 break;
862 case CTDB_CONTROL_SET_BAN_STATE:
863 ret = ctdb_ban_state_pull(buf, buflen, mem_ctx,
864 &cd->data.ban_state, &np);
865 break;
867 case CTDB_CONTROL_REGISTER_NOTIFY:
868 ret = ctdb_notify_data_pull(buf, buflen, mem_ctx,
869 &cd->data.notify, &np);
870 break;
872 case CTDB_CONTROL_DEREGISTER_NOTIFY:
873 ret = ctdb_uint64_pull(buf, buflen, &cd->data.srvid, &np);
874 break;
876 case CTDB_CONTROL_TRANS3_COMMIT:
877 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
878 &cd->data.recbuf, &np);
879 break;
881 case CTDB_CONTROL_GET_DB_SEQNUM:
882 offset = 0;
883 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
884 if (ret != 0) {
885 break;
887 offset += np;
888 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
889 offset += np;
890 np = offset;
891 break;
893 case CTDB_CONTROL_DB_SET_HEALTHY:
894 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
895 break;
897 case CTDB_CONTROL_DB_GET_HEALTH:
898 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
899 break;
901 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
902 ret = ctdb_sock_addr_pull(buf, buflen, mem_ctx,
903 &cd->data.addr, &np);
904 break;
906 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
907 ret = ctdb_iface_pull(buf, buflen, mem_ctx,
908 &cd->data.iface, &np);
909 break;
911 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
912 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
913 &cd->data.conn, &np);
914 break;
916 case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
917 ret = ctdb_key_data_pull(buf, buflen, mem_ctx,
918 &cd->data.key, &np);
919 break;
921 case CTDB_CONTROL_SET_DB_READONLY:
922 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
923 break;
925 case CTDB_CONTROL_TRAVERSE_START_EXT:
926 ret = ctdb_traverse_start_ext_pull(buf, buflen, mem_ctx,
927 &cd->data.traverse_start_ext,
928 &np);
929 break;
931 case CTDB_CONTROL_GET_DB_STATISTICS:
932 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
933 break;
935 case CTDB_CONTROL_SET_DB_STICKY:
936 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
937 break;
939 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
940 ret = ctdb_traverse_all_ext_pull(buf, buflen, mem_ctx,
941 &cd->data.traverse_all_ext,
942 &np);
943 break;
945 case CTDB_CONTROL_DB_DETACH:
946 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
947 break;
949 case CTDB_CONTROL_DB_FREEZE:
950 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
951 break;
953 case CTDB_CONTROL_DB_THAW:
954 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
955 break;
957 case CTDB_CONTROL_DB_TRANSACTION_START:
958 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
959 &cd->data.transdb, &np);
960 break;
962 case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
963 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
964 &cd->data.transdb, &np);
965 break;
967 case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
968 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
969 break;
971 case CTDB_CONTROL_DB_PULL:
972 ret = ctdb_pulldb_ext_pull(buf, buflen, mem_ctx,
973 &cd->data.pulldb_ext, &np);
974 break;
976 case CTDB_CONTROL_DB_PUSH_START:
977 ret = ctdb_pulldb_ext_pull(buf, buflen, mem_ctx,
978 &cd->data.pulldb_ext, &np);
979 break;
981 case CTDB_CONTROL_DB_PUSH_CONFIRM:
982 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
983 break;
985 case CTDB_CONTROL_DB_OPEN_FLAGS:
986 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
987 break;
989 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
990 ret = ctdb_string_pull(buf, buflen, mem_ctx,
991 &cd->data.db_name, &np);
992 break;
994 case CTDB_CONTROL_CHECK_PID_SRVID:
995 ret = ctdb_pid_srvid_pull(buf, buflen, mem_ctx,
996 &cd->data.pid_srvid, &np);
997 break;
999 case CTDB_CONTROL_VACUUM_FETCH:
1000 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
1001 &cd->data.recbuf, &np);
1002 break;
1004 case CTDB_CONTROL_DB_VACUUM:
1005 ret = ctdb_db_vacuum_pull(buf,
1006 buflen,
1007 mem_ctx,
1008 &cd->data.db_vacuum,
1009 &np);
1010 break;
1012 case CTDB_CONTROL_ECHO_DATA:
1013 ret = ctdb_echo_data_pull(buf,
1014 buflen,
1015 mem_ctx,
1016 &cd->data.echo_data,
1017 &np);
1018 break;
1021 if (ret != 0) {
1022 return ret;
1025 *npull = np;
1026 return 0;
1029 static size_t ctdb_reply_control_data_len(struct ctdb_reply_control_data *cd)
1031 size_t len = 0;
1033 if (cd == NULL) {
1034 return 0;
1037 switch (cd->opcode) {
1038 case CTDB_CONTROL_PROCESS_EXISTS:
1039 break;
1041 case CTDB_CONTROL_STATISTICS:
1042 len = ctdb_statistics_len(cd->data.stats);
1043 break;
1045 case CTDB_CONTROL_PING:
1046 break;
1048 case CTDB_CONTROL_GETDBPATH:
1049 len = ctdb_string_len(&cd->data.db_path);
1050 break;
1052 case CTDB_CONTROL_GETVNNMAP:
1053 len = ctdb_vnn_map_len(cd->data.vnnmap);
1054 break;
1056 case CTDB_CONTROL_SETVNNMAP:
1057 break;
1059 case CTDB_CONTROL_GET_DEBUG:
1060 len = ctdb_uint32_len(&cd->data.loglevel);
1061 break;
1063 case CTDB_CONTROL_SET_DEBUG:
1064 break;
1066 case CTDB_CONTROL_GET_DBMAP:
1067 len = ctdb_dbid_map_len(cd->data.dbmap);
1068 break;
1070 case CTDB_CONTROL_GET_RECMODE:
1071 break;
1073 case CTDB_CONTROL_SET_RECMODE:
1074 break;
1076 case CTDB_CONTROL_STATISTICS_RESET:
1077 break;
1079 case CTDB_CONTROL_DB_ATTACH:
1080 len = ctdb_uint32_len(&cd->data.db_id);
1081 break;
1083 case CTDB_CONTROL_TRAVERSE_START:
1084 break;
1086 case CTDB_CONTROL_TRAVERSE_ALL:
1087 break;
1089 case CTDB_CONTROL_TRAVERSE_DATA:
1090 break;
1092 case CTDB_CONTROL_REGISTER_SRVID:
1093 break;
1095 case CTDB_CONTROL_DEREGISTER_SRVID:
1096 break;
1098 case CTDB_CONTROL_GET_DBNAME:
1099 len = ctdb_string_len(&cd->data.db_name);
1100 break;
1102 case CTDB_CONTROL_ENABLE_SEQNUM:
1103 break;
1105 case CTDB_CONTROL_UPDATE_SEQNUM:
1106 break;
1108 case CTDB_CONTROL_DUMP_MEMORY:
1109 len = ctdb_string_len(&cd->data.mem_str);
1110 break;
1112 case CTDB_CONTROL_GET_PID:
1113 break;
1115 case CTDB_CONTROL_FREEZE:
1116 break;
1118 case CTDB_CONTROL_GET_PNN:
1119 break;
1121 case CTDB_CONTROL_SHUTDOWN:
1122 break;
1124 case CTDB_CONTROL_TCP_CLIENT:
1125 break;
1127 case CTDB_CONTROL_TCP_ADD:
1128 break;
1130 case CTDB_CONTROL_TCP_REMOVE:
1131 break;
1133 case CTDB_CONTROL_STARTUP:
1134 break;
1136 case CTDB_CONTROL_SET_TUNABLE:
1137 break;
1139 case CTDB_CONTROL_GET_TUNABLE:
1140 len = ctdb_uint32_len(&cd->data.tun_value);
1141 break;
1143 case CTDB_CONTROL_LIST_TUNABLES:
1144 len = ctdb_var_list_len(cd->data.tun_var_list);
1145 break;
1147 case CTDB_CONTROL_MODIFY_FLAGS:
1148 break;
1150 case CTDB_CONTROL_GET_ALL_TUNABLES:
1151 len = ctdb_tunable_list_len(cd->data.tun_list);
1152 break;
1154 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1155 len = ctdb_tickle_list_len(cd->data.tickles);
1156 break;
1158 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
1159 break;
1161 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1162 len = ctdb_uint32_len(&cd->data.db_id);
1163 break;
1165 case CTDB_CONTROL_UPDATE_RECORD:
1166 break;
1168 case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
1169 break;
1171 case CTDB_CONTROL_WIPE_DATABASE:
1172 break;
1174 case CTDB_CONTROL_UPTIME:
1175 len = ctdb_uptime_len(cd->data.uptime);
1176 break;
1178 case CTDB_CONTROL_START_RECOVERY:
1179 break;
1181 case CTDB_CONTROL_END_RECOVERY:
1182 break;
1184 case CTDB_CONTROL_RELOAD_NODES_FILE:
1185 break;
1187 case CTDB_CONTROL_TRY_DELETE_RECORDS:
1188 len = ctdb_rec_buffer_len(cd->data.recbuf);
1189 break;
1191 case CTDB_CONTROL_ADD_PUBLIC_IP:
1192 break;
1194 case CTDB_CONTROL_DEL_PUBLIC_IP:
1195 break;
1197 case CTDB_CONTROL_GET_CAPABILITIES:
1198 len = ctdb_uint32_len(&cd->data.caps);
1199 break;
1201 case CTDB_CONTROL_RECD_PING:
1202 break;
1204 case CTDB_CONTROL_RELEASE_IP:
1205 break;
1207 case CTDB_CONTROL_TAKEOVER_IP:
1208 break;
1210 case CTDB_CONTROL_GET_PUBLIC_IPS:
1211 len = ctdb_public_ip_list_len(cd->data.pubip_list);
1212 break;
1214 case CTDB_CONTROL_GET_NODEMAP:
1215 len = ctdb_node_map_len(cd->data.nodemap);
1216 break;
1218 case CTDB_CONTROL_TRAVERSE_KILL:
1219 break;
1221 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
1222 break;
1224 case CTDB_CONTROL_GET_RECLOCK_FILE:
1225 len = ctdb_string_len(&cd->data.reclock_file);
1226 break;
1228 case CTDB_CONTROL_STOP_NODE:
1229 break;
1231 case CTDB_CONTROL_CONTINUE_NODE:
1232 break;
1234 case CTDB_CONTROL_SET_LMASTERROLE:
1235 break;
1237 case CTDB_CONTROL_SET_RECMASTERROLE:
1238 break;
1240 case CTDB_CONTROL_SET_BAN_STATE:
1241 break;
1243 case CTDB_CONTROL_GET_BAN_STATE:
1244 len = ctdb_ban_state_len(cd->data.ban_state);
1245 break;
1247 case CTDB_CONTROL_REGISTER_NOTIFY:
1248 break;
1250 case CTDB_CONTROL_DEREGISTER_NOTIFY:
1251 break;
1253 case CTDB_CONTROL_TRANS3_COMMIT:
1254 break;
1256 case CTDB_CONTROL_GET_DB_SEQNUM:
1257 len = ctdb_uint64_len(&cd->data.seqnum);
1258 break;
1260 case CTDB_CONTROL_DB_SET_HEALTHY:
1261 break;
1263 case CTDB_CONTROL_DB_GET_HEALTH:
1264 len = ctdb_string_len(&cd->data.reason);
1265 break;
1267 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1268 len = ctdb_public_ip_info_len(cd->data.ipinfo);
1269 break;
1271 case CTDB_CONTROL_GET_IFACES:
1272 len = ctdb_iface_list_len(cd->data.iface_list);
1273 break;
1275 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
1276 break;
1278 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
1279 break;
1281 case CTDB_CONTROL_GET_STAT_HISTORY:
1282 len = ctdb_statistics_list_len(cd->data.stats_list);
1283 break;
1285 case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
1286 break;
1288 case CTDB_CONTROL_SET_DB_READONLY:
1289 break;
1291 case CTDB_CONTROL_TRAVERSE_START_EXT:
1292 break;
1294 case CTDB_CONTROL_GET_DB_STATISTICS:
1295 len = ctdb_db_statistics_len(cd->data.dbstats);
1296 break;
1298 case CTDB_CONTROL_SET_DB_STICKY:
1299 break;
1301 case CTDB_CONTROL_RELOAD_PUBLIC_IPS:
1302 break;
1304 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
1305 break;
1307 case CTDB_CONTROL_IPREALLOCATED:
1308 break;
1310 case CTDB_CONTROL_GET_RUNSTATE:
1311 len = ctdb_uint32_len(&cd->data.runstate);
1312 break;
1314 case CTDB_CONTROL_DB_DETACH:
1315 break;
1317 case CTDB_CONTROL_GET_NODES_FILE:
1318 len = ctdb_node_map_len(cd->data.nodemap);
1319 break;
1321 case CTDB_CONTROL_DB_FREEZE:
1322 break;
1324 case CTDB_CONTROL_DB_THAW:
1325 break;
1327 case CTDB_CONTROL_DB_TRANSACTION_START:
1328 break;
1330 case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
1331 break;
1333 case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
1334 break;
1336 case CTDB_CONTROL_DB_PULL:
1337 len = ctdb_uint32_len(&cd->data.num_records);
1338 break;
1340 case CTDB_CONTROL_DB_PUSH_START:
1341 break;
1343 case CTDB_CONTROL_DB_PUSH_CONFIRM:
1344 len = ctdb_uint32_len(&cd->data.num_records);
1345 break;
1347 case CTDB_CONTROL_DB_OPEN_FLAGS:
1348 len = ctdb_int32_len(&cd->data.tdb_flags);
1349 break;
1351 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1352 len = ctdb_uint32_len(&cd->data.db_id);
1353 break;
1355 case CTDB_CONTROL_CHECK_PID_SRVID:
1356 break;
1358 case CTDB_CONTROL_TUNNEL_REGISTER:
1359 break;
1361 case CTDB_CONTROL_TUNNEL_DEREGISTER:
1362 break;
1364 case CTDB_CONTROL_VACUUM_FETCH:
1365 break;
1367 case CTDB_CONTROL_DB_VACUUM:
1368 break;
1370 case CTDB_CONTROL_ECHO_DATA:
1371 len = ctdb_echo_data_len(cd->data.echo_data);
1372 break;
1374 case CTDB_CONTROL_DISABLE_NODE:
1375 break;
1377 case CTDB_CONTROL_ENABLE_NODE:
1378 break;
1381 return len;
1384 static void ctdb_reply_control_data_push(struct ctdb_reply_control_data *cd,
1385 uint8_t *buf, size_t *npush)
1387 size_t np = 0;
1389 switch (cd->opcode) {
1390 case CTDB_CONTROL_STATISTICS:
1391 ctdb_statistics_push(cd->data.stats, buf, &np);
1392 break;
1394 case CTDB_CONTROL_GETDBPATH:
1395 ctdb_string_push(&cd->data.db_path, buf, &np);
1396 break;
1398 case CTDB_CONTROL_GETVNNMAP:
1399 ctdb_vnn_map_push(cd->data.vnnmap, buf, &np);
1400 break;
1402 case CTDB_CONTROL_GET_DEBUG:
1403 ctdb_uint32_push(&cd->data.loglevel, buf, &np);
1404 break;
1406 case CTDB_CONTROL_GET_DBMAP:
1407 ctdb_dbid_map_push(cd->data.dbmap, buf, &np);
1408 break;
1410 case CTDB_CONTROL_DB_ATTACH:
1411 ctdb_uint32_push(&cd->data.db_id, buf, &np);
1412 break;
1414 case CTDB_CONTROL_GET_DBNAME:
1415 ctdb_string_push(&cd->data.db_name, buf, &np);
1416 break;
1418 case CTDB_CONTROL_DUMP_MEMORY:
1419 ctdb_string_push(&cd->data.mem_str, buf, &np);
1420 break;
1422 case CTDB_CONTROL_GET_PID:
1423 break;
1425 case CTDB_CONTROL_GET_TUNABLE:
1426 ctdb_uint32_push(&cd->data.tun_value, buf, &np);
1427 break;
1429 case CTDB_CONTROL_LIST_TUNABLES:
1430 ctdb_var_list_push(cd->data.tun_var_list, buf, &np);
1431 break;
1433 case CTDB_CONTROL_GET_ALL_TUNABLES:
1434 ctdb_tunable_list_push(cd->data.tun_list, buf, &np);
1435 break;
1437 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1438 ctdb_tickle_list_push(cd->data.tickles, buf, &np);
1439 break;
1441 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1442 ctdb_uint32_push(&cd->data.db_id, buf, &np);
1443 break;
1445 case CTDB_CONTROL_UPTIME:
1446 ctdb_uptime_push(cd->data.uptime, buf, &np);
1447 break;
1449 case CTDB_CONTROL_TRY_DELETE_RECORDS:
1450 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
1451 break;
1453 case CTDB_CONTROL_GET_CAPABILITIES:
1454 ctdb_uint32_push(&cd->data.caps, buf, &np);
1455 break;
1457 case CTDB_CONTROL_GET_PUBLIC_IPS:
1458 ctdb_public_ip_list_push(cd->data.pubip_list, buf, &np);
1459 break;
1461 case CTDB_CONTROL_GET_NODEMAP:
1462 ctdb_node_map_push(cd->data.nodemap, buf, &np);
1463 break;
1465 case CTDB_CONTROL_GET_RECLOCK_FILE:
1466 ctdb_string_push(&cd->data.reclock_file, buf, &np);
1467 break;
1469 case CTDB_CONTROL_GET_BAN_STATE:
1470 ctdb_ban_state_push(cd->data.ban_state, buf, &np);
1471 break;
1473 case CTDB_CONTROL_GET_DB_SEQNUM:
1474 ctdb_uint64_push(&cd->data.seqnum, buf, &np);
1475 break;
1477 case CTDB_CONTROL_DB_GET_HEALTH:
1478 ctdb_string_push(&cd->data.reason, buf, &np);
1479 break;
1481 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1482 ctdb_public_ip_info_push(cd->data.ipinfo, buf, &np);
1483 break;
1485 case CTDB_CONTROL_GET_IFACES:
1486 ctdb_iface_list_push(cd->data.iface_list, buf, &np);
1487 break;
1489 case CTDB_CONTROL_GET_STAT_HISTORY:
1490 ctdb_statistics_list_push(cd->data.stats_list, buf, &np);
1491 break;
1493 case CTDB_CONTROL_GET_DB_STATISTICS:
1494 ctdb_db_statistics_push(cd->data.dbstats, buf, &np);
1495 break;
1497 case CTDB_CONTROL_GET_RUNSTATE:
1498 ctdb_uint32_push(&cd->data.runstate, buf, &np);
1499 break;
1501 case CTDB_CONTROL_GET_NODES_FILE:
1502 ctdb_node_map_push(cd->data.nodemap, buf, &np);
1503 break;
1505 case CTDB_CONTROL_DB_PULL:
1506 ctdb_uint32_push(&cd->data.num_records, buf, &np);
1507 break;
1509 case CTDB_CONTROL_DB_PUSH_CONFIRM:
1510 ctdb_uint32_push(&cd->data.num_records, buf, &np);
1511 break;
1513 case CTDB_CONTROL_DB_OPEN_FLAGS:
1514 ctdb_int32_push(&cd->data.tdb_flags, buf, &np);
1515 break;
1517 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1518 ctdb_uint32_push(&cd->data.db_id, buf, &np);
1519 break;
1521 case CTDB_CONTROL_CHECK_PID_SRVID:
1522 break;
1524 case CTDB_CONTROL_VACUUM_FETCH:
1525 break;
1527 case CTDB_CONTROL_DB_VACUUM:
1528 break;
1530 case CTDB_CONTROL_ECHO_DATA:
1531 ctdb_echo_data_push(cd->data.echo_data, buf, &np);
1532 break;
1535 *npush = np;
1538 static int ctdb_reply_control_data_pull(uint8_t *buf, size_t buflen,
1539 uint32_t opcode, TALLOC_CTX *mem_ctx,
1540 struct ctdb_reply_control_data *cd,
1541 size_t *npull)
1543 size_t np = 0;
1544 int ret = 0;
1546 cd->opcode = opcode;
1548 switch (opcode) {
1549 case CTDB_CONTROL_STATISTICS:
1550 ret = ctdb_statistics_pull(buf, buflen, mem_ctx,
1551 &cd->data.stats, &np);
1552 break;
1554 case CTDB_CONTROL_GETDBPATH:
1555 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1556 &cd->data.db_path, &np);
1557 break;
1559 case CTDB_CONTROL_GETVNNMAP:
1560 ret = ctdb_vnn_map_pull(buf, buflen, mem_ctx,
1561 &cd->data.vnnmap, &np);
1562 break;
1564 case CTDB_CONTROL_GET_DEBUG:
1565 ret = ctdb_uint32_pull(buf, buflen, &cd->data.loglevel, &np);
1566 break;
1568 case CTDB_CONTROL_GET_DBMAP:
1569 ret = ctdb_dbid_map_pull(buf, buflen, mem_ctx,
1570 &cd->data.dbmap, &np);
1571 break;
1573 case CTDB_CONTROL_DB_ATTACH:
1574 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1575 break;
1577 case CTDB_CONTROL_GET_DBNAME:
1578 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1579 &cd->data.db_name, &np);
1580 break;
1582 case CTDB_CONTROL_DUMP_MEMORY:
1583 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1584 &cd->data.mem_str, &np);
1585 break;
1587 case CTDB_CONTROL_GET_PID:
1588 break;
1590 case CTDB_CONTROL_GET_TUNABLE:
1591 ret = ctdb_uint32_pull(buf, buflen, &cd->data.tun_value,
1592 &np);
1593 break;
1595 case CTDB_CONTROL_LIST_TUNABLES:
1596 ret = ctdb_var_list_pull(buf, buflen, mem_ctx,
1597 &cd->data.tun_var_list, &np);
1598 break;
1600 case CTDB_CONTROL_GET_ALL_TUNABLES:
1601 ret = ctdb_tunable_list_pull(buf, buflen, mem_ctx,
1602 &cd->data.tun_list, &np);
1603 break;
1605 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1606 ret = ctdb_tickle_list_pull(buf, buflen, mem_ctx,
1607 &cd->data.tickles, &np);
1608 break;
1610 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1611 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1612 break;
1614 case CTDB_CONTROL_UPTIME:
1615 ret = ctdb_uptime_pull(buf, buflen, mem_ctx,
1616 &cd->data.uptime, &np);
1617 break;
1619 case CTDB_CONTROL_TRY_DELETE_RECORDS:
1620 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
1621 &cd->data.recbuf, &np);
1622 break;
1624 case CTDB_CONTROL_GET_CAPABILITIES:
1625 ret = ctdb_uint32_pull(buf, buflen, &cd->data.caps, &np);
1626 break;
1628 case CTDB_CONTROL_GET_PUBLIC_IPS:
1629 ret = ctdb_public_ip_list_pull(buf, buflen, mem_ctx,
1630 &cd->data.pubip_list, &np);
1631 break;
1633 case CTDB_CONTROL_GET_NODEMAP:
1634 ret = ctdb_node_map_pull(buf, buflen, mem_ctx,
1635 &cd->data.nodemap, &np);
1636 break;
1638 case CTDB_CONTROL_GET_RECLOCK_FILE:
1639 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1640 &cd->data.reclock_file, &np);
1641 break;
1643 case CTDB_CONTROL_GET_BAN_STATE:
1644 ret = ctdb_ban_state_pull(buf, buflen, mem_ctx,
1645 &cd->data.ban_state, &np);
1646 break;
1648 case CTDB_CONTROL_GET_DB_SEQNUM:
1649 ret = ctdb_uint64_pull(buf, buflen, &cd->data.seqnum, &np);
1650 break;
1652 case CTDB_CONTROL_DB_GET_HEALTH:
1653 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1654 &cd->data.reason, &np);
1655 break;
1657 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1658 ret = ctdb_public_ip_info_pull(buf, buflen, mem_ctx,
1659 &cd->data.ipinfo, &np);
1660 break;
1662 case CTDB_CONTROL_GET_IFACES:
1663 ret = ctdb_iface_list_pull(buf, buflen, mem_ctx,
1664 &cd->data.iface_list, &np);
1665 break;
1667 case CTDB_CONTROL_GET_STAT_HISTORY:
1668 ret = ctdb_statistics_list_pull(buf, buflen, mem_ctx,
1669 &cd->data.stats_list, &np);
1670 break;
1672 case CTDB_CONTROL_GET_DB_STATISTICS:
1673 ret = ctdb_db_statistics_pull(buf, buflen, mem_ctx,
1674 &cd->data.dbstats, &np);
1675 break;
1677 case CTDB_CONTROL_GET_RUNSTATE:
1678 ret = ctdb_uint32_pull(buf, buflen, &cd->data.runstate, &np);
1679 break;
1681 case CTDB_CONTROL_GET_NODES_FILE:
1682 ret = ctdb_node_map_pull(buf, buflen, mem_ctx,
1683 &cd->data.nodemap, &np);
1684 break;
1686 case CTDB_CONTROL_DB_PULL:
1687 ret = ctdb_uint32_pull(buf, buflen, &cd->data.num_records,
1688 &np);
1689 break;
1691 case CTDB_CONTROL_DB_PUSH_CONFIRM:
1692 ret = ctdb_uint32_pull(buf, buflen, &cd->data.num_records,
1693 &np);
1694 break;
1696 case CTDB_CONTROL_DB_OPEN_FLAGS:
1697 ret = ctdb_int32_pull(buf, buflen, &cd->data.tdb_flags, &np);
1698 break;
1700 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1701 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1702 break;
1704 case CTDB_CONTROL_CHECK_PID_SRVID:
1705 break;
1707 case CTDB_CONTROL_VACUUM_FETCH:
1708 break;
1710 case CTDB_CONTROL_DB_VACUUM:
1711 break;
1713 case CTDB_CONTROL_ECHO_DATA:
1714 ret = ctdb_echo_data_pull(buf,
1715 buflen,
1716 mem_ctx,
1717 &cd->data.echo_data,
1718 &np);
1719 break;
1722 if (ret != 0) {
1723 return ret;
1726 *npull = np;
1727 return 0;
1730 size_t ctdb_req_control_len(struct ctdb_req_header *h,
1731 struct ctdb_req_control *c)
1733 uint32_t u32 = 0;
1735 return ctdb_req_header_len(h) +
1736 ctdb_uint32_len(&c->opcode) +
1737 ctdb_uint32_len(&c->pad) +
1738 ctdb_uint64_len(&c->srvid) +
1739 ctdb_uint32_len(&c->client_id) +
1740 ctdb_uint32_len(&c->flags) +
1741 ctdb_uint32_len(&u32) +
1742 ctdb_req_control_data_len(&c->rdata);
1745 int ctdb_req_control_push(struct ctdb_req_header *h,
1746 struct ctdb_req_control *c,
1747 uint8_t *buf, size_t *buflen)
1749 size_t offset = 0, np;
1750 size_t length;
1751 uint32_t u32;
1753 length = ctdb_req_control_len(h, c);
1754 if (*buflen < length) {
1755 *buflen = length;
1756 return EMSGSIZE;
1759 h->length = *buflen;
1760 ctdb_req_header_push(h, buf+offset, &np);
1761 offset += np;
1763 ctdb_uint32_push(&c->opcode, buf+offset, &np);
1764 offset += np;
1766 ctdb_uint32_push(&c->pad, buf+offset, &np);
1767 offset += np;
1769 ctdb_uint64_push(&c->srvid, buf+offset, &np);
1770 offset += np;
1772 ctdb_uint32_push(&c->client_id, buf+offset, &np);
1773 offset += np;
1775 ctdb_uint32_push(&c->flags, buf+offset, &np);
1776 offset += np;
1778 u32 = ctdb_req_control_data_len(&c->rdata);
1779 ctdb_uint32_push(&u32, buf+offset, &np);
1780 offset += np;
1782 ctdb_req_control_data_push(&c->rdata, buf+offset, &np);
1783 offset += np;
1785 if (offset > *buflen) {
1786 return EMSGSIZE;
1789 return 0;
1792 int ctdb_req_control_pull(uint8_t *buf, size_t buflen,
1793 struct ctdb_req_header *h,
1794 TALLOC_CTX *mem_ctx,
1795 struct ctdb_req_control *c)
1797 struct ctdb_req_header header;
1798 size_t offset = 0, np;
1799 uint32_t u32;
1800 int ret;
1802 ret = ctdb_req_header_pull(buf+offset, buflen-offset, &header, &np);
1803 if (ret != 0) {
1804 return ret;
1806 offset += np;
1808 if (h != NULL) {
1809 *h = header;
1812 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->opcode, &np);
1813 if (ret != 0) {
1814 return ret;
1816 offset += np;
1818 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->pad, &np);
1819 if (ret != 0) {
1820 return ret;
1822 offset += np;
1824 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &c->srvid, &np);
1825 if (ret != 0) {
1826 return ret;
1828 offset += np;
1830 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->client_id, &np);
1831 if (ret != 0) {
1832 return ret;
1834 offset += np;
1836 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->flags, &np);
1837 if (ret != 0) {
1838 return ret;
1840 offset += np;
1842 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
1843 if (ret != 0) {
1844 return ret;
1846 offset += np;
1848 if (u32 > buflen-offset) {
1849 return EMSGSIZE;
1852 ret = ctdb_req_control_data_pull(buf+offset, u32, c->opcode, mem_ctx,
1853 &c->rdata, &np);
1854 if (ret != 0) {
1855 return ret;
1857 offset += np;
1859 if (offset > buflen) {
1860 return EMSGSIZE;
1863 return 0;
1866 size_t ctdb_reply_control_len(struct ctdb_req_header *h,
1867 struct ctdb_reply_control *c)
1869 uint32_t dsize, esize;
1871 if (c->status == 0) {
1872 dsize = ctdb_reply_control_data_len(&c->rdata);
1873 esize = 0;
1874 } else {
1875 dsize = 0;
1876 esize = ctdb_string_len(&c->errmsg);
1879 return ctdb_req_header_len(h) +
1880 ctdb_int32_len(&c->status) +
1881 ctdb_uint32_len(&dsize) +
1882 ctdb_uint32_len(&esize) +
1883 dsize + esize;
1886 int ctdb_reply_control_push(struct ctdb_req_header *h,
1887 struct ctdb_reply_control *c,
1888 uint8_t *buf, size_t *buflen)
1890 size_t offset = 0, np;
1891 size_t length;
1892 uint32_t dsize, esize;
1894 length = ctdb_reply_control_len(h, c);
1895 if (*buflen < length) {
1896 *buflen = length;
1897 return EMSGSIZE;
1900 h->length = *buflen;
1901 ctdb_req_header_push(h, buf+offset, &np);
1902 offset += np;
1904 ctdb_int32_push(&c->status, buf+offset, &np);
1905 offset += np;
1907 if (c->status == 0) {
1908 dsize = ctdb_reply_control_data_len(&c->rdata);
1909 esize = 0;
1910 } else {
1911 dsize = 0;
1912 esize = ctdb_string_len(&c->errmsg);
1915 ctdb_uint32_push(&dsize, buf+offset, &np);
1916 offset += np;
1918 ctdb_uint32_push(&esize, buf+offset, &np);
1919 offset += np;
1921 if (c->status == 0) {
1922 ctdb_reply_control_data_push(&c->rdata, buf+offset, &np);
1923 } else {
1924 ctdb_string_push(&c->errmsg, buf+offset, &np);
1926 offset += np;
1928 return 0;
1931 int ctdb_reply_control_pull(uint8_t *buf, size_t buflen, uint32_t opcode,
1932 struct ctdb_req_header *h,
1933 TALLOC_CTX *mem_ctx,
1934 struct ctdb_reply_control *c)
1936 struct ctdb_req_header header;
1937 size_t offset = 0, np;
1938 uint32_t dsize, esize;
1939 int ret;
1941 ret = ctdb_req_header_pull(buf+offset, buflen-offset, &header, &np);
1942 if (ret != 0) {
1943 return ret;
1945 offset += np;
1947 if (h != NULL) {
1948 *h = header;
1951 ret = ctdb_int32_pull(buf+offset, buflen-offset, &c->status, &np);
1952 if (ret != 0) {
1953 return ret;
1955 offset += np;
1957 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &dsize, &np);
1958 if (ret != 0) {
1959 return ret;
1961 offset += np;
1963 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &esize, &np);
1964 if (ret != 0) {
1965 return ret;
1967 offset += np;
1969 c->errmsg = NULL;
1971 if (c->status == 0) {
1972 if (buflen-offset < dsize) {
1973 return EMSGSIZE;
1976 ret = ctdb_reply_control_data_pull(buf+offset, dsize,
1977 opcode, mem_ctx, &c->rdata,
1978 &np);
1979 if (ret != 0) {
1980 return ret;
1982 offset += np;
1984 } else {
1985 if (buflen-offset < esize) {
1986 return EMSGSIZE;
1989 ret = ctdb_string_pull(buf+offset, esize, mem_ctx, &c->errmsg,
1990 &np);
1991 if (ret != 0) {
1992 return ret;
1994 offset += np;
1997 return 0;