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->node.req_tunnel) +
210 ctdb_uint32_len(&in->client.req_call) +
211 ctdb_uint32_len(&in->client.req_message) +
212 ctdb_uint32_len(&in->client.req_control) +
213 ctdb_uint32_len(&in->client.req_tunnel) +
214 ctdb_uint32_len(&in->timeouts.call) +
215 ctdb_uint32_len(&in->timeouts.control) +
216 ctdb_uint32_len(&in->timeouts.traverse) +
217 ctdb_padding_len(4) +
218 ctdb_latency_counter_len(&in->reclock.ctdbd) +
219 ctdb_latency_counter_len(&in->reclock.recd) +
220 ctdb_uint32_len(&in->locks.num_calls) +
221 ctdb_uint32_len(&in->locks.num_current) +
222 ctdb_uint32_len(&in->locks.num_pending) +
223 ctdb_uint32_len(&in->locks.num_failed) +
224 ctdb_latency_counter_len(&in->locks.latency) +
225 MAX_COUNT_BUCKETS * ctdb_uint32_len(&in->locks.buckets[0]) +
226 ctdb_uint32_len(&in->total_calls) +
227 ctdb_uint32_len(&in->pending_calls) +
228 ctdb_uint32_len(&in->childwrite_calls) +
229 ctdb_uint32_len(&in->pending_childwrite_calls) +
230 ctdb_uint32_len(&in->memory_used) +
231 ctdb_uint32_len(&in->__last_counter) +
232 ctdb_uint32_len(&in->max_hop_count) +
234 ctdb_uint32_len(&in->hop_count_bucket[0]) +
235 ctdb_padding_len(4) +
236 ctdb_latency_counter_len(&in->call_latency) +
237 ctdb_latency_counter_len(&in->childwrite_latency) +
238 ctdb_uint32_len(&in->num_recoveries) +
239 ctdb_padding_len(4) +
240 ctdb_timeval_len(&in->statistics_start_time) +
241 ctdb_timeval_len(&in->statistics_current_time) +
242 ctdb_uint32_len(&in->total_ro_delegations) +
243 ctdb_uint32_len(&in->total_ro_revokes);
246 void ctdb_statistics_push(struct ctdb_statistics *in, uint8_t *buf,
249 size_t offset = 0, np;
252 ctdb_uint32_push(&in->num_clients, buf+offset, &np);
255 ctdb_uint32_push(&in->frozen, buf+offset, &np);
258 ctdb_uint32_push(&in->recovering, buf+offset, &np);
261 ctdb_uint32_push(&in->client_packets_sent, buf+offset, &np);
264 ctdb_uint32_push(&in->client_packets_recv, buf+offset, &np);
267 ctdb_uint32_push(&in->node_packets_sent, buf+offset, &np);
270 ctdb_uint32_push(&in->node_packets_recv, buf+offset, &np);
273 ctdb_uint32_push(&in->keepalive_packets_sent, buf+offset, &np);
276 ctdb_uint32_push(&in->keepalive_packets_recv, buf+offset, &np);
279 ctdb_uint32_push(&in->node.req_call, buf+offset, &np);
282 ctdb_uint32_push(&in->node.reply_call, buf+offset, &np);
285 ctdb_uint32_push(&in->node.req_dmaster, buf+offset, &np);
288 ctdb_uint32_push(&in->node.reply_dmaster, buf+offset, &np);
291 ctdb_uint32_push(&in->node.reply_error, buf+offset, &np);
294 ctdb_uint32_push(&in->node.req_message, buf+offset, &np);
297 ctdb_uint32_push(&in->node.req_control, buf+offset, &np);
300 ctdb_uint32_push(&in->node.reply_control, buf+offset, &np);
303 ctdb_uint32_push(&in->node.req_tunnel, buf+offset, &np);
306 ctdb_uint32_push(&in->client.req_call, buf+offset, &np);
309 ctdb_uint32_push(&in->client.req_message, buf+offset, &np);
312 ctdb_uint32_push(&in->client.req_control, buf+offset, &np);
315 ctdb_uint32_push(&in->client.req_tunnel, buf+offset, &np);
318 ctdb_uint32_push(&in->timeouts.call, buf+offset, &np);
321 ctdb_uint32_push(&in->timeouts.control, buf+offset, &np);
324 ctdb_uint32_push(&in->timeouts.traverse, buf+offset, &np);
327 ctdb_padding_push(4, buf+offset, &np);
330 ctdb_latency_counter_push(&in->reclock.ctdbd, buf+offset, &np);
333 ctdb_latency_counter_push(&in->reclock.recd, buf+offset, &np);
336 ctdb_uint32_push(&in->locks.num_calls, buf+offset, &np);
339 ctdb_uint32_push(&in->locks.num_current, buf+offset, &np);
342 ctdb_uint32_push(&in->locks.num_pending, buf+offset, &np);
345 ctdb_uint32_push(&in->locks.num_failed, buf+offset, &np);
348 ctdb_latency_counter_push(&in->locks.latency, buf+offset, &np);
351 for (i=0; i<MAX_COUNT_BUCKETS; i++) {
352 ctdb_uint32_push(&in->locks.buckets[i], buf+offset, &np);
356 ctdb_uint32_push(&in->total_calls, buf+offset, &np);
359 ctdb_uint32_push(&in->pending_calls, buf+offset, &np);
362 ctdb_uint32_push(&in->childwrite_calls, buf+offset, &np);
365 ctdb_uint32_push(&in->pending_childwrite_calls, buf+offset, &np);
368 ctdb_uint32_push(&in->memory_used, buf+offset, &np);
371 ctdb_uint32_push(&in->__last_counter, buf+offset, &np);
374 ctdb_uint32_push(&in->max_hop_count, buf+offset, &np);
377 for (i=0; i<MAX_COUNT_BUCKETS; i++) {
378 ctdb_uint32_push(&in->hop_count_bucket[i], buf+offset, &np);
382 ctdb_padding_push(4, buf+offset, &np);
385 ctdb_latency_counter_push(&in->call_latency, buf+offset, &np);
388 ctdb_latency_counter_push(&in->childwrite_latency, buf+offset, &np);
391 ctdb_uint32_push(&in->num_recoveries, buf+offset, &np);
394 ctdb_padding_push(4, buf+offset, &np);
397 ctdb_timeval_push(&in->statistics_start_time, buf+offset, &np);
400 ctdb_timeval_push(&in->statistics_current_time, buf+offset, &np);
403 ctdb_uint32_push(&in->total_ro_delegations, buf+offset, &np);
406 ctdb_uint32_push(&in->total_ro_revokes, buf+offset, &np);
412 static int ctdb_statistics_pull_elems(uint8_t *buf, size_t buflen,
414 struct ctdb_statistics *out,
417 size_t offset = 0, np;
420 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->num_clients,
427 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->frozen, &np);
433 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->recovering,
440 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
441 &out->client_packets_sent, &np);
447 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
448 &out->client_packets_recv, &np);
454 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
455 &out->node_packets_sent, &np);
461 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
462 &out->node_packets_recv, &np);
468 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
469 &out->keepalive_packets_sent, &np);
475 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
476 &out->keepalive_packets_recv, &np);
482 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
483 &out->node.req_call, &np);
489 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
490 &out->node.reply_call, &np);
496 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
497 &out->node.req_dmaster, &np);
503 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
504 &out->node.reply_dmaster, &np);
510 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
511 &out->node.reply_error, &np);
517 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
518 &out->node.req_message, &np);
524 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
525 &out->node.req_control, &np);
531 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
532 &out->node.reply_control, &np);
538 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
539 &out->node.req_tunnel, &np);
545 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
546 &out->client.req_call, &np);
552 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
553 &out->client.req_message, &np);
559 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
560 &out->client.req_control, &np);
566 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
567 &out->client.req_tunnel, &np);
573 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
574 &out->timeouts.call, &np);
580 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
581 &out->timeouts.control, &np);
587 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
588 &out->timeouts.traverse, &np);
594 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
600 ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
601 &out->reclock.ctdbd, &np);
607 ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
608 &out->reclock.recd, &np);
614 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
615 &out->locks.num_calls, &np);
621 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
622 &out->locks.num_current, &np);
628 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
629 &out->locks.num_pending, &np);
635 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
636 &out->locks.num_failed, &np);
642 ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
643 &out->locks.latency, &np);
649 for (i=0; i<MAX_COUNT_BUCKETS; i++) {
650 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
651 &out->locks.buckets[i], &np);
658 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
659 &out->total_calls, &np);
665 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
666 &out->pending_calls, &np);
672 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
673 &out->childwrite_calls, &np);
679 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
680 &out->pending_childwrite_calls, &np);
686 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->memory_used,
693 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
694 &out->__last_counter, &np);
700 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
701 &out->max_hop_count, &np);
707 for (i=0; i<MAX_COUNT_BUCKETS; i++) {
708 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
709 &out->hop_count_bucket[i], &np);
716 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
722 ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
723 &out->call_latency, &np);
729 ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
730 &out->childwrite_latency, &np);
736 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
737 &out->num_recoveries, &np);
743 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
749 ret = ctdb_timeval_pull(buf+offset, buflen-offset,
750 &out->statistics_start_time, &np);
756 ret = ctdb_timeval_pull(buf+offset, buflen-offset,
757 &out->statistics_current_time, &np);
763 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
764 &out->total_ro_delegations, &np);
770 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
771 &out->total_ro_revokes, &np);
781 int ctdb_statistics_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
782 struct ctdb_statistics **out, size_t *npull)
784 struct ctdb_statistics *val;
788 val = talloc(mem_ctx, struct ctdb_statistics);
793 ret = ctdb_statistics_pull_elems(buf, buflen, val, val, &np);
804 size_t ctdb_statistics_list_len(struct ctdb_statistics_list *in)
808 len = ctdb_int32_len(&in->num) + ctdb_padding_len(4);
810 len += in->num * ctdb_statistics_len(&in->stats[0]);
816 void ctdb_statistics_list_push(struct ctdb_statistics_list *in,
817 uint8_t *buf, size_t *npush)
819 size_t offset = 0, np;
822 ctdb_int32_push(&in->num, buf+offset, &np);
825 ctdb_padding_push(4, buf+offset, &np);
828 for (i=0; i<in->num; i++) {
829 ctdb_statistics_push(&in->stats[i], buf+offset, &np);
836 int ctdb_statistics_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
837 struct ctdb_statistics_list **out,
840 struct ctdb_statistics_list *val;
841 size_t offset = 0, np;
844 val = talloc(mem_ctx, struct ctdb_statistics_list);
849 ret = ctdb_int32_pull(buf+offset, buflen-offset, &val->num, &np);
855 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
866 val->stats = talloc_array(val, struct ctdb_statistics, val->num);
867 if (val->stats == NULL) {
872 for (i=0; i<val->num; i++) {
873 ret = ctdb_statistics_pull_elems(buf+offset, buflen-offset,
874 val, &val->stats[i], &np);
891 size_t ctdb_vnn_map_len(struct ctdb_vnn_map *in)
895 len = ctdb_uint32_len(&in->generation) + ctdb_uint32_len(&in->size);
897 len += in->size * ctdb_uint32_len(&in->map[0]);
903 void ctdb_vnn_map_push(struct ctdb_vnn_map *in, uint8_t *buf, size_t *npush)
905 size_t offset = 0, np;
908 ctdb_uint32_push(&in->generation, buf+offset, &np);
911 ctdb_uint32_push(&in->size, buf+offset, &np);
914 for (i=0; i<in->size; i++) {
915 ctdb_uint32_push(&in->map[i], buf+offset, &np);
922 int ctdb_vnn_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
923 struct ctdb_vnn_map **out, size_t *npull)
925 struct ctdb_vnn_map *val;
926 size_t offset = 0, np;
930 val = talloc(mem_ctx, struct ctdb_vnn_map);
935 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->generation,
942 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->size, &np);
948 if (val->size == 0) {
953 val->map = talloc_array(val, uint32_t, val->size);
954 if (val->map == NULL) {
959 for (i=0; i<val->size; i++) {
960 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
978 size_t ctdb_dbid_len(struct ctdb_dbid *in)
980 return ctdb_uint32_len(&in->db_id) +
981 ctdb_uint8_len(&in->flags) +
985 void ctdb_dbid_push(struct ctdb_dbid *in, uint8_t *buf, size_t *npush)
987 size_t offset = 0, np;
989 ctdb_uint32_push(&in->db_id, buf+offset, &np);
992 ctdb_uint8_push(&in->flags, buf+offset, &np);
995 ctdb_padding_push(3, buf+offset, &np);
1001 static int ctdb_dbid_pull_elems(uint8_t *buf, size_t buflen,
1002 TALLOC_CTX *mem_ctx, struct ctdb_dbid *out,
1005 size_t offset = 0, np;
1008 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->db_id, &np);
1014 ret = ctdb_uint8_pull(buf+offset, buflen-offset, &out->flags, &np);
1020 ret = ctdb_padding_pull(buf+offset, buflen-offset, 3, &np);
1030 int ctdb_dbid_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
1031 struct ctdb_dbid **out, size_t *npull)
1033 struct ctdb_dbid *val;
1037 val = talloc(mem_ctx, struct ctdb_dbid);
1042 ret = ctdb_dbid_pull_elems(buf, buflen, val, val, &np);
1053 size_t ctdb_dbid_map_len(struct ctdb_dbid_map *in)
1057 len = ctdb_uint32_len(&in->num);
1059 len += in->num * ctdb_dbid_len(&in->dbs[0]);
1065 void ctdb_dbid_map_push(struct ctdb_dbid_map *in, uint8_t *buf, size_t *npush)
1067 size_t offset = 0, np;
1070 ctdb_uint32_push(&in->num, buf+offset, &np);
1073 for (i=0; i<in->num; i++) {
1074 ctdb_dbid_push(&in->dbs[i], buf+offset, &np);
1081 int ctdb_dbid_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
1082 struct ctdb_dbid_map **out, size_t *npull)
1084 struct ctdb_dbid_map *val;
1085 size_t offset = 0, np;
1089 val = talloc(mem_ctx, struct ctdb_dbid_map);
1094 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
1100 if (val->num == 0) {
1105 val->dbs = talloc_array(val, struct ctdb_dbid, val->num);
1106 if (val->dbs == NULL) {
1111 for (i=0; i<val->num; i++) {
1112 ret = ctdb_dbid_pull_elems(buf+offset, buflen-offset, val,
1130 size_t ctdb_pulldb_len(struct ctdb_pulldb *in)
1132 return ctdb_uint32_len(&in->db_id) +
1133 ctdb_uint32_len(&in->lmaster);
1136 void ctdb_pulldb_push(struct ctdb_pulldb *in, uint8_t *buf, size_t *npush)
1138 size_t offset = 0, np;
1140 ctdb_uint32_push(&in->db_id, buf+offset, &np);
1143 ctdb_uint32_push(&in->lmaster, buf+offset, &np);
1149 int ctdb_pulldb_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
1150 struct ctdb_pulldb **out, size_t *npull)
1152 struct ctdb_pulldb *val;
1153 size_t offset = 0, np;
1156 val = talloc(mem_ctx, struct ctdb_pulldb);
1161 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
1168 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->lmaster, &np);
1180 size_t ctdb_pulldb_ext_len(struct ctdb_pulldb_ext *in)
1182 return ctdb_uint32_len(&in->db_id) +
1183 ctdb_uint32_len(&in->lmaster) +
1184 ctdb_uint64_len(&in->srvid);
1187 void ctdb_pulldb_ext_push(struct ctdb_pulldb_ext *in, uint8_t *buf,
1190 size_t offset = 0, np;
1192 ctdb_uint32_push(&in->db_id, buf+offset, &np);
1195 ctdb_uint32_push(&in->lmaster, buf+offset, &np);
1198 ctdb_uint64_push(&in->srvid, buf+offset, &np);
1204 int ctdb_pulldb_ext_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
1205 struct ctdb_pulldb_ext **out, size_t *npull)
1207 struct ctdb_pulldb_ext *val;
1208 size_t offset = 0, np;
1211 val = talloc(mem_ctx, struct ctdb_pulldb_ext);
1216 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
1222 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->lmaster, &np);
1228 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
1243 size_t ctdb_ltdb_header_len(struct ctdb_ltdb_header *in)
1245 return ctdb_uint64_len(&in->rsn) +
1246 ctdb_uint32_len(&in->dmaster) +
1247 ctdb_uint32_len(&in->reserved1) +
1248 ctdb_uint32_len(&in->flags) +
1249 ctdb_padding_len(4);
1252 void ctdb_ltdb_header_push(struct ctdb_ltdb_header *in, uint8_t *buf,
1255 size_t offset = 0, np;
1257 ctdb_uint64_push(&in->rsn, buf+offset, &np);
1260 ctdb_uint32_push(&in->dmaster, buf+offset, &np);
1263 ctdb_uint32_push(&in->reserved1, buf+offset, &np);
1266 ctdb_uint32_push(&in->flags, buf+offset, &np);
1269 ctdb_padding_push(4, buf+offset, &np);
1275 int ctdb_ltdb_header_pull(uint8_t *buf, size_t buflen,
1276 struct ctdb_ltdb_header *out, size_t *npull)
1278 size_t offset = 0, np;
1281 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &out->rsn, &np);
1287 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->dmaster, &np);
1293 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->reserved1,
1300 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->flags, &np);
1306 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
1316 int ctdb_ltdb_header_extract(TDB_DATA *data, struct ctdb_ltdb_header *header)
1321 ret = ctdb_ltdb_header_pull(data->dptr, data->dsize, header, &np);
1332 size_t ctdb_rec_data_len(struct ctdb_rec_data *in)
1336 u32 = ctdb_uint32_len(&in->reqid) +
1337 ctdb_tdb_datan_len(&in->key) +
1338 ctdb_tdb_datan_len(&in->data);
1340 if (in->header != NULL) {
1341 u32 += ctdb_ltdb_header_len(in->header);
1344 return ctdb_uint32_len(&u32) + u32;
1347 void ctdb_rec_data_push(struct ctdb_rec_data *in, uint8_t *buf, size_t *npush)
1349 size_t offset = 0, np;
1352 u32 = ctdb_rec_data_len(in);
1353 ctdb_uint32_push(&u32, buf+offset, &np);
1356 ctdb_uint32_push(&in->reqid, buf+offset, &np);
1359 u32 = ctdb_tdb_data_len(&in->key);
1360 ctdb_uint32_push(&u32, buf+offset, &np);
1363 u32 = ctdb_tdb_data_len(&in->data);
1364 if (in->header != NULL) {
1365 u32 += ctdb_ltdb_header_len(in->header);
1368 ctdb_uint32_push(&u32, buf+offset, &np);
1371 ctdb_tdb_data_push(&in->key, buf+offset, &np);
1374 /* If ltdb header is not NULL, then it is pushed as part of the data */
1375 if (in->header != NULL) {
1376 ctdb_ltdb_header_push(in->header, buf+offset, &np);
1379 ctdb_tdb_data_push(&in->data, buf+offset, &np);
1385 static int ctdb_rec_data_pull_data(uint8_t *buf, size_t buflen,
1387 TDB_DATA *key, TDB_DATA *data,
1390 size_t offset = 0, np;
1395 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
1406 ret = ctdb_uint32_pull(buf+offset, len-offset, reqid, &np);
1412 ret = ctdb_uint32_pull(buf+offset, len-offset, &u32, &np);
1419 ret = ctdb_uint32_pull(buf+offset, len-offset, &u32, &np);
1426 if (len-offset < key->dsize) {
1430 key->dptr = buf+offset;
1431 offset += key->dsize;
1433 if (len-offset < data->dsize) {
1437 data->dptr = buf+offset;
1438 offset += data->dsize;
1444 static int ctdb_rec_data_pull_elems(uint8_t *buf, size_t buflen,
1445 TALLOC_CTX *mem_ctx,
1446 struct ctdb_rec_data *out,
1454 ret = ctdb_rec_data_pull_data(buf, buflen, &reqid, &key, &data, &np);
1461 /* Always set header to NULL. If it is required, extract it using
1462 * ctdb_rec_data_extract_header()
1466 out->key.dsize = key.dsize;
1467 if (key.dsize > 0) {
1468 out->key.dptr = talloc_memdup(mem_ctx, key.dptr, key.dsize);
1469 if (out->key.dptr == NULL) {
1474 out->data.dsize = data.dsize;
1475 if (data.dsize > 0) {
1476 out->data.dptr = talloc_memdup(mem_ctx, data.dptr, data.dsize);
1477 if (out->data.dptr == NULL) {
1486 int ctdb_rec_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
1487 struct ctdb_rec_data **out, size_t *npull)
1489 struct ctdb_rec_data *val;
1493 val = talloc(mem_ctx, struct ctdb_rec_data);
1498 ret = ctdb_rec_data_pull_elems(buf, buflen, val, val, &np);
1509 size_t ctdb_rec_buffer_len(struct ctdb_rec_buffer *in)
1511 return ctdb_uint32_len(&in->db_id) +
1512 ctdb_uint32_len(&in->count) +
1516 void ctdb_rec_buffer_push(struct ctdb_rec_buffer *in, uint8_t *buf,
1519 size_t offset = 0, np;
1521 ctdb_uint32_push(&in->db_id, buf+offset, &np);
1524 ctdb_uint32_push(&in->count, buf+offset, &np);
1527 memcpy(buf+offset, in->buf, in->buflen);
1528 offset += in->buflen;
1533 int ctdb_rec_buffer_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
1534 struct ctdb_rec_buffer **out, size_t *npull)
1536 struct ctdb_rec_buffer *val;
1537 size_t offset = 0, np;
1541 val = talloc(mem_ctx, struct ctdb_rec_buffer);
1546 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
1552 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->count, &np);
1558 /* Since there is no buflen provided, walk the records to
1559 * validate the length of the buffer.
1561 val->buf = buf+offset;
1562 val->buflen = buflen-offset;
1565 ret = ctdb_rec_buffer_traverse(val, NULL, &length);
1570 if (length > buflen-offset) {
1575 val->buf = talloc_memdup(val, buf+offset, length);
1576 if (val->buf == NULL) {
1580 val->buflen = length;
1592 struct ctdb_rec_buffer *ctdb_rec_buffer_init(TALLOC_CTX *mem_ctx,
1595 struct ctdb_rec_buffer *recbuf;
1597 recbuf = talloc_zero(mem_ctx, struct ctdb_rec_buffer);
1598 if (recbuf == NULL) {
1602 recbuf->db_id = db_id;
1607 int ctdb_rec_buffer_add(TALLOC_CTX *mem_ctx, struct ctdb_rec_buffer *recbuf,
1608 uint32_t reqid, struct ctdb_ltdb_header *header,
1609 TDB_DATA key, TDB_DATA data)
1611 struct ctdb_rec_data recdata;
1615 recdata.reqid = reqid;
1616 recdata.header = header;
1618 recdata.data = data;
1620 len = ctdb_rec_data_len(&recdata);
1622 ptr = talloc_realloc(mem_ctx, recbuf->buf, uint8_t,
1623 recbuf->buflen + len);
1628 ctdb_rec_data_push(&recdata, &ptr[recbuf->buflen], &np);
1632 recbuf->buflen += np;
1636 int ctdb_rec_buffer_traverse(struct ctdb_rec_buffer *recbuf,
1637 ctdb_rec_parser_func_t func,
1642 size_t offset, reclen;
1646 for (i=0; i<recbuf->count; i++) {
1647 ret = ctdb_rec_data_pull_data(&recbuf->buf[offset],
1648 recbuf->buflen - offset,
1649 &reqid, &key, &data, &reclen);
1655 ret = func(reqid, NULL, key, data, private_data);
1669 size_t *length = (size_t *)private_data;
1677 int ctdb_rec_buffer_write(struct ctdb_rec_buffer *recbuf, int fd)
1681 n = write(fd, &recbuf->db_id, sizeof(uint32_t));
1682 if (n == -1 || n != sizeof(uint32_t)) {
1683 return (errno != 0 ? errno : EIO);
1685 n = write(fd, &recbuf->count, sizeof(uint32_t));
1686 if (n == -1 || n != sizeof(uint32_t)) {
1687 return (errno != 0 ? errno : EIO);
1689 n = write(fd, &recbuf->buflen, sizeof(size_t));
1690 if (n == -1 || n != sizeof(size_t)) {
1691 return (errno != 0 ? errno : EIO);
1693 n = write(fd, recbuf->buf, recbuf->buflen);
1694 if (n == -1 || n != recbuf->buflen) {
1695 return (errno != 0 ? errno : EIO);
1701 int ctdb_rec_buffer_read(int fd, TALLOC_CTX *mem_ctx,
1702 struct ctdb_rec_buffer **out)
1704 struct ctdb_rec_buffer *recbuf;
1707 recbuf = talloc(mem_ctx, struct ctdb_rec_buffer);
1708 if (recbuf == NULL) {
1712 n = read(fd, &recbuf->db_id, sizeof(uint32_t));
1713 if (n == -1 || n != sizeof(uint32_t)) {
1714 return (errno != 0 ? errno : EIO);
1716 n = read(fd, &recbuf->count, sizeof(uint32_t));
1717 if (n == -1 || n != sizeof(uint32_t)) {
1718 return (errno != 0 ? errno : EIO);
1720 n = read(fd, &recbuf->buflen, sizeof(size_t));
1721 if (n == -1 || n != sizeof(size_t)) {
1722 return (errno != 0 ? errno : EIO);
1725 recbuf->buf = talloc_size(recbuf, recbuf->buflen);
1726 if (recbuf->buf == NULL) {
1730 n = read(fd, recbuf->buf, recbuf->buflen);
1731 if (n == -1 || n != recbuf->buflen) {
1732 return (errno != 0 ? errno : EIO);
1739 size_t ctdb_traverse_start_len(struct ctdb_traverse_start *in)
1741 return ctdb_uint32_len(&in->db_id) +
1742 ctdb_uint32_len(&in->reqid) +
1743 ctdb_uint64_len(&in->srvid);
1746 void ctdb_traverse_start_push(struct ctdb_traverse_start *in, uint8_t *buf,
1749 size_t offset = 0, np;
1751 ctdb_uint32_push(&in->db_id, buf+offset, &np);
1754 ctdb_uint32_push(&in->reqid, buf+offset, &np);
1757 ctdb_uint64_push(&in->srvid, buf+offset, &np);
1763 int ctdb_traverse_start_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
1764 struct ctdb_traverse_start **out, size_t *npull)
1766 struct ctdb_traverse_start *val;
1767 size_t offset = 0, np;
1770 val = talloc(mem_ctx, struct ctdb_traverse_start);
1775 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
1781 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->reqid, &np);
1787 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
1802 size_t ctdb_traverse_all_len(struct ctdb_traverse_all *in)
1804 return ctdb_uint32_len(&in->db_id) +
1805 ctdb_uint32_len(&in->reqid) +
1806 ctdb_uint32_len(&in->pnn) +
1807 ctdb_uint32_len(&in->client_reqid) +
1808 ctdb_uint64_len(&in->srvid);
1811 void ctdb_traverse_all_push(struct ctdb_traverse_all *in, uint8_t *buf,
1814 size_t offset = 0, np;
1816 ctdb_uint32_push(&in->db_id, buf+offset, &np);
1819 ctdb_uint32_push(&in->reqid, buf+offset, &np);
1822 ctdb_uint32_push(&in->pnn, buf+offset, &np);
1825 ctdb_uint32_push(&in->client_reqid, buf+offset, &np);
1828 ctdb_uint64_push(&in->srvid, buf+offset, &np);
1834 int ctdb_traverse_all_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
1835 struct ctdb_traverse_all **out, size_t *npull)
1837 struct ctdb_traverse_all *val;
1838 size_t offset = 0, np;
1841 val = talloc(mem_ctx, struct ctdb_traverse_all);
1846 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
1852 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->reqid, &np);
1858 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
1864 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->client_reqid,
1871 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
1886 size_t ctdb_traverse_start_ext_len(struct ctdb_traverse_start_ext *in)
1888 return ctdb_uint32_len(&in->db_id) +
1889 ctdb_uint32_len(&in->reqid) +
1890 ctdb_uint64_len(&in->srvid) +
1891 ctdb_bool_len(&in->withemptyrecords) +
1892 ctdb_padding_len(7);
1895 void ctdb_traverse_start_ext_push(struct ctdb_traverse_start_ext *in,
1896 uint8_t *buf, size_t *npush)
1898 size_t offset = 0, np;
1900 ctdb_uint32_push(&in->db_id, buf+offset, &np);
1903 ctdb_uint32_push(&in->reqid, buf+offset, &np);
1906 ctdb_uint64_push(&in->srvid, buf+offset, &np);
1909 ctdb_bool_push(&in->withemptyrecords, buf+offset, &np);
1912 ctdb_padding_push(7, buf+offset, &np);
1918 int ctdb_traverse_start_ext_pull(uint8_t *buf, size_t buflen,
1919 TALLOC_CTX *mem_ctx,
1920 struct ctdb_traverse_start_ext **out,
1923 struct ctdb_traverse_start_ext *val;
1924 size_t offset = 0, np;
1927 val = talloc(mem_ctx, struct ctdb_traverse_start_ext);
1932 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
1938 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->reqid, &np);
1944 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
1950 ret = ctdb_bool_pull(buf+offset, buflen-offset,
1951 &val->withemptyrecords, &np);
1957 ret = ctdb_padding_pull(buf+offset, buflen-offset, 7, &np);
1972 size_t ctdb_traverse_all_ext_len(struct ctdb_traverse_all_ext *in)
1974 return ctdb_uint32_len(&in->db_id) +
1975 ctdb_uint32_len(&in->reqid) +
1976 ctdb_uint32_len(&in->pnn) +
1977 ctdb_uint32_len(&in->client_reqid) +
1978 ctdb_uint64_len(&in->srvid) +
1979 ctdb_bool_len(&in->withemptyrecords) +
1980 ctdb_padding_len(7);
1983 void ctdb_traverse_all_ext_push(struct ctdb_traverse_all_ext *in,
1984 uint8_t *buf, size_t *npush)
1986 size_t offset = 0, np;
1988 ctdb_uint32_push(&in->db_id, buf+offset, &np);
1991 ctdb_uint32_push(&in->reqid, buf+offset, &np);
1994 ctdb_uint32_push(&in->pnn, buf+offset, &np);
1997 ctdb_uint32_push(&in->client_reqid, buf+offset, &np);
2000 ctdb_uint64_push(&in->srvid, buf+offset, &np);
2003 ctdb_bool_push(&in->withemptyrecords, buf+offset, &np);
2006 ctdb_padding_push(7, buf+offset, &np);
2012 int ctdb_traverse_all_ext_pull(uint8_t *buf, size_t buflen,
2013 TALLOC_CTX *mem_ctx,
2014 struct ctdb_traverse_all_ext **out,
2017 struct ctdb_traverse_all_ext *val;
2018 size_t offset = 0, np;
2021 val = talloc(mem_ctx, struct ctdb_traverse_all_ext);
2026 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
2032 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->reqid, &np);
2038 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
2044 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->client_reqid,
2051 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
2057 ret = ctdb_bool_pull(buf+offset, buflen-offset,
2058 &val->withemptyrecords, &np);
2064 ret = ctdb_padding_pull(buf+offset, buflen-offset, 7, &np);
2079 size_t ctdb_sock_addr_len(ctdb_sock_addr *in)
2081 return sizeof(ctdb_sock_addr);
2084 void ctdb_sock_addr_push(ctdb_sock_addr *in, uint8_t *buf, size_t *npush)
2086 memcpy(buf, in, sizeof(ctdb_sock_addr));
2087 *npush = sizeof(ctdb_sock_addr);
2090 int ctdb_sock_addr_pull_elems(uint8_t *buf, size_t buflen,
2091 TALLOC_CTX *mem_ctx, ctdb_sock_addr *out,
2094 if (buflen < sizeof(ctdb_sock_addr)) {
2098 memcpy(out, buf, sizeof(ctdb_sock_addr));
2099 *npull = sizeof(ctdb_sock_addr);
2104 int ctdb_sock_addr_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
2105 ctdb_sock_addr **out, size_t *npull)
2107 ctdb_sock_addr *val;
2111 val = talloc(mem_ctx, ctdb_sock_addr);
2116 ret = ctdb_sock_addr_pull_elems(buf, buflen, val, val, &np);
2127 size_t ctdb_connection_len(struct ctdb_connection *in)
2129 return ctdb_sock_addr_len(&in->src) +
2130 ctdb_sock_addr_len(&in->dst);
2133 void ctdb_connection_push(struct ctdb_connection *in, uint8_t *buf,
2136 size_t offset = 0, np;
2138 ctdb_sock_addr_push(&in->src, buf+offset, &np);
2141 ctdb_sock_addr_push(&in->dst, buf+offset, &np);
2147 static int ctdb_connection_pull_elems(uint8_t *buf, size_t buflen,
2148 TALLOC_CTX *mem_ctx,
2149 struct ctdb_connection *out,
2152 size_t offset = 0, np;
2155 ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset,
2156 mem_ctx, &out->src, &np);
2162 ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset,
2163 mem_ctx, &out->dst, &np);
2173 int ctdb_connection_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
2174 struct ctdb_connection **out, size_t *npull)
2176 struct ctdb_connection *val;
2180 val = talloc(mem_ctx, struct ctdb_connection);
2185 ret = ctdb_connection_pull_elems(buf, buflen, val, val, &np);
2196 size_t ctdb_connection_list_len(struct ctdb_connection_list *in)
2200 len = ctdb_uint32_len(&in->num);
2202 len += in->num * ctdb_connection_len(&in->conn[0]);
2208 void ctdb_connection_list_push(struct ctdb_connection_list *in, uint8_t *buf,
2211 size_t offset = 0, np;
2214 ctdb_uint32_push(&in->num, buf+offset, &np);
2217 for (i=0; i<in->num; i++) {
2218 ctdb_connection_push(&in->conn[i], buf+offset, &np);
2225 int ctdb_connection_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
2226 struct ctdb_connection_list **out, size_t *npull)
2228 struct ctdb_connection_list *val;
2229 size_t offset = 0, np;
2233 val = talloc(mem_ctx, struct ctdb_connection_list);
2238 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
2244 if (val->num == 0) {
2249 val->conn = talloc_array(val, struct ctdb_connection, val->num);
2250 if (val->conn == NULL) {
2255 for (i=0; i<val->num; i++) {
2256 ret = ctdb_connection_pull_elems(buf+offset, buflen-offset,
2257 val, &val->conn[i], &np);
2274 size_t ctdb_tunable_len(struct ctdb_tunable *in)
2276 return ctdb_uint32_len(&in->value) +
2277 ctdb_stringn_len(&in->name);
2280 void ctdb_tunable_push(struct ctdb_tunable *in, uint8_t *buf, size_t *npush)
2282 size_t offset = 0, np;
2284 ctdb_uint32_push(&in->value, buf+offset, &np);
2287 ctdb_stringn_push(&in->name, buf+offset, &np);
2293 int ctdb_tunable_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
2294 struct ctdb_tunable **out, size_t *npull)
2296 struct ctdb_tunable *val;
2297 size_t offset = 0, np;
2300 val = talloc(mem_ctx, struct ctdb_tunable);
2305 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->value, &np);
2311 ret = ctdb_stringn_pull(buf+offset, buflen-offset, mem_ctx,
2327 size_t ctdb_node_flag_change_len(struct ctdb_node_flag_change *in)
2329 return ctdb_uint32_len(&in->pnn) +
2330 ctdb_uint32_len(&in->new_flags) +
2331 ctdb_uint32_len(&in->old_flags);
2334 void ctdb_node_flag_change_push(struct ctdb_node_flag_change *in,
2335 uint8_t *buf, size_t *npush)
2337 size_t offset = 0, np;
2339 ctdb_uint32_push(&in->pnn, buf+offset, &np);
2342 ctdb_uint32_push(&in->new_flags, buf+offset, &np);
2345 ctdb_uint32_push(&in->old_flags, buf+offset, &np);
2351 int ctdb_node_flag_change_pull(uint8_t *buf, size_t buflen,
2352 TALLOC_CTX *mem_ctx,
2353 struct ctdb_node_flag_change **out,
2356 struct ctdb_node_flag_change *val;
2357 size_t offset = 0, np;
2360 val = talloc(mem_ctx, struct ctdb_node_flag_change);
2365 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
2371 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->new_flags,
2378 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->old_flags,
2394 size_t ctdb_var_list_len(struct ctdb_var_list *in)
2399 for (i=0; i<in->count; i++) {
2400 u32 += ctdb_string_len(&in->var[i]);
2403 return ctdb_uint32_len(&u32) + u32;
2406 void ctdb_var_list_push(struct ctdb_var_list *in, uint8_t *buf, size_t *npush)
2408 size_t offset = 0, np;
2413 /* The length only corresponds to the payload size */
2414 u32 = ctdb_var_list_len(in);
2415 u32 -= ctdb_uint32_len(&u32);
2417 ctdb_uint32_push(&u32, buf+offset, &np);
2420 /* The variables are separated by ':' and the complete string is null
2423 for (i=0; i<in->count; i++) {
2424 ctdb_string_push(&in->var[i], buf+offset, &np);
2427 if (i < in->count - 1) {
2428 /* Replace '\0' with ':' */
2429 ctdb_uint8_push(&sep, buf+offset-1, &np);
2436 int ctdb_var_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
2437 struct ctdb_var_list **out, size_t *npull)
2439 struct ctdb_var_list *val;
2440 const char *str, **list;
2441 char *s, *tok, *ptr = NULL;
2442 size_t offset = 0, np;
2446 val = talloc_zero(mem_ctx, struct ctdb_var_list);
2451 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
2457 if (buflen-offset < u32) {
2462 ret = ctdb_string_pull(buf+offset, u32, val, &str, &np);
2468 s = discard_const(str);
2469 while ((tok = strtok_r(s, ":", &ptr)) != NULL) {
2470 list = talloc_realloc(val, val->var, const char *,
2479 s = talloc_strdup(val, tok);
2485 val->var[val->count] = s;
2490 talloc_free(discard_const(str));
2500 size_t ctdb_tunable_list_len(struct ctdb_tunable_list *in)
2502 return ctdb_uint32_len(&in->max_redirect_count) +
2503 ctdb_uint32_len(&in->seqnum_interval) +
2504 ctdb_uint32_len(&in->control_timeout) +
2505 ctdb_uint32_len(&in->traverse_timeout) +
2506 ctdb_uint32_len(&in->keepalive_interval) +
2507 ctdb_uint32_len(&in->keepalive_limit) +
2508 ctdb_uint32_len(&in->recover_timeout) +
2509 ctdb_uint32_len(&in->recover_interval) +
2510 ctdb_uint32_len(&in->election_timeout) +
2511 ctdb_uint32_len(&in->takeover_timeout) +
2512 ctdb_uint32_len(&in->monitor_interval) +
2513 ctdb_uint32_len(&in->tickle_update_interval) +
2514 ctdb_uint32_len(&in->script_timeout) +
2515 ctdb_uint32_len(&in->monitor_timeout_count) +
2516 ctdb_uint32_len(&in->script_unhealthy_on_timeout) +
2517 ctdb_uint32_len(&in->recovery_grace_period) +
2518 ctdb_uint32_len(&in->recovery_ban_period) +
2519 ctdb_uint32_len(&in->database_hash_size) +
2520 ctdb_uint32_len(&in->database_max_dead) +
2521 ctdb_uint32_len(&in->rerecovery_timeout) +
2522 ctdb_uint32_len(&in->enable_bans) +
2523 ctdb_uint32_len(&in->deterministic_public_ips) +
2524 ctdb_uint32_len(&in->reclock_ping_period) +
2525 ctdb_uint32_len(&in->no_ip_failback) +
2526 ctdb_uint32_len(&in->disable_ip_failover) +
2527 ctdb_uint32_len(&in->verbose_memory_names) +
2528 ctdb_uint32_len(&in->recd_ping_timeout) +
2529 ctdb_uint32_len(&in->recd_ping_failcount) +
2530 ctdb_uint32_len(&in->log_latency_ms) +
2531 ctdb_uint32_len(&in->reclock_latency_ms) +
2532 ctdb_uint32_len(&in->recovery_drop_all_ips) +
2533 ctdb_uint32_len(&in->verify_recovery_lock) +
2534 ctdb_uint32_len(&in->vacuum_interval) +
2535 ctdb_uint32_len(&in->vacuum_max_run_time) +
2536 ctdb_uint32_len(&in->repack_limit) +
2537 ctdb_uint32_len(&in->vacuum_limit) +
2538 ctdb_uint32_len(&in->max_queue_depth_drop_msg) +
2539 ctdb_uint32_len(&in->allow_unhealthy_db_read) +
2540 ctdb_uint32_len(&in->stat_history_interval) +
2541 ctdb_uint32_len(&in->deferred_attach_timeout) +
2542 ctdb_uint32_len(&in->vacuum_fast_path_count) +
2543 ctdb_uint32_len(&in->lcp2_public_ip_assignment) +
2544 ctdb_uint32_len(&in->allow_client_db_attach) +
2545 ctdb_uint32_len(&in->recover_pdb_by_seqnum) +
2546 ctdb_uint32_len(&in->deferred_rebalance_on_node_add) +
2547 ctdb_uint32_len(&in->fetch_collapse) +
2548 ctdb_uint32_len(&in->hopcount_make_sticky) +
2549 ctdb_uint32_len(&in->sticky_duration) +
2550 ctdb_uint32_len(&in->sticky_pindown) +
2551 ctdb_uint32_len(&in->no_ip_takeover) +
2552 ctdb_uint32_len(&in->db_record_count_warn) +
2553 ctdb_uint32_len(&in->db_record_size_warn) +
2554 ctdb_uint32_len(&in->db_size_warn) +
2555 ctdb_uint32_len(&in->pulldb_preallocation_size) +
2556 ctdb_uint32_len(&in->no_ip_host_on_all_disabled) +
2557 ctdb_uint32_len(&in->samba3_hack) +
2558 ctdb_uint32_len(&in->mutex_enabled) +
2559 ctdb_uint32_len(&in->lock_processes_per_db) +
2560 ctdb_uint32_len(&in->rec_buffer_size_limit) +
2561 ctdb_uint32_len(&in->queue_buffer_size) +
2562 ctdb_uint32_len(&in->ip_alloc_algorithm) +
2563 ctdb_uint32_len(&in->allow_mixed_versions);
2566 void ctdb_tunable_list_push(struct ctdb_tunable_list *in, uint8_t *buf,
2569 size_t offset = 0, np;
2571 ctdb_uint32_push(&in->max_redirect_count, buf+offset, &np);
2574 ctdb_uint32_push(&in->seqnum_interval, buf+offset, &np);
2577 ctdb_uint32_push(&in->control_timeout, buf+offset, &np);
2580 ctdb_uint32_push(&in->traverse_timeout, buf+offset, &np);
2583 ctdb_uint32_push(&in->keepalive_interval, buf+offset, &np);
2586 ctdb_uint32_push(&in->keepalive_limit, buf+offset, &np);
2589 ctdb_uint32_push(&in->recover_timeout, buf+offset, &np);
2592 ctdb_uint32_push(&in->recover_interval, buf+offset, &np);
2595 ctdb_uint32_push(&in->election_timeout, buf+offset, &np);
2598 ctdb_uint32_push(&in->takeover_timeout, buf+offset, &np);
2601 ctdb_uint32_push(&in->monitor_interval, buf+offset, &np);
2604 ctdb_uint32_push(&in->tickle_update_interval, buf+offset, &np);
2607 ctdb_uint32_push(&in->script_timeout, buf+offset, &np);
2610 ctdb_uint32_push(&in->monitor_timeout_count, buf+offset, &np);
2613 ctdb_uint32_push(&in->script_unhealthy_on_timeout, buf+offset, &np);
2616 ctdb_uint32_push(&in->recovery_grace_period, buf+offset, &np);
2619 ctdb_uint32_push(&in->recovery_ban_period, buf+offset, &np);
2622 ctdb_uint32_push(&in->database_hash_size, buf+offset, &np);
2625 ctdb_uint32_push(&in->database_max_dead, buf+offset, &np);
2628 ctdb_uint32_push(&in->rerecovery_timeout, buf+offset, &np);
2631 ctdb_uint32_push(&in->enable_bans, buf+offset, &np);
2634 ctdb_uint32_push(&in->deterministic_public_ips, buf+offset, &np);
2637 ctdb_uint32_push(&in->reclock_ping_period, buf+offset, &np);
2640 ctdb_uint32_push(&in->no_ip_failback, buf+offset, &np);
2643 ctdb_uint32_push(&in->disable_ip_failover, buf+offset, &np);
2646 ctdb_uint32_push(&in->verbose_memory_names, buf+offset, &np);
2649 ctdb_uint32_push(&in->recd_ping_timeout, buf+offset, &np);
2652 ctdb_uint32_push(&in->recd_ping_failcount, buf+offset, &np);
2655 ctdb_uint32_push(&in->log_latency_ms, buf+offset, &np);
2658 ctdb_uint32_push(&in->reclock_latency_ms, buf+offset, &np);
2661 ctdb_uint32_push(&in->recovery_drop_all_ips, buf+offset, &np);
2664 ctdb_uint32_push(&in->verify_recovery_lock, buf+offset, &np);
2667 ctdb_uint32_push(&in->vacuum_interval, buf+offset, &np);
2670 ctdb_uint32_push(&in->vacuum_max_run_time, buf+offset, &np);
2673 ctdb_uint32_push(&in->repack_limit, buf+offset, &np);
2676 ctdb_uint32_push(&in->vacuum_limit, buf+offset, &np);
2679 ctdb_uint32_push(&in->max_queue_depth_drop_msg, buf+offset, &np);
2682 ctdb_uint32_push(&in->allow_unhealthy_db_read, buf+offset, &np);
2685 ctdb_uint32_push(&in->stat_history_interval, buf+offset, &np);
2688 ctdb_uint32_push(&in->deferred_attach_timeout, buf+offset, &np);
2691 ctdb_uint32_push(&in->vacuum_fast_path_count, buf+offset, &np);
2694 ctdb_uint32_push(&in->lcp2_public_ip_assignment, buf+offset, &np);
2697 ctdb_uint32_push(&in->allow_client_db_attach, buf+offset, &np);
2700 ctdb_uint32_push(&in->recover_pdb_by_seqnum, buf+offset, &np);
2703 ctdb_uint32_push(&in->deferred_rebalance_on_node_add, buf+offset, &np);
2706 ctdb_uint32_push(&in->fetch_collapse, buf+offset, &np);
2709 ctdb_uint32_push(&in->hopcount_make_sticky, buf+offset, &np);
2712 ctdb_uint32_push(&in->sticky_duration, buf+offset, &np);
2715 ctdb_uint32_push(&in->sticky_pindown, buf+offset, &np);
2718 ctdb_uint32_push(&in->no_ip_takeover, buf+offset, &np);
2721 ctdb_uint32_push(&in->db_record_count_warn, buf+offset, &np);
2724 ctdb_uint32_push(&in->db_record_size_warn, buf+offset, &np);
2727 ctdb_uint32_push(&in->db_size_warn, buf+offset, &np);
2730 ctdb_uint32_push(&in->pulldb_preallocation_size, buf+offset, &np);
2733 ctdb_uint32_push(&in->no_ip_host_on_all_disabled, buf+offset, &np);
2736 ctdb_uint32_push(&in->samba3_hack, buf+offset, &np);
2739 ctdb_uint32_push(&in->mutex_enabled, buf+offset, &np);
2742 ctdb_uint32_push(&in->lock_processes_per_db, buf+offset, &np);
2745 ctdb_uint32_push(&in->rec_buffer_size_limit, buf+offset, &np);
2748 ctdb_uint32_push(&in->queue_buffer_size, buf+offset, &np);
2751 ctdb_uint32_push(&in->ip_alloc_algorithm, buf+offset, &np);
2754 ctdb_uint32_push(&in->allow_mixed_versions, buf+offset, &np);
2760 static int ctdb_tunable_list_pull_elems(uint8_t *buf, size_t buflen,
2761 TALLOC_CTX *mem_ctx,
2762 struct ctdb_tunable_list *out,
2765 size_t offset = 0, np;
2768 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2769 &out->max_redirect_count, &np);
2775 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2776 &out->seqnum_interval, &np);
2782 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2783 &out->control_timeout, &np);
2789 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2790 &out->traverse_timeout, &np);
2796 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2797 &out->keepalive_interval, &np);
2803 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2804 &out->keepalive_limit, &np);
2810 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2811 &out->recover_timeout, &np);
2817 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2818 &out->recover_interval, &np);
2824 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2825 &out->election_timeout, &np);
2831 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2832 &out->takeover_timeout, &np);
2838 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2839 &out->monitor_interval, &np);
2845 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2846 &out->tickle_update_interval, &np);
2852 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2853 &out->script_timeout, &np);
2859 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2860 &out->monitor_timeout_count, &np);
2866 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2867 &out->script_unhealthy_on_timeout, &np);
2873 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2874 &out->recovery_grace_period, &np);
2880 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2881 &out->recovery_ban_period, &np);
2887 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2888 &out->database_hash_size, &np);
2894 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2895 &out->database_max_dead, &np);
2901 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2902 &out->rerecovery_timeout, &np);
2908 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2909 &out->enable_bans, &np);
2915 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2916 &out->deterministic_public_ips, &np);
2922 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2923 &out->reclock_ping_period, &np);
2929 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2930 &out->no_ip_failback, &np);
2936 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2937 &out->disable_ip_failover, &np);
2943 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2944 &out->verbose_memory_names, &np);
2950 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2951 &out->recd_ping_timeout, &np);
2957 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2958 &out->recd_ping_failcount, &np);
2964 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2965 &out->log_latency_ms, &np);
2971 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2972 &out->reclock_latency_ms, &np);
2978 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2979 &out->recovery_drop_all_ips, &np);
2985 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2986 &out->verify_recovery_lock, &np);
2992 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
2993 &out->vacuum_interval, &np);
2999 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3000 &out->vacuum_max_run_time, &np);
3006 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3007 &out->repack_limit, &np);
3013 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3014 &out->vacuum_limit, &np);
3020 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3021 &out->max_queue_depth_drop_msg, &np);
3027 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3028 &out->allow_unhealthy_db_read, &np);
3034 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3035 &out->stat_history_interval, &np);
3041 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3042 &out->deferred_attach_timeout, &np);
3048 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3049 &out->vacuum_fast_path_count, &np);
3055 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3056 &out->lcp2_public_ip_assignment, &np);
3062 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3063 &out->allow_client_db_attach, &np);
3069 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3070 &out->recover_pdb_by_seqnum, &np);
3076 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3077 &out->deferred_rebalance_on_node_add, &np);
3083 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3084 &out->fetch_collapse, &np);
3090 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3091 &out->hopcount_make_sticky, &np);
3097 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3098 &out->sticky_duration, &np);
3104 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3105 &out->sticky_pindown, &np);
3111 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3112 &out->no_ip_takeover, &np);
3118 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3119 &out->db_record_count_warn, &np);
3125 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3126 &out->db_record_size_warn, &np);
3132 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3133 &out->db_size_warn, &np);
3139 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3140 &out->pulldb_preallocation_size, &np);
3146 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3147 &out->no_ip_host_on_all_disabled, &np);
3153 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3154 &out->samba3_hack, &np);
3160 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3161 &out->mutex_enabled, &np);
3167 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3168 &out->lock_processes_per_db, &np);
3174 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3175 &out->rec_buffer_size_limit, &np);
3181 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3182 &out->queue_buffer_size, &np);
3188 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3189 &out->ip_alloc_algorithm, &np);
3195 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
3196 &out->allow_mixed_versions, &np);
3206 int ctdb_tunable_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
3207 struct ctdb_tunable_list **out, size_t *npull)
3209 struct ctdb_tunable_list *val;
3213 val = talloc(mem_ctx, struct ctdb_tunable_list);
3218 ret = ctdb_tunable_list_pull_elems(buf, buflen, val, val, &np);
3229 size_t ctdb_tickle_list_len(struct ctdb_tickle_list *in)
3233 len = ctdb_sock_addr_len(&in->addr) +
3234 ctdb_uint32_len(&in->num);
3236 len += in->num * ctdb_connection_len(&in->conn[0]);
3242 void ctdb_tickle_list_push(struct ctdb_tickle_list *in, uint8_t *buf,
3245 size_t offset = 0, np;
3248 ctdb_sock_addr_push(&in->addr, buf+offset, &np);
3251 ctdb_uint32_push(&in->num, buf+offset, &np);
3254 for (i=0; i<in->num; i++) {
3255 ctdb_connection_push(&in->conn[i], buf+offset, &np);
3262 int ctdb_tickle_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
3263 struct ctdb_tickle_list **out, size_t *npull)
3265 struct ctdb_tickle_list *val;
3266 size_t offset = 0, np;
3270 val = talloc(mem_ctx, struct ctdb_tickle_list);
3275 ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset, val,
3282 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
3288 if (val->num == 0) {
3293 val->conn = talloc_array(val, struct ctdb_connection, val->num);
3294 if (val->conn == NULL) {
3299 for (i=0; i<val->num; i++) {
3300 ret = ctdb_connection_pull_elems(buf+offset, buflen-offset,
3301 val, &val->conn[i], &np);
3318 size_t ctdb_addr_info_len(struct ctdb_addr_info *in)
3320 return ctdb_sock_addr_len(&in->addr) +
3321 ctdb_uint32_len(&in->mask) +
3322 ctdb_stringn_len(&in->iface);
3325 void ctdb_addr_info_push(struct ctdb_addr_info *in, uint8_t *buf,
3328 size_t offset = 0, np;
3330 ctdb_sock_addr_push(&in->addr, buf+offset, &np);
3333 ctdb_uint32_push(&in->mask, buf+offset, &np);
3336 ctdb_stringn_push(&in->iface, buf+offset, &np);
3342 int ctdb_addr_info_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
3343 struct ctdb_addr_info **out, size_t *npull)
3345 struct ctdb_addr_info *val;
3346 size_t offset = 0, np;
3349 val = talloc(mem_ctx, struct ctdb_addr_info);
3354 ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset, val,
3361 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->mask, &np);
3367 ret = ctdb_stringn_pull(buf+offset, buflen-offset, val, &val->iface,
3383 size_t ctdb_transdb_len(struct ctdb_transdb *in)
3385 return ctdb_uint32_len(&in->db_id) +
3386 ctdb_uint32_len(&in->tid);
3389 void ctdb_transdb_push(struct ctdb_transdb *in, uint8_t *buf, size_t *npush)
3391 size_t offset = 0, np;
3393 ctdb_uint32_push(&in->db_id, buf+offset, &np);
3396 ctdb_uint32_push(&in->tid, buf+offset, &np);
3402 int ctdb_transdb_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
3403 struct ctdb_transdb **out, size_t *npull)
3405 struct ctdb_transdb *val;
3406 size_t offset = 0, np;
3409 val = talloc(mem_ctx, struct ctdb_transdb);
3414 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
3420 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->tid, &np);
3435 size_t ctdb_uptime_len(struct ctdb_uptime *in)
3437 return ctdb_timeval_len(&in->current_time) +
3438 ctdb_timeval_len(&in->ctdbd_start_time) +
3439 ctdb_timeval_len(&in->last_recovery_started) +
3440 ctdb_timeval_len(&in->last_recovery_finished);
3443 void ctdb_uptime_push(struct ctdb_uptime *in, uint8_t *buf, size_t *npush)
3445 size_t offset = 0, np;
3447 ctdb_timeval_push(&in->current_time, buf+offset, &np);
3450 ctdb_timeval_push(&in->ctdbd_start_time, buf+offset, &np);
3453 ctdb_timeval_push(&in->last_recovery_started, buf+offset, &np);
3456 ctdb_timeval_push(&in->last_recovery_finished, buf+offset, &np);
3462 int ctdb_uptime_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
3463 struct ctdb_uptime **out, size_t *npull)
3465 struct ctdb_uptime *val;
3466 size_t offset = 0, np;
3469 val = talloc(mem_ctx, struct ctdb_uptime);
3474 ret = ctdb_timeval_pull(buf+offset, buflen-offset, &val->current_time,
3481 ret = ctdb_timeval_pull(buf+offset, buflen-offset,
3482 &val->ctdbd_start_time, &np);
3488 ret = ctdb_timeval_pull(buf+offset, buflen-offset,
3489 &val->last_recovery_started, &np);
3495 ret = ctdb_timeval_pull(buf+offset, buflen-offset,
3496 &val->last_recovery_finished, &np);
3511 size_t ctdb_public_ip_len(struct ctdb_public_ip *in)
3513 return ctdb_uint32_len(&in->pnn) +
3514 ctdb_sock_addr_len(&in->addr);
3517 void ctdb_public_ip_push(struct ctdb_public_ip *in, uint8_t *buf,
3520 size_t offset = 0, np;
3522 ctdb_uint32_push(&in->pnn, buf+offset, &np);
3525 ctdb_sock_addr_push(&in->addr, buf+offset, &np);
3531 static int ctdb_public_ip_pull_elems(uint8_t *buf, size_t buflen,
3532 TALLOC_CTX *mem_ctx,
3533 struct ctdb_public_ip *out, size_t *npull)
3535 size_t offset = 0, np;
3538 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->pnn, &np);
3544 ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset, mem_ctx,
3555 int ctdb_public_ip_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
3556 struct ctdb_public_ip **out, size_t *npull)
3558 struct ctdb_public_ip *val;
3562 val = talloc(mem_ctx, struct ctdb_public_ip);
3567 ret = ctdb_public_ip_pull_elems(buf, buflen, val, val, &np);
3578 size_t ctdb_public_ip_list_len(struct ctdb_public_ip_list *in)
3582 len = ctdb_uint32_len(&in->num);
3584 len += in->num * ctdb_public_ip_len(&in->ip[0]);
3590 void ctdb_public_ip_list_push(struct ctdb_public_ip_list *in, uint8_t *buf,
3593 size_t offset = 0, np;
3596 ctdb_uint32_push(&in->num, buf+offset, &np);
3599 for (i=0; i<in->num; i++) {
3600 ctdb_public_ip_push(&in->ip[i], buf+offset, &np);
3607 int ctdb_public_ip_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
3608 struct ctdb_public_ip_list **out, size_t *npull)
3610 struct ctdb_public_ip_list *val;
3611 size_t offset = 0, np;
3615 val = talloc(mem_ctx, struct ctdb_public_ip_list);
3620 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
3626 if (val->num == 0) {
3631 val->ip = talloc_array(val, struct ctdb_public_ip, val->num);
3632 if (val->ip == NULL) {
3637 for (i=0; i<val->num; i++) {
3638 ret = ctdb_public_ip_pull_elems(buf+offset, buflen-offset,
3639 val->ip, &val->ip[i], &np);
3656 size_t ctdb_node_and_flags_len(struct ctdb_node_and_flags *in)
3658 return ctdb_uint32_len(&in->pnn) +
3659 ctdb_uint32_len(&in->flags) +
3660 ctdb_sock_addr_len(&in->addr);
3663 void ctdb_node_and_flags_push(struct ctdb_node_and_flags *in, uint8_t *buf,
3666 size_t offset = 0, np;
3668 ctdb_uint32_push(&in->pnn, buf+offset, &np);
3671 ctdb_uint32_push(&in->flags, buf+offset, &np);
3674 ctdb_sock_addr_push(&in->addr, buf+offset, &np);
3680 static int ctdb_node_and_flags_pull_elems(uint8_t *buf, size_t buflen,
3681 TALLOC_CTX *mem_ctx,
3682 struct ctdb_node_and_flags *out,
3685 size_t offset = 0, np;
3688 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->pnn, &np);
3694 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->flags, &np);
3700 ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset, mem_ctx,
3711 int ctdb_node_and_flags_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
3712 struct ctdb_node_and_flags **out, size_t *npull)
3714 struct ctdb_node_and_flags *val;
3718 val = talloc(mem_ctx, struct ctdb_node_and_flags);
3723 ret = ctdb_node_and_flags_pull_elems(buf, buflen, val, val, &np);
3734 size_t ctdb_node_map_len(struct ctdb_node_map *in)
3738 len = ctdb_uint32_len(&in->num);
3740 len += in->num * ctdb_node_and_flags_len(&in->node[0]);
3746 void ctdb_node_map_push(struct ctdb_node_map *in, uint8_t *buf, size_t *npush)
3748 size_t offset = 0, np;
3751 ctdb_uint32_push(&in->num, buf+offset, &np);
3754 for (i=0; i<in->num; i++) {
3755 ctdb_node_and_flags_push(&in->node[i], buf+offset, &np);
3762 int ctdb_node_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
3763 struct ctdb_node_map **out, size_t *npull)
3765 struct ctdb_node_map *val;
3766 size_t offset = 0, np;
3770 val = talloc(mem_ctx, struct ctdb_node_map);
3775 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
3781 if (val->num == 0) {
3786 val->node = talloc_array(val, struct ctdb_node_and_flags, val->num);
3787 if (val->node == NULL) {
3792 for (i=0; i<val->num; i++) {
3793 ret = ctdb_node_and_flags_pull_elems(buf+offset,
3795 val->node, &val->node[i],
3813 size_t ctdb_script_len(struct ctdb_script *in)
3815 return ctdb_chararray_len(in->name, MAX_SCRIPT_NAME+1) +
3816 ctdb_timeval_len(&in->start) +
3817 ctdb_timeval_len(&in->finished) +
3818 ctdb_int32_len(&in->status) +
3819 ctdb_chararray_len(in->output, MAX_SCRIPT_OUTPUT+1) +
3820 ctdb_padding_len(4);
3823 void ctdb_script_push(struct ctdb_script *in, uint8_t *buf, size_t *npush)
3825 size_t offset = 0, np;
3827 ctdb_chararray_push(in->name, MAX_SCRIPT_NAME+1, buf+offset, &np);
3830 ctdb_timeval_push(&in->start, buf+offset, &np);
3833 ctdb_timeval_push(&in->finished, buf+offset, &np);
3836 ctdb_int32_push(&in->status, buf+offset, &np);
3839 ctdb_chararray_push(in->output, MAX_SCRIPT_OUTPUT+1, buf+offset, &np);
3842 ctdb_padding_push(4, buf+offset, &np);
3848 static int ctdb_script_pull_elems(uint8_t *buf, size_t buflen,
3849 TALLOC_CTX *mem_ctx,
3850 struct ctdb_script *out, size_t *npull)
3852 size_t offset = 0, np;
3855 ret = ctdb_chararray_pull(buf+offset, buflen-offset,
3856 out->name, MAX_SCRIPT_NAME+1, &np);
3862 ret = ctdb_timeval_pull(buf+offset, buflen-offset, &out->start, &np);
3868 ret = ctdb_timeval_pull(buf+offset, buflen-offset, &out->finished,
3875 ret = ctdb_int32_pull(buf+offset, buflen-offset, &out->status, &np);
3881 ret = ctdb_chararray_pull(buf+offset, buflen-offset,
3882 out->output, MAX_SCRIPT_OUTPUT+1, &np);
3888 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
3898 int ctdb_script_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
3899 struct ctdb_script **out, size_t *npull)
3901 struct ctdb_script *val;
3905 val = talloc(mem_ctx, struct ctdb_script);
3910 ret = ctdb_script_pull_elems(buf, buflen, val, val, &np);
3921 size_t ctdb_script_list_len(struct ctdb_script_list *in)
3929 len = ctdb_uint32_len(&in->num_scripts) + ctdb_padding_len(4);
3930 if (in->num_scripts > 0) {
3931 len += in->num_scripts * ctdb_script_len(&in->script[0]);
3937 void ctdb_script_list_push(struct ctdb_script_list *in, uint8_t *buf,
3940 size_t offset = 0, np;
3948 ctdb_uint32_push(&in->num_scripts, buf+offset, &np);
3951 ctdb_padding_push(4, buf+offset, &np);
3954 for (i=0; i<in->num_scripts; i++) {
3955 ctdb_script_push(&in->script[i], buf+offset, &np);
3962 int ctdb_script_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
3963 struct ctdb_script_list **out, size_t *npull)
3965 struct ctdb_script_list *val;
3966 size_t offset = 0, np;
3970 /* If event scripts have never been run, the result will be NULL */
3976 val = talloc(mem_ctx, struct ctdb_script_list);
3981 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num_scripts,
3988 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
3994 if (val->num_scripts == 0) {
3999 val->script = talloc_array(val, struct ctdb_script, val->num_scripts);
4000 if (val->script == NULL) {
4005 for (i=0; i<val->num_scripts; i++) {
4006 ret = ctdb_script_pull_elems(buf+offset, buflen-offset,
4007 val, &val->script[i], &np);
4024 size_t ctdb_ban_state_len(struct ctdb_ban_state *in)
4026 return ctdb_uint32_len(&in->pnn) +
4027 ctdb_uint32_len(&in->time);
4030 void ctdb_ban_state_push(struct ctdb_ban_state *in, uint8_t *buf,
4033 size_t offset = 0, np;
4035 ctdb_uint32_push(&in->pnn, buf+offset, &np);
4038 ctdb_uint32_push(&in->time, buf+offset, &np);
4044 int ctdb_ban_state_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
4045 struct ctdb_ban_state **out, size_t *npull)
4047 struct ctdb_ban_state *val;
4048 size_t offset = 0, np;
4051 val = talloc(mem_ctx, struct ctdb_ban_state);
4056 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
4062 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->time, &np);
4077 size_t ctdb_notify_data_len(struct ctdb_notify_data *in)
4079 return ctdb_uint64_len(&in->srvid) +
4080 ctdb_tdb_datan_len(&in->data);
4083 void ctdb_notify_data_push(struct ctdb_notify_data *in, uint8_t *buf,
4086 size_t offset = 0, np;
4088 ctdb_uint64_push(&in->srvid, buf+offset, &np);
4091 ctdb_tdb_datan_push(&in->data, buf+offset, &np);
4097 int ctdb_notify_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
4098 struct ctdb_notify_data **out, size_t *npull)
4100 struct ctdb_notify_data *val;
4101 size_t offset = 0, np;
4104 val = talloc(mem_ctx, struct ctdb_notify_data);
4109 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
4115 ret = ctdb_tdb_datan_pull(buf+offset, buflen-offset, val, &val->data,
4131 size_t ctdb_iface_len(struct ctdb_iface *in)
4133 return ctdb_chararray_len(in->name, CTDB_IFACE_SIZE+2) +
4134 ctdb_uint16_len(&in->link_state) +
4135 ctdb_uint32_len(&in->references);
4138 void ctdb_iface_push(struct ctdb_iface *in, uint8_t *buf, size_t *npush)
4140 size_t offset = 0, np;
4142 ctdb_chararray_push(in->name, CTDB_IFACE_SIZE+2, buf+offset, &np);
4145 ctdb_uint16_push(&in->link_state, buf+offset, &np);
4148 ctdb_uint32_push(&in->references, buf+offset, &np);
4154 static int ctdb_iface_pull_elems(uint8_t *buf, size_t buflen,
4155 TALLOC_CTX *mem_ctx,
4156 struct ctdb_iface *out, size_t *npull)
4158 size_t offset = 0, np;
4161 ret = ctdb_chararray_pull(buf+offset, buflen-offset,
4162 out->name, CTDB_IFACE_SIZE+2, &np);
4168 ret = ctdb_uint16_pull(buf+offset, buflen-offset, &out->link_state,
4175 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->references,
4186 int ctdb_iface_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
4187 struct ctdb_iface **out, size_t *npull)
4189 struct ctdb_iface *val;
4193 val = talloc(mem_ctx, struct ctdb_iface);
4198 ret = ctdb_iface_pull_elems(buf, buflen, val, val, &np);
4209 size_t ctdb_iface_list_len(struct ctdb_iface_list *in)
4213 len = ctdb_uint32_len(&in->num);
4215 len += in->num * ctdb_iface_len(&in->iface[0]);
4221 void ctdb_iface_list_push(struct ctdb_iface_list *in, uint8_t *buf,
4224 size_t offset = 0, np;
4227 ctdb_uint32_push(&in->num, buf+offset, &np);
4230 for (i=0; i<in->num; i++) {
4231 ctdb_iface_push(&in->iface[i], buf+offset, &np);
4238 int ctdb_iface_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
4239 struct ctdb_iface_list **out, size_t *npull)
4241 struct ctdb_iface_list *val;
4242 size_t offset = 0, np;
4246 val = talloc(mem_ctx, struct ctdb_iface_list);
4251 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
4257 if (val->num == 0) {
4262 val->iface = talloc_array(val, struct ctdb_iface, val->num);
4263 if (val->iface == NULL) {
4268 for (i=0; i<val->num; i++) {
4269 ret = ctdb_iface_pull_elems(buf+offset, buflen-offset,
4270 val, &val->iface[i], &np);
4287 size_t ctdb_public_ip_info_len(struct ctdb_public_ip_info *in)
4289 return ctdb_public_ip_len(&in->ip) +
4290 ctdb_uint32_len(&in->active_idx) +
4291 ctdb_iface_list_len(in->ifaces);
4294 void ctdb_public_ip_info_push(struct ctdb_public_ip_info *in, uint8_t *buf,
4297 size_t offset = 0, np;
4299 ctdb_public_ip_push(&in->ip, buf+offset, &np);
4302 ctdb_uint32_push(&in->active_idx, buf+offset, &np);
4305 ctdb_iface_list_push(in->ifaces, buf+offset, &np);
4311 int ctdb_public_ip_info_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
4312 struct ctdb_public_ip_info **out, size_t *npull)
4314 struct ctdb_public_ip_info *val;
4315 size_t offset = 0, np;
4318 val = talloc(mem_ctx, struct ctdb_public_ip_info);
4323 ret = ctdb_public_ip_pull_elems(buf+offset, buflen-offset, val,
4330 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->active_idx,
4337 ret = ctdb_iface_list_pull(buf+offset, buflen-offset, val,
4353 size_t ctdb_key_data_len(struct ctdb_key_data *in)
4355 return ctdb_uint32_len(&in->db_id) +
4356 ctdb_padding_len(4) +
4357 ctdb_ltdb_header_len(&in->header) +
4358 ctdb_tdb_datan_len(&in->key);
4361 void ctdb_key_data_push(struct ctdb_key_data *in, uint8_t *buf, size_t *npush)
4363 size_t offset = 0, np;
4365 ctdb_uint32_push(&in->db_id, buf+offset, &np);
4368 ctdb_padding_push(4, buf+offset, &np);
4371 ctdb_ltdb_header_push(&in->header, buf+offset, &np);
4374 ctdb_tdb_datan_push(&in->key, buf+offset, &np);
4380 int ctdb_key_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
4381 struct ctdb_key_data **out, size_t *npull)
4383 struct ctdb_key_data *val;
4384 size_t offset = 0, np;
4387 val = talloc(mem_ctx, struct ctdb_key_data);
4392 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
4398 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
4404 ret = ctdb_ltdb_header_pull(buf+offset, buflen-offset, &val->header,
4411 ret = ctdb_tdb_datan_pull(buf+offset, buflen-offset, val, &val->key,
4427 /* In the tdb_data structure marshalling, we are only interested in dsize.
4428 * The dptr value is ignored. The actual tdb_data blob is stored separately.
4430 * This is only required for ctdb_db_statistics and will be dropped in future.
4433 static size_t tdb_data_struct_len(TDB_DATA *data)
4435 return sizeof(void *) + sizeof(size_t);
4438 static void tdb_data_struct_push(TDB_DATA *data, uint8_t *buf, size_t *npush)
4442 memcpy(buf+offset, &data->dptr, sizeof(void *));
4443 offset += sizeof(void *);
4445 memcpy(buf+offset, &data->dsize, sizeof(size_t));
4446 offset += sizeof(size_t);
4451 static int tdb_data_struct_pull(uint8_t *buf, size_t buflen, TDB_DATA *data,
4457 if (buflen-offset < sizeof(void *)) {
4461 memcpy(&ptr, buf+offset, sizeof(void *));
4462 offset += sizeof(void *);
4465 if (buflen-offset < sizeof(size_t)) {
4469 memcpy(&data->dsize, buf+offset, sizeof(size_t));
4470 offset += sizeof(size_t);
4476 size_t ctdb_db_statistics_len(struct ctdb_db_statistics *in)
4478 TDB_DATA data = { 0 };
4483 len = ctdb_uint32_len(&in->locks.num_calls) +
4484 ctdb_uint32_len(&in->locks.num_current) +
4485 ctdb_uint32_len(&in->locks.num_pending) +
4486 ctdb_uint32_len(&in->locks.num_failed) +
4487 ctdb_latency_counter_len(&in->locks.latency) +
4489 ctdb_uint32_len(&in->locks.buckets[0]) +
4490 ctdb_latency_counter_len(&in->vacuum.latency) +
4491 ctdb_uint32_len(&in->db_ro_delegations) +
4492 ctdb_uint32_len(&in->db_ro_revokes) +
4494 ctdb_uint32_len(&in->hop_count_bucket[0]) +
4495 ctdb_uint32_len(&in->num_hot_keys) +
4496 ctdb_padding_len(4) +
4498 (ctdb_uint32_len(&u32) + ctdb_padding_len(4) +
4499 tdb_data_struct_len(&data));
4501 for (i=0; i<MAX_HOT_KEYS; i++) {
4502 len += ctdb_tdb_data_len(&in->hot_keys[i].key);
4508 void ctdb_db_statistics_push(struct ctdb_db_statistics *in, uint8_t *buf,
4511 size_t offset = 0, np;
4512 uint32_t num_hot_keys;
4515 ctdb_uint32_push(&in->locks.num_calls, buf+offset, &np);
4518 ctdb_uint32_push(&in->locks.num_current, buf+offset, &np);
4521 ctdb_uint32_push(&in->locks.num_pending, buf+offset, &np);
4524 ctdb_uint32_push(&in->locks.num_failed, buf+offset, &np);
4527 ctdb_latency_counter_push(&in->locks.latency, buf+offset, &np);
4530 for (i=0; i<MAX_COUNT_BUCKETS; i++) {
4531 ctdb_uint32_push(&in->locks.buckets[i], buf+offset, &np);
4535 ctdb_latency_counter_push(&in->vacuum.latency, buf+offset, &np);
4538 ctdb_uint32_push(&in->db_ro_delegations, buf+offset, &np);
4541 ctdb_uint32_push(&in->db_ro_revokes, buf+offset, &np);
4544 for (i=0; i<MAX_COUNT_BUCKETS; i++) {
4545 ctdb_uint32_push(&in->hop_count_bucket[i], buf+offset, &np);
4549 num_hot_keys = MAX_HOT_KEYS;
4550 ctdb_uint32_push(&num_hot_keys, buf+offset, &np);
4553 ctdb_padding_push(4, buf+offset, &np);
4556 for (i=0; i<MAX_HOT_KEYS; i++) {
4557 ctdb_uint32_push(&in->hot_keys[i].count, buf+offset, &np);
4560 ctdb_padding_push(4, buf+offset, &np);
4563 tdb_data_struct_push(&in->hot_keys[i].key, buf+offset, &np);
4567 for (i=0; i<MAX_HOT_KEYS; i++) {
4568 ctdb_tdb_data_push(&in->hot_keys[i].key, buf+offset, &np);
4575 static int ctdb_db_statistics_pull_elems(uint8_t *buf, size_t buflen,
4576 TALLOC_CTX *mem_ctx,
4577 struct ctdb_db_statistics *out,
4580 size_t offset = 0, np;
4583 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
4584 &out->locks.num_calls, &np);
4590 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
4591 &out->locks.num_current, &np);
4597 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
4598 &out->locks.num_pending, &np);
4604 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
4605 &out->locks.num_failed, &np);
4611 ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
4612 &out->locks.latency, &np);
4618 for (i=0; i<MAX_COUNT_BUCKETS; i++) {
4619 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
4620 &out->locks.buckets[i], &np);
4627 ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
4628 &out->vacuum.latency, &np);
4634 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
4635 &out->db_ro_delegations, &np);
4641 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
4642 &out->db_ro_revokes, &np);
4648 for (i=0; i<MAX_COUNT_BUCKETS; i++) {
4649 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
4650 &out->hop_count_bucket[i], &np);
4657 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
4658 &out->num_hot_keys, &np);
4664 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
4670 for (i=0; i<MAX_HOT_KEYS; i++) {
4671 ret = ctdb_uint32_pull(buf+offset, buflen-offset,
4672 &out->hot_keys[i].count, &np);
4678 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
4684 ret = tdb_data_struct_pull(buf+offset, buflen-offset,
4685 &out->hot_keys[i].key, &np);
4692 for (i=0; i<MAX_HOT_KEYS; i++) {
4693 ret = ctdb_tdb_data_pull(buf+offset,
4694 out->hot_keys[i].key.dsize,
4695 out, &out->hot_keys[i].key, &np);
4706 int ctdb_db_statistics_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
4707 struct ctdb_db_statistics **out, size_t *npull)
4709 struct ctdb_db_statistics *val;
4713 val = talloc(mem_ctx, struct ctdb_db_statistics);
4718 ret = ctdb_db_statistics_pull_elems(buf, buflen, val, val, &np);
4729 size_t ctdb_pid_srvid_len(struct ctdb_pid_srvid *in)
4731 return ctdb_pid_len(&in->pid) +
4732 ctdb_uint64_len(&in->srvid);
4735 void ctdb_pid_srvid_push(struct ctdb_pid_srvid *in, uint8_t *buf,
4738 size_t offset = 0, np;
4740 ctdb_pid_push(&in->pid, buf+offset, &np);
4743 ctdb_uint64_push(&in->srvid, buf+offset, &np);
4749 int ctdb_pid_srvid_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
4750 struct ctdb_pid_srvid **out, size_t *npull)
4752 struct ctdb_pid_srvid *val;
4753 size_t offset = 0, np;
4756 val = talloc(mem_ctx, struct ctdb_pid_srvid);
4761 ret = ctdb_pid_pull(buf+offset, buflen-offset, &val->pid, &np);
4767 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
4782 size_t ctdb_election_message_len(struct ctdb_election_message *in)
4784 return ctdb_uint32_len(&in->num_connected) +
4785 ctdb_padding_len(4) +
4786 ctdb_timeval_len(&in->priority_time) +
4787 ctdb_uint32_len(&in->pnn) +
4788 ctdb_uint32_len(&in->node_flags);
4791 void ctdb_election_message_push(struct ctdb_election_message *in,
4792 uint8_t *buf, size_t *npush)
4794 size_t offset = 0, np;
4796 ctdb_uint32_push(&in->num_connected, buf+offset, &np);
4799 ctdb_padding_push(4, buf+offset, &np);
4802 ctdb_timeval_push(&in->priority_time, buf+offset, &np);
4805 ctdb_uint32_push(&in->pnn, buf+offset, &np);
4808 ctdb_uint32_push(&in->node_flags, buf+offset, &np);
4814 int ctdb_election_message_pull(uint8_t *buf, size_t buflen,
4815 TALLOC_CTX *mem_ctx,
4816 struct ctdb_election_message **out,
4819 struct ctdb_election_message *val;
4820 size_t offset = 0, np;
4823 val = talloc(mem_ctx, struct ctdb_election_message);
4828 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num_connected,
4835 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
4841 ret = ctdb_timeval_pull(buf+offset, buflen-offset,
4842 &val->priority_time, &np);
4848 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
4854 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->node_flags,
4870 size_t ctdb_srvid_message_len(struct ctdb_srvid_message *in)
4872 return ctdb_uint32_len(&in->pnn) +
4873 ctdb_padding_len(4) +
4874 ctdb_uint64_len(&in->srvid);
4877 void ctdb_srvid_message_push(struct ctdb_srvid_message *in, uint8_t *buf,
4880 size_t offset = 0, np;
4882 ctdb_uint32_push(&in->pnn, buf+offset, &np);
4885 ctdb_padding_push(4, buf+offset, &np);
4888 ctdb_uint64_push(&in->srvid, buf+offset, &np);
4894 int ctdb_srvid_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
4895 struct ctdb_srvid_message **out, size_t *npull)
4897 struct ctdb_srvid_message *val;
4898 size_t offset = 0, np;
4901 val = talloc(mem_ctx, struct ctdb_srvid_message);
4906 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
4912 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
4918 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
4933 size_t ctdb_disable_message_len(struct ctdb_disable_message *in)
4935 return ctdb_uint32_len(&in->pnn) +
4936 ctdb_padding_len(4) +
4937 ctdb_uint64_len(&in->srvid) +
4938 ctdb_uint32_len(&in->timeout) +
4939 ctdb_padding_len(4);
4942 void ctdb_disable_message_push(struct ctdb_disable_message *in, uint8_t *buf,
4945 size_t offset = 0, np;
4947 ctdb_uint32_push(&in->pnn, buf+offset, &np);
4950 ctdb_padding_push(4, buf+offset, &np);
4953 ctdb_uint64_push(&in->srvid, buf+offset, &np);
4956 ctdb_uint32_push(&in->timeout, buf+offset, &np);
4959 ctdb_padding_push(4, buf+offset, &np);
4965 int ctdb_disable_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
4966 struct ctdb_disable_message **out,
4969 struct ctdb_disable_message *val;
4970 size_t offset = 0, np;
4973 val = talloc(mem_ctx, struct ctdb_disable_message);
4978 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
4984 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
4990 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
4996 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->timeout, &np);
5002 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
5017 size_t ctdb_server_id_len(struct ctdb_server_id *in)
5019 return ctdb_uint64_len(&in->pid) +
5020 ctdb_uint32_len(&in->task_id) +
5021 ctdb_uint32_len(&in->vnn) +
5022 ctdb_uint64_len(&in->unique_id);
5025 void ctdb_server_id_push(struct ctdb_server_id *in, uint8_t *buf,
5028 size_t offset = 0, np;
5030 ctdb_uint64_push(&in->pid, buf+offset, &np);
5033 ctdb_uint32_push(&in->task_id, buf+offset, &np);
5036 ctdb_uint32_push(&in->vnn, buf+offset, &np);
5039 ctdb_uint64_push(&in->unique_id, buf+offset, &np);
5045 int ctdb_server_id_pull(uint8_t *buf, size_t buflen,
5046 struct ctdb_server_id *out, size_t *npull)
5048 size_t offset = 0, np;
5051 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &out->pid, &np);
5057 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->task_id, &np);
5063 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->vnn, &np);
5069 ret = ctdb_uint64_pull(buf+offset, buflen-offset, &out->unique_id,
5080 size_t ctdb_g_lock_len(struct ctdb_g_lock *in)
5082 return ctdb_uint32_len(&in->type) +
5083 ctdb_padding_len(4) +
5084 ctdb_server_id_len(&in->sid);
5087 void ctdb_g_lock_push(struct ctdb_g_lock *in, uint8_t *buf, size_t *npush)
5089 size_t offset = 0, np;
5093 ctdb_uint32_push(&type, buf+offset, &np);
5096 ctdb_padding_push(4, buf+offset, &np);
5099 ctdb_server_id_push(&in->sid, buf+offset, &np);
5105 int ctdb_g_lock_pull(uint8_t *buf, size_t buflen, struct ctdb_g_lock *out,
5108 size_t offset = 0, np;
5112 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &type, &np);
5119 out->type = CTDB_G_LOCK_READ;
5120 } else if (type == 1) {
5121 out->type = CTDB_G_LOCK_WRITE;
5126 ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
5132 ret = ctdb_server_id_pull(buf+offset, buflen-offset, &out->sid, &np);
5142 size_t ctdb_g_lock_list_len(struct ctdb_g_lock_list *in)
5147 len += in->num * ctdb_g_lock_len(&in->lock[0]);
5153 void ctdb_g_lock_list_push(struct ctdb_g_lock_list *in, uint8_t *buf,
5156 size_t offset = 0, np;
5159 for (i=0; i<in->num; i++) {
5160 ctdb_g_lock_push(&in->lock[i], buf+offset, &np);
5167 int ctdb_g_lock_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
5168 struct ctdb_g_lock_list **out, size_t *npull)
5170 struct ctdb_g_lock_list *val;
5171 struct ctdb_g_lock lock = { 0 };
5172 size_t offset = 0, np;
5176 val = talloc(mem_ctx, struct ctdb_g_lock_list);
5187 val->num = buflen / ctdb_g_lock_len(&lock);
5189 val->lock = talloc_array(val, struct ctdb_g_lock, val->num);
5190 if (val->lock == NULL) {
5195 for (i=0; i<val->num; i++) {
5196 ret = ctdb_g_lock_pull(buf+offset, buflen-offset,
5197 &val->lock[i], &np);