2 synchronous wrappers for 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/>.
24 #include "libctdb_private.h"
26 /* On failure, frees req and returns NULL. */
27 static struct ctdb_request *synchronous(struct ctdb_connection *ctdb,
28 struct ctdb_request *req,
33 /* Pass through allocation failures. */
37 fds.fd = ctdb_get_fd(ctdb);
39 fds.events = ctdb_which_events(ctdb);
40 if (poll(&fds, 1, -1) < 0) {
41 /* Signalled is OK, other error is bad. */
44 ctdb_request_free(ctdb, req);
47 if (ctdb_service(ctdb, fds.revents) < 0) {
48 ctdb_request_free(ctdb, req);
55 static void set(struct ctdb_connection *ctdb,
56 struct ctdb_request *req, bool *done)
61 int ctdb_getrecmaster(struct ctdb_connection *ctdb,
62 uint32_t destnode, uint32_t *recmaster)
64 struct ctdb_request *req;
68 req = synchronous(ctdb,
69 ctdb_getrecmaster_send(ctdb, destnode, set, &done),
72 ret = ctdb_getrecmaster_recv(ctdb, req, recmaster);
73 ctdb_request_free(ctdb, req);
78 struct ctdb_db *ctdb_attachdb(struct ctdb_connection *ctdb,
79 const char *name, int persistent,
82 struct ctdb_request *req;
84 struct ctdb_db *ret = NULL;
86 req = synchronous(ctdb,
87 ctdb_attachdb_send(ctdb, name, persistent, tdb_flags,
91 ret = ctdb_attachdb_recv(ctdb, req);
92 ctdb_request_free(ctdb, req);
97 int ctdb_getpnn(struct ctdb_connection *ctdb,
98 uint32_t destnode, uint32_t *pnn)
100 struct ctdb_request *req;
104 req = synchronous(ctdb,
105 ctdb_getpnn_send(ctdb, destnode, set, &done),
108 ret = ctdb_getpnn_recv(ctdb, req, pnn);
109 ctdb_request_free(ctdb, req);