summaryrefslogtreecommitdiff
path: root/source4/cluster/ctdb/common
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2007-02-08 02:57:08 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:44:49 -0500
commitaa40cc408b7b50f265913b5107932e237ce032a6 (patch)
tree8e40f4c3c68083b1477a5984d0e819fe81b2fcd1 /source4/cluster/ctdb/common
parent07478016d7354274cd53ff2b4ec1dda3f0f439d1 (diff)
downloadsamba-aa40cc408b7b50f265913b5107932e237ce032a6.tar.gz
samba-aa40cc408b7b50f265913b5107932e237ce032a6.tar.bz2
samba-aa40cc408b7b50f265913b5107932e237ce032a6.zip
r21232: added a raw ctdb messaging api - allowing ctdb applications to take
advantage of the ctdb messaging layer for their own data (This used to be commit b288ba05e5dc2aa5c8cd26eaee1c41b12e4996da)
Diffstat (limited to 'source4/cluster/ctdb/common')
-rw-r--r--source4/cluster/ctdb/common/ctdb.c18
-rw-r--r--source4/cluster/ctdb/common/ctdb_call.c13
-rw-r--r--source4/cluster/ctdb/common/ctdb_message.c91
3 files changed, 109 insertions, 13 deletions
diff --git a/source4/cluster/ctdb/common/ctdb.c b/source4/cluster/ctdb/common/ctdb.c
index ecef14bca4..9e92059b95 100644
--- a/source4/cluster/ctdb/common/ctdb.c
+++ b/source4/cluster/ctdb/common/ctdb.c
@@ -212,6 +212,10 @@ static void ctdb_recv_pkt(struct ctdb_context *ctdb, uint8_t *data, uint32_t len
ctdb_reply_dmaster(ctdb, hdr);
break;
+ case CTDB_REQ_MESSAGE:
+ ctdb_request_message(ctdb, hdr);
+ break;
+
default:
printf("Packet with unknown operation %d\n", hdr->operation);
talloc_free(hdr);
@@ -267,6 +271,20 @@ void ctdb_wait_loop(struct ctdb_context *ctdb)
}
}
+
+/*
+ queue a packet or die
+*/
+void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
+{
+ struct ctdb_node *node;
+ node = ctdb->nodes[hdr->destnode];
+ if (ctdb->methods->queue_pkt(node, (uint8_t *)hdr, hdr->length) != 0) {
+ ctdb_fatal(ctdb, "Unable to queue packet\n");
+ }
+}
+
+
static const struct ctdb_upcalls ctdb_upcalls = {
.recv_pkt = ctdb_recv_pkt,
.node_dead = ctdb_node_dead,
diff --git a/source4/cluster/ctdb/common/ctdb_call.c b/source4/cluster/ctdb/common/ctdb_call.c
index 0169baf906..fb29aad9ac 100644
--- a/source4/cluster/ctdb/common/ctdb_call.c
+++ b/source4/cluster/ctdb/common/ctdb_call.c
@@ -29,19 +29,6 @@
#include "../include/ctdb_private.h"
/*
- queue a packet or die
-*/
-static void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
-{
- struct ctdb_node *node;
- node = ctdb->nodes[hdr->destnode];
- if (ctdb->methods->queue_pkt(node, (uint8_t *)hdr, hdr->length) != 0) {
- ctdb_fatal(ctdb, "Unable to queue packet\n");
- }
-}
-
-
-/*
local version of ctdb_call
*/
static int ctdb_call_local(struct ctdb_context *ctdb, struct ctdb_call *call,
diff --git a/source4/cluster/ctdb/common/ctdb_message.c b/source4/cluster/ctdb/common/ctdb_message.c
new file mode 100644
index 0000000000..abdf9e6216
--- /dev/null
+++ b/source4/cluster/ctdb/common/ctdb_message.c
@@ -0,0 +1,91 @@
+/*
+ ctdb_message protocol code
+
+ Copyright (C) Andrew Tridgell 2007
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+/*
+ see http://wiki.samba.org/index.php/Samba_%26_Clustering for
+ protocol design and packet details
+*/
+#include "includes.h"
+#include "lib/events/events.h"
+#include "lib/tdb/include/tdb.h"
+#include "system/network.h"
+#include "system/filesys.h"
+#include "../include/ctdb_private.h"
+
+
+/*
+ called when a CTDB_REQ_MESSAGE packet comes in
+
+ this dispatches the messages to the registered ctdb message handler
+*/
+void ctdb_request_message(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
+{
+ struct ctdb_req_message *c = (struct ctdb_req_message *)hdr;
+ TDB_DATA data;
+ if (ctdb->message_handler == NULL) {
+ /* no registered message handler */
+ talloc_free(hdr);
+ return;
+ }
+ data.dptr = &c->data[0];
+ data.dsize = c->datalen;
+ ctdb->message_handler(ctdb, c->srvid, data, ctdb->message_private);
+ talloc_free(hdr);
+}
+
+
+/*
+ send a ctdb message
+*/
+int ctdb_send_message(struct ctdb_context *ctdb, uint32_t vnn,
+ uint32_t srvid, uint32_t msg_type, TDB_DATA data)
+{
+ struct ctdb_req_message *r;
+ int len;
+
+ len = offsetof(struct ctdb_req_message, data) + data.dsize;
+ r = ctdb->methods->allocate_pkt(ctdb, len);
+ CTDB_NO_MEMORY(ctdb, r);
+
+ r->hdr.length = len;
+ r->hdr.operation = CTDB_REQ_MESSAGE;
+ r->hdr.destnode = vnn;
+ r->hdr.srcnode = ctdb->vnn;
+ r->hdr.reqid = 0;
+ r->srvid = srvid;
+ r->datalen = data.dsize;
+ memcpy(&r->data[0], data.dptr, data.dsize);
+
+ ctdb_queue_packet(ctdb, &r->hdr);
+
+ talloc_free(r);
+ return 0;
+}
+
+/*
+ setup handler for receipt of ctdb messages from ctdb_send_message()
+*/
+int ctdb_set_message_handler(struct ctdb_context *ctdb, ctdb_message_fn_t handler,
+ void *private)
+{
+ ctdb->message_handler = handler;
+ ctdb->message_private = private;
+ return 0;
+}
+