2 Misc control routines of libctdb
4 Copyright (C) Rusty Russell 2010
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include <ctdb_protocol.h>
22 #include "libctdb_private.h"
24 /* Remove type-safety macros. */
25 #undef ctdb_getrecmaster_send
26 #undef ctdb_getrecmode_send
27 #undef ctdb_getpnn_send
28 #undef ctdb_getnodemap_send
29 #undef ctdb_getpublicips_send
30 #undef ctdb_getdbseqnum_send
32 bool ctdb_getrecmaster_recv(struct ctdb_connection *ctdb,
33 struct ctdb_request *req, uint32_t *recmaster)
35 struct ctdb_reply_control *reply;
37 reply = unpack_reply_control(req, CTDB_CONTROL_GET_RECMASTER);
41 if (reply->status == -1) {
42 DEBUG(ctdb, LOG_ERR, "ctdb_getrecmaster_recv: status -1");
45 *recmaster = reply->status;
49 struct ctdb_request *ctdb_getrecmaster_send(struct ctdb_connection *ctdb,
51 ctdb_callback_t callback,
54 return new_ctdb_control_request(ctdb, CTDB_CONTROL_GET_RECMASTER,
56 callback, private_data);
59 bool ctdb_getrecmode_recv(struct ctdb_connection *ctdb,
60 struct ctdb_request *req, uint32_t *recmode)
62 struct ctdb_reply_control *reply;
64 reply = unpack_reply_control(req, CTDB_CONTROL_GET_RECMODE);
68 if (reply->status == -1) {
69 DEBUG(ctdb, LOG_ERR, "ctdb_getrecmode_recv: status -1");
72 *recmode = reply->status;
76 struct ctdb_request *ctdb_getrecmode_send(struct ctdb_connection *ctdb,
78 ctdb_callback_t callback,
81 return new_ctdb_control_request(ctdb, CTDB_CONTROL_GET_RECMODE,
83 callback, private_data);
86 bool ctdb_getpnn_recv(struct ctdb_connection *ctdb,
87 struct ctdb_request *req, uint32_t *pnn)
89 struct ctdb_reply_control *reply;
91 reply = unpack_reply_control(req, CTDB_CONTROL_GET_PNN);
95 if (reply->status == -1) {
96 DEBUG(ctdb, LOG_ERR, "ctdb_getpnn_recv: status -1");
103 struct ctdb_request *ctdb_getpnn_send(struct ctdb_connection *ctdb,
105 ctdb_callback_t callback,
108 return new_ctdb_control_request(ctdb, CTDB_CONTROL_GET_PNN, destnode,
109 NULL, 0, callback, private_data);
112 bool ctdb_getnodemap_recv(struct ctdb_connection *ctdb,
113 struct ctdb_request *req, struct ctdb_node_map **nodemap)
115 struct ctdb_reply_control *reply;
118 reply = unpack_reply_control(req, CTDB_CONTROL_GET_NODEMAP);
122 if (reply->status == -1) {
123 DEBUG(ctdb, LOG_ERR, "ctdb_getnodemap_recv: status -1");
126 if (reply->datalen == 0) {
127 DEBUG(ctdb, LOG_ERR, "ctdb_getnodemap_recv: returned data is 0 bytes");
131 *nodemap = malloc(reply->datalen);
132 if (*nodemap == NULL) {
133 DEBUG(ctdb, LOG_ERR, "ctdb_getnodemap_recv: failed to malloc buffer");
136 memcpy(*nodemap, reply->data, reply->datalen);
140 struct ctdb_request *ctdb_getnodemap_send(struct ctdb_connection *ctdb,
142 ctdb_callback_t callback,
145 return new_ctdb_control_request(ctdb, CTDB_CONTROL_GET_NODEMAP,
147 NULL, 0, callback, private_data);
150 void ctdb_free_nodemap(struct ctdb_node_map *nodemap)
152 if (nodemap == NULL) {
158 bool ctdb_getpublicips_recv(struct ctdb_connection *ctdb,
159 struct ctdb_request *req,
160 struct ctdb_all_public_ips **ips)
162 struct ctdb_reply_control *reply;
165 reply = unpack_reply_control(req, CTDB_CONTROL_GET_PUBLIC_IPS);
169 if (reply->status == -1) {
170 DEBUG(ctdb, LOG_ERR, "ctdb_getpublicips_recv: status -1");
173 if (reply->datalen == 0) {
174 DEBUG(ctdb, LOG_ERR, "ctdb_getpublicips_recv: returned data is 0 bytes");
178 *ips = malloc(reply->datalen);
180 DEBUG(ctdb, LOG_ERR, "ctdb_getpublicips_recv: failed to malloc buffer");
183 memcpy(*ips, reply->data, reply->datalen);
187 struct ctdb_request *ctdb_getpublicips_send(struct ctdb_connection *ctdb,
189 ctdb_callback_t callback,
192 return new_ctdb_control_request(ctdb, CTDB_CONTROL_GET_PUBLIC_IPS,
194 NULL, 0, callback, private_data);
197 void ctdb_free_publicips(struct ctdb_all_public_ips *ips)
205 bool ctdb_getdbseqnum_recv(struct ctdb_connection *ctdb,
206 struct ctdb_request *req, uint64_t *seqnum)
208 struct ctdb_reply_control *reply;
210 reply = unpack_reply_control(req, CTDB_CONTROL_GET_DB_SEQNUM);
214 if (reply->status == -1) {
215 DEBUG(ctdb, LOG_ERR, "ctdb_getdbseqnum_recv: status -1");
219 if (reply->datalen != sizeof(uint64_t)) {
220 DEBUG(ctdb, LOG_ERR, "ctdb_getdbseqnum wrong size of data was %d but expected %d bytes", reply->datalen, (int)sizeof(uint64_t));
224 *seqnum = *((uint64_t *)reply->data);
229 struct ctdb_request *ctdb_getdbseqnum_send(struct ctdb_connection *ctdb,
232 ctdb_callback_t callback,
237 *((uint32_t *)&indata) = dbid;
239 return new_ctdb_control_request(ctdb, CTDB_CONTROL_GET_DB_SEQNUM,
240 destnode, &indata, sizeof(uint64_t),
241 callback, private_data);