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
31 bool ctdb_getrecmaster_recv(struct ctdb_connection *ctdb,
32 struct ctdb_request *req, uint32_t *recmaster)
34 struct ctdb_reply_control *reply;
36 reply = unpack_reply_control(req, CTDB_CONTROL_GET_RECMASTER);
40 if (reply->status == -1) {
41 DEBUG(ctdb, LOG_ERR, "ctdb_getrecmaster_recv: status -1");
44 *recmaster = reply->status;
48 struct ctdb_request *ctdb_getrecmaster_send(struct ctdb_connection *ctdb,
50 ctdb_callback_t callback,
53 return new_ctdb_control_request(ctdb, CTDB_CONTROL_GET_RECMASTER,
55 callback, private_data);
58 bool ctdb_getrecmode_recv(struct ctdb_connection *ctdb,
59 struct ctdb_request *req, uint32_t *recmode)
61 struct ctdb_reply_control *reply;
63 reply = unpack_reply_control(req, CTDB_CONTROL_GET_RECMODE);
67 if (reply->status == -1) {
68 DEBUG(ctdb, LOG_ERR, "ctdb_getrecmode_recv: status -1");
71 *recmode = reply->status;
75 struct ctdb_request *ctdb_getrecmode_send(struct ctdb_connection *ctdb,
77 ctdb_callback_t callback,
80 return new_ctdb_control_request(ctdb, CTDB_CONTROL_GET_RECMODE,
82 callback, private_data);
85 bool ctdb_getpnn_recv(struct ctdb_connection *ctdb,
86 struct ctdb_request *req, uint32_t *pnn)
88 struct ctdb_reply_control *reply;
90 reply = unpack_reply_control(req, CTDB_CONTROL_GET_PNN);
94 if (reply->status == -1) {
95 DEBUG(ctdb, LOG_ERR, "ctdb_getpnn_recv: status -1");
102 struct ctdb_request *ctdb_getpnn_send(struct ctdb_connection *ctdb,
104 ctdb_callback_t callback,
107 return new_ctdb_control_request(ctdb, CTDB_CONTROL_GET_PNN, destnode,
108 NULL, 0, callback, private_data);
111 bool ctdb_getnodemap_recv(struct ctdb_connection *ctdb,
112 struct ctdb_request *req, struct ctdb_node_map **nodemap)
114 struct ctdb_reply_control *reply;
117 reply = unpack_reply_control(req, CTDB_CONTROL_GET_NODEMAP);
121 if (reply->status == -1) {
122 DEBUG(ctdb, LOG_ERR, "ctdb_getnodemap_recv: status -1");
125 if (reply->datalen == 0) {
126 DEBUG(ctdb, LOG_ERR, "ctdb_getnodemap_recv: returned data is 0 bytes");
130 *nodemap = malloc(reply->datalen);
131 if (*nodemap == NULL) {
132 DEBUG(ctdb, LOG_ERR, "ctdb_getnodemap_recv: failed to malloc buffer");
135 memcpy(*nodemap, reply->data, reply->datalen);
139 struct ctdb_request *ctdb_getnodemap_send(struct ctdb_connection *ctdb,
141 ctdb_callback_t callback,
144 return new_ctdb_control_request(ctdb, CTDB_CONTROL_GET_NODEMAP,
146 NULL, 0, callback, private_data);
149 void ctdb_free_nodemap(struct ctdb_node_map *nodemap)
151 if (nodemap == NULL) {
157 bool ctdb_getpublicips_recv(struct ctdb_connection *ctdb,
158 struct ctdb_request *req,
159 struct ctdb_all_public_ips **ips)
161 struct ctdb_reply_control *reply;
164 reply = unpack_reply_control(req, CTDB_CONTROL_GET_PUBLIC_IPS);
168 if (reply->status == -1) {
169 DEBUG(ctdb, LOG_ERR, "ctdb_getpublicips_recv: status -1");
172 if (reply->datalen == 0) {
173 DEBUG(ctdb, LOG_ERR, "ctdb_getpublicips_recv: returned data is 0 bytes");
177 *ips = malloc(reply->datalen);
179 DEBUG(ctdb, LOG_ERR, "ctdb_getpublicips_recv: failed to malloc buffer");
182 memcpy(*ips, reply->data, reply->datalen);
186 struct ctdb_request *ctdb_getpublicips_send(struct ctdb_connection *ctdb,
188 ctdb_callback_t callback,
191 return new_ctdb_control_request(ctdb, CTDB_CONTROL_GET_PUBLIC_IPS,
193 NULL, 0, callback, private_data);
196 void ctdb_free_publicips(struct ctdb_all_public_ips *ips)