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);
45 DEBUG(ctdb, LOG_ERR, "ctdb_synchronous: poll failed");
48 if (ctdb_service(ctdb, fds.revents) < 0) {
49 ctdb_request_free(ctdb, req);
56 static void set(struct ctdb_connection *ctdb,
57 struct ctdb_request *req, bool *done)
62 bool ctdb_getrecmaster(struct ctdb_connection *ctdb,
63 uint32_t destnode, uint32_t *recmaster)
65 struct ctdb_request *req;
69 req = synchronous(ctdb,
70 ctdb_getrecmaster_send(ctdb, destnode, set, &done),
73 ret = ctdb_getrecmaster_recv(ctdb, req, recmaster);
74 ctdb_request_free(ctdb, req);
79 struct ctdb_db *ctdb_attachdb(struct ctdb_connection *ctdb,
80 const char *name, int persistent,
83 struct ctdb_request *req;
85 struct ctdb_db *ret = NULL;
87 req = synchronous(ctdb,
88 ctdb_attachdb_send(ctdb, name, persistent, tdb_flags,
92 ret = ctdb_attachdb_recv(ctdb, req);
93 ctdb_request_free(ctdb, req);
98 bool ctdb_getpnn(struct ctdb_connection *ctdb,
99 uint32_t destnode, uint32_t *pnn)
101 struct ctdb_request *req;
105 req = synchronous(ctdb,
106 ctdb_getpnn_send(ctdb, destnode, set, &done),
109 ret = ctdb_getpnn_recv(ctdb, req, pnn);
110 ctdb_request_free(ctdb, req);