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/>.
25 /* FIXME: Find a way to share more code here. */
26 struct ctdb_getrecmaster {
32 static bool ctdb_service_flush(struct ctdb_connection *ctdb)
36 fds.fd = ctdb_get_fd(ctdb);
37 fds.events = ctdb_which_events(ctdb);
38 if (poll(&fds, 1, -1) < 0) {
39 /* Signalled is OK, other error is bad. */
40 return errno == EINTR;
42 return ctdb_service(ctdb, fds.revents) >= 0;
45 static void getrecmaster_done(int status, uint32_t recmaster, void *priv_data)
47 struct ctdb_getrecmaster *grm = priv_data;
48 *grm->recmaster = recmaster;
53 int ctdb_getrecmaster(struct ctdb_connection *ctdb,
54 uint32_t destnode, uint32_t *recmaster)
56 struct ctdb_request *req;
57 struct ctdb_getrecmaster grm;
60 grm.recmaster = recmaster;
61 req = ctdb_getrecmaster_send(ctdb, destnode, getrecmaster_done, &grm);
66 if (!ctdb_service_flush(ctdb)) {
74 struct ctdb_attachdb {
77 struct ctdb_db *ctdb_db;
80 static void attachdb_sync_done(int status,
81 struct ctdb_db *ctdb_db, void *private_data)
83 struct ctdb_attachdb *atb = private_data;
84 atb->ctdb_db = ctdb_db;
89 struct ctdb_db *ctdb_attachdb(struct ctdb_connection *ctdb,
90 const char *name, int persistent,
93 struct ctdb_request *req;
94 struct ctdb_attachdb atb;
97 req = ctdb_attachdb_send(ctdb, name, persistent, tdb_flags,
98 attachdb_sync_done, &atb);
103 if (!ctdb_service_flush(ctdb)) {