[SCM] CTDB repository - branch libctdb updated - ctdb-1.0.114-87-gce742cb
Ronnie Sahlberg
sahlberg at samba.org
Tue May 11 17:23:51 MDT 2010
The branch, libctdb has been updated
via ce742cbc4090bca736208429ca3abd7f126fe83f (commit)
from 8552ef6c62b77fd333ff8b15f6ff82011dfbd54f (commit)
http://gitweb.samba.org/?p=sahlberg/ctdb.git;a=shortlog;h=libctdb
- Log -----------------------------------------------------------------
commit ce742cbc4090bca736208429ca3abd7f126fe83f
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Wed May 12 09:22:12 2010 +1000
additional cleanup.
create async version of ctdb_set_message_handler()
-----------------------------------------------------------------------
Summary of changes:
client/ctdb_client.c | 31 --------------------
include/ctdb.h | 15 ++++++++-
libctdb/libctdb.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++--
libctdb/tst.c | 2 +
4 files changed, 89 insertions(+), 36 deletions(-)
Changeset truncated at 500 lines:
diff --git a/client/ctdb_client.c b/client/ctdb_client.c
index f8e98b5..a0d5997 100644
--- a/client/ctdb_client.c
+++ b/client/ctdb_client.c
@@ -2220,37 +2220,6 @@ int ctdb_ctrl_get_server_id_list(struct ctdb_context *ctdb,
}
/*
- initialise the ctdb daemon for client applications
-
- NOTE: In current code the daemon does not fork. This is for testing purposes only
- and to simplify the code.
-*/
-struct ctdb_context *ctdb_init(struct event_context *ev)
-{
- int ret;
- struct ctdb_context *ctdb;
-
- ctdb = talloc_zero(ev, struct ctdb_context);
- if (ctdb == NULL) {
- DEBUG(DEBUG_ERR,(__location__ " talloc_zero failed.\n"));
- return NULL;
- }
- ctdb->ev = ev;
- ctdb->idr = idr_init(ctdb);
- CTDB_NO_MEMORY_NULL(ctdb, ctdb->idr);
-
- ret = ctdb_set_socketname(ctdb, CTDB_PATH);
- if (ret != 0) {
- DEBUG(DEBUG_ERR,(__location__ " ctdb_set_socketname failed.\n"));
- talloc_free(ctdb);
- return NULL;
- }
-
- return ctdb;
-}
-
-
-/*
set some ctdb flags
*/
void ctdb_set_flags(struct ctdb_context *ctdb, unsigned flags)
diff --git a/include/ctdb.h b/include/ctdb.h
index df9f54c..807204b 100644
--- a/include/ctdb.h
+++ b/include/ctdb.h
@@ -45,8 +45,19 @@ int ctdb_cancel(ctdb_handle *);
*/
typedef void (*ctdb_message_fn_t)(struct ctdb_context *, uint64_t srvid, TDB_DATA data, void *);
+typedef void (*ctdb_set_message_handler_cb)(int32_t status, void *private_data);
+
+ctdb_handle *
+ctdb_set_message_handler_send(struct ctdb_context *ctdb, uint64_t srvid,
+ ctdb_set_message_handler_cb callback,
+ ctdb_message_fn_t handler, void *private_data);
+
+int ctdb_set_message_handler_recv(struct ctdb_context *ctdb,
+ ctdb_handle *handle);
+
int ctdb_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid, ctdb_message_fn_t handler, void *private_data);
+
int ctdb_remove_message_handler(struct ctdb_context *ctdb, uint64_t srvid, void *private_data);
int ctdb_send_message(struct ctdb_context *ctdb, uint32_t pnn, uint64_t srvid, TDB_DATA data);
@@ -57,12 +68,12 @@ int ctdb_send_message(struct ctdb_context *ctdb, uint32_t pnn, uint64_t srvid, T
/*
* functions to read the recovery master of a node
*/
-typedef void (*get_recmaster_cb)(int32_t status, int32_t recmaster, void *private_data);
+typedef void (*ctdb_get_recmaster_cb)(int32_t status, int32_t recmaster, void *private_data);
ctdb_handle *
ctdb_getrecmaster_send(struct ctdb_context *ctdb,
uint32_t destnode,
- get_recmaster_cb callback,
+ ctdb_get_recmaster_cb callback,
void *private_data);
int ctdb_getrecmaster_recv(struct ctdb_context *ctdb,
ctdb_handle *handle,
diff --git a/libctdb/libctdb.c b/libctdb/libctdb.c
index 40369be..61470de 100644
--- a/libctdb/libctdb.c
+++ b/libctdb/libctdb.c
@@ -144,7 +144,7 @@ static void
ctdb_getrecmaster_recv_cb(struct ctdb_client_control_state *state)
{
struct ctdb_control_cb_data *cb_data = state->async.private_data;
- get_recmaster_cb callback = (get_recmaster_cb)cb_data->callback;
+ ctdb_get_recmaster_cb callback = (ctdb_get_recmaster_cb)cb_data->callback;
callback(0, state->status, cb_data->private_data);
}
@@ -156,7 +156,7 @@ ctdb_getrecmaster_recv_cb(struct ctdb_client_control_state *state)
ctdb_handle *
ctdb_getrecmaster_send(struct ctdb_context *ctdb,
uint32_t destnode,
- get_recmaster_cb callback,
+ ctdb_get_recmaster_cb callback,
void *private_data)
{
struct ctdb_client_control_state *state;
@@ -166,6 +166,11 @@ ctdb_getrecmaster_send(struct ctdb_context *ctdb,
CTDB_CONTROL_GET_RECMASTER, 0, tdb_null,
ctdb, NULL, NULL);
+ if (state == NULL) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to send GET_RECMASTER control\n"));
+ return NULL;
+ }
+
if (callback != NULL) {
cb_data = talloc(state, struct ctdb_control_cb_data);
cb_data->callback = callback;
@@ -194,7 +199,7 @@ int ctdb_getrecmaster_recv(struct ctdb_context *ctdb, ctdb_handle *handle, uint3
*recmaster = (uint32_t)res;
}
- return 0;
+ return state->status;
}
int ctdb_getrecmaster(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *recmaster)
@@ -212,3 +217,69 @@ int ctdb_getrecmaster(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *re
+/*
+ tell the daemon what messaging srvid we will use, and register the message
+ handler function in the client
+*/
+ctdb_handle *
+ctdb_set_message_handler_send(struct ctdb_context *ctdb, uint64_t srvid,
+ ctdb_set_message_handler_cb callback,
+ ctdb_message_fn_t handler,
+ void *private_data)
+
+{
+ struct ctdb_client_control_state *state;
+ struct ctdb_control_cb_data *cb_data;
+
+ if (ctdb_register_message_handler(ctdb, ctdb, srvid, handler, private_data) != 0) {
+ return NULL;
+ }
+
+ state = ctdb_control_send(ctdb, CTDB_CURRENT_NODE, srvid,
+ CTDB_CONTROL_REGISTER_SRVID, 0, tdb_null,
+ ctdb, NULL, NULL);
+
+ if (state == NULL) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to send REGISTER_SRVID control\n"));
+ return NULL;
+ }
+
+ if (callback != NULL) {
+ cb_data = talloc(state, struct ctdb_control_cb_data);
+ cb_data->callback = callback;
+ cb_data->private_data = private_data;
+
+ state->async.fn = ctdb_getrecmaster_recv_cb;
+ state->async.private_data = cb_data;
+ }
+
+ return (ctdb_handle *)state;
+}
+
+int ctdb_set_message_handler_recv(struct ctdb_context *ctdb, ctdb_handle *handle)
+{
+ 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 || res != 0) {
+ DEBUG(DEBUG_ERR,(__location__ " ctdb_set_message_handler_recv failed\n"));
+ return -1;
+ }
+
+ return state->status;
+}
+
+int ctdb_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid, ctdb_message_fn_t handler, void *private_data)
+{
+ struct ctdb_client_control_state *state;
+
+ state = ctdb_set_message_handler_send(ctdb, srvid, NULL, handler, private_data);
+ if (state == NULL) {
+ DEBUG(DEBUG_ERR,(__location__ " ctdb_set_message_handler_send() failed.\n"));
+ return -1;
+ }
+
+ return ctdb_set_message_handler_recv(ctdb, state);
+}
diff --git a/libctdb/tst.c b/libctdb/tst.c
index c6dde12..51829b5 100644
--- a/libctdb/tst.c
+++ b/libctdb/tst.c
@@ -1,6 +1,8 @@
#include <stdio.h>
#include <stdint.h>
#include <poll.h>
+#include <fcntl.h>
+#include "lib/tdb/include/tdb.h"
#include "include/ctdb.h"
--
CTDB repository
More information about the samba-cvs
mailing list