[SCM] CTDB repository - branch libctdb updated - ctdb-1.0.114-97-gf5ca198
Ronnie Sahlberg
sahlberg at samba.org
Wed May 12 20:18:24 MDT 2010
The branch, libctdb has been updated
via f5ca198445ec9b6c6e989c52057a46c144e3a033 (commit)
via 1f00d8191dcf0f9d506adcbdbbc8ad0b35b0b9fc (commit)
via 3d99dc78978830eafd9b2c7f58b19d524f0df2be (commit)
from fade378b6af02c3c8ca33cd7851657ac3f865cf5 (commit)
http://gitweb.samba.org/?p=sahlberg/ctdb.git;a=shortlog;h=libctdb
- Log -----------------------------------------------------------------
commit f5ca198445ec9b6c6e989c52057a46c144e3a033
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Thu May 13 12:16:00 2010 +1000
change the old ctdb_ctrl_getpnn() function with tiemout use the new
libctdb functions instead of calling ctdb_control() directly.
commit 1f00d8191dcf0f9d506adcbdbbc8ad0b35b0b9fc
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Thu May 13 12:00:22 2010 +1000
Change the ctdb_getpnn*() functions to take a destination node parameter so we can send it to any node (as a "ping are you there?")
move the special addresses like CTDB_CURRENT_NODE from ctdb_protocol.h to ctdb.h
commit 3d99dc78978830eafd9b2c7f58b19d524f0df2be
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date: Thu May 13 10:14:27 2010 +1000
Add a control to read the PNN number of the local node to libctdb
-----------------------------------------------------------------------
Summary of changes:
client/ctdb_client.c | 19 ++++++--
include/ctdb.h | 79 ++++++++++++++++++++++++++++++++----
include/ctdb_protocol.h | 8 ----
libctdb/libctdb.c | 103 +++++++++++++++++++++++++++++++++++++++++++----
libctdb/tst.c | 21 +++++++--
5 files changed, 196 insertions(+), 34 deletions(-)
Changeset truncated at 500 lines:
diff --git a/client/ctdb_client.c b/client/ctdb_client.c
index 7b49931..a3349e0 100644
--- a/client/ctdb_client.c
+++ b/client/ctdb_client.c
@@ -1393,17 +1393,26 @@ int ctdb_ctrl_thaw(struct ctdb_context *ctdb, struct timeval timeout, uint32_t d
int ctdb_ctrl_getpnn(struct ctdb_context *ctdb, struct timeval timeout, uint32_t destnode)
{
int ret;
- int32_t res;
+ uint32_t pnn;
+ ctdb_handle *handle;
- ret = ctdb_control(ctdb, destnode, 0,
- CTDB_CONTROL_GET_PNN, 0, tdb_null,
- NULL, NULL, &res, &timeout, NULL);
+ handle = ctdb_getpnn_send(ctdb, destnode, NULL, NULL);
+ if (handle == NULL) {
+ DEBUG(DEBUG_ERR, (__location__ " Failed to send getpnn control\n"));
+ return -1;
+ }
+
+ if (!timeval_is_zero(&timeout)) {
+ event_add_timed(ctdb->ev, handle, timeout, ctdb_control_timeout_func, handle);
+ }
+
+ ret = ctdb_getpnn_recv(ctdb, handle, &pnn);
if (ret != 0) {
DEBUG(DEBUG_ERR,(__location__ " ctdb_control for getpnn failed\n"));
return -1;
}
- return res;
+ return pnn;
}
/*
diff --git a/include/ctdb.h b/include/ctdb.h
index 12bdb89..b074876 100644
--- a/include/ctdb.h
+++ b/include/ctdb.h
@@ -20,6 +20,19 @@
#ifndef _CTDB_H
#define _CTDB_H
+/* Functions are not thread safe so all function calls must be wrapped
+ * inside a pthread_mutex for threaded applications.
+ *
+ * All _send() functions are guaranteed to be non-blocking and fully
+ * asynchronous.
+ *
+ * Avoid using the synchronous calls
+ */
+
+/*
+ * Connect to ctdb using the specified domain socket.
+ * Returns a ctdb context if successful or NULL.
+ */
struct ctdb_context *ctdb_connect(const char *addr);
int ctdb_get_fd(struct ctdb_context *ctdb);
@@ -29,22 +42,35 @@ int ctdb_which_events(struct ctdb_context *ctdb);
int ctdb_service(struct ctdb_context *ctdb);
+/*
+ * Special node addresses :
+ */
+/* used on the domain socket, send a pdu to the local daemon */
+#define CTDB_CURRENT_NODE 0xF0000001
+/* send a broadcast to all nodes in the cluster, active or not */
+#define CTDB_BROADCAST_ALL 0xF0000002
+/* send a broadcast to all nodes in the current vnn map */
+#define CTDB_BROADCAST_VNNMAP 0xF0000003
+/* send a broadcast to all connected nodes */
+#define CTDB_BROADCAST_CONNECTED 0xF0000004
+
-typedef void ctdb_handle;
-/*
- * function to cancel a request/call
- */
-int ctdb_cancel(ctdb_handle *);
+typedef void ctdb_handle;
/*
- * messaging functions
+ * messaging functions
+ * these functions provide a messaging layer for applications to communicate
+ * with eachother across
*/
typedef void (*ctdb_message_fn_t)(struct ctdb_context *, uint64_t srvid, TDB_DATA data, void *);
+/*
+ * register a message handler and start listening on a service port
+ */
typedef void (*ctdb_set_message_handler_cb)(int32_t status, void *private_data);
ctdb_handle *
@@ -59,6 +85,10 @@ int ctdb_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
ctdb_message_fn_t handler, void *private_data);
+
+/*
+ * unregister a message handler and stop listening on teh specified port
+ */
typedef void (*ctdb_remove_message_handler_cb)(int32_t status, void *private_data);
ctdb_handle *
@@ -72,20 +102,44 @@ int ctdb_remove_message_handler_recv(struct ctdb_context *ctdb,
int ctdb_remove_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
void *private_data);
+/*
+ * send a message to a specific node/port
+ * this function is non-blocking
+ */
int ctdb_send_message(struct ctdb_context *ctdb, uint32_t pnn, uint64_t srvid, TDB_DATA data);
/*
+ * functions to read the pnn number of the local node
+ */
+typedef void (*ctdb_getpnn_cb)(int32_t status, int32_t pnn, void *private_data);
+
+ctdb_handle *
+ctdb_getpnn_send(struct ctdb_context *ctdb,
+ uint32_t destnode,
+ ctdb_getpnn_cb callback,
+ void *private_data);
+int ctdb_getpnn_recv(struct ctdb_context *ctdb,
+ ctdb_handle *handle,
+ uint32_t *pnn);
+int ctdb_getpnn(struct ctdb_context *ctdb,
+ uint32_t destnode,
+ uint32_t *pnn);
+
+
+
+
+/*
* functions to read the recovery master of a node
*/
-typedef void (*ctdb_get_recmaster_cb)(int32_t status, int32_t recmaster, void *private_data);
+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,
- ctdb_get_recmaster_cb callback,
+ ctdb_getrecmaster_cb callback,
void *private_data);
int ctdb_getrecmaster_recv(struct ctdb_context *ctdb,
ctdb_handle *handle,
@@ -95,4 +149,13 @@ int ctdb_getrecmaster(struct ctdb_context *ctdb,
uint32_t *recmaster);
+
+
+/*
+ * cancel a request/call
+ */
+int ctdb_cancel(ctdb_handle *);
+
+
+
#endif
diff --git a/include/ctdb_protocol.h b/include/ctdb_protocol.h
index e1d2e4e..22ea63d 100644
--- a/include/ctdb_protocol.h
+++ b/include/ctdb_protocol.h
@@ -121,14 +121,6 @@ struct ctdb_call_info {
*/
#define CTDB_SRVID_SAMBA_NOTIFY 0xFE00000000000000LL
-/* used on the domain socket, send a pdu to the local daemon */
-#define CTDB_CURRENT_NODE 0xF0000001
-/* send a broadcast to all nodes in the cluster, active or not */
-#define CTDB_BROADCAST_ALL 0xF0000002
-/* send a broadcast to all nodes in the current vnn map */
-#define CTDB_BROADCAST_VNNMAP 0xF0000003
-/* send a broadcast to all connected nodes */
-#define CTDB_BROADCAST_CONNECTED 0xF0000004
/* the key used for transaction locking on persistent databases */
#define CTDB_TRANSACTION_LOCK_KEY "__transaction_lock__"
diff --git a/libctdb/libctdb.c b/libctdb/libctdb.c
index 47cc7c2..19ec8ce 100644
--- a/libctdb/libctdb.c
+++ b/libctdb/libctdb.c
@@ -145,23 +145,101 @@ struct ctdb_control_cb_data {
void *private_data;
};
+
+
+
+/*************************
+ * GET PNN of local node *
+ *************************/
static void
-ctdb_getrecmaster_recv_cb(struct ctdb_client_control_state *state)
+ctdb_getpnn_recv_cb(struct ctdb_client_control_state *state)
{
struct ctdb_control_cb_data *cb_data = state->async.private_data;
- ctdb_get_recmaster_cb callback = (ctdb_get_recmaster_cb)cb_data->callback;
+ ctdb_getpnn_cb callback = (ctdb_getpnn_cb)cb_data->callback;
callback(0, state->status, cb_data->private_data);
}
+ctdb_handle *
+ctdb_getpnn_send(struct ctdb_context *ctdb,
+ uint32_t destnode,
+ ctdb_getpnn_cb callback,
+ void *private_data)
+{
+ struct ctdb_client_control_state *state;
+ struct ctdb_control_cb_data *cb_data;
+
+ state = ctdb_control_send(ctdb, destnode, 0,
+ CTDB_CONTROL_GET_PNN, 0, tdb_null,
+ ctdb, NULL);
+
+ if (state == NULL) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to send GET_PNN 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_getpnn_recv_cb;
+ state->async.private_data = cb_data;
+ }
+
+ return (ctdb_handle *)state;
+}
+
+int ctdb_getpnn_recv(struct ctdb_context *ctdb, ctdb_handle *handle, uint32_t *pnn)
+{
+ 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__ " ctdb_getpnn_recv failed\n"));
+ return -1;
+ }
+
+ if (pnn != NULL) {
+ *pnn = (uint32_t)res;
+ }
+
+ return state->status;
+}
+
+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, NULL, NULL);
+ if (state == NULL) {
+ DEBUG(DEBUG_ERR,(__location__ " ctdb_getpnn_send() failed.\n"));
+ return -1;
+ }
+
+ return ctdb_getpnn_recv(ctdb, state, pnn);
+}
+
+
+
+/***********************
+ * GET RECOVERY MASTER *
+ ***********************/
+static void
+ctdb_getrecmaster_recv_cb(struct ctdb_client_control_state *state)
+{
+ struct ctdb_control_cb_data *cb_data = state->async.private_data;
+ ctdb_getrecmaster_cb callback = (ctdb_getrecmaster_cb)cb_data->callback;
+
+ callback(0, state->status, cb_data->private_data);
+}
-/*
- get the recovery master of a remote node
- */
ctdb_handle *
ctdb_getrecmaster_send(struct ctdb_context *ctdb,
uint32_t destnode,
- ctdb_get_recmaster_cb callback,
+ ctdb_getrecmaster_cb callback,
void *private_data)
{
struct ctdb_client_control_state *state;
@@ -200,7 +278,7 @@ int ctdb_getrecmaster_recv(struct ctdb_context *ctdb, ctdb_handle *handle, uint3
return -1;
}
- if (recmaster) {
+ if (recmaster != NULL) {
*recmaster = (uint32_t)res;
}
@@ -211,7 +289,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, NULL, recmaster);
+ state = ctdb_getrecmaster_send(ctdb, destnode, NULL, NULL);
if (state == NULL) {
DEBUG(DEBUG_ERR,(__location__ " ctdb_getrecmaster_send() failed.\n"));
return -1;
@@ -221,6 +299,15 @@ int ctdb_getrecmaster(struct ctdb_context *ctdb, uint32_t destnode, uint32_t *re
}
+
+
+
+
+
+
+
+
+
static void
ctdb_set_message_handler_recv_cb(struct ctdb_client_control_state *state)
{
diff --git a/libctdb/tst.c b/libctdb/tst.c
index 002d77b..17d7f6e 100644
--- a/libctdb/tst.c
+++ b/libctdb/tst.c
@@ -1,7 +1,9 @@
#include <stdio.h>
#include <stdint.h>
+#include <stdlib.h>
#include <poll.h>
#include <fcntl.h>
+#include <string.h>
#include "lib/tdb/include/tdb.h"
#include "include/ctdb.h"
@@ -11,9 +13,14 @@ void msg_h(struct ctdb_context *ctdb, uint64_t srvid, TDB_DATA data, void *priva
}
+void pnn_cb(int32_t status, int32_t pnn, void *private_data)
+{
+ printf("status:%d pnn:%d\n", status, pnn);
+}
+
void rm_cb(int32_t status, int32_t recmaster, void *private_data)
{
- printf("recmaster:%d\n", recmaster);
+ printf("status:%d recmaster:%d\n", status, recmaster);
}
int main(int argc, char *argv[])
@@ -27,8 +34,6 @@ int main(int argc, char *argv[])
ctdb_context = ctdb_connect("/tmp/ctdb.socket");
- pfd.fd = ctdb_get_fd(ctdb_context);
-
handle = ctdb_set_message_handler_send(ctdb_context, 55, NULL, msg_h, NULL);
if (handle == NULL) {
printf("Failed to register message port\n");
@@ -49,15 +54,21 @@ int main(int argc, char *argv[])
exit(10);
}
- handle = ctdb_getrecmaster_send(ctdb_context, 0, rm_cb, NULL);
+ handle = ctdb_getpnn_send(ctdb_context, CTDB_CURRENT_NODE, pnn_cb, NULL);
+ if (handle == NULL) {
+ printf("Failed to send get_pnn control\n");
+ exit(10);
+ }
+
+ handle = ctdb_getrecmaster_send(ctdb_context, CTDB_CURRENT_NODE, rm_cb, NULL);
if (handle == NULL) {
printf("Failed to send get_recmaster control\n");
exit(10);
}
+ pfd.fd = ctdb_get_fd(ctdb_context);
for (;;) {
-
pfd.events = ctdb_which_events(ctdb_context);
if (poll(&pfd, 1, -1) < 0) {
printf("Poll failed");
--
CTDB repository
More information about the samba-cvs
mailing list