add a sync wrapper for the getpnn control
[metze/ctdb/wip.git] / libctdb / control.c
1 /*
2    Misc control routines of libctdb
3
4    Copyright (C) Rusty Russell 2010
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 #include <ctdb.h>
20 #include <ctdb_protocol.h>
21 #include "libctdb_private.h"
22
23 /* Remove type-safety macros. */
24 #undef ctdb_getrecmaster_send
25 #undef ctdb_getpnn_send
26
27 int ctdb_getrecmaster_recv(struct ctdb_request *req, uint32_t *recmaster)
28 {
29         struct ctdb_reply_control *reply;
30
31         reply = unpack_reply_control(req, CTDB_CONTROL_GET_RECMASTER);
32         if (!reply || reply->status == -1)
33                 return -1;
34         *recmaster = reply->status;
35         return 0;
36 }
37
38 struct ctdb_request *ctdb_getrecmaster_send(struct ctdb_connection *ctdb,
39                                             uint32_t destnode,
40                                             ctdb_callback_t callback,
41                                             void *private_data)
42 {
43         return new_ctdb_control_request(ctdb, CTDB_CONTROL_GET_RECMASTER,
44                                         destnode, NULL, 0,
45                                         callback, private_data);
46 }
47
48 int ctdb_getpnn_recv(struct ctdb_request *req, uint32_t *pnn)
49 {
50         struct ctdb_reply_control *reply;
51
52         reply = unpack_reply_control(req, CTDB_CONTROL_GET_PNN);
53         if (!reply || reply->status == -1)
54                 return -1;
55         *pnn = reply->status;
56         return 0;
57 }
58
59 struct ctdb_request *ctdb_getpnn_send(struct ctdb_connection *ctdb,
60                                       uint32_t destnode,
61                                       ctdb_callback_t callback,
62                                       void *private_data)
63 {
64         return new_ctdb_control_request(ctdb, CTDB_CONTROL_GET_PNN, destnode,
65                                         NULL, 0, callback, private_data);
66 }