2 ctdb_call protocol code
4 Copyright (C) Andrew Tridgell 2006
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/events/events.h"
25 #include "lib/tdb/include/tdb.h"
26 #include "lib/util/dlinklist.h"
27 #include "system/network.h"
28 #include "system/filesys.h"
29 #include "../include/ctdb_private.h"
32 find the ctdb_db from a db index
34 struct ctdb_db_context *find_ctdb_db(struct ctdb_context *ctdb, uint32_t id)
36 struct ctdb_db_context *ctdb_db;
38 for (ctdb_db=ctdb->db_list; ctdb_db; ctdb_db=ctdb_db->next) {
39 if (ctdb_db->db_id == id) {
48 a varient of input packet that can be used in lock requeue
50 static void ctdb_call_input_pkt(void *p, struct ctdb_req_header *hdr)
52 struct ctdb_context *ctdb = talloc_get_type(p, struct ctdb_context);
53 ctdb_input_pkt(ctdb, hdr);
60 static void ctdb_send_error(struct ctdb_context *ctdb,
61 struct ctdb_req_header *hdr, uint32_t status,
62 const char *fmt, ...) PRINTF_ATTRIBUTE(4,5);
63 static void ctdb_send_error(struct ctdb_context *ctdb,
64 struct ctdb_req_header *hdr, uint32_t status,
68 struct ctdb_reply_error *r;
72 if (ctdb->methods == NULL) {
73 DEBUG(DEBUG_ERR,(__location__ " Failed to send error. Transport is DOWN\n"));
78 msg = talloc_vasprintf(ctdb, fmt, ap);
80 ctdb_fatal(ctdb, "Unable to allocate error in ctdb_send_error\n");
84 msglen = strlen(msg)+1;
85 len = offsetof(struct ctdb_reply_error, msg);
86 r = ctdb_transport_allocate(ctdb, msg, CTDB_REPLY_ERROR, len + msglen,
87 struct ctdb_reply_error);
88 CTDB_NO_MEMORY_FATAL(ctdb, r);
90 r->hdr.destnode = hdr->srcnode;
91 r->hdr.reqid = hdr->reqid;
94 memcpy(&r->msg[0], msg, msglen);
96 ctdb_queue_packet(ctdb, &r->hdr);
103 send a redirect reply
105 static void ctdb_call_send_redirect(struct ctdb_context *ctdb,
107 struct ctdb_req_call *c,
108 struct ctdb_ltdb_header *header)
111 uint32_t lmaster = ctdb_lmaster(ctdb, &key);
112 if (ctdb->pnn == lmaster) {
113 c->hdr.destnode = header->dmaster;
114 } else if ((c->hopcount % ctdb->tunable.max_redirect_count) == 0) {
115 c->hdr.destnode = lmaster;
117 c->hdr.destnode = header->dmaster;
120 ctdb_queue_packet(ctdb, &c->hdr);
127 caller must have the chainlock before calling this routine. Caller must be
130 static void ctdb_send_dmaster_reply(struct ctdb_db_context *ctdb_db,
131 struct ctdb_ltdb_header *header,
132 TDB_DATA key, TDB_DATA data,
133 uint32_t new_dmaster,
136 struct ctdb_context *ctdb = ctdb_db->ctdb;
137 struct ctdb_reply_dmaster *r;
141 if (ctdb->pnn != ctdb_lmaster(ctdb, &key)) {
142 DEBUG(DEBUG_ALERT,(__location__ " Caller is not lmaster!\n"));
146 header->dmaster = new_dmaster;
147 ret = ctdb_ltdb_store(ctdb_db, key, header, data);
149 ctdb_fatal(ctdb, "ctdb_send_dmaster_reply unable to update dmaster");
153 if (ctdb->methods == NULL) {
154 ctdb_fatal(ctdb, "ctdb_send_dmaster_reply cant update dmaster sicne transport is down");
158 /* put the packet on a temporary context, allowing us to safely free
159 it below even if ctdb_reply_dmaster() has freed it already */
160 tmp_ctx = talloc_new(ctdb);
162 /* send the CTDB_REPLY_DMASTER */
163 len = offsetof(struct ctdb_reply_dmaster, data) + key.dsize + data.dsize;
164 r = ctdb_transport_allocate(ctdb, tmp_ctx, CTDB_REPLY_DMASTER, len,
165 struct ctdb_reply_dmaster);
166 CTDB_NO_MEMORY_FATAL(ctdb, r);
168 r->hdr.destnode = new_dmaster;
169 r->hdr.reqid = reqid;
170 r->rsn = header->rsn;
171 r->keylen = key.dsize;
172 r->datalen = data.dsize;
173 r->db_id = ctdb_db->db_id;
174 memcpy(&r->data[0], key.dptr, key.dsize);
175 memcpy(&r->data[key.dsize], data.dptr, data.dsize);
177 ctdb_queue_packet(ctdb, &r->hdr);
179 talloc_free(tmp_ctx);
183 send a dmaster request (give another node the dmaster for a record)
185 This is always sent to the lmaster, which ensures that the lmaster
186 always knows who the dmaster is. The lmaster will then send a
187 CTDB_REPLY_DMASTER to the new dmaster
189 static void ctdb_call_send_dmaster(struct ctdb_db_context *ctdb_db,
190 struct ctdb_req_call *c,
191 struct ctdb_ltdb_header *header,
192 TDB_DATA *key, TDB_DATA *data)
194 struct ctdb_req_dmaster *r;
195 struct ctdb_context *ctdb = ctdb_db->ctdb;
197 uint32_t lmaster = ctdb_lmaster(ctdb, key);
199 if (ctdb->methods == NULL) {
200 ctdb_fatal(ctdb, "Failed ctdb_call_send_dmaster since transport is down");
204 if (lmaster == ctdb->pnn) {
205 ctdb_send_dmaster_reply(ctdb_db, header, *key, *data,
206 c->hdr.srcnode, c->hdr.reqid);
210 len = offsetof(struct ctdb_req_dmaster, data) + key->dsize + data->dsize;
211 r = ctdb_transport_allocate(ctdb, ctdb, CTDB_REQ_DMASTER, len,
212 struct ctdb_req_dmaster);
213 CTDB_NO_MEMORY_FATAL(ctdb, r);
214 r->hdr.destnode = lmaster;
215 r->hdr.reqid = c->hdr.reqid;
217 r->rsn = header->rsn;
218 r->dmaster = c->hdr.srcnode;
219 r->keylen = key->dsize;
220 r->datalen = data->dsize;
221 memcpy(&r->data[0], key->dptr, key->dsize);
222 memcpy(&r->data[key->dsize], data->dptr, data->dsize);
224 header->dmaster = c->hdr.srcnode;
225 if (ctdb_ltdb_store(ctdb_db, *key, header, *data) != 0) {
226 ctdb_fatal(ctdb, "Failed to store record in ctdb_call_send_dmaster");
229 ctdb_queue_packet(ctdb, &r->hdr);
235 called when a CTDB_REPLY_DMASTER packet comes in, or when the lmaster
236 gets a CTDB_REQUEST_DMASTER for itself. We become the dmaster.
238 must be called with the chainlock held. This function releases the chainlock
240 static void ctdb_become_dmaster(struct ctdb_db_context *ctdb_db,
241 struct ctdb_req_header *hdr,
242 TDB_DATA key, TDB_DATA data,
245 struct ctdb_call_state *state;
246 struct ctdb_context *ctdb = ctdb_db->ctdb;
247 struct ctdb_ltdb_header header;
249 DEBUG(DEBUG_INFO,("pnn %u dmaster response %08x\n", ctdb->pnn, ctdb_hash(&key)));
252 header.rsn = rsn + 1;
253 header.dmaster = ctdb->pnn;
255 if (ctdb_ltdb_store(ctdb_db, key, &header, data) != 0) {
256 ctdb_fatal(ctdb, "ctdb_reply_dmaster store failed\n");
257 ctdb_ltdb_unlock(ctdb_db, key);
261 state = ctdb_reqid_find(ctdb, hdr->reqid, struct ctdb_call_state);
264 DEBUG(DEBUG_ERR,("pnn %u Invalid reqid %u in ctdb_become_dmaster from node %u\n",
265 ctdb->pnn, hdr->reqid, hdr->srcnode));
266 ctdb_ltdb_unlock(ctdb_db, key);
270 if (hdr->reqid != state->reqid) {
271 /* we found a record but it was the wrong one */
272 DEBUG(DEBUG_ERR, ("Dropped orphan in ctdb_become_dmaster with reqid:%u\n from node %u", hdr->reqid, hdr->srcnode));
273 ctdb_ltdb_unlock(ctdb_db, key);
277 ctdb_call_local(ctdb_db, state->call, &header, state, &data, ctdb->pnn);
279 ctdb_ltdb_unlock(ctdb_db, state->call->key);
281 state->state = CTDB_CALL_DONE;
282 if (state->async.fn) {
283 state->async.fn(state);
290 called when a CTDB_REQ_DMASTER packet comes in
292 this comes into the lmaster for a record when the current dmaster
293 wants to give up the dmaster role and give it to someone else
295 void ctdb_request_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
297 struct ctdb_req_dmaster *c = (struct ctdb_req_dmaster *)hdr;
298 TDB_DATA key, data, data2;
299 struct ctdb_ltdb_header header;
300 struct ctdb_db_context *ctdb_db;
304 key.dsize = c->keylen;
305 data.dptr = c->data + c->keylen;
306 data.dsize = c->datalen;
308 ctdb_db = find_ctdb_db(ctdb, c->db_id);
310 ctdb_send_error(ctdb, hdr, -1,
311 "Unknown database in request. db_id==0x%08x",
316 /* fetch the current record */
317 ret = ctdb_ltdb_lock_fetch_requeue(ctdb_db, key, &header, hdr, &data2,
318 ctdb_call_input_pkt, ctdb, False);
320 ctdb_fatal(ctdb, "ctdb_req_dmaster failed to fetch record");
324 DEBUG(DEBUG_INFO,(__location__ " deferring ctdb_request_dmaster\n"));
328 if (ctdb_lmaster(ctdb, &key) != ctdb->pnn) {
329 DEBUG(DEBUG_ALERT,("pnn %u dmaster request to non-lmaster lmaster=%u gen=%u curgen=%u\n",
330 ctdb->pnn, ctdb_lmaster(ctdb, &key),
331 hdr->generation, ctdb->vnn_map->generation));
332 ctdb_fatal(ctdb, "ctdb_req_dmaster to non-lmaster");
335 DEBUG(DEBUG_INFO,("pnn %u dmaster request on %08x for %u from %u\n",
336 ctdb->pnn, ctdb_hash(&key), c->dmaster, c->hdr.srcnode));
338 /* its a protocol error if the sending node is not the current dmaster */
339 if (header.dmaster != hdr->srcnode) {
340 DEBUG(DEBUG_ALERT,("pnn %u dmaster request for new-dmaster %u from non-master %u real-dmaster=%u key %08x dbid 0x%08x gen=%u curgen=%u c->rsn=%llu header.rsn=%llu reqid=%u keyval=0x%08x\n",
341 ctdb->pnn, c->dmaster, hdr->srcnode, header.dmaster, ctdb_hash(&key),
342 ctdb_db->db_id, hdr->generation, ctdb->vnn_map->generation,
343 (unsigned long long)c->rsn, (unsigned long long)header.rsn, c->hdr.reqid,
344 (key.dsize >= 4)?(*(uint32_t *)key.dptr):0));
346 * with the new vacuuming code there are conditions where a node has outdated
347 * information about the real dmaster
348 * since here we are lmaster and always know who is the real dmaster
349 * we don't need to exit with a fatal error and we even don't have
350 * to initiate a recovery
354 if (header.rsn > c->rsn) {
355 DEBUG(DEBUG_ALERT,("pnn %u dmaster request with older RSN new-dmaster %u from %u real-dmaster=%u key %08x dbid 0x%08x gen=%u curgen=%u c->rsn=%llu header.rsn=%llu reqid=%u\n",
356 ctdb->pnn, c->dmaster, hdr->srcnode, header.dmaster, ctdb_hash(&key),
357 ctdb_db->db_id, hdr->generation, ctdb->vnn_map->generation,
358 (unsigned long long)c->rsn, (unsigned long long)header.rsn, c->hdr.reqid));
361 /* use the rsn from the sending node */
364 /* check if the new dmaster is the lmaster, in which case we
365 skip the dmaster reply */
366 if (c->dmaster == ctdb->pnn) {
367 ctdb_become_dmaster(ctdb_db, hdr, key, data, c->rsn);
369 ctdb_send_dmaster_reply(ctdb_db, &header, key, data, c->dmaster, hdr->reqid);
370 ctdb_ltdb_unlock(ctdb_db, key);
376 called when a CTDB_REQ_CALL packet comes in
378 void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
380 struct ctdb_req_call *c = (struct ctdb_req_call *)hdr;
382 struct ctdb_reply_call *r;
384 struct ctdb_ltdb_header header;
385 struct ctdb_call *call;
386 struct ctdb_db_context *ctdb_db;
388 if (ctdb->methods == NULL) {
389 DEBUG(DEBUG_ERR,(__location__ " Failed ctdb_request_call. Transport is DOWN\n"));
394 ctdb_db = find_ctdb_db(ctdb, c->db_id);
396 ctdb_send_error(ctdb, hdr, -1,
397 "Unknown database in request. db_id==0x%08x",
402 call = talloc(hdr, struct ctdb_call);
403 CTDB_NO_MEMORY_FATAL(ctdb, call);
405 call->call_id = c->callid;
406 call->key.dptr = c->data;
407 call->key.dsize = c->keylen;
408 call->call_data.dptr = c->data + c->keylen;
409 call->call_data.dsize = c->calldatalen;
411 /* determine if we are the dmaster for this key. This also
412 fetches the record data (if any), thus avoiding a 2nd fetch of the data
413 if the call will be answered locally */
415 ret = ctdb_ltdb_lock_fetch_requeue(ctdb_db, call->key, &header, hdr, &data,
416 ctdb_call_input_pkt, ctdb, False);
418 ctdb_send_error(ctdb, hdr, ret, "ltdb fetch failed in ctdb_request_call");
422 DEBUG(DEBUG_INFO,(__location__ " deferred ctdb_request_call\n"));
426 /* if we are not the dmaster, then send a redirect to the
428 if (header.dmaster != ctdb->pnn) {
429 talloc_free(data.dptr);
430 ctdb_call_send_redirect(ctdb, call->key, c, &header);
431 ctdb_ltdb_unlock(ctdb_db, call->key);
435 if (c->hopcount > ctdb->statistics.max_hop_count) {
436 ctdb->statistics.max_hop_count = c->hopcount;
439 /* if this nodes has done enough consecutive calls on the same record
440 then give them the record
441 or if the node requested an immediate migration
443 if ( c->hdr.srcnode != ctdb->pnn &&
444 ((header.laccessor == c->hdr.srcnode
445 && header.lacount >= ctdb->tunable.max_lacount)
446 || (c->flags & CTDB_IMMEDIATE_MIGRATION)) ) {
447 if (ctdb_db->transaction_active) {
448 DEBUG(DEBUG_WARNING, (__location__ " refusing migration"
449 " of key %s while transaction is active\n",
450 (char *)call->key.dptr));
452 DEBUG(DEBUG_INFO,("pnn %u starting migration of %08x to %u\n",
453 ctdb->pnn, ctdb_hash(&(call->key)), c->hdr.srcnode));
454 ctdb_call_send_dmaster(ctdb_db, c, &header, &(call->key), &data);
455 talloc_free(data.dptr);
456 ctdb_ltdb_unlock(ctdb_db, call->key);
461 ctdb_call_local(ctdb_db, call, &header, hdr, &data, c->hdr.srcnode);
463 ctdb_ltdb_unlock(ctdb_db, call->key);
465 len = offsetof(struct ctdb_reply_call, data) + call->reply_data.dsize;
466 r = ctdb_transport_allocate(ctdb, ctdb, CTDB_REPLY_CALL, len,
467 struct ctdb_reply_call);
468 CTDB_NO_MEMORY_FATAL(ctdb, r);
469 r->hdr.destnode = hdr->srcnode;
470 r->hdr.reqid = hdr->reqid;
471 r->status = call->status;
472 r->datalen = call->reply_data.dsize;
473 if (call->reply_data.dsize) {
474 memcpy(&r->data[0], call->reply_data.dptr, call->reply_data.dsize);
477 ctdb_queue_packet(ctdb, &r->hdr);
483 called when a CTDB_REPLY_CALL packet comes in
485 This packet comes in response to a CTDB_REQ_CALL request packet. It
486 contains any reply data from the call
488 void ctdb_reply_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
490 struct ctdb_reply_call *c = (struct ctdb_reply_call *)hdr;
491 struct ctdb_call_state *state;
493 state = ctdb_reqid_find(ctdb, hdr->reqid, struct ctdb_call_state);
495 DEBUG(DEBUG_ERR, (__location__ " reqid %u not found\n", hdr->reqid));
499 if (hdr->reqid != state->reqid) {
500 /* we found a record but it was the wrong one */
501 DEBUG(DEBUG_ERR, ("Dropped orphaned call reply with reqid:%u\n",hdr->reqid));
505 state->call->reply_data.dptr = c->data;
506 state->call->reply_data.dsize = c->datalen;
507 state->call->status = c->status;
509 talloc_steal(state, c);
511 state->state = CTDB_CALL_DONE;
512 if (state->async.fn) {
513 state->async.fn(state);
519 called when a CTDB_REPLY_DMASTER packet comes in
521 This packet comes in from the lmaster response to a CTDB_REQ_CALL
522 request packet. It means that the current dmaster wants to give us
525 void ctdb_reply_dmaster(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
527 struct ctdb_reply_dmaster *c = (struct ctdb_reply_dmaster *)hdr;
528 struct ctdb_db_context *ctdb_db;
532 ctdb_db = find_ctdb_db(ctdb, c->db_id);
533 if (ctdb_db == NULL) {
534 DEBUG(DEBUG_ERR,("Unknown db_id 0x%x in ctdb_reply_dmaster\n", c->db_id));
539 key.dsize = c->keylen;
540 data.dptr = &c->data[key.dsize];
541 data.dsize = c->datalen;
543 ret = ctdb_ltdb_lock_requeue(ctdb_db, key, hdr,
544 ctdb_call_input_pkt, ctdb, False);
549 DEBUG(DEBUG_ERR,(__location__ " Failed to get lock in ctdb_reply_dmaster\n"));
553 ctdb_become_dmaster(ctdb_db, hdr, key, data, c->rsn);
558 called when a CTDB_REPLY_ERROR packet comes in
560 void ctdb_reply_error(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
562 struct ctdb_reply_error *c = (struct ctdb_reply_error *)hdr;
563 struct ctdb_call_state *state;
565 state = ctdb_reqid_find(ctdb, hdr->reqid, struct ctdb_call_state);
567 DEBUG(DEBUG_ERR,("pnn %u Invalid reqid %u in ctdb_reply_error\n",
568 ctdb->pnn, hdr->reqid));
572 if (hdr->reqid != state->reqid) {
573 /* we found a record but it was the wrong one */
574 DEBUG(DEBUG_ERR, ("Dropped orphaned error reply with reqid:%u\n",hdr->reqid));
578 talloc_steal(state, c);
580 state->state = CTDB_CALL_ERROR;
581 state->errmsg = (char *)c->msg;
582 if (state->async.fn) {
583 state->async.fn(state);
591 static int ctdb_call_destructor(struct ctdb_call_state *state)
593 DLIST_REMOVE(state->ctdb_db->ctdb->pending_calls, state);
594 ctdb_reqid_remove(state->ctdb_db->ctdb, state->reqid);
600 called when a ctdb_call needs to be resent after a reconfigure event
602 static void ctdb_call_resend(struct ctdb_call_state *state)
604 struct ctdb_context *ctdb = state->ctdb_db->ctdb;
606 state->generation = ctdb->vnn_map->generation;
608 /* use a new reqid, in case the old reply does eventually come in */
609 ctdb_reqid_remove(ctdb, state->reqid);
610 state->reqid = ctdb_reqid_new(ctdb, state);
611 state->c->hdr.reqid = state->reqid;
613 /* update the generation count for this request, so its valid with the new vnn_map */
614 state->c->hdr.generation = state->generation;
616 /* send the packet to ourselves, it will be redirected appropriately */
617 state->c->hdr.destnode = ctdb->pnn;
619 ctdb_queue_packet(ctdb, &state->c->hdr);
620 DEBUG(DEBUG_NOTICE,("resent ctdb_call\n"));
624 resend all pending calls on recovery
626 void ctdb_call_resend_all(struct ctdb_context *ctdb)
628 struct ctdb_call_state *state, *next;
629 for (state=ctdb->pending_calls;state;state=next) {
631 ctdb_call_resend(state);
636 this allows the caller to setup a async.fn
638 static void call_local_trigger(struct event_context *ev, struct timed_event *te,
639 struct timeval t, void *private_data)
641 struct ctdb_call_state *state = talloc_get_type(private_data, struct ctdb_call_state);
642 if (state->async.fn) {
643 state->async.fn(state);
649 construct an event driven local ctdb_call
651 this is used so that locally processed ctdb_call requests are processed
652 in an event driven manner
654 struct ctdb_call_state *ctdb_call_local_send(struct ctdb_db_context *ctdb_db,
655 struct ctdb_call *call,
656 struct ctdb_ltdb_header *header,
659 struct ctdb_call_state *state;
660 struct ctdb_context *ctdb = ctdb_db->ctdb;
663 state = talloc_zero(ctdb_db, struct ctdb_call_state);
664 CTDB_NO_MEMORY_NULL(ctdb, state);
666 talloc_steal(state, data->dptr);
668 state->state = CTDB_CALL_DONE;
669 state->call = talloc(state, struct ctdb_call);
670 CTDB_NO_MEMORY_NULL(ctdb, state->call);
671 *(state->call) = *call;
672 state->ctdb_db = ctdb_db;
674 ret = ctdb_call_local(ctdb_db, state->call, header, state, data, ctdb->pnn);
676 event_add_timed(ctdb->ev, state, timeval_zero(), call_local_trigger, state);
683 make a remote ctdb call - async send. Called in daemon context.
685 This constructs a ctdb_call request and queues it for processing.
686 This call never blocks.
688 struct ctdb_call_state *ctdb_daemon_call_send_remote(struct ctdb_db_context *ctdb_db,
689 struct ctdb_call *call,
690 struct ctdb_ltdb_header *header)
693 struct ctdb_call_state *state;
694 struct ctdb_context *ctdb = ctdb_db->ctdb;
696 if (ctdb->methods == NULL) {
697 DEBUG(DEBUG_ERR,(__location__ " Failed send packet. Transport is down\n"));
701 state = talloc_zero(ctdb_db, struct ctdb_call_state);
702 CTDB_NO_MEMORY_NULL(ctdb, state);
703 state->call = talloc(state, struct ctdb_call);
704 CTDB_NO_MEMORY_NULL(ctdb, state->call);
706 state->reqid = ctdb_reqid_new(ctdb, state);
707 state->ctdb_db = ctdb_db;
708 talloc_set_destructor(state, ctdb_call_destructor);
710 len = offsetof(struct ctdb_req_call, data) + call->key.dsize + call->call_data.dsize;
711 state->c = ctdb_transport_allocate(ctdb, state, CTDB_REQ_CALL, len,
712 struct ctdb_req_call);
713 CTDB_NO_MEMORY_NULL(ctdb, state->c);
714 state->c->hdr.destnode = header->dmaster;
716 /* this limits us to 16k outstanding messages - not unreasonable */
717 state->c->hdr.reqid = state->reqid;
718 state->c->flags = call->flags;
719 state->c->db_id = ctdb_db->db_id;
720 state->c->callid = call->call_id;
721 state->c->hopcount = 0;
722 state->c->keylen = call->key.dsize;
723 state->c->calldatalen = call->call_data.dsize;
724 memcpy(&state->c->data[0], call->key.dptr, call->key.dsize);
725 memcpy(&state->c->data[call->key.dsize],
726 call->call_data.dptr, call->call_data.dsize);
727 *(state->call) = *call;
728 state->call->call_data.dptr = &state->c->data[call->key.dsize];
729 state->call->key.dptr = &state->c->data[0];
731 state->state = CTDB_CALL_WAIT;
732 state->generation = ctdb->vnn_map->generation;
734 DLIST_ADD(ctdb->pending_calls, state);
736 ctdb_queue_packet(ctdb, &state->c->hdr);
742 make a remote ctdb call - async recv - called in daemon context
744 This is called when the program wants to wait for a ctdb_call to complete and get the
745 results. This call will block unless the call has already completed.
747 int ctdb_daemon_call_recv(struct ctdb_call_state *state, struct ctdb_call *call)
749 while (state->state < CTDB_CALL_DONE) {
750 event_loop_once(state->ctdb_db->ctdb->ev);
752 if (state->state != CTDB_CALL_DONE) {
753 ctdb_set_error(state->ctdb_db->ctdb, "%s", state->errmsg);
758 if (state->call->reply_data.dsize) {
759 call->reply_data.dptr = talloc_memdup(call,
760 state->call->reply_data.dptr,
761 state->call->reply_data.dsize);
762 call->reply_data.dsize = state->call->reply_data.dsize;
764 call->reply_data.dptr = NULL;
765 call->reply_data.dsize = 0;
767 call->status = state->call->status;
774 send a keepalive packet to the other node
776 void ctdb_send_keepalive(struct ctdb_context *ctdb, uint32_t destnode)
778 struct ctdb_req_keepalive *r;
780 if (ctdb->methods == NULL) {
781 DEBUG(DEBUG_ERR,(__location__ " Failed to send keepalive. Transport is DOWN\n"));
785 r = ctdb_transport_allocate(ctdb, ctdb, CTDB_REQ_KEEPALIVE,
786 sizeof(struct ctdb_req_keepalive),
787 struct ctdb_req_keepalive);
788 CTDB_NO_MEMORY_FATAL(ctdb, r);
789 r->hdr.destnode = destnode;
792 ctdb->statistics.keepalive_packets_sent++;
794 ctdb_queue_packet(ctdb, &r->hdr);