2 CTDB protocol marshalling
4 Copyright (C) Amitay Isaacs 2015-2017
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/>.
21 #include "system/network.h"
27 #include "protocol_private.h"
28 #include "protocol_api.h"
30 size_t ctdb_tdb_data_len(TDB_DATA *in)
32 return in->dsize > UINT32_MAX ? UINT32_MAX : in->dsize;
35 void ctdb_tdb_data_push(TDB_DATA *in, uint8_t *buf, size_t *npush)
37 size_t len = ctdb_tdb_data_len(in);
40 memcpy(buf, in->dptr, len);
46 int ctdb_tdb_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
47 TDB_DATA *out, size_t *npull)
51 if (buflen > UINT32_MAX) {
57 val.dptr = talloc_memdup(mem_ctx, buf, buflen);
58 if (val.dptr == NULL) {
70 size_t ctdb_tdb_datan_len(TDB_DATA *in)
72 uint32_t u32 = ctdb_tdb_data_len(in);
74 return ctdb_uint32_len(&u32) + u32;
77 void ctdb_tdb_datan_push(TDB_DATA *in, uint8_t *buf, size_t *npush)
79 size_t offset = 0, np;
80 uint32_t u32 = ctdb_tdb_data_len(in);
82 ctdb_uint32_push(&u32, buf+offset, &np);
85 ctdb_tdb_data_push(in, buf+offset, &np);
91 int ctdb_tdb_datan_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
92 TDB_DATA *out, size_t *npull)
94 size_t offset = 0, np;
98 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
104 if (buflen-offset < u32) {
108 ret = ctdb_tdb_data_pull(buf+offset, u32, mem_ctx, out, &np);
118 size_t ctdb_latency_counter_len(struct ctdb_latency_counter *in)
120 return ctdb_int32_len(&in->num) +
121 ctdb_padding_len(4) +
122 ctdb_double_len(&in->min) +
123 ctdb_double_len(&in->max) +
124 ctdb_double_len(&in->total);
127 void ctdb_latency_counter_push(struct ctdb_latency_counter *in, uint8_t *buf,
130 size_t offset = 0, np;
132 ctdb_int32_push(&in->num, buf+offset, &np);
135 ctdb_padding_push(4, buf+offset, &np);
138 ctdb_double_push(&in->min, buf+offset, &np);
141 ctdb_double_push(&in->max, buf+offset, &np);
144 ctdb_double_push(&in->total, buf+offset, &np);
150 int ctdb_latency_counter_pull(uint8_t *buf, size_t buflen,
151 struct ctdb_latency_counter *out, size_t *npull)
153 size_t offset = 0, np;
156 ret = ctdb_int32_pull(buf+offset, buflen-offset, &out->num, &np);
162 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
168 ret = ctdb_double_pull(buf+offset, buflen-offset, &out->min, &np);
174 ret = ctdb_double_pull(buf+offset, buflen-offset, &out->max, &np);
180 ret = ctdb_double_pull(buf+offset, buflen-offset, &out->total, &np);
190 size_t ctdb_statistics_len(struct ctdb_statistics *in)
192 return ctdb_uint32_len(&in->num_clients) +
193 ctdb_uint32_len(&in->frozen) +
194 ctdb_uint32_len(&in->recovering) +
195 ctdb_uint32_len(&in->client_packets_sent) +
196 ctdb_uint32_len(&in->client_packets_recv) +
197 ctdb_uint32_len(&in->node_packets_sent) +
198 ctdb_uint32_len(&in->node_packets_recv) +
199 ctdb_uint32_len(&in->keepalive_packets_sent) +
200 ctdb_uint32_len(&in->keepalive_packets_recv) +
201 ctdb_uint32_len(&in->node.req_call) +
202 ctdb_uint32_len(&in->node.reply_call) +
203 ctdb_uint32_len(&in->node.req_dmaster) +
204 ctdb_uint32_len(&in->node.reply_dmaster) +
205 ctdb_uint32_len(&in->node.reply_error) +
206 ctdb_uint32_len(&in->node.req_message) +
207 ctdb_uint32_len(&in->node.req_control) +
208 ctdb_uint32_len(&in->node.reply_control) +
209 ctdb_uint32_len(&in->client.req_call) +
210 ctdb_uint32_len(&in->client.req_message) +
211 ctdb_uint32_len(&in->client.req_control) +
212 ctdb_uint32_len(&in->timeouts.call) +
213 ctdb_uint32_len(&in->timeouts.control) +
214 ctdb_uint32_len(&in->timeouts.traverse) +
215 ctdb_padding_len(4) +
216 ctdb_latency_counter_len(&in->reclock.ctdbd) +
217 ctdb_latency_counter_len(&in->reclock.recd) +
218 ctdb_uint32_len(&in->locks.num_calls) +
219 ctdb_uint32_len(&in->locks.num_current) +
220 ctdb_uint32_len(&in->locks.num_pending) +
221 ctdb_uint32_len(&in->locks.num_failed) +
222 ctdb_latency_counter_len(&in->locks.latency) +
223 MAX_COUNT_BUCKETS * ctdb_uint32_len(&in->locks.buckets[0]) +
224 ctdb_uint32_len(&in->total_calls) +
225 ctdb_uint32_len(&in->pending_calls) +
226 ctdb_uint32_len(&in->childwrite_calls) +
227 ctdb_uint32_len(&in->pending_childwrite_calls) +
228 ctdb_uint32_len(&in->memory_used) +
229 ctdb_uint32_len(&in->__last_counter) +
230 ctdb_uint32_len(&in->max_hop_count) +
232 ctdb_uint32_len(&in->hop_count_bucket[0]) +
233 ctdb_padding_len(4) +
234 ctdb_latency_counter_len(&in->call_latency) +
235 ctdb_latency_counter_len(&in->childwrite_latency) +
236 ctdb_uint32_len(&in->num_recoveries) +
237 ctdb_padding_len(4) +
238 ctdb_timeval_len(&in->statistics_start_time) +
239 ctdb_timeval_len(&in->statistics_current_time) +
240 ctdb_uint32_len(&in->total_ro_delegations) +
241 ctdb_uint32_len(&in->total_ro_revokes);
244 void ctdb_statistics_push(struct ctdb_statistics *in, uint8_t *buf,
247 size_t offset = 0, np;
250 ctdb_uint32_push(&in->num_clients, buf+offset, &np);
253 ctdb_uint32_push(&in->frozen, buf+offset, &np);
256 ctdb_uint32_push(&in->recovering, buf+offset, &np);
259 ctdb_uint32_push(&in->client_packets_sent, buf+offset, &np);
262 ctdb_uint32_push(&in->client_packets_recv, buf+offset, &np);
265 ctdb_uint32_push(&in->node_packets_sent, buf+offset, &np);
268 ctdb_uint32_push(&in->node_packets_recv, buf+offset, &np);
271 ctdb_uint32_push(&in->keepalive_packets_sent, buf+offset, &np);
274 ctdb_uint32_push(&in->keepalive_packets_recv, buf+offset, &np);
277 ctdb_uint32_push(&in->node.req_call, buf+offset, &np);
280 ctdb_uint32_push(&in->node.reply_call, buf+offset, &np);
283 ctdb_uint32_push(&in->node.req_dmaster, buf+offset, &np);
286 ctdb_uint32_push(&in->node.reply_dmaster, buf+offset, &np);
289 ctdb_uint32_push(&in->node.reply_error, buf+offset, &np);
292 ctdb_uint32_push(&in->node.req_message, buf+offset, &np);
295 ctdb_uint32_push(&in->node.req_control, buf+offset, &np);
298 ctdb_uint32_push(&in->node.reply_control, buf+offset, &np);
301 ctdb_uint32_push(&in->client.req_call, buf+offset, &np);
304 ctdb_uint32_push(&in->client.req_message, buf+offset, &np);
307 ctdb_uint32_push(&in->client.req_control, buf+offset, &np);
310 ctdb_uint32_push(&in->timeouts.call, buf+offset, &np);
313 ctdb_uint32_push(&in->timeouts.control, buf+offset, &np);
316 ctdb_uint32_push(&in->timeouts.traverse, buf+offset, &np);
319 ctdb_padding_push(4, buf+offset, &np);
322 ctdb_latency_counter_push(&in->reclock.ctdbd, buf+offset, &np);
325 ctdb_latency_counter_push(&in->reclock.recd, buf+offset, &np);
328 ctdb_uint32_push(&in->locks.num_calls, buf+offset, &np);
331 ctdb_uint32_push(&in->locks.num_current, buf+offset, &np);
334 ctdb_uint32_push(&in->locks.num_pending, buf+offset, &np);
337 ctdb_uint32_push(&in->locks.num_failed, buf+offset, &np);
340 ctdb_latency_counter_push(&in->locks.latency, buf+offset, &np);
343 for (i=0; i<MAX_COUNT_BUCKETS; i++) {
344 ctdb_uint32_push(&in->locks.buckets[i], buf+offset, &np);
348 ctdb_uint32_push(&in->total_calls, buf+offset, &np);
351 ctdb_uint32_push(&in->pending_calls, buf+offset, &np);
354 ctdb_uint32_push(&in->childwrite_calls, buf+offset, &np);
357 ctdb_uint32_push(&in->pending_childwrite_calls, buf+offset, &np);
360 ctdb_uint32_push(&in->memory_used, buf+offset, &np);
363 ctdb_uint32_push(&in->__last_counter, buf+offset, &np);
366 ctdb_uint32_push(&in->max_hop_count, buf+offset, &np);
369 for (i=0; i<MAX_COUNT_BUCKETS; i++) {
370 ctdb_uint32_push(&in->hop_count_bucket[i], buf+offset, &np);
374 ctdb_padding_push(4, buf+offset, &np);
377 ctdb_latency_counter_push(&in->call_latency, buf+offset, &np);
380 ctdb_latency_counter_push(&in->childwrite_latency, buf+offset, &np);
383 ctdb_uint32_push(&in->num_recoveries, buf+offset, &np);
386 ctdb_padding_push(4, buf+offset, &np);
389 ctdb_timeval_push(&in->statistics_start_time, buf+offset, &np);
392 ctdb_timeval_push(&in->statistics_current_time, buf+offset, &np);
395 ctdb_uint32_push(&in->total_ro_delegations, buf+offset, &np);
398 ctdb_uint32_push(&in->total_ro_revokes, buf+offset, &np);
404 static int ctdb_statistics_pull_elems(uint8_t *buf, size_t buflen,
406 struct ctdb_statistics *out,
409 size_t offset = 0, np;
412 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->num_clients,
419 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->frozen, &np);
425 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->recovering,
432 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
433 &out->client_packets_sent, &np);
439 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
440 &out->client_packets_recv, &np);
446 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
447 &out->node_packets_sent, &np);
453 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
454 &out->node_packets_recv, &np);
460 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
461 &out->keepalive_packets_sent, &np);
467 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
468 &out->keepalive_packets_recv, &np);
474 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
475 &out->node.req_call, &np);
481 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
482 &out->node.reply_call, &np);
488 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
489 &out->node.req_dmaster, &np);
495 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
496 &out->node.reply_dmaster, &np);
502 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
503 &out->node.reply_error, &np);
509 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
510 &out->node.req_message, &np);
516 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
517 &out->node.req_control, &np);
523 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
524 &out->node.reply_control, &np);
530 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
531 &out->client.req_call, &np);
537 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
538 &out->client.req_message, &np);
544 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
545 &out->client.req_control, &np);
551 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
552 &out->timeouts.call, &np);
558 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
559 &out->timeouts.control, &np);
565 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
566 &out->timeouts.traverse, &np);
572 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
578 ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
579 &out->reclock.ctdbd, &np);
585 ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
586 &out->reclock.recd, &np);
592 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
593 &out->locks.num_calls, &np);
599 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
600 &out->locks.num_current, &np);
606 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
607 &out->locks.num_pending, &np);
613 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
614 &out->locks.num_failed, &np);
620 ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
621 &out->locks.latency, &np);
627 for (i=0; i<MAX_COUNT_BUCKETS; i++) {
628 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
629 &out->locks.buckets[i], &np);
636 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
637 &out->total_calls, &np);
643 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
644 &out->pending_calls, &np);
650 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
651 &out->childwrite_calls, &np);
657 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
658 &out->pending_childwrite_calls, &np);
664 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->memory_used,
671 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
672 &out->__last_counter, &np);
678 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
679 &out->max_hop_count, &np);
685 for (i=0; i<MAX_COUNT_BUCKETS; i++) {
686 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
687 &out->hop_count_bucket[i], &np);
694 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
700 ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
701 &out->call_latency, &np);
707 ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
708 &out->childwrite_latency, &np);
714 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
715 &out->num_recoveries, &np);
721 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
727 ret = ctdb_timeval_pull(buf+offset, buflen-offset,
728 &out->statistics_start_time, &np);
734 ret = ctdb_timeval_pull(buf+offset, buflen-offset,
735 &out->statistics_current_time, &np);
741 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
742 &out->total_ro_delegations, &np);
748 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
749 &out->total_ro_revokes, &np);
759 int ctdb_statistics_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
760 struct ctdb_statistics **out, size_t *npull)
762 struct ctdb_statistics *val;
766 val = talloc(mem_ctx, struct ctdb_statistics);
771 ret = ctdb_statistics_pull_elems(buf, buflen, val, val, &np);
782 size_t ctdb_statistics_list_len(struct ctdb_statistics_list *in)
786 len = ctdb_int32_len(&in->num) + ctdb_padding_len(4);
788 len += in->num * ctdb_statistics_len(&in->stats[0]);
794 void ctdb_statistics_list_push(struct ctdb_statistics_list *in,
795 uint8_t *buf, size_t *npush)
797 size_t offset = 0, np;
800 ctdb_int32_push(&in->num, buf+offset, &np);
803 ctdb_padding_push(4, buf+offset, &np);
806 for (i=0; i<in->num; i++) {
807 ctdb_statistics_push(&in->stats[i], buf+offset, &np);
814 int ctdb_statistics_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
815 struct ctdb_statistics_list **out,
818 struct ctdb_statistics_list *val;
819 size_t offset = 0, np;
822 val = talloc(mem_ctx, struct ctdb_statistics_list);
827 ret = ctdb_int32_pull(buf+offset, buflen-offset, &val->num, &np);
833 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
844 val->stats = talloc_array(val, struct ctdb_statistics, val->num);
845 if (val->stats == NULL) {
850 for (i=0; i<val->num; i++) {
851 ret = ctdb_statistics_pull_elems(buf+offset, buflen-offset,
852 val, &val->stats[i], &np);
869 size_t ctdb_vnn_map_len(struct ctdb_vnn_map *in)
873 len = ctdb_uint32_len(&in->generation) + ctdb_uint32_len(&in->size);
875 len += in->size * ctdb_uint32_len(&in->map[0]);
881 void ctdb_vnn_map_push(struct ctdb_vnn_map *in, uint8_t *buf, size_t *npush)
883 size_t offset = 0, np;
886 ctdb_uint32_push(&in->generation, buf+offset, &np);
889 ctdb_uint32_push(&in->size, buf+offset, &np);
892 for (i=0; i<in->size; i++) {
893 ctdb_uint32_push(&in->map[i], buf+offset, &np);
900 int ctdb_vnn_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
901 struct ctdb_vnn_map **out, size_t *npull)
903 struct ctdb_vnn_map *val;
904 size_t offset = 0, np;
908 val = talloc(mem_ctx, struct ctdb_vnn_map);
913 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->generation,
920 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->size, &np);
926 if (val->size == 0) {
931 val->map = talloc_array(val, uint32_t, val->size);
932 if (val->map == NULL) {
937 for (i=0; i<val->size; i++) {
938 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
956 size_t ctdb_dbid_len(struct ctdb_dbid *in)
958 return ctdb_uint32_len(&in->db_id) +
959 ctdb_uint8_len(&in->flags) +
963 void ctdb_dbid_push(struct ctdb_dbid *in, uint8_t *buf, size_t *npush)
965 size_t offset = 0, np;
967 ctdb_uint32_push(&in->db_id, buf+offset, &np);
970 ctdb_uint8_push(&in->flags, buf+offset, &np);
973 ctdb_padding_push(3, buf+offset, &np);
979 static int ctdb_dbid_pull_elems(uint8_t *buf, size_t buflen,
980 TALLOC_CTX *mem_ctx, struct ctdb_dbid *out,
983 size_t offset = 0, np;
986 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->db_id, &np);
992 ret = ctdb_uint8_pull(buf+offset, buflen-offset, &out->flags, &np);
998 ret = ctdb_padding_pull(buf+offset, buflen-offset, 3, &np);
1008 int ctdb_dbid_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
1009 struct ctdb_dbid **out, size_t *npull)
1011 struct ctdb_dbid *val;
1015 val = talloc(mem_ctx, struct ctdb_dbid);
1020 ret = ctdb_dbid_pull_elems(buf, buflen, val, val, &np);
1031 size_t ctdb_dbid_map_len(struct ctdb_dbid_map *in)
1035 len = ctdb_uint32_len(&in->num);
1037 len += in->num * ctdb_dbid_len(&in->dbs[0]);
1043 void ctdb_dbid_map_push(struct ctdb_dbid_map *in, uint8_t *buf, size_t *npush)
1045 size_t offset = 0, np;
1048 ctdb_uint32_push(&in->num, buf+offset, &np);
1051 for (i=0; i<in->num; i++) {
1052 ctdb_dbid_push(&in->dbs[i], buf+offset, &np);
1059 int ctdb_dbid_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
1060 struct ctdb_dbid_map **out, size_t *npull)
1062 struct ctdb_dbid_map *val;
1063 size_t offset = 0, np;
1067 val = talloc(mem_ctx, struct ctdb_dbid_map);
1072 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
1078 if (val->num == 0) {
1083 val->dbs = talloc_array(val, struct ctdb_dbid, val->num);
1084 if (val->dbs == NULL) {
1089 for (i=0; i<val->num; i++) {
1090 ret = ctdb_dbid_pull_elems(buf+offset, buflen-offset, val,
1108 size_t ctdb_pulldb_len(struct ctdb_pulldb *in)
1110 return ctdb_uint32_len(&in->db_id) +
1111 ctdb_uint32_len(&in->lmaster);
1114 void ctdb_pulldb_push(struct ctdb_pulldb *in, uint8_t *buf, size_t *npush)
1116 size_t offset = 0, np;
1118 ctdb_uint32_push(&in->db_id, buf+offset, &np);
1121 ctdb_uint32_push(&in->lmaster, buf+offset, &np);
1127 int ctdb_pulldb_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
1128 struct ctdb_pulldb **out, size_t *npull)
1130 struct ctdb_pulldb *val;
1131 size_t offset = 0, np;
1134 val = talloc(mem_ctx, struct ctdb_pulldb);
1139 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
1146 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->lmaster, &np);
1158 size_t ctdb_pulldb_ext_len(struct ctdb_pulldb_ext *in)
1160 return ctdb_uint32_len(&in->db_id) +
1161 ctdb_uint32_len(&in->lmaster) +
1162 ctdb_uint64_len(&in->srvid);
1165 void ctdb_pulldb_ext_push(struct ctdb_pulldb_ext *in, uint8_t *buf,
1168 size_t offset = 0, np;
1170 ctdb_uint32_push(&in->db_id, buf+offset, &np);
1173 ctdb_uint32_push(&in->lmaster, buf+offset, &np);
1176 ctdb_uint64_push(&in->srvid, buf+offset, &np);
1182 int ctdb_pulldb_ext_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
1183 struct ctdb_pulldb_ext **out, size_t *npull)
1185 struct ctdb_pulldb_ext *val;
1186 size_t offset = 0, np;
1189 val = talloc(mem_ctx, struct ctdb_pulldb_ext);
1194 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
1200 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->lmaster, &np);
1206 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
1221 size_t ctdb_ltdb_header_len(struct ctdb_ltdb_header *in)
1223 return ctdb_uint64_len(&in->rsn) +
1224 ctdb_uint32_len(&in->dmaster) +
1225 ctdb_uint32_len(&in->reserved1) +
1226 ctdb_uint32_len(&in->flags) +
1227 ctdb_padding_len(4);
1230 void ctdb_ltdb_header_push(struct ctdb_ltdb_header *in, uint8_t *buf,
1233 size_t offset = 0, np;
1235 ctdb_uint64_push(&in->rsn, buf+offset, &np);
1238 ctdb_uint32_push(&in->dmaster, buf+offset, &np);
1241 ctdb_uint32_push(&in->reserved1, buf+offset, &np);
1244 ctdb_uint32_push(&in->flags, buf+offset, &np);
1247 ctdb_padding_push(4, buf+offset, &np);
1253 int ctdb_ltdb_header_pull(uint8_t *buf, size_t buflen,
1254 struct ctdb_ltdb_header *out, size_t *npull)
1256 size_t offset = 0, np;
1259 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &out->rsn, &np);
1265 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->dmaster, &np);
1271 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->reserved1,
1278 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->flags, &np);
1284 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
1294 int ctdb_ltdb_header_extract(TDB_DATA *data, struct ctdb_ltdb_header *header)
1299 ret = ctdb_ltdb_header_pull(data->dptr, data->dsize, header, &np);
1310 size_t ctdb_rec_data_len(struct ctdb_rec_data *in)
1314 u32 = ctdb_uint32_len(&in->reqid) +
1315 ctdb_tdb_datan_len(&in->key) +
1316 ctdb_tdb_datan_len(&in->data);
1318 if (in->header != NULL) {
1319 u32 += ctdb_ltdb_header_len(in->header);
1322 return ctdb_uint32_len(&u32) + u32;
1325 void ctdb_rec_data_push(struct ctdb_rec_data *in, uint8_t *buf, size_t *npush)
1327 size_t offset = 0, np;
1330 u32 = ctdb_rec_data_len(in);
1331 ctdb_uint32_push(&u32, buf+offset, &np);
1334 ctdb_uint32_push(&in->reqid, buf+offset, &np);
1337 u32 = ctdb_tdb_data_len(&in->key);
1338 ctdb_uint32_push(&u32, buf+offset, &np);
1341 u32 = ctdb_tdb_data_len(&in->data);
1342 if (in->header != NULL) {
1343 u32 += ctdb_ltdb_header_len(in->header);
1346 ctdb_uint32_push(&u32, buf+offset, &np);
1349 ctdb_tdb_data_push(&in->key, buf+offset, &np);
1352 /* If ltdb header is not NULL, then it is pushed as part of the data */
1353 if (in->header != NULL) {
1354 ctdb_ltdb_header_push(in->header, buf+offset, &np);
1357 ctdb_tdb_data_push(&in->data, buf+offset, &np);
1363 static int ctdb_rec_data_pull_data(uint8_t *buf, size_t buflen,
1365 TDB_DATA *key, TDB_DATA *data,
1368 size_t offset = 0, np;
1373 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
1384 ret = ctdb_uint32_pull(buf+offset, len-offset, reqid, &np);
1390 ret = ctdb_uint32_pull(buf+offset, len-offset, &u32, &np);
1397 ret = ctdb_uint32_pull(buf+offset, len-offset, &u32, &np);
1404 if (len-offset < key->dsize) {
1408 key->dptr = buf+offset;
1409 offset += key->dsize;
1411 if (len-offset < data->dsize) {
1415 data->dptr = buf+offset;
1416 offset += data->dsize;
1422 static int ctdb_rec_data_pull_elems(uint8_t *buf, size_t buflen,
1423 TALLOC_CTX *mem_ctx,
1424 struct ctdb_rec_data *out,
1432 ret = ctdb_rec_data_pull_data(buf, buflen, &reqid, &key, &data, &np);
1439 /* Always set header to NULL. If it is required, extract it using
1440 * ctdb_rec_data_extract_header()
1444 out->key.dsize = key.dsize;
1445 if (key.dsize > 0) {
1446 out->key.dptr = talloc_memdup(mem_ctx, key.dptr, key.dsize);
1447 if (out->key.dptr == NULL) {
1452 out->data.dsize = data.dsize;
1453 if (data.dsize > 0) {
1454 out->data.dptr = talloc_memdup(mem_ctx, data.dptr, data.dsize);
1455 if (out->data.dptr == NULL) {
1464 int ctdb_rec_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
1465 struct ctdb_rec_data **out, size_t *npull)
1467 struct ctdb_rec_data *val;
1471 val = talloc(mem_ctx, struct ctdb_rec_data);
1476 ret = ctdb_rec_data_pull_elems(buf, buflen, val, val, &np);
1487 size_t ctdb_rec_buffer_len(struct ctdb_rec_buffer *in)
1489 return ctdb_uint32_len(&in->db_id) +
1490 ctdb_uint32_len(&in->count) +
1494 void ctdb_rec_buffer_push(struct ctdb_rec_buffer *in, uint8_t *buf,
1497 size_t offset = 0, np;
1499 ctdb_uint32_push(&in->db_id, buf+offset, &np);
1502 ctdb_uint32_push(&in->count, buf+offset, &np);
1505 memcpy(buf+offset, in->buf, in->buflen);
1506 offset += in->buflen;
1511 int ctdb_rec_buffer_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
1512 struct ctdb_rec_buffer **out, size_t *npull)
1514 struct ctdb_rec_buffer *val;
1515 size_t offset = 0, np;
1519 val = talloc(mem_ctx, struct ctdb_rec_buffer);
1524 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
1530 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->count, &np);
1536 /* Since there is no buflen provided, walk the records to
1537 * validate the length of the buffer.
1539 val->buf = buf+offset;
1540 val->buflen = buflen-offset;
1543 ret = ctdb_rec_buffer_traverse(val, NULL, &length);
1548 if (length > buflen-offset) {
1553 val->buf = talloc_memdup(val, buf+offset, length);
1554 if (val->buf == NULL) {
1558 val->buflen = length;
1570 struct ctdb_rec_buffer *ctdb_rec_buffer_init(TALLOC_CTX *mem_ctx,
1573 struct ctdb_rec_buffer *recbuf;
1575 recbuf = talloc_zero(mem_ctx, struct ctdb_rec_buffer);
1576 if (recbuf == NULL) {
1580 recbuf->db_id = db_id;
1585 int ctdb_rec_buffer_add(TALLOC_CTX *mem_ctx, struct ctdb_rec_buffer *recbuf,
1586 uint32_t reqid, struct ctdb_ltdb_header *header,
1587 TDB_DATA key, TDB_DATA data)
1589 struct ctdb_rec_data recdata;
1593 recdata.reqid = reqid;
1594 recdata.header = header;
1596 recdata.data = data;
1598 len = ctdb_rec_data_len(&recdata);
1600 ptr = talloc_realloc(mem_ctx, recbuf->buf, uint8_t,
1601 recbuf->buflen + len);
1606 ctdb_rec_data_push(&recdata, &ptr[recbuf->buflen], &np);
1610 recbuf->buflen += np;
1614 int ctdb_rec_buffer_traverse(struct ctdb_rec_buffer *recbuf,
1615 ctdb_rec_parser_func_t func,
1620 size_t offset, reclen;
1624 for (i=0; i<recbuf->count; i++) {
1625 ret = ctdb_rec_data_pull_data(&recbuf->buf[offset],
1626 recbuf->buflen - offset,
1627 &reqid, &key, &data, &reclen);
1633 ret = func(reqid, NULL, key, data, private_data);
1647 size_t *length = (size_t *)private_data;
1655 int ctdb_rec_buffer_write(struct ctdb_rec_buffer *recbuf, int fd)
1659 n = write(fd, &recbuf->db_id, sizeof(uint32_t));
1660 if (n == -1 || n != sizeof(uint32_t)) {
1661 return (errno != 0 ? errno : EIO);
1663 n = write(fd, &recbuf->count, sizeof(uint32_t));
1664 if (n == -1 || n != sizeof(uint32_t)) {
1665 return (errno != 0 ? errno : EIO);
1667 n = write(fd, &recbuf->buflen, sizeof(size_t));
1668 if (n == -1 || n != sizeof(size_t)) {
1669 return (errno != 0 ? errno : EIO);
1671 n = write(fd, recbuf->buf, recbuf->buflen);
1672 if (n == -1 || n != recbuf->buflen) {
1673 return (errno != 0 ? errno : EIO);
1679 int ctdb_rec_buffer_read(int fd, TALLOC_CTX *mem_ctx,
1680 struct ctdb_rec_buffer **out)
1682 struct ctdb_rec_buffer *recbuf;
1685 recbuf = talloc(mem_ctx, struct ctdb_rec_buffer);
1686 if (recbuf == NULL) {
1690 n = read(fd, &recbuf->db_id, sizeof(uint32_t));
1691 if (n == -1 || n != sizeof(uint32_t)) {
1692 return (errno != 0 ? errno : EIO);
1694 n = read(fd, &recbuf->count, sizeof(uint32_t));
1695 if (n == -1 || n != sizeof(uint32_t)) {
1696 return (errno != 0 ? errno : EIO);
1698 n = read(fd, &recbuf->buflen, sizeof(size_t));
1699 if (n == -1 || n != sizeof(size_t)) {
1700 return (errno != 0 ? errno : EIO);
1703 recbuf->buf = talloc_size(recbuf, recbuf->buflen);
1704 if (recbuf->buf == NULL) {
1708 n = read(fd, recbuf->buf, recbuf->buflen);
1709 if (n == -1 || n != recbuf->buflen) {
1710 return (errno != 0 ? errno : EIO);
1717 size_t ctdb_traverse_start_len(struct ctdb_traverse_start *in)
1719 return ctdb_uint32_len(&in->db_id) +
1720 ctdb_uint32_len(&in->reqid) +
1721 ctdb_uint64_len(&in->srvid);
1724 void ctdb_traverse_start_push(struct ctdb_traverse_start *in, uint8_t *buf,
1727 size_t offset = 0, np;
1729 ctdb_uint32_push(&in->db_id, buf+offset, &np);
1732 ctdb_uint32_push(&in->reqid, buf+offset, &np);
1735 ctdb_uint64_push(&in->srvid, buf+offset, &np);
1741 int ctdb_traverse_start_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
1742 struct ctdb_traverse_start **out, size_t *npull)
1744 struct ctdb_traverse_start *val;
1745 size_t offset = 0, np;
1748 val = talloc(mem_ctx, struct ctdb_traverse_start);
1753 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
1759 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->reqid, &np);
1765 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
1780 size_t ctdb_traverse_all_len(struct ctdb_traverse_all *in)
1782 return ctdb_uint32_len(&in->db_id) +
1783 ctdb_uint32_len(&in->reqid) +
1784 ctdb_uint32_len(&in->pnn) +
1785 ctdb_uint32_len(&in->client_reqid) +
1786 ctdb_uint64_len(&in->srvid);
1789 void ctdb_traverse_all_push(struct ctdb_traverse_all *in, uint8_t *buf,
1792 size_t offset = 0, np;
1794 ctdb_uint32_push(&in->db_id, buf+offset, &np);
1797 ctdb_uint32_push(&in->reqid, buf+offset, &np);
1800 ctdb_uint32_push(&in->pnn, buf+offset, &np);
1803 ctdb_uint32_push(&in->client_reqid, buf+offset, &np);
1806 ctdb_uint64_push(&in->srvid, buf+offset, &np);
1812 int ctdb_traverse_all_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
1813 struct ctdb_traverse_all **out, size_t *npull)
1815 struct ctdb_traverse_all *val;
1816 size_t offset = 0, np;
1819 val = talloc(mem_ctx, struct ctdb_traverse_all);
1824 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
1830 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->reqid, &np);
1836 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
1842 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->client_reqid,
1849 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
1864 size_t ctdb_traverse_start_ext_len(struct ctdb_traverse_start_ext *in)
1866 return ctdb_uint32_len(&in->db_id) +
1867 ctdb_uint32_len(&in->reqid) +
1868 ctdb_uint64_len(&in->srvid) +
1869 ctdb_bool_len(&in->withemptyrecords) +
1870 ctdb_padding_len(7);
1873 void ctdb_traverse_start_ext_push(struct ctdb_traverse_start_ext *in,
1874 uint8_t *buf, size_t *npush)
1876 size_t offset = 0, np;
1878 ctdb_uint32_push(&in->db_id, buf+offset, &np);
1881 ctdb_uint32_push(&in->reqid, buf+offset, &np);
1884 ctdb_uint64_push(&in->srvid, buf+offset, &np);
1887 ctdb_bool_push(&in->withemptyrecords, buf+offset, &np);
1890 ctdb_padding_push(7, buf+offset, &np);
1896 int ctdb_traverse_start_ext_pull(uint8_t *buf, size_t buflen,
1897 TALLOC_CTX *mem_ctx,
1898 struct ctdb_traverse_start_ext **out,
1901 struct ctdb_traverse_start_ext *val;
1902 size_t offset = 0, np;
1905 val = talloc(mem_ctx, struct ctdb_traverse_start_ext);
1910 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
1916 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->reqid, &np);
1922 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
1928 ret = ctdb_bool_pull(buf+offset, buflen-offset,
1929 &val->withemptyrecords, &np);
1935 ret = ctdb_padding_pull(buf+offset, buflen-offset, 7, &np);
1950 size_t ctdb_traverse_all_ext_len(struct ctdb_traverse_all_ext *in)
1952 return ctdb_uint32_len(&in->db_id) +
1953 ctdb_uint32_len(&in->reqid) +
1954 ctdb_uint32_len(&in->pnn) +
1955 ctdb_uint32_len(&in->client_reqid) +
1956 ctdb_uint64_len(&in->srvid) +
1957 ctdb_bool_len(&in->withemptyrecords) +
1958 ctdb_padding_len(7);
1961 void ctdb_traverse_all_ext_push(struct ctdb_traverse_all_ext *in,
1962 uint8_t *buf, size_t *npush)
1964 size_t offset = 0, np;
1966 ctdb_uint32_push(&in->db_id, buf+offset, &np);
1969 ctdb_uint32_push(&in->reqid, buf+offset, &np);
1972 ctdb_uint32_push(&in->pnn, buf+offset, &np);
1975 ctdb_uint32_push(&in->client_reqid, buf+offset, &np);
1978 ctdb_uint64_push(&in->srvid, buf+offset, &np);
1981 ctdb_bool_push(&in->withemptyrecords, buf+offset, &np);
1984 ctdb_padding_push(7, buf+offset, &np);
1990 int ctdb_traverse_all_ext_pull(uint8_t *buf, size_t buflen,
1991 TALLOC_CTX *mem_ctx,
1992 struct ctdb_traverse_all_ext **out,
1995 struct ctdb_traverse_all_ext *val;
1996 size_t offset = 0, np;
1999 val = talloc(mem_ctx, struct ctdb_traverse_all_ext);
2004 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
2010 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->reqid, &np);
2016 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
2022 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->client_reqid,
2029 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
2035 ret = ctdb_bool_pull(buf+offset, buflen-offset,
2036 &val->withemptyrecords, &np);
2042 ret = ctdb_padding_pull(buf+offset, buflen-offset, 7, &np);
2057 size_t ctdb_sock_addr_len(ctdb_sock_addr *in)
2059 return sizeof(ctdb_sock_addr);
2062 void ctdb_sock_addr_push(ctdb_sock_addr *in, uint8_t *buf, size_t *npush)
2064 memcpy(buf, in, sizeof(ctdb_sock_addr));
2065 *npush = sizeof(ctdb_sock_addr);
2068 int ctdb_sock_addr_pull_elems(uint8_t *buf, size_t buflen,
2069 TALLOC_CTX *mem_ctx, ctdb_sock_addr *out,
2072 if (buflen < sizeof(ctdb_sock_addr)) {
2076 memcpy(out, buf, sizeof(ctdb_sock_addr));
2077 *npull = sizeof(ctdb_sock_addr);
2082 int ctdb_sock_addr_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
2083 ctdb_sock_addr **out, size_t *npull)
2085 ctdb_sock_addr *val;
2089 val = talloc(mem_ctx, ctdb_sock_addr);
2094 ret = ctdb_sock_addr_pull_elems(buf, buflen, val, val, &np);
2105 size_t ctdb_connection_len(struct ctdb_connection *in)
2107 return ctdb_sock_addr_len(&in->src) +
2108 ctdb_sock_addr_len(&in->dst);
2111 void ctdb_connection_push(struct ctdb_connection *in, uint8_t *buf,
2114 size_t offset = 0, np;
2116 ctdb_sock_addr_push(&in->src, buf+offset, &np);
2119 ctdb_sock_addr_push(&in->dst, buf+offset, &np);
2125 static int ctdb_connection_pull_elems(uint8_t *buf, size_t buflen,
2126 TALLOC_CTX *mem_ctx,
2127 struct ctdb_connection *out,
2130 size_t offset = 0, np;
2133 ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset,
2134 mem_ctx, &out->src, &np);
2140 ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset,
2141 mem_ctx, &out->dst, &np);
2151 int ctdb_connection_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
2152 struct ctdb_connection **out, size_t *npull)
2154 struct ctdb_connection *val;
2158 val = talloc(mem_ctx, struct ctdb_connection);
2163 ret = ctdb_connection_pull_elems(buf, buflen, val, val, &np);
2174 size_t ctdb_connection_list_len(struct ctdb_connection_list *in)
2178 len = ctdb_uint32_len(&in->num);
2180 len += in->num * ctdb_connection_len(&in->conn[0]);
2186 void ctdb_connection_list_push(struct ctdb_connection_list *in, uint8_t *buf,
2189 size_t offset = 0, np;
2192 ctdb_uint32_push(&in->num, buf+offset, &np);
2195 for (i=0; i<in->num; i++) {
2196 ctdb_connection_push(&in->conn[i], buf+offset, &np);
2203 int ctdb_connection_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
2204 struct ctdb_connection_list **out, size_t *npull)
2206 struct ctdb_connection_list *val;
2207 size_t offset = 0, np;
2211 val = talloc(mem_ctx, struct ctdb_connection_list);
2216 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
2222 if (val->num == 0) {
2227 val->conn = talloc_array(val, struct ctdb_connection, val->num);
2228 if (val->conn == NULL) {
2233 for (i=0; i<val->num; i++) {
2234 ret = ctdb_connection_pull_elems(buf+offset, buflen-offset,
2235 val, &val->conn[i], &np);
2252 size_t ctdb_tunable_len(struct ctdb_tunable *in)
2254 return ctdb_uint32_len(&in->value) +
2255 ctdb_stringn_len(&in->name);
2258 void ctdb_tunable_push(struct ctdb_tunable *in, uint8_t *buf, size_t *npush)
2260 size_t offset = 0, np;
2262 ctdb_uint32_push(&in->value, buf+offset, &np);
2265 ctdb_stringn_push(&in->name, buf+offset, &np);
2271 int ctdb_tunable_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
2272 struct ctdb_tunable **out, size_t *npull)
2274 struct ctdb_tunable *val;
2275 size_t offset = 0, np;
2278 val = talloc(mem_ctx, struct ctdb_tunable);
2283 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->value, &np);
2289 ret = ctdb_stringn_pull(buf+offset, buflen-offset, mem_ctx,
2305 size_t ctdb_node_flag_change_len(struct ctdb_node_flag_change *in)
2307 return ctdb_uint32_len(&in->pnn) +
2308 ctdb_uint32_len(&in->new_flags) +
2309 ctdb_uint32_len(&in->old_flags);
2312 void ctdb_node_flag_change_push(struct ctdb_node_flag_change *in,
2313 uint8_t *buf, size_t *npush)
2315 size_t offset = 0, np;
2317 ctdb_uint32_push(&in->pnn, buf+offset, &np);
2320 ctdb_uint32_push(&in->new_flags, buf+offset, &np);
2323 ctdb_uint32_push(&in->old_flags, buf+offset, &np);
2329 int ctdb_node_flag_change_pull(uint8_t *buf, size_t buflen,
2330 TALLOC_CTX *mem_ctx,
2331 struct ctdb_node_flag_change **out,
2334 struct ctdb_node_flag_change *val;
2335 size_t offset = 0, np;
2338 val = talloc(mem_ctx, struct ctdb_node_flag_change);
2343 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
2349 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->new_flags,
2356 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->old_flags,
2372 size_t ctdb_var_list_len(struct ctdb_var_list *in)
2377 for (i=0; i<in->count; i++) {
2378 u32 += ctdb_string_len(&in->var[i]);
2381 return ctdb_uint32_len(&u32) + u32;
2384 void ctdb_var_list_push(struct ctdb_var_list *in, uint8_t *buf, size_t *npush)
2386 size_t offset = 0, np;
2391 /* The length only corresponds to the payload size */
2392 u32 = ctdb_var_list_len(in);
2393 u32 -= ctdb_uint32_len(&u32);
2395 ctdb_uint32_push(&u32, buf+offset, &np);
2398 /* The variables are separated by ':' and the complete string is null
2401 for (i=0; i<in->count; i++) {
2402 ctdb_string_push(&in->var[i], buf+offset, &np);
2405 if (i < in->count - 1) {
2406 /* Replace '\0' with ':' */
2407 ctdb_uint8_push(&sep, buf+offset-1, &np);
2414 int ctdb_var_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
2415 struct ctdb_var_list **out, size_t *npull)
2417 struct ctdb_var_list *val;
2418 const char *str, **list;
2419 char *s, *tok, *ptr = NULL;
2420 size_t offset = 0, np;
2424 val = talloc_zero(mem_ctx, struct ctdb_var_list);
2429 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
2435 if (buflen-offset < u32) {
2440 ret = ctdb_string_pull(buf+offset, u32, val, &str, &np);
2446 s = discard_const(str);
2447 while ((tok = strtok_r(s, ":", &ptr)) != NULL) {
2448 list = talloc_realloc(val, val->var, const char *,
2457 s = talloc_strdup(val, tok);
2463 val->var[val->count] = s;
2468 talloc_free(discard_const(str));
2478 size_t ctdb_tunable_list_len(struct ctdb_tunable_list *in)
2480 return ctdb_uint32_len(&in->max_redirect_count) +
2481 ctdb_uint32_len(&in->seqnum_interval) +
2482 ctdb_uint32_len(&in->control_timeout) +
2483 ctdb_uint32_len(&in->traverse_timeout) +
2484 ctdb_uint32_len(&in->keepalive_interval) +
2485 ctdb_uint32_len(&in->keepalive_limit) +
2486 ctdb_uint32_len(&in->recover_timeout) +
2487 ctdb_uint32_len(&in->recover_interval) +
2488 ctdb_uint32_len(&in->election_timeout) +
2489 ctdb_uint32_len(&in->takeover_timeout) +
2490 ctdb_uint32_len(&in->monitor_interval) +
2491 ctdb_uint32_len(&in->tickle_update_interval) +
2492 ctdb_uint32_len(&in->script_timeout) +
2493 ctdb_uint32_len(&in->monitor_timeout_count) +
2494 ctdb_uint32_len(&in->script_unhealthy_on_timeout) +
2495 ctdb_uint32_len(&in->recovery_grace_period) +
2496 ctdb_uint32_len(&in->recovery_ban_period) +
2497 ctdb_uint32_len(&in->database_hash_size) +
2498 ctdb_uint32_len(&in->database_max_dead) +
2499 ctdb_uint32_len(&in->rerecovery_timeout) +
2500 ctdb_uint32_len(&in->enable_bans) +
2501 ctdb_uint32_len(&in->deterministic_public_ips) +
2502 ctdb_uint32_len(&in->reclock_ping_period) +
2503 ctdb_uint32_len(&in->no_ip_failback) +
2504 ctdb_uint32_len(&in->disable_ip_failover) +
2505 ctdb_uint32_len(&in->verbose_memory_names) +
2506 ctdb_uint32_len(&in->recd_ping_timeout) +
2507 ctdb_uint32_len(&in->recd_ping_failcount) +
2508 ctdb_uint32_len(&in->log_latency_ms) +
2509 ctdb_uint32_len(&in->reclock_latency_ms) +
2510 ctdb_uint32_len(&in->recovery_drop_all_ips) +
2511 ctdb_uint32_len(&in->verify_recovery_lock) +
2512 ctdb_uint32_len(&in->vacuum_interval) +
2513 ctdb_uint32_len(&in->vacuum_max_run_time) +
2514 ctdb_uint32_len(&in->repack_limit) +
2515 ctdb_uint32_len(&in->vacuum_limit) +
2516 ctdb_uint32_len(&in->max_queue_depth_drop_msg) +
2517 ctdb_uint32_len(&in->allow_unhealthy_db_read) +
2518 ctdb_uint32_len(&in->stat_history_interval) +
2519 ctdb_uint32_len(&in->deferred_attach_timeout) +
2520 ctdb_uint32_len(&in->vacuum_fast_path_count) +
2521 ctdb_uint32_len(&in->lcp2_public_ip_assignment) +
2522 ctdb_uint32_len(&in->allow_client_db_attach) +
2523 ctdb_uint32_len(&in->recover_pdb_by_seqnum) +
2524 ctdb_uint32_len(&in->deferred_rebalance_on_node_add) +
2525 ctdb_uint32_len(&in->fetch_collapse) +
2526 ctdb_uint32_len(&in->hopcount_make_sticky) +
2527 ctdb_uint32_len(&in->sticky_duration) +
2528 ctdb_uint32_len(&in->sticky_pindown) +
2529 ctdb_uint32_len(&in->no_ip_takeover) +
2530 ctdb_uint32_len(&in->db_record_count_warn) +
2531 ctdb_uint32_len(&in->db_record_size_warn) +
2532 ctdb_uint32_len(&in->db_size_warn) +
2533 ctdb_uint32_len(&in->pulldb_preallocation_size) +
2534 ctdb_uint32_len(&in->no_ip_host_on_all_disabled) +
2535 ctdb_uint32_len(&in->samba3_hack) +
2536 ctdb_uint32_len(&in->mutex_enabled) +
2537 ctdb_uint32_len(&in->lock_processes_per_db) +
2538 ctdb_uint32_len(&in->rec_buffer_size_limit) +
2539 ctdb_uint32_len(&in->queue_buffer_size) +
2540 ctdb_uint32_len(&in->ip_alloc_algorithm) +
2541 ctdb_uint32_len(&in->allow_mixed_versions);
2544 void ctdb_tunable_list_push(struct ctdb_tunable_list *in, uint8_t *buf,
2547 size_t offset = 0, np;
2549 ctdb_uint32_push(&in->max_redirect_count, buf+offset, &np);
2552 ctdb_uint32_push(&in->seqnum_interval, buf+offset, &np);
2555 ctdb_uint32_push(&in->control_timeout, buf+offset, &np);
2558 ctdb_uint32_push(&in->traverse_timeout, buf+offset, &np);
2561 ctdb_uint32_push(&in->keepalive_interval, buf+offset, &np);
2564 ctdb_uint32_push(&in->keepalive_limit, buf+offset, &np);
2567 ctdb_uint32_push(&in->recover_timeout, buf+offset, &np);
2570 ctdb_uint32_push(&in->recover_interval, buf+offset, &np);
2573 ctdb_uint32_push(&in->election_timeout, buf+offset, &np);
2576 ctdb_uint32_push(&in->takeover_timeout, buf+offset, &np);
2579 ctdb_uint32_push(&in->monitor_interval, buf+offset, &np);
2582 ctdb_uint32_push(&in->tickle_update_interval, buf+offset, &np);
2585 ctdb_uint32_push(&in->script_timeout, buf+offset, &np);
2588 ctdb_uint32_push(&in->monitor_timeout_count, buf+offset, &np);
2591 ctdb_uint32_push(&in->script_unhealthy_on_timeout, buf+offset, &np);
2594 ctdb_uint32_push(&in->recovery_grace_period, buf+offset, &np);
2597 ctdb_uint32_push(&in->recovery_ban_period, buf+offset, &np);
2600 ctdb_uint32_push(&in->database_hash_size, buf+offset, &np);
2603 ctdb_uint32_push(&in->database_max_dead, buf+offset, &np);
2606 ctdb_uint32_push(&in->rerecovery_timeout, buf+offset, &np);
2609 ctdb_uint32_push(&in->enable_bans, buf+offset, &np);
2612 ctdb_uint32_push(&in->deterministic_public_ips, buf+offset, &np);
2615 ctdb_uint32_push(&in->reclock_ping_period, buf+offset, &np);
2618 ctdb_uint32_push(&in->no_ip_failback, buf+offset, &np);
2621 ctdb_uint32_push(&in->disable_ip_failover, buf+offset, &np);
2624 ctdb_uint32_push(&in->verbose_memory_names, buf+offset, &np);
2627 ctdb_uint32_push(&in->recd_ping_timeout, buf+offset, &np);
2630 ctdb_uint32_push(&in->recd_ping_failcount, buf+offset, &np);
2633 ctdb_uint32_push(&in->log_latency_ms, buf+offset, &np);
2636 ctdb_uint32_push(&in->reclock_latency_ms, buf+offset, &np);
2639 ctdb_uint32_push(&in->recovery_drop_all_ips, buf+offset, &np);
2642 ctdb_uint32_push(&in->verify_recovery_lock, buf+offset, &np);
2645 ctdb_uint32_push(&in->vacuum_interval, buf+offset, &np);
2648 ctdb_uint32_push(&in->vacuum_max_run_time, buf+offset, &np);
2651 ctdb_uint32_push(&in->repack_limit, buf+offset, &np);
2654 ctdb_uint32_push(&in->vacuum_limit, buf+offset, &np);
2657 ctdb_uint32_push(&in->max_queue_depth_drop_msg, buf+offset, &np);
2660 ctdb_uint32_push(&in->allow_unhealthy_db_read, buf+offset, &np);
2663 ctdb_uint32_push(&in->stat_history_interval, buf+offset, &np);
2666 ctdb_uint32_push(&in->deferred_attach_timeout, buf+offset, &np);
2669 ctdb_uint32_push(&in->vacuum_fast_path_count, buf+offset, &np);
2672 ctdb_uint32_push(&in->lcp2_public_ip_assignment, buf+offset, &np);
2675 ctdb_uint32_push(&in->allow_client_db_attach, buf+offset, &np);
2678 ctdb_uint32_push(&in->recover_pdb_by_seqnum, buf+offset, &np);
2681 ctdb_uint32_push(&in->deferred_rebalance_on_node_add, buf+offset, &np);
2684 ctdb_uint32_push(&in->fetch_collapse, buf+offset, &np);
2687 ctdb_uint32_push(&in->hopcount_make_sticky, buf+offset, &np);
2690 ctdb_uint32_push(&in->sticky_duration, buf+offset, &np);
2693 ctdb_uint32_push(&in->sticky_pindown, buf+offset, &np);
2696 ctdb_uint32_push(&in->no_ip_takeover, buf+offset, &np);
2699 ctdb_uint32_push(&in->db_record_count_warn, buf+offset, &np);
2702 ctdb_uint32_push(&in->db_record_size_warn, buf+offset, &np);
2705 ctdb_uint32_push(&in->db_size_warn, buf+offset, &np);
2708 ctdb_uint32_push(&in->pulldb_preallocation_size, buf+offset, &np);
2711 ctdb_uint32_push(&in->no_ip_host_on_all_disabled, buf+offset, &np);
2714 ctdb_uint32_push(&in->samba3_hack, buf+offset, &np);
2717 ctdb_uint32_push(&in->mutex_enabled, buf+offset, &np);
2720 ctdb_uint32_push(&in->lock_processes_per_db, buf+offset, &np);
2723 ctdb_uint32_push(&in->rec_buffer_size_limit, buf+offset, &np);
2726 ctdb_uint32_push(&in->queue_buffer_size, buf+offset, &np);
2729 ctdb_uint32_push(&in->ip_alloc_algorithm, buf+offset, &np);
2732 ctdb_uint32_push(&in->allow_mixed_versions, buf+offset, &np);
2738 static int ctdb_tunable_list_pull_elems(uint8_t *buf, size_t buflen,
2739 TALLOC_CTX *mem_ctx,
2740 struct ctdb_tunable_list *out,
2743 size_t offset = 0, np;
2746 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2747 &out->max_redirect_count, &np);
2753 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2754 &out->seqnum_interval, &np);
2760 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2761 &out->control_timeout, &np);
2767 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2768 &out->traverse_timeout, &np);
2774 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2775 &out->keepalive_interval, &np);
2781 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2782 &out->keepalive_limit, &np);
2788 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2789 &out->recover_timeout, &np);
2795 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2796 &out->recover_interval, &np);
2802 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2803 &out->election_timeout, &np);
2809 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2810 &out->takeover_timeout, &np);
2816 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2817 &out->monitor_interval, &np);
2823 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2824 &out->tickle_update_interval, &np);
2830 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2831 &out->script_timeout, &np);
2837 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2838 &out->monitor_timeout_count, &np);
2844 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2845 &out->script_unhealthy_on_timeout, &np);
2851 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2852 &out->recovery_grace_period, &np);
2858 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2859 &out->recovery_ban_period, &np);
2865 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2866 &out->database_hash_size, &np);
2872 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2873 &out->database_max_dead, &np);
2879 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2880 &out->rerecovery_timeout, &np);
2886 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2887 &out->enable_bans, &np);
2893 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2894 &out->deterministic_public_ips, &np);
2900 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2901 &out->reclock_ping_period, &np);
2907 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2908 &out->no_ip_failback, &np);
2914 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2915 &out->disable_ip_failover, &np);
2921 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2922 &out->verbose_memory_names, &np);
2928 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2929 &out->recd_ping_timeout, &np);
2935 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2936 &out->recd_ping_failcount, &np);
2942 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2943 &out->log_latency_ms, &np);
2949 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2950 &out->reclock_latency_ms, &np);
2956 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2957 &out->recovery_drop_all_ips, &np);
2963 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2964 &out->verify_recovery_lock, &np);
2970 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2971 &out->vacuum_interval, &np);
2977 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2978 &out->vacuum_max_run_time, &np);
2984 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2985 &out->repack_limit, &np);
2991 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2992 &out->vacuum_limit, &np);
2998 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2999 &out->max_queue_depth_drop_msg, &np);
3005 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3006 &out->allow_unhealthy_db_read, &np);
3012 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3013 &out->stat_history_interval, &np);
3019 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3020 &out->deferred_attach_timeout, &np);
3026 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3027 &out->vacuum_fast_path_count, &np);
3033 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3034 &out->lcp2_public_ip_assignment, &np);
3040 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3041 &out->allow_client_db_attach, &np);
3047 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3048 &out->recover_pdb_by_seqnum, &np);
3054 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3055 &out->deferred_rebalance_on_node_add, &np);
3061 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3062 &out->fetch_collapse, &np);
3068 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3069 &out->hopcount_make_sticky, &np);
3075 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3076 &out->sticky_duration, &np);
3082 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3083 &out->sticky_pindown, &np);
3089 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3090 &out->no_ip_takeover, &np);
3096 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3097 &out->db_record_count_warn, &np);
3103 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3104 &out->db_record_size_warn, &np);
3110 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3111 &out->db_size_warn, &np);
3117 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3118 &out->pulldb_preallocation_size, &np);
3124 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3125 &out->no_ip_host_on_all_disabled, &np);
3131 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3132 &out->samba3_hack, &np);
3138 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3139 &out->mutex_enabled, &np);
3145 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3146 &out->lock_processes_per_db, &np);
3152 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3153 &out->rec_buffer_size_limit, &np);
3159 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3160 &out->queue_buffer_size, &np);
3166 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3167 &out->ip_alloc_algorithm, &np);
3173 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3174 &out->allow_mixed_versions, &np);
3184 int ctdb_tunable_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
3185 struct ctdb_tunable_list **out, size_t *npull)
3187 struct ctdb_tunable_list *val;
3191 val = talloc(mem_ctx, struct ctdb_tunable_list);
3196 ret = ctdb_tunable_list_pull_elems(buf, buflen, val, val, &np);
3207 size_t ctdb_tickle_list_len(struct ctdb_tickle_list *in)
3211 len = ctdb_sock_addr_len(&in->addr) +
3212 ctdb_uint32_len(&in->num);
3214 len += in->num * ctdb_connection_len(&in->conn[0]);
3220 void ctdb_tickle_list_push(struct ctdb_tickle_list *in, uint8_t *buf,
3223 size_t offset = 0, np;
3226 ctdb_sock_addr_push(&in->addr, buf+offset, &np);
3229 ctdb_uint32_push(&in->num, buf+offset, &np);
3232 for (i=0; i<in->num; i++) {
3233 ctdb_connection_push(&in->conn[i], buf+offset, &np);
3240 int ctdb_tickle_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
3241 struct ctdb_tickle_list **out, size_t *npull)
3243 struct ctdb_tickle_list *val;
3244 size_t offset = 0, np;
3248 val = talloc(mem_ctx, struct ctdb_tickle_list);
3253 ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset, val,
3260 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
3266 if (val->num == 0) {
3271 val->conn = talloc_array(val, struct ctdb_connection, val->num);
3272 if (val->conn == NULL) {
3277 for (i=0; i<val->num; i++) {
3278 ret = ctdb_connection_pull_elems(buf+offset, buflen-offset,
3279 val, &val->conn[i], &np);
3296 size_t ctdb_addr_info_len(struct ctdb_addr_info *in)
3298 return ctdb_sock_addr_len(&in->addr) +
3299 ctdb_uint32_len(&in->mask) +
3300 ctdb_stringn_len(&in->iface);
3303 void ctdb_addr_info_push(struct ctdb_addr_info *in, uint8_t *buf,
3306 size_t offset = 0, np;
3308 ctdb_sock_addr_push(&in->addr, buf+offset, &np);
3311 ctdb_uint32_push(&in->mask, buf+offset, &np);
3314 ctdb_stringn_push(&in->iface, buf+offset, &np);
3320 int ctdb_addr_info_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
3321 struct ctdb_addr_info **out, size_t *npull)
3323 struct ctdb_addr_info *val;
3324 size_t offset = 0, np;
3327 val = talloc(mem_ctx, struct ctdb_addr_info);
3332 ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset, val,
3339 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->mask, &np);
3345 ret = ctdb_stringn_pull(buf+offset, buflen-offset, val, &val->iface,
3361 size_t ctdb_transdb_len(struct ctdb_transdb *in)
3363 return ctdb_uint32_len(&in->db_id) +
3364 ctdb_uint32_len(&in->tid);
3367 void ctdb_transdb_push(struct ctdb_transdb *in, uint8_t *buf, size_t *npush)
3369 size_t offset = 0, np;
3371 ctdb_uint32_push(&in->db_id, buf+offset, &np);
3374 ctdb_uint32_push(&in->tid, buf+offset, &np);
3380 int ctdb_transdb_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
3381 struct ctdb_transdb **out, size_t *npull)
3383 struct ctdb_transdb *val;
3384 size_t offset = 0, np;
3387 val = talloc(mem_ctx, struct ctdb_transdb);
3392 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
3398 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->tid, &np);
3413 size_t ctdb_uptime_len(struct ctdb_uptime *in)
3415 return ctdb_timeval_len(&in->current_time) +
3416 ctdb_timeval_len(&in->ctdbd_start_time) +
3417 ctdb_timeval_len(&in->last_recovery_started) +
3418 ctdb_timeval_len(&in->last_recovery_finished);
3421 void ctdb_uptime_push(struct ctdb_uptime *in, uint8_t *buf, size_t *npush)
3423 size_t offset = 0, np;
3425 ctdb_timeval_push(&in->current_time, buf+offset, &np);
3428 ctdb_timeval_push(&in->ctdbd_start_time, buf+offset, &np);
3431 ctdb_timeval_push(&in->last_recovery_started, buf+offset, &np);
3434 ctdb_timeval_push(&in->last_recovery_finished, buf+offset, &np);
3440 int ctdb_uptime_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
3441 struct ctdb_uptime **out, size_t *npull)
3443 struct ctdb_uptime *val;
3444 size_t offset = 0, np;
3447 val = talloc(mem_ctx, struct ctdb_uptime);
3452 ret = ctdb_timeval_pull(buf+offset, buflen-offset, &val->current_time,
3459 ret = ctdb_timeval_pull(buf+offset, buflen-offset,
3460 &val->ctdbd_start_time, &np);
3466 ret = ctdb_timeval_pull(buf+offset, buflen-offset,
3467 &val->last_recovery_started, &np);
3473 ret = ctdb_timeval_pull(buf+offset, buflen-offset,
3474 &val->last_recovery_finished, &np);
3489 size_t ctdb_public_ip_len(struct ctdb_public_ip *in)
3491 return ctdb_uint32_len(&in->pnn) +
3492 ctdb_sock_addr_len(&in->addr);
3495 void ctdb_public_ip_push(struct ctdb_public_ip *in, uint8_t *buf,
3498 size_t offset = 0, np;
3500 ctdb_uint32_push(&in->pnn, buf+offset, &np);
3503 ctdb_sock_addr_push(&in->addr, buf+offset, &np);
3509 static int ctdb_public_ip_pull_elems(uint8_t *buf, size_t buflen,
3510 TALLOC_CTX *mem_ctx,
3511 struct ctdb_public_ip *out, size_t *npull)
3513 size_t offset = 0, np;
3516 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->pnn, &np);
3522 ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset, mem_ctx,
3533 int ctdb_public_ip_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
3534 struct ctdb_public_ip **out, size_t *npull)
3536 struct ctdb_public_ip *val;
3540 val = talloc(mem_ctx, struct ctdb_public_ip);
3545 ret = ctdb_public_ip_pull_elems(buf, buflen, val, val, &np);
3556 size_t ctdb_public_ip_list_len(struct ctdb_public_ip_list *in)
3560 len = ctdb_uint32_len(&in->num);
3562 len += in->num * ctdb_public_ip_len(&in->ip[0]);
3568 void ctdb_public_ip_list_push(struct ctdb_public_ip_list *in, uint8_t *buf,
3571 size_t offset = 0, np;
3574 ctdb_uint32_push(&in->num, buf+offset, &np);
3577 for (i=0; i<in->num; i++) {
3578 ctdb_public_ip_push(&in->ip[i], buf+offset, &np);
3585 int ctdb_public_ip_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
3586 struct ctdb_public_ip_list **out, size_t *npull)
3588 struct ctdb_public_ip_list *val;
3589 size_t offset = 0, np;
3593 val = talloc(mem_ctx, struct ctdb_public_ip_list);
3598 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
3604 if (val->num == 0) {
3609 val->ip = talloc_array(val, struct ctdb_public_ip, val->num);
3610 if (val->ip == NULL) {
3615 for (i=0; i<val->num; i++) {
3616 ret = ctdb_public_ip_pull_elems(buf+offset, buflen-offset,
3617 val->ip, &val->ip[i], &np);
3634 size_t ctdb_node_and_flags_len(struct ctdb_node_and_flags *in)
3636 return ctdb_uint32_len(&in->pnn) +
3637 ctdb_uint32_len(&in->flags) +
3638 ctdb_sock_addr_len(&in->addr);
3641 void ctdb_node_and_flags_push(struct ctdb_node_and_flags *in, uint8_t *buf,
3644 size_t offset = 0, np;
3646 ctdb_uint32_push(&in->pnn, buf+offset, &np);
3649 ctdb_uint32_push(&in->flags, buf+offset, &np);
3652 ctdb_sock_addr_push(&in->addr, buf+offset, &np);
3658 static int ctdb_node_and_flags_pull_elems(uint8_t *buf, size_t buflen,
3659 TALLOC_CTX *mem_ctx,
3660 struct ctdb_node_and_flags *out,
3663 size_t offset = 0, np;
3666 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->pnn, &np);
3672 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->flags, &np);
3678 ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset, mem_ctx,
3689 int ctdb_node_and_flags_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
3690 struct ctdb_node_and_flags **out, size_t *npull)
3692 struct ctdb_node_and_flags *val;
3696 val = talloc(mem_ctx, struct ctdb_node_and_flags);
3701 ret = ctdb_node_and_flags_pull_elems(buf, buflen, val, val, &np);
3712 size_t ctdb_node_map_len(struct ctdb_node_map *in)
3716 len = ctdb_uint32_len(&in->num);
3718 len += in->num * ctdb_node_and_flags_len(&in->node[0]);
3724 void ctdb_node_map_push(struct ctdb_node_map *in, uint8_t *buf, size_t *npush)
3726 size_t offset = 0, np;
3729 ctdb_uint32_push(&in->num, buf+offset, &np);
3732 for (i=0; i<in->num; i++) {
3733 ctdb_node_and_flags_push(&in->node[i], buf+offset, &np);
3740 int ctdb_node_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
3741 struct ctdb_node_map **out, size_t *npull)
3743 struct ctdb_node_map *val;
3744 size_t offset = 0, np;
3748 val = talloc(mem_ctx, struct ctdb_node_map);
3753 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
3759 if (val->num == 0) {
3764 val->node = talloc_array(val, struct ctdb_node_and_flags, val->num);
3765 if (val->node == NULL) {
3770 for (i=0; i<val->num; i++) {
3771 ret = ctdb_node_and_flags_pull_elems(buf+offset,
3773 val->node, &val->node[i],
3791 size_t ctdb_script_len(struct ctdb_script *in)
3793 return ctdb_chararray_len(in->name, MAX_SCRIPT_NAME+1) +
3794 ctdb_timeval_len(&in->start) +
3795 ctdb_timeval_len(&in->finished) +
3796 ctdb_int32_len(&in->status) +
3797 ctdb_chararray_len(in->output, MAX_SCRIPT_OUTPUT+1) +
3798 ctdb_padding_len(4);
3801 void ctdb_script_push(struct ctdb_script *in, uint8_t *buf, size_t *npush)
3803 size_t offset = 0, np;
3805 ctdb_chararray_push(in->name, MAX_SCRIPT_NAME+1, buf+offset, &np);
3808 ctdb_timeval_push(&in->start, buf+offset, &np);
3811 ctdb_timeval_push(&in->finished, buf+offset, &np);
3814 ctdb_int32_push(&in->status, buf+offset, &np);
3817 ctdb_chararray_push(in->output, MAX_SCRIPT_OUTPUT+1, buf+offset, &np);
3820 ctdb_padding_push(4, buf+offset, &np);
3826 static int ctdb_script_pull_elems(uint8_t *buf, size_t buflen,
3827 TALLOC_CTX *mem_ctx,
3828 struct ctdb_script *out, size_t *npull)
3830 size_t offset = 0, np;
3833 ret = ctdb_chararray_pull(buf+offset, buflen-offset,
3834 out->name, MAX_SCRIPT_NAME+1, &np);
3840 ret = ctdb_timeval_pull(buf+offset, buflen-offset, &out->start, &np);
3846 ret = ctdb_timeval_pull(buf+offset, buflen-offset, &out->finished,
3853 ret = ctdb_int32_pull(buf+offset, buflen-offset, &out->status, &np);
3859 ret = ctdb_chararray_pull(buf+offset, buflen-offset,
3860 out->output, MAX_SCRIPT_OUTPUT+1, &np);
3866 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
3876 int ctdb_script_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
3877 struct ctdb_script **out, size_t *npull)
3879 struct ctdb_script *val;
3883 val = talloc(mem_ctx, struct ctdb_script);
3888 ret = ctdb_script_pull_elems(buf, buflen, val, val, &np);
3899 size_t ctdb_script_list_len(struct ctdb_script_list *in)
3907 len = ctdb_uint32_len(&in->num_scripts) + ctdb_padding_len(4);
3908 if (in->num_scripts > 0) {
3909 len += in->num_scripts * ctdb_script_len(&in->script[0]);
3915 void ctdb_script_list_push(struct ctdb_script_list *in, uint8_t *buf,
3918 size_t offset = 0, np;
3926 ctdb_uint32_push(&in->num_scripts, buf+offset, &np);
3929 ctdb_padding_push(4, buf+offset, &np);
3932 for (i=0; i<in->num_scripts; i++) {
3933 ctdb_script_push(&in->script[i], buf+offset, &np);
3940 int ctdb_script_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
3941 struct ctdb_script_list **out, size_t *npull)
3943 struct ctdb_script_list *val;
3944 size_t offset = 0, np;
3948 /* If event scripts have never been run, the result will be NULL */
3954 val = talloc(mem_ctx, struct ctdb_script_list);
3959 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num_scripts,
3966 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
3972 if (val->num_scripts == 0) {
3977 val->script = talloc_array(val, struct ctdb_script, val->num_scripts);
3978 if (val->script == NULL) {
3983 for (i=0; i<val->num_scripts; i++) {
3984 ret = ctdb_script_pull_elems(buf+offset, buflen-offset,
3985 val, &val->script[i], &np);
4002 size_t ctdb_ban_state_len(struct ctdb_ban_state *in)
4004 return ctdb_uint32_len(&in->pnn) +
4005 ctdb_uint32_len(&in->time);
4008 void ctdb_ban_state_push(struct ctdb_ban_state *in, uint8_t *buf,
4011 size_t offset = 0, np;
4013 ctdb_uint32_push(&in->pnn, buf+offset, &np);
4016 ctdb_uint32_push(&in->time, buf+offset, &np);
4022 int ctdb_ban_state_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
4023 struct ctdb_ban_state **out, size_t *npull)
4025 struct ctdb_ban_state *val;
4026 size_t offset = 0, np;
4029 val = talloc(mem_ctx, struct ctdb_ban_state);
4034 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
4040 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->time, &np);
4055 size_t ctdb_notify_data_len(struct ctdb_notify_data *in)
4057 return ctdb_uint64_len(&in->srvid) +
4058 ctdb_tdb_datan_len(&in->data);
4061 void ctdb_notify_data_push(struct ctdb_notify_data *in, uint8_t *buf,
4064 size_t offset = 0, np;
4066 ctdb_uint64_push(&in->srvid, buf+offset, &np);
4069 ctdb_tdb_datan_push(&in->data, buf+offset, &np);
4075 int ctdb_notify_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
4076 struct ctdb_notify_data **out, size_t *npull)
4078 struct ctdb_notify_data *val;
4079 size_t offset = 0, np;
4082 val = talloc(mem_ctx, struct ctdb_notify_data);
4087 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
4093 ret = ctdb_tdb_datan_pull(buf+offset, buflen-offset, val, &val->data,
4109 size_t ctdb_iface_len(struct ctdb_iface *in)
4111 return ctdb_chararray_len(in->name, CTDB_IFACE_SIZE+2) +
4112 ctdb_uint16_len(&in->link_state) +
4113 ctdb_uint32_len(&in->references);
4116 void ctdb_iface_push(struct ctdb_iface *in, uint8_t *buf, size_t *npush)
4118 size_t offset = 0, np;
4120 ctdb_chararray_push(in->name, CTDB_IFACE_SIZE+2, buf+offset, &np);
4123 ctdb_uint16_push(&in->link_state, buf+offset, &np);
4126 ctdb_uint32_push(&in->references, buf+offset, &np);
4132 static int ctdb_iface_pull_elems(uint8_t *buf, size_t buflen,
4133 TALLOC_CTX *mem_ctx,
4134 struct ctdb_iface *out, size_t *npull)
4136 size_t offset = 0, np;
4139 ret = ctdb_chararray_pull(buf+offset, buflen-offset,
4140 out->name, CTDB_IFACE_SIZE+2, &np);
4146 ret = ctdb_uint16_pull(buf+offset, buflen-offset, &out->link_state,
4153 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->references,
4164 int ctdb_iface_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
4165 struct ctdb_iface **out, size_t *npull)
4167 struct ctdb_iface *val;
4171 val = talloc(mem_ctx, struct ctdb_iface);
4176 ret = ctdb_iface_pull_elems(buf, buflen, val, val, &np);
4187 size_t ctdb_iface_list_len(struct ctdb_iface_list *in)
4191 len = ctdb_uint32_len(&in->num);
4193 len += in->num * ctdb_iface_len(&in->iface[0]);
4199 void ctdb_iface_list_push(struct ctdb_iface_list *in, uint8_t *buf,
4202 size_t offset = 0, np;
4205 ctdb_uint32_push(&in->num, buf+offset, &np);
4208 for (i=0; i<in->num; i++) {
4209 ctdb_iface_push(&in->iface[i], buf+offset, &np);
4216 int ctdb_iface_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
4217 struct ctdb_iface_list **out, size_t *npull)
4219 struct ctdb_iface_list *val;
4220 size_t offset = 0, np;
4224 val = talloc(mem_ctx, struct ctdb_iface_list);
4229 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
4235 if (val->num == 0) {
4240 val->iface = talloc_array(val, struct ctdb_iface, val->num);
4241 if (val->iface == NULL) {
4246 for (i=0; i<val->num; i++) {
4247 ret = ctdb_iface_pull_elems(buf+offset, buflen-offset,
4248 val, &val->iface[i], &np);
4265 size_t ctdb_public_ip_info_len(struct ctdb_public_ip_info *in)
4267 return ctdb_public_ip_len(&in->ip) +
4268 ctdb_uint32_len(&in->active_idx) +
4269 ctdb_iface_list_len(in->ifaces);
4272 void ctdb_public_ip_info_push(struct ctdb_public_ip_info *in, uint8_t *buf,
4275 size_t offset = 0, np;
4277 ctdb_public_ip_push(&in->ip, buf+offset, &np);
4280 ctdb_uint32_push(&in->active_idx, buf+offset, &np);
4283 ctdb_iface_list_push(in->ifaces, buf+offset, &np);
4289 int ctdb_public_ip_info_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
4290 struct ctdb_public_ip_info **out, size_t *npull)
4292 struct ctdb_public_ip_info *val;
4293 size_t offset = 0, np;
4296 val = talloc(mem_ctx, struct ctdb_public_ip_info);
4301 ret = ctdb_public_ip_pull_elems(buf+offset, buflen-offset, val,
4308 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->active_idx,
4315 ret = ctdb_iface_list_pull(buf+offset, buflen-offset, val,
4331 size_t ctdb_key_data_len(struct ctdb_key_data *in)
4333 return ctdb_uint32_len(&in->db_id) +
4334 ctdb_padding_len(4) +
4335 ctdb_ltdb_header_len(&in->header) +
4336 ctdb_tdb_datan_len(&in->key);
4339 void ctdb_key_data_push(struct ctdb_key_data *in, uint8_t *buf, size_t *npush)
4341 size_t offset = 0, np;
4343 ctdb_uint32_push(&in->db_id, buf+offset, &np);
4346 ctdb_padding_push(4, buf+offset, &np);
4349 ctdb_ltdb_header_push(&in->header, buf+offset, &np);
4352 ctdb_tdb_datan_push(&in->key, buf+offset, &np);
4358 int ctdb_key_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
4359 struct ctdb_key_data **out, size_t *npull)
4361 struct ctdb_key_data *val;
4362 size_t offset = 0, np;
4365 val = talloc(mem_ctx, struct ctdb_key_data);
4370 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
4376 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
4382 ret = ctdb_ltdb_header_pull(buf+offset, buflen-offset, &val->header,
4389 ret = ctdb_tdb_datan_pull(buf+offset, buflen-offset, val, &val->key,
4405 /* In the tdb_data structure marshalling, we are only interested in dsize.
4406 * The dptr value is ignored. The actual tdb_data blob is stored separately.
4408 * This is only required for ctdb_db_statistics and will be dropped in future.
4411 static size_t tdb_data_struct_len(TDB_DATA *data)
4413 return sizeof(void *) + sizeof(size_t);
4416 static void tdb_data_struct_push(TDB_DATA *data, uint8_t *buf, size_t *npush)
4420 memcpy(buf+offset, &data->dptr, sizeof(void *));
4421 offset += sizeof(void *);
4423 memcpy(buf+offset, &data->dsize, sizeof(size_t));
4424 offset += sizeof(size_t);
4429 static int tdb_data_struct_pull(uint8_t *buf, size_t buflen, TDB_DATA *data,
4435 if (buflen-offset < sizeof(void *)) {
4439 memcpy(&ptr, buf+offset, sizeof(void *));
4440 offset += sizeof(void *);
4443 if (buflen-offset < sizeof(size_t)) {
4447 memcpy(&data->dsize, buf+offset, sizeof(size_t));
4448 offset += sizeof(size_t);
4454 size_t ctdb_db_statistics_len(struct ctdb_db_statistics *in)
4456 TDB_DATA data = { 0 };
4461 len = ctdb_uint32_len(&in->locks.num_calls) +
4462 ctdb_uint32_len(&in->locks.num_current) +
4463 ctdb_uint32_len(&in->locks.num_pending) +
4464 ctdb_uint32_len(&in->locks.num_failed) +
4465 ctdb_latency_counter_len(&in->locks.latency) +
4467 ctdb_uint32_len(&in->locks.buckets[0]) +
4468 ctdb_latency_counter_len(&in->vacuum.latency) +
4469 ctdb_uint32_len(&in->db_ro_delegations) +
4470 ctdb_uint32_len(&in->db_ro_revokes) +
4472 ctdb_uint32_len(&in->hop_count_bucket[0]) +
4473 ctdb_uint32_len(&in->num_hot_keys) +
4474 ctdb_padding_len(4) +
4476 (ctdb_uint32_len(&u32) + ctdb_padding_len(4) +
4477 tdb_data_struct_len(&data));
4479 for (i=0; i<MAX_HOT_KEYS; i++) {
4480 len += ctdb_tdb_data_len(&in->hot_keys[i].key);
4486 void ctdb_db_statistics_push(struct ctdb_db_statistics *in, uint8_t *buf,
4489 size_t offset = 0, np;
4490 uint32_t num_hot_keys;
4493 ctdb_uint32_push(&in->locks.num_calls, buf+offset, &np);
4496 ctdb_uint32_push(&in->locks.num_current, buf+offset, &np);
4499 ctdb_uint32_push(&in->locks.num_pending, buf+offset, &np);
4502 ctdb_uint32_push(&in->locks.num_failed, buf+offset, &np);
4505 ctdb_latency_counter_push(&in->locks.latency, buf+offset, &np);
4508 for (i=0; i<MAX_COUNT_BUCKETS; i++) {
4509 ctdb_uint32_push(&in->locks.buckets[i], buf+offset, &np);
4513 ctdb_latency_counter_push(&in->vacuum.latency, buf+offset, &np);
4516 ctdb_uint32_push(&in->db_ro_delegations, buf+offset, &np);
4519 ctdb_uint32_push(&in->db_ro_revokes, buf+offset, &np);
4522 for (i=0; i<MAX_COUNT_BUCKETS; i++) {
4523 ctdb_uint32_push(&in->hop_count_bucket[i], buf+offset, &np);
4527 num_hot_keys = MAX_HOT_KEYS;
4528 ctdb_uint32_push(&num_hot_keys, buf+offset, &np);
4531 ctdb_padding_push(4, buf+offset, &np);
4534 for (i=0; i<MAX_HOT_KEYS; i++) {
4535 ctdb_uint32_push(&in->hot_keys[i].count, buf+offset, &np);
4538 ctdb_padding_push(4, buf+offset, &np);
4541 tdb_data_struct_push(&in->hot_keys[i].key, buf+offset, &np);
4545 for (i=0; i<MAX_HOT_KEYS; i++) {
4546 ctdb_tdb_data_push(&in->hot_keys[i].key, buf+offset, &np);
4553 static int ctdb_db_statistics_pull_elems(uint8_t *buf, size_t buflen,
4554 TALLOC_CTX *mem_ctx,
4555 struct ctdb_db_statistics *out,
4558 size_t offset = 0, np;
4561 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
4562 &out->locks.num_calls, &np);
4568 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
4569 &out->locks.num_current, &np);
4575 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
4576 &out->locks.num_pending, &np);
4582 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
4583 &out->locks.num_failed, &np);
4589 ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
4590 &out->locks.latency, &np);
4596 for (i=0; i<MAX_COUNT_BUCKETS; i++) {
4597 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
4598 &out->locks.buckets[i], &np);
4605 ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
4606 &out->vacuum.latency, &np);
4612 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
4613 &out->db_ro_delegations, &np);
4619 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
4620 &out->db_ro_revokes, &np);
4626 for (i=0; i<MAX_COUNT_BUCKETS; i++) {
4627 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
4628 &out->hop_count_bucket[i], &np);
4635 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
4636 &out->num_hot_keys, &np);
4642 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
4648 for (i=0; i<MAX_HOT_KEYS; i++) {
4649 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
4650 &out->hot_keys[i].count, &np);
4656 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
4662 ret = tdb_data_struct_pull(buf+offset, buflen-offset,
4663 &out->hot_keys[i].key, &np);
4670 for (i=0; i<MAX_HOT_KEYS; i++) {
4671 ret = ctdb_tdb_data_pull(buf+offset,
4672 out->hot_keys[i].key.dsize,
4673 out, &out->hot_keys[i].key, &np);
4684 int ctdb_db_statistics_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
4685 struct ctdb_db_statistics **out, size_t *npull)
4687 struct ctdb_db_statistics *val;
4691 val = talloc(mem_ctx, struct ctdb_db_statistics);
4696 ret = ctdb_db_statistics_pull_elems(buf, buflen, val, val, &np);
4707 size_t ctdb_election_message_len(struct ctdb_election_message *in)
4709 return ctdb_uint32_len(&in->num_connected) +
4710 ctdb_padding_len(4) +
4711 ctdb_timeval_len(&in->priority_time) +
4712 ctdb_uint32_len(&in->pnn) +
4713 ctdb_uint32_len(&in->node_flags);
4716 void ctdb_election_message_push(struct ctdb_election_message *in,
4717 uint8_t *buf, size_t *npush)
4719 size_t offset = 0, np;
4721 ctdb_uint32_push(&in->num_connected, buf+offset, &np);
4724 ctdb_padding_push(4, buf+offset, &np);
4727 ctdb_timeval_push(&in->priority_time, buf+offset, &np);
4730 ctdb_uint32_push(&in->pnn, buf+offset, &np);
4733 ctdb_uint32_push(&in->node_flags, buf+offset, &np);
4739 int ctdb_election_message_pull(uint8_t *buf, size_t buflen,
4740 TALLOC_CTX *mem_ctx,
4741 struct ctdb_election_message **out,
4744 struct ctdb_election_message *val;
4745 size_t offset = 0, np;
4748 val = talloc(mem_ctx, struct ctdb_election_message);
4753 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num_connected,
4760 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
4766 ret = ctdb_timeval_pull(buf+offset, buflen-offset,
4767 &val->priority_time, &np);
4773 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
4779 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->node_flags,
4795 size_t ctdb_srvid_message_len(struct ctdb_srvid_message *in)
4797 return ctdb_uint32_len(&in->pnn) +
4798 ctdb_padding_len(4) +
4799 ctdb_uint64_len(&in->srvid);
4802 void ctdb_srvid_message_push(struct ctdb_srvid_message *in, uint8_t *buf,
4805 size_t offset = 0, np;
4807 ctdb_uint32_push(&in->pnn, buf+offset, &np);
4810 ctdb_padding_push(4, buf+offset, &np);
4813 ctdb_uint64_push(&in->srvid, buf+offset, &np);
4819 int ctdb_srvid_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
4820 struct ctdb_srvid_message **out, size_t *npull)
4822 struct ctdb_srvid_message *val;
4823 size_t offset = 0, np;
4826 val = talloc(mem_ctx, struct ctdb_srvid_message);
4831 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
4837 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
4843 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
4858 size_t ctdb_disable_message_len(struct ctdb_disable_message *in)
4860 return ctdb_uint32_len(&in->pnn) +
4861 ctdb_padding_len(4) +
4862 ctdb_uint64_len(&in->srvid) +
4863 ctdb_uint32_len(&in->timeout) +
4864 ctdb_padding_len(4);
4867 void ctdb_disable_message_push(struct ctdb_disable_message *in, uint8_t *buf,
4870 size_t offset = 0, np;
4872 ctdb_uint32_push(&in->pnn, buf+offset, &np);
4875 ctdb_padding_push(4, buf+offset, &np);
4878 ctdb_uint64_push(&in->srvid, buf+offset, &np);
4881 ctdb_uint32_push(&in->timeout, buf+offset, &np);
4884 ctdb_padding_push(4, buf+offset, &np);
4890 int ctdb_disable_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
4891 struct ctdb_disable_message **out,
4894 struct ctdb_disable_message *val;
4895 size_t offset = 0, np;
4898 val = talloc(mem_ctx, struct ctdb_disable_message);
4903 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
4909 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
4915 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
4921 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->timeout, &np);
4927 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
4942 size_t ctdb_server_id_len(struct ctdb_server_id *in)
4944 return ctdb_uint64_len(&in->pid) +
4945 ctdb_uint32_len(&in->task_id) +
4946 ctdb_uint32_len(&in->vnn) +
4947 ctdb_uint64_len(&in->unique_id);
4950 void ctdb_server_id_push(struct ctdb_server_id *in, uint8_t *buf,
4953 size_t offset = 0, np;
4955 ctdb_uint64_push(&in->pid, buf+offset, &np);
4958 ctdb_uint32_push(&in->task_id, buf+offset, &np);
4961 ctdb_uint32_push(&in->vnn, buf+offset, &np);
4964 ctdb_uint64_push(&in->unique_id, buf+offset, &np);
4970 int ctdb_server_id_pull(uint8_t *buf, size_t buflen,
4971 struct ctdb_server_id *out, size_t *npull)
4973 size_t offset = 0, np;
4976 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &out->pid, &np);
4982 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->task_id, &np);
4988 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->vnn, &np);
4994 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &out->unique_id,
5005 size_t ctdb_g_lock_len(struct ctdb_g_lock *in)
5007 return ctdb_uint32_len(&in->type) +
5008 ctdb_padding_len(4) +
5009 ctdb_server_id_len(&in->sid);
5012 void ctdb_g_lock_push(struct ctdb_g_lock *in, uint8_t *buf, size_t *npush)
5014 size_t offset = 0, np;
5018 ctdb_uint32_push(&type, buf+offset, &np);
5021 ctdb_padding_push(4, buf+offset, &np);
5024 ctdb_server_id_push(&in->sid, buf+offset, &np);
5030 int ctdb_g_lock_pull(uint8_t *buf, size_t buflen, struct ctdb_g_lock *out,
5033 size_t offset = 0, np;
5037 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &type, &np);
5044 out->type = CTDB_G_LOCK_READ;
5045 } else if (type == 1) {
5046 out->type = CTDB_G_LOCK_WRITE;
5051 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
5057 ret = ctdb_server_id_pull(buf+offset, buflen-offset, &out->sid, &np);
5067 size_t ctdb_g_lock_list_len(struct ctdb_g_lock_list *in)
5072 len += in->num * ctdb_g_lock_len(&in->lock[0]);
5078 void ctdb_g_lock_list_push(struct ctdb_g_lock_list *in, uint8_t *buf,
5081 size_t offset = 0, np;
5084 for (i=0; i<in->num; i++) {
5085 ctdb_g_lock_push(&in->lock[i], buf+offset, &np);
5092 int ctdb_g_lock_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
5093 struct ctdb_g_lock_list **out, size_t *npull)
5095 struct ctdb_g_lock_list *val;
5096 struct ctdb_g_lock lock = { 0 };
5097 size_t offset = 0, np;
5101 val = talloc(mem_ctx, struct ctdb_g_lock_list);
5112 val->num = buflen / ctdb_g_lock_len(&lock);
5114 val->lock = talloc_array(val, struct ctdb_g_lock, val->num);
5115 if (val->lock == NULL) {
5120 for (i=0; i<val->num; i++) {
5121 ret = ctdb_g_lock_pull(buf+offset, buflen-offset,
5122 &val->lock[i], &np);