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_getpnn_send
27 #undef ctdb_getnodemap_send
28 #undef ctdb_getpublicips_send
30 bool ctdb_getrecmaster_recv(struct ctdb_connection *ctdb,
31 struct ctdb_request *req, uint32_t *recmaster)
33 struct ctdb_reply_control *reply;
35 reply = unpack_reply_control(ctdb, req, CTDB_CONTROL_GET_RECMASTER);
39 if (reply->status == -1) {
40 DEBUG(ctdb, LOG_ERR, "ctdb_getrecmaster_recv: status -1");
43 *recmaster = reply->status;
47 struct ctdb_request *ctdb_getrecmaster_send(struct ctdb_connection *ctdb,
49 ctdb_callback_t callback,
52 return new_ctdb_control_request(ctdb, CTDB_CONTROL_GET_RECMASTER,
54 callback, private_data);
57 bool ctdb_getpnn_recv(struct ctdb_connection *ctdb,
58 struct ctdb_request *req, uint32_t *pnn)
60 struct ctdb_reply_control *reply;
62 reply = unpack_reply_control(ctdb, req, CTDB_CONTROL_GET_PNN);
66 if (reply->status == -1) {
67 DEBUG(ctdb, LOG_ERR, "ctdb_getpnn_recv: status -1");
74 struct ctdb_request *ctdb_getpnn_send(struct ctdb_connection *ctdb,
76 ctdb_callback_t callback,
79 return new_ctdb_control_request(ctdb, CTDB_CONTROL_GET_PNN, destnode,
80 NULL, 0, callback, private_data);
83 bool ctdb_getnodemap_recv(struct ctdb_connection *ctdb,
84 struct ctdb_request *req, struct ctdb_node_map **nodemap)
86 struct ctdb_reply_control *reply;
89 reply = unpack_reply_control(ctdb, req, CTDB_CONTROL_GET_NODEMAP);
93 if (reply->status == -1) {
94 DEBUG(ctdb, LOG_ERR, "ctdb_getnodemap_recv: status -1");
97 if (reply->datalen == 0) {
98 DEBUG(ctdb, LOG_ERR, "ctdb_getnodemap_recv: returned data is 0 bytes");
102 *nodemap = malloc(reply->datalen);
103 if (*nodemap == NULL) {
104 DEBUG(ctdb, LOG_ERR, "ctdb_getnodemap_recv: failed to malloc buffer");
107 memcpy(*nodemap, reply->data, reply->datalen);
111 struct ctdb_request *ctdb_getnodemap_send(struct ctdb_connection *ctdb,
113 ctdb_callback_t callback,
116 return new_ctdb_control_request(ctdb, CTDB_CONTROL_GET_NODEMAP,
118 NULL, 0, callback, private_data);
121 void ctdb_free_nodemap(struct ctdb_node_map *nodemap)
123 if (nodemap == NULL) {
129 bool ctdb_getpublicips_recv(struct ctdb_connection *ctdb,
130 struct ctdb_request *req,
131 struct ctdb_all_public_ips **ips)
133 struct ctdb_reply_control *reply;
136 reply = unpack_reply_control(ctdb, req, CTDB_CONTROL_GET_PUBLIC_IPS);
140 if (reply->status == -1) {
141 DEBUG(ctdb, LOG_ERR, "ctdb_getpublicips_recv: status -1");
144 if (reply->datalen == 0) {
145 DEBUG(ctdb, LOG_ERR, "ctdb_getpublicips_recv: returned data is 0 bytes");
149 *ips = malloc(reply->datalen);
151 DEBUG(ctdb, LOG_ERR, "ctdb_getpublicips_recv: failed to malloc buffer");
154 memcpy(*ips, reply->data, reply->datalen);
158 struct ctdb_request *ctdb_getpublicips_send(struct ctdb_connection *ctdb,
160 ctdb_callback_t callback,
163 return new_ctdb_control_request(ctdb, CTDB_CONTROL_GET_PUBLIC_IPS,
165 NULL, 0, callback, private_data);
168 void ctdb_free_publicips(struct ctdb_all_public_ips *ips)