2 ctdb_message protocol code
4 Copyright (C) Andrew Tridgell 2007
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
20 see http://wiki.samba.org/index.php/Samba_%26_Clustering for
21 protocol design and packet details
24 #include "lib/tevent/tevent.h"
25 #include "lib/tdb/include/tdb.h"
26 #include "system/network.h"
27 #include "system/filesys.h"
28 #include "../include/ctdb_private.h"
29 #include "lib/util/dlinklist.h"
32 this dispatches the messages to the registered ctdb message handler
34 int ctdb_dispatch_message(struct ctdb_context *ctdb, uint64_t srvid, TDB_DATA data)
36 struct ctdb_message_list *ml;
38 for (ml=ctdb->message_list;ml;ml=ml->next) {
39 if (ml->srvid == srvid || ml->srvid == CTDB_SRVID_ALL) {
40 ml->message_handler(ctdb, srvid, data, ml->message_private);
48 called when a CTDB_REQ_MESSAGE packet comes in
50 void ctdb_request_message(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
52 struct ctdb_req_message *c = (struct ctdb_req_message *)hdr;
55 data.dsize = c->datalen;
56 data.dptr = talloc_memdup(c, &c->data[0], c->datalen);
58 ctdb_dispatch_message(ctdb, c->srvid, data);
63 when a client goes away, we need to remove its srvid handler from the list
65 static int message_handler_destructor(struct ctdb_message_list *m)
67 DLIST_REMOVE(m->ctdb->message_list, m);
72 setup handler for receipt of ctdb messages from ctdb_send_message()
74 int ctdb_register_message_handler(struct ctdb_context *ctdb,
77 ctdb_msg_fn_t handler,
80 struct ctdb_message_list *m;
82 m = talloc(mem_ctx, struct ctdb_message_list);
83 CTDB_NO_MEMORY(ctdb, m);
87 m->message_handler = handler;
88 m->message_private = private_data;
90 DLIST_ADD(ctdb->message_list, m);
92 talloc_set_destructor(m, message_handler_destructor);
99 setup handler for receipt of ctdb messages from ctdb_send_message()
101 int ctdb_deregister_message_handler(struct ctdb_context *ctdb, uint64_t srvid, void *private_data)
103 struct ctdb_message_list *m;
105 for (m=ctdb->message_list;m;m=m->next) {
106 if (m->srvid == srvid && m->message_private == private_data) {