Fix spelling mistakes
[samba.git] / ctdb / protocol / protocol_control.c
1 /*
2    CTDB protocol marshalling
3
4    Copyright (C) Amitay Isaacs  2015
5
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.
10
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.
15
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/>.
18 */
19
20 #include "replace.h"
21 #include "system/network.h"
22
23 #include <talloc.h>
24 #include <tdb.h>
25
26 #include "protocol.h"
27 #include "protocol_api.h"
28 #include "protocol_private.h"
29
30 static size_t ctdb_req_control_data_len(struct ctdb_req_control_data *cd)
31 {
32         size_t len = 0;
33         uint32_t u32;
34
35         if (cd == NULL) {
36                 return 0;
37         }
38
39         switch (cd->opcode) {
40         case CTDB_CONTROL_PROCESS_EXISTS:
41                 len = ctdb_pid_len(&cd->data.pid);
42                 break;
43
44         case CTDB_CONTROL_STATISTICS:
45                 break;
46
47         case CTDB_CONTROL_PING:
48                 break;
49
50         case CTDB_CONTROL_GETDBPATH:
51                 len = ctdb_uint32_len(&cd->data.db_id);
52                 break;
53
54         case CTDB_CONTROL_GETVNNMAP:
55                 break;
56
57         case CTDB_CONTROL_SETVNNMAP:
58                 len = ctdb_vnn_map_len(cd->data.vnnmap);
59                 break;
60
61         case CTDB_CONTROL_GET_DEBUG:
62                 break;
63
64         case CTDB_CONTROL_SET_DEBUG:
65                 len = ctdb_uint32_len(&cd->data.loglevel);
66                 break;
67
68         case CTDB_CONTROL_GET_DBMAP:
69                 break;
70
71         case CTDB_CONTROL_PULL_DB:
72                 len = ctdb_pulldb_len(cd->data.pulldb);
73                 break;
74
75         case CTDB_CONTROL_PUSH_DB:
76                 len = ctdb_rec_buffer_len(cd->data.recbuf);
77                 break;
78
79         case CTDB_CONTROL_GET_RECMODE:
80                 break;
81
82         case CTDB_CONTROL_SET_RECMODE:
83                 len = ctdb_uint32_len(&cd->data.recmode);
84                 break;
85
86         case CTDB_CONTROL_STATISTICS_RESET:
87                 break;
88
89         case CTDB_CONTROL_DB_ATTACH:
90                 len = ctdb_string_len(&cd->data.db_name);
91                 break;
92
93         case CTDB_CONTROL_SET_CALL:
94                 break;
95
96         case CTDB_CONTROL_TRAVERSE_START:
97                 len = ctdb_traverse_start_len(cd->data.traverse_start);
98                 break;
99
100         case CTDB_CONTROL_TRAVERSE_ALL:
101                 len = ctdb_traverse_all_len(cd->data.traverse_all);
102                 break;
103
104         case CTDB_CONTROL_TRAVERSE_DATA:
105                 len = ctdb_rec_data_len(cd->data.rec_data);
106                 break;
107
108         case CTDB_CONTROL_REGISTER_SRVID:
109                 break;
110
111         case CTDB_CONTROL_DEREGISTER_SRVID:
112                 break;
113
114         case CTDB_CONTROL_GET_DBNAME:
115                 len = ctdb_uint32_len(&cd->data.db_id);
116                 break;
117
118         case CTDB_CONTROL_ENABLE_SEQNUM:
119                 len = ctdb_uint32_len(&cd->data.db_id);
120                 break;
121
122         case CTDB_CONTROL_UPDATE_SEQNUM:
123                 len = ctdb_uint32_len(&cd->data.db_id);
124                 break;
125
126         case CTDB_CONTROL_DUMP_MEMORY:
127                 break;
128
129         case CTDB_CONTROL_GET_PID:
130                 break;
131
132         case CTDB_CONTROL_GET_RECMASTER:
133                 break;
134
135         case CTDB_CONTROL_SET_RECMASTER:
136                 len = ctdb_uint32_len(&cd->data.recmaster);
137                 break;
138
139         case CTDB_CONTROL_FREEZE:
140                 break;
141
142         case CTDB_CONTROL_GET_PNN:
143                 break;
144
145         case CTDB_CONTROL_SHUTDOWN:
146                 break;
147
148         case CTDB_CONTROL_GET_MONMODE:
149                 break;
150
151         case CTDB_CONTROL_TCP_CLIENT:
152                 len = ctdb_connection_len(cd->data.conn);
153                 break;
154
155         case CTDB_CONTROL_TCP_ADD:
156                 len = ctdb_connection_len(cd->data.conn);
157                 break;
158
159         case CTDB_CONTROL_TCP_REMOVE:
160                 len = ctdb_connection_len(cd->data.conn);
161                 break;
162
163         case CTDB_CONTROL_STARTUP:
164                 break;
165
166         case CTDB_CONTROL_SET_TUNABLE:
167                 len = ctdb_tunable_len(cd->data.tunable);
168                 break;
169
170         case CTDB_CONTROL_GET_TUNABLE:
171                 len = ctdb_stringn_len(&cd->data.tun_var);
172                 break;
173
174         case CTDB_CONTROL_LIST_TUNABLES:
175                 break;
176
177         case CTDB_CONTROL_MODIFY_FLAGS:
178                 len = ctdb_node_flag_change_len(cd->data.flag_change);
179                 break;
180
181         case CTDB_CONTROL_GET_ALL_TUNABLES:
182                 break;
183
184         case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
185                 len = ctdb_sock_addr_len(cd->data.addr);
186                 break;
187
188         case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
189                 len = ctdb_tickle_list_len(cd->data.tickles);
190                 break;
191
192         case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
193                 len = ctdb_string_len(&cd->data.db_name);
194                 break;
195
196         case CTDB_CONTROL_UPDATE_RECORD:
197                 len = ctdb_rec_buffer_len(cd->data.recbuf);
198                 break;
199
200         case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
201                 len = ctdb_addr_info_len(cd->data.addr_info);
202                 break;
203
204         case CTDB_CONTROL_WIPE_DATABASE:
205                 len = ctdb_transdb_len(cd->data.transdb);
206                 break;
207
208         case CTDB_CONTROL_UPTIME:
209                 break;
210
211         case CTDB_CONTROL_START_RECOVERY:
212                 break;
213
214         case CTDB_CONTROL_END_RECOVERY:
215                 break;
216
217         case CTDB_CONTROL_RELOAD_NODES_FILE:
218                 break;
219
220         case CTDB_CONTROL_TRY_DELETE_RECORDS:
221                 len = ctdb_rec_buffer_len(cd->data.recbuf);
222                 break;
223
224         case CTDB_CONTROL_ENABLE_MONITOR:
225                 break;
226
227         case CTDB_CONTROL_DISABLE_MONITOR:
228                 break;
229
230         case CTDB_CONTROL_ADD_PUBLIC_IP:
231                 len = ctdb_addr_info_len(cd->data.addr_info);
232                 break;
233
234         case CTDB_CONTROL_DEL_PUBLIC_IP:
235                 len = ctdb_addr_info_len(cd->data.addr_info);
236                 break;
237
238         case CTDB_CONTROL_GET_CAPABILITIES:
239                 break;
240
241         case CTDB_CONTROL_RECD_PING:
242                 break;
243
244         case CTDB_CONTROL_RELEASE_IP:
245                 len = ctdb_public_ip_len(cd->data.pubip);
246                 break;
247
248         case CTDB_CONTROL_TAKEOVER_IP:
249                 len = ctdb_public_ip_len(cd->data.pubip);
250                 break;
251
252         case CTDB_CONTROL_GET_PUBLIC_IPS:
253                 break;
254
255         case CTDB_CONTROL_GET_NODEMAP:
256                 break;
257
258         case CTDB_CONTROL_TRAVERSE_KILL:
259                 len = ctdb_traverse_start_len(cd->data.traverse_start);
260                 break;
261
262         case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
263                 len = ctdb_double_len(&cd->data.reclock_latency);
264                 break;
265
266         case CTDB_CONTROL_GET_RECLOCK_FILE:
267                 break;
268
269         case CTDB_CONTROL_STOP_NODE:
270                 break;
271
272         case CTDB_CONTROL_CONTINUE_NODE:
273                 break;
274
275         case CTDB_CONTROL_SET_LMASTERROLE:
276                 len = ctdb_uint32_len(&cd->data.role);
277                 break;
278
279         case CTDB_CONTROL_SET_RECMASTERROLE:
280                 len = ctdb_uint32_len(&cd->data.role);
281                 break;
282
283         case CTDB_CONTROL_SET_BAN_STATE:
284                 len = ctdb_ban_state_len(cd->data.ban_state);
285                 break;
286
287         case CTDB_CONTROL_GET_BAN_STATE:
288                 break;
289
290         case CTDB_CONTROL_REGISTER_NOTIFY:
291                 len = ctdb_notify_data_len(cd->data.notify);
292                 break;
293
294         case CTDB_CONTROL_DEREGISTER_NOTIFY:
295                 len = ctdb_uint64_len(&cd->data.srvid);
296                 break;
297
298         case CTDB_CONTROL_TRANS3_COMMIT:
299                 len = ctdb_rec_buffer_len(cd->data.recbuf);
300                 break;
301
302         case CTDB_CONTROL_GET_DB_SEQNUM:
303                 u32 = 0;
304                 len = ctdb_uint32_len(&cd->data.db_id) + ctdb_uint32_len(&u32);
305                 break;
306
307         case CTDB_CONTROL_DB_SET_HEALTHY:
308                 len = ctdb_uint32_len(&cd->data.db_id);
309                 break;
310
311         case CTDB_CONTROL_DB_GET_HEALTH:
312                 len = ctdb_uint32_len(&cd->data.db_id);
313                 break;
314
315         case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
316                 len = ctdb_sock_addr_len(cd->data.addr);
317                 break;
318
319         case CTDB_CONTROL_GET_IFACES:
320                 break;
321
322         case CTDB_CONTROL_SET_IFACE_LINK_STATE:
323                 len = ctdb_iface_len(cd->data.iface);
324                 break;
325
326         case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
327                 len = ctdb_connection_len(cd->data.conn);
328                 break;
329
330         case CTDB_CONTROL_GET_STAT_HISTORY:
331                 break;
332
333         case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
334                 len = ctdb_key_data_len(cd->data.key);
335                 break;
336
337         case CTDB_CONTROL_SET_DB_READONLY:
338                 len = ctdb_uint32_len(&cd->data.db_id);
339                 break;
340
341         case CTDB_CONTROL_CHECK_SRVIDS:
342                 break;
343
344         case CTDB_CONTROL_TRAVERSE_START_EXT:
345                 len = ctdb_traverse_start_ext_len(cd->data.traverse_start_ext);
346                 break;
347
348         case CTDB_CONTROL_GET_DB_STATISTICS:
349                 len = ctdb_uint32_len(&cd->data.db_id);
350                 break;
351
352         case CTDB_CONTROL_SET_DB_STICKY:
353                 len = ctdb_uint32_len(&cd->data.db_id);
354                 break;
355
356         case CTDB_CONTROL_RELOAD_PUBLIC_IPS:
357                 break;
358
359         case CTDB_CONTROL_TRAVERSE_ALL_EXT:
360                 len = ctdb_traverse_all_ext_len(cd->data.traverse_all_ext);
361                 break;
362
363         case CTDB_CONTROL_IPREALLOCATED:
364                 break;
365
366         case CTDB_CONTROL_GET_RUNSTATE:
367                 break;
368
369         case CTDB_CONTROL_DB_DETACH:
370                 len = ctdb_uint32_len(&cd->data.db_id);
371                 break;
372
373         case CTDB_CONTROL_GET_NODES_FILE:
374                 break;
375
376         case CTDB_CONTROL_DB_FREEZE:
377                 len = ctdb_uint32_len(&cd->data.db_id);
378                 break;
379
380         case CTDB_CONTROL_DB_THAW:
381                 len = ctdb_uint32_len(&cd->data.db_id);
382                 break;
383
384         case CTDB_CONTROL_DB_TRANSACTION_START:
385                 len = ctdb_transdb_len(cd->data.transdb);
386                 break;
387
388         case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
389                 len = ctdb_transdb_len(cd->data.transdb);
390                 break;
391
392         case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
393                 len = ctdb_uint32_len(&cd->data.db_id);
394                 break;
395
396         case CTDB_CONTROL_DB_PULL:
397                 len = ctdb_pulldb_ext_len(cd->data.pulldb_ext);
398                 break;
399
400         case CTDB_CONTROL_DB_PUSH_START:
401                 len = ctdb_pulldb_ext_len(cd->data.pulldb_ext);
402                 break;
403
404         case CTDB_CONTROL_DB_PUSH_CONFIRM:
405                 len = ctdb_uint32_len(&cd->data.db_id);
406                 break;
407
408         case CTDB_CONTROL_DB_OPEN_FLAGS:
409                 len = ctdb_uint32_len(&cd->data.db_id);
410                 break;
411
412         case CTDB_CONTROL_DB_ATTACH_REPLICATED:
413                 len = ctdb_string_len(&cd->data.db_name);
414                 break;
415
416         case CTDB_CONTROL_CHECK_PID_SRVID:
417                 len = ctdb_pid_srvid_len(cd->data.pid_srvid);
418                 break;
419
420         case CTDB_CONTROL_TUNNEL_REGISTER:
421                 break;
422
423         case CTDB_CONTROL_TUNNEL_DEREGISTER:
424                 break;
425         }
426
427         return len;
428 }
429
430 static void ctdb_req_control_data_push(struct ctdb_req_control_data *cd,
431                                        uint8_t *buf, size_t *npush)
432 {
433         size_t np = 0, offset;
434         uint32_t u32;
435
436         switch (cd->opcode) {
437         case CTDB_CONTROL_PROCESS_EXISTS:
438                 ctdb_pid_push(&cd->data.pid, buf, &np);
439                 break;
440
441         case CTDB_CONTROL_GETDBPATH:
442                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
443                 break;
444
445         case CTDB_CONTROL_SETVNNMAP:
446                 ctdb_vnn_map_push(cd->data.vnnmap, buf, &np);
447                 break;
448
449         case CTDB_CONTROL_SET_DEBUG:
450                 ctdb_uint32_push(&cd->data.loglevel, buf, &np);
451                 break;
452
453         case CTDB_CONTROL_PULL_DB:
454                 ctdb_pulldb_push(cd->data.pulldb, buf, &np);
455                 break;
456
457         case CTDB_CONTROL_PUSH_DB:
458                 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
459                 break;
460
461         case CTDB_CONTROL_SET_RECMODE:
462                 ctdb_uint32_push(&cd->data.recmode, buf, &np);
463                 break;
464
465         case CTDB_CONTROL_DB_ATTACH:
466                 ctdb_string_push(&cd->data.db_name, buf, &np);
467                 break;
468
469         case CTDB_CONTROL_SET_CALL:
470                 break;
471
472         case CTDB_CONTROL_TRAVERSE_START:
473                 ctdb_traverse_start_push(cd->data.traverse_start, buf, &np);
474                 break;
475
476         case CTDB_CONTROL_TRAVERSE_ALL:
477                 ctdb_traverse_all_push(cd->data.traverse_all, buf, &np);
478                 break;
479
480         case CTDB_CONTROL_TRAVERSE_DATA:
481                 ctdb_rec_data_push(cd->data.rec_data, buf, &np);
482                 break;
483
484         case CTDB_CONTROL_GET_DBNAME:
485                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
486                 break;
487
488         case CTDB_CONTROL_ENABLE_SEQNUM:
489                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
490                 break;
491
492         case CTDB_CONTROL_UPDATE_SEQNUM:
493                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
494                 break;
495
496         case CTDB_CONTROL_SET_RECMASTER:
497                 ctdb_uint32_push(&cd->data.recmaster, buf, &np);
498                 break;
499
500         case CTDB_CONTROL_TCP_CLIENT:
501                 ctdb_connection_push(cd->data.conn, buf, &np);
502                 break;
503
504         case CTDB_CONTROL_TCP_ADD:
505                 ctdb_connection_push(cd->data.conn, buf, &np);
506                 break;
507
508         case CTDB_CONTROL_TCP_REMOVE:
509                 ctdb_connection_push(cd->data.conn, buf, &np);
510                 break;
511
512         case CTDB_CONTROL_SET_TUNABLE:
513                 ctdb_tunable_push(cd->data.tunable, buf, &np);
514                 break;
515
516         case CTDB_CONTROL_GET_TUNABLE:
517                 ctdb_stringn_push(&cd->data.tun_var, buf, &np);
518                 break;
519
520         case CTDB_CONTROL_MODIFY_FLAGS:
521                 ctdb_node_flag_change_push(cd->data.flag_change, buf, &np);
522                 break;
523
524         case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
525                 ctdb_sock_addr_push(cd->data.addr, buf, &np);
526                 break;
527
528         case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
529                 ctdb_tickle_list_push(cd->data.tickles, buf, &np);
530                 break;
531
532         case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
533                 ctdb_string_push(&cd->data.db_name, buf, &np);
534                 break;
535
536         case CTDB_CONTROL_UPDATE_RECORD:
537                 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
538                 break;
539
540         case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
541                 ctdb_addr_info_push(cd->data.addr_info, buf, &np);
542                 break;
543
544         case CTDB_CONTROL_WIPE_DATABASE:
545                 ctdb_transdb_push(cd->data.transdb, buf, &np);
546                 break;
547
548         case CTDB_CONTROL_TRY_DELETE_RECORDS:
549                 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
550                 break;
551
552         case CTDB_CONTROL_ADD_PUBLIC_IP:
553                 ctdb_addr_info_push(cd->data.addr_info, buf, &np);
554                 break;
555
556         case CTDB_CONTROL_DEL_PUBLIC_IP:
557                 ctdb_addr_info_push(cd->data.addr_info, buf, &np);
558                 break;
559
560         case CTDB_CONTROL_RELEASE_IP:
561                 ctdb_public_ip_push(cd->data.pubip, buf, &np);
562                 break;
563
564         case CTDB_CONTROL_TAKEOVER_IP:
565                 ctdb_public_ip_push(cd->data.pubip, buf, &np);
566                 break;
567
568         case CTDB_CONTROL_TRAVERSE_KILL:
569                 ctdb_traverse_start_push(cd->data.traverse_start, buf, &np);
570                 break;
571
572         case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
573                 ctdb_double_push(&cd->data.reclock_latency, buf, &np);
574                 break;
575
576         case CTDB_CONTROL_SET_LMASTERROLE:
577                 ctdb_uint32_push(&cd->data.role, buf, &np);
578                 break;
579
580         case CTDB_CONTROL_SET_RECMASTERROLE:
581                 ctdb_uint32_push(&cd->data.role, buf, &np);
582                 break;
583
584         case CTDB_CONTROL_SET_BAN_STATE:
585                 ctdb_ban_state_push(cd->data.ban_state, buf, &np);
586                 break;
587
588         case CTDB_CONTROL_REGISTER_NOTIFY:
589                 ctdb_notify_data_push(cd->data.notify, buf, &np);
590                 break;
591
592         case CTDB_CONTROL_DEREGISTER_NOTIFY:
593                 ctdb_uint64_push(&cd->data.srvid, buf, &np);
594                 break;
595
596         case CTDB_CONTROL_TRANS3_COMMIT:
597                 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
598                 break;
599
600         case CTDB_CONTROL_GET_DB_SEQNUM:
601                 u32 = 0;
602                 offset = 0;
603                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
604                 offset += np;
605                 ctdb_uint32_push(&u32, buf+offset, &np);
606                 offset += np;
607                 np = offset;
608                 break;
609
610         case CTDB_CONTROL_DB_SET_HEALTHY:
611                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
612                 break;
613
614         case CTDB_CONTROL_DB_GET_HEALTH:
615                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
616                 break;
617
618         case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
619                 ctdb_sock_addr_push(cd->data.addr, buf, &np);
620                 break;
621
622         case CTDB_CONTROL_SET_IFACE_LINK_STATE:
623                 ctdb_iface_push(cd->data.iface, buf, &np);
624                 break;
625
626         case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
627                 ctdb_connection_push(cd->data.conn, buf, &np);
628                 break;
629
630         case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
631                 ctdb_key_data_push(cd->data.key, buf, &np);
632                 break;
633
634         case CTDB_CONTROL_SET_DB_READONLY:
635                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
636                 break;
637
638         case CTDB_CONTROL_CHECK_SRVIDS:
639                 break;
640
641         case CTDB_CONTROL_TRAVERSE_START_EXT:
642                 ctdb_traverse_start_ext_push(cd->data.traverse_start_ext, buf,
643                                              &np);
644                 break;
645
646         case CTDB_CONTROL_GET_DB_STATISTICS:
647                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
648                 break;
649
650         case CTDB_CONTROL_SET_DB_STICKY:
651                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
652                 break;
653
654         case CTDB_CONTROL_TRAVERSE_ALL_EXT:
655                 ctdb_traverse_all_ext_push(cd->data.traverse_all_ext, buf,
656                                            &np);
657                 break;
658
659         case CTDB_CONTROL_DB_DETACH:
660                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
661                 break;
662
663         case CTDB_CONTROL_DB_FREEZE:
664                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
665                 break;
666
667         case CTDB_CONTROL_DB_THAW:
668                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
669                 break;
670
671         case CTDB_CONTROL_DB_TRANSACTION_START:
672                 ctdb_transdb_push(cd->data.transdb, buf, &np);
673                 break;
674
675         case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
676                 ctdb_transdb_push(cd->data.transdb, buf, &np);
677                 break;
678
679         case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
680                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
681                 break;
682
683         case CTDB_CONTROL_DB_PULL:
684                 ctdb_pulldb_ext_push(cd->data.pulldb_ext, buf, &np);
685                 break;
686
687         case CTDB_CONTROL_DB_PUSH_START:
688                 ctdb_pulldb_ext_push(cd->data.pulldb_ext, buf, &np);
689                 break;
690
691         case CTDB_CONTROL_DB_PUSH_CONFIRM:
692                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
693                 break;
694
695         case CTDB_CONTROL_DB_OPEN_FLAGS:
696                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
697                 break;
698
699         case CTDB_CONTROL_DB_ATTACH_REPLICATED:
700                 ctdb_string_push(&cd->data.db_name, buf, &np);
701                 break;
702
703         case CTDB_CONTROL_CHECK_PID_SRVID:
704                 ctdb_pid_srvid_push(cd->data.pid_srvid, buf, &np);
705                 break;
706         }
707
708         *npush = np;
709 }
710
711 static int ctdb_req_control_data_pull(uint8_t *buf, size_t buflen,
712                                       uint32_t opcode,
713                                       TALLOC_CTX *mem_ctx,
714                                       struct ctdb_req_control_data *cd,
715                                       size_t *npull)
716 {
717         size_t np = 0, offset;
718         uint32_t u32;
719         int ret = 0;
720
721         cd->opcode = opcode;
722
723         switch (opcode) {
724         case CTDB_CONTROL_PROCESS_EXISTS:
725                 ret = ctdb_pid_pull(buf, buflen, &cd->data.pid, &np);
726                 break;
727
728         case CTDB_CONTROL_GETDBPATH:
729                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
730                 break;
731
732         case CTDB_CONTROL_SETVNNMAP:
733                 ret = ctdb_vnn_map_pull(buf, buflen, mem_ctx,
734                                         &cd->data.vnnmap, &np);
735                 break;
736
737         case CTDB_CONTROL_SET_DEBUG:
738                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.loglevel, &np);
739                 break;
740
741         case CTDB_CONTROL_PULL_DB:
742                 ret = ctdb_pulldb_pull(buf, buflen, mem_ctx,
743                                        &cd->data.pulldb, &np);
744                 break;
745
746         case CTDB_CONTROL_PUSH_DB:
747                 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
748                                            &cd->data.recbuf, &np);
749                 break;
750
751         case CTDB_CONTROL_SET_RECMODE:
752                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.recmode, &np);
753                 break;
754
755         case CTDB_CONTROL_DB_ATTACH:
756                 ret = ctdb_string_pull(buf, buflen, mem_ctx,
757                                        &cd->data.db_name, &np);
758                 break;
759
760         case CTDB_CONTROL_SET_CALL:
761                 break;
762
763         case CTDB_CONTROL_TRAVERSE_START:
764                 ret = ctdb_traverse_start_pull(buf, buflen, mem_ctx,
765                                                &cd->data.traverse_start, &np);
766                 break;
767
768         case CTDB_CONTROL_TRAVERSE_ALL:
769                 ret = ctdb_traverse_all_pull(buf, buflen, mem_ctx,
770                                              &cd->data.traverse_all, &np);
771                 break;
772
773         case CTDB_CONTROL_TRAVERSE_DATA:
774                 ret = ctdb_rec_data_pull(buf, buflen, mem_ctx,
775                                          &cd->data.rec_data, &np);
776                 break;
777
778         case CTDB_CONTROL_GET_DBNAME:
779                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
780                 break;
781
782         case CTDB_CONTROL_ENABLE_SEQNUM:
783                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
784                 break;
785
786         case CTDB_CONTROL_UPDATE_SEQNUM:
787                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
788                 break;
789
790         case CTDB_CONTROL_SET_RECMASTER:
791                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.recmaster, &np);
792                 break;
793
794         case CTDB_CONTROL_TCP_CLIENT:
795                 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
796                                            &cd->data.conn, &np);
797                 break;
798
799         case CTDB_CONTROL_TCP_ADD:
800                 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
801                                            &cd->data.conn, &np);
802                 break;
803
804         case CTDB_CONTROL_TCP_REMOVE:
805                 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
806                                            &cd->data.conn, &np);
807                 break;
808
809         case CTDB_CONTROL_SET_TUNABLE:
810                 ret = ctdb_tunable_pull(buf, buflen, mem_ctx,
811                                         &cd->data.tunable, &np);
812                 break;
813
814         case CTDB_CONTROL_GET_TUNABLE:
815                 ret = ctdb_stringn_pull(buf, buflen, mem_ctx,
816                                         &cd->data.tun_var, &np);
817                 break;
818
819         case CTDB_CONTROL_MODIFY_FLAGS:
820                 ret = ctdb_node_flag_change_pull(buf, buflen, mem_ctx,
821                                                  &cd->data.flag_change, &np);
822                 break;
823
824         case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
825                 ret = ctdb_sock_addr_pull(buf, buflen, mem_ctx,
826                                           &cd->data.addr, &np);
827                 break;
828
829         case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
830                 ret = ctdb_tickle_list_pull(buf, buflen, mem_ctx,
831                                             &cd->data.tickles, &np);
832                 break;
833
834         case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
835                 ret = ctdb_string_pull(buf, buflen, mem_ctx,
836                                        &cd->data.db_name, &np);
837                 break;
838
839         case CTDB_CONTROL_UPDATE_RECORD:
840                 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
841                                            &cd->data.recbuf, &np);
842                 break;
843
844         case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
845                 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
846                                           &cd->data.addr_info, &np);
847                 break;
848
849         case CTDB_CONTROL_WIPE_DATABASE:
850                 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
851                                        &cd->data.transdb, &np);
852                 break;
853
854         case CTDB_CONTROL_TRY_DELETE_RECORDS:
855                 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
856                                            &cd->data.recbuf, &np);
857                 break;
858
859         case CTDB_CONTROL_ADD_PUBLIC_IP:
860                 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
861                                           &cd->data.addr_info, &np);
862                 break;
863
864         case CTDB_CONTROL_DEL_PUBLIC_IP:
865                 ret = ctdb_addr_info_pull(buf, buflen, mem_ctx,
866                                           &cd->data.addr_info, &np);
867                 break;
868
869         case CTDB_CONTROL_RELEASE_IP:
870                 ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
871                                           &cd->data.pubip, &np);
872                 break;
873
874         case CTDB_CONTROL_TAKEOVER_IP:
875                 ret = ctdb_public_ip_pull(buf, buflen, mem_ctx,
876                                           &cd->data.pubip, &np);
877                 break;
878
879         case CTDB_CONTROL_TRAVERSE_KILL:
880                 ret = ctdb_traverse_start_pull(buf, buflen, mem_ctx,
881                                                &cd->data.traverse_start, &np);
882                 break;
883
884         case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
885                 ret = ctdb_double_pull(buf, buflen, &cd->data.reclock_latency,
886                                        &np);
887                 break;
888
889         case CTDB_CONTROL_SET_LMASTERROLE:
890                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.role, &np);
891                 break;
892
893         case CTDB_CONTROL_SET_RECMASTERROLE:
894                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.role, &np);
895                 break;
896
897         case CTDB_CONTROL_SET_BAN_STATE:
898                 ret = ctdb_ban_state_pull(buf, buflen, mem_ctx,
899                                           &cd->data.ban_state, &np);
900                 break;
901
902         case CTDB_CONTROL_REGISTER_NOTIFY:
903                 ret = ctdb_notify_data_pull(buf, buflen, mem_ctx,
904                                             &cd->data.notify, &np);
905                 break;
906
907         case CTDB_CONTROL_DEREGISTER_NOTIFY:
908                 ret = ctdb_uint64_pull(buf, buflen, &cd->data.srvid, &np);
909                 break;
910
911         case CTDB_CONTROL_TRANS3_COMMIT:
912                 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
913                                            &cd->data.recbuf, &np);
914                 break;
915
916         case CTDB_CONTROL_GET_DB_SEQNUM:
917                 offset = 0;
918                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
919                 if (ret != 0) {
920                         break;
921                 }
922                 offset += np;
923                 ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
924                 offset += np;
925                 np = offset;
926                 break;
927
928         case CTDB_CONTROL_DB_SET_HEALTHY:
929                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
930                 break;
931
932         case CTDB_CONTROL_DB_GET_HEALTH:
933                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
934                 break;
935
936         case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
937                 ret = ctdb_sock_addr_pull(buf, buflen, mem_ctx,
938                                           &cd->data.addr, &np);
939                 break;
940
941         case CTDB_CONTROL_SET_IFACE_LINK_STATE:
942                 ret = ctdb_iface_pull(buf, buflen, mem_ctx,
943                                       &cd->data.iface, &np);
944                 break;
945
946         case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
947                 ret = ctdb_connection_pull(buf, buflen, mem_ctx,
948                                            &cd->data.conn, &np);
949                 break;
950
951         case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
952                 ret = ctdb_key_data_pull(buf, buflen, mem_ctx,
953                                          &cd->data.key, &np);
954                 break;
955
956         case CTDB_CONTROL_SET_DB_READONLY:
957                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
958                 break;
959
960         case CTDB_CONTROL_CHECK_SRVIDS:
961                 break;
962
963         case CTDB_CONTROL_TRAVERSE_START_EXT:
964                 ret = ctdb_traverse_start_ext_pull(buf, buflen, mem_ctx,
965                                                    &cd->data.traverse_start_ext,
966                                                    &np);
967                 break;
968
969         case CTDB_CONTROL_GET_DB_STATISTICS:
970                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
971                 break;
972
973         case CTDB_CONTROL_SET_DB_STICKY:
974                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
975                 break;
976
977         case CTDB_CONTROL_TRAVERSE_ALL_EXT:
978                 ret = ctdb_traverse_all_ext_pull(buf, buflen, mem_ctx,
979                                                  &cd->data.traverse_all_ext,
980                                                  &np);
981                 break;
982
983         case CTDB_CONTROL_DB_DETACH:
984                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
985                 break;
986
987         case CTDB_CONTROL_DB_FREEZE:
988                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
989                 break;
990
991         case CTDB_CONTROL_DB_THAW:
992                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
993                 break;
994
995         case CTDB_CONTROL_DB_TRANSACTION_START:
996                 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
997                                         &cd->data.transdb, &np);
998                 break;
999
1000         case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
1001                 ret = ctdb_transdb_pull(buf, buflen, mem_ctx,
1002                                         &cd->data.transdb, &np);
1003                 break;
1004
1005         case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
1006                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1007                 break;
1008
1009         case CTDB_CONTROL_DB_PULL:
1010                 ret = ctdb_pulldb_ext_pull(buf, buflen, mem_ctx,
1011                                            &cd->data.pulldb_ext, &np);
1012                 break;
1013
1014         case CTDB_CONTROL_DB_PUSH_START:
1015                 ret = ctdb_pulldb_ext_pull(buf, buflen, mem_ctx,
1016                                            &cd->data.pulldb_ext, &np);
1017                 break;
1018
1019         case CTDB_CONTROL_DB_PUSH_CONFIRM:
1020                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1021                 break;
1022
1023         case CTDB_CONTROL_DB_OPEN_FLAGS:
1024                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1025                 break;
1026
1027         case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1028                 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1029                                        &cd->data.db_name, &np);
1030                 break;
1031
1032         case CTDB_CONTROL_CHECK_PID_SRVID:
1033                 ret = ctdb_pid_srvid_pull(buf, buflen, mem_ctx,
1034                                           &cd->data.pid_srvid, &np);
1035                 break;
1036         }
1037
1038         if (ret != 0) {
1039                 return ret;
1040         }
1041
1042         *npull = np;
1043         return 0;
1044 }
1045
1046 static size_t ctdb_reply_control_data_len(struct ctdb_reply_control_data *cd)
1047 {
1048         size_t len = 0;
1049
1050         if (cd == NULL) {
1051                 return 0;
1052         }
1053
1054         switch (cd->opcode) {
1055         case CTDB_CONTROL_PROCESS_EXISTS:
1056                 break;
1057
1058         case CTDB_CONTROL_STATISTICS:
1059                 len = ctdb_statistics_len(cd->data.stats);
1060                 break;
1061
1062         case CTDB_CONTROL_PING:
1063                 break;
1064
1065         case CTDB_CONTROL_GETDBPATH:
1066                 len = ctdb_string_len(&cd->data.db_path);
1067                 break;
1068
1069         case CTDB_CONTROL_GETVNNMAP:
1070                 len = ctdb_vnn_map_len(cd->data.vnnmap);
1071                 break;
1072
1073         case CTDB_CONTROL_SETVNNMAP:
1074                 break;
1075
1076         case CTDB_CONTROL_GET_DEBUG:
1077                 len = ctdb_uint32_len(&cd->data.loglevel);
1078                 break;
1079
1080         case CTDB_CONTROL_SET_DEBUG:
1081                 break;
1082
1083         case CTDB_CONTROL_GET_DBMAP:
1084                 len = ctdb_dbid_map_len(cd->data.dbmap);
1085                 break;
1086
1087         case CTDB_CONTROL_PULL_DB:
1088                 len = ctdb_rec_buffer_len(cd->data.recbuf);
1089                 break;
1090
1091         case CTDB_CONTROL_PUSH_DB:
1092                 break;
1093
1094         case CTDB_CONTROL_GET_RECMODE:
1095                 break;
1096
1097         case CTDB_CONTROL_SET_RECMODE:
1098                 break;
1099
1100         case CTDB_CONTROL_STATISTICS_RESET:
1101                 break;
1102
1103         case CTDB_CONTROL_DB_ATTACH:
1104                 len = ctdb_uint32_len(&cd->data.db_id);
1105                 break;
1106
1107         case CTDB_CONTROL_SET_CALL:
1108                 break;
1109
1110         case CTDB_CONTROL_TRAVERSE_START:
1111                 break;
1112
1113         case CTDB_CONTROL_TRAVERSE_ALL:
1114                 break;
1115
1116         case CTDB_CONTROL_TRAVERSE_DATA:
1117                 break;
1118
1119         case CTDB_CONTROL_REGISTER_SRVID:
1120                 break;
1121
1122         case CTDB_CONTROL_DEREGISTER_SRVID:
1123                 break;
1124
1125         case CTDB_CONTROL_GET_DBNAME:
1126                 len = ctdb_string_len(&cd->data.db_name);
1127                 break;
1128
1129         case CTDB_CONTROL_ENABLE_SEQNUM:
1130                 break;
1131
1132         case CTDB_CONTROL_UPDATE_SEQNUM:
1133                 break;
1134
1135         case CTDB_CONTROL_DUMP_MEMORY:
1136                 len = ctdb_string_len(&cd->data.mem_str);
1137                 break;
1138
1139         case CTDB_CONTROL_GET_PID:
1140                 break;
1141
1142         case CTDB_CONTROL_GET_RECMASTER:
1143                 break;
1144
1145         case CTDB_CONTROL_SET_RECMASTER:
1146                 break;
1147
1148         case CTDB_CONTROL_FREEZE:
1149                 break;
1150
1151         case CTDB_CONTROL_GET_PNN:
1152                 break;
1153
1154         case CTDB_CONTROL_SHUTDOWN:
1155                 break;
1156
1157         case CTDB_CONTROL_GET_MONMODE:
1158                 break;
1159
1160         case CTDB_CONTROL_TCP_CLIENT:
1161                 break;
1162
1163         case CTDB_CONTROL_TCP_ADD:
1164                 break;
1165
1166         case CTDB_CONTROL_TCP_REMOVE:
1167                 break;
1168
1169         case CTDB_CONTROL_STARTUP:
1170                 break;
1171
1172         case CTDB_CONTROL_SET_TUNABLE:
1173                 break;
1174
1175         case CTDB_CONTROL_GET_TUNABLE:
1176                 len = ctdb_uint32_len(&cd->data.tun_value);
1177                 break;
1178
1179         case CTDB_CONTROL_LIST_TUNABLES:
1180                 len = ctdb_var_list_len(cd->data.tun_var_list);
1181                 break;
1182
1183         case CTDB_CONTROL_MODIFY_FLAGS:
1184                 break;
1185
1186         case CTDB_CONTROL_GET_ALL_TUNABLES:
1187                 len = ctdb_tunable_list_len(cd->data.tun_list);
1188                 break;
1189
1190         case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1191                 len = ctdb_tickle_list_len(cd->data.tickles);
1192                 break;
1193
1194         case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
1195                 break;
1196
1197         case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1198                 len = ctdb_uint32_len(&cd->data.db_id);
1199                 break;
1200
1201         case CTDB_CONTROL_UPDATE_RECORD:
1202                 break;
1203
1204         case CTDB_CONTROL_SEND_GRATUITOUS_ARP:
1205                 break;
1206
1207         case CTDB_CONTROL_WIPE_DATABASE:
1208                 break;
1209
1210         case CTDB_CONTROL_UPTIME:
1211                 len = ctdb_uptime_len(cd->data.uptime);
1212                 break;
1213
1214         case CTDB_CONTROL_START_RECOVERY:
1215                 break;
1216
1217         case CTDB_CONTROL_END_RECOVERY:
1218                 break;
1219
1220         case CTDB_CONTROL_RELOAD_NODES_FILE:
1221                 break;
1222
1223         case CTDB_CONTROL_TRY_DELETE_RECORDS:
1224                 len = ctdb_rec_buffer_len(cd->data.recbuf);
1225                 break;
1226
1227         case CTDB_CONTROL_ENABLE_MONITOR:
1228                 break;
1229
1230         case CTDB_CONTROL_DISABLE_MONITOR:
1231                 break;
1232
1233         case CTDB_CONTROL_ADD_PUBLIC_IP:
1234                 break;
1235
1236         case CTDB_CONTROL_DEL_PUBLIC_IP:
1237                 break;
1238
1239         case CTDB_CONTROL_GET_CAPABILITIES:
1240                 len = ctdb_uint32_len(&cd->data.caps);
1241                 break;
1242
1243         case CTDB_CONTROL_RECD_PING:
1244                 break;
1245
1246         case CTDB_CONTROL_RELEASE_IP:
1247                 break;
1248
1249         case CTDB_CONTROL_TAKEOVER_IP:
1250                 break;
1251
1252         case CTDB_CONTROL_GET_PUBLIC_IPS:
1253                 len = ctdb_public_ip_list_len(cd->data.pubip_list);
1254                 break;
1255
1256         case CTDB_CONTROL_GET_NODEMAP:
1257                 len = ctdb_node_map_len(cd->data.nodemap);
1258                 break;
1259
1260         case CTDB_CONTROL_TRAVERSE_KILL:
1261                 break;
1262
1263         case CTDB_CONTROL_RECD_RECLOCK_LATENCY:
1264                 break;
1265
1266         case CTDB_CONTROL_GET_RECLOCK_FILE:
1267                 len = ctdb_string_len(&cd->data.reclock_file);
1268                 break;
1269
1270         case CTDB_CONTROL_STOP_NODE:
1271                 break;
1272
1273         case CTDB_CONTROL_CONTINUE_NODE:
1274                 break;
1275
1276         case CTDB_CONTROL_SET_LMASTERROLE:
1277                 break;
1278
1279         case CTDB_CONTROL_SET_RECMASTERROLE:
1280                 break;
1281
1282         case CTDB_CONTROL_SET_BAN_STATE:
1283                 break;
1284
1285         case CTDB_CONTROL_GET_BAN_STATE:
1286                 len = ctdb_ban_state_len(cd->data.ban_state);
1287                 break;
1288
1289         case CTDB_CONTROL_SET_DB_PRIORITY:
1290                 break;
1291
1292         case CTDB_CONTROL_GET_DB_PRIORITY:
1293                 break;
1294
1295         case CTDB_CONTROL_REGISTER_NOTIFY:
1296                 break;
1297
1298         case CTDB_CONTROL_DEREGISTER_NOTIFY:
1299                 break;
1300
1301         case CTDB_CONTROL_TRANS3_COMMIT:
1302                 break;
1303
1304         case CTDB_CONTROL_GET_DB_SEQNUM:
1305                 len = ctdb_uint64_len(&cd->data.seqnum);
1306                 break;
1307
1308         case CTDB_CONTROL_DB_SET_HEALTHY:
1309                 break;
1310
1311         case CTDB_CONTROL_DB_GET_HEALTH:
1312                 len = ctdb_string_len(&cd->data.reason);
1313                 break;
1314
1315         case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1316                 len = ctdb_public_ip_info_len(cd->data.ipinfo);
1317                 break;
1318
1319         case CTDB_CONTROL_GET_IFACES:
1320                 len = ctdb_iface_list_len(cd->data.iface_list);
1321                 break;
1322
1323         case CTDB_CONTROL_SET_IFACE_LINK_STATE:
1324                 break;
1325
1326         case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
1327                 break;
1328
1329         case CTDB_CONTROL_GET_STAT_HISTORY:
1330                 len = ctdb_statistics_list_len(cd->data.stats_list);
1331                 break;
1332
1333         case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
1334                 break;
1335
1336         case CTDB_CONTROL_SET_DB_READONLY:
1337                 break;
1338
1339         case CTDB_CONTROL_CHECK_SRVIDS:
1340                 break;
1341
1342         case CTDB_CONTROL_TRAVERSE_START_EXT:
1343                 break;
1344
1345         case CTDB_CONTROL_GET_DB_STATISTICS:
1346                 len = ctdb_db_statistics_len(cd->data.dbstats);
1347                 break;
1348
1349         case CTDB_CONTROL_SET_DB_STICKY:
1350                 break;
1351
1352         case CTDB_CONTROL_RELOAD_PUBLIC_IPS:
1353                 break;
1354
1355         case CTDB_CONTROL_TRAVERSE_ALL_EXT:
1356                 break;
1357
1358         case CTDB_CONTROL_IPREALLOCATED:
1359                 break;
1360
1361         case CTDB_CONTROL_GET_RUNSTATE:
1362                 len = ctdb_uint32_len(&cd->data.runstate);
1363                 break;
1364
1365         case CTDB_CONTROL_DB_DETACH:
1366                 break;
1367
1368         case CTDB_CONTROL_GET_NODES_FILE:
1369                 len = ctdb_node_map_len(cd->data.nodemap);
1370                 break;
1371
1372         case CTDB_CONTROL_DB_FREEZE:
1373                 break;
1374
1375         case CTDB_CONTROL_DB_THAW:
1376                 break;
1377
1378         case CTDB_CONTROL_DB_TRANSACTION_START:
1379                 break;
1380
1381         case CTDB_CONTROL_DB_TRANSACTION_COMMIT:
1382                 break;
1383
1384         case CTDB_CONTROL_DB_TRANSACTION_CANCEL:
1385                 break;
1386
1387         case CTDB_CONTROL_DB_PULL:
1388                 len = ctdb_uint32_len(&cd->data.num_records);
1389                 break;
1390
1391         case CTDB_CONTROL_DB_PUSH_START:
1392                 break;
1393
1394         case CTDB_CONTROL_DB_PUSH_CONFIRM:
1395                 len = ctdb_uint32_len(&cd->data.num_records);
1396                 break;
1397
1398         case CTDB_CONTROL_DB_OPEN_FLAGS:
1399                 len = ctdb_int32_len(&cd->data.tdb_flags);
1400                 break;
1401
1402         case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1403                 len = ctdb_uint32_len(&cd->data.db_id);
1404                 break;
1405
1406         case CTDB_CONTROL_CHECK_PID_SRVID:
1407                 break;
1408
1409         case CTDB_CONTROL_TUNNEL_REGISTER:
1410                 break;
1411
1412         case CTDB_CONTROL_TUNNEL_DEREGISTER:
1413                 break;
1414         }
1415
1416         return len;
1417 }
1418
1419 static void ctdb_reply_control_data_push(struct ctdb_reply_control_data *cd,
1420                                          uint8_t *buf, size_t *npush)
1421 {
1422         size_t np = 0;
1423
1424         switch (cd->opcode) {
1425         case CTDB_CONTROL_STATISTICS:
1426                 ctdb_statistics_push(cd->data.stats, buf, &np);
1427                 break;
1428
1429         case CTDB_CONTROL_GETDBPATH:
1430                 ctdb_string_push(&cd->data.db_path, buf, &np);
1431                 break;
1432
1433         case CTDB_CONTROL_GETVNNMAP:
1434                 ctdb_vnn_map_push(cd->data.vnnmap, buf, &np);
1435                 break;
1436
1437         case CTDB_CONTROL_GET_DEBUG:
1438                 ctdb_uint32_push(&cd->data.loglevel, buf, &np);
1439                 break;
1440
1441         case CTDB_CONTROL_GET_DBMAP:
1442                 ctdb_dbid_map_push(cd->data.dbmap, buf, &np);
1443                 break;
1444
1445         case CTDB_CONTROL_PULL_DB:
1446                 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
1447                 break;
1448
1449         case CTDB_CONTROL_PUSH_DB:
1450                 break;
1451
1452         case CTDB_CONTROL_DB_ATTACH:
1453                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
1454                 break;
1455
1456         case CTDB_CONTROL_GET_DBNAME:
1457                 ctdb_string_push(&cd->data.db_name, buf, &np);
1458                 break;
1459
1460         case CTDB_CONTROL_DUMP_MEMORY:
1461                 ctdb_string_push(&cd->data.mem_str, buf, &np);
1462                 break;
1463
1464         case CTDB_CONTROL_GET_PID:
1465                 break;
1466
1467         case CTDB_CONTROL_GET_RECMASTER:
1468                 break;
1469
1470         case CTDB_CONTROL_GET_TUNABLE:
1471                 ctdb_uint32_push(&cd->data.tun_value, buf, &np);
1472                 break;
1473
1474         case CTDB_CONTROL_LIST_TUNABLES:
1475                 ctdb_var_list_push(cd->data.tun_var_list, buf, &np);
1476                 break;
1477
1478         case CTDB_CONTROL_GET_ALL_TUNABLES:
1479                 ctdb_tunable_list_push(cd->data.tun_list, buf, &np);
1480                 break;
1481
1482         case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1483                 ctdb_tickle_list_push(cd->data.tickles, buf, &np);
1484                 break;
1485
1486         case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1487                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
1488                 break;
1489
1490         case CTDB_CONTROL_UPTIME:
1491                 ctdb_uptime_push(cd->data.uptime, buf, &np);
1492                 break;
1493
1494         case CTDB_CONTROL_TRY_DELETE_RECORDS:
1495                 ctdb_rec_buffer_push(cd->data.recbuf, buf, &np);
1496                 break;
1497
1498         case CTDB_CONTROL_GET_CAPABILITIES:
1499                 ctdb_uint32_push(&cd->data.caps, buf, &np);
1500                 break;
1501
1502         case CTDB_CONTROL_GET_PUBLIC_IPS:
1503                 ctdb_public_ip_list_push(cd->data.pubip_list, buf, &np);
1504                 break;
1505
1506         case CTDB_CONTROL_GET_NODEMAP:
1507                 ctdb_node_map_push(cd->data.nodemap, buf, &np);
1508                 break;
1509
1510         case CTDB_CONTROL_GET_RECLOCK_FILE:
1511                 ctdb_string_push(&cd->data.reclock_file, buf, &np);
1512                 break;
1513
1514         case CTDB_CONTROL_GET_BAN_STATE:
1515                 ctdb_ban_state_push(cd->data.ban_state, buf, &np);
1516                 break;
1517
1518         case CTDB_CONTROL_GET_DB_PRIORITY:
1519                 break;
1520
1521         case CTDB_CONTROL_GET_DB_SEQNUM:
1522                 ctdb_uint64_push(&cd->data.seqnum, buf, &np);
1523                 break;
1524
1525         case CTDB_CONTROL_DB_GET_HEALTH:
1526                 ctdb_string_push(&cd->data.reason, buf, &np);
1527                 break;
1528
1529         case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1530                 ctdb_public_ip_info_push(cd->data.ipinfo, buf, &np);
1531                 break;
1532
1533         case CTDB_CONTROL_GET_IFACES:
1534                 ctdb_iface_list_push(cd->data.iface_list, buf, &np);
1535                 break;
1536
1537         case CTDB_CONTROL_GET_STAT_HISTORY:
1538                 ctdb_statistics_list_push(cd->data.stats_list, buf, &np);
1539                 break;
1540
1541         case CTDB_CONTROL_CHECK_SRVIDS:
1542                 break;
1543
1544         case CTDB_CONTROL_GET_DB_STATISTICS:
1545                 ctdb_db_statistics_push(cd->data.dbstats, buf, &np);
1546                 break;
1547
1548         case CTDB_CONTROL_GET_RUNSTATE:
1549                 ctdb_uint32_push(&cd->data.runstate, buf, &np);
1550                 break;
1551
1552         case CTDB_CONTROL_GET_NODES_FILE:
1553                 ctdb_node_map_push(cd->data.nodemap, buf, &np);
1554                 break;
1555
1556         case CTDB_CONTROL_DB_PULL:
1557                 ctdb_uint32_push(&cd->data.num_records, buf, &np);
1558                 break;
1559
1560         case CTDB_CONTROL_DB_PUSH_CONFIRM:
1561                 ctdb_uint32_push(&cd->data.num_records, buf, &np);
1562                 break;
1563
1564         case CTDB_CONTROL_DB_OPEN_FLAGS:
1565                 ctdb_int32_push(&cd->data.tdb_flags, buf, &np);
1566                 break;
1567
1568         case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1569                 ctdb_uint32_push(&cd->data.db_id, buf, &np);
1570                 break;
1571
1572         case CTDB_CONTROL_CHECK_PID_SRVID:
1573                 break;
1574         }
1575
1576         *npush = np;
1577 }
1578
1579 static int ctdb_reply_control_data_pull(uint8_t *buf, size_t buflen,
1580                                         uint32_t opcode, TALLOC_CTX *mem_ctx,
1581                                         struct ctdb_reply_control_data *cd,
1582                                         size_t *npull)
1583 {
1584         size_t np = 0;
1585         int ret = 0;
1586
1587         cd->opcode = opcode;
1588
1589         switch (opcode) {
1590         case CTDB_CONTROL_STATISTICS:
1591                 ret = ctdb_statistics_pull(buf, buflen, mem_ctx,
1592                                            &cd->data.stats, &np);
1593                 break;
1594
1595         case CTDB_CONTROL_GETDBPATH:
1596                 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1597                                        &cd->data.db_path, &np);
1598                 break;
1599
1600         case CTDB_CONTROL_GETVNNMAP:
1601                 ret = ctdb_vnn_map_pull(buf, buflen, mem_ctx,
1602                                         &cd->data.vnnmap, &np);
1603                 break;
1604
1605         case CTDB_CONTROL_GET_DEBUG:
1606                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.loglevel, &np);
1607                 break;
1608
1609         case CTDB_CONTROL_GET_DBMAP:
1610                 ret = ctdb_dbid_map_pull(buf, buflen, mem_ctx,
1611                                          &cd->data.dbmap, &np);
1612                 break;
1613
1614         case CTDB_CONTROL_PULL_DB:
1615                 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
1616                                            &cd->data.recbuf, &np);
1617                 break;
1618
1619         case CTDB_CONTROL_PUSH_DB:
1620                 break;
1621
1622         case CTDB_CONTROL_DB_ATTACH:
1623                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1624                 break;
1625
1626         case CTDB_CONTROL_GET_DBNAME:
1627                 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1628                                        &cd->data.db_name, &np);
1629                 break;
1630
1631         case CTDB_CONTROL_DUMP_MEMORY:
1632                 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1633                                        &cd->data.mem_str, &np);
1634                 break;
1635
1636         case CTDB_CONTROL_GET_PID:
1637                 break;
1638
1639         case CTDB_CONTROL_GET_RECMASTER:
1640                 break;
1641
1642         case CTDB_CONTROL_GET_TUNABLE:
1643                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.tun_value,
1644                                        &np);
1645                 break;
1646
1647         case CTDB_CONTROL_LIST_TUNABLES:
1648                 ret = ctdb_var_list_pull(buf, buflen, mem_ctx,
1649                                          &cd->data.tun_var_list, &np);
1650                 break;
1651
1652         case CTDB_CONTROL_GET_ALL_TUNABLES:
1653                 ret = ctdb_tunable_list_pull(buf, buflen, mem_ctx,
1654                                              &cd->data.tun_list, &np);
1655                 break;
1656
1657         case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
1658                 ret = ctdb_tickle_list_pull(buf, buflen, mem_ctx,
1659                                             &cd->data.tickles, &np);
1660                 break;
1661
1662         case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
1663                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1664                 break;
1665
1666         case CTDB_CONTROL_UPTIME:
1667                 ret = ctdb_uptime_pull(buf, buflen, mem_ctx,
1668                                        &cd->data.uptime, &np);
1669                 break;
1670
1671         case CTDB_CONTROL_TRY_DELETE_RECORDS:
1672                 ret = ctdb_rec_buffer_pull(buf, buflen, mem_ctx,
1673                                            &cd->data.recbuf, &np);
1674                 break;
1675
1676         case CTDB_CONTROL_GET_CAPABILITIES:
1677                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.caps, &np);
1678                 break;
1679
1680         case CTDB_CONTROL_GET_PUBLIC_IPS:
1681                 ret = ctdb_public_ip_list_pull(buf, buflen, mem_ctx,
1682                                                &cd->data.pubip_list, &np);
1683                 break;
1684
1685         case CTDB_CONTROL_GET_NODEMAP:
1686                 ret = ctdb_node_map_pull(buf, buflen, mem_ctx,
1687                                          &cd->data.nodemap, &np);
1688                 break;
1689
1690         case CTDB_CONTROL_GET_RECLOCK_FILE:
1691                 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1692                                        &cd->data.reclock_file, &np);
1693                 break;
1694
1695         case CTDB_CONTROL_GET_BAN_STATE:
1696                 ret = ctdb_ban_state_pull(buf, buflen, mem_ctx,
1697                                           &cd->data.ban_state, &np);
1698                 break;
1699
1700         case CTDB_CONTROL_GET_DB_PRIORITY:
1701                 break;
1702
1703         case CTDB_CONTROL_GET_DB_SEQNUM:
1704                 ret = ctdb_uint64_pull(buf, buflen, &cd->data.seqnum, &np);
1705                 break;
1706
1707         case CTDB_CONTROL_DB_GET_HEALTH:
1708                 ret = ctdb_string_pull(buf, buflen, mem_ctx,
1709                                        &cd->data.reason, &np);
1710                 break;
1711
1712         case CTDB_CONTROL_GET_PUBLIC_IP_INFO:
1713                 ret = ctdb_public_ip_info_pull(buf, buflen, mem_ctx,
1714                                                &cd->data.ipinfo, &np);
1715                 break;
1716
1717         case CTDB_CONTROL_GET_IFACES:
1718                 ret = ctdb_iface_list_pull(buf, buflen, mem_ctx,
1719                                            &cd->data.iface_list, &np);
1720                 break;
1721
1722         case CTDB_CONTROL_GET_STAT_HISTORY:
1723                 ret = ctdb_statistics_list_pull(buf, buflen, mem_ctx,
1724                                                 &cd->data.stats_list, &np);
1725                 break;
1726
1727         case CTDB_CONTROL_CHECK_SRVIDS:
1728                 break;
1729
1730         case CTDB_CONTROL_GET_DB_STATISTICS:
1731                 ret = ctdb_db_statistics_pull(buf, buflen, mem_ctx,
1732                                               &cd->data.dbstats, &np);
1733                 break;
1734
1735         case CTDB_CONTROL_GET_RUNSTATE:
1736                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.runstate, &np);
1737                 break;
1738
1739         case CTDB_CONTROL_GET_NODES_FILE:
1740                 ret = ctdb_node_map_pull(buf, buflen, mem_ctx,
1741                                          &cd->data.nodemap, &np);
1742                 break;
1743
1744         case CTDB_CONTROL_DB_PULL:
1745                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.num_records,
1746                                        &np);
1747                 break;
1748
1749         case CTDB_CONTROL_DB_PUSH_CONFIRM:
1750                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.num_records,
1751                                        &np);
1752                 break;
1753
1754         case CTDB_CONTROL_DB_OPEN_FLAGS:
1755                 ret = ctdb_int32_pull(buf, buflen, &cd->data.tdb_flags, &np);
1756                 break;
1757
1758         case CTDB_CONTROL_DB_ATTACH_REPLICATED:
1759                 ret = ctdb_uint32_pull(buf, buflen, &cd->data.db_id, &np);
1760                 break;
1761
1762         case CTDB_CONTROL_CHECK_PID_SRVID:
1763                 break;
1764         }
1765
1766         if (ret != 0) {
1767                 return ret;
1768         }
1769
1770         *npull = np;
1771         return 0;
1772 }
1773
1774 size_t ctdb_req_control_len(struct ctdb_req_header *h,
1775                             struct ctdb_req_control *c)
1776 {
1777         uint32_t u32 = 0;
1778
1779         return ctdb_req_header_len(h) +
1780                 ctdb_uint32_len(&c->opcode) +
1781                 ctdb_uint32_len(&c->pad) +
1782                 ctdb_uint64_len(&c->srvid) +
1783                 ctdb_uint32_len(&c->client_id) +
1784                 ctdb_uint32_len(&c->flags) +
1785                 ctdb_uint32_len(&u32) +
1786                 ctdb_req_control_data_len(&c->rdata);
1787 }
1788
1789 int ctdb_req_control_push(struct ctdb_req_header *h,
1790                           struct ctdb_req_control *c,
1791                           uint8_t *buf, size_t *buflen)
1792 {
1793         size_t offset = 0, np;
1794         size_t length;
1795         uint32_t u32;
1796
1797         length = ctdb_req_control_len(h, c);
1798         if (*buflen < length) {
1799                 *buflen = length;
1800                 return EMSGSIZE;
1801         }
1802
1803         h->length = *buflen;
1804         ctdb_req_header_push(h, buf+offset, &np);
1805         offset += np;
1806
1807         ctdb_uint32_push(&c->opcode, buf+offset, &np);
1808         offset += np;
1809
1810         ctdb_uint32_push(&c->pad, buf+offset, &np);
1811         offset += np;
1812
1813         ctdb_uint64_push(&c->srvid, buf+offset, &np);
1814         offset += np;
1815
1816         ctdb_uint32_push(&c->client_id, buf+offset, &np);
1817         offset += np;
1818
1819         ctdb_uint32_push(&c->flags, buf+offset, &np);
1820         offset += np;
1821
1822         u32 = ctdb_req_control_data_len(&c->rdata);
1823         ctdb_uint32_push(&u32, buf+offset, &np);
1824         offset += np;
1825
1826         ctdb_req_control_data_push(&c->rdata, buf+offset, &np);
1827         offset += np;
1828
1829         if (offset > *buflen) {
1830                 return EMSGSIZE;
1831         }
1832
1833         return 0;
1834 }
1835
1836 int ctdb_req_control_pull(uint8_t *buf, size_t buflen,
1837                           struct ctdb_req_header *h,
1838                           TALLOC_CTX *mem_ctx,
1839                           struct ctdb_req_control *c)
1840 {
1841         struct ctdb_req_header header;
1842         size_t offset = 0, np;
1843         uint32_t u32;
1844         int ret;
1845
1846         ret = ctdb_req_header_pull(buf+offset, buflen-offset, &header, &np);
1847         if (ret != 0) {
1848                 return ret;
1849         }
1850         offset += np;
1851
1852         if (h != NULL) {
1853                 *h = header;
1854         }
1855
1856         ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->opcode, &np);
1857         if (ret != 0) {
1858                 return ret;
1859         }
1860         offset += np;
1861
1862         ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->pad, &np);
1863         if (ret != 0) {
1864                 return ret;
1865         }
1866         offset += np;
1867
1868         ret = ctdb_uint64_pull(buf+offset, buflen-offset, &c->srvid, &np);
1869         if (ret != 0) {
1870                 return ret;
1871         }
1872         offset += np;
1873
1874         ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->client_id, &np);
1875         if (ret != 0) {
1876                 return ret;
1877         }
1878         offset += np;
1879
1880         ret = ctdb_uint32_pull(buf+offset, buflen-offset, &c->flags, &np);
1881         if (ret != 0) {
1882                 return ret;
1883         }
1884         offset += np;
1885
1886         ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
1887         if (ret != 0) {
1888                 return ret;
1889         }
1890         offset += np;
1891
1892         if (u32 > buflen-offset) {
1893                 return EMSGSIZE;
1894         }
1895
1896         ret = ctdb_req_control_data_pull(buf+offset, u32, c->opcode, mem_ctx,
1897                                          &c->rdata, &np);
1898         if (ret != 0) {
1899                 return ret;
1900         }
1901         offset += np;
1902
1903         if (offset > buflen) {
1904                 return EMSGSIZE;
1905         }
1906
1907         return 0;
1908 }
1909
1910 size_t ctdb_reply_control_len(struct ctdb_req_header *h,
1911                               struct ctdb_reply_control *c)
1912 {
1913         uint32_t dsize, esize;
1914
1915         if (c->status == 0) {
1916                 dsize = ctdb_reply_control_data_len(&c->rdata);
1917                 esize = 0;
1918         } else {
1919                 dsize = 0;
1920                 esize = ctdb_string_len(&c->errmsg);
1921         }
1922
1923         return ctdb_req_header_len(h) +
1924                 ctdb_int32_len(&c->status) +
1925                 ctdb_uint32_len(&dsize) +
1926                 ctdb_uint32_len(&esize) +
1927                 dsize + esize;
1928 }
1929
1930 int ctdb_reply_control_push(struct ctdb_req_header *h,
1931                             struct ctdb_reply_control *c,
1932                             uint8_t *buf, size_t *buflen)
1933 {
1934         size_t offset = 0, np;
1935         size_t length;
1936         uint32_t dsize, esize;
1937
1938         length = ctdb_reply_control_len(h, c);
1939         if (*buflen < length) {
1940                 *buflen = length;
1941                 return EMSGSIZE;
1942         }
1943
1944         h->length = *buflen;
1945         ctdb_req_header_push(h, buf+offset, &np);
1946         offset += np;
1947
1948         ctdb_int32_push(&c->status, buf+offset, &np);
1949         offset += np;
1950
1951         if (c->status == 0) {
1952                 dsize = ctdb_reply_control_data_len(&c->rdata);
1953                 esize = 0;
1954         } else {
1955                 dsize = 0;
1956                 esize = ctdb_string_len(&c->errmsg);
1957         }
1958
1959         ctdb_uint32_push(&dsize, buf+offset, &np);
1960         offset += np;
1961
1962         ctdb_uint32_push(&esize, buf+offset, &np);
1963         offset += np;
1964
1965         if (c->status == 0) {
1966                 ctdb_reply_control_data_push(&c->rdata, buf+offset, &np);
1967         } else {
1968                 ctdb_string_push(&c->errmsg, buf+offset, &np);
1969         }
1970         offset += np;
1971
1972         return 0;
1973 }
1974
1975 int ctdb_reply_control_pull(uint8_t *buf, size_t buflen, uint32_t opcode,
1976                             struct ctdb_req_header *h,
1977                             TALLOC_CTX *mem_ctx,
1978                             struct ctdb_reply_control *c)
1979 {
1980         struct ctdb_req_header header;
1981         size_t offset = 0, np;
1982         uint32_t dsize, esize;
1983         int ret;
1984
1985         ret = ctdb_req_header_pull(buf+offset, buflen-offset, &header, &np);
1986         if (ret != 0) {
1987                 return ret;
1988         }
1989         offset += np;
1990
1991         if (h != NULL) {
1992                 *h = header;
1993         }
1994
1995         ret = ctdb_int32_pull(buf+offset, buflen-offset, &c->status, &np);
1996         if (ret != 0) {
1997                 return ret;
1998         }
1999         offset += np;
2000
2001         ret = ctdb_uint32_pull(buf+offset, buflen-offset, &dsize, &np);
2002         if (ret != 0) {
2003                 return ret;
2004         }
2005         offset += np;
2006
2007         ret = ctdb_uint32_pull(buf+offset, buflen-offset, &esize, &np);
2008         if (ret != 0) {
2009                 return ret;
2010         }
2011         offset += np;
2012
2013         c->errmsg = NULL;
2014
2015         if (c->status == 0) {
2016                 if (buflen-offset < dsize) {
2017                         return EMSGSIZE;
2018                 }
2019
2020                 ret = ctdb_reply_control_data_pull(buf+offset, dsize,
2021                                                    opcode, mem_ctx, &c->rdata,
2022                                                    &np);
2023                 if (ret != 0) {
2024                         return ret;
2025                 }
2026                 offset += np;
2027
2028         } else {
2029                 if (buflen-offset < esize) {
2030                         return EMSGSIZE;
2031                 }
2032
2033                 ret = ctdb_string_pull(buf+offset, esize, mem_ctx, &c->errmsg,
2034                                        &np);
2035                 if (ret != 0) {
2036                         return ret;
2037                 }
2038                 offset += np;
2039         }
2040
2041         return 0;
2042 }