2 ctdb_message protocol code
4 Copyright (C) Andrew Tridgell 2007
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library 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 GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 see http://wiki.samba.org/index.php/Samba_%26_Clustering for
22 protocol design and packet details
25 #include "lib/events/events.h"
26 #include "lib/tdb/include/tdb.h"
27 #include "system/network.h"
28 #include "system/filesys.h"
29 #include "../include/ctdb_private.h"
33 called when a CTDB_REQ_MESSAGE packet comes in
35 this dispatches the messages to the registered ctdb message handler
37 void ctdb_request_message(struct ctdb_context
*ctdb
, struct ctdb_req_header
*hdr
)
39 struct ctdb_req_message
*c
= (struct ctdb_req_message
*)hdr
;
41 if (ctdb
->message_handler
== NULL
) {
42 /* no registered message handler */
46 data
.dptr
= &c
->data
[0];
47 data
.dsize
= c
->datalen
;
48 ctdb
->message_handler(ctdb
, c
->srvid
, data
, ctdb
->message_private
);
56 int ctdb_send_message(struct ctdb_context
*ctdb
, uint32_t vnn
,
57 uint32_t srvid
, TDB_DATA data
)
59 struct ctdb_req_message
*r
;
62 len
= offsetof(struct ctdb_req_message
, data
) + data
.dsize
;
63 r
= ctdb
->methods
->allocate_pkt(ctdb
, len
);
64 CTDB_NO_MEMORY(ctdb
, r
);
67 r
->hdr
.operation
= CTDB_REQ_MESSAGE
;
68 r
->hdr
.destnode
= vnn
;
69 r
->hdr
.srcnode
= ctdb
->vnn
;
72 r
->datalen
= data
.dsize
;
73 memcpy(&r
->data
[0], data
.dptr
, data
.dsize
);
75 ctdb_queue_packet(ctdb
, &r
->hdr
);
82 setup handler for receipt of ctdb messages from ctdb_send_message()
84 int ctdb_set_message_handler(struct ctdb_context
*ctdb
, ctdb_message_fn_t handler
,
87 ctdb
->message_handler
= handler
;
88 ctdb
->message_private
= private;