libsmb: Add cli_smb2_query_info_fnum
[Samba.git] / ctdb / protocol / protocol_control.c
blob0b88b5c8b5a5016fe5bc0585e67a53c63d0a70ae
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_PULL_DB:
72 len = ctdb_pulldb_len(cd->data.pulldb);
73 break;
75 case CTDB_CONTROL_PUSH_DB:
76 len = ctdb_rec_buffer_len(cd->data.recbuf);
77 break;
79 case CTDB_CONTROL_GET_RECMODE:
80 break;
82 case CTDB_CONTROL_SET_RECMODE:
83 len = ctdb_uint32_len(&cd->data.recmode);
84 break;
86 case CTDB_CONTROL_STATISTICS_RESET:
87 break;
89 case CTDB_CONTROL_DB_ATTACH:
90 len = ctdb_string_len(&cd->data.db_name);
91 break;
93 case CTDB_CONTROL_SET_CALL:
94 break;
96 case CTDB_CONTROL_TRAVERSE_START:
97 len = ctdb_traverse_start_len(cd->data.traverse_start);
98 break;
100 case CTDB_CONTROL_TRAVERSE_ALL:
101 len = ctdb_traverse_all_len(cd->data.traverse_all);
102 break;
104 case CTDB_CONTROL_TRAVERSE_DATA:
105 len = ctdb_rec_data_len(cd->data.rec_data);
106 break;
108 case CTDB_CONTROL_REGISTER_SRVID:
109 break;
111 case CTDB_CONTROL_DEREGISTER_SRVID:
112 break;
114 case CTDB_CONTROL_GET_DBNAME:
115 len = ctdb_uint32_len(&cd->data.db_id);
116 break;
118 case CTDB_CONTROL_ENABLE_SEQNUM:
119 len = ctdb_uint32_len(&cd->data.db_id);
120 break;
122 case CTDB_CONTROL_UPDATE_SEQNUM:
123 len = ctdb_uint32_len(&cd->data.db_id);
124 break;
126 case CTDB_CONTROL_DUMP_MEMORY:
127 break;
129 case CTDB_CONTROL_GET_PID:
130 break;
132 case CTDB_CONTROL_GET_RECMASTER:
133 break;
135 case CTDB_CONTROL_SET_RECMASTER:
136 len = ctdb_uint32_len(&cd->data.recmaster);
137 break;
139 case CTDB_CONTROL_FREEZE:
140 break;
142 case CTDB_CONTROL_GET_PNN:
143 break;
145 case CTDB_CONTROL_SHUTDOWN:
146 break;
148 case CTDB_CONTROL_GET_MONMODE:
149 break;
151 case CTDB_CONTROL_TCP_CLIENT:
152 len = ctdb_connection_len(cd->data.conn);
153 break;
155 case CTDB_CONTROL_TCP_ADD:
156 len = ctdb_connection_len(cd->data.conn);
157 break;
159 case CTDB_CONTROL_TCP_REMOVE:
160 len = ctdb_connection_len(cd->data.conn);
161 break;
163 case CTDB_CONTROL_STARTUP:
164 break;
166 case CTDB_CONTROL_SET_TUNABLE:
167 len = ctdb_tunable_len(cd->data.tunable);
168 break;
170 case CTDB_CONTROL_GET_TUNABLE:
171 len = ctdb_stringn_len(&cd->data.tun_var);
172 break;
174 case CTDB_CONTROL_LIST_TUNABLES:
175 break;
177 case CTDB_CONTROL_MODIFY_FLAGS:
178 len = ctdb_node_flag_change_len(cd->data.flag_change);
179 break;
181 case CTDB_CONTROL_GET_ALL_TUNABLES:
182 break;
184 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
185 len = ctdb_sock_addr_len(cd->data.addr);
186 break;
188 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
189 len = ctdb_tickle_list_len(cd->data.tickles);
190 break;
192 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
193 len = ctdb_string_len(&cd->data.db_name);
194 break;
196 case CTDB_CONTROL_UPDATE_RECORD:
197 len = ctdb_rec_buffer_len(cd->data.recbuf);
198 break;
200 case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
201 len = ctdb_addr_info_len(cd->data.addr_info);
202 break;
204 case CTDB_CONTROL_WIPE_DATABASE:
205 len = ctdb_transdb_len(cd->data.transdb);
206 break;
208 case CTDB_CONTROL_UPTIME:
209 break;
211 case CTDB_CONTROL_START_RECOVERY:
212 break;
214 case CTDB_CONTROL_END_RECOVERY:
215 break;
217 case CTDB_CONTROL_RELOAD_NODES_FILE:
218 break;
220 case CTDB_CONTROL_TRY_DELETE_RECORDS:
221 len = ctdb_rec_buffer_len(cd->data.recbuf);
222 break;
224 case CTDB_CONTROL_ENABLE_MONITOR:
225 break;
227 case CTDB_CONTROL_DISABLE_MONITOR:
228 break;
230 case CTDB_CONTROL_ADD_PUBLIC_IP:
231 len = ctdb_addr_info_len(cd->data.addr_info);
232 break;
234 case CTDB_CONTROL_DEL_PUBLIC_IP:
235 len = ctdb_addr_info_len(cd->data.addr_info);
236 break;
238 case CTDB_CONTROL_GET_CAPABILITIES:
239 break;
241 case CTDB_CONTROL_RECD_PING:
242 break;
244 case CTDB_CONTROL_RELEASE_IP:
245 len = ctdb_public_ip_len(cd->data.pubip);
246 break;
248 case CTDB_CONTROL_TAKEOVER_IP:
249 len = ctdb_public_ip_len(cd->data.pubip);
250 break;
252 case CTDB_CONTROL_GET_PUBLIC_IPS:
253 break;
255 case CTDB_CONTROL_GET_NODEMAP:
256 break;
258 case CTDB_CONTROL_TRAVERSE_KILL:
259 len = ctdb_traverse_start_len(cd->data.traverse_start);
260 break;
262 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
263 len = ctdb_double_len(&cd->data.reclock_latency);
264 break;
266 case CTDB_CONTROL_GET_RECLOCK_FILE:
267 break;
269 case CTDB_CONTROL_STOP_NODE:
270 break;
272 case CTDB_CONTROL_CONTINUE_NODE:
273 break;
275 case CTDB_CONTROL_SET_LMASTERROLE:
276 len = ctdb_uint32_len(&cd->data.role);
277 break;
279 case CTDB_CONTROL_SET_RECMASTERROLE:
280 len = ctdb_uint32_len(&cd->data.role);
281 break;
283 case CTDB_CONTROL_SET_BAN_STATE:
284 len = ctdb_ban_state_len(cd->data.ban_state);
285 break;
287 case CTDB_CONTROL_GET_BAN_STATE:
288 break;
290 case CTDB_CONTROL_REGISTER_NOTIFY:
291 len = ctdb_notify_data_len(cd->data.notify);
292 break;
294 case CTDB_CONTROL_DEREGISTER_NOTIFY:
295 len = ctdb_uint64_len(&cd->data.srvid);
296 break;
298 case CTDB_CONTROL_TRANS3_COMMIT:
299 len = ctdb_rec_buffer_len(cd->data.recbuf);
300 break;
302 case CTDB_CONTROL_GET_DB_SEQNUM:
303 u32 = 0;
304 len = ctdb_uint32_len(&cd->data.db_id) + ctdb_uint32_len(&u32);
305 break;
307 case CTDB_CONTROL_DB_SET_HEALTHY:
308 len = ctdb_uint32_len(&cd->data.db_id);
309 break;
311 case CTDB_CONTROL_DB_GET_HEALTH:
312 len = ctdb_uint32_len(&cd->data.db_id);
313 break;
315 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
316 len = ctdb_sock_addr_len(cd->data.addr);
317 break;
319 case CTDB_CONTROL_GET_IFACES:
320 break;
322 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
323 len = ctdb_iface_len(cd->data.iface);
324 break;
326 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
327 len = ctdb_connection_len(cd->data.conn);
328 break;
330 case CTDB_CONTROL_GET_STAT_HISTORY:
331 break;
333 case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
334 len = ctdb_key_data_len(cd->data.key);
335 break;
337 case CTDB_CONTROL_SET_DB_READONLY:
338 len = ctdb_uint32_len(&cd->data.db_id);
339 break;
341 case CTDB_CONTROL_CHECK_SRVIDS:
342 break;
344 case CTDB_CONTROL_TRAVERSE_START_EXT:
345 len = ctdb_traverse_start_ext_len(cd->data.traverse_start_ext);
346 break;
348 case CTDB_CONTROL_GET_DB_STATISTICS:
349 len = ctdb_uint32_len(&cd->data.db_id);
350 break;
352 case CTDB_CONTROL_SET_DB_STICKY:
353 len = ctdb_uint32_len(&cd->data.db_id);
354 break;
356 case CTDB_CONTROL_RELOAD_PUBLIC_IPS:
357 break;
359 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
360 len = ctdb_traverse_all_ext_len(cd->data.traverse_all_ext);
361 break;
363 case CTDB_CONTROL_IPREALLOCATED:
364 break;
366 case CTDB_CONTROL_GET_RUNSTATE:
367 break;
369 case CTDB_CONTROL_DB_DETACH:
370 len = ctdb_uint32_len(&cd->data.db_id);
371 break;
373 case CTDB_CONTROL_GET_NODES_FILE:
374 break;
376 case CTDB_CONTROL_DB_FREEZE:
377 len = ctdb_uint32_len(&cd->data.db_id);
378 break;
380 case CTDB_CONTROL_DB_THAW:
381 len = ctdb_uint32_len(&cd->data.db_id);
382 break;
384 case CTDB_CONTROL_DB_TRANSACTION_START:
385 len = ctdb_transdb_len(cd->data.transdb);
386 break;
388 case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
389 len = ctdb_transdb_len(cd->data.transdb);
390 break;
392 case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
393 len = ctdb_uint32_len(&cd->data.db_id);
394 break;
396 case CTDB_CONTROL_DB_PULL:
397 len = ctdb_pulldb_ext_len(cd->data.pulldb_ext);
398 break;
400 case CTDB_CONTROL_DB_PUSH_START:
401 len = ctdb_pulldb_ext_len(cd->data.pulldb_ext);
402 break;
404 case CTDB_CONTROL_DB_PUSH_CONFIRM:
405 len = ctdb_uint32_len(&cd->data.db_id);
406 break;
408 case CTDB_CONTROL_DB_OPEN_FLAGS:
409 len = ctdb_uint32_len(&cd->data.db_id);
410 break;
412 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
413 len = ctdb_string_len(&cd->data.db_name);
414 break;
416 case CTDB_CONTROL_CHECK_PID_SRVID:
417 len = ctdb_pid_srvid_len(cd->data.pid_srvid);
418 break;
420 case CTDB_CONTROL_TUNNEL_REGISTER:
421 break;
423 case CTDB_CONTROL_TUNNEL_DEREGISTER:
424 break;
427 return len;
430 static void ctdb_req_control_data_push(struct ctdb_req_control_data *cd,
431 uint8_t *buf, size_t *npush)
433 size_t np = 0, offset;
434 uint32_t u32;
436 switch (cd->opcode) {
437 case CTDB_CONTROL_PROCESS_EXISTS:
438 ctdb_pid_push(&cd->data.pid, buf, &np);
439 break;
441 case CTDB_CONTROL_GETDBPATH:
442 ctdb_uint32_push(&cd->data.db_id, buf, &np);
443 break;
445 case CTDB_CONTROL_SETVNNMAP:
446 ctdb_vnn_map_push(cd->data.vnnmap, buf, &np);
447 break;
449 case CTDB_CONTROL_SET_DEBUG:
450 ctdb_uint32_push(&cd->data.loglevel, buf, &np);
451 break;
453 case CTDB_CONTROL_PULL_DB:
454 ctdb_pulldb_push(cd->data.pulldb, buf, &np);
455 break;
457 case CTDB_CONTROL_PUSH_DB:
458 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
459 break;
461 case CTDB_CONTROL_SET_RECMODE:
462 ctdb_uint32_push(&cd->data.recmode, buf, &np);
463 break;
465 case CTDB_CONTROL_DB_ATTACH:
466 ctdb_string_push(&cd->data.db_name, buf, &np);
467 break;
469 case CTDB_CONTROL_SET_CALL:
470 break;
472 case CTDB_CONTROL_TRAVERSE_START:
473 ctdb_traverse_start_push(cd->data.traverse_start, buf, &np);
474 break;
476 case CTDB_CONTROL_TRAVERSE_ALL:
477 ctdb_traverse_all_push(cd->data.traverse_all, buf, &np);
478 break;
480 case CTDB_CONTROL_TRAVERSE_DATA:
481 ctdb_rec_data_push(cd->data.rec_data, buf, &np);
482 break;
484 case CTDB_CONTROL_GET_DBNAME:
485 ctdb_uint32_push(&cd->data.db_id, buf, &np);
486 break;
488 case CTDB_CONTROL_ENABLE_SEQNUM:
489 ctdb_uint32_push(&cd->data.db_id, buf, &np);
490 break;
492 case CTDB_CONTROL_UPDATE_SEQNUM:
493 ctdb_uint32_push(&cd->data.db_id, buf, &np);
494 break;
496 case CTDB_CONTROL_SET_RECMASTER:
497 ctdb_uint32_push(&cd->data.recmaster, buf, &np);
498 break;
500 case CTDB_CONTROL_TCP_CLIENT:
501 ctdb_connection_push(cd->data.conn, buf, &np);
502 break;
504 case CTDB_CONTROL_TCP_ADD:
505 ctdb_connection_push(cd->data.conn, buf, &np);
506 break;
508 case CTDB_CONTROL_TCP_REMOVE:
509 ctdb_connection_push(cd->data.conn, buf, &np);
510 break;
512 case CTDB_CONTROL_SET_TUNABLE:
513 ctdb_tunable_push(cd->data.tunable, buf, &np);
514 break;
516 case CTDB_CONTROL_GET_TUNABLE:
517 ctdb_stringn_push(&cd->data.tun_var, buf, &np);
518 break;
520 case CTDB_CONTROL_MODIFY_FLAGS:
521 ctdb_node_flag_change_push(cd->data.flag_change, buf, &np);
522 break;
524 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
525 ctdb_sock_addr_push(cd->data.addr, buf, &np);
526 break;
528 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
529 ctdb_tickle_list_push(cd->data.tickles, buf, &np);
530 break;
532 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
533 ctdb_string_push(&cd->data.db_name, buf, &np);
534 break;
536 case CTDB_CONTROL_UPDATE_RECORD:
537 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
538 break;
540 case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
541 ctdb_addr_info_push(cd->data.addr_info, buf, &np);
542 break;
544 case CTDB_CONTROL_WIPE_DATABASE:
545 ctdb_transdb_push(cd->data.transdb, buf, &np);
546 break;
548 case CTDB_CONTROL_TRY_DELETE_RECORDS:
549 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
550 break;
552 case CTDB_CONTROL_ADD_PUBLIC_IP:
553 ctdb_addr_info_push(cd->data.addr_info, buf, &np);
554 break;
556 case CTDB_CONTROL_DEL_PUBLIC_IP:
557 ctdb_addr_info_push(cd->data.addr_info, buf, &np);
558 break;
560 case CTDB_CONTROL_RELEASE_IP:
561 ctdb_public_ip_push(cd->data.pubip, buf, &np);
562 break;
564 case CTDB_CONTROL_TAKEOVER_IP:
565 ctdb_public_ip_push(cd->data.pubip, buf, &np);
566 break;
568 case CTDB_CONTROL_TRAVERSE_KILL:
569 ctdb_traverse_start_push(cd->data.traverse_start, buf, &np);
570 break;
572 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
573 ctdb_double_push(&cd->data.reclock_latency, buf, &np);
574 break;
576 case CTDB_CONTROL_SET_LMASTERROLE:
577 ctdb_uint32_push(&cd->data.role, buf, &np);
578 break;
580 case CTDB_CONTROL_SET_RECMASTERROLE:
581 ctdb_uint32_push(&cd->data.role, buf, &np);
582 break;
584 case CTDB_CONTROL_SET_BAN_STATE:
585 ctdb_ban_state_push(cd->data.ban_state, buf, &np);
586 break;
588 case CTDB_CONTROL_REGISTER_NOTIFY:
589 ctdb_notify_data_push(cd->data.notify, buf, &np);
590 break;
592 case CTDB_CONTROL_DEREGISTER_NOTIFY:
593 ctdb_uint64_push(&cd->data.srvid, buf, &np);
594 break;
596 case CTDB_CONTROL_TRANS3_COMMIT:
597 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
598 break;
600 case CTDB_CONTROL_GET_DB_SEQNUM:
601 u32 = 0;
602 offset = 0;
603 ctdb_uint32_push(&cd->data.db_id, buf, &np);
604 offset += np;
605 ctdb_uint32_push(&u32, buf+offset, &np);
606 offset += np;
607 np = offset;
608 break;
610 case CTDB_CONTROL_DB_SET_HEALTHY:
611 ctdb_uint32_push(&cd->data.db_id, buf, &np);
612 break;
614 case CTDB_CONTROL_DB_GET_HEALTH:
615 ctdb_uint32_push(&cd->data.db_id, buf, &np);
616 break;
618 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
619 ctdb_sock_addr_push(cd->data.addr, buf, &np);
620 break;
622 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
623 ctdb_iface_push(cd->data.iface, buf, &np);
624 break;
626 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
627 ctdb_connection_push(cd->data.conn, buf, &np);
628 break;
630 case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
631 ctdb_key_data_push(cd->data.key, buf, &np);
632 break;
634 case CTDB_CONTROL_SET_DB_READONLY:
635 ctdb_uint32_push(&cd->data.db_id, buf, &np);
636 break;
638 case CTDB_CONTROL_CHECK_SRVIDS:
639 break;
641 case CTDB_CONTROL_TRAVERSE_START_EXT:
642 ctdb_traverse_start_ext_push(cd->data.traverse_start_ext, buf,
643 &np);
644 break;
646 case CTDB_CONTROL_GET_DB_STATISTICS:
647 ctdb_uint32_push(&cd->data.db_id, buf, &np);
648 break;
650 case CTDB_CONTROL_SET_DB_STICKY:
651 ctdb_uint32_push(&cd->data.db_id, buf, &np);
652 break;
654 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
655 ctdb_traverse_all_ext_push(cd->data.traverse_all_ext, buf,
656 &np);
657 break;
659 case CTDB_CONTROL_DB_DETACH:
660 ctdb_uint32_push(&cd->data.db_id, buf, &np);
661 break;
663 case CTDB_CONTROL_DB_FREEZE:
664 ctdb_uint32_push(&cd->data.db_id, buf, &np);
665 break;
667 case CTDB_CONTROL_DB_THAW:
668 ctdb_uint32_push(&cd->data.db_id, buf, &np);
669 break;
671 case CTDB_CONTROL_DB_TRANSACTION_START:
672 ctdb_transdb_push(cd->data.transdb, buf, &np);
673 break;
675 case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
676 ctdb_transdb_push(cd->data.transdb, buf, &np);
677 break;
679 case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
680 ctdb_uint32_push(&cd->data.db_id, buf, &np);
681 break;
683 case CTDB_CONTROL_DB_PULL:
684 ctdb_pulldb_ext_push(cd->data.pulldb_ext, buf, &np);
685 break;
687 case CTDB_CONTROL_DB_PUSH_START:
688 ctdb_pulldb_ext_push(cd->data.pulldb_ext, buf, &np);
689 break;
691 case CTDB_CONTROL_DB_PUSH_CONFIRM:
692 ctdb_uint32_push(&cd->data.db_id, buf, &np);
693 break;
695 case CTDB_CONTROL_DB_OPEN_FLAGS:
696 ctdb_uint32_push(&cd->data.db_id, buf, &np);
697 break;
699 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
700 ctdb_string_push(&cd->data.db_name, buf, &np);
701 break;
703 case CTDB_CONTROL_CHECK_PID_SRVID:
704 ctdb_pid_srvid_push(cd->data.pid_srvid, buf, &np);
705 break;
708 *npush = np;
711 static int ctdb_req_control_data_pull(uint8_t *buf, size_t buflen,
712 uint32_t opcode,
713 TALLOC_CTX *mem_ctx,
714 struct ctdb_req_control_data *cd,
715 size_t *npull)
717 size_t np = 0, offset;
718 uint32_t u32;
719 int ret = 0;
721 cd->opcode = opcode;
723 switch (opcode) {
724 case CTDB_CONTROL_PROCESS_EXISTS:
725 ret = ctdb_pid_pull(buf, buflen, &cd->data.pid, &np);
726 break;
728 case CTDB_CONTROL_GETDBPATH:
729 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
730 break;
732 case CTDB_CONTROL_SETVNNMAP:
733 ret = ctdb_vnn_map_pull(buf, buflen, mem_ctx,
734 &cd->data.vnnmap, &np);
735 break;
737 case CTDB_CONTROL_SET_DEBUG:
738 ret = ctdb_uint32_pull(buf, buflen, &cd->data.loglevel, &np);
739 break;
741 case CTDB_CONTROL_PULL_DB:
742 ret = ctdb_pulldb_pull(buf, buflen, mem_ctx,
743 &cd->data.pulldb, &np);
744 break;
746 case CTDB_CONTROL_PUSH_DB:
747 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
748 &cd->data.recbuf, &np);
749 break;
751 case CTDB_CONTROL_SET_RECMODE:
752 ret = ctdb_uint32_pull(buf, buflen, &cd->data.recmode, &np);
753 break;
755 case CTDB_CONTROL_DB_ATTACH:
756 ret = ctdb_string_pull(buf, buflen, mem_ctx,
757 &cd->data.db_name, &np);
758 break;
760 case CTDB_CONTROL_SET_CALL:
761 break;
763 case CTDB_CONTROL_TRAVERSE_START:
764 ret = ctdb_traverse_start_pull(buf, buflen, mem_ctx,
765 &cd->data.traverse_start, &np);
766 break;
768 case CTDB_CONTROL_TRAVERSE_ALL:
769 ret = ctdb_traverse_all_pull(buf, buflen, mem_ctx,
770 &cd->data.traverse_all, &np);
771 break;
773 case CTDB_CONTROL_TRAVERSE_DATA:
774 ret = ctdb_rec_data_pull(buf, buflen, mem_ctx,
775 &cd->data.rec_data, &np);
776 break;
778 case CTDB_CONTROL_GET_DBNAME:
779 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
780 break;
782 case CTDB_CONTROL_ENABLE_SEQNUM:
783 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
784 break;
786 case CTDB_CONTROL_UPDATE_SEQNUM:
787 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
788 break;
790 case CTDB_CONTROL_SET_RECMASTER:
791 ret = ctdb_uint32_pull(buf, buflen, &cd->data.recmaster, &np);
792 break;
794 case CTDB_CONTROL_TCP_CLIENT:
795 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
796 &cd->data.conn, &np);
797 break;
799 case CTDB_CONTROL_TCP_ADD:
800 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
801 &cd->data.conn, &np);
802 break;
804 case CTDB_CONTROL_TCP_REMOVE:
805 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
806 &cd->data.conn, &np);
807 break;
809 case CTDB_CONTROL_SET_TUNABLE:
810 ret = ctdb_tunable_pull(buf, buflen, mem_ctx,
811 &cd->data.tunable, &np);
812 break;
814 case CTDB_CONTROL_GET_TUNABLE:
815 ret = ctdb_stringn_pull(buf, buflen, mem_ctx,
816 &cd->data.tun_var, &np);
817 break;
819 case CTDB_CONTROL_MODIFY_FLAGS:
820 ret = ctdb_node_flag_change_pull(buf, buflen, mem_ctx,
821 &cd->data.flag_change, &np);
822 break;
824 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
825 ret = ctdb_sock_addr_pull(buf, buflen, mem_ctx,
826 &cd->data.addr, &np);
827 break;
829 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
830 ret = ctdb_tickle_list_pull(buf, buflen, mem_ctx,
831 &cd->data.tickles, &np);
832 break;
834 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
835 ret = ctdb_string_pull(buf, buflen, mem_ctx,
836 &cd->data.db_name, &np);
837 break;
839 case CTDB_CONTROL_UPDATE_RECORD:
840 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
841 &cd->data.recbuf, &np);
842 break;
844 case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
845 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
846 &cd->data.addr_info, &np);
847 break;
849 case CTDB_CONTROL_WIPE_DATABASE:
850 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
851 &cd->data.transdb, &np);
852 break;
854 case CTDB_CONTROL_TRY_DELETE_RECORDS:
855 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
856 &cd->data.recbuf, &np);
857 break;
859 case CTDB_CONTROL_ADD_PUBLIC_IP:
860 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
861 &cd->data.addr_info, &np);
862 break;
864 case CTDB_CONTROL_DEL_PUBLIC_IP:
865 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
866 &cd->data.addr_info, &np);
867 break;
869 case CTDB_CONTROL_RELEASE_IP:
870 ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
871 &cd->data.pubip, &np);
872 break;
874 case CTDB_CONTROL_TAKEOVER_IP:
875 ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
876 &cd->data.pubip, &np);
877 break;
879 case CTDB_CONTROL_TRAVERSE_KILL:
880 ret = ctdb_traverse_start_pull(buf, buflen, mem_ctx,
881 &cd->data.traverse_start, &np);
882 break;
884 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
885 ret = ctdb_double_pull(buf, buflen, &cd->data.reclock_latency,
886 &np);
887 break;
889 case CTDB_CONTROL_SET_LMASTERROLE:
890 ret = ctdb_uint32_pull(buf, buflen, &cd->data.role, &np);
891 break;
893 case CTDB_CONTROL_SET_RECMASTERROLE:
894 ret = ctdb_uint32_pull(buf, buflen, &cd->data.role, &np);
895 break;
897 case CTDB_CONTROL_SET_BAN_STATE:
898 ret = ctdb_ban_state_pull(buf, buflen, mem_ctx,
899 &cd->data.ban_state, &np);
900 break;
902 case CTDB_CONTROL_REGISTER_NOTIFY:
903 ret = ctdb_notify_data_pull(buf, buflen, mem_ctx,
904 &cd->data.notify, &np);
905 break;
907 case CTDB_CONTROL_DEREGISTER_NOTIFY:
908 ret = ctdb_uint64_pull(buf, buflen, &cd->data.srvid, &np);
909 break;
911 case CTDB_CONTROL_TRANS3_COMMIT:
912 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
913 &cd->data.recbuf, &np);
914 break;
916 case CTDB_CONTROL_GET_DB_SEQNUM:
917 offset = 0;
918 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
919 if (ret != 0) {
920 break;
922 offset += np;
923 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
924 offset += np;
925 np = offset;
926 break;
928 case CTDB_CONTROL_DB_SET_HEALTHY:
929 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
930 break;
932 case CTDB_CONTROL_DB_GET_HEALTH:
933 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
934 break;
936 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
937 ret = ctdb_sock_addr_pull(buf, buflen, mem_ctx,
938 &cd->data.addr, &np);
939 break;
941 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
942 ret = ctdb_iface_pull(buf, buflen, mem_ctx,
943 &cd->data.iface, &np);
944 break;
946 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
947 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
948 &cd->data.conn, &np);
949 break;
951 case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
952 ret = ctdb_key_data_pull(buf, buflen, mem_ctx,
953 &cd->data.key, &np);
954 break;
956 case CTDB_CONTROL_SET_DB_READONLY:
957 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
958 break;
960 case CTDB_CONTROL_CHECK_SRVIDS:
961 break;
963 case CTDB_CONTROL_TRAVERSE_START_EXT:
964 ret = ctdb_traverse_start_ext_pull(buf, buflen, mem_ctx,
965 &cd->data.traverse_start_ext,
966 &np);
967 break;
969 case CTDB_CONTROL_GET_DB_STATISTICS:
970 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
971 break;
973 case CTDB_CONTROL_SET_DB_STICKY:
974 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
975 break;
977 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
978 ret = ctdb_traverse_all_ext_pull(buf, buflen, mem_ctx,
979 &cd->data.traverse_all_ext,
980 &np);
981 break;
983 case CTDB_CONTROL_DB_DETACH:
984 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
985 break;
987 case CTDB_CONTROL_DB_FREEZE:
988 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
989 break;
991 case CTDB_CONTROL_DB_THAW:
992 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
993 break;
995 case CTDB_CONTROL_DB_TRANSACTION_START:
996 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
997 &cd->data.transdb, &np);
998 break;
1000 case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
1001 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
1002 &cd->data.transdb, &np);
1003 break;
1005 case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
1006 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1007 break;
1009 case CTDB_CONTROL_DB_PULL:
1010 ret = ctdb_pulldb_ext_pull(buf, buflen, mem_ctx,
1011 &cd->data.pulldb_ext, &np);
1012 break;
1014 case CTDB_CONTROL_DB_PUSH_START:
1015 ret = ctdb_pulldb_ext_pull(buf, buflen, mem_ctx,
1016 &cd->data.pulldb_ext, &np);
1017 break;
1019 case CTDB_CONTROL_DB_PUSH_CONFIRM:
1020 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1021 break;
1023 case CTDB_CONTROL_DB_OPEN_FLAGS:
1024 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1025 break;
1027 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1028 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1029 &cd->data.db_name, &np);
1030 break;
1032 case CTDB_CONTROL_CHECK_PID_SRVID:
1033 ret = ctdb_pid_srvid_pull(buf, buflen, mem_ctx,
1034 &cd->data.pid_srvid, &np);
1035 break;
1038 if (ret != 0) {
1039 return ret;
1042 *npull = np;
1043 return 0;
1046 static size_t ctdb_reply_control_data_len(struct ctdb_reply_control_data *cd)
1048 size_t len = 0;
1050 if (cd == NULL) {
1051 return 0;
1054 switch (cd->opcode) {
1055 case CTDB_CONTROL_PROCESS_EXISTS:
1056 break;
1058 case CTDB_CONTROL_STATISTICS:
1059 len = ctdb_statistics_len(cd->data.stats);
1060 break;
1062 case CTDB_CONTROL_PING:
1063 break;
1065 case CTDB_CONTROL_GETDBPATH:
1066 len = ctdb_string_len(&cd->data.db_path);
1067 break;
1069 case CTDB_CONTROL_GETVNNMAP:
1070 len = ctdb_vnn_map_len(cd->data.vnnmap);
1071 break;
1073 case CTDB_CONTROL_SETVNNMAP:
1074 break;
1076 case CTDB_CONTROL_GET_DEBUG:
1077 len = ctdb_uint32_len(&cd->data.loglevel);
1078 break;
1080 case CTDB_CONTROL_SET_DEBUG:
1081 break;
1083 case CTDB_CONTROL_GET_DBMAP:
1084 len = ctdb_dbid_map_len(cd->data.dbmap);
1085 break;
1087 case CTDB_CONTROL_PULL_DB:
1088 len = ctdb_rec_buffer_len(cd->data.recbuf);
1089 break;
1091 case CTDB_CONTROL_PUSH_DB:
1092 break;
1094 case CTDB_CONTROL_GET_RECMODE:
1095 break;
1097 case CTDB_CONTROL_SET_RECMODE:
1098 break;
1100 case CTDB_CONTROL_STATISTICS_RESET:
1101 break;
1103 case CTDB_CONTROL_DB_ATTACH:
1104 len = ctdb_uint32_len(&cd->data.db_id);
1105 break;
1107 case CTDB_CONTROL_SET_CALL:
1108 break;
1110 case CTDB_CONTROL_TRAVERSE_START:
1111 break;
1113 case CTDB_CONTROL_TRAVERSE_ALL:
1114 break;
1116 case CTDB_CONTROL_TRAVERSE_DATA:
1117 break;
1119 case CTDB_CONTROL_REGISTER_SRVID:
1120 break;
1122 case CTDB_CONTROL_DEREGISTER_SRVID:
1123 break;
1125 case CTDB_CONTROL_GET_DBNAME:
1126 len = ctdb_string_len(&cd->data.db_name);
1127 break;
1129 case CTDB_CONTROL_ENABLE_SEQNUM:
1130 break;
1132 case CTDB_CONTROL_UPDATE_SEQNUM:
1133 break;
1135 case CTDB_CONTROL_DUMP_MEMORY:
1136 len = ctdb_string_len(&cd->data.mem_str);
1137 break;
1139 case CTDB_CONTROL_GET_PID:
1140 break;
1142 case CTDB_CONTROL_GET_RECMASTER:
1143 break;
1145 case CTDB_CONTROL_SET_RECMASTER:
1146 break;
1148 case CTDB_CONTROL_FREEZE:
1149 break;
1151 case CTDB_CONTROL_GET_PNN:
1152 break;
1154 case CTDB_CONTROL_SHUTDOWN:
1155 break;
1157 case CTDB_CONTROL_GET_MONMODE:
1158 break;
1160 case CTDB_CONTROL_TCP_CLIENT:
1161 break;
1163 case CTDB_CONTROL_TCP_ADD:
1164 break;
1166 case CTDB_CONTROL_TCP_REMOVE:
1167 break;
1169 case CTDB_CONTROL_STARTUP:
1170 break;
1172 case CTDB_CONTROL_SET_TUNABLE:
1173 break;
1175 case CTDB_CONTROL_GET_TUNABLE:
1176 len = ctdb_uint32_len(&cd->data.tun_value);
1177 break;
1179 case CTDB_CONTROL_LIST_TUNABLES:
1180 len = ctdb_var_list_len(cd->data.tun_var_list);
1181 break;
1183 case CTDB_CONTROL_MODIFY_FLAGS:
1184 break;
1186 case CTDB_CONTROL_GET_ALL_TUNABLES:
1187 len = ctdb_tunable_list_len(cd->data.tun_list);
1188 break;
1190 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1191 len = ctdb_tickle_list_len(cd->data.tickles);
1192 break;
1194 case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
1195 break;
1197 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1198 len = ctdb_uint32_len(&cd->data.db_id);
1199 break;
1201 case CTDB_CONTROL_UPDATE_RECORD:
1202 break;
1204 case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
1205 break;
1207 case CTDB_CONTROL_WIPE_DATABASE:
1208 break;
1210 case CTDB_CONTROL_UPTIME:
1211 len = ctdb_uptime_len(cd->data.uptime);
1212 break;
1214 case CTDB_CONTROL_START_RECOVERY:
1215 break;
1217 case CTDB_CONTROL_END_RECOVERY:
1218 break;
1220 case CTDB_CONTROL_RELOAD_NODES_FILE:
1221 break;
1223 case CTDB_CONTROL_TRY_DELETE_RECORDS:
1224 len = ctdb_rec_buffer_len(cd->data.recbuf);
1225 break;
1227 case CTDB_CONTROL_ENABLE_MONITOR:
1228 break;
1230 case CTDB_CONTROL_DISABLE_MONITOR:
1231 break;
1233 case CTDB_CONTROL_ADD_PUBLIC_IP:
1234 break;
1236 case CTDB_CONTROL_DEL_PUBLIC_IP:
1237 break;
1239 case CTDB_CONTROL_GET_CAPABILITIES:
1240 len = ctdb_uint32_len(&cd->data.caps);
1241 break;
1243 case CTDB_CONTROL_RECD_PING:
1244 break;
1246 case CTDB_CONTROL_RELEASE_IP:
1247 break;
1249 case CTDB_CONTROL_TAKEOVER_IP:
1250 break;
1252 case CTDB_CONTROL_GET_PUBLIC_IPS:
1253 len = ctdb_public_ip_list_len(cd->data.pubip_list);
1254 break;
1256 case CTDB_CONTROL_GET_NODEMAP:
1257 len = ctdb_node_map_len(cd->data.nodemap);
1258 break;
1260 case CTDB_CONTROL_TRAVERSE_KILL:
1261 break;
1263 case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
1264 break;
1266 case CTDB_CONTROL_GET_RECLOCK_FILE:
1267 len = ctdb_string_len(&cd->data.reclock_file);
1268 break;
1270 case CTDB_CONTROL_STOP_NODE:
1271 break;
1273 case CTDB_CONTROL_CONTINUE_NODE:
1274 break;
1276 case CTDB_CONTROL_SET_LMASTERROLE:
1277 break;
1279 case CTDB_CONTROL_SET_RECMASTERROLE:
1280 break;
1282 case CTDB_CONTROL_SET_BAN_STATE:
1283 break;
1285 case CTDB_CONTROL_GET_BAN_STATE:
1286 len = ctdb_ban_state_len(cd->data.ban_state);
1287 break;
1289 case CTDB_CONTROL_SET_DB_PRIORITY:
1290 break;
1292 case CTDB_CONTROL_GET_DB_PRIORITY:
1293 break;
1295 case CTDB_CONTROL_REGISTER_NOTIFY:
1296 break;
1298 case CTDB_CONTROL_DEREGISTER_NOTIFY:
1299 break;
1301 case CTDB_CONTROL_TRANS3_COMMIT:
1302 break;
1304 case CTDB_CONTROL_GET_DB_SEQNUM:
1305 len = ctdb_uint64_len(&cd->data.seqnum);
1306 break;
1308 case CTDB_CONTROL_DB_SET_HEALTHY:
1309 break;
1311 case CTDB_CONTROL_DB_GET_HEALTH:
1312 len = ctdb_string_len(&cd->data.reason);
1313 break;
1315 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1316 len = ctdb_public_ip_info_len(cd->data.ipinfo);
1317 break;
1319 case CTDB_CONTROL_GET_IFACES:
1320 len = ctdb_iface_list_len(cd->data.iface_list);
1321 break;
1323 case CTDB_CONTROL_SET_IFACE_LINK_STATE:
1324 break;
1326 case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
1327 break;
1329 case CTDB_CONTROL_GET_STAT_HISTORY:
1330 len = ctdb_statistics_list_len(cd->data.stats_list);
1331 break;
1333 case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
1334 break;
1336 case CTDB_CONTROL_SET_DB_READONLY:
1337 break;
1339 case CTDB_CONTROL_CHECK_SRVIDS:
1340 break;
1342 case CTDB_CONTROL_TRAVERSE_START_EXT:
1343 break;
1345 case CTDB_CONTROL_GET_DB_STATISTICS:
1346 len = ctdb_db_statistics_len(cd->data.dbstats);
1347 break;
1349 case CTDB_CONTROL_SET_DB_STICKY:
1350 break;
1352 case CTDB_CONTROL_RELOAD_PUBLIC_IPS:
1353 break;
1355 case CTDB_CONTROL_TRAVERSE_ALL_EXT:
1356 break;
1358 case CTDB_CONTROL_IPREALLOCATED:
1359 break;
1361 case CTDB_CONTROL_GET_RUNSTATE:
1362 len = ctdb_uint32_len(&cd->data.runstate);
1363 break;
1365 case CTDB_CONTROL_DB_DETACH:
1366 break;
1368 case CTDB_CONTROL_GET_NODES_FILE:
1369 len = ctdb_node_map_len(cd->data.nodemap);
1370 break;
1372 case CTDB_CONTROL_DB_FREEZE:
1373 break;
1375 case CTDB_CONTROL_DB_THAW:
1376 break;
1378 case CTDB_CONTROL_DB_TRANSACTION_START:
1379 break;
1381 case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
1382 break;
1384 case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
1385 break;
1387 case CTDB_CONTROL_DB_PULL:
1388 len = ctdb_uint32_len(&cd->data.num_records);
1389 break;
1391 case CTDB_CONTROL_DB_PUSH_START:
1392 break;
1394 case CTDB_CONTROL_DB_PUSH_CONFIRM:
1395 len = ctdb_uint32_len(&cd->data.num_records);
1396 break;
1398 case CTDB_CONTROL_DB_OPEN_FLAGS:
1399 len = ctdb_int32_len(&cd->data.tdb_flags);
1400 break;
1402 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1403 len = ctdb_uint32_len(&cd->data.db_id);
1404 break;
1406 case CTDB_CONTROL_CHECK_PID_SRVID:
1407 break;
1409 case CTDB_CONTROL_TUNNEL_REGISTER:
1410 break;
1412 case CTDB_CONTROL_TUNNEL_DEREGISTER:
1413 break;
1416 return len;
1419 static void ctdb_reply_control_data_push(struct ctdb_reply_control_data *cd,
1420 uint8_t *buf, size_t *npush)
1422 size_t np = 0;
1424 switch (cd->opcode) {
1425 case CTDB_CONTROL_STATISTICS:
1426 ctdb_statistics_push(cd->data.stats, buf, &np);
1427 break;
1429 case CTDB_CONTROL_GETDBPATH:
1430 ctdb_string_push(&cd->data.db_path, buf, &np);
1431 break;
1433 case CTDB_CONTROL_GETVNNMAP:
1434 ctdb_vnn_map_push(cd->data.vnnmap, buf, &np);
1435 break;
1437 case CTDB_CONTROL_GET_DEBUG:
1438 ctdb_uint32_push(&cd->data.loglevel, buf, &np);
1439 break;
1441 case CTDB_CONTROL_GET_DBMAP:
1442 ctdb_dbid_map_push(cd->data.dbmap, buf, &np);
1443 break;
1445 case CTDB_CONTROL_PULL_DB:
1446 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
1447 break;
1449 case CTDB_CONTROL_PUSH_DB:
1450 break;
1452 case CTDB_CONTROL_DB_ATTACH:
1453 ctdb_uint32_push(&cd->data.db_id, buf, &np);
1454 break;
1456 case CTDB_CONTROL_GET_DBNAME:
1457 ctdb_string_push(&cd->data.db_name, buf, &np);
1458 break;
1460 case CTDB_CONTROL_DUMP_MEMORY:
1461 ctdb_string_push(&cd->data.mem_str, buf, &np);
1462 break;
1464 case CTDB_CONTROL_GET_PID:
1465 break;
1467 case CTDB_CONTROL_GET_RECMASTER:
1468 break;
1470 case CTDB_CONTROL_GET_TUNABLE:
1471 ctdb_uint32_push(&cd->data.tun_value, buf, &np);
1472 break;
1474 case CTDB_CONTROL_LIST_TUNABLES:
1475 ctdb_var_list_push(cd->data.tun_var_list, buf, &np);
1476 break;
1478 case CTDB_CONTROL_GET_ALL_TUNABLES:
1479 ctdb_tunable_list_push(cd->data.tun_list, buf, &np);
1480 break;
1482 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1483 ctdb_tickle_list_push(cd->data.tickles, buf, &np);
1484 break;
1486 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1487 ctdb_uint32_push(&cd->data.db_id, buf, &np);
1488 break;
1490 case CTDB_CONTROL_UPTIME:
1491 ctdb_uptime_push(cd->data.uptime, buf, &np);
1492 break;
1494 case CTDB_CONTROL_TRY_DELETE_RECORDS:
1495 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
1496 break;
1498 case CTDB_CONTROL_GET_CAPABILITIES:
1499 ctdb_uint32_push(&cd->data.caps, buf, &np);
1500 break;
1502 case CTDB_CONTROL_GET_PUBLIC_IPS:
1503 ctdb_public_ip_list_push(cd->data.pubip_list, buf, &np);
1504 break;
1506 case CTDB_CONTROL_GET_NODEMAP:
1507 ctdb_node_map_push(cd->data.nodemap, buf, &np);
1508 break;
1510 case CTDB_CONTROL_GET_RECLOCK_FILE:
1511 ctdb_string_push(&cd->data.reclock_file, buf, &np);
1512 break;
1514 case CTDB_CONTROL_GET_BAN_STATE:
1515 ctdb_ban_state_push(cd->data.ban_state, buf, &np);
1516 break;
1518 case CTDB_CONTROL_GET_DB_PRIORITY:
1519 break;
1521 case CTDB_CONTROL_GET_DB_SEQNUM:
1522 ctdb_uint64_push(&cd->data.seqnum, buf, &np);
1523 break;
1525 case CTDB_CONTROL_DB_GET_HEALTH:
1526 ctdb_string_push(&cd->data.reason, buf, &np);
1527 break;
1529 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1530 ctdb_public_ip_info_push(cd->data.ipinfo, buf, &np);
1531 break;
1533 case CTDB_CONTROL_GET_IFACES:
1534 ctdb_iface_list_push(cd->data.iface_list, buf, &np);
1535 break;
1537 case CTDB_CONTROL_GET_STAT_HISTORY:
1538 ctdb_statistics_list_push(cd->data.stats_list, buf, &np);
1539 break;
1541 case CTDB_CONTROL_CHECK_SRVIDS:
1542 break;
1544 case CTDB_CONTROL_GET_DB_STATISTICS:
1545 ctdb_db_statistics_push(cd->data.dbstats, buf, &np);
1546 break;
1548 case CTDB_CONTROL_GET_RUNSTATE:
1549 ctdb_uint32_push(&cd->data.runstate, buf, &np);
1550 break;
1552 case CTDB_CONTROL_GET_NODES_FILE:
1553 ctdb_node_map_push(cd->data.nodemap, buf, &np);
1554 break;
1556 case CTDB_CONTROL_DB_PULL:
1557 ctdb_uint32_push(&cd->data.num_records, buf, &np);
1558 break;
1560 case CTDB_CONTROL_DB_PUSH_CONFIRM:
1561 ctdb_uint32_push(&cd->data.num_records, buf, &np);
1562 break;
1564 case CTDB_CONTROL_DB_OPEN_FLAGS:
1565 ctdb_int32_push(&cd->data.tdb_flags, buf, &np);
1566 break;
1568 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1569 ctdb_uint32_push(&cd->data.db_id, buf, &np);
1570 break;
1572 case CTDB_CONTROL_CHECK_PID_SRVID:
1573 break;
1576 *npush = np;
1579 static int ctdb_reply_control_data_pull(uint8_t *buf, size_t buflen,
1580 uint32_t opcode, TALLOC_CTX *mem_ctx,
1581 struct ctdb_reply_control_data *cd,
1582 size_t *npull)
1584 size_t np = 0;
1585 int ret = 0;
1587 cd->opcode = opcode;
1589 switch (opcode) {
1590 case CTDB_CONTROL_STATISTICS:
1591 ret = ctdb_statistics_pull(buf, buflen, mem_ctx,
1592 &cd->data.stats, &np);
1593 break;
1595 case CTDB_CONTROL_GETDBPATH:
1596 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1597 &cd->data.db_path, &np);
1598 break;
1600 case CTDB_CONTROL_GETVNNMAP:
1601 ret = ctdb_vnn_map_pull(buf, buflen, mem_ctx,
1602 &cd->data.vnnmap, &np);
1603 break;
1605 case CTDB_CONTROL_GET_DEBUG:
1606 ret = ctdb_uint32_pull(buf, buflen, &cd->data.loglevel, &np);
1607 break;
1609 case CTDB_CONTROL_GET_DBMAP:
1610 ret = ctdb_dbid_map_pull(buf, buflen, mem_ctx,
1611 &cd->data.dbmap, &np);
1612 break;
1614 case CTDB_CONTROL_PULL_DB:
1615 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
1616 &cd->data.recbuf, &np);
1617 break;
1619 case CTDB_CONTROL_PUSH_DB:
1620 break;
1622 case CTDB_CONTROL_DB_ATTACH:
1623 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1624 break;
1626 case CTDB_CONTROL_GET_DBNAME:
1627 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1628 &cd->data.db_name, &np);
1629 break;
1631 case CTDB_CONTROL_DUMP_MEMORY:
1632 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1633 &cd->data.mem_str, &np);
1634 break;
1636 case CTDB_CONTROL_GET_PID:
1637 break;
1639 case CTDB_CONTROL_GET_RECMASTER:
1640 break;
1642 case CTDB_CONTROL_GET_TUNABLE:
1643 ret = ctdb_uint32_pull(buf, buflen, &cd->data.tun_value,
1644 &np);
1645 break;
1647 case CTDB_CONTROL_LIST_TUNABLES:
1648 ret = ctdb_var_list_pull(buf, buflen, mem_ctx,
1649 &cd->data.tun_var_list, &np);
1650 break;
1652 case CTDB_CONTROL_GET_ALL_TUNABLES:
1653 ret = ctdb_tunable_list_pull(buf, buflen, mem_ctx,
1654 &cd->data.tun_list, &np);
1655 break;
1657 case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1658 ret = ctdb_tickle_list_pull(buf, buflen, mem_ctx,
1659 &cd->data.tickles, &np);
1660 break;
1662 case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1663 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1664 break;
1666 case CTDB_CONTROL_UPTIME:
1667 ret = ctdb_uptime_pull(buf, buflen, mem_ctx,
1668 &cd->data.uptime, &np);
1669 break;
1671 case CTDB_CONTROL_TRY_DELETE_RECORDS:
1672 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
1673 &cd->data.recbuf, &np);
1674 break;
1676 case CTDB_CONTROL_GET_CAPABILITIES:
1677 ret = ctdb_uint32_pull(buf, buflen, &cd->data.caps, &np);
1678 break;
1680 case CTDB_CONTROL_GET_PUBLIC_IPS:
1681 ret = ctdb_public_ip_list_pull(buf, buflen, mem_ctx,
1682 &cd->data.pubip_list, &np);
1683 break;
1685 case CTDB_CONTROL_GET_NODEMAP:
1686 ret = ctdb_node_map_pull(buf, buflen, mem_ctx,
1687 &cd->data.nodemap, &np);
1688 break;
1690 case CTDB_CONTROL_GET_RECLOCK_FILE:
1691 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1692 &cd->data.reclock_file, &np);
1693 break;
1695 case CTDB_CONTROL_GET_BAN_STATE:
1696 ret = ctdb_ban_state_pull(buf, buflen, mem_ctx,
1697 &cd->data.ban_state, &np);
1698 break;
1700 case CTDB_CONTROL_GET_DB_PRIORITY:
1701 break;
1703 case CTDB_CONTROL_GET_DB_SEQNUM:
1704 ret = ctdb_uint64_pull(buf, buflen, &cd->data.seqnum, &np);
1705 break;
1707 case CTDB_CONTROL_DB_GET_HEALTH:
1708 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1709 &cd->data.reason, &np);
1710 break;
1712 case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1713 ret = ctdb_public_ip_info_pull(buf, buflen, mem_ctx,
1714 &cd->data.ipinfo, &np);
1715 break;
1717 case CTDB_CONTROL_GET_IFACES:
1718 ret = ctdb_iface_list_pull(buf, buflen, mem_ctx,
1719 &cd->data.iface_list, &np);
1720 break;
1722 case CTDB_CONTROL_GET_STAT_HISTORY:
1723 ret = ctdb_statistics_list_pull(buf, buflen, mem_ctx,
1724 &cd->data.stats_list, &np);
1725 break;
1727 case CTDB_CONTROL_CHECK_SRVIDS:
1728 break;
1730 case CTDB_CONTROL_GET_DB_STATISTICS:
1731 ret = ctdb_db_statistics_pull(buf, buflen, mem_ctx,
1732 &cd->data.dbstats, &np);
1733 break;
1735 case CTDB_CONTROL_GET_RUNSTATE:
1736 ret = ctdb_uint32_pull(buf, buflen, &cd->data.runstate, &np);
1737 break;
1739 case CTDB_CONTROL_GET_NODES_FILE:
1740 ret = ctdb_node_map_pull(buf, buflen, mem_ctx,
1741 &cd->data.nodemap, &np);
1742 break;
1744 case CTDB_CONTROL_DB_PULL:
1745 ret = ctdb_uint32_pull(buf, buflen, &cd->data.num_records,
1746 &np);
1747 break;
1749 case CTDB_CONTROL_DB_PUSH_CONFIRM:
1750 ret = ctdb_uint32_pull(buf, buflen, &cd->data.num_records,
1751 &np);
1752 break;
1754 case CTDB_CONTROL_DB_OPEN_FLAGS:
1755 ret = ctdb_int32_pull(buf, buflen, &cd->data.tdb_flags, &np);
1756 break;
1758 case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1759 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1760 break;
1762 case CTDB_CONTROL_CHECK_PID_SRVID:
1763 break;
1766 if (ret != 0) {
1767 return ret;
1770 *npull = np;
1771 return 0;
1774 size_t ctdb_req_control_len(struct ctdb_req_header *h,
1775 struct ctdb_req_control *c)
1777 uint32_t u32 = 0;
1779 return ctdb_req_header_len(h) +
1780 ctdb_uint32_len(&c->opcode) +
1781 ctdb_uint32_len(&c->pad) +
1782 ctdb_uint64_len(&c->srvid) +
1783 ctdb_uint32_len(&c->client_id) +
1784 ctdb_uint32_len(&c->flags) +
1785 ctdb_uint32_len(&u32) +
1786 ctdb_req_control_data_len(&c->rdata);
1789 int ctdb_req_control_push(struct ctdb_req_header *h,
1790 struct ctdb_req_control *c,
1791 uint8_t *buf, size_t *buflen)
1793 size_t offset = 0, np;
1794 size_t length;
1795 uint32_t u32;
1797 length = ctdb_req_control_len(h, c);
1798 if (*buflen < length) {
1799 *buflen = length;
1800 return EMSGSIZE;
1803 h->length = *buflen;
1804 ctdb_req_header_push(h, buf+offset, &np);
1805 offset += np;
1807 ctdb_uint32_push(&c->opcode, buf+offset, &np);
1808 offset += np;
1810 ctdb_uint32_push(&c->pad, buf+offset, &np);
1811 offset += np;
1813 ctdb_uint64_push(&c->srvid, buf+offset, &np);
1814 offset += np;
1816 ctdb_uint32_push(&c->client_id, buf+offset, &np);
1817 offset += np;
1819 ctdb_uint32_push(&c->flags, buf+offset, &np);
1820 offset += np;
1822 u32 = ctdb_req_control_data_len(&c->rdata);
1823 ctdb_uint32_push(&u32, buf+offset, &np);
1824 offset += np;
1826 ctdb_req_control_data_push(&c->rdata, buf+offset, &np);
1827 offset += np;
1829 if (offset > *buflen) {
1830 return EMSGSIZE;
1833 return 0;
1836 int ctdb_req_control_pull(uint8_t *buf, size_t buflen,
1837 struct ctdb_req_header *h,
1838 TALLOC_CTX *mem_ctx,
1839 struct ctdb_req_control *c)
1841 struct ctdb_req_header header;
1842 size_t offset = 0, np;
1843 uint32_t u32;
1844 int ret;
1846 ret = ctdb_req_header_pull(buf+offset, buflen-offset, &header, &np);
1847 if (ret != 0) {
1848 return ret;
1850 offset += np;
1852 if (h != NULL) {
1853 *h = header;
1856 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->opcode, &np);
1857 if (ret != 0) {
1858 return ret;
1860 offset += np;
1862 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->pad, &np);
1863 if (ret != 0) {
1864 return ret;
1866 offset += np;
1868 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &c->srvid, &np);
1869 if (ret != 0) {
1870 return ret;
1872 offset += np;
1874 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->client_id, &np);
1875 if (ret != 0) {
1876 return ret;
1878 offset += np;
1880 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->flags, &np);
1881 if (ret != 0) {
1882 return ret;
1884 offset += np;
1886 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
1887 if (ret != 0) {
1888 return ret;
1890 offset += np;
1892 if (u32 > buflen-offset) {
1893 return EMSGSIZE;
1896 ret = ctdb_req_control_data_pull(buf+offset, u32, c->opcode, mem_ctx,
1897 &c->rdata, &np);
1898 if (ret != 0) {
1899 return ret;
1901 offset += np;
1903 if (offset > buflen) {
1904 return EMSGSIZE;
1907 return 0;
1910 size_t ctdb_reply_control_len(struct ctdb_req_header *h,
1911 struct ctdb_reply_control *c)
1913 uint32_t dsize, esize;
1915 if (c->status == 0) {
1916 dsize = ctdb_reply_control_data_len(&c->rdata);
1917 esize = 0;
1918 } else {
1919 dsize = 0;
1920 esize = ctdb_string_len(&c->errmsg);
1923 return ctdb_req_header_len(h) +
1924 ctdb_int32_len(&c->status) +
1925 ctdb_uint32_len(&dsize) +
1926 ctdb_uint32_len(&esize) +
1927 dsize + esize;
1930 int ctdb_reply_control_push(struct ctdb_req_header *h,
1931 struct ctdb_reply_control *c,
1932 uint8_t *buf, size_t *buflen)
1934 size_t offset = 0, np;
1935 size_t length;
1936 uint32_t dsize, esize;
1938 length = ctdb_reply_control_len(h, c);
1939 if (*buflen < length) {
1940 *buflen = length;
1941 return EMSGSIZE;
1944 h->length = *buflen;
1945 ctdb_req_header_push(h, buf+offset, &np);
1946 offset += np;
1948 ctdb_int32_push(&c->status, buf+offset, &np);
1949 offset += np;
1951 if (c->status == 0) {
1952 dsize = ctdb_reply_control_data_len(&c->rdata);
1953 esize = 0;
1954 } else {
1955 dsize = 0;
1956 esize = ctdb_string_len(&c->errmsg);
1959 ctdb_uint32_push(&dsize, buf+offset, &np);
1960 offset += np;
1962 ctdb_uint32_push(&esize, buf+offset, &np);
1963 offset += np;
1965 if (c->status == 0) {
1966 ctdb_reply_control_data_push(&c->rdata, buf+offset, &np);
1967 } else {
1968 ctdb_string_push(&c->errmsg, buf+offset, &np);
1970 offset += np;
1972 return 0;
1975 int ctdb_reply_control_pull(uint8_t *buf, size_t buflen, uint32_t opcode,
1976 struct ctdb_req_header *h,
1977 TALLOC_CTX *mem_ctx,
1978 struct ctdb_reply_control *c)
1980 struct ctdb_req_header header;
1981 size_t offset = 0, np;
1982 uint32_t dsize, esize;
1983 int ret;
1985 ret = ctdb_req_header_pull(buf+offset, buflen-offset, &header, &np);
1986 if (ret != 0) {
1987 return ret;
1989 offset += np;
1991 if (h != NULL) {
1992 *h = header;
1995 ret = ctdb_int32_pull(buf+offset, buflen-offset, &c->status, &np);
1996 if (ret != 0) {
1997 return ret;
1999 offset += np;
2001 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &dsize, &np);
2002 if (ret != 0) {
2003 return ret;
2005 offset += np;
2007 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &esize, &np);
2008 if (ret != 0) {
2009 return ret;
2011 offset += np;
2013 c->errmsg = NULL;
2015 if (c->status == 0) {
2016 if (buflen-offset < dsize) {
2017 return EMSGSIZE;
2020 ret = ctdb_reply_control_data_pull(buf+offset, dsize,
2021 opcode, mem_ctx, &c->rdata,
2022 &np);
2023 if (ret != 0) {
2024 return ret;
2026 offset += np;
2028 } else {
2029 if (buflen-offset < esize) {
2030 return EMSGSIZE;
2033 ret = ctdb_string_pull(buf+offset, esize, mem_ctx, &c->errmsg,
2034 &np);
2035 if (ret != 0) {
2036 return ret;
2038 offset += np;
2041 return 0;