2 Unix SMB/CIFS implementation.
3 Samba internal messaging functions
4 Copyright (C) 2007 by Volker Lendecke
5 Copyright (C) 2007 by Andrew Tridgell
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "ctdbd_conn.h"
26 #include "system/select.h"
27 #include "lib/util/util_net.h"
28 #include "lib/util/sys_rw_data.h"
29 #include "lib/util/iov_buf.h"
30 #include "lib/util/select.h"
31 #include "lib/util/debug.h"
32 #include "lib/util/talloc_stack.h"
33 #include "lib/util/genrand.h"
34 #include "lib/util/fault.h"
35 #include "lib/util/dlinklist.h"
36 #include "lib/util/tevent_unix.h"
37 #include "lib/util/sys_rw.h"
38 #include "lib/util/blocking.h"
39 #include "ctdb/include/ctdb_protocol.h"
40 #include "lib/async_req/async_sock.h"
42 /* paths to these include files come from --with-ctdb= in configure */
44 struct ctdbd_srvid_cb
{
46 int (*cb
)(struct tevent_context
*ev
,
47 uint32_t src_vnn
, uint32_t dst_vnn
,
49 const uint8_t *msg
, size_t msglen
,
54 struct ctdbd_connection
{
58 struct ctdbd_srvid_cb
*callbacks
;
63 * Outgoing queue for writev_send of asynchronous ctdb requests
65 struct tevent_queue
*outgoing
;
66 struct tevent_req
**pending
;
67 struct tevent_req
*read_req
;
70 static bool ctdbd_conn_has_async_reqs(struct ctdbd_connection
*conn
)
72 size_t len
= talloc_array_length(conn
->pending
);
76 static uint32_t ctdbd_next_reqid(struct ctdbd_connection
*conn
)
79 if (conn
->reqid
== 0) {
85 static int ctdbd_control(struct ctdbd_connection
*conn
,
86 uint32_t vnn
, uint32_t opcode
,
87 uint64_t srvid
, uint32_t flags
,
89 TALLOC_CTX
*mem_ctx
, TDB_DATA
*outdata
,
93 * exit on fatal communications errors with the ctdbd daemon
95 static void cluster_fatal(const char *why
)
97 DEBUG(0,("cluster fatal event: %s - exiting immediately\n", why
));
98 /* we don't use smb_panic() as we don't want to delay to write
99 a core file. We need to release this process id immediately
100 so that someone else can take over without getting sharing
108 static void ctdb_packet_dump(struct ctdb_req_header
*hdr
)
110 if (DEBUGLEVEL
< 11) {
113 DEBUGADD(11, ("len=%"PRIu32
", magic=%"PRIu32
", vers=%"PRIu32
", "
114 "gen=%"PRIu32
", op=%"PRIu32
", reqid=%"PRIu32
"\n",
124 * Register a srvid with ctdbd
126 int register_with_ctdbd(struct ctdbd_connection
*conn
, uint64_t srvid
,
127 int (*cb
)(struct tevent_context
*ev
,
128 uint32_t src_vnn
, uint32_t dst_vnn
,
130 const uint8_t *msg
, size_t msglen
,
137 size_t num_callbacks
;
138 struct ctdbd_srvid_cb
*tmp
;
140 ret
= ctdbd_control_local(conn
, CTDB_CONTROL_REGISTER_SRVID
, srvid
, 0,
141 tdb_null
, NULL
, NULL
, &cstatus
);
146 num_callbacks
= talloc_array_length(conn
->callbacks
);
148 tmp
= talloc_realloc(conn
, conn
->callbacks
, struct ctdbd_srvid_cb
,
153 conn
->callbacks
= tmp
;
155 conn
->callbacks
[num_callbacks
] = (struct ctdbd_srvid_cb
) {
156 .srvid
= srvid
, .cb
= cb
, .private_data
= private_data
162 static int ctdbd_msg_call_back(struct tevent_context
*ev
,
163 struct ctdbd_connection
*conn
,
164 struct ctdb_req_message_old
*msg
)
167 size_t i
, num_callbacks
;
169 msg_len
= msg
->hdr
.length
;
170 if (msg_len
< offsetof(struct ctdb_req_message_old
, data
)) {
171 DBG_DEBUG("len %"PRIu32
" too small\n", msg_len
);
174 msg_len
-= offsetof(struct ctdb_req_message_old
, data
);
176 if (msg_len
< msg
->datalen
) {
177 DBG_DEBUG("msg_len=%"PRIu32
" < msg->datalen=%"PRIu32
"\n",
178 msg_len
, msg
->datalen
);
182 num_callbacks
= talloc_array_length(conn
->callbacks
);
184 for (i
=0; i
<num_callbacks
; i
++) {
185 struct ctdbd_srvid_cb
*cb
= &conn
->callbacks
[i
];
187 if ((cb
->srvid
== msg
->srvid
) && (cb
->cb
!= NULL
)) {
191 msg
->hdr
.srcnode
, msg
->hdr
.destnode
,
192 msg
->srvid
, msg
->data
, msg
->datalen
,
203 * get our vnn from the cluster
205 static int get_cluster_vnn(struct ctdbd_connection
*conn
, uint32_t *vnn
)
209 ret
= ctdbd_control_local(conn
, CTDB_CONTROL_GET_PNN
, 0, 0,
210 tdb_null
, NULL
, NULL
, &cstatus
);
212 DEBUG(1, ("ctdbd_control failed: %s\n", strerror(ret
)));
215 *vnn
= (uint32_t)cstatus
;
220 * Are we active (i.e. not banned or stopped?)
222 static bool ctdbd_working(struct ctdbd_connection
*conn
, uint32_t vnn
)
225 TDB_DATA outdata
= {0};
226 struct ctdb_node_map_old
*m
;
231 ret
= ctdbd_control_local(conn
, CTDB_CONTROL_GET_NODEMAP
, 0, 0,
232 tdb_null
, talloc_tos(), &outdata
, &cstatus
);
234 DEBUG(1, ("ctdbd_control failed: %s\n", strerror(ret
)));
237 if ((cstatus
!= 0) || (outdata
.dptr
== NULL
)) {
238 DEBUG(2, ("Received invalid ctdb data\n"));
242 m
= (struct ctdb_node_map_old
*)outdata
.dptr
;
244 for (i
=0; i
<m
->num
; i
++) {
245 if (vnn
== m
->nodes
[i
].pnn
) {
251 DEBUG(2, ("Did not find ourselves (node %d) in nodemap\n",
256 if ((m
->nodes
[i
].flags
& NODE_FLAGS_INACTIVE
) != 0) {
257 DEBUG(2, ("Node has status %x, not active\n",
258 (int)m
->nodes
[i
].flags
));
264 TALLOC_FREE(outdata
.dptr
);
268 uint32_t ctdbd_vnn(const struct ctdbd_connection
*conn
)
270 return conn
->our_vnn
;
274 * Get us a ctdb connection
277 static int ctdbd_connect(const char *sockname
, int *pfd
)
279 struct samba_sockaddr addr
= {
280 .sa_socklen
= sizeof(struct sockaddr_un
),
283 .sun_family
= AF_UNIX
,
291 fd
= socket(AF_UNIX
, SOCK_STREAM
, 0);
294 DEBUG(3, ("Could not create socket: %s\n", strerror(err
)));
298 namelen
= strlcpy(addr
.u
.un
.sun_path
,
300 sizeof(addr
.u
.un
.sun_path
));
301 if (namelen
>= sizeof(addr
.u
.un
.sun_path
)) {
302 DEBUG(3, ("%s: Socket name too long: %s\n", __func__
,
308 ret
= connect(fd
, &addr
.u
.sa
, addr
.sa_socklen
);
311 DEBUG(1, ("connect(%s) failed: %s\n", sockname
,
321 static int ctdb_read_packet(int fd
, int timeout
, TALLOC_CTX
*mem_ctx
,
322 struct ctdb_req_header
**result
)
324 struct ctdb_req_header
*req
;
329 struct pollfd pfd
= { .fd
= fd
, .events
= POLLIN
};
332 ret
= sys_poll_intr(&pfd
, 1, timeout
);
344 nread
= read_data(fd
, &msglen
, sizeof(msglen
));
352 if (msglen
< sizeof(struct ctdb_req_header
)) {
356 req
= talloc_size(mem_ctx
, msglen
);
360 talloc_set_name_const(req
, "struct ctdb_req_header");
362 req
->length
= msglen
;
364 nread
= read_data(fd
, ((char *)req
) + sizeof(msglen
),
365 msglen
- sizeof(msglen
));
380 * Read a full ctdbd request. If we have a messaging context, defer incoming
381 * messages that might come in between.
384 static int ctdb_read_req(struct ctdbd_connection
*conn
, uint32_t reqid
,
385 TALLOC_CTX
*mem_ctx
, struct ctdb_req_header
**result
)
387 struct ctdb_req_header
*hdr
= NULL
;
392 ret
= ctdb_read_packet(conn
->fd
, conn
->timeout
, mem_ctx
, &hdr
);
394 DBG_ERR("ctdb_read_packet failed: %s\n", strerror(ret
));
395 cluster_fatal("failed to read data from ctdbd\n");
398 SMB_ASSERT(hdr
!= NULL
);
400 DEBUG(11, ("Received ctdb packet\n"));
401 ctdb_packet_dump(hdr
);
403 if (hdr
->operation
== CTDB_REQ_MESSAGE
) {
404 struct ctdb_req_message_old
*msg
= (struct ctdb_req_message_old
*)hdr
;
406 ret
= ctdbd_msg_call_back(NULL
, conn
, msg
);
416 if ((reqid
!= 0) && (hdr
->reqid
!= reqid
)) {
417 /* we got the wrong reply */
418 DEBUG(0,("Discarding mismatched ctdb reqid %u should have "
419 "been %u\n", hdr
->reqid
, reqid
));
424 *result
= talloc_move(mem_ctx
, &hdr
);
429 static int ctdbd_connection_destructor(struct ctdbd_connection
*c
);
432 * Get us a ctdbd connection
435 static int ctdbd_init_connection_internal(TALLOC_CTX
*mem_ctx
,
436 const char *sockname
, int timeout
,
437 struct ctdbd_connection
*conn
)
441 conn
->timeout
= timeout
;
442 if (conn
->timeout
== 0) {
446 ret
= ctdbd_connect(sockname
, &conn
->fd
);
448 DEBUG(1, ("ctdbd_connect failed: %s\n", strerror(ret
)));
451 talloc_set_destructor(conn
, ctdbd_connection_destructor
);
453 ret
= get_cluster_vnn(conn
, &conn
->our_vnn
);
455 DEBUG(10, ("get_cluster_vnn failed: %s\n", strerror(ret
)));
459 if (!ctdbd_working(conn
, conn
->our_vnn
)) {
460 DEBUG(2, ("Node is not working, can not connect\n"));
464 generate_random_buffer((unsigned char *)&conn
->rand_srvid
,
465 sizeof(conn
->rand_srvid
));
467 ret
= register_with_ctdbd(conn
, conn
->rand_srvid
, NULL
, NULL
);
469 DEBUG(5, ("Could not register random srvid: %s\n",
477 int ctdbd_init_connection(TALLOC_CTX
*mem_ctx
,
478 const char *sockname
, int timeout
,
479 struct ctdbd_connection
**pconn
)
481 struct ctdbd_connection
*conn
;
484 if (!(conn
= talloc_zero(mem_ctx
, struct ctdbd_connection
))) {
485 DEBUG(0, ("talloc failed\n"));
489 ret
= ctdbd_init_connection_internal(mem_ctx
,
494 DBG_ERR("ctdbd_init_connection_internal failed (%s)\n",
507 int ctdbd_reinit_connection(TALLOC_CTX
*mem_ctx
,
508 const char *sockname
, int timeout
,
509 struct ctdbd_connection
*conn
)
513 ret
= ctdbd_connection_destructor(conn
);
515 DBG_ERR("ctdbd_connection_destructor failed\n");
519 ret
= ctdbd_init_connection_internal(mem_ctx
,
524 DBG_ERR("ctdbd_init_connection_internal failed (%s)\n",
532 int ctdbd_init_async_connection(
534 const char *sockname
,
536 struct ctdbd_connection
**pconn
)
538 struct ctdbd_connection
*conn
= NULL
;
541 ret
= ctdbd_init_connection(mem_ctx
, sockname
, timeout
, &conn
);
546 ret
= set_blocking(conn
->fd
, false);
553 conn
->outgoing
= tevent_queue_create(conn
, "ctdb async outgoing");
554 if (conn
->outgoing
== NULL
) {
563 int ctdbd_conn_get_fd(struct ctdbd_connection
*conn
)
569 * Packet handler to receive and handle a ctdb message
571 static int ctdb_handle_message(struct tevent_context
*ev
,
572 struct ctdbd_connection
*conn
,
573 struct ctdb_req_header
*hdr
)
575 struct ctdb_req_message_old
*msg
;
577 if (hdr
->operation
!= CTDB_REQ_MESSAGE
) {
578 DEBUG(0, ("Received async msg of type %u, discarding\n",
583 msg
= (struct ctdb_req_message_old
*)hdr
;
585 ctdbd_msg_call_back(ev
, conn
, msg
);
590 void ctdbd_socket_readable(struct tevent_context
*ev
,
591 struct ctdbd_connection
*conn
)
593 struct ctdb_req_header
*hdr
= NULL
;
596 ret
= ctdb_read_packet(conn
->fd
, conn
->timeout
, talloc_tos(), &hdr
);
598 DBG_ERR("ctdb_read_packet failed: %s\n", strerror(ret
));
599 cluster_fatal("failed to read data from ctdbd\n");
601 SMB_ASSERT(hdr
!= NULL
);
603 ret
= ctdb_handle_message(ev
, conn
, hdr
);
608 DEBUG(10, ("could not handle incoming message: %s\n",
613 int ctdbd_messaging_send_iov(struct ctdbd_connection
*conn
,
614 uint32_t dst_vnn
, uint64_t dst_srvid
,
615 const struct iovec
*iov
, int iovlen
)
617 struct ctdb_req_message_old r
;
618 struct iovec iov2
[iovlen
+1];
619 size_t buflen
= iov_buflen(iov
, iovlen
);
622 r
.hdr
.length
= offsetof(struct ctdb_req_message_old
, data
) + buflen
;
623 r
.hdr
.ctdb_magic
= CTDB_MAGIC
;
624 r
.hdr
.ctdb_version
= CTDB_PROTOCOL
;
625 r
.hdr
.generation
= 1;
626 r
.hdr
.operation
= CTDB_REQ_MESSAGE
;
627 r
.hdr
.destnode
= dst_vnn
;
628 r
.hdr
.srcnode
= conn
->our_vnn
;
633 DEBUG(10, ("ctdbd_messaging_send: Sending ctdb packet\n"));
634 ctdb_packet_dump(&r
.hdr
);
636 iov2
[0].iov_base
= &r
;
637 iov2
[0].iov_len
= offsetof(struct ctdb_req_message_old
, data
);
638 memcpy(&iov2
[1], iov
, iovlen
* sizeof(struct iovec
));
640 nwritten
= write_data_iov(conn
->fd
, iov2
, iovlen
+1);
641 if (nwritten
== -1) {
642 DEBUG(3, ("write_data_iov failed: %s\n", strerror(errno
)));
643 cluster_fatal("cluster dispatch daemon msg write error\n");
650 * send/recv a generic ctdb control message
652 static int ctdbd_control(struct ctdbd_connection
*conn
,
653 uint32_t vnn
, uint32_t opcode
,
654 uint64_t srvid
, uint32_t flags
,
656 TALLOC_CTX
*mem_ctx
, TDB_DATA
*outdata
,
659 struct ctdb_req_control_old req
;
660 struct ctdb_req_header
*hdr
;
661 struct ctdb_reply_control_old
*reply
= NULL
;
666 if (ctdbd_conn_has_async_reqs(conn
)) {
668 * Can't use sync call while an async call is in flight. Adding
669 * this check as a safety net. We'll be using different
670 * connections for sync and async requests, so this shouldn't
671 * happen, but who knows...
673 DBG_ERR("Async ctdb req on sync connection\n");
678 req
.hdr
.length
= offsetof(struct ctdb_req_control_old
, data
) + data
.dsize
;
679 req
.hdr
.ctdb_magic
= CTDB_MAGIC
;
680 req
.hdr
.ctdb_version
= CTDB_PROTOCOL
;
681 req
.hdr
.operation
= CTDB_REQ_CONTROL
;
682 req
.hdr
.reqid
= ctdbd_next_reqid(conn
);
683 req
.hdr
.destnode
= vnn
;
686 req
.datalen
= data
.dsize
;
689 DBG_DEBUG("Sending ctdb packet reqid=%"PRIu32
", vnn=%"PRIu32
", "
690 "opcode=%"PRIu32
", srvid=%"PRIu64
"\n", req
.hdr
.reqid
,
691 req
.hdr
.destnode
, req
.opcode
, req
.srvid
);
692 ctdb_packet_dump(&req
.hdr
);
694 iov
[0].iov_base
= &req
;
695 iov
[0].iov_len
= offsetof(struct ctdb_req_control_old
, data
);
696 iov
[1].iov_base
= data
.dptr
;
697 iov
[1].iov_len
= data
.dsize
;
699 nwritten
= write_data_iov(conn
->fd
, iov
, ARRAY_SIZE(iov
));
700 if (nwritten
== -1) {
701 DEBUG(3, ("write_data_iov failed: %s\n", strerror(errno
)));
702 cluster_fatal("cluster dispatch daemon msg write error\n");
705 if (flags
& CTDB_CTRL_FLAG_NOREPLY
) {
712 ret
= ctdb_read_req(conn
, req
.hdr
.reqid
, NULL
, &hdr
);
714 DEBUG(10, ("ctdb_read_req failed: %s\n", strerror(ret
)));
718 if (hdr
->operation
!= CTDB_REPLY_CONTROL
) {
719 DEBUG(0, ("received invalid reply\n"));
723 reply
= (struct ctdb_reply_control_old
*)hdr
;
726 if (!(outdata
->dptr
= (uint8_t *)talloc_memdup(
727 mem_ctx
, reply
->data
, reply
->datalen
))) {
731 outdata
->dsize
= reply
->datalen
;
734 (*cstatus
) = reply
->status
;
742 * see if a remote process exists
744 bool ctdbd_process_exists(struct ctdbd_connection
*conn
, uint32_t vnn
,
745 pid_t pid
, uint64_t unique_id
)
747 uint8_t buf
[sizeof(pid
)+sizeof(unique_id
)];
751 if (unique_id
== SERVERID_UNIQUE_ID_NOT_TO_VERIFY
) {
752 ret
= ctdbd_control(conn
, vnn
, CTDB_CONTROL_PROCESS_EXISTS
,
754 (TDB_DATA
) { .dptr
= (uint8_t *)&pid
,
755 .dsize
= sizeof(pid
) },
756 NULL
, NULL
, &cstatus
);
760 return (cstatus
== 0);
763 memcpy(buf
, &pid
, sizeof(pid
));
764 memcpy(buf
+sizeof(pid
), &unique_id
, sizeof(unique_id
));
766 ret
= ctdbd_control(conn
, vnn
, CTDB_CONTROL_CHECK_PID_SRVID
, 0, 0,
767 (TDB_DATA
) { .dptr
= buf
, .dsize
= sizeof(buf
) },
768 NULL
, NULL
, &cstatus
);
772 return (cstatus
== 0);
778 char *ctdbd_dbpath(struct ctdbd_connection
*conn
,
779 TALLOC_CTX
*mem_ctx
, uint32_t db_id
)
783 TDB_DATA rdata
= {0};
786 data
.dptr
= (uint8_t*)&db_id
;
787 data
.dsize
= sizeof(db_id
);
789 ret
= ctdbd_control_local(conn
, CTDB_CONTROL_GETDBPATH
, 0, 0, data
,
790 mem_ctx
, &rdata
, &cstatus
);
791 if ((ret
!= 0) || cstatus
!= 0) {
792 DEBUG(0, (__location__
" ctdb_control for getdbpath failed: %s\n",
794 TALLOC_FREE(rdata
.dptr
);
797 return (char *)rdata
.dptr
;
801 * attach to a ctdb database
803 int ctdbd_db_attach(struct ctdbd_connection
*conn
,
804 const char *name
, uint32_t *db_id
, bool persistent
)
810 data
= string_term_tdb_data(name
);
812 ret
= ctdbd_control_local(conn
,
814 ? CTDB_CONTROL_DB_ATTACH_PERSISTENT
815 : CTDB_CONTROL_DB_ATTACH
,
816 0, 0, data
, NULL
, &data
, &cstatus
);
818 DEBUG(0, (__location__
" ctdb_control for db_attach "
819 "failed: %s\n", strerror(ret
)));
823 if (cstatus
!= 0 || data
.dsize
!= sizeof(uint32_t)) {
824 DEBUG(0,(__location__
" ctdb_control for db_attach failed\n"));
825 TALLOC_FREE(data
.dptr
);
829 *db_id
= *(uint32_t *)data
.dptr
;
830 talloc_free(data
.dptr
);
836 * force the migration of a record to this node
838 int ctdbd_migrate(struct ctdbd_connection
*conn
, uint32_t db_id
, TDB_DATA key
)
840 struct ctdb_req_call_old req
;
841 struct ctdb_req_header
*hdr
= NULL
;
846 if (ctdbd_conn_has_async_reqs(conn
)) {
848 * Can't use sync call while an async call is in flight. Adding
849 * this check as a safety net. We'll be using different
850 * connections for sync and async requests, so this shouldn't
851 * happen, but who knows...
853 DBG_ERR("Async ctdb req on sync connection\n");
859 req
.hdr
.length
= offsetof(struct ctdb_req_call_old
, data
) + key
.dsize
;
860 req
.hdr
.ctdb_magic
= CTDB_MAGIC
;
861 req
.hdr
.ctdb_version
= CTDB_PROTOCOL
;
862 req
.hdr
.operation
= CTDB_REQ_CALL
;
863 req
.hdr
.reqid
= ctdbd_next_reqid(conn
);
864 req
.flags
= CTDB_IMMEDIATE_MIGRATION
;
865 req
.callid
= CTDB_NULL_FUNC
;
867 req
.keylen
= key
.dsize
;
869 DEBUG(10, ("ctdbd_migrate: Sending ctdb packet\n"));
870 ctdb_packet_dump(&req
.hdr
);
872 iov
[0].iov_base
= &req
;
873 iov
[0].iov_len
= offsetof(struct ctdb_req_call_old
, data
);
874 iov
[1].iov_base
= key
.dptr
;
875 iov
[1].iov_len
= key
.dsize
;
877 nwritten
= write_data_iov(conn
->fd
, iov
, ARRAY_SIZE(iov
));
878 if (nwritten
== -1) {
879 DEBUG(3, ("write_data_iov failed: %s\n", strerror(errno
)));
880 cluster_fatal("cluster dispatch daemon msg write error\n");
883 ret
= ctdb_read_req(conn
, req
.hdr
.reqid
, NULL
, &hdr
);
885 DEBUG(10, ("ctdb_read_req failed: %s\n", strerror(ret
)));
889 if (hdr
->operation
!= CTDB_REPLY_CALL
) {
890 if (hdr
->operation
== CTDB_REPLY_ERROR
) {
891 DBG_ERR("received error from ctdb\n");
893 DBG_ERR("received invalid reply\n");
906 * Fetch a record and parse it
908 int ctdbd_parse(struct ctdbd_connection
*conn
, uint32_t db_id
,
909 TDB_DATA key
, bool local_copy
,
910 void (*parser
)(TDB_DATA key
, TDB_DATA data
,
914 struct ctdb_req_call_old req
;
915 struct ctdb_req_header
*hdr
= NULL
;
916 struct ctdb_reply_call_old
*reply
;
922 if (ctdbd_conn_has_async_reqs(conn
)) {
924 * Can't use sync call while an async call is in flight. Adding
925 * this check as a safety net. We'll be using different
926 * connections for sync and async requests, so this shouldn't
927 * happen, but who knows...
929 DBG_ERR("Async ctdb req on sync connection\n");
933 flags
= local_copy
? CTDB_WANT_READONLY
: 0;
937 req
.hdr
.length
= offsetof(struct ctdb_req_call_old
, data
) + key
.dsize
;
938 req
.hdr
.ctdb_magic
= CTDB_MAGIC
;
939 req
.hdr
.ctdb_version
= CTDB_PROTOCOL
;
940 req
.hdr
.operation
= CTDB_REQ_CALL
;
941 req
.hdr
.reqid
= ctdbd_next_reqid(conn
);
943 req
.callid
= CTDB_FETCH_FUNC
;
945 req
.keylen
= key
.dsize
;
947 iov
[0].iov_base
= &req
;
948 iov
[0].iov_len
= offsetof(struct ctdb_req_call_old
, data
);
949 iov
[1].iov_base
= key
.dptr
;
950 iov
[1].iov_len
= key
.dsize
;
952 nwritten
= write_data_iov(conn
->fd
, iov
, ARRAY_SIZE(iov
));
953 if (nwritten
== -1) {
954 DEBUG(3, ("write_data_iov failed: %s\n", strerror(errno
)));
955 cluster_fatal("cluster dispatch daemon msg write error\n");
958 ret
= ctdb_read_req(conn
, req
.hdr
.reqid
, NULL
, &hdr
);
960 DEBUG(10, ("ctdb_read_req failed: %s\n", strerror(ret
)));
964 if ((hdr
== NULL
) || (hdr
->operation
!= CTDB_REPLY_CALL
)) {
965 DEBUG(0, ("received invalid reply\n"));
969 reply
= (struct ctdb_reply_call_old
*)hdr
;
971 if (reply
->datalen
== 0) {
973 * Treat an empty record as non-existing
979 parser(key
, make_tdb_data(&reply
->data
[0], reply
->datalen
),
989 Traverse a ctdb database. "conn" must be an otherwise unused
990 ctdb_connection where no other messages but the traverse ones are
994 int ctdbd_traverse(struct ctdbd_connection
*conn
, uint32_t db_id
,
995 void (*fn
)(TDB_DATA key
, TDB_DATA data
,
1001 struct ctdb_traverse_start t
;
1002 int32_t cstatus
= 0;
1004 if (ctdbd_conn_has_async_reqs(conn
)) {
1006 * Can't use sync call while an async call is in flight. Adding
1007 * this check as a safety net. We'll be using different
1008 * connections for sync and async requests, so this shouldn't
1009 * happen, but who knows...
1011 DBG_ERR("Async ctdb req on sync connection\n");
1016 t
.srvid
= conn
->rand_srvid
;
1017 t
.reqid
= ctdbd_next_reqid(conn
);
1019 data
.dptr
= (uint8_t *)&t
;
1020 data
.dsize
= sizeof(t
);
1022 ret
= ctdbd_control_local(conn
, CTDB_CONTROL_TRAVERSE_START
,
1024 0, data
, NULL
, NULL
, &cstatus
);
1026 if ((ret
!= 0) || (cstatus
!= 0)) {
1027 DEBUG(0,("ctdbd_control failed: %s, %d\n", strerror(ret
),
1032 * We need a mapping here
1040 struct ctdb_req_header
*hdr
= NULL
;
1041 struct ctdb_req_message_old
*m
;
1042 struct ctdb_rec_data_old
*d
;
1044 ret
= ctdb_read_packet(conn
->fd
, conn
->timeout
, conn
, &hdr
);
1046 DBG_ERR("ctdb_read_packet failed: %s\n", strerror(ret
));
1047 cluster_fatal("failed to read data from ctdbd\n");
1049 SMB_ASSERT(hdr
!= NULL
);
1051 if (hdr
->operation
!= CTDB_REQ_MESSAGE
) {
1052 DEBUG(0, ("Got operation %u, expected a message\n",
1053 (unsigned)hdr
->operation
));
1057 m
= (struct ctdb_req_message_old
*)hdr
;
1058 d
= (struct ctdb_rec_data_old
*)&m
->data
[0];
1059 if (m
->datalen
< sizeof(uint32_t) || m
->datalen
!= d
->length
) {
1060 DEBUG(0, ("Got invalid traverse data of length %d\n",
1065 key
.dsize
= d
->keylen
;
1066 key
.dptr
= &d
->data
[0];
1067 data
.dsize
= d
->datalen
;
1068 data
.dptr
= &d
->data
[d
->keylen
];
1070 if (key
.dsize
== 0 && data
.dsize
== 0) {
1071 /* end of traverse */
1075 if (data
.dsize
< sizeof(struct ctdb_ltdb_header
)) {
1076 DEBUG(0, ("Got invalid ltdb header length %d\n",
1080 data
.dsize
-= sizeof(struct ctdb_ltdb_header
);
1081 data
.dptr
+= sizeof(struct ctdb_ltdb_header
);
1084 fn(key
, data
, private_data
);
1091 This is used to canonicalize a ctdb_sock_addr structure.
1093 static void smbd_ctdb_canonicalize_ip(const struct sockaddr_storage
*in
,
1094 struct sockaddr_storage
*out
)
1096 memcpy(out
, in
, sizeof (*out
));
1099 if (in
->ss_family
== AF_INET6
) {
1100 const char prefix
[12] = { 0,0,0,0,0,0,0,0,0,0,0xff,0xff };
1101 const struct sockaddr_in6
*in6
=
1102 (const struct sockaddr_in6
*)in
;
1103 struct sockaddr_in
*out4
= (struct sockaddr_in
*)out
;
1104 if (memcmp(&in6
->sin6_addr
, prefix
, 12) == 0) {
1105 memset(out
, 0, sizeof(*out
));
1106 #ifdef HAVE_SOCK_SIN_LEN
1107 out4
->sin_len
= sizeof(*out
);
1109 out4
->sin_family
= AF_INET
;
1110 out4
->sin_port
= in6
->sin6_port
;
1111 memcpy(&out4
->sin_addr
, &in6
->sin6_addr
.s6_addr
[12], 4);
1118 * Register us as a server for a particular tcp connection
1121 int ctdbd_register_ips(struct ctdbd_connection
*conn
,
1122 const struct sockaddr_storage
*_server
,
1123 const struct sockaddr_storage
*_client
,
1124 int (*cb
)(struct tevent_context
*ev
,
1125 uint32_t src_vnn
, uint32_t dst_vnn
,
1127 const uint8_t *msg
, size_t msglen
,
1128 void *private_data
),
1131 struct ctdb_connection p
;
1132 TDB_DATA data
= { .dptr
= (uint8_t *)&p
, .dsize
= sizeof(p
) };
1134 struct sockaddr_storage client
;
1135 struct sockaddr_storage server
;
1138 * Only one connection so far
1141 smbd_ctdb_canonicalize_ip(_client
, &client
);
1142 smbd_ctdb_canonicalize_ip(_server
, &server
);
1144 switch (client
.ss_family
) {
1146 memcpy(&p
.dst
.ip
, &server
, sizeof(p
.dst
.ip
));
1147 memcpy(&p
.src
.ip
, &client
, sizeof(p
.src
.ip
));
1150 memcpy(&p
.dst
.ip6
, &server
, sizeof(p
.dst
.ip6
));
1151 memcpy(&p
.src
.ip6
, &client
, sizeof(p
.src
.ip6
));
1158 * We want to be told about IP releases
1161 ret
= register_with_ctdbd(conn
, CTDB_SRVID_RELEASE_IP
,
1168 * inform ctdb of our tcp connection, so if IP takeover happens ctdb
1169 * can send an extra ack to trigger a reset for our client, so it
1170 * immediately reconnects
1172 ret
= ctdbd_control_local(conn
,
1173 CTDB_CONTROL_TCP_CLIENT
, 0,
1174 CTDB_CTRL_FLAG_NOREPLY
, data
, NULL
, NULL
,
1182 static int ctdbd_control_get_public_ips(struct ctdbd_connection
*conn
,
1184 TALLOC_CTX
*mem_ctx
,
1185 struct ctdb_public_ip_list_old
**_ips
)
1187 struct ctdb_public_ip_list_old
*ips
= NULL
;
1189 int32_t cstatus
= -1;
1196 ret
= ctdbd_control_local(conn
,
1197 CTDB_CONTROL_GET_PUBLIC_IPS
,
1200 tdb_null
, /* indata */
1204 if (ret
!= 0 || cstatus
!= 0) {
1205 DBG_ERR("ctdb_control for getpublicips failed ret:%d cstatus:%d\n",
1210 min_dsize
= offsetof(struct ctdb_public_ip_list_old
, ips
);
1211 if (outdata
.dsize
< min_dsize
) {
1212 DBG_ERR("outdata.dsize=%zu < min_dsize=%zu\n",
1213 outdata
.dsize
, min_dsize
);
1216 max_ips
= (outdata
.dsize
- min_dsize
)/sizeof(struct ctdb_public_ip
);
1217 ips
= (struct ctdb_public_ip_list_old
*)outdata
.dptr
;
1218 if ((size_t)ips
->num
> max_ips
) {
1219 DBG_ERR("ips->num=%zu > max_ips=%zu\n",
1220 (size_t)ips
->num
, max_ips
);
1228 int ctdbd_public_ip_foreach(struct ctdbd_connection
*conn
,
1229 int (*cb
)(uint32_t total_ip_count
,
1230 const struct sockaddr_storage
*ip
,
1232 void *private_data
),
1236 struct ctdb_public_ip_list_old
*ips
= NULL
;
1238 TALLOC_CTX
*frame
= talloc_stackframe();
1240 ret
= ctdbd_control_get_public_ips(conn
, 0, frame
, &ips
);
1246 for (i
=0; i
< ips
->num
; i
++) {
1247 struct samba_sockaddr tmp
= {
1249 .sa
= ips
->ips
[i
].addr
.sa
,
1255 true, /* all ctdb public ips are movable */
1269 call a control on the local node
1271 int ctdbd_control_local(struct ctdbd_connection
*conn
, uint32_t opcode
,
1272 uint64_t srvid
, uint32_t flags
, TDB_DATA data
,
1273 TALLOC_CTX
*mem_ctx
, TDB_DATA
*outdata
,
1276 return ctdbd_control(conn
, CTDB_CURRENT_NODE
, opcode
, srvid
, flags
, data
,
1277 mem_ctx
, outdata
, cstatus
);
1280 int ctdb_watch_us(struct ctdbd_connection
*conn
)
1282 struct ctdb_notify_data_old reg_data
;
1287 reg_data
.srvid
= CTDB_SRVID_SAMBA_NOTIFY
;
1289 reg_data
.notify_data
[0] = 0;
1291 struct_len
= offsetof(struct ctdb_notify_data_old
,
1292 notify_data
) + reg_data
.len
;
1294 ret
= ctdbd_control_local(
1295 conn
, CTDB_CONTROL_REGISTER_NOTIFY
, conn
->rand_srvid
, 0,
1296 make_tdb_data((uint8_t *)®_data
, struct_len
),
1297 NULL
, NULL
, &cstatus
);
1299 DEBUG(1, ("ctdbd_control_local failed: %s\n",
1305 int ctdb_unwatch(struct ctdbd_connection
*conn
)
1307 uint64_t srvid
= CTDB_SRVID_SAMBA_NOTIFY
;
1311 ret
= ctdbd_control_local(
1312 conn
, CTDB_CONTROL_DEREGISTER_NOTIFY
, conn
->rand_srvid
, 0,
1313 make_tdb_data((uint8_t *)&srvid
, sizeof(srvid
)),
1314 NULL
, NULL
, &cstatus
);
1316 DEBUG(1, ("ctdbd_control_local failed: %s\n",
1322 int ctdbd_probe(const char *sockname
, int timeout
)
1325 * Do a very early check if ctdbd is around to avoid an abort and core
1328 struct ctdbd_connection
*conn
= NULL
;
1331 ret
= ctdbd_init_connection(talloc_tos(), sockname
, timeout
,
1335 * We only care if we can connect.
1342 static int ctdbd_connection_destructor(struct ctdbd_connection
*c
)
1351 void ctdbd_prep_hdr_next_reqid(
1352 struct ctdbd_connection
*conn
, struct ctdb_req_header
*hdr
)
1354 *hdr
= (struct ctdb_req_header
) {
1355 .ctdb_magic
= CTDB_MAGIC
,
1356 .ctdb_version
= CTDB_PROTOCOL
,
1357 .reqid
= ctdbd_next_reqid(conn
),
1358 .destnode
= CTDB_CURRENT_NODE
,
1362 struct ctdbd_pkt_read_state
{
1366 static ssize_t
ctdbd_pkt_read_more(
1367 uint8_t *buf
, size_t buflen
, void *private_data
);
1368 static void ctdbd_pkt_read_done(struct tevent_req
*subreq
);
1370 static struct tevent_req
*ctdbd_pkt_read_send(
1371 TALLOC_CTX
*mem_ctx
, struct tevent_context
*ev
, int fd
)
1373 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
1374 struct ctdbd_pkt_read_state
*state
= NULL
;
1376 req
= tevent_req_create(mem_ctx
, &state
, struct ctdbd_pkt_read_state
);
1380 subreq
= read_packet_send(state
, ev
, fd
, 4, ctdbd_pkt_read_more
, NULL
);
1381 if (tevent_req_nomem(subreq
, req
)) {
1382 return tevent_req_post(req
, ev
);
1384 tevent_req_set_callback(subreq
, ctdbd_pkt_read_done
, req
);
1388 static ssize_t
ctdbd_pkt_read_more(
1389 uint8_t *buf
, size_t buflen
, void *private_data
)
1396 return 0; /* Been here, done */
1398 memcpy(&msglen
, buf
, 4);
1400 if (msglen
< sizeof(struct ctdb_req_header
)) {
1403 return msglen
- sizeof(msglen
);
1406 static void ctdbd_pkt_read_done(struct tevent_req
*subreq
)
1408 struct tevent_req
*req
= tevent_req_callback_data(
1409 subreq
, struct tevent_req
);
1410 struct ctdbd_pkt_read_state
*state
= tevent_req_data(
1411 req
, struct ctdbd_pkt_read_state
);
1415 nread
= read_packet_recv(subreq
, state
, &state
->pkt
, &err
);
1416 TALLOC_FREE(subreq
);
1418 tevent_req_error(req
, err
);
1421 tevent_req_done(req
);
1424 static int ctdbd_pkt_read_recv(
1425 struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
, uint8_t **pkt
)
1427 struct ctdbd_pkt_read_state
*state
= tevent_req_data(
1428 req
, struct ctdbd_pkt_read_state
);
1431 if (tevent_req_is_unix_error(req
, &err
)) {
1434 *pkt
= talloc_move(mem_ctx
, &state
->pkt
);
1435 tevent_req_received(req
);
1439 static bool ctdbd_conn_receive_next(struct ctdbd_connection
*conn
);
1440 static void ctdbd_conn_received(struct tevent_req
*subreq
);
1442 struct ctdbd_req_state
{
1443 struct ctdbd_connection
*conn
;
1444 struct tevent_context
*ev
;
1446 struct ctdb_req_header
*reply
;
1449 static void ctdbd_req_unset_pending(struct tevent_req
*req
)
1451 struct ctdbd_req_state
*state
= tevent_req_data(
1452 req
, struct ctdbd_req_state
);
1453 struct ctdbd_connection
*conn
= state
->conn
;
1454 size_t num_pending
= talloc_array_length(conn
->pending
);
1455 size_t i
, num_after
;
1457 tevent_req_set_cleanup_fn(req
, NULL
);
1459 if (num_pending
== 1) {
1461 * conn->read_req is a child of conn->pending
1463 TALLOC_FREE(conn
->pending
);
1464 conn
->read_req
= NULL
;
1468 for (i
=0; i
<num_pending
; i
++) {
1469 if (req
== conn
->pending
[i
]) {
1473 if (i
== num_pending
) {
1475 * Something's seriously broken. Just returning here is the
1476 * right thing nevertheless, the point of this routine is to
1477 * remove ourselves from conn->pending.
1482 num_after
= num_pending
- i
- 1;
1483 if (num_after
> 0) {
1484 memmove(&conn
->pending
[i
],
1485 &conn
->pending
[i
] + 1,
1486 sizeof(*conn
->pending
) * num_after
);
1488 conn
->pending
= talloc_realloc(
1489 NULL
, conn
->pending
, struct tevent_req
*, num_pending
- 1);
1492 static void ctdbd_req_cleanup(
1493 struct tevent_req
*req
, enum tevent_req_state req_state
)
1495 ctdbd_req_unset_pending(req
);
1498 static bool ctdbd_req_set_pending(struct tevent_req
*req
)
1500 struct ctdbd_req_state
*state
= tevent_req_data(
1501 req
, struct ctdbd_req_state
);
1502 struct ctdbd_connection
*conn
= state
->conn
;
1503 struct tevent_req
**pending
= NULL
;
1504 size_t num_pending
= talloc_array_length(conn
->pending
);
1507 pending
= talloc_realloc(
1508 conn
, conn
->pending
, struct tevent_req
*, num_pending
+ 1);
1509 if (pending
== NULL
) {
1512 pending
[num_pending
] = req
;
1513 conn
->pending
= pending
;
1515 tevent_req_set_cleanup_fn(req
, ctdbd_req_cleanup
);
1517 ok
= ctdbd_conn_receive_next(conn
);
1519 ctdbd_req_unset_pending(req
);
1526 static bool ctdbd_conn_receive_next(struct ctdbd_connection
*conn
)
1528 size_t num_pending
= talloc_array_length(conn
->pending
);
1529 struct tevent_req
*req
= NULL
;
1530 struct ctdbd_req_state
*state
= NULL
;
1532 if (conn
->read_req
!= NULL
) {
1535 if (num_pending
== 0) {
1542 req
= conn
->pending
[0];
1543 state
= tevent_req_data(req
, struct ctdbd_req_state
);
1545 conn
->read_req
= ctdbd_pkt_read_send(
1546 conn
->pending
, state
->ev
, conn
->fd
);
1547 if (conn
->read_req
== NULL
) {
1550 tevent_req_set_callback(conn
->read_req
, ctdbd_conn_received
, conn
);
1554 static void ctdbd_conn_received(struct tevent_req
*subreq
)
1556 struct ctdbd_connection
*conn
= tevent_req_callback_data(
1557 subreq
, struct ctdbd_connection
);
1558 TALLOC_CTX
*frame
= talloc_stackframe();
1559 uint8_t *pkt
= NULL
;
1561 struct ctdb_req_header
*hdr
= NULL
;
1563 struct tevent_req
*req
= NULL
;
1564 struct ctdbd_req_state
*state
= NULL
;
1565 size_t i
, num_pending
;
1568 SMB_ASSERT(subreq
== conn
->read_req
);
1569 conn
->read_req
= NULL
;
1571 ret
= ctdbd_pkt_read_recv(subreq
, frame
, &pkt
);
1572 TALLOC_FREE(subreq
);
1574 cluster_fatal("ctdbd_pkt_read failed\n");
1577 hdr
= (struct ctdb_req_header
*)pkt
;
1579 num_pending
= talloc_array_length(conn
->pending
);
1581 for (i
=0; i
<num_pending
; i
++) {
1582 req
= conn
->pending
[i
];
1583 state
= tevent_req_data(req
, struct ctdbd_req_state
);
1584 if (state
->reqid
== reqid
) {
1589 if (i
== num_pending
) {
1595 state
->reply
= talloc_move(state
, &hdr
);
1596 tevent_req_defer_callback(req
, state
->ev
);
1597 tevent_req_done(req
);
1601 ok
= ctdbd_conn_receive_next(conn
);
1603 cluster_fatal("ctdbd_conn_receive_next failed\n");
1607 static void ctdbd_req_written(struct tevent_req
*subreq
);
1609 struct tevent_req
*ctdbd_req_send(
1610 TALLOC_CTX
*mem_ctx
,
1611 struct tevent_context
*ev
,
1612 struct ctdbd_connection
*conn
,
1616 struct tevent_req
*req
= NULL
, *subreq
= NULL
;
1617 struct ctdbd_req_state
*state
= NULL
;
1618 struct ctdb_req_header
*hdr
= NULL
;
1621 req
= tevent_req_create(mem_ctx
, &state
, struct ctdbd_req_state
);
1628 if ((num_iov
== 0) ||
1629 (iov
[0].iov_len
< sizeof(struct ctdb_req_header
))) {
1630 tevent_req_error(req
, EINVAL
);
1631 return tevent_req_post(req
, ev
);
1633 hdr
= iov
[0].iov_base
;
1634 state
->reqid
= hdr
->reqid
;
1636 ok
= ctdbd_req_set_pending(req
);
1638 tevent_req_oom(req
);
1639 return tevent_req_post(req
, ev
);
1642 subreq
= writev_send(
1643 state
, ev
, conn
->outgoing
, conn
->fd
, false, iov
, num_iov
);
1644 if (tevent_req_nomem(subreq
, req
)) {
1645 return tevent_req_post(req
, ev
);
1647 tevent_req_set_callback(subreq
, ctdbd_req_written
, req
);
1652 static void ctdbd_req_written(struct tevent_req
*subreq
)
1654 struct tevent_req
*req
= tevent_req_callback_data(
1655 subreq
, struct tevent_req
);
1659 nwritten
= writev_recv(subreq
, &err
);
1660 TALLOC_FREE(subreq
);
1661 if (nwritten
== -1) {
1662 tevent_req_error(req
, err
);
1668 struct tevent_req
*req
,
1669 TALLOC_CTX
*mem_ctx
,
1670 struct ctdb_req_header
**reply
)
1672 struct ctdbd_req_state
*state
= tevent_req_data(
1673 req
, struct ctdbd_req_state
);
1676 if (tevent_req_is_unix_error(req
, &err
)) {
1679 *reply
= talloc_move(mem_ctx
, &state
->reply
);
1680 tevent_req_received(req
);
1684 struct ctdbd_parse_state
{
1685 struct tevent_context
*ev
;
1686 struct ctdbd_connection
*conn
;
1689 uint8_t _keybuf
[64];
1690 struct ctdb_req_call_old ctdb_req
;
1691 struct iovec iov
[2];
1692 void (*parser
)(TDB_DATA key
,
1694 void *private_data
);
1698 static void ctdbd_parse_done(struct tevent_req
*subreq
);
1700 struct tevent_req
*ctdbd_parse_send(TALLOC_CTX
*mem_ctx
,
1701 struct tevent_context
*ev
,
1702 struct ctdbd_connection
*conn
,
1706 void (*parser
)(TDB_DATA key
,
1708 void *private_data
),
1710 enum dbwrap_req_state
*req_state
)
1712 struct tevent_req
*req
= NULL
;
1713 struct ctdbd_parse_state
*state
= NULL
;
1715 uint32_t packet_length
;
1716 struct tevent_req
*subreq
= NULL
;
1718 req
= tevent_req_create(mem_ctx
, &state
, struct ctdbd_parse_state
);
1720 *req_state
= DBWRAP_REQ_ERROR
;
1724 *req_state
= DBWRAP_REQ_DISPATCHED
;
1726 *state
= (struct ctdbd_parse_state
) {
1729 .reqid
= ctdbd_next_reqid(conn
),
1731 .private_data
= private_data
,
1734 flags
= local_copy
? CTDB_WANT_READONLY
: 0;
1735 packet_length
= offsetof(struct ctdb_req_call_old
, data
) + key
.dsize
;
1738 * Copy the key into our state, as ctdb_pkt_send_cleanup() requires that
1739 * all passed iov elements have a lifetime longer that the tevent_req
1740 * returned by ctdb_pkt_send_send(). This is required continue sending a
1741 * the low level request into the ctdb socket, if a higher level
1742 * ('this') request is canceled (or talloc free'd) by the application
1743 * layer, without sending invalid packets to ctdb.
1745 if (key
.dsize
> sizeof(state
->_keybuf
)) {
1746 state
->key
.dptr
= talloc_memdup(state
, key
.dptr
, key
.dsize
);
1747 if (tevent_req_nomem(state
->key
.dptr
, req
)) {
1748 return tevent_req_post(req
, ev
);
1751 memcpy(state
->_keybuf
, key
.dptr
, key
.dsize
);
1752 state
->key
.dptr
= state
->_keybuf
;
1754 state
->key
.dsize
= key
.dsize
;
1756 state
->ctdb_req
.hdr
.length
= packet_length
;
1757 state
->ctdb_req
.hdr
.ctdb_magic
= CTDB_MAGIC
;
1758 state
->ctdb_req
.hdr
.ctdb_version
= CTDB_PROTOCOL
;
1759 state
->ctdb_req
.hdr
.operation
= CTDB_REQ_CALL
;
1760 state
->ctdb_req
.hdr
.reqid
= state
->reqid
;
1761 state
->ctdb_req
.flags
= flags
;
1762 state
->ctdb_req
.callid
= CTDB_FETCH_FUNC
;
1763 state
->ctdb_req
.db_id
= db_id
;
1764 state
->ctdb_req
.keylen
= state
->key
.dsize
;
1766 state
->iov
[0].iov_base
= &state
->ctdb_req
;
1767 state
->iov
[0].iov_len
= offsetof(struct ctdb_req_call_old
, data
);
1768 state
->iov
[1].iov_base
= state
->key
.dptr
;
1769 state
->iov
[1].iov_len
= state
->key
.dsize
;
1771 subreq
= ctdbd_req_send(
1772 state
, ev
, conn
, state
->iov
, ARRAY_SIZE(state
->iov
));
1773 if (tevent_req_nomem(subreq
, req
)) {
1774 *req_state
= DBWRAP_REQ_ERROR
;
1775 return tevent_req_post(req
, ev
);
1777 tevent_req_set_callback(subreq
, ctdbd_parse_done
, req
);
1782 static void ctdbd_parse_done(struct tevent_req
*subreq
)
1784 struct tevent_req
*req
= tevent_req_callback_data(
1785 subreq
, struct tevent_req
);
1786 struct ctdbd_parse_state
*state
= tevent_req_data(
1787 req
, struct ctdbd_parse_state
);
1788 struct ctdb_req_header
*hdr
= NULL
;
1789 struct ctdb_reply_call_old
*reply
= NULL
;
1792 ret
= ctdbd_req_recv(subreq
, state
, &hdr
);
1793 TALLOC_FREE(subreq
);
1794 if (tevent_req_error(req
, ret
)) {
1795 DBG_DEBUG("ctdb_req_recv failed %s\n", strerror(ret
));
1798 SMB_ASSERT(hdr
!= NULL
);
1800 if (hdr
->operation
!= CTDB_REPLY_CALL
) {
1801 DBG_ERR("received invalid reply\n");
1802 ctdb_packet_dump(hdr
);
1803 tevent_req_error(req
, EIO
);
1807 reply
= (struct ctdb_reply_call_old
*)hdr
;
1809 if (reply
->datalen
== 0) {
1811 * Treat an empty record as non-existing
1813 tevent_req_error(req
, ENOENT
);
1817 state
->parser(state
->key
,
1818 make_tdb_data(&reply
->data
[0], reply
->datalen
),
1819 state
->private_data
);
1821 tevent_req_done(req
);
1825 int ctdbd_parse_recv(struct tevent_req
*req
)
1827 return tevent_req_simple_recv_unix(req
);