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 #ifdef CLUSTER_SUPPORT
27 #include "ctdbd_conn.h"
28 #include "ctdb_packet.h"
32 * It is not possible to include ctdb.h and tdb_compat.h (included via
33 * some other include above) without warnings. This fixes those
41 #ifdef typesafe_cb_preargs
42 #undef typesafe_cb_preargs
45 #ifdef typesafe_cb_postargs
46 #undef typesafe_cb_postargs
49 /* paths to these include files come from --with-ctdb= in configure */
52 #include "ctdb_private.h"
54 struct ctdbd_connection
{
55 struct messaging_context
*msg_ctx
;
59 struct ctdb_packet_context
*pkt
;
62 void (*release_ip_handler
)(const char *ip_addr
, void *private_data
);
63 void *release_ip_priv
;
66 static uint32_t ctdbd_next_reqid(struct ctdbd_connection
*conn
)
69 if (conn
->reqid
== 0) {
75 static NTSTATUS
ctdbd_control(struct ctdbd_connection
*conn
,
76 uint32_t vnn
, uint32 opcode
,
77 uint64_t srvid
, uint32_t flags
, TDB_DATA data
,
78 TALLOC_CTX
*mem_ctx
, TDB_DATA
*outdata
,
82 * exit on fatal communications errors with the ctdbd daemon
84 static void cluster_fatal(const char *why
)
86 DEBUG(0,("cluster fatal event: %s - exiting immediately\n", why
));
87 /* we don't use smb_panic() as we don't want to delay to write
88 a core file. We need to release this process id immediately
89 so that someone else can take over without getting sharing
97 static void ctdb_packet_dump(struct ctdb_req_header
*hdr
)
99 if (DEBUGLEVEL
< 11) {
102 DEBUGADD(11, ("len=%d, magic=%x, vers=%d, gen=%d, op=%d, reqid=%d\n",
103 (int)hdr
->length
, (int)hdr
->ctdb_magic
,
104 (int)hdr
->ctdb_version
, (int)hdr
->generation
,
105 (int)hdr
->operation
, (int)hdr
->reqid
));
109 * Register a srvid with ctdbd
111 NTSTATUS
register_with_ctdbd(struct ctdbd_connection
*conn
, uint64_t srvid
)
115 return ctdbd_control(conn
, CTDB_CURRENT_NODE
,
116 CTDB_CONTROL_REGISTER_SRVID
, srvid
, 0,
117 tdb_null
, NULL
, NULL
, &cstatus
);
121 * get our vnn from the cluster
123 static NTSTATUS
get_cluster_vnn(struct ctdbd_connection
*conn
, uint32
*vnn
)
127 status
= ctdbd_control(conn
,
128 CTDB_CURRENT_NODE
, CTDB_CONTROL_GET_PNN
, 0, 0,
129 tdb_null
, NULL
, NULL
, &cstatus
);
130 if (!NT_STATUS_IS_OK(status
)) {
131 cluster_fatal("ctdbd_control failed\n");
133 *vnn
= (uint32_t)cstatus
;
138 * Are we active (i.e. not banned or stopped?)
140 static bool ctdbd_working(struct ctdbd_connection
*conn
, uint32_t vnn
)
145 struct ctdb_node_map
*m
;
146 uint32_t failure_flags
;
150 status
= ctdbd_control(conn
, CTDB_CURRENT_NODE
,
151 CTDB_CONTROL_GET_NODEMAP
, 0, 0,
152 tdb_null
, talloc_tos(), &outdata
, &cstatus
);
153 if (!NT_STATUS_IS_OK(status
)) {
154 cluster_fatal("ctdbd_control failed\n");
156 if ((cstatus
!= 0) || (outdata
.dptr
== NULL
)) {
157 DEBUG(2, ("Received invalid ctdb data\n"));
161 m
= (struct ctdb_node_map
*)outdata
.dptr
;
163 for (i
=0; i
<m
->num
; i
++) {
164 if (vnn
== m
->nodes
[i
].pnn
) {
170 DEBUG(2, ("Did not find ourselves (node %d) in nodemap\n",
175 failure_flags
= NODE_FLAGS_BANNED
| NODE_FLAGS_DISCONNECTED
176 | NODE_FLAGS_PERMANENTLY_DISABLED
| NODE_FLAGS_STOPPED
;
178 if ((m
->nodes
[i
].flags
& failure_flags
) != 0) {
179 DEBUG(2, ("Node has status %x, not active\n",
180 (int)m
->nodes
[i
].flags
));
186 TALLOC_FREE(outdata
.dptr
);
190 uint32
ctdbd_vnn(const struct ctdbd_connection
*conn
)
192 return conn
->our_vnn
;
196 * Get us a ctdb connection
199 static NTSTATUS
ctdbd_connect(TALLOC_CTX
*mem_ctx
,
200 struct ctdb_packet_context
**presult
)
202 struct ctdb_packet_context
*result
;
203 const char *sockname
= lp_ctdbd_socket();
204 struct sockaddr_un addr
;
208 if (!sockname
|| !*sockname
) {
209 sockname
= CTDB_PATH
;
212 fd
= socket(AF_UNIX
, SOCK_STREAM
, 0);
214 DEBUG(3, ("Could not create socket: %s\n", strerror(errno
)));
215 return map_nt_error_from_unix(errno
);
219 addr
.sun_family
= AF_UNIX
;
220 strncpy(addr
.sun_path
, sockname
, sizeof(addr
.sun_path
));
222 salen
= sizeof(struct sockaddr_un
);
223 if (connect(fd
, (struct sockaddr
*)(void *)&addr
, salen
) == -1) {
224 DEBUG(1, ("connect(%s) failed: %s\n", sockname
,
227 return map_nt_error_from_unix(errno
);
230 if (!(result
= ctdb_packet_init(mem_ctx
, fd
))) {
232 return NT_STATUS_NO_MEMORY
;
240 * Do we have a complete ctdb packet in the queue?
243 static bool ctdb_req_complete(const uint8_t *buf
, size_t available
,
249 if (available
< sizeof(msglen
)) {
253 msglen
= *((uint32
*)buf
);
255 DEBUG(11, ("msglen = %d\n", msglen
));
257 if (msglen
< sizeof(struct ctdb_req_header
)) {
258 DEBUG(0, ("Got invalid msglen: %d, expected at least %d for "
259 "the req_header\n", (int)msglen
,
260 (int)sizeof(struct ctdb_req_header
)));
261 cluster_fatal("ctdbd protocol error\n");
264 if (available
< msglen
) {
273 * State necessary to defer an incoming message while we are waiting for a
277 struct deferred_msg_state
{
278 struct messaging_context
*msg_ctx
;
279 struct messaging_rec
*rec
;
283 * Timed event handler for the deferred message
286 static void deferred_message_dispatch(struct event_context
*event_ctx
,
287 struct timed_event
*te
,
291 struct deferred_msg_state
*state
= talloc_get_type_abort(
292 private_data
, struct deferred_msg_state
);
294 messaging_dispatch_rec(state
->msg_ctx
, state
->rec
);
299 struct req_pull_state
{
305 * Pull a ctdb request out of the incoming ctdb_packet queue
308 static NTSTATUS
ctdb_req_pull(uint8_t *buf
, size_t length
,
311 struct req_pull_state
*state
= (struct req_pull_state
*)private_data
;
313 state
->req
.data
= talloc_move(state
->mem_ctx
, &buf
);
314 state
->req
.length
= length
;
319 * Fetch a messaging_rec from an incoming ctdb style message
322 static struct messaging_rec
*ctdb_pull_messaging_rec(TALLOC_CTX
*mem_ctx
,
323 size_t overall_length
,
324 struct ctdb_req_message
*msg
)
326 struct messaging_rec
*result
;
328 enum ndr_err_code ndr_err
;
330 if ((overall_length
< offsetof(struct ctdb_req_message
, data
))
332 < offsetof(struct ctdb_req_message
, data
) + msg
->datalen
)) {
334 cluster_fatal("got invalid msg length");
337 if (!(result
= talloc(mem_ctx
, struct messaging_rec
))) {
338 DEBUG(0, ("talloc failed\n"));
342 blob
= data_blob_const(msg
->data
, msg
->datalen
);
344 ndr_err
= ndr_pull_struct_blob(
345 &blob
, result
, result
,
346 (ndr_pull_flags_fn_t
)ndr_pull_messaging_rec
);
348 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
349 DEBUG(0, ("ndr_pull_struct_blob failed: %s\n",
350 ndr_errstr(ndr_err
)));
355 if (DEBUGLEVEL
>= 11) {
356 DEBUG(11, ("ctdb_pull_messaging_rec:\n"));
357 NDR_PRINT_DEBUG(messaging_rec
, result
);
363 static NTSTATUS
ctdb_packet_fd_read_sync(struct ctdb_packet_context
*ctx
)
365 int timeout
= lp_ctdb_timeout();
370 return ctdb_packet_fd_read_sync_timeout(ctx
, timeout
);
374 * Read a full ctdbd request. If we have a messaging context, defer incoming
375 * messages that might come in between.
378 static NTSTATUS
ctdb_read_req(struct ctdbd_connection
*conn
, uint32 reqid
,
379 TALLOC_CTX
*mem_ctx
, void *result
)
381 struct ctdb_req_header
*hdr
;
382 struct req_pull_state state
;
387 state
.mem_ctx
= mem_ctx
;
389 while (!ctdb_packet_handler(conn
->pkt
, ctdb_req_complete
,
390 ctdb_req_pull
, &state
, &status
)) {
394 status
= ctdb_packet_fd_read_sync(conn
->pkt
);
396 if (NT_STATUS_EQUAL(status
, NT_STATUS_NETWORK_BUSY
)) {
399 } else if (NT_STATUS_EQUAL(status
, NT_STATUS_RETRY
)) {
404 if (!NT_STATUS_IS_OK(status
)) {
405 DEBUG(0, ("packet_fd_read failed: %s\n", nt_errstr(status
)));
406 cluster_fatal("ctdbd died\n");
410 if (!NT_STATUS_IS_OK(status
)) {
411 DEBUG(0, ("Could not read ctdb_packet: %s\n", nt_errstr(status
)));
412 cluster_fatal("ctdbd died\n");
415 hdr
= (struct ctdb_req_header
*)state
.req
.data
;
417 DEBUG(11, ("Received ctdb packet\n"));
418 ctdb_packet_dump(hdr
);
420 if (hdr
->operation
== CTDB_REQ_MESSAGE
) {
421 struct timed_event
*evt
;
422 struct deferred_msg_state
*msg_state
;
423 struct ctdb_req_message
*msg
= (struct ctdb_req_message
*)hdr
;
425 if (conn
->msg_ctx
== NULL
) {
426 DEBUG(1, ("Got a message without having a msg ctx, "
427 "dropping msg %llu\n",
428 (long long unsigned)msg
->srvid
));
432 if ((conn
->release_ip_handler
!= NULL
)
433 && (msg
->srvid
== CTDB_SRVID_RELEASE_IP
)) {
434 /* must be dispatched immediately */
435 DEBUG(10, ("received CTDB_SRVID_RELEASE_IP\n"));
436 conn
->release_ip_handler((const char *)msg
->data
,
437 conn
->release_ip_priv
);
442 if ((msg
->srvid
== CTDB_SRVID_RECONFIGURE
)
443 || (msg
->srvid
== CTDB_SRVID_SAMBA_NOTIFY
)) {
445 DEBUG(1, ("ctdb_read_req: Got %s message\n",
446 (msg
->srvid
== CTDB_SRVID_RECONFIGURE
)
447 ? "cluster reconfigure" : "SAMBA_NOTIFY"));
449 messaging_send(conn
->msg_ctx
,
450 messaging_server_id(conn
->msg_ctx
),
451 MSG_SMB_BRL_VALIDATE
, &data_blob_null
);
452 messaging_send(conn
->msg_ctx
,
453 messaging_server_id(conn
->msg_ctx
),
454 MSG_DBWRAP_G_LOCK_RETRY
,
460 msg_state
= talloc(NULL
, struct deferred_msg_state
);
461 if (msg_state
== NULL
) {
462 DEBUG(0, ("talloc failed\n"));
467 if (!(msg_state
->rec
= ctdb_pull_messaging_rec(
468 msg_state
, state
.req
.length
, msg
))) {
469 DEBUG(0, ("ctdbd_pull_messaging_rec failed\n"));
470 TALLOC_FREE(msg_state
);
477 msg_state
->msg_ctx
= conn
->msg_ctx
;
480 * We're waiting for a call reply, but an async message has
481 * crossed. Defer dispatching to the toplevel event loop.
483 evt
= event_add_timed(conn
->msg_ctx
->event_ctx
,
484 conn
->msg_ctx
->event_ctx
,
486 deferred_message_dispatch
,
489 DEBUG(0, ("event_add_timed failed\n"));
490 TALLOC_FREE(msg_state
);
498 if ((reqid
!= 0) && (hdr
->reqid
!= reqid
)) {
499 /* we got the wrong reply */
500 DEBUG(0,("Discarding mismatched ctdb reqid %u should have "
501 "been %u\n", hdr
->reqid
, reqid
));
506 *((void **)result
) = talloc_move(mem_ctx
, &hdr
);
512 * Get us a ctdbd connection
515 static NTSTATUS
ctdbd_init_connection(TALLOC_CTX
*mem_ctx
,
516 struct ctdbd_connection
**pconn
)
518 struct ctdbd_connection
*conn
;
521 if (!(conn
= talloc_zero(mem_ctx
, struct ctdbd_connection
))) {
522 DEBUG(0, ("talloc failed\n"));
523 return NT_STATUS_NO_MEMORY
;
526 status
= ctdbd_connect(conn
, &conn
->pkt
);
528 if (!NT_STATUS_IS_OK(status
)) {
529 DEBUG(10, ("ctdbd_connect failed: %s\n", nt_errstr(status
)));
533 status
= get_cluster_vnn(conn
, &conn
->our_vnn
);
535 if (!NT_STATUS_IS_OK(status
)) {
536 DEBUG(10, ("get_cluster_vnn failed: %s\n", nt_errstr(status
)));
540 if (!ctdbd_working(conn
, conn
->our_vnn
)) {
541 DEBUG(2, ("Node is not working, can not connect\n"));
542 status
= NT_STATUS_INTERNAL_DB_ERROR
;
546 generate_random_buffer((unsigned char *)&conn
->rand_srvid
,
547 sizeof(conn
->rand_srvid
));
549 status
= register_with_ctdbd(conn
, conn
->rand_srvid
);
551 if (!NT_STATUS_IS_OK(status
)) {
552 DEBUG(5, ("Could not register random srvid: %s\n",
566 * Get us a ctdbd connection and register us as a process
569 NTSTATUS
ctdbd_messaging_connection(TALLOC_CTX
*mem_ctx
,
570 struct ctdbd_connection
**pconn
)
572 struct ctdbd_connection
*conn
;
575 status
= ctdbd_init_connection(mem_ctx
, &conn
);
577 if (!NT_STATUS_IS_OK(status
)) {
581 status
= register_with_ctdbd(conn
, (uint64_t)getpid());
582 if (!NT_STATUS_IS_OK(status
)) {
586 status
= register_with_ctdbd(conn
, MSG_SRVID_SAMBA
);
587 if (!NT_STATUS_IS_OK(status
)) {
591 status
= register_with_ctdbd(conn
, CTDB_SRVID_SAMBA_NOTIFY
);
592 if (!NT_STATUS_IS_OK(status
)) {
604 struct messaging_context
*ctdb_conn_msg_ctx(struct ctdbd_connection
*conn
)
606 return conn
->msg_ctx
;
609 int ctdbd_conn_get_fd(struct ctdbd_connection
*conn
)
611 return ctdb_packet_get_fd(conn
->pkt
);
615 * Packet handler to receive and handle a ctdb message
617 static NTSTATUS
ctdb_handle_message(uint8_t *buf
, size_t length
,
620 struct ctdbd_connection
*conn
= talloc_get_type_abort(
621 private_data
, struct ctdbd_connection
);
622 struct ctdb_req_message
*msg
;
623 struct messaging_rec
*msg_rec
;
625 msg
= (struct ctdb_req_message
*)buf
;
627 if (msg
->hdr
.operation
!= CTDB_REQ_MESSAGE
) {
628 DEBUG(0, ("Received async msg of type %u, discarding\n",
629 msg
->hdr
.operation
));
631 return NT_STATUS_INVALID_PARAMETER
;
634 if ((conn
->release_ip_handler
!= NULL
)
635 && (msg
->srvid
== CTDB_SRVID_RELEASE_IP
)) {
636 /* must be dispatched immediately */
637 DEBUG(10, ("received CTDB_SRVID_RELEASE_IP\n"));
638 conn
->release_ip_handler((const char *)msg
->data
,
639 conn
->release_ip_priv
);
644 SMB_ASSERT(conn
->msg_ctx
!= NULL
);
646 if ((msg
->srvid
== CTDB_SRVID_RECONFIGURE
)
647 || (msg
->srvid
== CTDB_SRVID_SAMBA_NOTIFY
)){
648 DEBUG(0,("Got cluster reconfigure message\n"));
650 * when the cluster is reconfigured or someone of the
651 * family has passed away (SAMBA_NOTIFY), we need to
652 * clean the brl database
654 messaging_send(conn
->msg_ctx
,
655 messaging_server_id(conn
->msg_ctx
),
656 MSG_SMB_BRL_VALIDATE
, &data_blob_null
);
658 messaging_send(conn
->msg_ctx
,
659 messaging_server_id(conn
->msg_ctx
),
660 MSG_DBWRAP_G_LOCK_RETRY
,
667 /* only messages to our pid or the broadcast are valid here */
668 if (msg
->srvid
!= getpid() && msg
->srvid
!= MSG_SRVID_SAMBA
) {
669 DEBUG(0,("Got unexpected message with srvid=%llu\n",
670 (unsigned long long)msg
->srvid
));
675 if (!(msg_rec
= ctdb_pull_messaging_rec(NULL
, length
, msg
))) {
676 DEBUG(10, ("ctdb_pull_messaging_rec failed\n"));
678 return NT_STATUS_NO_MEMORY
;
681 messaging_dispatch_rec(conn
->msg_ctx
, msg_rec
);
683 TALLOC_FREE(msg_rec
);
689 * The ctdbd socket is readable asynchronuously
692 static void ctdbd_socket_handler(struct event_context
*event_ctx
,
693 struct fd_event
*event
,
697 struct ctdbd_connection
*conn
= talloc_get_type_abort(
698 private_data
, struct ctdbd_connection
);
702 status
= ctdb_packet_fd_read(conn
->pkt
);
704 if (!NT_STATUS_IS_OK(status
)) {
705 DEBUG(0, ("packet_fd_read failed: %s\n", nt_errstr(status
)));
706 cluster_fatal("ctdbd died\n");
709 while (ctdb_packet_handler(conn
->pkt
, ctdb_req_complete
,
710 ctdb_handle_message
, conn
, &status
)) {
711 if (!NT_STATUS_IS_OK(status
)) {
712 DEBUG(10, ("could not handle incoming message: %s\n",
719 * Prepare a ctdbd connection to receive messages
722 NTSTATUS
ctdbd_register_msg_ctx(struct ctdbd_connection
*conn
,
723 struct messaging_context
*msg_ctx
)
725 SMB_ASSERT(conn
->msg_ctx
== NULL
);
726 SMB_ASSERT(conn
->fde
== NULL
);
728 if (!(conn
->fde
= event_add_fd(msg_ctx
->event_ctx
, conn
,
729 ctdb_packet_get_fd(conn
->pkt
),
731 ctdbd_socket_handler
,
733 DEBUG(0, ("event_add_fd failed\n"));
734 return NT_STATUS_NO_MEMORY
;
737 conn
->msg_ctx
= msg_ctx
;
743 * Send a messaging message across a ctdbd
746 NTSTATUS
ctdbd_messaging_send(struct ctdbd_connection
*conn
,
747 uint32 dst_vnn
, uint64 dst_srvid
,
748 struct messaging_rec
*msg
)
750 struct ctdb_req_message r
;
754 enum ndr_err_code ndr_err
;
756 if (!(mem_ctx
= talloc_init("ctdbd_messaging_send"))) {
757 DEBUG(0, ("talloc failed\n"));
758 return NT_STATUS_NO_MEMORY
;
761 ndr_err
= ndr_push_struct_blob(
763 (ndr_push_flags_fn_t
)ndr_push_messaging_rec
);
765 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
766 DEBUG(0, ("ndr_push_struct_blob failed: %s\n",
767 ndr_errstr(ndr_err
)));
768 status
= ndr_map_error2ntstatus(ndr_err
);
772 r
.hdr
.length
= offsetof(struct ctdb_req_message
, data
) + blob
.length
;
773 r
.hdr
.ctdb_magic
= CTDB_MAGIC
;
774 r
.hdr
.ctdb_version
= CTDB_VERSION
;
775 r
.hdr
.generation
= 1;
776 r
.hdr
.operation
= CTDB_REQ_MESSAGE
;
777 r
.hdr
.destnode
= dst_vnn
;
778 r
.hdr
.srcnode
= conn
->our_vnn
;
781 r
.datalen
= blob
.length
;
783 DEBUG(10, ("ctdbd_messaging_send: Sending ctdb packet\n"));
784 ctdb_packet_dump(&r
.hdr
);
786 status
= ctdb_packet_send(
788 data_blob_const(&r
, offsetof(struct ctdb_req_message
, data
)),
791 if (!NT_STATUS_IS_OK(status
)) {
792 DEBUG(0, ("ctdb_packet_send failed: %s\n", nt_errstr(status
)));
796 status
= ctdb_packet_flush(conn
->pkt
);
798 if (!NT_STATUS_IS_OK(status
)) {
799 DEBUG(3, ("write to ctdbd failed: %s\n", nt_errstr(status
)));
800 cluster_fatal("cluster dispatch daemon msg write error\n");
803 status
= NT_STATUS_OK
;
805 TALLOC_FREE(mem_ctx
);
810 * send/recv a generic ctdb control message
812 static NTSTATUS
ctdbd_control(struct ctdbd_connection
*conn
,
813 uint32_t vnn
, uint32 opcode
,
814 uint64_t srvid
, uint32_t flags
,
816 TALLOC_CTX
*mem_ctx
, TDB_DATA
*outdata
,
819 struct ctdb_req_control req
;
820 struct ctdb_reply_control
*reply
= NULL
;
821 struct ctdbd_connection
*new_conn
= NULL
;
825 status
= ctdbd_init_connection(NULL
, &new_conn
);
827 if (!NT_STATUS_IS_OK(status
)) {
828 DEBUG(10, ("Could not init temp connection: %s\n",
837 req
.hdr
.length
= offsetof(struct ctdb_req_control
, data
) + data
.dsize
;
838 req
.hdr
.ctdb_magic
= CTDB_MAGIC
;
839 req
.hdr
.ctdb_version
= CTDB_VERSION
;
840 req
.hdr
.operation
= CTDB_REQ_CONTROL
;
841 req
.hdr
.reqid
= ctdbd_next_reqid(conn
);
842 req
.hdr
.destnode
= vnn
;
845 req
.datalen
= data
.dsize
;
848 DEBUG(10, ("ctdbd_control: Sending ctdb packet\n"));
849 ctdb_packet_dump(&req
.hdr
);
851 status
= ctdb_packet_send(
853 data_blob_const(&req
, offsetof(struct ctdb_req_control
, data
)),
854 data_blob_const(data
.dptr
, data
.dsize
));
856 if (!NT_STATUS_IS_OK(status
)) {
857 DEBUG(3, ("ctdb_packet_send failed: %s\n", nt_errstr(status
)));
861 status
= ctdb_packet_flush(conn
->pkt
);
863 if (!NT_STATUS_IS_OK(status
)) {
864 DEBUG(3, ("write to ctdbd failed: %s\n", nt_errstr(status
)));
865 cluster_fatal("cluster dispatch daemon control write error\n");
868 if (flags
& CTDB_CTRL_FLAG_NOREPLY
) {
869 TALLOC_FREE(new_conn
);
876 status
= ctdb_read_req(conn
, req
.hdr
.reqid
, NULL
, (void *)&reply
);
878 if (!NT_STATUS_IS_OK(status
)) {
879 DEBUG(10, ("ctdb_read_req failed: %s\n", nt_errstr(status
)));
883 if (reply
->hdr
.operation
!= CTDB_REPLY_CONTROL
) {
884 DEBUG(0, ("received invalid reply\n"));
889 if (!(outdata
->dptr
= (uint8
*)talloc_memdup(
890 mem_ctx
, reply
->data
, reply
->datalen
))) {
892 return NT_STATUS_NO_MEMORY
;
894 outdata
->dsize
= reply
->datalen
;
897 (*cstatus
) = reply
->status
;
900 status
= NT_STATUS_OK
;
903 TALLOC_FREE(new_conn
);
909 * see if a remote process exists
911 bool ctdbd_process_exists(struct ctdbd_connection
*conn
, uint32 vnn
, pid_t pid
)
919 if (!ctdb_processes_exist(conn
, &id
, 1, &result
)) {
920 DEBUG(10, ("ctdb_processes_exist failed\n"));
926 bool ctdb_processes_exist(struct ctdbd_connection
*conn
,
927 const struct server_id
*pids
, int num_pids
,
930 TALLOC_CTX
*frame
= talloc_stackframe();
936 reqids
= talloc_array(talloc_tos(), uint32_t, num_pids
);
937 if (reqids
== NULL
) {
941 for (i
=0; i
<num_pids
; i
++) {
942 struct ctdb_req_control req
;
946 reqids
[i
] = ctdbd_next_reqid(conn
);
951 * pids[i].pid is uint64_t, scale down to pid_t which
952 * is the wire protocol towards ctdb.
956 DEBUG(10, ("Requesting PID %d/%d, reqid=%d\n",
957 (int)pids
[i
].vnn
, (int)pid
,
960 req
.hdr
.length
= offsetof(struct ctdb_req_control
, data
);
961 req
.hdr
.length
+= sizeof(pid
);
962 req
.hdr
.ctdb_magic
= CTDB_MAGIC
;
963 req
.hdr
.ctdb_version
= CTDB_VERSION
;
964 req
.hdr
.operation
= CTDB_REQ_CONTROL
;
965 req
.hdr
.reqid
= reqids
[i
];
966 req
.hdr
.destnode
= pids
[i
].vnn
;
967 req
.opcode
= CTDB_CONTROL_PROCESS_EXISTS
;
969 req
.datalen
= sizeof(pid
);
972 DEBUG(10, ("ctdbd_control: Sending ctdb packet\n"));
973 ctdb_packet_dump(&req
.hdr
);
975 status
= ctdb_packet_send(
978 &req
, offsetof(struct ctdb_req_control
, data
)),
979 data_blob_const(&pid
, sizeof(pid
)));
980 if (!NT_STATUS_IS_OK(status
)) {
981 DEBUG(10, ("ctdb_packet_send failed: %s\n",
987 status
= ctdb_packet_flush(conn
->pkt
);
988 if (!NT_STATUS_IS_OK(status
)) {
989 DEBUG(10, ("ctdb_packet_flush failed: %s\n",
996 while (num_received
< num_pids
) {
997 struct ctdb_reply_control
*reply
= NULL
;
1000 status
= ctdb_read_req(conn
, 0, talloc_tos(), (void *)&reply
);
1001 if (!NT_STATUS_IS_OK(status
)) {
1002 DEBUG(10, ("ctdb_read_req failed: %s\n",
1003 nt_errstr(status
)));
1007 if (reply
->hdr
.operation
!= CTDB_REPLY_CONTROL
) {
1008 DEBUG(10, ("Received invalid reply\n"));
1012 reqid
= reply
->hdr
.reqid
;
1014 DEBUG(10, ("Received reqid %d\n", (int)reqid
));
1016 for (i
=0; i
<num_pids
; i
++) {
1017 if (reqid
== reqids
[i
]) {
1021 if (i
== num_pids
) {
1022 DEBUG(10, ("Received unknown record number %u\n",
1026 results
[i
] = ((reply
->status
) == 0);
1037 struct ctdb_vnn_list
{
1040 unsigned num_srvids
;
1041 unsigned num_filled
;
1043 unsigned *pid_indexes
;
1047 * Get a list of all vnns mentioned in a list of
1048 * server_ids. vnn_indexes tells where in the vnns array we have to
1051 static bool ctdb_collect_vnns(TALLOC_CTX
*mem_ctx
,
1052 const struct server_id
*pids
, unsigned num_pids
,
1053 struct ctdb_vnn_list
**pvnns
,
1054 unsigned *pnum_vnns
)
1056 struct ctdb_vnn_list
*vnns
= NULL
;
1057 unsigned *vnn_indexes
= NULL
;
1058 unsigned i
, num_vnns
= 0;
1060 vnn_indexes
= talloc_array(mem_ctx
, unsigned, num_pids
);
1061 if (vnn_indexes
== NULL
) {
1065 for (i
=0; i
<num_pids
; i
++) {
1067 uint32_t vnn
= pids
[i
].vnn
;
1069 for (j
=0; j
<num_vnns
; j
++) {
1070 if (vnn
== vnns
[j
].vnn
) {
1078 * Already in the array
1080 vnns
[j
].num_srvids
+= 1;
1083 vnns
= talloc_realloc(mem_ctx
, vnns
, struct ctdb_vnn_list
,
1088 vnns
[num_vnns
].vnn
= vnn
;
1089 vnns
[num_vnns
].num_srvids
= 1;
1090 vnns
[num_vnns
].num_filled
= 0;
1093 for (i
=0; i
<num_vnns
; i
++) {
1094 struct ctdb_vnn_list
*vnn
= &vnns
[i
];
1096 vnn
->srvids
= talloc_array(vnns
, uint64_t, vnn
->num_srvids
);
1097 if (vnn
->srvids
== NULL
) {
1100 vnn
->pid_indexes
= talloc_array(vnns
, unsigned,
1102 if (vnn
->pid_indexes
== NULL
) {
1106 for (i
=0; i
<num_pids
; i
++) {
1107 struct ctdb_vnn_list
*vnn
= &vnns
[vnn_indexes
[i
]];
1108 vnn
->srvids
[vnn
->num_filled
] = pids
[i
].unique_id
;
1109 vnn
->pid_indexes
[vnn
->num_filled
] = i
;
1110 vnn
->num_filled
+= 1;
1113 TALLOC_FREE(vnn_indexes
);
1115 *pnum_vnns
= num_vnns
;
1119 TALLOC_FREE(vnn_indexes
);
1123 #ifdef HAVE_CTDB_CONTROL_CHECK_SRVIDS_DECL
1125 bool ctdb_serverids_exist(struct ctdbd_connection
*conn
,
1126 const struct server_id
*pids
, unsigned num_pids
,
1129 unsigned i
, num_received
;
1131 struct ctdb_vnn_list
*vnns
= NULL
;
1133 bool result
= false;
1135 if (!ctdb_collect_vnns(talloc_tos(), pids
, num_pids
,
1136 &vnns
, &num_vnns
)) {
1140 for (i
=0; i
<num_vnns
; i
++) {
1141 struct ctdb_vnn_list
*vnn
= &vnns
[i
];
1142 struct ctdb_req_control req
;
1144 vnn
->reqid
= ctdbd_next_reqid(conn
);
1148 DEBUG(10, ("Requesting VNN %d, reqid=%d, num_srvids=%u\n",
1149 (int)vnn
->vnn
, (int)vnn
->reqid
, vnn
->num_srvids
));
1151 req
.hdr
.length
= offsetof(struct ctdb_req_control
, data
);
1152 req
.hdr
.ctdb_magic
= CTDB_MAGIC
;
1153 req
.hdr
.ctdb_version
= CTDB_VERSION
;
1154 req
.hdr
.operation
= CTDB_REQ_CONTROL
;
1155 req
.hdr
.reqid
= vnn
->reqid
;
1156 req
.hdr
.destnode
= vnn
->vnn
;
1157 req
.opcode
= CTDB_CONTROL_CHECK_SRVIDS
;
1159 req
.datalen
= sizeof(uint64_t) * vnn
->num_srvids
;
1160 req
.hdr
.length
+= req
.datalen
;
1163 DEBUG(10, ("ctdbd_control: Sending ctdb packet\n"));
1164 ctdb_packet_dump(&req
.hdr
);
1166 status
= ctdb_packet_send(
1169 &req
, offsetof(struct ctdb_req_control
,
1171 data_blob_const(vnn
->srvids
, req
.datalen
));
1172 if (!NT_STATUS_IS_OK(status
)) {
1173 DEBUG(10, ("ctdb_packet_send failed: %s\n",
1174 nt_errstr(status
)));
1179 status
= ctdb_packet_flush(conn
->pkt
);
1180 if (!NT_STATUS_IS_OK(status
)) {
1181 DEBUG(10, ("ctdb_packet_flush failed: %s\n",
1182 nt_errstr(status
)));
1188 while (num_received
< num_vnns
) {
1189 struct ctdb_reply_control
*reply
= NULL
;
1190 struct ctdb_vnn_list
*vnn
;
1193 status
= ctdb_read_req(conn
, 0, talloc_tos(), (void *)&reply
);
1194 if (!NT_STATUS_IS_OK(status
)) {
1195 DEBUG(10, ("ctdb_read_req failed: %s\n",
1196 nt_errstr(status
)));
1200 if (reply
->hdr
.operation
!= CTDB_REPLY_CONTROL
) {
1201 DEBUG(10, ("Received invalid reply\n"));
1205 reqid
= reply
->hdr
.reqid
;
1207 DEBUG(10, ("Received reqid %d\n", (int)reqid
));
1209 for (i
=0; i
<num_vnns
; i
++) {
1210 if (reqid
== vnns
[i
].reqid
) {
1214 if (i
== num_vnns
) {
1215 DEBUG(10, ("Received unknown reqid number %u\n",
1220 DEBUG(10, ("Found index %u\n", i
));
1224 DEBUG(10, ("Received vnn %u, vnn->num_srvids %u, datalen %u\n",
1225 (unsigned)vnn
->vnn
, vnn
->num_srvids
,
1226 (unsigned)reply
->datalen
));
1228 if (reply
->datalen
< ((vnn
->num_srvids
+7)/8)) {
1229 DEBUG(10, ("Received short reply\n"));
1233 for (i
=0; i
<vnn
->num_srvids
; i
++) {
1234 int idx
= vnn
->pid_indexes
[i
];
1236 if (pids
[i
].unique_id
==
1237 SERVERID_UNIQUE_ID_NOT_TO_VERIFY
) {
1238 results
[idx
] = true;
1241 results
[idx
] = ((reply
->data
[i
/8] & (1<<(i
%8))) != 0);
1254 #endif /* HAVE_CTDB_CONTROL_CHECK_SRVIDS_DECL */
1259 char *ctdbd_dbpath(struct ctdbd_connection
*conn
,
1260 TALLOC_CTX
*mem_ctx
, uint32_t db_id
)
1266 data
.dptr
= (uint8_t*)&db_id
;
1267 data
.dsize
= sizeof(db_id
);
1269 status
= ctdbd_control(conn
, CTDB_CURRENT_NODE
,
1270 CTDB_CONTROL_GETDBPATH
, 0, 0, data
,
1271 mem_ctx
, &data
, &cstatus
);
1272 if (!NT_STATUS_IS_OK(status
) || cstatus
!= 0) {
1273 DEBUG(0,(__location__
" ctdb_control for getdbpath failed\n"));
1277 return (char *)data
.dptr
;
1281 * attach to a ctdb database
1283 NTSTATUS
ctdbd_db_attach(struct ctdbd_connection
*conn
,
1284 const char *name
, uint32_t *db_id
, int tdb_flags
)
1289 bool persistent
= (tdb_flags
& TDB_CLEAR_IF_FIRST
) == 0;
1291 data
.dptr
= (uint8_t*)name
;
1292 data
.dsize
= strlen(name
)+1;
1294 status
= ctdbd_control(conn
, CTDB_CURRENT_NODE
,
1296 ? CTDB_CONTROL_DB_ATTACH_PERSISTENT
1297 : CTDB_CONTROL_DB_ATTACH
,
1298 tdb_flags
, 0, data
, NULL
, &data
, &cstatus
);
1299 if (!NT_STATUS_IS_OK(status
)) {
1300 DEBUG(0, (__location__
" ctdb_control for db_attach "
1301 "failed: %s\n", nt_errstr(status
)));
1305 if (cstatus
!= 0 || data
.dsize
!= sizeof(uint32_t)) {
1306 DEBUG(0,(__location__
" ctdb_control for db_attach failed\n"));
1307 return NT_STATUS_INTERNAL_ERROR
;
1310 *db_id
= *(uint32_t *)data
.dptr
;
1311 talloc_free(data
.dptr
);
1313 if (!(tdb_flags
& TDB_SEQNUM
)) {
1314 return NT_STATUS_OK
;
1317 data
.dptr
= (uint8_t *)db_id
;
1318 data
.dsize
= sizeof(*db_id
);
1320 status
= ctdbd_control(conn
, CTDB_CURRENT_NODE
,
1321 CTDB_CONTROL_ENABLE_SEQNUM
, 0, 0, data
,
1322 NULL
, NULL
, &cstatus
);
1323 if (!NT_STATUS_IS_OK(status
) || cstatus
!= 0) {
1324 DEBUG(0,(__location__
" ctdb_control for enable seqnum "
1326 return NT_STATUS_IS_OK(status
) ? NT_STATUS_INTERNAL_ERROR
:
1330 return NT_STATUS_OK
;
1334 * force the migration of a record to this node
1336 NTSTATUS
ctdbd_migrate(struct ctdbd_connection
*conn
, uint32 db_id
,
1339 struct ctdb_req_call req
;
1340 struct ctdb_reply_call
*reply
;
1345 req
.hdr
.length
= offsetof(struct ctdb_req_call
, data
) + key
.dsize
;
1346 req
.hdr
.ctdb_magic
= CTDB_MAGIC
;
1347 req
.hdr
.ctdb_version
= CTDB_VERSION
;
1348 req
.hdr
.operation
= CTDB_REQ_CALL
;
1349 req
.hdr
.reqid
= ctdbd_next_reqid(conn
);
1350 req
.flags
= CTDB_IMMEDIATE_MIGRATION
;
1351 req
.callid
= CTDB_NULL_FUNC
;
1353 req
.keylen
= key
.dsize
;
1355 DEBUG(10, ("ctdbd_migrate: Sending ctdb packet\n"));
1356 ctdb_packet_dump(&req
.hdr
);
1358 status
= ctdb_packet_send(
1360 data_blob_const(&req
, offsetof(struct ctdb_req_call
, data
)),
1361 data_blob_const(key
.dptr
, key
.dsize
));
1363 if (!NT_STATUS_IS_OK(status
)) {
1364 DEBUG(3, ("ctdb_packet_send failed: %s\n", nt_errstr(status
)));
1368 status
= ctdb_packet_flush(conn
->pkt
);
1370 if (!NT_STATUS_IS_OK(status
)) {
1371 DEBUG(3, ("write to ctdbd failed: %s\n", nt_errstr(status
)));
1372 cluster_fatal("cluster dispatch daemon control write error\n");
1375 status
= ctdb_read_req(conn
, req
.hdr
.reqid
, NULL
, (void *)&reply
);
1377 if (!NT_STATUS_IS_OK(status
)) {
1378 DEBUG(0, ("ctdb_read_req failed: %s\n", nt_errstr(status
)));
1382 if (reply
->hdr
.operation
!= CTDB_REPLY_CALL
) {
1383 DEBUG(0, ("received invalid reply\n"));
1384 status
= NT_STATUS_INTERNAL_ERROR
;
1388 status
= NT_STATUS_OK
;
1396 * remotely fetch a record (read-only)
1398 NTSTATUS
ctdbd_fetch(struct ctdbd_connection
*conn
, uint32 db_id
,
1399 TDB_DATA key
, TALLOC_CTX
*mem_ctx
, TDB_DATA
*data
,
1402 struct ctdb_req_call req
;
1403 struct ctdb_reply_call
*reply
;
1407 #ifdef HAVE_CTDB_WANT_READONLY_DECL
1408 flags
= local_copy
? CTDB_WANT_READONLY
: 0;
1415 req
.hdr
.length
= offsetof(struct ctdb_req_call
, data
) + key
.dsize
;
1416 req
.hdr
.ctdb_magic
= CTDB_MAGIC
;
1417 req
.hdr
.ctdb_version
= CTDB_VERSION
;
1418 req
.hdr
.operation
= CTDB_REQ_CALL
;
1419 req
.hdr
.reqid
= ctdbd_next_reqid(conn
);
1421 req
.callid
= CTDB_FETCH_FUNC
;
1423 req
.keylen
= key
.dsize
;
1425 status
= ctdb_packet_send(
1427 data_blob_const(&req
, offsetof(struct ctdb_req_call
, data
)),
1428 data_blob_const(key
.dptr
, key
.dsize
));
1430 if (!NT_STATUS_IS_OK(status
)) {
1431 DEBUG(3, ("ctdb_packet_send failed: %s\n", nt_errstr(status
)));
1435 status
= ctdb_packet_flush(conn
->pkt
);
1437 if (!NT_STATUS_IS_OK(status
)) {
1438 DEBUG(3, ("write to ctdbd failed: %s\n", nt_errstr(status
)));
1439 cluster_fatal("cluster dispatch daemon control write error\n");
1442 status
= ctdb_read_req(conn
, req
.hdr
.reqid
, NULL
, (void *)&reply
);
1444 if (!NT_STATUS_IS_OK(status
)) {
1445 DEBUG(0, ("ctdb_read_req failed: %s\n", nt_errstr(status
)));
1449 if (reply
->hdr
.operation
!= CTDB_REPLY_CALL
) {
1450 DEBUG(0, ("received invalid reply\n"));
1451 status
= NT_STATUS_INTERNAL_ERROR
;
1455 data
->dsize
= reply
->datalen
;
1456 if (data
->dsize
== 0) {
1461 data
->dptr
= (uint8
*)talloc_memdup(mem_ctx
, &reply
->data
[0],
1463 if (data
->dptr
== NULL
) {
1464 DEBUG(0, ("talloc failed\n"));
1465 status
= NT_STATUS_NO_MEMORY
;
1470 status
= NT_STATUS_OK
;
1476 struct ctdbd_traverse_state
{
1477 void (*fn
)(TDB_DATA key
, TDB_DATA data
, void *private_data
);
1482 * Handle a traverse record coming in on the ctdbd connection
1485 static NTSTATUS
ctdb_traverse_handler(uint8_t *buf
, size_t length
,
1488 struct ctdbd_traverse_state
*state
=
1489 (struct ctdbd_traverse_state
*)private_data
;
1491 struct ctdb_req_message
*m
;
1492 struct ctdb_rec_data
*d
;
1495 m
= (struct ctdb_req_message
*)buf
;
1497 if (length
< sizeof(*m
) || m
->hdr
.length
!= length
) {
1498 DEBUG(0, ("Got invalid message of length %d\n", (int)length
));
1500 return NT_STATUS_UNEXPECTED_IO_ERROR
;
1503 d
= (struct ctdb_rec_data
*)&m
->data
[0];
1504 if (m
->datalen
< sizeof(uint32_t) || m
->datalen
!= d
->length
) {
1505 DEBUG(0, ("Got invalid traverse data of length %d\n",
1508 return NT_STATUS_UNEXPECTED_IO_ERROR
;
1511 key
.dsize
= d
->keylen
;
1512 key
.dptr
= &d
->data
[0];
1513 data
.dsize
= d
->datalen
;
1514 data
.dptr
= &d
->data
[d
->keylen
];
1516 if (key
.dsize
== 0 && data
.dsize
== 0) {
1517 /* end of traverse */
1518 return NT_STATUS_END_OF_FILE
;
1521 if (data
.dsize
< sizeof(struct ctdb_ltdb_header
)) {
1522 DEBUG(0, ("Got invalid ltdb header length %d\n",
1525 return NT_STATUS_UNEXPECTED_IO_ERROR
;
1527 data
.dsize
-= sizeof(struct ctdb_ltdb_header
);
1528 data
.dptr
+= sizeof(struct ctdb_ltdb_header
);
1531 state
->fn(key
, data
, state
->private_data
);
1535 return NT_STATUS_OK
;
1539 Traverse a ctdb database. This uses a kind-of hackish way to open a second
1540 connection to ctdbd to avoid the hairy recursive and async problems with
1544 NTSTATUS
ctdbd_traverse(uint32 db_id
,
1545 void (*fn
)(TDB_DATA key
, TDB_DATA data
,
1546 void *private_data
),
1549 struct ctdbd_connection
*conn
;
1553 struct ctdb_traverse_start t
;
1555 struct ctdbd_traverse_state state
;
1558 status
= ctdbd_init_connection(NULL
, &conn
);
1560 if (!NT_STATUS_IS_OK(status
)) {
1561 DEBUG(0, ("ctdbd_init_connection failed: %s\n",
1562 nt_errstr(status
)));
1567 t
.srvid
= conn
->rand_srvid
;
1568 t
.reqid
= ctdbd_next_reqid(conn
);
1570 data
.dptr
= (uint8_t *)&t
;
1571 data
.dsize
= sizeof(t
);
1573 status
= ctdbd_control(conn
, CTDB_CURRENT_NODE
,
1574 CTDB_CONTROL_TRAVERSE_START
, conn
->rand_srvid
, 0,
1575 data
, NULL
, NULL
, &cstatus
);
1577 if (!NT_STATUS_IS_OK(status
) || (cstatus
!= 0)) {
1579 DEBUG(0,("ctdbd_control failed: %s, %d\n", nt_errstr(status
),
1582 if (NT_STATUS_IS_OK(status
)) {
1584 * We need a mapping here
1586 status
= NT_STATUS_UNSUCCESSFUL
;
1592 state
.private_data
= private_data
;
1596 status
= NT_STATUS_OK
;
1598 if (ctdb_packet_handler(conn
->pkt
, ctdb_req_complete
,
1599 ctdb_traverse_handler
, &state
, &status
)) {
1601 if (NT_STATUS_EQUAL(status
, NT_STATUS_END_OF_FILE
)) {
1602 status
= NT_STATUS_OK
;
1607 * There might be more in the queue
1612 if (!NT_STATUS_IS_OK(status
)) {
1616 status
= ctdb_packet_fd_read_sync(conn
->pkt
);
1618 if (NT_STATUS_EQUAL(status
, NT_STATUS_RETRY
)) {
1620 * There might be more in the queue
1625 if (NT_STATUS_EQUAL(status
, NT_STATUS_END_OF_FILE
)) {
1626 status
= NT_STATUS_OK
;
1630 if (!NT_STATUS_IS_OK(status
)) {
1631 DEBUG(0, ("ctdb_packet_fd_read_sync failed: %s\n", nt_errstr(status
)));
1632 cluster_fatal("ctdbd died\n");
1642 This is used to canonicalize a ctdb_sock_addr structure.
1644 static void smbd_ctdb_canonicalize_ip(const struct sockaddr_storage
*in
,
1645 struct sockaddr_storage
*out
)
1647 memcpy(out
, in
, sizeof (*out
));
1650 if (in
->ss_family
== AF_INET6
) {
1651 const char prefix
[12] = { 0,0,0,0,0,0,0,0,0,0,0xff,0xff };
1652 const struct sockaddr_in6
*in6
= (struct sockaddr_in6
*)in
;
1653 struct sockaddr_in
*out4
= (struct sockaddr_in
*)out
;
1654 if (memcmp(&in6
->sin6_addr
, prefix
, 12) == 0) {
1655 memset(out
, 0, sizeof(*out
));
1656 #ifdef HAVE_SOCK_SIN_LEN
1657 out4
->sin_len
= sizeof(*out
);
1659 out4
->sin_family
= AF_INET
;
1660 out4
->sin_port
= in6
->sin6_port
;
1661 memcpy(&out4
->sin_addr
, &in6
->sin6_addr
.s6_addr
[12], 4);
1668 * Register us as a server for a particular tcp connection
1671 NTSTATUS
ctdbd_register_ips(struct ctdbd_connection
*conn
,
1672 const struct sockaddr_storage
*_server
,
1673 const struct sockaddr_storage
*_client
,
1674 void (*release_ip_handler
)(const char *ip_addr
,
1675 void *private_data
),
1679 * we still use ctdb_control_tcp for ipv4
1680 * because we want to work against older ctdb
1681 * versions at runtime
1683 struct ctdb_control_tcp p4
;
1684 #ifdef HAVE_STRUCT_CTDB_CONTROL_TCP_ADDR
1685 struct ctdb_control_tcp_addr p
;
1689 struct sockaddr_storage client
;
1690 struct sockaddr_storage server
;
1693 * Only one connection so far
1695 SMB_ASSERT(conn
->release_ip_handler
== NULL
);
1697 smbd_ctdb_canonicalize_ip(_client
, &client
);
1698 smbd_ctdb_canonicalize_ip(_server
, &server
);
1700 switch (client
.ss_family
) {
1702 memcpy(&p4
.dest
, &server
, sizeof(p4
.dest
));
1703 memcpy(&p4
.src
, &client
, sizeof(p4
.src
));
1704 data
.dptr
= (uint8_t *)&p4
;
1705 data
.dsize
= sizeof(p4
);
1707 #ifdef HAVE_STRUCT_CTDB_CONTROL_TCP_ADDR
1709 memcpy(&p
.dest
.ip6
, &server
, sizeof(p
.dest
.ip6
));
1710 memcpy(&p
.src
.ip6
, &client
, sizeof(p
.src
.ip6
));
1711 data
.dptr
= (uint8_t *)&p
;
1712 data
.dsize
= sizeof(p
);
1716 return NT_STATUS_INTERNAL_ERROR
;
1719 conn
->release_ip_handler
= release_ip_handler
;
1720 conn
->release_ip_priv
= private_data
;
1723 * We want to be told about IP releases
1726 status
= register_with_ctdbd(conn
, CTDB_SRVID_RELEASE_IP
);
1727 if (!NT_STATUS_IS_OK(status
)) {
1732 * inform ctdb of our tcp connection, so if IP takeover happens ctdb
1733 * can send an extra ack to trigger a reset for our client, so it
1734 * immediately reconnects
1736 return ctdbd_control(conn
, CTDB_CURRENT_NODE
,
1737 CTDB_CONTROL_TCP_CLIENT
, 0,
1738 CTDB_CTRL_FLAG_NOREPLY
, data
, NULL
, NULL
, NULL
);
1742 * We want to handle reconfigure events
1744 NTSTATUS
ctdbd_register_reconfigure(struct ctdbd_connection
*conn
)
1746 return register_with_ctdbd(conn
, CTDB_SRVID_RECONFIGURE
);
1750 call a control on the local node
1752 NTSTATUS
ctdbd_control_local(struct ctdbd_connection
*conn
, uint32 opcode
,
1753 uint64_t srvid
, uint32_t flags
, TDB_DATA data
,
1754 TALLOC_CTX
*mem_ctx
, TDB_DATA
*outdata
,
1757 return ctdbd_control(conn
, CTDB_CURRENT_NODE
, opcode
, srvid
, flags
, data
, mem_ctx
, outdata
, cstatus
);
1760 NTSTATUS
ctdb_watch_us(struct ctdbd_connection
*conn
)
1762 struct ctdb_client_notify_register reg_data
;
1767 reg_data
.srvid
= CTDB_SRVID_SAMBA_NOTIFY
;
1769 reg_data
.notify_data
[0] = 0;
1771 struct_len
= offsetof(struct ctdb_client_notify_register
,
1772 notify_data
) + reg_data
.len
;
1774 status
= ctdbd_control_local(
1775 conn
, CTDB_CONTROL_REGISTER_NOTIFY
, conn
->rand_srvid
, 0,
1776 make_tdb_data((uint8_t *)®_data
, struct_len
),
1777 NULL
, NULL
, &cstatus
);
1778 if (!NT_STATUS_IS_OK(status
)) {
1779 DEBUG(1, ("ctdbd_control_local failed: %s\n",
1780 nt_errstr(status
)));
1785 NTSTATUS
ctdb_unwatch(struct ctdbd_connection
*conn
)
1787 struct ctdb_client_notify_deregister dereg_data
;
1791 dereg_data
.srvid
= CTDB_SRVID_SAMBA_NOTIFY
;
1793 status
= ctdbd_control_local(
1794 conn
, CTDB_CONTROL_DEREGISTER_NOTIFY
, conn
->rand_srvid
, 0,
1795 make_tdb_data((uint8_t *)&dereg_data
, sizeof(dereg_data
)),
1796 NULL
, NULL
, &cstatus
);
1797 if (!NT_STATUS_IS_OK(status
)) {
1798 DEBUG(1, ("ctdbd_control_local failed: %s\n",
1799 nt_errstr(status
)));