3 Utility functions to connect to the ctdb daemon
5 Copyright (C) Andrew Tridgell 2006
6 Copyright (C) Ronnie sahlberg 2010
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, see <http://www.gnu.org/licenses/>.
24 #include "include/libctdb.h"
25 #include "lib/events/events.h"
26 #include "include/ctdb_private.h"
28 struct ctdb_context *libctdb_connect(const char *addr)
30 struct event_context *ev;
31 struct ctdb_context *ctdb;
34 ev = event_context_init(NULL);
39 fprintf(stderr, "Failed to init ctdb\n");
43 ret = ctdb_set_socketname(ctdb, addr);
45 fprintf(stderr, __location__ " ctdb_set_socketname failed - %s\n", ctdb_errstr(ctdb));
50 ret = ctdb_socket_connect(ctdb);
52 fprintf(stderr, __location__ " Failed to connect to daemon\n");
61 int libctdb_get_fd(struct ctdb_context *ctdb)
63 return ctdb->daemon.sd;
66 int libctdb_which_events(struct ctdb_context *ctdb)
68 if (ctdb_queue_length(ctdb->daemon.queue) > 0) {
69 return POLLIN|POLLOUT;
78 initialise the ctdb daemon for client applications
80 struct ctdb_context *ctdb_init(struct event_context *ev)
83 struct ctdb_context *ctdb;
85 ctdb = talloc_zero(ev, struct ctdb_context);
87 DEBUG(DEBUG_ERR,(__location__ " talloc_zero failed.\n"));
91 ctdb->idr = idr_init(ctdb);
92 CTDB_NO_MEMORY_NULL(ctdb, ctdb->idr);
94 ret = ctdb_set_socketname(ctdb, CTDB_PATH);
96 DEBUG(DEBUG_ERR,(__location__ " ctdb_set_socketname failed.\n"));
109 * This is a bit hairy. due to the way ctdbd uses events.
110 * ctdbd quite frequently uses
111 * event_add_timed(... timeval_zero() ...)
113 * for example once it has finished reading off a full pdu off the
114 * domain socket, before calling the actual recdeive function.
116 * we probably need a new event function to handle these timed events
117 * event_loop_all_queued() or similar
119 int libctdb_service(struct ctdb_context *ctdb)
123 ret = event_loop_once(ctdb->ev);
124 ret = event_loop_once(ctdb->ev);
131 int libctdb_cancel(libctdb_handle *handle)
137 struct libctdb_control_cb_data {
143 libctdb_getrecmaster_recv_cb(struct ctdb_client_control_state *state)
145 struct libctdb_control_cb_data *cb_data = state->async.private_data;
146 get_recmaster_cb callback = (get_recmaster_cb)cb_data->callback;
148 callback(0, state->status, cb_data->private_data);
153 get the recovery master of a remote node
156 libctdb_getrecmaster_cb_send(struct ctdb_context *ctdb,
158 get_recmaster_cb callback,
161 struct ctdb_client_control_state *state;
162 struct libctdb_control_cb_data *cb_data;
164 state = ctdb_control_send(ctdb, destnode, 0,
165 CTDB_CONTROL_GET_RECMASTER, 0, tdb_null,
168 cb_data = talloc(state, struct libctdb_control_cb_data);
169 cb_data->callback = callback;
170 cb_data->private_data = private_data;
172 state->async.fn = libctdb_getrecmaster_recv_cb;
173 state->async.private_data = cb_data;
175 return (libctdb_handle *)state;