From: Ronnie Sahlberg Date: Tue, 11 May 2010 01:26:48 +0000 (+1000) Subject: add libctdb getrecmaster control recv function and X-Git-Url: http://git.samba.org/?p=sahlberg%2Fctdb.git;a=commitdiff_plain;h=2dbbc98985783dc14462371ffaf1febf2484a79d add libctdb getrecmaster control recv function and a sync version of getrecmaster --- diff --git a/include/libctdb.h b/include/libctdb.h index 928da565..6a1926b3 100644 --- a/include/libctdb.h +++ b/include/libctdb.h @@ -42,10 +42,17 @@ typedef void (*get_recmaster_cb)(int32_t status, int32_t recmaster, void *privat libctdb_handle * -libctdb_getrecmaster_cb_send(struct ctdb_context *ctdb, +libctdb_getrecmaster_send(struct ctdb_context *ctdb, uint32_t destnode, get_recmaster_cb callback, void *private_data); +int libctdb_getrecmaster_recv(struct ctdb_context *ctdb, + libctdb_handle *handle, + uint32_t *recmaster); +int libctdb_getrecmaster(struct ctdb_context *ctdb, + uint32_t destnode, + uint32_t *recmaster); + int libctdb_cancel(libctdb_handle *); diff --git a/libctdb/libctdb.c b/libctdb/libctdb.c index 994c0745..e3a7c1ab 100644 --- a/libctdb/libctdb.c +++ b/libctdb/libctdb.c @@ -153,7 +153,7 @@ libctdb_getrecmaster_recv_cb(struct ctdb_client_control_state *state) get the recovery master of a remote node */ libctdb_handle * -libctdb_getrecmaster_cb_send(struct ctdb_context *ctdb, +libctdb_getrecmaster_send(struct ctdb_context *ctdb, uint32_t destnode, get_recmaster_cb callback, void *private_data) @@ -165,17 +165,49 @@ libctdb_getrecmaster_cb_send(struct ctdb_context *ctdb, CTDB_CONTROL_GET_RECMASTER, 0, tdb_null, ctdb, NULL, NULL); - cb_data = talloc(state, struct libctdb_control_cb_data); - cb_data->callback = callback; - cb_data->private_data = private_data; + if (callback != NULL) { + cb_data = talloc(state, struct libctdb_control_cb_data); + cb_data->callback = callback; + cb_data->private_data = private_data; - state->async.fn = libctdb_getrecmaster_recv_cb; - state->async.private_data = cb_data; + state->async.fn = libctdb_getrecmaster_recv_cb; + state->async.private_data = cb_data; + } return (libctdb_handle *)state; } +int libctdb_getrecmaster_recv(struct ctdb_context *ctdb, libctdb_handle *handle, uint32_t *recmaster) +{ + struct ctdb_client_control_state *state = talloc_get_type(handle, struct ctdb_client_control_state); + int ret; + int32_t res; + + ret = ctdb_control_recv(ctdb, state, state, NULL, &res, NULL); + if (ret != 0) { + DEBUG(DEBUG_ERR,(__location__ " libctdb_getrecmaster_recv failed\n")); + return -1; + } + + if (recmaster) { + *recmaster = (uint32_t)res; + } + + return 0; +} + +int libctdb_getrecmaster(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *recmaster) +{ + struct ctdb_client_control_state *state; + + state = libctdb_getrecmaster_send(ctdb, destnode, NULL, recmaster); + if (state == NULL) { + DEBUG(DEBUG_ERR,(__location__ " libctdb_getrecmaster_send() failed.\n")); + return -1; + } + return libctdb_getrecmaster_recv(ctdb, state, recmaster); +} diff --git a/libctdb/tst.c b/libctdb/tst.c index 6781746b..251c3768 100644 --- a/libctdb/tst.c +++ b/libctdb/tst.c @@ -20,7 +20,7 @@ int main(int argc, char *argv[]) pfd.fd = libctdb_get_fd(ctdb_context); - state = libctdb_getrecmaster_cb_send(ctdb_context, 0, rm_cb, NULL); + state = libctdb_getrecmaster_send(ctdb_context, 0, rm_cb, NULL); for (;;) { pfd.events = libctdb_which_events(ctdb_context);