]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
merged ctdb messaging code from samba4
authorAndrew Tridgell <tridge@samba.org>
Thu, 8 Feb 2007 22:42:04 +0000 (09:42 +1100)
committerAndrew Tridgell <tridge@samba.org>
Thu, 8 Feb 2007 22:42:04 +0000 (09:42 +1100)
(This used to be ctdb commit af3010562763811deb9b7e37fea9962a42885d9d)

ctdb/Makefile.in
ctdb/common/ctdb.c
ctdb/common/ctdb_call.c
ctdb/common/ctdb_message.c [new file with mode: 0644]
ctdb/include/ctdb.h
ctdb/include/ctdb_private.h

index 1f130c6b849b7b9729db3f70f843700745dbf5ff..1db76a8a812efb5e3fac3c9775a171f9792a08ee 100644 (file)
@@ -21,7 +21,8 @@ LIB_FLAGS=@LDFLAGS@ -Llib @LIBS@ -lpopt @INFINIBAND_LIBS@
 EVENTS_OBJ = lib/events/events.o lib/events/events_standard.o
 
 CTDB_COMMON_OBJ = common/ctdb.o common/util.o common/ctdb_util.o \
-       common/ctdb_call.o common/ctdb_ltdb.o lib/util/idtree.o lib/util/db_wrap.o
+       common/ctdb_call.o common/ctdb_ltdb.o common/ctdb_message.o \
+       lib/util/idtree.o lib/util/db_wrap.o
 
 CTDB_TCP_OBJ = tcp/tcp_connect.o tcp/tcp_io.o tcp/tcp_init.o
 
index ecef14bca413d44c2c08c76f94160ea0b86fa15f..9e92059b950e373952746945d7081e1638d61318 100644 (file)
@@ -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,
index 0169baf906245a4823a32d8d9482116c4d1a0ed7..fb29aad9ac7e77aaebba8b1360abb2d0223270ac 100644 (file)
 #include "system/filesys.h"
 #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
 */
diff --git a/ctdb/common/ctdb_message.c b/ctdb/common/ctdb_message.c
new file mode 100644 (file)
index 0000000..abdf9e6
--- /dev/null
@@ -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;
+}
+
index 7eebcb83db8e04e6238042f8ce8679b2ebcfe706..335af83215a0d58310e27a6ba19e95cb74c27b21 100644 (file)
@@ -127,4 +127,14 @@ void ctdb_wait_loop(struct ctdb_context *ctdb);
 /* return vnn of this node */
 uint32_t ctdb_get_vnn(struct ctdb_context *ctdb);
 
+/* setup a handler for ctdb messages */
+typedef void (*ctdb_message_fn_t)(struct ctdb_context *, uint32_t srvid, 
+                                 TDB_DATA data, void *);
+int ctdb_set_message_handler(struct ctdb_context *ctdb, ctdb_message_fn_t handler,
+                            void *private);
+
+/* 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);
+
 #endif
index 977206f400cc781b1b830fa5fcfc0f5f446ddcd9..c863781c50e75a81914a17af917d3e52c7c0503c 100644 (file)
@@ -94,6 +94,8 @@ struct ctdb_context {
        const struct ctdb_upcalls *upcalls; /* transport upcalls */
        void *private; /* private to transport */
        unsigned max_lacount;
+       ctdb_message_fn_t message_handler;
+       void *message_private;
 };
 
 #define CTDB_NO_MEMORY(ctdb, p) do { if (!(p)) { \
@@ -138,7 +140,8 @@ enum ctdb_operation {
        CTDB_REPLY_REDIRECT = 2,
        CTDB_REQ_DMASTER    = 3,
        CTDB_REPLY_DMASTER  = 4,
-       CTDB_REPLY_ERROR    = 5
+       CTDB_REPLY_ERROR    = 5,
+       CTDB_REQ_MESSAGE    = 6
 };
 
 /*
@@ -193,6 +196,13 @@ struct ctdb_reply_dmaster {
        uint8_t  data[1];
 };
 
+struct ctdb_req_message {
+       struct ctdb_req_header hdr;
+       uint32_t srvid;
+       uint32_t datalen;
+       uint8_t data[1];
+};
+
 /* internal prototypes */
 void ctdb_set_error(struct ctdb_context *ctdb, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
 void ctdb_fatal(struct ctdb_context *ctdb, const char *msg);
@@ -203,6 +213,7 @@ int ctdb_parse_address(struct ctdb_context *ctdb,
 uint32_t ctdb_hash(const TDB_DATA *key);
 void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
 void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
+void ctdb_request_message(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
 void ctdb_reply_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
 void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
 void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
@@ -213,6 +224,7 @@ int ctdb_ltdb_fetch(struct ctdb_context *ctdb,
                    TDB_DATA key, struct ctdb_ltdb_header *header, TDB_DATA *data);
 int ctdb_ltdb_store(struct ctdb_context *ctdb, TDB_DATA key, 
                    struct ctdb_ltdb_header *header, TDB_DATA data);
+void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
 
 
 #endif