ctdb-logging: Drop enum debug_level
[kai/samba-autobuild/.git] / ctdb / protocol / protocol_client.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 /*
31 void ctdb_req_call_fill(struct ctdb_req_call *c,
32                         uint32_t db_id, uint32_t flags,
33                         uint32_t call_id, TDB_DATA key)
34 {
35         request->flags = flags;
36         c->db_id = db_id;
37         c->call_id = call_id;
38         c->key = key;
39         c->calldata = tdb_null;
40 }
41 */
42
43 static int ctdb_reply_control_generic(struct ctdb_reply_control *reply,
44                                       uint32_t opcode)
45 {
46         if (reply->rdata.opcode != opcode) {
47                 return EPROTO;
48         }
49
50         return reply->status;
51 }
52
53 /* CTDB_CONTROL_PROCESS_EXISTS */
54
55 void ctdb_req_control_process_exists(struct ctdb_req_control *request,
56                                      pid_t pid)
57 {
58         request->opcode = CTDB_CONTROL_PROCESS_EXISTS;
59         request->pad = 0;
60         request->srvid = 0;
61         request->client_id = 0;
62         request->flags = 0;
63
64         request->rdata.opcode = CTDB_CONTROL_PROCESS_EXISTS;
65         request->rdata.data.pid = pid;
66
67 }
68
69 int ctdb_reply_control_process_exists(struct ctdb_reply_control *reply,
70                                       int *status)
71 {
72         if (reply->rdata.opcode != CTDB_CONTROL_PROCESS_EXISTS) {
73                 return EPROTO;
74         }
75
76         *status = reply->status;
77         reply->status = 0;
78
79         return reply->status;
80 }
81
82 /* CTDB_CONTROL_STATISTICS */
83
84 void ctdb_req_control_statistics(struct ctdb_req_control *request)
85 {
86         request->opcode = CTDB_CONTROL_STATISTICS;
87         request->pad = 0;
88         request->srvid = 0;
89         request->client_id = 0;
90         request->flags = 0;
91
92         request->rdata.opcode = CTDB_CONTROL_STATISTICS;
93 }
94
95 int ctdb_reply_control_statistics(struct ctdb_reply_control *reply,
96                                   TALLOC_CTX *mem_ctx,
97                                   struct ctdb_statistics **stats)
98 {
99         if (reply->rdata.opcode != CTDB_CONTROL_STATISTICS) {
100                 return EPROTO;
101         }
102
103         if (reply->status == 0) {
104                 *stats = talloc_steal(mem_ctx, reply->rdata.data.stats);
105         }
106         return reply->status;
107 }
108
109 /* CTDB_CONTROL_PING */
110
111 void ctdb_req_control_ping(struct ctdb_req_control *request)
112 {
113         request->opcode = CTDB_CONTROL_PING;
114         request->pad = 0;
115         request->srvid = 0;
116         request->client_id = 0;
117         request->flags = 0;
118
119         request->rdata.opcode = CTDB_CONTROL_PING;
120 }
121
122 int ctdb_reply_control_ping(struct ctdb_reply_control *reply,
123                             int *num_clients)
124 {
125         if (reply->rdata.opcode != CTDB_CONTROL_PING) {
126                 return EPROTO;
127         }
128
129         if (reply->status >= 0) {
130                 *num_clients = reply->status;
131                 reply->status = 0;
132         }
133         return reply->status;
134 }
135
136 /* CTDB_CONTROL_GETDBPATH */
137
138 void ctdb_req_control_getdbpath(struct ctdb_req_control *request,
139                                 uint32_t db_id)
140 {
141         request->opcode = CTDB_CONTROL_GETDBPATH;
142         request->pad = 0;
143         request->srvid = 0;
144         request->client_id = 0;
145         request->flags = 0;
146
147         request->rdata.opcode = CTDB_CONTROL_GETDBPATH;
148         request->rdata.data.db_id = db_id;
149 }
150
151 int ctdb_reply_control_getdbpath(struct ctdb_reply_control *reply,
152                                  TALLOC_CTX *mem_ctx, const char **db_path)
153 {
154         if (reply->rdata.opcode != CTDB_CONTROL_GETDBPATH) {
155                 return EPROTO;
156         }
157
158         if (reply->status == 0) {
159                 *db_path = talloc_steal(mem_ctx, reply->rdata.data.db_path);
160         }
161         return reply->status;
162 }
163
164 /* CTDB_CONTROL_GETVNNMAP */
165
166 void ctdb_req_control_getvnnmap(struct ctdb_req_control *request)
167 {
168         request->opcode = CTDB_CONTROL_GETVNNMAP;
169         request->pad = 0;
170         request->srvid = 0;
171         request->client_id = 0;
172         request->flags = 0;
173
174         request->rdata.opcode = CTDB_CONTROL_GETVNNMAP;
175 }
176
177 int ctdb_reply_control_getvnnmap(struct ctdb_reply_control *reply,
178                                  TALLOC_CTX *mem_ctx,
179                                  struct ctdb_vnn_map **vnnmap)
180 {
181         if (reply->rdata.opcode != CTDB_CONTROL_GETVNNMAP) {
182                 return EPROTO;
183         }
184
185         if (reply->status == 0) {
186                 *vnnmap = talloc_steal(mem_ctx, reply->rdata.data.vnnmap);
187         }
188         return reply->status;
189 }
190
191 /* CTDB_CONTROL_SETVNNMAP */
192
193 void ctdb_req_control_setvnnmap(struct ctdb_req_control *request,
194                                 struct ctdb_vnn_map *vnnmap)
195 {
196         request->opcode = CTDB_CONTROL_SETVNNMAP;
197         request->pad = 0;
198         request->srvid = 0;
199         request->client_id = 0;
200         request->flags = 0;
201
202         request->rdata.opcode = CTDB_CONTROL_SETVNNMAP;
203         request->rdata.data.vnnmap = vnnmap;
204 }
205
206 int ctdb_reply_control_setvnnmap(struct ctdb_reply_control *reply)
207 {
208         return ctdb_reply_control_generic(reply, CTDB_CONTROL_SETVNNMAP);
209 }
210
211 /* CTDB_CONTROL_GET_DEBUG */
212
213 void ctdb_req_control_get_debug(struct ctdb_req_control *request)
214 {
215         request->opcode = CTDB_CONTROL_GET_DEBUG;
216         request->pad = 0;
217         request->srvid = 0;
218         request->client_id = 0;
219         request->flags = 0;
220
221         request->rdata.opcode = CTDB_CONTROL_GET_DEBUG;
222 }
223
224 int ctdb_reply_control_get_debug(struct ctdb_reply_control *reply,
225                                  int *loglevel)
226 {
227         if (reply->rdata.opcode != CTDB_CONTROL_GET_DEBUG) {
228                 return EPROTO;
229         }
230
231         if (reply->status == 0) {
232                 *loglevel = (int)reply->rdata.data.loglevel;
233         }
234         return reply->status;
235 }
236
237 /* CTDB_CONTROL_SET_DEBUG */
238
239 void ctdb_req_control_set_debug(struct ctdb_req_control *request,
240                                 int loglevel)
241 {
242         request->opcode = CTDB_CONTROL_SET_DEBUG;
243         request->pad = 0;
244         request->srvid = 0;
245         request->client_id = 0;
246         request->flags = 0;
247
248         request->rdata.opcode = CTDB_CONTROL_SET_DEBUG;
249         request->rdata.data.loglevel = (uint32_t)loglevel;
250 }
251
252 int ctdb_reply_control_set_debug(struct ctdb_reply_control *reply)
253 {
254         return ctdb_reply_control_generic(reply, CTDB_CONTROL_SET_DEBUG);
255 }
256
257 /* CTDB_CONTROL_GET_DBMAP */
258
259 void ctdb_req_control_get_dbmap(struct ctdb_req_control *request)
260 {
261         request->opcode = CTDB_CONTROL_GET_DBMAP;
262         request->pad = 0;
263         request->srvid = 0;
264         request->client_id = 0;
265         request->flags = 0;
266
267         request->rdata.opcode = CTDB_CONTROL_GET_DBMAP;
268 }
269
270 int ctdb_reply_control_get_dbmap(struct ctdb_reply_control *reply,
271                                  TALLOC_CTX *mem_ctx,
272                                  struct ctdb_dbid_map **dbmap)
273 {
274         if (reply->rdata.opcode != CTDB_CONTROL_GET_DBMAP) {
275                 return EPROTO;
276         }
277
278         if (reply->status == 0) {
279                 *dbmap = talloc_steal(mem_ctx, reply->rdata.data.dbmap);
280         }
281         return reply->status;
282 }
283
284 /* CTDB_CONTROL_PULL_DB */
285
286 void ctdb_req_control_pull_db(struct ctdb_req_control *request,
287                               struct ctdb_pulldb *pulldb)
288 {
289         request->opcode = CTDB_CONTROL_PULL_DB;
290         request->pad = 0;
291         request->srvid = 0;
292         request->client_id = 0;
293         request->flags = 0;
294
295         request->rdata.opcode = CTDB_CONTROL_PULL_DB;
296         request->rdata.data.pulldb = pulldb;
297 }
298
299 int ctdb_reply_control_pull_db(struct ctdb_reply_control *reply,
300                                TALLOC_CTX *mem_ctx,
301                                struct ctdb_rec_buffer **recbuf)
302 {
303         if (reply->rdata.opcode != CTDB_CONTROL_PULL_DB) {
304                 return EPROTO;
305         }
306
307         if (reply->status == 0) {
308                 *recbuf = talloc_steal(mem_ctx, reply->rdata.data.recbuf);
309         }
310         return reply->status;
311 }
312
313 /* CTDB_CONTROL_PUSH_DB */
314
315 void ctdb_req_control_push_db(struct ctdb_req_control *request,
316                               struct ctdb_rec_buffer *recbuf)
317 {
318         request->opcode = CTDB_CONTROL_PUSH_DB;
319         request->pad = 0;
320         request->srvid = 0;
321         request->client_id = 0;
322         request->flags = 0;
323
324         request->rdata.opcode = CTDB_CONTROL_PUSH_DB;
325         request->rdata.data.recbuf = recbuf;
326 }
327
328 int ctdb_reply_control_push_db(struct ctdb_reply_control *reply)
329 {
330         return ctdb_reply_control_generic(reply, CTDB_CONTROL_PUSH_DB);
331 }
332
333 /* CTDB_CONTROL_GET_RECMODE */
334
335 void ctdb_req_control_get_recmode(struct ctdb_req_control *request)
336 {
337         request->opcode = CTDB_CONTROL_GET_RECMODE;
338         request->pad = 0;
339         request->srvid = 0;
340         request->client_id = 0;
341         request->flags = 0;
342
343         request->rdata.opcode = CTDB_CONTROL_GET_RECMODE;
344 }
345
346 int ctdb_reply_control_get_recmode(struct ctdb_reply_control *reply,
347                                    int *recmode)
348 {
349         if (reply->rdata.opcode != CTDB_CONTROL_GET_RECMODE) {
350                 return EPROTO;
351         }
352
353         if (reply->status >= 0) {
354                 *recmode = reply->status;
355                 reply->status = 0;
356         }
357         return reply->status;
358 }
359
360 /* CTDB_CONTROL_SET_RECMODE */
361
362 void ctdb_req_control_set_recmode(struct ctdb_req_control *request,
363                                   int recmode)
364 {
365         request->opcode = CTDB_CONTROL_SET_RECMODE;
366         request->pad = 0;
367         request->srvid = 0;
368         request->client_id = 0;
369         request->flags = 0;
370
371         request->rdata.opcode = CTDB_CONTROL_SET_RECMODE;
372         request->rdata.data.recmode = recmode;
373 }
374
375 int ctdb_reply_control_set_recmode(struct ctdb_reply_control *reply)
376 {
377         return ctdb_reply_control_generic(reply, CTDB_CONTROL_SET_RECMODE);
378 }
379
380 /* CTDB_CONTROL_STATISTICS_RESET */
381
382 void ctdb_req_control_statistics_reset(struct ctdb_req_control *request)
383 {
384         request->opcode = CTDB_CONTROL_STATISTICS_RESET;
385         request->pad = 0;
386         request->srvid = 0;
387         request->client_id = 0;
388         request->flags = 0;
389
390         request->rdata.opcode = CTDB_CONTROL_STATISTICS_RESET;
391 }
392
393 int ctdb_reply_control_statistics_reset(struct ctdb_reply_control *reply)
394 {
395         return ctdb_reply_control_generic(reply,
396                                           CTDB_CONTROL_STATISTICS_RESET);
397 }
398
399 /* CTDB_CONTROL_DB_ATTACH */
400
401 void ctdb_req_control_db_attach(struct ctdb_req_control *request,
402                                 const char *db_name, uint32_t tdb_flags)
403 {
404         request->opcode = CTDB_CONTROL_DB_ATTACH;
405         request->pad = 0;
406         request->srvid = tdb_flags;
407         request->client_id = 0;
408         request->flags = 0;
409
410         request->rdata.opcode = CTDB_CONTROL_DB_ATTACH;
411         request->rdata.data.db_name = db_name;
412 }
413
414 int ctdb_reply_control_db_attach(struct ctdb_reply_control *reply,
415                                  uint32_t *db_id)
416 {
417         if (reply->rdata.opcode != CTDB_CONTROL_DB_ATTACH) {
418                 return EPROTO;
419         }
420
421         if (reply->status == 0) {
422                 *db_id = reply->rdata.data.db_id;
423         }
424         return reply->status;
425 }
426
427 /* CTDB_CONTROL_SET_CALL */
428
429 /* CTDB_CONTROL_TRAVERSE_START */
430
431 void ctdb_req_control_traverse_start(struct ctdb_req_control *request,
432                                      struct ctdb_traverse_start *traverse)
433 {
434         request->opcode = CTDB_CONTROL_TRAVERSE_START;
435         request->pad = 0;
436         request->srvid = 0;
437         request->client_id = 0;
438         request->flags = 0;
439
440         request->rdata.opcode = CTDB_CONTROL_TRAVERSE_START;
441         request->rdata.data.traverse_start = traverse;
442 }
443
444 int ctdb_reply_control_traverse_start(struct ctdb_reply_control *reply)
445 {
446         return ctdb_reply_control_generic(reply, CTDB_CONTROL_TRAVERSE_START);
447 }
448
449 /* CTDB_CONTROL_TRAVERSE_ALL */
450 /* CTDB_CONTROL_TRAVERSE_DATA */
451
452 /* CTDB_CONTROL_REGISTER_SRVID */
453
454 void ctdb_req_control_register_srvid(struct ctdb_req_control *request,
455                                      uint64_t srvid)
456 {
457         request->opcode = CTDB_CONTROL_REGISTER_SRVID;
458         request->pad = 0;
459         request->srvid = srvid;
460         request->client_id = 0;
461         request->flags = 0;
462
463         request->rdata.opcode = CTDB_CONTROL_REGISTER_SRVID;
464 }
465
466 int ctdb_reply_control_register_srvid(struct ctdb_reply_control *reply)
467 {
468         return ctdb_reply_control_generic(reply, CTDB_CONTROL_REGISTER_SRVID);
469 }
470
471 /* CTDB_CONTROL_DEREGISTER_SRVID */
472
473 void ctdb_req_control_deregister_srvid(struct ctdb_req_control *request,
474                                        uint64_t srvid)
475 {
476         request->opcode = CTDB_CONTROL_DEREGISTER_SRVID;
477         request->pad = 0;
478         request->srvid = srvid;
479         request->client_id = 0;
480         request->flags = 0;
481
482         request->rdata.opcode = CTDB_CONTROL_DEREGISTER_SRVID;
483 }
484
485 int ctdb_reply_control_deregister_srvid(struct ctdb_reply_control *reply)
486 {
487         return ctdb_reply_control_generic(reply,
488                                           CTDB_CONTROL_DEREGISTER_SRVID);
489 }
490
491 /* CTDB_CONTROL_GET_DBNAME */
492
493 void ctdb_req_control_get_dbname(struct ctdb_req_control *request,
494                                  uint32_t db_id)
495 {
496         request->opcode = CTDB_CONTROL_GET_DBNAME;
497         request->pad = 0;
498         request->srvid = 0;
499         request->client_id = 0;
500         request->flags = 0;
501
502         request->rdata.opcode = CTDB_CONTROL_GET_DBNAME;
503         request->rdata.data.db_id = db_id;
504 }
505
506 int ctdb_reply_control_get_dbname(struct ctdb_reply_control *reply,
507                                   TALLOC_CTX *mem_ctx, const char **db_name)
508 {
509         if (reply->rdata.opcode != CTDB_CONTROL_GET_DBNAME) {
510                 return EPROTO;
511         }
512
513         if (reply->status == 0) {
514                 *db_name = talloc_steal(mem_ctx, reply->rdata.data.db_name);
515         }
516         return reply->status;
517 }
518
519 /* CTDB_CONTROL_ENABLE_SEQNUM */
520
521 void ctdb_req_control_enable_seqnum(struct ctdb_req_control *request,
522                                     uint32_t db_id)
523 {
524         request->opcode = CTDB_CONTROL_ENABLE_SEQNUM;
525         request->pad = 0;
526         request->srvid = 0;
527         request->client_id = 0;
528         request->flags = 0;
529
530         request->rdata.opcode = CTDB_CONTROL_ENABLE_SEQNUM;
531         request->rdata.data.db_id = db_id;
532 }
533
534 int ctdb_reply_control_enable_seqnum(struct ctdb_reply_control *reply)
535 {
536         return ctdb_reply_control_generic(reply, CTDB_CONTROL_ENABLE_SEQNUM);
537 }
538
539 /* CTDB_CONTROL_UPDATE_SEQNUM */
540
541 void ctdb_req_control_update_seqnum(struct ctdb_req_control *request,
542                                     uint32_t db_id)
543 {
544         request->opcode = CTDB_CONTROL_UPDATE_SEQNUM;
545         request->pad = 0;
546         request->srvid = 0;
547         request->client_id = 0;
548         request->flags = 0;
549
550         request->rdata.opcode = CTDB_CONTROL_UPDATE_SEQNUM;
551         request->rdata.data.db_id = db_id;
552 }
553
554 int ctdb_reply_control_update_seqnum(struct ctdb_reply_control *reply)
555 {
556         return ctdb_reply_control_generic(reply, CTDB_CONTROL_UPDATE_SEQNUM);
557 }
558
559 /* CTDB_CONTROL_DUMP_MEMORY */
560
561 void ctdb_req_control_dump_memory(struct ctdb_req_control *request)
562 {
563         request->opcode = CTDB_CONTROL_DUMP_MEMORY;
564         request->pad = 0;
565         request->srvid = 0;
566         request->client_id = 0;
567         request->flags = 0;
568
569         request->rdata.opcode = CTDB_CONTROL_DUMP_MEMORY;
570 }
571
572 int ctdb_reply_control_dump_memory(struct ctdb_reply_control *reply,
573                                    TALLOC_CTX *mem_ctx, const char **mem_str)
574 {
575         if (reply->rdata.opcode != CTDB_CONTROL_DUMP_MEMORY) {
576                 return EPROTO;
577         }
578
579         if (reply->status == 0) {
580                 *mem_str = talloc_steal(mem_ctx, reply->rdata.data.mem_str);
581         }
582         return reply->status;
583 }
584
585 /* CTDB_CONTROL_GET_PID */
586
587 void ctdb_req_control_get_pid(struct ctdb_req_control *request)
588 {
589         request->opcode = CTDB_CONTROL_GET_PID;
590         request->pad = 0;
591         request->srvid = 0;
592         request->client_id = 0;
593         request->flags = 0;
594
595         request->rdata.opcode = CTDB_CONTROL_GET_PID;
596 }
597
598 int ctdb_reply_control_get_pid(struct ctdb_reply_control *reply,
599                                pid_t *pid)
600 {
601         if (reply->rdata.opcode != CTDB_CONTROL_GET_PID) {
602                 return EPROTO;
603         }
604
605         *pid = reply->status;
606         reply->status = 0;
607
608         return reply->status;
609 }
610
611 /* CTDB_CONTROL_GET_RECMASTER */
612
613 void ctdb_req_control_get_recmaster(struct ctdb_req_control *request)
614 {
615         request->opcode = CTDB_CONTROL_GET_RECMASTER;
616         request->pad = 0;
617         request->srvid = 0;
618         request->client_id = 0;
619         request->flags = 0;
620
621         request->rdata.opcode = CTDB_CONTROL_GET_RECMASTER;
622 }
623
624 int ctdb_reply_control_get_recmaster(struct ctdb_reply_control *reply,
625                                      uint32_t *recmaster)
626 {
627         if (reply->rdata.opcode != CTDB_CONTROL_GET_RECMASTER) {
628                 return EPROTO;
629         }
630
631         *recmaster = reply->status;
632         reply->status = 0;
633
634         return reply->status;
635 }
636
637 /* CTDB_CONTROL_SET_RECMASTER */
638
639 void ctdb_req_control_set_recmaster(struct ctdb_req_control *request,
640                                     int recmaster)
641 {
642         request->opcode = CTDB_CONTROL_SET_RECMASTER;
643         request->pad = 0;
644         request->srvid = 0;
645         request->client_id = 0;
646         request->flags = 0;
647
648         request->rdata.opcode = CTDB_CONTROL_SET_RECMASTER;
649         request->rdata.data.recmaster = recmaster;
650 }
651
652 int ctdb_reply_control_set_recmaster(struct ctdb_reply_control *reply)
653 {
654         return ctdb_reply_control_generic(reply, CTDB_CONTROL_SET_RECMASTER);
655 }
656
657 /* CTDB_CONTROL_FREEZE */
658
659 void ctdb_req_control_freeze(struct ctdb_req_control *request,
660                              uint32_t priority)
661 {
662         request->opcode = CTDB_CONTROL_FREEZE;
663         request->pad = 0;
664         request->srvid = priority;
665         request->client_id = 0;
666         request->flags = 0;
667
668         request->rdata.opcode = CTDB_CONTROL_FREEZE;
669 }
670
671 int ctdb_reply_control_freeze(struct ctdb_reply_control *reply)
672 {
673         return ctdb_reply_control_generic(reply, CTDB_CONTROL_FREEZE);
674 }
675
676 /* CTDB_CONTROL_GET_PNN */
677
678 void ctdb_req_control_get_pnn(struct ctdb_req_control *request)
679 {
680         request->opcode = CTDB_CONTROL_GET_PNN;
681         request->pad = 0;
682         request->srvid = 0;
683         request->client_id = 0;
684         request->flags = 0;
685
686         request->rdata.opcode = CTDB_CONTROL_GET_PNN;
687 }
688
689 int ctdb_reply_control_get_pnn(struct ctdb_reply_control *reply,
690                                uint32_t *pnn)
691 {
692         if (reply->rdata.opcode != CTDB_CONTROL_GET_PNN) {
693                 return EPROTO;
694         }
695
696         if (reply->status >= 0) {
697                 *pnn = reply->status;
698                 reply->status = 0;
699         }
700         return reply->status;
701 }
702
703 /* CTDB_CONTROL_SHUTDOWN */
704
705 void ctdb_req_control_shutdown(struct ctdb_req_control *request)
706 {
707         request->opcode = CTDB_CONTROL_SHUTDOWN;
708         request->pad = 0;
709         request->srvid = 0;
710         request->client_id = 0;
711         request->flags = CTDB_CTRL_FLAG_NOREPLY;
712
713         request->rdata.opcode = CTDB_CONTROL_SHUTDOWN;
714 }
715
716 int ctdb_reply_control_shutdown(struct ctdb_reply_control *reply)
717 {
718         return ctdb_reply_control_generic(reply, CTDB_CONTROL_SHUTDOWN);
719 }
720
721 /* CTDB_CONTROL_GET_MONMODE */
722
723 void ctdb_req_control_get_monmode(struct ctdb_req_control *request)
724 {
725         request->opcode = CTDB_CONTROL_GET_MONMODE;
726         request->pad = 0;
727         request->srvid = 0;
728         request->client_id = 0;
729         request->flags = 0;
730
731         request->rdata.opcode = CTDB_CONTROL_GET_MONMODE;
732 }
733
734 int ctdb_reply_control_get_monmode(struct ctdb_reply_control *reply,
735                                    int *mon_mode)
736 {
737         if (reply->rdata.opcode != CTDB_CONTROL_GET_MONMODE) {
738                 return EPROTO;
739         }
740
741         if (reply->status >= 0) {
742                 *mon_mode = reply->status;
743                 reply->status = 0;
744         }
745         return reply->status;
746 }
747
748 /* CTDB_CONTROL_TCP_CLIENT */
749
750 void ctdb_req_control_tcp_client(struct ctdb_req_control *request,
751                                  struct ctdb_connection *conn)
752 {
753         request->opcode = CTDB_CONTROL_TCP_CLIENT;
754         request->pad = 0;
755         request->srvid = 0;
756         request->client_id = 0;
757         request->flags = 0;
758
759         request->rdata.opcode = CTDB_CONTROL_TCP_CLIENT;
760         request->rdata.data.conn = conn;
761 }
762
763 int ctdb_reply_control_tcp_client(struct ctdb_reply_control *reply)
764 {
765         return ctdb_reply_control_generic(reply, CTDB_CONTROL_TCP_CLIENT);
766 }
767
768 /* CTDB_CONTROL_TCP_ADD */
769
770 void ctdb_req_control_tcp_add(struct ctdb_req_control *request,
771                               struct ctdb_connection *conn)
772 {
773         request->opcode = CTDB_CONTROL_TCP_ADD;
774         request->pad = 0;
775         request->srvid = 0;
776         request->client_id = 0;
777         request->flags = 0;
778
779         request->rdata.opcode = CTDB_CONTROL_TCP_ADD;
780         request->rdata.data.conn = conn;
781 }
782
783 int ctdb_reply_control_tcp_add(struct ctdb_reply_control *reply)
784 {
785         return ctdb_reply_control_generic(reply, CTDB_CONTROL_TCP_ADD);
786 }
787
788 /* CTDB_CONTROL_TCP_REMOVE */
789
790 void ctdb_req_control_tcp_remove(struct ctdb_req_control *request,
791                                  struct ctdb_connection *conn)
792 {
793         request->opcode = CTDB_CONTROL_TCP_REMOVE;
794         request->pad = 0;
795         request->srvid = 0;
796         request->client_id = 0;
797         request->flags = 0;
798
799         request->rdata.opcode = CTDB_CONTROL_TCP_REMOVE;
800         request->rdata.data.conn = conn;
801 }
802
803 int ctdb_reply_control_tcp_remove(struct ctdb_reply_control *reply)
804 {
805         return ctdb_reply_control_generic(reply, CTDB_CONTROL_TCP_REMOVE);
806 }
807
808 /* CTDB_CONTROL_STARTUP */
809
810 void ctdb_req_control_startup(struct ctdb_req_control *request)
811 {
812         request->opcode = CTDB_CONTROL_STARTUP;
813         request->pad = 0;
814         request->srvid = 0;
815         request->client_id = 0;
816         request->flags = 0;
817
818         request->rdata.opcode = CTDB_CONTROL_STARTUP;
819 }
820
821 int ctdb_reply_control_startup(struct ctdb_reply_control *reply)
822 {
823         return ctdb_reply_control_generic(reply, CTDB_CONTROL_STARTUP);
824 }
825
826 /* CTDB_CONTROL_SET_TUNABLE */
827
828 void ctdb_req_control_set_tunable(struct ctdb_req_control *request,
829                                   struct ctdb_tunable *tunable)
830 {
831         request->opcode = CTDB_CONTROL_SET_TUNABLE;
832         request->pad = 0;
833         request->srvid = 0;
834         request->client_id = 0;
835         request->flags = 0;
836
837         request->rdata.opcode = CTDB_CONTROL_SET_TUNABLE;
838         request->rdata.data.tunable = tunable;
839 }
840
841 int ctdb_reply_control_set_tunable(struct ctdb_reply_control *reply)
842 {
843         return ctdb_reply_control_generic(reply, CTDB_CONTROL_SET_TUNABLE);
844 }
845
846 /* CTDB_CONTROL_GET_TUNABLE */
847
848 void ctdb_req_control_get_tunable(struct ctdb_req_control *request,
849                                   const char *name)
850 {
851         request->opcode = CTDB_CONTROL_GET_TUNABLE;
852         request->pad = 0;
853         request->srvid = 0;
854         request->client_id = 0;
855         request->flags = 0;
856
857         request->rdata.opcode = CTDB_CONTROL_GET_TUNABLE;
858         request->rdata.data.tun_var = discard_const(name);
859 }
860
861 int ctdb_reply_control_get_tunable(struct ctdb_reply_control *reply,
862                                    uint32_t *value)
863 {
864         if (reply->rdata.opcode != CTDB_CONTROL_GET_TUNABLE) {
865                 return EPROTO;
866         }
867
868         if (reply->status == 0) {
869                 *value = reply->rdata.data.tun_value;
870         }
871         return reply->status;
872 }
873
874 /* CTDB_CONTROL_LIST_TUNABLES */
875
876 void ctdb_req_control_list_tunables(struct ctdb_req_control *request)
877 {
878         request->opcode = CTDB_CONTROL_LIST_TUNABLES;
879         request->pad = 0;
880         request->srvid = 0;
881         request->client_id = 0;
882         request->flags = 0;
883
884         request->rdata.opcode = CTDB_CONTROL_LIST_TUNABLES;
885 }
886
887 int ctdb_reply_control_list_tunables(struct ctdb_reply_control *reply,
888                                      TALLOC_CTX *mem_ctx,
889                                      struct ctdb_var_list **tun_var_list)
890 {
891         if (reply->rdata.opcode != CTDB_CONTROL_LIST_TUNABLES) {
892                 return EPROTO;
893         }
894
895         if (reply->status == 0) {
896                 *tun_var_list = talloc_steal(mem_ctx,
897                                              reply->rdata.data.tun_var_list);
898         }
899         return reply->status;
900 }
901
902 /* CTDB_CONTROL_MODIFY_FLAGS */
903
904 void ctdb_req_control_modify_flags(struct ctdb_req_control *request,
905                                    struct ctdb_node_flag_change *flag_change)
906 {
907         request->opcode = CTDB_CONTROL_MODIFY_FLAGS;
908         request->pad = 0;
909         request->srvid = 0;
910         request->client_id = 0;
911         request->flags = 0;
912
913         request->rdata.opcode = CTDB_CONTROL_MODIFY_FLAGS;
914         request->rdata.data.flag_change = flag_change;
915 }
916
917 int ctdb_reply_control_modify_flags(struct ctdb_reply_control *reply)
918 {
919         return ctdb_reply_control_generic(reply, CTDB_CONTROL_MODIFY_FLAGS);
920 }
921
922 /* CTDB_CONTROL_GET_ALL_TUNABLES */
923
924 void ctdb_req_control_get_all_tunables(struct ctdb_req_control *request)
925 {
926         request->opcode = CTDB_CONTROL_GET_ALL_TUNABLES;
927         request->pad = 0;
928         request->srvid = 0;
929         request->client_id = 0;
930         request->flags = 0;
931
932         request->rdata.opcode = CTDB_CONTROL_GET_ALL_TUNABLES;
933 }
934
935 int ctdb_reply_control_get_all_tunables(struct ctdb_reply_control *reply,
936                                         TALLOC_CTX *mem_ctx,
937                                         struct ctdb_tunable_list **tun_list)
938 {
939         if (reply->rdata.opcode != CTDB_CONTROL_GET_ALL_TUNABLES) {
940                 return EPROTO;
941         }
942
943         if (reply->status == 0) {
944                 *tun_list = talloc_steal(mem_ctx, reply->rdata.data.tun_list);
945         }
946         return reply->status;
947 }
948
949 /* CTDB_CONTROL_GET_TCP_TICKLE_LIST */
950
951 void ctdb_req_control_get_tcp_tickle_list(struct ctdb_req_control *request,
952                                           ctdb_sock_addr *addr)
953 {
954         request->opcode = CTDB_CONTROL_GET_TCP_TICKLE_LIST;
955         request->pad = 0;
956         request->srvid = 0;
957         request->client_id = 0;
958         request->flags = 0;
959
960         request->rdata.opcode = CTDB_CONTROL_GET_TCP_TICKLE_LIST;
961         request->rdata.data.addr = addr;
962 }
963
964 int ctdb_reply_control_get_tcp_tickle_list(struct ctdb_reply_control *reply,
965                                            TALLOC_CTX *mem_ctx,
966                                            struct ctdb_tickle_list **tickles)
967 {
968         if (reply->rdata.opcode != CTDB_CONTROL_GET_TCP_TICKLE_LIST) {
969                 return EPROTO;
970         }
971
972         if (reply->status == 0) {
973                 *tickles = talloc_steal(mem_ctx, reply->rdata.data.tickles);
974         }
975         return reply->status;
976 }
977
978 /* CTDB_CONTROL_SET_TCP_TICKLE_LIST */
979
980 void ctdb_req_control_set_tcp_tickle_list(struct ctdb_req_control *request,
981                                           struct ctdb_tickle_list *tickles)
982 {
983         request->opcode = CTDB_CONTROL_SET_TCP_TICKLE_LIST;
984         request->pad = 0;
985         request->srvid = 0;
986         request->client_id = 0;
987         request->flags = 0;
988
989         request->rdata.opcode = CTDB_CONTROL_SET_TCP_TICKLE_LIST;
990         request->rdata.data.tickles = tickles;
991 }
992
993 int ctdb_reply_control_set_tcp_tickle_list(struct ctdb_reply_control *reply)
994 {
995         return ctdb_reply_control_generic(reply,
996                                           CTDB_CONTROL_SET_TCP_TICKLE_LIST);
997 }
998
999 /* CTDB_CONTROL_DB_ATTACH_PERSISTENT */
1000
1001 void ctdb_req_control_db_attach_persistent(struct ctdb_req_control *request,
1002                                            const char *db_name,
1003                                            uint32_t tdb_flags)
1004 {
1005         request->opcode = CTDB_CONTROL_DB_ATTACH_PERSISTENT;
1006         request->pad = 0;
1007         request->srvid = tdb_flags;
1008         request->client_id = 0;
1009         request->flags = 0;
1010
1011         request->rdata.opcode = CTDB_CONTROL_DB_ATTACH_PERSISTENT;
1012         request->rdata.data.db_name = db_name;
1013 }
1014
1015 int ctdb_reply_control_db_attach_persistent(struct ctdb_reply_control *reply,
1016                                             uint32_t *db_id)
1017 {
1018         if (reply->rdata.opcode != CTDB_CONTROL_DB_ATTACH_PERSISTENT) {
1019                 return EPROTO;
1020         }
1021
1022         if (reply->status == 0) {
1023                 *db_id = reply->rdata.data.db_id;
1024         }
1025         return reply->status;
1026 }
1027
1028 /* CTDB_CONTROL_UPDATE_RECORD */
1029
1030 void ctdb_req_control_update_record(struct ctdb_req_control *request,
1031                                     struct ctdb_rec_buffer *recbuf)
1032 {
1033         request->opcode = CTDB_CONTROL_UPDATE_RECORD;
1034         request->pad = 0;
1035         request->srvid = 0;
1036         request->client_id = 0;
1037         request->flags = 0;
1038
1039         request->rdata.opcode = CTDB_CONTROL_UPDATE_RECORD;
1040         request->rdata.data.recbuf = recbuf;
1041 }
1042
1043 int ctdb_reply_control_update_record(struct ctdb_reply_control *reply)
1044 {
1045         return ctdb_reply_control_generic(reply, CTDB_CONTROL_UPDATE_RECORD);
1046 }
1047
1048 /* CTDB_CONTROL_SEND_GRATUITOUS_ARP */
1049
1050 void ctdb_req_control_send_gratuitous_arp(struct ctdb_req_control *request,
1051                                           struct ctdb_addr_info *addr_info)
1052 {
1053         request->opcode = CTDB_CONTROL_SEND_GRATUITOUS_ARP;
1054         request->pad = 0;
1055         request->srvid = 0;
1056         request->client_id = 0;
1057         request->flags = 0;
1058
1059         request->rdata.opcode = CTDB_CONTROL_SEND_GRATUITOUS_ARP;
1060         request->rdata.data.addr_info = addr_info;
1061 }
1062
1063 int ctdb_reply_control_send_gratuitous_arp(struct ctdb_reply_control *reply)
1064 {
1065         return ctdb_reply_control_generic(reply,
1066                                           CTDB_CONTROL_SEND_GRATUITOUS_ARP);
1067 }
1068
1069 /* CTDB_CONTROL_WIPE_DATABASE */
1070
1071 void ctdb_req_control_wipe_database(struct ctdb_req_control *request,
1072                                     struct ctdb_transdb *transdb)
1073 {
1074         request->opcode = CTDB_CONTROL_WIPE_DATABASE;
1075         request->pad = 0;
1076         request->srvid = 0;
1077         request->client_id = 0;
1078         request->flags = 0;
1079
1080         request->rdata.opcode = CTDB_CONTROL_WIPE_DATABASE;
1081         request->rdata.data.transdb = transdb;
1082 }
1083
1084 int ctdb_reply_control_wipe_database(struct ctdb_reply_control *reply)
1085 {
1086         return ctdb_reply_control_generic(reply, CTDB_CONTROL_WIPE_DATABASE);
1087 }
1088
1089 /* CTDB_CONTROL_UPTIME */
1090
1091 void ctdb_req_control_uptime(struct ctdb_req_control *request)
1092 {
1093         request->opcode = CTDB_CONTROL_UPTIME;
1094         request->pad = 0;
1095         request->srvid = 0;
1096         request->client_id = 0;
1097         request->flags = 0;
1098
1099         request->rdata.opcode = CTDB_CONTROL_UPTIME;
1100 }
1101
1102 int ctdb_reply_control_uptime(struct ctdb_reply_control *reply,
1103                               TALLOC_CTX *mem_ctx, struct ctdb_uptime **uptime)
1104 {
1105         if (reply->rdata.opcode != CTDB_CONTROL_UPTIME) {
1106                 return EPROTO;
1107         }
1108
1109         if (reply->status == 0) {
1110                 *uptime = talloc_steal(mem_ctx, reply->rdata.data.uptime);
1111         }
1112         return reply->status;
1113 }
1114
1115 /* CTDB_CONTROL_START_RECOVERY */
1116
1117 void ctdb_req_control_start_recovery(struct ctdb_req_control *request)
1118 {
1119         request->opcode = CTDB_CONTROL_START_RECOVERY;
1120         request->pad = 0;
1121         request->srvid = 0;
1122         request->client_id = 0;
1123         request->flags = 0;
1124
1125         request->rdata.opcode = CTDB_CONTROL_START_RECOVERY;
1126 }
1127
1128 int ctdb_reply_control_start_recovery(struct ctdb_reply_control *reply)
1129 {
1130         return ctdb_reply_control_generic(reply, CTDB_CONTROL_START_RECOVERY);
1131 }
1132
1133 /* CTDB_CONTROL_END_RECOVERY */
1134
1135 void ctdb_req_control_end_recovery(struct ctdb_req_control *request)
1136 {
1137         request->opcode = CTDB_CONTROL_END_RECOVERY;
1138         request->pad = 0;
1139         request->srvid = 0;
1140         request->client_id = 0;
1141         request->flags = 0;
1142
1143         request->rdata.opcode = CTDB_CONTROL_END_RECOVERY;
1144 }
1145
1146 int ctdb_reply_control_end_recovery(struct ctdb_reply_control *reply)
1147 {
1148         return ctdb_reply_control_generic(reply, CTDB_CONTROL_END_RECOVERY);
1149 }
1150
1151 /* CTDB_CONTROL_RELOAD_NODES_FILE */
1152
1153 void ctdb_req_control_reload_nodes_file(struct ctdb_req_control *request)
1154 {
1155         request->opcode = CTDB_CONTROL_RELOAD_NODES_FILE;
1156         request->pad = 0;
1157         request->srvid = 0;
1158         request->client_id = 0;
1159         request->flags = 0;
1160
1161         request->rdata.opcode = CTDB_CONTROL_RELOAD_NODES_FILE;
1162 }
1163
1164 int ctdb_reply_control_reload_nodes_file(struct ctdb_reply_control *reply)
1165 {
1166         return ctdb_reply_control_generic(reply,
1167                                           CTDB_CONTROL_RELOAD_NODES_FILE);
1168 }
1169
1170 /* CTDB_CONTROL_TRY_DELETE_RECORDS */
1171
1172 void ctdb_req_control_try_delete_records(struct ctdb_req_control *request,
1173                                          struct ctdb_rec_buffer *recbuf)
1174 {
1175         request->opcode = CTDB_CONTROL_TRY_DELETE_RECORDS;
1176         request->pad = 0;
1177         request->srvid = 0;
1178         request->client_id = 0;
1179         request->flags = 0;
1180
1181         request->rdata.opcode = CTDB_CONTROL_TRY_DELETE_RECORDS;
1182         request->rdata.data.recbuf = recbuf;
1183 }
1184
1185 int ctdb_reply_control_try_delete_records(struct ctdb_reply_control *reply,
1186                                           TALLOC_CTX *mem_ctx,
1187                                           struct ctdb_rec_buffer **recbuf)
1188 {
1189         if (reply->rdata.opcode != CTDB_CONTROL_TRY_DELETE_RECORDS) {
1190                 return EPROTO;
1191         }
1192
1193         if (reply->status == 0) {
1194                 *recbuf = talloc_steal(mem_ctx, reply->rdata.data.recbuf);
1195         }
1196         return reply->status;
1197 }
1198
1199 /* CTDB_CONTROL_ENABLE_MONITOR */
1200
1201 void ctdb_req_control_enable_monitor(struct ctdb_req_control *request)
1202 {
1203         request->opcode = CTDB_CONTROL_ENABLE_MONITOR;
1204         request->pad = 0;
1205         request->srvid = 0;
1206         request->client_id = 0;
1207         request->flags = 0;
1208
1209         request->rdata.opcode = CTDB_CONTROL_ENABLE_MONITOR;
1210 }
1211
1212 int ctdb_reply_control_enable_monitor(struct ctdb_reply_control *reply)
1213 {
1214         return ctdb_reply_control_generic(reply, CTDB_CONTROL_ENABLE_MONITOR);
1215 }
1216
1217 /* CTDB_CONTROL_DISABLE_MONITOR */
1218
1219 void ctdb_req_control_disable_monitor(struct ctdb_req_control *request)
1220 {
1221         request->opcode = CTDB_CONTROL_DISABLE_MONITOR;
1222         request->pad = 0;
1223         request->srvid = 0;
1224         request->client_id = 0;
1225         request->flags = 0;
1226
1227         request->rdata.opcode = CTDB_CONTROL_DISABLE_MONITOR;
1228 }
1229
1230 int ctdb_reply_control_disable_monitor(struct ctdb_reply_control *reply)
1231 {
1232         return ctdb_reply_control_generic(reply, CTDB_CONTROL_DISABLE_MONITOR);
1233 }
1234
1235 /* CTDB_CONTROL_ADD_PUBLIC_IP */
1236
1237 void ctdb_req_control_add_public_ip(struct ctdb_req_control *request,
1238                                     struct ctdb_addr_info *addr_info)
1239 {
1240         request->opcode = CTDB_CONTROL_ADD_PUBLIC_IP;
1241         request->pad = 0;
1242         request->srvid = 0;
1243         request->client_id = 0;
1244         request->flags = 0;
1245
1246         request->rdata.opcode = CTDB_CONTROL_ADD_PUBLIC_IP;
1247         request->rdata.data.addr_info = addr_info;
1248 }
1249
1250 int ctdb_reply_control_add_public_ip(struct ctdb_reply_control *reply)
1251 {
1252         return ctdb_reply_control_generic(reply, CTDB_CONTROL_ADD_PUBLIC_IP);
1253 }
1254
1255 /* CTDB_CONTROL_DEL_PUBLIC_IP */
1256
1257 void ctdb_req_control_del_public_ip(struct ctdb_req_control *request,
1258                                     struct ctdb_addr_info *addr_info)
1259 {
1260         request->opcode = CTDB_CONTROL_DEL_PUBLIC_IP;
1261         request->pad = 0;
1262         request->srvid = 0;
1263         request->client_id = 0;
1264         request->flags = 0;
1265
1266         request->rdata.opcode = CTDB_CONTROL_DEL_PUBLIC_IP;
1267         request->rdata.data.addr_info = addr_info;
1268 }
1269
1270 int ctdb_reply_control_del_public_ip(struct ctdb_reply_control *reply)
1271 {
1272         return ctdb_reply_control_generic(reply, CTDB_CONTROL_DEL_PUBLIC_IP);
1273 }
1274
1275 /* CTDB_CONTROL_RUN_EVENTSCRIPTS */
1276
1277 void ctdb_req_control_run_eventscripts(struct ctdb_req_control *request,
1278                                        const char *event_str)
1279 {
1280         request->opcode = CTDB_CONTROL_RUN_EVENTSCRIPTS;
1281         request->pad = 0;
1282         request->srvid = 0;
1283         request->client_id = 0;
1284         request->flags = 0;
1285
1286         request->rdata.opcode = CTDB_CONTROL_RUN_EVENTSCRIPTS;
1287         request->rdata.data.event_str = event_str;
1288 }
1289
1290 int ctdb_reply_control_run_eventscripts(struct ctdb_reply_control *reply)
1291 {
1292         return ctdb_reply_control_generic(reply,
1293                                           CTDB_CONTROL_RUN_EVENTSCRIPTS);
1294 }
1295
1296 /* CTDB_CONTROL_GET_CAPABILITIES */
1297
1298 void ctdb_req_control_get_capabilities(struct ctdb_req_control *request)
1299 {
1300         request->opcode = CTDB_CONTROL_GET_CAPABILITIES;
1301         request->pad = 0;
1302         request->srvid = 0;
1303         request->client_id = 0;
1304         request->flags = 0;
1305
1306         request->rdata.opcode = CTDB_CONTROL_GET_CAPABILITIES;
1307 }
1308
1309 int ctdb_reply_control_get_capabilities(struct ctdb_reply_control *reply,
1310                                         uint32_t *caps)
1311 {
1312         if (reply->rdata.opcode != CTDB_CONTROL_GET_CAPABILITIES) {
1313                 return EPROTO;
1314         }
1315
1316         if (reply->status == 0) {
1317                 *caps = reply->rdata.data.caps;
1318         }
1319         return reply->status;
1320 }
1321
1322 /* CTDB_CONTROL_RECD_PING */
1323
1324 void ctdb_req_control_recd_ping(struct ctdb_req_control *request)
1325 {
1326         request->opcode = CTDB_CONTROL_RECD_PING;
1327         request->pad = 0;
1328         request->srvid = 0;
1329         request->client_id = 0;
1330         request->flags = 0;
1331
1332         request->rdata.opcode = CTDB_CONTROL_RECD_PING;
1333 }
1334
1335 int ctdb_reply_control_recd_ping(struct ctdb_reply_control *reply)
1336 {
1337         return ctdb_reply_control_generic(reply, CTDB_CONTROL_RECD_PING);
1338 }
1339
1340 /* CTDB_CONTROL_RELEASE_IP */
1341
1342 void ctdb_req_control_release_ip(struct ctdb_req_control *request,
1343                                  struct ctdb_public_ip *pubip)
1344 {
1345         request->opcode = CTDB_CONTROL_RELEASE_IP;
1346         request->pad = 0;
1347         request->srvid = 0;
1348         request->client_id = 0;
1349         request->flags = 0;
1350
1351         request->rdata.opcode = CTDB_CONTROL_RELEASE_IP;
1352         request->rdata.data.pubip = pubip;
1353 }
1354
1355 int ctdb_reply_control_release_ip(struct ctdb_reply_control *reply)
1356 {
1357         return ctdb_reply_control_generic(reply, CTDB_CONTROL_RELEASE_IP);
1358 }
1359
1360 /* CTDB_CONTROL_TAKEOVER_IP */
1361
1362 void ctdb_req_control_takeover_ip(struct ctdb_req_control *request,
1363                                   struct ctdb_public_ip *pubip)
1364 {
1365         request->opcode = CTDB_CONTROL_TAKEOVER_IP;
1366         request->pad = 0;
1367         request->srvid = 0;
1368         request->client_id = 0;
1369         request->flags = 0;
1370
1371         request->rdata.opcode = CTDB_CONTROL_TAKEOVER_IP;
1372         request->rdata.data.pubip = pubip;
1373 }
1374
1375 int ctdb_reply_control_takeover_ip(struct ctdb_reply_control *reply)
1376 {
1377         return ctdb_reply_control_generic(reply, CTDB_CONTROL_TAKEOVER_IP);
1378 }
1379
1380 /* CTDB_CONTROL_GET_PUBLIC_IPS */
1381
1382 void ctdb_req_control_get_public_ips(struct ctdb_req_control *request)
1383 {
1384         request->opcode = CTDB_CONTROL_GET_PUBLIC_IPS;
1385         request->pad = 0;
1386         request->srvid = 0;
1387         request->client_id = 0;
1388         request->flags = 0;
1389
1390         request->rdata.opcode = CTDB_CONTROL_GET_PUBLIC_IPS;
1391 }
1392
1393 int ctdb_reply_control_get_public_ips(struct ctdb_reply_control *reply,
1394                                       TALLOC_CTX *mem_ctx,
1395                                       struct ctdb_public_ip_list **pubip_list)
1396 {
1397         if (reply->rdata.opcode != CTDB_CONTROL_GET_PUBLIC_IPS) {
1398                 return EPROTO;
1399         }
1400
1401         if (reply->status == 0) {
1402                 *pubip_list = talloc_steal(mem_ctx,
1403                                            reply->rdata.data.pubip_list);
1404         }
1405         return reply->status;
1406 }
1407
1408 /* CTDB_CONTROL_GET_NODEMAP */
1409
1410 void ctdb_req_control_get_nodemap(struct ctdb_req_control *request)
1411 {
1412         request->opcode = CTDB_CONTROL_GET_NODEMAP;
1413         request->pad = 0;
1414         request->srvid = 0;
1415         request->client_id = 0;
1416         request->flags = 0;
1417
1418         request->rdata.opcode = CTDB_CONTROL_GET_NODEMAP;
1419 }
1420
1421 int ctdb_reply_control_get_nodemap(struct ctdb_reply_control *reply,
1422                                    TALLOC_CTX *mem_ctx,
1423                                    struct ctdb_node_map **nodemap)
1424 {
1425         if (reply->rdata.opcode != CTDB_CONTROL_GET_NODEMAP) {
1426                 return EPROTO;
1427         }
1428
1429         if (reply->status == 0) {
1430                 *nodemap = talloc_steal(mem_ctx, reply->rdata.data.nodemap);
1431         }
1432         return reply->status;
1433 }
1434
1435 /* CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS */
1436
1437 void ctdb_req_control_get_event_script_status(struct ctdb_req_control *request,
1438                                               uint32_t event)
1439 {
1440         request->opcode = CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS;
1441         request->pad = 0;
1442         request->srvid = 0;
1443         request->client_id = 0;
1444         request->flags = 0;
1445
1446         request->rdata.opcode = CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS;
1447         request->rdata.data.event = event;
1448 }
1449
1450 int ctdb_reply_control_get_event_script_status(struct ctdb_reply_control *reply,
1451                                                TALLOC_CTX *mem_ctx,
1452                                                struct ctdb_script_list **slist)
1453 {
1454         if (reply->rdata.opcode != CTDB_CONTROL_GET_EVENT_SCRIPT_STATUS) {
1455                 return EPROTO;
1456         }
1457
1458         if (reply->status == 0) {
1459                 *slist = talloc_steal(mem_ctx, reply->rdata.data.script_list);
1460         }
1461         return reply->status;
1462 }
1463
1464 /* CTDB_CONTROL_TRAVERSE_KILL */
1465
1466 void ctdb_req_control_traverse_kill(struct ctdb_req_control *request,
1467                                     struct ctdb_traverse_start *traverse)
1468 {
1469         request->opcode = CTDB_CONTROL_TRAVERSE_KILL;
1470         request->pad = 0;
1471         request->srvid = 0;
1472         request->client_id = 0;
1473         request->flags = 0;
1474
1475         request->rdata.opcode = CTDB_CONTROL_TRAVERSE_KILL;
1476         request->rdata.data.traverse_start = traverse;
1477 }
1478
1479 int ctdb_reply_control_traverse_kill(struct ctdb_reply_control *reply)
1480 {
1481         return ctdb_reply_control_generic(reply, CTDB_CONTROL_TRAVERSE_KILL);
1482 }
1483
1484 /* CTDB_CONTROL_RECD_RECLOCK_LATENCY */
1485
1486 void ctdb_req_control_recd_reclock_latency(struct ctdb_req_control *request,
1487                                            double reclock_latency)
1488 {
1489         request->opcode = CTDB_CONTROL_RECD_RECLOCK_LATENCY;
1490         request->pad = 0;
1491         request->srvid = 0;
1492         request->client_id = 0;
1493         request->flags = 0;
1494
1495         request->rdata.opcode = CTDB_CONTROL_RECD_RECLOCK_LATENCY;
1496         request->rdata.data.reclock_latency = reclock_latency;
1497 }
1498
1499 int ctdb_reply_control_recd_reclock_latency(struct ctdb_reply_control *reply)
1500 {
1501         return ctdb_reply_control_generic(reply,
1502                                           CTDB_CONTROL_RECD_RECLOCK_LATENCY);
1503 }
1504
1505 /* CTDB_CONTROL_GET_RECLOCK_FILE */
1506
1507 void ctdb_req_control_get_reclock_file(struct ctdb_req_control *request)
1508 {
1509         request->opcode = CTDB_CONTROL_GET_RECLOCK_FILE;
1510         request->pad = 0;
1511         request->srvid = 0;
1512         request->client_id = 0;
1513         request->flags = 0;
1514
1515         request->rdata.opcode = CTDB_CONTROL_GET_RECLOCK_FILE;
1516 }
1517
1518 int ctdb_reply_control_get_reclock_file(struct ctdb_reply_control *reply,
1519                                         TALLOC_CTX *mem_ctx,
1520                                         const char **reclock_file)
1521 {
1522         if (reply->rdata.opcode != CTDB_CONTROL_GET_RECLOCK_FILE) {
1523                 return EPROTO;
1524         }
1525
1526         if (reply->status == 0) {
1527                 *reclock_file = talloc_steal(mem_ctx,
1528                                              reply->rdata.data.reclock_file);
1529         }
1530         return reply->status;
1531 }
1532
1533 /* CTDB_CONTROL_STOP_NODE */
1534
1535 void ctdb_req_control_stop_node(struct ctdb_req_control *request)
1536 {
1537         request->opcode = CTDB_CONTROL_STOP_NODE;
1538         request->pad = 0;
1539         request->srvid = 0;
1540         request->client_id = 0;
1541         request->flags = 0;
1542
1543         request->rdata.opcode = CTDB_CONTROL_STOP_NODE;
1544 }
1545
1546 int ctdb_reply_control_stop_node(struct ctdb_reply_control *reply)
1547 {
1548         return ctdb_reply_control_generic(reply, CTDB_CONTROL_STOP_NODE);
1549 }
1550
1551 /* CTDB_CONTROL_CONTINUE_NODE */
1552
1553 void ctdb_req_control_continue_node(struct ctdb_req_control *request)
1554 {
1555         request->opcode = CTDB_CONTROL_CONTINUE_NODE;
1556         request->pad = 0;
1557         request->srvid = 0;
1558         request->client_id = 0;
1559         request->flags = 0;
1560
1561         request->rdata.opcode = CTDB_CONTROL_CONTINUE_NODE;
1562 }
1563
1564 int ctdb_reply_control_continue_node(struct ctdb_reply_control *reply)
1565 {
1566         return ctdb_reply_control_generic(reply, CTDB_CONTROL_CONTINUE_NODE);
1567 }
1568
1569 /* CTDB_CONTROL_SET_LMASTERROLE */
1570
1571 void ctdb_req_control_set_lmasterrole(struct ctdb_req_control *request,
1572                                       uint32_t lmaster_role)
1573 {
1574         request->opcode = CTDB_CONTROL_SET_LMASTERROLE;
1575         request->pad = 0;
1576         request->srvid = 0;
1577         request->client_id = 0;
1578         request->flags = 0;
1579
1580         request->rdata.opcode = CTDB_CONTROL_SET_LMASTERROLE;
1581         request->rdata.data.role = lmaster_role;
1582 }
1583
1584 int ctdb_reply_control_set_lmasterrole(struct ctdb_reply_control *reply)
1585 {
1586         return ctdb_reply_control_generic(reply, CTDB_CONTROL_SET_LMASTERROLE);
1587 }
1588
1589 /* CTDB_CONTROL_SET_RECMASTERROLE */
1590
1591 void ctdb_req_control_set_recmasterrole(struct ctdb_req_control *request,
1592                                         uint32_t recmaster_role)
1593 {
1594         request->opcode = CTDB_CONTROL_SET_RECMASTERROLE;
1595         request->pad = 0;
1596         request->srvid = 0;
1597         request->client_id = 0;
1598         request->flags = 0;
1599
1600         request->rdata.opcode = CTDB_CONTROL_SET_RECMASTERROLE;
1601         request->rdata.data.role = recmaster_role;
1602 }
1603
1604 int ctdb_reply_control_set_recmasterrole(struct ctdb_reply_control *reply)
1605 {
1606         return ctdb_reply_control_generic(reply,
1607                                           CTDB_CONTROL_SET_RECMASTERROLE);
1608 }
1609
1610 /* CTDB_CONTROL_ENABLE_SCRIPT */
1611
1612 void ctdb_req_control_enable_script(struct ctdb_req_control *request,
1613                                     const char *script)
1614 {
1615         request->opcode = CTDB_CONTROL_ENABLE_SCRIPT;
1616         request->pad = 0;
1617         request->srvid = 0;
1618         request->client_id = 0;
1619         request->flags = 0;
1620
1621         request->rdata.opcode = CTDB_CONTROL_ENABLE_SCRIPT;
1622         request->rdata.data.script = script;
1623 }
1624
1625 int ctdb_reply_control_enable_script(struct ctdb_reply_control *reply)
1626 {
1627         return ctdb_reply_control_generic(reply, CTDB_CONTROL_ENABLE_SCRIPT);
1628 }
1629
1630 /* CTDB_CONTROL_DISABLE_SCRIPT */
1631
1632 void ctdb_req_control_disable_script(struct ctdb_req_control *request,
1633                                      const char *script)
1634 {
1635         request->opcode = CTDB_CONTROL_DISABLE_SCRIPT;
1636         request->pad = 0;
1637         request->srvid = 0;
1638         request->client_id = 0;
1639         request->flags = 0;
1640
1641         request->rdata.opcode = CTDB_CONTROL_DISABLE_SCRIPT;
1642         request->rdata.data.script = script;
1643 }
1644
1645 int ctdb_reply_control_disable_script(struct ctdb_reply_control *reply)
1646 {
1647         return ctdb_reply_control_generic(reply, CTDB_CONTROL_DISABLE_SCRIPT);
1648 }
1649
1650 /* CTDB_CONTROL_SET_BAN_STATE */
1651
1652 void ctdb_req_control_set_ban_state(struct ctdb_req_control *request,
1653                                     struct ctdb_ban_state *ban_state)
1654 {
1655         request->opcode = CTDB_CONTROL_SET_BAN_STATE;
1656         request->pad = 0;
1657         request->srvid = 0;
1658         request->client_id = 0;
1659         request->flags = 0;
1660
1661         request->rdata.opcode = CTDB_CONTROL_SET_BAN_STATE;
1662         request->rdata.data.ban_state = ban_state;
1663 }
1664
1665 int ctdb_reply_control_set_ban_state(struct ctdb_reply_control *reply)
1666 {
1667         return ctdb_reply_control_generic(reply, CTDB_CONTROL_SET_BAN_STATE);
1668 }
1669
1670 /* CTDB_CONTROL_GET_BAN_STATE */
1671
1672 void ctdb_req_control_get_ban_state(struct ctdb_req_control *request)
1673 {
1674         request->opcode = CTDB_CONTROL_GET_BAN_STATE;
1675         request->pad = 0;
1676         request->srvid = 0;
1677         request->client_id = 0;
1678         request->flags = 0;
1679
1680         request->rdata.opcode = CTDB_CONTROL_GET_BAN_STATE;
1681 }
1682
1683 int ctdb_reply_control_get_ban_state(struct ctdb_reply_control *reply,
1684                                      TALLOC_CTX *mem_ctx,
1685                                      struct ctdb_ban_state **ban_state)
1686 {
1687         if (reply->rdata.opcode != CTDB_CONTROL_GET_BAN_STATE) {
1688                 return EPROTO;
1689         }
1690
1691         if (reply->status == 0) {
1692                 *ban_state = talloc_steal(mem_ctx,
1693                                           reply->rdata.data.ban_state);
1694         }
1695         return reply->status;
1696 }
1697
1698 /* CTDB_CONTROL_REGISTER_NOTIFY */
1699
1700 void ctdb_req_control_register_notify(struct ctdb_req_control *request,
1701                                       struct ctdb_notify_data *notify)
1702 {
1703         request->opcode = CTDB_CONTROL_REGISTER_NOTIFY;
1704         request->pad = 0;
1705         request->srvid = 0;
1706         request->client_id = 0;
1707         request->flags = 0;
1708
1709         request->rdata.opcode = CTDB_CONTROL_REGISTER_NOTIFY;
1710         request->rdata.data.notify = notify;
1711 }
1712
1713 int ctdb_reply_control_register_notify(struct ctdb_reply_control *reply)
1714 {
1715         return ctdb_reply_control_generic(reply, CTDB_CONTROL_REGISTER_NOTIFY);
1716 }
1717
1718 /* CTDB_CONTROL_DEREGISTER_NOTIFY */
1719
1720 void ctdb_req_control_deregister_notify(struct ctdb_req_control *request,
1721                                         uint64_t srvid)
1722 {
1723         request->opcode = CTDB_CONTROL_DEREGISTER_NOTIFY;
1724         request->pad = 0;
1725         request->srvid = 0;
1726         request->client_id = 0;
1727         request->flags = 0;
1728
1729         request->rdata.opcode = CTDB_CONTROL_DEREGISTER_NOTIFY;
1730         request->rdata.data.srvid = srvid;
1731 }
1732
1733 int ctdb_reply_control_deregister_notify(struct ctdb_reply_control *reply)
1734 {
1735         return ctdb_reply_control_generic(reply,
1736                                           CTDB_CONTROL_DEREGISTER_NOTIFY);
1737 }
1738
1739 /* CTDB_CONTROL_TRANS3_COMMIT */
1740
1741 void ctdb_req_control_trans3_commit(struct ctdb_req_control *request,
1742                                     struct ctdb_rec_buffer *recbuf)
1743 {
1744         request->opcode = CTDB_CONTROL_TRANS3_COMMIT;
1745         request->pad = 0;
1746         request->srvid = 0;
1747         request->client_id = 0;
1748         request->flags = 0;
1749
1750         request->rdata.opcode = CTDB_CONTROL_TRANS3_COMMIT;
1751         request->rdata.data.recbuf = recbuf;
1752 }
1753
1754 int ctdb_reply_control_trans3_commit(struct ctdb_reply_control *reply)
1755 {
1756         return ctdb_reply_control_generic(reply, CTDB_CONTROL_TRANS3_COMMIT);
1757 }
1758
1759 /* CTDB_CONTROL_GET_DB_SEQNUM */
1760
1761 void ctdb_req_control_get_db_seqnum(struct ctdb_req_control *request,
1762                                     uint32_t db_id)
1763 {
1764         request->opcode = CTDB_CONTROL_GET_DB_SEQNUM;
1765         request->pad = 0;
1766         request->srvid = 0;
1767         request->client_id = 0;
1768         request->flags = 0;
1769
1770         request->rdata.opcode = CTDB_CONTROL_GET_DB_SEQNUM;
1771         request->rdata.data.db_id = db_id;
1772 }
1773
1774 int ctdb_reply_control_get_db_seqnum(struct ctdb_reply_control *reply,
1775                                      uint64_t *seqnum)
1776 {
1777         if (reply->rdata.opcode != CTDB_CONTROL_GET_DB_SEQNUM) {
1778                 return EPROTO;
1779         }
1780
1781         if (reply->status == 0) {
1782                 *seqnum = reply->rdata.data.seqnum;
1783         }
1784         return reply->status;
1785 }
1786
1787 /* CTDB_CONTROL_DB_SET_HEALTHY */
1788
1789 void ctdb_req_control_db_set_healthy(struct ctdb_req_control *request,
1790                                      uint32_t db_id)
1791 {
1792         request->opcode = CTDB_CONTROL_DB_SET_HEALTHY;
1793         request->pad = 0;
1794         request->srvid = 0;
1795         request->client_id = 0;
1796         request->flags = 0;
1797
1798         request->rdata.opcode = CTDB_CONTROL_DB_SET_HEALTHY;
1799         request->rdata.data.db_id = db_id;
1800 }
1801
1802 int ctdb_reply_control_db_set_healthy(struct ctdb_reply_control *reply)
1803 {
1804         return ctdb_reply_control_generic(reply, CTDB_CONTROL_DB_SET_HEALTHY);
1805 }
1806
1807 /* CTDB_CONTROL_DB_GET_HEALTH */
1808
1809 void ctdb_req_control_db_get_health(struct ctdb_req_control *request,
1810                                     uint32_t db_id)
1811 {
1812         request->opcode = CTDB_CONTROL_DB_GET_HEALTH;
1813         request->pad = 0;
1814         request->srvid = 0;
1815         request->client_id = 0;
1816         request->flags = 0;
1817
1818         request->rdata.opcode = CTDB_CONTROL_DB_GET_HEALTH;
1819         request->rdata.data.db_id = db_id;
1820 }
1821
1822 int ctdb_reply_control_db_get_health(struct ctdb_reply_control *reply,
1823                                      TALLOC_CTX *mem_ctx, const char **reason)
1824 {
1825         if (reply->rdata.opcode != CTDB_CONTROL_DB_GET_HEALTH) {
1826                 return EPROTO;
1827         }
1828
1829         if (reply->status == 0) {
1830                 *reason = talloc_steal(mem_ctx, reply->rdata.data.reason);
1831         }
1832         return reply->status;
1833 }
1834
1835 /* CTDB_CONTROL_GET_PUBLIC_IP_INFO */
1836
1837 void ctdb_req_control_get_public_ip_info(struct ctdb_req_control *request,
1838                                          ctdb_sock_addr *addr)
1839 {
1840         request->opcode = CTDB_CONTROL_GET_PUBLIC_IP_INFO;
1841         request->pad = 0;
1842         request->srvid = 0;
1843         request->client_id = 0;
1844         request->flags = 0;
1845
1846         request->rdata.opcode = CTDB_CONTROL_GET_PUBLIC_IP_INFO;
1847         request->rdata.data.addr = addr;
1848 }
1849
1850 int ctdb_reply_control_get_public_ip_info(struct ctdb_reply_control *reply,
1851                                           TALLOC_CTX *mem_ctx,
1852                                           struct ctdb_public_ip_info **ipinfo)
1853 {
1854         if (reply->rdata.opcode != CTDB_CONTROL_GET_PUBLIC_IP_INFO) {
1855                 return EPROTO;
1856         }
1857
1858         if (reply->status == 0) {
1859                 *ipinfo = talloc_steal(mem_ctx, reply->rdata.data.ipinfo);
1860         }
1861         return reply->status;
1862 }
1863
1864 /* CTDB_CONTROL_GET_IFACES */
1865
1866 void ctdb_req_control_get_ifaces(struct ctdb_req_control *request)
1867 {
1868         request->opcode = CTDB_CONTROL_GET_IFACES;
1869         request->pad = 0;
1870         request->srvid = 0;
1871         request->client_id = 0;
1872         request->flags = 0;
1873
1874         request->rdata.opcode = CTDB_CONTROL_GET_IFACES;
1875 }
1876
1877 int ctdb_reply_control_get_ifaces(struct ctdb_reply_control *reply,
1878                                   TALLOC_CTX *mem_ctx,
1879                                   struct ctdb_iface_list **iface_list)
1880 {
1881         if (reply->rdata.opcode != CTDB_CONTROL_GET_IFACES) {
1882                 return EPROTO;
1883         }
1884
1885         if (reply->status == 0) {
1886                 *iface_list = talloc_steal(mem_ctx,
1887                                            reply->rdata.data.iface_list);
1888         }
1889         return reply->status;
1890 }
1891
1892 /* CTDB_CONTROL_SET_IFACE_LINK_STATE */
1893
1894 void ctdb_req_control_set_iface_link_state(struct ctdb_req_control *request,
1895                                            struct ctdb_iface *iface)
1896 {
1897         request->opcode = CTDB_CONTROL_SET_IFACE_LINK_STATE;
1898         request->pad = 0;
1899         request->srvid = 0;
1900         request->client_id = 0;
1901         request->flags = 0;
1902
1903         request->rdata.opcode = CTDB_CONTROL_SET_IFACE_LINK_STATE;
1904         request->rdata.data.iface = iface;
1905 }
1906
1907 int ctdb_reply_control_set_iface_link_state(struct ctdb_reply_control *reply)
1908 {
1909         return ctdb_reply_control_generic(reply,
1910                                           CTDB_CONTROL_SET_IFACE_LINK_STATE);
1911 }
1912
1913 /* CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE */
1914
1915 void ctdb_req_control_tcp_add_delayed_update(struct ctdb_req_control *request,
1916                                              struct ctdb_connection *conn)
1917 {
1918         request->opcode = CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE;
1919         request->pad = 0;
1920         request->srvid = 0;
1921         request->client_id = 0;
1922         request->flags = 0;
1923
1924         request->rdata.opcode = CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE;
1925         request->rdata.data.conn = conn;
1926 }
1927
1928 int ctdb_reply_control_tcp_add_delayed_update(struct ctdb_reply_control *reply)
1929 {
1930         return ctdb_reply_control_generic(reply,
1931                                           CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE);
1932 }
1933
1934 /* CTDB_CONTROL_GET_STAT_HISTORY */
1935
1936 void ctdb_req_control_get_stat_history(struct ctdb_req_control *request)
1937 {
1938         request->opcode = CTDB_CONTROL_GET_STAT_HISTORY;
1939         request->pad = 0;
1940         request->srvid = 0;
1941         request->client_id = 0;
1942         request->flags = 0;
1943
1944         request->rdata.opcode = CTDB_CONTROL_GET_STAT_HISTORY;
1945 }
1946
1947 int ctdb_reply_control_get_stat_history(struct ctdb_reply_control *reply,
1948                                         TALLOC_CTX *mem_ctx,
1949                                         struct ctdb_statistics_list **stats_list)
1950 {
1951         if (reply->rdata.opcode != CTDB_CONTROL_GET_STAT_HISTORY) {
1952                 return EPROTO;
1953         }
1954
1955         if (reply->status == 0) {
1956                 *stats_list = talloc_steal(mem_ctx,
1957                                            reply->rdata.data.stats_list);
1958         }
1959         return reply->status;
1960 }
1961
1962 /* CTDB_CONTROL_SCHEDULE_FOR_DELETION */
1963
1964 void ctdb_req_control_schedule_for_deletion(struct ctdb_req_control *request,
1965                                             struct ctdb_key_data *key)
1966 {
1967         request->opcode = CTDB_CONTROL_SCHEDULE_FOR_DELETION;
1968         request->pad = 0;
1969         request->srvid = 0;
1970         request->client_id = 0;
1971         request->flags = 0;
1972
1973         request->rdata.opcode = CTDB_CONTROL_SCHEDULE_FOR_DELETION;
1974         request->rdata.data.key = key;
1975 }
1976
1977 int ctdb_reply_control_schedule_for_deletion(struct ctdb_reply_control *reply)
1978 {
1979         return ctdb_reply_control_generic(reply,
1980                                           CTDB_CONTROL_SCHEDULE_FOR_DELETION);
1981 }
1982
1983 /* CTDB_CONTROL_SET_DB_READONLY */
1984
1985 void ctdb_req_control_set_db_readonly(struct ctdb_req_control *request,
1986                                       uint32_t db_id)
1987 {
1988         request->opcode = CTDB_CONTROL_SET_DB_READONLY;
1989         request->pad = 0;
1990         request->srvid = 0;
1991         request->client_id = 0;
1992         request->flags = 0;
1993
1994         request->rdata.opcode = CTDB_CONTROL_SET_DB_READONLY;
1995         request->rdata.data.db_id = db_id;
1996 }
1997
1998 int ctdb_reply_control_set_db_readonly(struct ctdb_reply_control *reply)
1999 {
2000         return ctdb_reply_control_generic(reply, CTDB_CONTROL_SET_DB_READONLY);
2001 }
2002
2003 /* CTDB_CONTROL_CHECK_SRVIDS */
2004
2005 void ctdb_req_control_check_srvids(struct ctdb_req_control *request,
2006                                    struct ctdb_uint64_array *u64_array)
2007 {
2008         request->opcode = CTDB_CONTROL_CHECK_SRVIDS;
2009         request->pad = 0;
2010         request->srvid = 0;
2011         request->client_id = 0;
2012         request->flags = 0;
2013
2014         request->rdata.opcode = CTDB_CONTROL_CHECK_SRVIDS;
2015         request->rdata.data.u64_array = u64_array;
2016 }
2017
2018 int ctdb_reply_control_check_srvids(struct ctdb_reply_control *reply,
2019                                     TALLOC_CTX *mem_ctx,
2020                                     struct ctdb_uint8_array **u8_array)
2021 {
2022         if (reply->rdata.opcode != CTDB_CONTROL_CHECK_SRVIDS) {
2023                 return EPROTO;
2024         }
2025
2026         if (reply->status == 0) {
2027                 *u8_array = talloc_steal(mem_ctx, reply->rdata.data.u8_array);
2028         }
2029         return reply->status;
2030 }
2031
2032 /* CTDB_CONTROL_TRAVERSE_START_EXT */
2033
2034 void ctdb_req_control_traverse_start_ext(struct ctdb_req_control *request,
2035                                          struct ctdb_traverse_start_ext *traverse)
2036 {
2037         request->opcode = CTDB_CONTROL_TRAVERSE_START_EXT;
2038         request->pad = 0;
2039         request->srvid = 0;
2040         request->client_id = 0;
2041         request->flags = 0;
2042
2043         request->rdata.opcode = CTDB_CONTROL_TRAVERSE_START_EXT;
2044         request->rdata.data.traverse_start_ext = traverse;
2045 }
2046
2047 int ctdb_reply_control_traverse_start_ext(struct ctdb_reply_control *reply)
2048 {
2049         return ctdb_reply_control_generic(reply,
2050                                           CTDB_CONTROL_TRAVERSE_START_EXT);
2051 }
2052
2053 /* CTDB_CONTROL_GET_DB_STATISTICS */
2054
2055 void ctdb_req_control_get_db_statistics(struct ctdb_req_control *request,
2056                                         uint32_t db_id)
2057 {
2058         request->opcode = CTDB_CONTROL_GET_DB_STATISTICS;
2059         request->pad = 0;
2060         request->srvid = 0;
2061         request->client_id = 0;
2062         request->flags = 0;
2063
2064         request->rdata.opcode = CTDB_CONTROL_GET_DB_STATISTICS;
2065         request->rdata.data.db_id = db_id;
2066 }
2067
2068 int ctdb_reply_control_get_db_statistics(struct ctdb_reply_control *reply,
2069                                          TALLOC_CTX *mem_ctx,
2070                                          struct ctdb_db_statistics **dbstats)
2071 {
2072         if (reply->rdata.opcode != CTDB_CONTROL_GET_DB_STATISTICS) {
2073                 return EPROTO;
2074         }
2075
2076         if (reply->status == 0) {
2077                 *dbstats = talloc_steal(mem_ctx, reply->rdata.data.dbstats);
2078         }
2079         return reply->status;
2080 }
2081
2082 /* CTDB_CONTROL_SET_DB_STICKY */
2083
2084 void ctdb_req_control_set_db_sticky(struct ctdb_req_control *request,
2085                                     uint32_t db_id)
2086 {
2087         request->opcode = CTDB_CONTROL_SET_DB_STICKY;
2088         request->pad = 0;
2089         request->srvid = 0;
2090         request->client_id = 0;
2091         request->flags = 0;
2092
2093         request->rdata.opcode = CTDB_CONTROL_SET_DB_STICKY;
2094         request->rdata.data.db_id = db_id;
2095 }
2096
2097 int ctdb_reply_control_set_db_sticky(struct ctdb_reply_control *reply)
2098 {
2099         return ctdb_reply_control_generic(reply, CTDB_CONTROL_SET_DB_STICKY);
2100 }
2101
2102 /* CTDB_CONTROL_RELOAD_PUBLIC_IPS */
2103
2104 void ctdb_req_control_reload_public_ips(struct ctdb_req_control *request)
2105 {
2106         request->opcode = CTDB_CONTROL_RELOAD_PUBLIC_IPS;
2107         request->pad = 0;
2108         request->srvid = 0;
2109         request->client_id = 0;
2110         request->flags = 0;
2111
2112         request->rdata.opcode = CTDB_CONTROL_RELOAD_PUBLIC_IPS;
2113 }
2114
2115 int ctdb_reply_control_reload_public_ips(struct ctdb_reply_control *reply)
2116 {
2117         return ctdb_reply_control_generic(reply,
2118                                           CTDB_CONTROL_RELOAD_PUBLIC_IPS);
2119 }
2120
2121 /* CTDB_CONTROL_TRAVERSE_ALL_EXT */
2122
2123 /* CTDB_CONTROL_RECEIVE_RECORDS */
2124
2125 void ctdb_req_control_receive_records(struct ctdb_req_control *request,
2126                                       struct ctdb_rec_buffer *recbuf)
2127 {
2128         request->opcode = CTDB_CONTROL_RECEIVE_RECORDS;
2129         request->pad = 0;
2130         request->srvid = 0;
2131         request->client_id = 0;
2132         request->flags = 0;
2133
2134         request->rdata.opcode = CTDB_CONTROL_RECEIVE_RECORDS;
2135         request->rdata.data.recbuf = recbuf;
2136 }
2137
2138 int ctdb_reply_control_receive_records(struct ctdb_reply_control *reply,
2139                                        TALLOC_CTX *mem_ctx,
2140                                        struct ctdb_rec_buffer **recbuf)
2141 {
2142         if (reply->rdata.opcode != CTDB_CONTROL_RECEIVE_RECORDS) {
2143                 return EPROTO;
2144         }
2145
2146         if (reply->status == 0) {
2147                 *recbuf = talloc_steal(mem_ctx, reply->rdata.data.recbuf);
2148         }
2149         return reply->status;
2150 }
2151
2152 /* CTDB_CONTROL_IPREALLOCATED */
2153
2154 void ctdb_req_control_ipreallocated(struct ctdb_req_control *request)
2155 {
2156         request->opcode = CTDB_CONTROL_IPREALLOCATED;
2157         request->pad = 0;
2158         request->srvid = 0;
2159         request->client_id = 0;
2160         request->flags = 0;
2161
2162         request->rdata.opcode = CTDB_CONTROL_IPREALLOCATED;
2163 }
2164
2165 int ctdb_reply_control_ipreallocated(struct ctdb_reply_control *reply)
2166 {
2167         return ctdb_reply_control_generic(reply, CTDB_CONTROL_IPREALLOCATED);
2168 }
2169
2170 /* CTDB_CONTROL_GET_RUNSTATE */
2171
2172 void ctdb_req_control_get_runstate(struct ctdb_req_control *request)
2173 {
2174         request->opcode = CTDB_CONTROL_GET_RUNSTATE;
2175         request->pad = 0;
2176         request->srvid = 0;
2177         request->client_id = 0;
2178         request->flags = 0;
2179
2180         request->rdata.opcode = CTDB_CONTROL_GET_RUNSTATE;
2181 }
2182
2183 int ctdb_reply_control_get_runstate(struct ctdb_reply_control *reply,
2184                                     enum ctdb_runstate *runstate)
2185 {
2186         if (reply->rdata.opcode != CTDB_CONTROL_GET_RUNSTATE) {
2187                 return EPROTO;
2188         }
2189
2190         if (reply->status == 0) {
2191                 *runstate = reply->rdata.data.runstate;
2192         }
2193         return reply->status;
2194 }
2195
2196 /* CTDB_CONTROL_DB_DETACH */
2197
2198 void ctdb_req_control_db_detach(struct ctdb_req_control *request,
2199                                 uint32_t db_id)
2200 {
2201         request->opcode = CTDB_CONTROL_DB_DETACH;
2202         request->pad = 0;
2203         request->srvid = 0;
2204         request->client_id = 0;
2205         request->flags = 0;
2206
2207         request->rdata.opcode = CTDB_CONTROL_DB_DETACH;
2208         request->rdata.data.db_id = db_id;
2209 }
2210
2211 int ctdb_reply_control_db_detach(struct ctdb_reply_control *reply)
2212 {
2213         return ctdb_reply_control_generic(reply, CTDB_CONTROL_DB_DETACH);
2214 }
2215
2216 /* CTDB_CONTROL_GET_NODES_FILE */
2217
2218 void ctdb_req_control_get_nodes_file(struct ctdb_req_control *request)
2219 {
2220         request->opcode = CTDB_CONTROL_GET_NODES_FILE;
2221         request->pad = 0;
2222         request->srvid = 0;
2223         request->client_id = 0;
2224         request->flags = 0;
2225
2226         request->rdata.opcode = CTDB_CONTROL_GET_NODES_FILE;
2227 }
2228
2229 int ctdb_reply_control_get_nodes_file(struct ctdb_reply_control *reply,
2230                                       TALLOC_CTX *mem_ctx,
2231                                       struct ctdb_node_map **nodemap)
2232 {
2233         if (reply->rdata.opcode != CTDB_CONTROL_GET_NODES_FILE) {
2234                 return EPROTO;
2235         }
2236
2237         if (reply->status == 0) {
2238                 *nodemap = talloc_steal(mem_ctx, reply->rdata.data.nodemap);
2239         }
2240         return reply->status;
2241 }
2242
2243 /* CTDB_CONTROL_DB_FREEZE */
2244
2245 void ctdb_req_control_db_freeze(struct ctdb_req_control *request,
2246                                 uint32_t db_id)
2247 {
2248         request->opcode = CTDB_CONTROL_DB_FREEZE;
2249         request->pad = 0;
2250         request->srvid = 0;
2251         request->client_id = 0;
2252         request->flags = 0;
2253
2254         request->rdata.opcode = CTDB_CONTROL_DB_FREEZE;
2255         request->rdata.data.db_id = db_id;
2256 }
2257
2258 int ctdb_reply_control_db_freeze(struct ctdb_reply_control *reply)
2259 {
2260         return ctdb_reply_control_generic(reply, CTDB_CONTROL_DB_FREEZE);
2261 }
2262
2263 /* CTDB_CONTROL_DB_THAW */
2264
2265 void ctdb_req_control_db_thaw(struct ctdb_req_control *request,
2266                               uint32_t db_id)
2267 {
2268         request->opcode = CTDB_CONTROL_DB_THAW;
2269         request->pad = 0;
2270         request->srvid = 0;
2271         request->client_id = 0;
2272         request->flags = 0;
2273
2274         request->rdata.opcode = CTDB_CONTROL_DB_THAW;
2275         request->rdata.data.db_id = db_id;
2276 }
2277
2278 int ctdb_reply_control_db_thaw(struct ctdb_reply_control *reply)
2279 {
2280         return ctdb_reply_control_generic(reply, CTDB_CONTROL_DB_THAW);
2281 }
2282
2283 /* CTDB_CONTROL_DB_TRANSACTION_START */
2284
2285 void ctdb_req_control_db_transaction_start(struct ctdb_req_control *request,
2286                                            struct ctdb_transdb *transdb)
2287 {
2288         request->opcode = CTDB_CONTROL_DB_TRANSACTION_START;
2289         request->pad = 0;
2290         request->srvid = 0;
2291         request->client_id = 0;
2292         request->flags = 0;
2293
2294         request->rdata.opcode = CTDB_CONTROL_DB_TRANSACTION_START;
2295         request->rdata.data.transdb = transdb;
2296 }
2297
2298 int ctdb_reply_control_db_transaction_start(struct ctdb_reply_control *reply)
2299 {
2300         return ctdb_reply_control_generic(reply,
2301                                           CTDB_CONTROL_DB_TRANSACTION_START);
2302 }
2303
2304 /* CTDB_CONTROL_DB_TRANSACTION_COMMIT */
2305
2306 void ctdb_req_control_db_transaction_commit(struct ctdb_req_control *request,
2307                                             struct ctdb_transdb *transdb)
2308 {
2309         request->opcode = CTDB_CONTROL_DB_TRANSACTION_COMMIT;
2310         request->pad = 0;
2311         request->srvid = 0;
2312         request->client_id = 0;
2313         request->flags = 0;
2314
2315         request->rdata.opcode = CTDB_CONTROL_DB_TRANSACTION_COMMIT;
2316         request->rdata.data.transdb = transdb;
2317 }
2318
2319 int ctdb_reply_control_db_transaction_commit(struct ctdb_reply_control *reply)
2320 {
2321         return ctdb_reply_control_generic(reply,
2322                                           CTDB_CONTROL_DB_TRANSACTION_COMMIT);
2323 }
2324
2325 /* CTDB_CONTROL_DB_TRANSACTION_CANCEL */
2326
2327 void ctdb_req_control_db_transaction_cancel(struct ctdb_req_control *request,
2328                                             uint32_t db_id)
2329 {
2330         request->opcode = CTDB_CONTROL_DB_TRANSACTION_CANCEL;
2331         request->pad = 0;
2332         request->srvid = 0;
2333         request->client_id = 0;
2334         request->flags = 0;
2335
2336         request->rdata.opcode = CTDB_CONTROL_DB_TRANSACTION_CANCEL;
2337         request->rdata.data.db_id = db_id;
2338 }
2339
2340 int ctdb_reply_control_db_transaction_cancel(struct ctdb_reply_control *reply)
2341 {
2342         return ctdb_reply_control_generic(reply,
2343                                           CTDB_CONTROL_DB_TRANSACTION_CANCEL);
2344 }
2345
2346 /* CTDB_CONTROL_DB_PULL */
2347
2348 void ctdb_req_control_db_pull(struct ctdb_req_control *request,
2349                               struct ctdb_pulldb_ext *pulldb_ext)
2350 {
2351         request->opcode = CTDB_CONTROL_DB_PULL;
2352         request->pad = 0;
2353         request->srvid = 0;
2354         request->client_id = 0;
2355         request->flags = 0;
2356
2357         request->rdata.opcode = CTDB_CONTROL_DB_PULL;
2358         request->rdata.data.pulldb_ext = pulldb_ext;
2359 }
2360
2361 int ctdb_reply_control_db_pull(struct ctdb_reply_control *reply,
2362                                uint32_t *num_records)
2363 {
2364         if (reply->rdata.opcode != CTDB_CONTROL_DB_PULL) {
2365                 return EPROTO;
2366         }
2367
2368         if (reply->status == 0) {
2369                 *num_records = reply->rdata.data.num_records;
2370         }
2371         return reply->status;
2372 }
2373
2374 /* CTDB_CONTROL_DB_PUSH_START */
2375
2376 void ctdb_req_control_db_push_start(struct ctdb_req_control *request,
2377                                     struct ctdb_pulldb_ext *pulldb_ext)
2378 {
2379         request->opcode = CTDB_CONTROL_DB_PUSH_START;
2380         request->pad = 0;
2381         request->srvid = 0;
2382         request->client_id = 0;
2383         request->flags = 0;
2384
2385         request->rdata.opcode = CTDB_CONTROL_DB_PUSH_START;
2386         request->rdata.data.pulldb_ext = pulldb_ext;
2387 }
2388
2389 int ctdb_reply_control_db_push_start(struct ctdb_reply_control *reply)
2390 {
2391         return ctdb_reply_control_generic(reply, CTDB_CONTROL_DB_PUSH_START);
2392 }
2393
2394 /* CTDB_CONTROL_DB_PUSH_CONFIRM */
2395
2396 void ctdb_req_control_db_push_confirm(struct ctdb_req_control *request,
2397                                       uint32_t db_id)
2398 {
2399         request->opcode = CTDB_CONTROL_DB_PUSH_CONFIRM;
2400         request->pad = 0;
2401         request->srvid = 0;
2402         request->client_id = 0;
2403         request->flags = 0;
2404
2405         request->rdata.opcode = CTDB_CONTROL_DB_PUSH_CONFIRM;
2406         request->rdata.data.db_id = db_id;
2407 }
2408
2409 int ctdb_reply_control_db_push_confirm(struct ctdb_reply_control *reply,
2410                                        uint32_t *num_records)
2411 {
2412         if (reply->rdata.opcode != CTDB_CONTROL_DB_PUSH_CONFIRM) {
2413                 return EPROTO;
2414         }
2415
2416         if (reply->status == 0) {
2417                 *num_records = reply->rdata.data.num_records;
2418         }
2419         return reply->status;
2420 }