[SCM] CTDB repository - branch libctdb updated - ctdb-1.0.114-113-g029675b
Ronnie Sahlberg
sahlberg at samba.org
Mon May 17 20:20:51 MDT 2010
The branch, libctdb has been updated
via 029675b432cb455e466bca723db0dc90fdbf54b5 (commit)
from e9418d95052490b0d8de98cb4c37b74f25ea8842 (commit)
http://gitweb.samba.org/?p=sahlberg/ctdb.git;a=shortlog;h=libctdb
- Log -----------------------------------------------------------------
commit 029675b432cb455e466bca723db0dc90fdbf54b5
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Tue May 18 12:19:12 2010 +1000
Remove ctdb_set_callback() from the public API and provide the callback as part
of the *_send() signature.
-----------------------------------------------------------------------
Summary of changes:
client/ctdb_client.c | 2 +-
include/ctdb.h | 40 +++++++++-------------------------------
libctdb/libctdb.c | 25 +++++++++++++++++++------
libctdb/tst.c | 19 ++++---------------
4 files changed, 33 insertions(+), 53 deletions(-)
Changeset truncated at 500 lines:
diff --git a/client/ctdb_client.c b/client/ctdb_client.c
index 6a19510..4d49293 100644
--- a/client/ctdb_client.c
+++ b/client/ctdb_client.c
@@ -1112,7 +1112,7 @@ int ctdb_ctrl_getpnn(struct ctdb_context *ctdb, struct timeval timeout, uint32_t
uint32_t pnn;
ctdb_handle *handle;
- handle = ctdb_getpnn_send(ctdb, destnode);
+ handle = ctdb_getpnn_send(ctdb, destnode, NULL, NULL);
if (handle == NULL) {
DEBUG(DEBUG_ERR, (__location__ " Failed to send getpnn control\n"));
return -1;
diff --git a/include/ctdb.h b/include/ctdb.h
index 86886e5..6e07a10 100644
--- a/include/ctdb.h
+++ b/include/ctdb.h
@@ -35,7 +35,7 @@
* The exception is when called from in the registered callback,
* in this case the fucntion is guaranteed not to block.
*
- * 2, Registering an async callback to be invoked when the call completes.
+ * 2, providing an async callback to be invoked when the call completes.
* From inside the callback you use the *_recv() function to extract the
* response data.
*
@@ -77,31 +77,7 @@ int ctdb_service(struct ctdb_context *ctdb);
typedef void ctdb_handle;
-/*
- * After issuing a *_send() command, you can use this function to register a
- * a callback function to be automatically called once the call
- * finishes.
- *
- * Once the callback function returns, the handle will be automatically
- * destroyed.
- *
- * If using ctdb_free() to abort a call in flight, you have to take care
- * to avoid the race condition that would exist between the callback and
- * ctdb_free().
- *
- * Possible method could be :
- * * take pthreads mutex
- * * ctdb_set_callback(handle, NULL, NULL)
- * * verify that the callback has not yet been called
- * (if it has handle is no longer valid)
- * * ctdb_free(handle)
- * * release pthreads mutex
- */
-typedef void (*ctdb_callback)(int32_t status, struct ctdb_context *ctdb, ctdb_handle *, void *private_data);
-
-int ctdb_set_callback(ctdb_handle *handle, ctdb_callback callback, void *private_data);
-
-
+typedef void (*ctdb_generic_callback)(int32_t status, struct ctdb_context *ctdb, ctdb_handle *, void *private_data);
/*
@@ -224,7 +200,9 @@ int ctdb_send_message(struct ctdb_context *ctdb, uint32_t pnn, uint64_t srvid, T
*/
ctdb_handle *
ctdb_getpnn_send(struct ctdb_context *ctdb,
- uint32_t destnode);
+ uint32_t destnode,
+ ctdb_generic_callback callback,
+ void *private_data);
int ctdb_getpnn_recv(struct ctdb_context *ctdb,
ctdb_handle *handle,
uint32_t *pnn);
@@ -238,11 +216,11 @@ int ctdb_getpnn(struct ctdb_context *ctdb,
/*
* functions to read the recovery master of a node
*/
-typedef void (*ctdb_getrecmaster_cb)(int32_t status, int32_t recmaster, void *private_data);
-
ctdb_handle *
ctdb_getrecmaster_send(struct ctdb_context *ctdb,
- uint32_t destnode);
+ uint32_t destnode,
+ ctdb_generic_callback callback,
+ void *private_data);
int ctdb_getrecmaster_recv(struct ctdb_context *ctdb,
ctdb_handle *handle,
uint32_t *recmaster);
@@ -254,7 +232,7 @@ int ctdb_getrecmaster(struct ctdb_context *ctdb,
/*
- * cancel a request/call
+ * cancel a request/call or release a resource
*/
int ctdb_free(ctdb_handle *);
diff --git a/libctdb/libctdb.c b/libctdb/libctdb.c
index e4a5ea6..9fe55a9 100644
--- a/libctdb/libctdb.c
+++ b/libctdb/libctdb.c
@@ -45,7 +45,7 @@ static void
ctdb_control_cb(struct ctdb_client_control_state *state)
{
struct ctdb_control_cb_data *cb_data = state->async.private_data;
- ctdb_callback callback = (ctdb_callback)cb_data->callback;
+ ctdb_generic_callback callback = (ctdb_generic_callback)cb_data->callback;
/* dont recurse */
state->async.fn = NULL;
@@ -63,7 +63,8 @@ ctdb_control_cb(struct ctdb_client_control_state *state)
/*
* This function is used to set the callback action for a handle
*/
-int ctdb_set_callback(ctdb_handle *handle, ctdb_callback callback, void *private_data)
+static int
+ctdb_set_generic_callback(ctdb_handle *handle, ctdb_generic_callback callback, void *private_data)
{
struct ctdb_client_control_state *control_state = talloc_get_type(handle, struct ctdb_client_control_state);
@@ -240,7 +241,9 @@ int ctdb_free(ctdb_handle *handle)
*************************/
ctdb_handle *
ctdb_getpnn_send(struct ctdb_context *ctdb,
- uint32_t destnode)
+ uint32_t destnode,
+ ctdb_generic_callback callback,
+ void *private_data)
{
struct ctdb_client_control_state *state;
@@ -253,6 +256,10 @@ ctdb_getpnn_send(struct ctdb_context *ctdb,
return NULL;
}
+ if (callback != NULL) {
+ ctdb_set_generic_callback(state, callback, private_data);
+ }
+
return (ctdb_handle *)state;
}
@@ -278,7 +285,7 @@ int ctdb_getpnn(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *pnn)
{
struct ctdb_client_control_state *state;
- state = ctdb_getpnn_send(ctdb, destnode);
+ state = ctdb_getpnn_send(ctdb, destnode, NULL, NULL);
if (state == NULL) {
DEBUG(DEBUG_ERR,(__location__ " ctdb_getpnn_send() failed.\n"));
return -1;
@@ -294,7 +301,9 @@ int ctdb_getpnn(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *pnn)
***********************/
ctdb_handle *
ctdb_getrecmaster_send(struct ctdb_context *ctdb,
- uint32_t destnode)
+ uint32_t destnode,
+ ctdb_generic_callback callback,
+ void *private_data)
{
struct ctdb_client_control_state *state;
@@ -307,6 +316,10 @@ ctdb_getrecmaster_send(struct ctdb_context *ctdb,
return NULL;
}
+ if (callback != NULL) {
+ ctdb_set_generic_callback(state, callback, private_data);
+ }
+
return (ctdb_handle *)state;
}
@@ -332,7 +345,7 @@ int ctdb_getrecmaster(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *re
{
struct ctdb_client_control_state *state;
- state = ctdb_getrecmaster_send(ctdb, destnode);
+ state = ctdb_getrecmaster_send(ctdb, destnode, NULL, NULL);
if (state == NULL) {
DEBUG(DEBUG_ERR,(__location__ " ctdb_getrecmaster_send() failed.\n"));
return -1;
diff --git a/libctdb/tst.c b/libctdb/tst.c
index d3db133..ca968a4 100644
--- a/libctdb/tst.c
+++ b/libctdb/tst.c
@@ -146,24 +146,18 @@ int main(int argc, char *argv[])
* ASYNC call with callback to read the recmaster
* this is the preferred way to use libctdb
*/
- handle = ctdb_getrecmaster_send(ctdb, CTDB_CURRENT_NODE);
+ handle = ctdb_getrecmaster_send(ctdb, CTDB_CURRENT_NODE, rm_cb, NULL);
if (handle == NULL) {
printf("Failed to send get_recmaster control\n");
exit(10);
}
- ret = ctdb_set_callback(handle, rm_cb, NULL);
- if (ret != 0) {
- printf("Failed to set callback for get_recmaster\n");
- ctdb_free(handle);
- exit(10);
- }
/*
* SEMI-SYNC call with callback to read the recmaster
* calls the blocking *_recv() function.
* Avoid this mode for performance critical tasks
*/
- handle = ctdb_getrecmaster_send(ctdb, CTDB_CURRENT_NODE);
+ handle = ctdb_getrecmaster_send(ctdb, CTDB_CURRENT_NODE, NULL, NULL);
if (handle == NULL) {
printf("Failed to send get_recmaster control\n");
exit(10);
@@ -192,17 +186,12 @@ int main(int argc, char *argv[])
- handle = ctdb_getpnn_send(ctdb, CTDB_CURRENT_NODE);
+ handle = ctdb_getpnn_send(ctdb, CTDB_CURRENT_NODE, pnn_cb, NULL);
if (handle == NULL) {
printf("Failed to send get_pnn control\n");
exit(10);
}
- ret = ctdb_set_callback(handle, pnn_cb, NULL);
- if (ret != 0) {
- printf("Failed to set callback for getpnn\n");
- ctdb_free(handle);
- exit(10);
- }
+
handle = ctdb_readrecordlock_send(ctdb, ctdb_db_context, key, rrl_cb, NULL);
--
CTDB repository
More information about the samba-cvs
mailing list