2 ctdb_call protocol code
4 Copyright (C) Andrew Tridgell 2006
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
22 #include "lib/events/events.h"
23 #include "system/network.h"
24 #include "system/filesys.h"
25 #include "ctdb_private.h"
29 local version of ctdb_call
31 static int ctdb_call_local(struct ctdb_context *ctdb, TDB_DATA key, int call_id,
32 TDB_DATA *call_data, TDB_DATA *reply_data)
35 struct ctdb_registered_call *fn;
38 c = talloc(ctdb, struct ctdb_call);
39 CTDB_NO_MEMORY(ctdb, c);
41 data = tdb_fetch(ctdb->ltdb, key);
44 c->call_data = call_data;
45 c->record_data.dptr = talloc_memdup(c, data.dptr, data.dsize);
46 CTDB_NO_MEMORY(ctdb, c->record_data.dptr);
47 if (data.dptr) free(data.dptr);
51 for (fn=ctdb->calls;fn;fn=fn->next) {
52 if (fn->id == call_id) break;
55 ctdb_set_error(ctdb, "Unknown call id %u\n", call_id);
60 free(c->record_data.dptr);
61 ctdb_set_error(ctdb, "ctdb_call %u failed\n", call_id);
66 if (tdb_store(ctdb->ltdb, key, *c->new_data, TDB_REPLACE) != 0) {
67 ctdb_set_error(ctdb, "ctdb_call tdb_store failed\n");
74 *reply_data = *c->reply_data;
75 talloc_steal(ctdb, reply_data->dptr);
77 reply_data->dptr = NULL;
78 reply_data->dsize = 0;
88 make a remote ctdb call
90 int ctdb_call(struct ctdb_context *ctdb, TDB_DATA key, int call_id,
91 TDB_DATA *call_data, TDB_DATA *reply_data)
94 struct ctdb_req_call *c;
96 struct ctdb_node *node;
98 dest = ctdb_hash(&key) % ctdb->num_nodes;
99 if (dest == ctdb->vnn) {
100 return ctdb_call_local(ctdb, key, call_id, call_data, reply_data);
103 len = sizeof(*c) + key.dsize + (call_data?call_data->dsize:0);
104 c = talloc_size(ctdb, len);
105 CTDB_NO_MEMORY(ctdb, c);
107 c->hdr.operation = CTDB_OP_CALL;
108 c->hdr.destnode = dest;
109 c->hdr.srcnode = ctdb->vnn;
110 /* this limits us to 16k outstanding messages - not unreasonable */
111 c->hdr.reqid = idr_get_new(ctdb->idr, c, 0xFFFF);
113 c->keylen = key.dsize;
114 c->calldatalen = call_data?call_data->dsize:0;
115 memcpy(&c->data[0], key.dptr, key.dsize);
117 memcpy(&c->data[key.dsize], call_data->dptr, call_data->dsize);
120 node = ctdb->nodes[dest];
122 if (ctdb->methods->queue_pkt(node, (uint8_t *)c, len) != 0) {
128 event_add_timed(ctdb->ev, c, timeval_current_ofs(CTDB_REQ_TIMEOUT, 0),
129 ctdb_call_timeout, c);