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/>.
24 #include "ctdbd_conn.h"
25 #include "system/select.h"
26 #include "lib/sys_rw_data.h"
30 /* paths to these include files come from --with-ctdb= in configure */
33 #include "ctdb_private.h"
35 struct ctdbd_connection
{
36 struct messaging_context
*msg_ctx
;
42 struct tevent_fd
*fde
;
44 bool (*release_ip_handler
)(const char *ip_addr
, void *private_data
);
45 void *release_ip_priv
;
48 static uint32_t ctdbd_next_reqid(struct ctdbd_connection
*conn
)
51 if (conn
->reqid
== 0) {
57 static NTSTATUS
ctdbd_control(struct ctdbd_connection
*conn
,
58 uint32_t vnn
, uint32_t opcode
,
59 uint64_t srvid
, uint32_t flags
, TDB_DATA data
,
60 TALLOC_CTX
*mem_ctx
, TDB_DATA
*outdata
,
64 * exit on fatal communications errors with the ctdbd daemon
66 static void cluster_fatal(const char *why
)
68 DEBUG(0,("cluster fatal event: %s - exiting immediately\n", why
));
69 /* we don't use smb_panic() as we don't want to delay to write
70 a core file. We need to release this process id immediately
71 so that someone else can take over without getting sharing
79 static void ctdb_packet_dump(struct ctdb_req_header
*hdr
)
81 if (DEBUGLEVEL
< 11) {
84 DEBUGADD(11, ("len=%d, magic=%x, vers=%d, gen=%d, op=%d, reqid=%d\n",
85 (int)hdr
->length
, (int)hdr
->ctdb_magic
,
86 (int)hdr
->ctdb_version
, (int)hdr
->generation
,
87 (int)hdr
->operation
, (int)hdr
->reqid
));
91 * Register a srvid with ctdbd
93 NTSTATUS
register_with_ctdbd(struct ctdbd_connection
*conn
, uint64_t srvid
)
101 status
= ctdbd_control(conn
, CTDB_CURRENT_NODE
,
102 CTDB_CONTROL_REGISTER_SRVID
, srvid
, 0,
103 tdb_null
, NULL
, NULL
, &cstatus
);
104 if (!NT_STATUS_IS_OK(status
)) {
108 num_srvids
= talloc_array_length(conn
->srvids
);
110 tmp
= talloc_realloc(conn
, conn
->srvids
, uint64_t,
113 return NT_STATUS_NO_MEMORY
;
117 conn
->srvids
[num_srvids
] = srvid
;
121 static bool ctdb_is_our_srvid(struct ctdbd_connection
*conn
, uint64_t srvid
)
123 size_t i
, num_srvids
;
125 num_srvids
= talloc_array_length(conn
->srvids
);
127 for (i
=0; i
<num_srvids
; i
++) {
128 if (srvid
== conn
->srvids
[i
]) {
136 * get our vnn from the cluster
138 static NTSTATUS
get_cluster_vnn(struct ctdbd_connection
*conn
, uint32_t *vnn
)
142 status
= ctdbd_control(conn
,
143 CTDB_CURRENT_NODE
, CTDB_CONTROL_GET_PNN
, 0, 0,
144 tdb_null
, NULL
, NULL
, &cstatus
);
145 if (!NT_STATUS_IS_OK(status
)) {
146 DEBUG(1, ("ctdbd_control failed: %s\n", nt_errstr(status
)));
149 *vnn
= (uint32_t)cstatus
;
154 * Are we active (i.e. not banned or stopped?)
156 static bool ctdbd_working(struct ctdbd_connection
*conn
, uint32_t vnn
)
161 struct ctdb_node_map
*m
;
162 uint32_t failure_flags
;
166 status
= ctdbd_control(conn
, CTDB_CURRENT_NODE
,
167 CTDB_CONTROL_GET_NODEMAP
, 0, 0,
168 tdb_null
, talloc_tos(), &outdata
, &cstatus
);
169 if (!NT_STATUS_IS_OK(status
)) {
170 DEBUG(1, ("ctdbd_control failed: %s\n", nt_errstr(status
)));
173 if ((cstatus
!= 0) || (outdata
.dptr
== NULL
)) {
174 DEBUG(2, ("Received invalid ctdb data\n"));
178 m
= (struct ctdb_node_map
*)outdata
.dptr
;
180 for (i
=0; i
<m
->num
; i
++) {
181 if (vnn
== m
->nodes
[i
].pnn
) {
187 DEBUG(2, ("Did not find ourselves (node %d) in nodemap\n",
192 failure_flags
= NODE_FLAGS_BANNED
| NODE_FLAGS_DISCONNECTED
193 | NODE_FLAGS_PERMANENTLY_DISABLED
| NODE_FLAGS_STOPPED
;
195 if ((m
->nodes
[i
].flags
& failure_flags
) != 0) {
196 DEBUG(2, ("Node has status %x, not active\n",
197 (int)m
->nodes
[i
].flags
));
203 TALLOC_FREE(outdata
.dptr
);
207 uint32_t ctdbd_vnn(const struct ctdbd_connection
*conn
)
209 return conn
->our_vnn
;
212 const char *lp_ctdbd_socket(void)
216 ret
= lp__ctdbd_socket();
217 if (ret
!= NULL
&& strlen(ret
) > 0) {
225 * Get us a ctdb connection
228 static int ctdbd_connect(int *pfd
)
230 const char *sockname
= lp_ctdbd_socket();
231 struct sockaddr_un addr
= { 0, };
236 fd
= socket(AF_UNIX
, SOCK_STREAM
, 0);
239 DEBUG(3, ("Could not create socket: %s\n", strerror(err
)));
243 addr
.sun_family
= AF_UNIX
;
245 namelen
= strlcpy(addr
.sun_path
, sockname
, sizeof(addr
.sun_path
));
246 if (namelen
>= sizeof(addr
.sun_path
)) {
247 DEBUG(3, ("%s: Socket name too long: %s\n", __func__
,
253 salen
= sizeof(struct sockaddr_un
);
255 if (connect(fd
, (struct sockaddr
*)(void *)&addr
, salen
) == -1) {
257 DEBUG(1, ("connect(%s) failed: %s\n", sockname
,
268 * State necessary to defer an incoming message while we are waiting for a
272 struct deferred_msg_state
{
273 struct messaging_context
*msg_ctx
;
274 struct messaging_rec
*rec
;
278 * Timed event handler for the deferred message
281 static void deferred_message_dispatch(struct tevent_context
*event_ctx
,
282 struct tevent_timer
*te
,
286 struct deferred_msg_state
*state
= talloc_get_type_abort(
287 private_data
, struct deferred_msg_state
);
289 messaging_dispatch_rec(state
->msg_ctx
, state
->rec
);
295 * Fetch a messaging_rec from an incoming ctdb style message
298 static struct messaging_rec
*ctdb_pull_messaging_rec(TALLOC_CTX
*mem_ctx
,
299 size_t overall_length
,
300 struct ctdb_req_message
*msg
)
302 struct messaging_rec
*result
;
304 enum ndr_err_code ndr_err
;
306 if ((overall_length
< offsetof(struct ctdb_req_message
, data
))
308 < offsetof(struct ctdb_req_message
, data
) + msg
->datalen
)) {
310 cluster_fatal("got invalid msg length");
313 if (!(result
= talloc(mem_ctx
, struct messaging_rec
))) {
314 DEBUG(0, ("talloc failed\n"));
318 blob
= data_blob_const(msg
->data
, msg
->datalen
);
320 ndr_err
= ndr_pull_struct_blob(
321 &blob
, result
, result
,
322 (ndr_pull_flags_fn_t
)ndr_pull_messaging_rec
);
324 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
325 DEBUG(0, ("ndr_pull_struct_blob failed: %s\n",
326 ndr_errstr(ndr_err
)));
331 if (DEBUGLEVEL
>= 11) {
332 DEBUG(11, ("ctdb_pull_messaging_rec:\n"));
333 NDR_PRINT_DEBUG(messaging_rec
, result
);
339 static NTSTATUS
ctdb_read_packet(int fd
, TALLOC_CTX
*mem_ctx
,
340 struct ctdb_req_header
**result
)
342 int timeout
= lp_ctdb_timeout();
343 struct ctdb_req_header
*req
;
353 ret
= poll_one_fd(fd
, POLLIN
, timeout
, &revents
);
355 return map_nt_error_from_unix(errno
);
358 return NT_STATUS_IO_TIMEOUT
;
361 return NT_STATUS_UNEXPECTED_IO_ERROR
;
365 status
= read_data_ntstatus(fd
, (char *)&msglen
, sizeof(msglen
));
366 if (!NT_STATUS_IS_OK(status
)) {
370 if (msglen
< sizeof(struct ctdb_req_header
)) {
371 return NT_STATUS_UNEXPECTED_IO_ERROR
;
374 req
= talloc_size(mem_ctx
, msglen
);
376 return NT_STATUS_NO_MEMORY
;
378 talloc_set_name_const(req
, "struct ctdb_req_header");
380 req
->length
= msglen
;
382 status
= read_data_ntstatus(fd
, ((char *)req
) + sizeof(msglen
),
383 msglen
- sizeof(msglen
));
384 if (!NT_STATUS_IS_OK(status
)) {
393 * Read a full ctdbd request. If we have a messaging context, defer incoming
394 * messages that might come in between.
397 static NTSTATUS
ctdb_read_req(struct ctdbd_connection
*conn
, uint32_t reqid
,
399 struct ctdb_req_header
**result
)
401 struct ctdb_req_header
*hdr
;
406 status
= ctdb_read_packet(conn
->fd
, mem_ctx
, &hdr
);
407 if (!NT_STATUS_IS_OK(status
)) {
408 DEBUG(0, ("ctdb_read_packet failed: %s\n", nt_errstr(status
)));
409 cluster_fatal("ctdbd died\n");
412 DEBUG(11, ("Received ctdb packet\n"));
413 ctdb_packet_dump(hdr
);
415 if (hdr
->operation
== CTDB_REQ_MESSAGE
) {
416 struct tevent_timer
*evt
;
417 struct deferred_msg_state
*msg_state
;
418 struct ctdb_req_message
*msg
= (struct ctdb_req_message
*)hdr
;
420 if (conn
->msg_ctx
== NULL
) {
421 DEBUG(1, ("Got a message without having a msg ctx, "
422 "dropping msg %llu\n",
423 (long long unsigned)msg
->srvid
));
427 if ((conn
->release_ip_handler
!= NULL
)
428 && (msg
->srvid
== CTDB_SRVID_RELEASE_IP
)) {
431 /* must be dispatched immediately */
432 DEBUG(10, ("received CTDB_SRVID_RELEASE_IP\n"));
433 ret
= conn
->release_ip_handler((const char *)msg
->data
,
434 conn
->release_ip_priv
);
439 * We need to release the ip,
440 * so return an error to the upper layers.
442 * We make sure we don't trigger this again.
444 conn
->release_ip_handler
= NULL
;
445 conn
->release_ip_priv
= NULL
;
446 return NT_STATUS_ADDRESS_CLOSED
;
451 if ((msg
->srvid
== CTDB_SRVID_RECONFIGURE
)
452 || (msg
->srvid
== CTDB_SRVID_SAMBA_NOTIFY
)) {
454 DEBUG(1, ("ctdb_read_req: Got %s message\n",
455 (msg
->srvid
== CTDB_SRVID_RECONFIGURE
)
456 ? "cluster reconfigure" : "SAMBA_NOTIFY"));
458 messaging_send(conn
->msg_ctx
,
459 messaging_server_id(conn
->msg_ctx
),
460 MSG_SMB_BRL_VALIDATE
, &data_blob_null
);
465 msg_state
= talloc(NULL
, struct deferred_msg_state
);
466 if (msg_state
== NULL
) {
467 DEBUG(0, ("talloc failed\n"));
472 if (!(msg_state
->rec
= ctdb_pull_messaging_rec(
473 msg_state
, msg
->hdr
.length
, msg
))) {
474 DEBUG(0, ("ctdbd_pull_messaging_rec failed\n"));
475 TALLOC_FREE(msg_state
);
482 msg_state
->msg_ctx
= conn
->msg_ctx
;
485 * We're waiting for a call reply, but an async message has
486 * crossed. Defer dispatching to the toplevel event loop.
488 evt
= tevent_add_timer(messaging_tevent_context(conn
->msg_ctx
),
489 messaging_tevent_context(conn
->msg_ctx
),
491 deferred_message_dispatch
,
494 DEBUG(0, ("event_add_timed failed\n"));
495 TALLOC_FREE(msg_state
);
503 if ((reqid
!= 0) && (hdr
->reqid
!= reqid
)) {
504 /* we got the wrong reply */
505 DEBUG(0,("Discarding mismatched ctdb reqid %u should have "
506 "been %u\n", hdr
->reqid
, reqid
));
511 *result
= talloc_move(mem_ctx
, &hdr
);
516 static int ctdbd_connection_destructor(struct ctdbd_connection
*c
)
522 * Get us a ctdbd connection
525 static NTSTATUS
ctdbd_init_connection(TALLOC_CTX
*mem_ctx
,
526 struct ctdbd_connection
**pconn
)
528 struct ctdbd_connection
*conn
;
532 if (!(conn
= talloc_zero(mem_ctx
, struct ctdbd_connection
))) {
533 DEBUG(0, ("talloc failed\n"));
534 return NT_STATUS_NO_MEMORY
;
537 ret
= ctdbd_connect(&conn
->fd
);
539 status
= map_nt_error_from_unix(errno
);
540 DEBUG(10, ("ctdbd_connect failed: %s\n", strerror(errno
)));
543 talloc_set_destructor(conn
, ctdbd_connection_destructor
);
545 status
= get_cluster_vnn(conn
, &conn
->our_vnn
);
547 if (!NT_STATUS_IS_OK(status
)) {
548 DEBUG(10, ("get_cluster_vnn failed: %s\n", nt_errstr(status
)));
552 if (!ctdbd_working(conn
, conn
->our_vnn
)) {
553 DEBUG(2, ("Node is not working, can not connect\n"));
554 status
= NT_STATUS_INTERNAL_DB_ERROR
;
558 generate_random_buffer((unsigned char *)&conn
->rand_srvid
,
559 sizeof(conn
->rand_srvid
));
561 status
= register_with_ctdbd(conn
, conn
->rand_srvid
);
563 if (!NT_STATUS_IS_OK(status
)) {
564 DEBUG(5, ("Could not register random srvid: %s\n",
578 * Get us a ctdbd connection and register us as a process
581 NTSTATUS
ctdbd_messaging_connection(TALLOC_CTX
*mem_ctx
,
582 struct ctdbd_connection
**pconn
)
584 struct ctdbd_connection
*conn
;
587 status
= ctdbd_init_connection(mem_ctx
, &conn
);
589 if (!NT_STATUS_IS_OK(status
)) {
593 status
= register_with_ctdbd(conn
, (uint64_t)getpid());
594 if (!NT_STATUS_IS_OK(status
)) {
598 status
= register_with_ctdbd(conn
, MSG_SRVID_SAMBA
);
599 if (!NT_STATUS_IS_OK(status
)) {
603 status
= register_with_ctdbd(conn
, CTDB_SRVID_SAMBA_NOTIFY
);
604 if (!NT_STATUS_IS_OK(status
)) {
616 struct messaging_context
*ctdb_conn_msg_ctx(struct ctdbd_connection
*conn
)
618 return conn
->msg_ctx
;
621 int ctdbd_conn_get_fd(struct ctdbd_connection
*conn
)
627 * Packet handler to receive and handle a ctdb message
629 static NTSTATUS
ctdb_handle_message(struct messaging_context
*msg_ctx
,
630 struct ctdbd_connection
*conn
,
631 struct ctdb_req_header
*hdr
)
633 struct ctdb_req_message
*msg
;
634 struct messaging_rec
*msg_rec
;
636 if (hdr
->operation
!= CTDB_REQ_MESSAGE
) {
637 DEBUG(0, ("Received async msg of type %u, discarding\n",
639 return NT_STATUS_INVALID_PARAMETER
;
642 msg
= (struct ctdb_req_message
*)hdr
;
644 if ((conn
->release_ip_handler
!= NULL
)
645 && (msg
->srvid
== CTDB_SRVID_RELEASE_IP
)) {
648 /* must be dispatched immediately */
649 DEBUG(10, ("received CTDB_SRVID_RELEASE_IP\n"));
650 ret
= conn
->release_ip_handler((const char *)msg
->data
,
651 conn
->release_ip_priv
);
654 * We need to release the ip.
656 * We make sure we don't trigger this again.
658 conn
->release_ip_handler
= NULL
;
659 conn
->release_ip_priv
= NULL
;
664 SMB_ASSERT(conn
->msg_ctx
!= NULL
);
666 if ((msg
->srvid
== CTDB_SRVID_RECONFIGURE
)
667 || (msg
->srvid
== CTDB_SRVID_SAMBA_NOTIFY
)){
668 DEBUG(0,("Got cluster reconfigure message\n"));
670 * when the cluster is reconfigured or someone of the
671 * family has passed away (SAMBA_NOTIFY), we need to
672 * clean the brl database
674 messaging_send(conn
->msg_ctx
,
675 messaging_server_id(conn
->msg_ctx
),
676 MSG_SMB_BRL_VALIDATE
, &data_blob_null
);
681 if (!ctdb_is_our_srvid(conn
, msg
->srvid
)) {
682 DEBUG(0,("Got unexpected message with srvid=%llu\n",
683 (unsigned long long)msg
->srvid
));
687 msg_rec
= ctdb_pull_messaging_rec(talloc_tos(), msg
->hdr
.length
, msg
);
688 if (msg_rec
== NULL
) {
689 DEBUG(10, ("ctdb_pull_messaging_rec failed\n"));
690 return NT_STATUS_NO_MEMORY
;
692 messaging_dispatch_rec(conn
->msg_ctx
, msg_rec
);
697 * The ctdbd socket is readable asynchronuously
700 static void ctdbd_socket_handler(struct tevent_context
*event_ctx
,
701 struct tevent_fd
*event
,
705 struct ctdbd_connection
*conn
= talloc_get_type_abort(
706 private_data
, struct ctdbd_connection
);
707 struct ctdb_req_header
*hdr
= NULL
;
710 status
= ctdb_read_packet(conn
->fd
, talloc_tos(), &hdr
);
711 if (!NT_STATUS_IS_OK(status
)) {
712 DEBUG(0, ("ctdb_read_packet failed: %s\n", nt_errstr(status
)));
713 cluster_fatal("ctdbd died\n");
716 status
= ctdb_handle_message(conn
->msg_ctx
, conn
, hdr
);
717 if (!NT_STATUS_IS_OK(status
)) {
718 DEBUG(10, ("could not handle incoming message: %s\n",
724 * Prepare a ctdbd connection to receive messages
727 NTSTATUS
ctdbd_register_msg_ctx(struct ctdbd_connection
*conn
,
728 struct messaging_context
*msg_ctx
)
730 SMB_ASSERT(conn
->msg_ctx
== NULL
);
731 SMB_ASSERT(conn
->fde
== NULL
);
733 if (!(conn
->fde
= tevent_add_fd(messaging_tevent_context(msg_ctx
),
737 ctdbd_socket_handler
,
739 DEBUG(0, ("event_add_fd failed\n"));
740 return NT_STATUS_NO_MEMORY
;
743 conn
->msg_ctx
= msg_ctx
;
749 * Send a messaging message across a ctdbd
752 NTSTATUS
ctdbd_messaging_send(struct ctdbd_connection
*conn
,
753 uint32_t dst_vnn
, uint64_t dst_srvid
,
754 struct messaging_rec
*msg
)
758 enum ndr_err_code ndr_err
;
760 ndr_err
= ndr_push_struct_blob(
761 &blob
, talloc_tos(), msg
,
762 (ndr_push_flags_fn_t
)ndr_push_messaging_rec
);
764 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
765 DEBUG(0, ("ndr_push_struct_blob failed: %s\n",
766 ndr_errstr(ndr_err
)));
767 return ndr_map_error2ntstatus(ndr_err
);
770 status
= ctdbd_messaging_send_blob(conn
, dst_vnn
, dst_srvid
,
771 blob
.data
, blob
.length
);
772 TALLOC_FREE(blob
.data
);
776 NTSTATUS
ctdbd_messaging_send_blob(struct ctdbd_connection
*conn
,
777 uint32_t dst_vnn
, uint64_t dst_srvid
,
778 const uint8_t *buf
, size_t buflen
)
780 struct ctdb_req_message r
;
784 r
.hdr
.length
= offsetof(struct ctdb_req_message
, data
) + buflen
;
785 r
.hdr
.ctdb_magic
= CTDB_MAGIC
;
786 r
.hdr
.ctdb_version
= CTDB_PROTOCOL
;
787 r
.hdr
.generation
= 1;
788 r
.hdr
.operation
= CTDB_REQ_MESSAGE
;
789 r
.hdr
.destnode
= dst_vnn
;
790 r
.hdr
.srcnode
= conn
->our_vnn
;
795 DEBUG(10, ("ctdbd_messaging_send: Sending ctdb packet\n"));
796 ctdb_packet_dump(&r
.hdr
);
798 iov
[0].iov_base
= &r
;
799 iov
[0].iov_len
= offsetof(struct ctdb_req_message
, data
);
800 iov
[1].iov_base
= discard_const_p(uint8_t, buf
);
801 iov
[1].iov_len
= buflen
;
803 nwritten
= write_data_iov(conn
->fd
, iov
, ARRAY_SIZE(iov
));
804 if (nwritten
== -1) {
805 DEBUG(3, ("write_data_iov failed: %s\n", strerror(errno
)));
806 cluster_fatal("cluster dispatch daemon msg write error\n");
813 * send/recv a generic ctdb control message
815 static NTSTATUS
ctdbd_control(struct ctdbd_connection
*conn
,
816 uint32_t vnn
, uint32_t opcode
,
817 uint64_t srvid
, uint32_t flags
,
819 TALLOC_CTX
*mem_ctx
, TDB_DATA
*outdata
,
822 struct ctdb_req_control req
;
823 struct ctdb_req_header
*hdr
;
824 struct ctdb_reply_control
*reply
= NULL
;
825 struct ctdbd_connection
*new_conn
= NULL
;
831 status
= ctdbd_init_connection(NULL
, &new_conn
);
833 if (!NT_STATUS_IS_OK(status
)) {
834 DEBUG(10, ("Could not init temp connection: %s\n",
843 req
.hdr
.length
= offsetof(struct ctdb_req_control
, data
) + data
.dsize
;
844 req
.hdr
.ctdb_magic
= CTDB_MAGIC
;
845 req
.hdr
.ctdb_version
= CTDB_PROTOCOL
;
846 req
.hdr
.operation
= CTDB_REQ_CONTROL
;
847 req
.hdr
.reqid
= ctdbd_next_reqid(conn
);
848 req
.hdr
.destnode
= vnn
;
851 req
.datalen
= data
.dsize
;
854 DEBUG(10, ("ctdbd_control: Sending ctdb packet\n"));
855 ctdb_packet_dump(&req
.hdr
);
857 iov
[0].iov_base
= &req
;
858 iov
[0].iov_len
= offsetof(struct ctdb_req_control
, data
);
859 iov
[1].iov_base
= data
.dptr
;
860 iov
[1].iov_len
= data
.dsize
;
862 nwritten
= write_data_iov(conn
->fd
, iov
, ARRAY_SIZE(iov
));
863 if (nwritten
== -1) {
864 DEBUG(3, ("write_data_iov failed: %s\n", strerror(errno
)));
865 cluster_fatal("cluster dispatch daemon msg 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
, &hdr
);
878 if (!NT_STATUS_IS_OK(status
)) {
879 DEBUG(10, ("ctdb_read_req failed: %s\n", nt_errstr(status
)));
883 if (hdr
->operation
!= CTDB_REPLY_CONTROL
) {
884 DEBUG(0, ("received invalid reply\n"));
887 reply
= (struct ctdb_reply_control
*)hdr
;
890 if (!(outdata
->dptr
= (uint8
*)talloc_memdup(
891 mem_ctx
, reply
->data
, reply
->datalen
))) {
893 return NT_STATUS_NO_MEMORY
;
895 outdata
->dsize
= reply
->datalen
;
898 (*cstatus
) = reply
->status
;
901 status
= NT_STATUS_OK
;
904 TALLOC_FREE(new_conn
);
910 * see if a remote process exists
912 bool ctdbd_process_exists(struct ctdbd_connection
*conn
, uint32_t vnn
, pid_t pid
)
920 if (!ctdb_processes_exist(conn
, &id
, 1, &result
)) {
921 DEBUG(10, ("ctdb_processes_exist failed\n"));
927 bool ctdb_processes_exist(struct ctdbd_connection
*conn
,
928 const struct server_id
*pids
, int num_pids
,
931 TALLOC_CTX
*frame
= talloc_stackframe();
937 reqids
= talloc_array(talloc_tos(), uint32_t, num_pids
);
938 if (reqids
== NULL
) {
942 for (i
=0; i
<num_pids
; i
++) {
943 struct ctdb_req_control req
;
949 reqids
[i
] = ctdbd_next_reqid(conn
);
954 * pids[i].pid is uint64_t, scale down to pid_t which
955 * is the wire protocol towards ctdb.
959 DEBUG(10, ("Requesting PID %d/%d, reqid=%d\n",
960 (int)pids
[i
].vnn
, (int)pid
,
963 req
.hdr
.length
= offsetof(struct ctdb_req_control
, data
);
964 req
.hdr
.length
+= sizeof(pid
);
965 req
.hdr
.ctdb_magic
= CTDB_MAGIC
;
966 req
.hdr
.ctdb_version
= CTDB_PROTOCOL
;
967 req
.hdr
.operation
= CTDB_REQ_CONTROL
;
968 req
.hdr
.reqid
= reqids
[i
];
969 req
.hdr
.destnode
= pids
[i
].vnn
;
970 req
.opcode
= CTDB_CONTROL_PROCESS_EXISTS
;
972 req
.datalen
= sizeof(pid
);
975 DEBUG(10, ("ctdbd_control: Sending ctdb packet\n"));
976 ctdb_packet_dump(&req
.hdr
);
978 iov
[0].iov_base
= &req
;
979 iov
[0].iov_len
= offsetof(struct ctdb_req_control
, data
);
980 iov
[1].iov_base
= &pid
;
981 iov
[1].iov_len
= sizeof(pid
);
983 nwritten
= write_data_iov(conn
->fd
, iov
, ARRAY_SIZE(iov
));
984 if (nwritten
== -1) {
985 status
= map_nt_error_from_unix(errno
);
986 DEBUG(10, ("write_data_iov failed: %s\n",
994 while (num_received
< num_pids
) {
995 struct ctdb_req_header
*hdr
;
996 struct ctdb_reply_control
*reply
;
999 status
= ctdb_read_req(conn
, 0, talloc_tos(), &hdr
);
1000 if (!NT_STATUS_IS_OK(status
)) {
1001 DEBUG(10, ("ctdb_read_req failed: %s\n",
1002 nt_errstr(status
)));
1006 if (hdr
->operation
!= CTDB_REPLY_CONTROL
) {
1007 DEBUG(10, ("Received invalid reply\n"));
1010 reply
= (struct ctdb_reply_control
*)hdr
;
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
) {
1062 DEBUG(1, ("talloc_array failed\n"));
1066 for (i
=0; i
<num_pids
; i
++) {
1068 uint32_t vnn
= pids
[i
].vnn
;
1070 for (j
=0; j
<num_vnns
; j
++) {
1071 if (vnn
== vnns
[j
].vnn
) {
1079 * Already in the array
1081 vnns
[j
].num_srvids
+= 1;
1084 vnns
= talloc_realloc(mem_ctx
, vnns
, struct ctdb_vnn_list
,
1087 DEBUG(1, ("talloc_realloc failed\n"));
1090 vnns
[num_vnns
].vnn
= vnn
;
1091 vnns
[num_vnns
].num_srvids
= 1;
1092 vnns
[num_vnns
].num_filled
= 0;
1095 for (i
=0; i
<num_vnns
; i
++) {
1096 struct ctdb_vnn_list
*vnn
= &vnns
[i
];
1098 vnn
->srvids
= talloc_array(vnns
, uint64_t, vnn
->num_srvids
);
1099 if (vnn
->srvids
== NULL
) {
1100 DEBUG(1, ("talloc_array failed\n"));
1103 vnn
->pid_indexes
= talloc_array(vnns
, unsigned,
1105 if (vnn
->pid_indexes
== NULL
) {
1106 DEBUG(1, ("talloc_array failed\n"));
1110 for (i
=0; i
<num_pids
; i
++) {
1111 struct ctdb_vnn_list
*vnn
= &vnns
[vnn_indexes
[i
]];
1112 vnn
->srvids
[vnn
->num_filled
] = pids
[i
].unique_id
;
1113 vnn
->pid_indexes
[vnn
->num_filled
] = i
;
1114 vnn
->num_filled
+= 1;
1117 TALLOC_FREE(vnn_indexes
);
1119 *pnum_vnns
= num_vnns
;
1123 TALLOC_FREE(vnn_indexes
);
1127 bool ctdb_serverids_exist_supported(struct ctdbd_connection
*conn
)
1132 bool ctdb_serverids_exist(struct ctdbd_connection
*conn
,
1133 const struct server_id
*pids
, unsigned num_pids
,
1136 unsigned i
, num_received
;
1138 struct ctdb_vnn_list
*vnns
= NULL
;
1141 if (!ctdb_collect_vnns(talloc_tos(), pids
, num_pids
,
1142 &vnns
, &num_vnns
)) {
1143 DEBUG(1, ("ctdb_collect_vnns failed\n"));
1147 for (i
=0; i
<num_vnns
; i
++) {
1148 struct ctdb_vnn_list
*vnn
= &vnns
[i
];
1149 struct ctdb_req_control req
;
1150 struct iovec iov
[2];
1153 vnn
->reqid
= ctdbd_next_reqid(conn
);
1157 DEBUG(10, ("Requesting VNN %d, reqid=%d, num_srvids=%u\n",
1158 (int)vnn
->vnn
, (int)vnn
->reqid
, vnn
->num_srvids
));
1160 req
.hdr
.length
= offsetof(struct ctdb_req_control
, data
);
1161 req
.hdr
.ctdb_magic
= CTDB_MAGIC
;
1162 req
.hdr
.ctdb_version
= CTDB_PROTOCOL
;
1163 req
.hdr
.operation
= CTDB_REQ_CONTROL
;
1164 req
.hdr
.reqid
= vnn
->reqid
;
1165 req
.hdr
.destnode
= vnn
->vnn
;
1166 req
.opcode
= CTDB_CONTROL_CHECK_SRVIDS
;
1168 req
.datalen
= sizeof(uint64_t) * vnn
->num_srvids
;
1169 req
.hdr
.length
+= req
.datalen
;
1172 DEBUG(10, ("ctdbd_control: Sending ctdb packet\n"));
1173 ctdb_packet_dump(&req
.hdr
);
1175 iov
[0].iov_base
= &req
;
1176 iov
[0].iov_len
= offsetof(struct ctdb_req_control
, data
);
1177 iov
[1].iov_base
= vnn
->srvids
;
1178 iov
[1].iov_len
= req
.datalen
;
1180 nwritten
= write_data_iov(conn
->fd
, iov
, ARRAY_SIZE(iov
));
1181 if (nwritten
== -1) {
1182 status
= map_nt_error_from_unix(errno
);
1183 DEBUG(10, ("write_data_iov failed: %s\n",
1191 while (num_received
< num_vnns
) {
1192 struct ctdb_req_header
*hdr
;
1193 struct ctdb_reply_control
*reply
;
1194 struct ctdb_vnn_list
*vnn
;
1196 uint8_t *reply_data
;
1198 status
= ctdb_read_req(conn
, 0, talloc_tos(), &hdr
);
1199 if (!NT_STATUS_IS_OK(status
)) {
1200 DEBUG(1, ("ctdb_read_req failed: %s\n",
1201 nt_errstr(status
)));
1205 if (hdr
->operation
!= CTDB_REPLY_CONTROL
) {
1206 DEBUG(1, ("Received invalid reply %u\n",
1207 (unsigned)hdr
->operation
));
1210 reply
= (struct ctdb_reply_control
*)hdr
;
1212 reqid
= reply
->hdr
.reqid
;
1214 DEBUG(10, ("Received reqid %d\n", (int)reqid
));
1216 for (i
=0; i
<num_vnns
; i
++) {
1217 if (reqid
== vnns
[i
].reqid
) {
1221 if (i
== num_vnns
) {
1222 DEBUG(1, ("Received unknown reqid number %u\n",
1227 DEBUG(10, ("Found index %u\n", i
));
1231 DEBUG(10, ("Received vnn %u, vnn->num_srvids %u, datalen %u\n",
1232 (unsigned)vnn
->vnn
, vnn
->num_srvids
,
1233 (unsigned)reply
->datalen
));
1235 if (reply
->datalen
>= ((vnn
->num_srvids
+7)/8)) {
1239 reply_data
= reply
->data
;
1242 * Got an error reply
1244 DEBUG(5, ("Received short reply len %d, status %u, "
1246 (unsigned)reply
->datalen
,
1247 (unsigned)reply
->status
,
1248 (unsigned)reply
->errorlen
));
1249 dump_data(5, reply
->data
, reply
->errorlen
);
1252 * This will trigger everything set to false
1257 for (i
=0; i
<vnn
->num_srvids
; i
++) {
1258 int idx
= vnn
->pid_indexes
[i
];
1260 if (pids
[i
].unique_id
==
1261 SERVERID_UNIQUE_ID_NOT_TO_VERIFY
) {
1262 results
[idx
] = true;
1266 (reply_data
!= NULL
) &&
1267 ((reply_data
[i
/8] & (1<<(i
%8))) != 0);
1277 cluster_fatal("serverids_exist failed");
1284 char *ctdbd_dbpath(struct ctdbd_connection
*conn
,
1285 TALLOC_CTX
*mem_ctx
, uint32_t db_id
)
1289 TDB_DATA rdata
= {0};
1290 int32_t cstatus
= 0;
1292 data
.dptr
= (uint8_t*)&db_id
;
1293 data
.dsize
= sizeof(db_id
);
1295 status
= ctdbd_control(conn
, CTDB_CURRENT_NODE
,
1296 CTDB_CONTROL_GETDBPATH
, 0, 0, data
,
1297 mem_ctx
, &rdata
, &cstatus
);
1298 if (!NT_STATUS_IS_OK(status
) || cstatus
!= 0) {
1299 DEBUG(0,(__location__
" ctdb_control for getdbpath failed\n"));
1303 return (char *)rdata
.dptr
;
1307 * attach to a ctdb database
1309 NTSTATUS
ctdbd_db_attach(struct ctdbd_connection
*conn
,
1310 const char *name
, uint32_t *db_id
, int tdb_flags
)
1315 bool persistent
= (tdb_flags
& TDB_CLEAR_IF_FIRST
) == 0;
1317 data
= string_term_tdb_data(name
);
1319 status
= ctdbd_control(conn
, CTDB_CURRENT_NODE
,
1321 ? CTDB_CONTROL_DB_ATTACH_PERSISTENT
1322 : CTDB_CONTROL_DB_ATTACH
,
1323 tdb_flags
, 0, data
, NULL
, &data
, &cstatus
);
1324 if (!NT_STATUS_IS_OK(status
)) {
1325 DEBUG(0, (__location__
" ctdb_control for db_attach "
1326 "failed: %s\n", nt_errstr(status
)));
1330 if (cstatus
!= 0 || data
.dsize
!= sizeof(uint32_t)) {
1331 DEBUG(0,(__location__
" ctdb_control for db_attach failed\n"));
1332 return NT_STATUS_INTERNAL_ERROR
;
1335 *db_id
= *(uint32_t *)data
.dptr
;
1336 talloc_free(data
.dptr
);
1338 if (!(tdb_flags
& TDB_SEQNUM
)) {
1339 return NT_STATUS_OK
;
1342 data
.dptr
= (uint8_t *)db_id
;
1343 data
.dsize
= sizeof(*db_id
);
1345 status
= ctdbd_control(conn
, CTDB_CURRENT_NODE
,
1346 CTDB_CONTROL_ENABLE_SEQNUM
, 0, 0, data
,
1347 NULL
, NULL
, &cstatus
);
1348 if (!NT_STATUS_IS_OK(status
) || cstatus
!= 0) {
1349 DEBUG(0,(__location__
" ctdb_control for enable seqnum "
1351 return NT_STATUS_IS_OK(status
) ? NT_STATUS_INTERNAL_ERROR
:
1355 return NT_STATUS_OK
;
1359 * force the migration of a record to this node
1361 NTSTATUS
ctdbd_migrate(struct ctdbd_connection
*conn
, uint32_t db_id
,
1364 struct ctdb_req_call req
;
1365 struct ctdb_req_header
*hdr
;
1366 struct iovec iov
[2];
1372 req
.hdr
.length
= offsetof(struct ctdb_req_call
, data
) + key
.dsize
;
1373 req
.hdr
.ctdb_magic
= CTDB_MAGIC
;
1374 req
.hdr
.ctdb_version
= CTDB_PROTOCOL
;
1375 req
.hdr
.operation
= CTDB_REQ_CALL
;
1376 req
.hdr
.reqid
= ctdbd_next_reqid(conn
);
1377 req
.flags
= CTDB_IMMEDIATE_MIGRATION
;
1378 req
.callid
= CTDB_NULL_FUNC
;
1380 req
.keylen
= key
.dsize
;
1382 DEBUG(10, ("ctdbd_migrate: Sending ctdb packet\n"));
1383 ctdb_packet_dump(&req
.hdr
);
1385 iov
[0].iov_base
= &req
;
1386 iov
[0].iov_len
= offsetof(struct ctdb_req_call
, data
);
1387 iov
[1].iov_base
= key
.dptr
;
1388 iov
[1].iov_len
= key
.dsize
;
1390 nwritten
= write_data_iov(conn
->fd
, iov
, ARRAY_SIZE(iov
));
1391 if (nwritten
== -1) {
1392 DEBUG(3, ("write_data_iov failed: %s\n", strerror(errno
)));
1393 cluster_fatal("cluster dispatch daemon msg write error\n");
1396 status
= ctdb_read_req(conn
, req
.hdr
.reqid
, NULL
, &hdr
);
1398 if (!NT_STATUS_IS_OK(status
)) {
1399 DEBUG(0, ("ctdb_read_req failed: %s\n", nt_errstr(status
)));
1403 if (hdr
->operation
!= CTDB_REPLY_CALL
) {
1404 DEBUG(0, ("received invalid reply\n"));
1405 status
= NT_STATUS_INTERNAL_ERROR
;
1409 status
= NT_STATUS_OK
;
1417 * Fetch a record and parse it
1419 NTSTATUS
ctdbd_parse(struct ctdbd_connection
*conn
, uint32_t db_id
,
1420 TDB_DATA key
, bool local_copy
,
1421 void (*parser
)(TDB_DATA key
, TDB_DATA data
,
1422 void *private_data
),
1425 struct ctdb_req_call req
;
1426 struct ctdb_req_header
*hdr
= NULL
;
1427 struct ctdb_reply_call
*reply
;
1428 struct iovec iov
[2];
1433 flags
= local_copy
? CTDB_WANT_READONLY
: 0;
1437 req
.hdr
.length
= offsetof(struct ctdb_req_call
, data
) + key
.dsize
;
1438 req
.hdr
.ctdb_magic
= CTDB_MAGIC
;
1439 req
.hdr
.ctdb_version
= CTDB_PROTOCOL
;
1440 req
.hdr
.operation
= CTDB_REQ_CALL
;
1441 req
.hdr
.reqid
= ctdbd_next_reqid(conn
);
1443 req
.callid
= CTDB_FETCH_FUNC
;
1445 req
.keylen
= key
.dsize
;
1447 iov
[0].iov_base
= &req
;
1448 iov
[0].iov_len
= offsetof(struct ctdb_req_call
, data
);
1449 iov
[1].iov_base
= key
.dptr
;
1450 iov
[1].iov_len
= key
.dsize
;
1452 nwritten
= write_data_iov(conn
->fd
, iov
, ARRAY_SIZE(iov
));
1453 if (nwritten
== -1) {
1454 DEBUG(3, ("write_data_iov failed: %s\n", strerror(errno
)));
1455 cluster_fatal("cluster dispatch daemon msg write error\n");
1458 status
= ctdb_read_req(conn
, req
.hdr
.reqid
, NULL
, &hdr
);
1460 if (!NT_STATUS_IS_OK(status
)) {
1461 DEBUG(0, ("ctdb_read_req failed: %s\n", nt_errstr(status
)));
1465 if (hdr
->operation
!= CTDB_REPLY_CALL
) {
1466 DEBUG(0, ("received invalid reply\n"));
1467 status
= NT_STATUS_INTERNAL_ERROR
;
1470 reply
= (struct ctdb_reply_call
*)hdr
;
1472 if (reply
->datalen
== 0) {
1474 * Treat an empty record as non-existing
1476 status
= NT_STATUS_NOT_FOUND
;
1480 parser(key
, make_tdb_data(&reply
->data
[0], reply
->datalen
),
1483 status
= NT_STATUS_OK
;
1490 Traverse a ctdb database. This uses a kind-of hackish way to open a second
1491 connection to ctdbd to avoid the hairy recursive and async problems with
1495 NTSTATUS
ctdbd_traverse(uint32_t db_id
,
1496 void (*fn
)(TDB_DATA key
, TDB_DATA data
,
1497 void *private_data
),
1500 struct ctdbd_connection
*conn
;
1504 struct ctdb_traverse_start t
;
1508 status
= ctdbd_init_connection(NULL
, &conn
);
1510 if (!NT_STATUS_IS_OK(status
)) {
1511 DEBUG(0, ("ctdbd_init_connection failed: %s\n",
1512 nt_errstr(status
)));
1517 t
.srvid
= conn
->rand_srvid
;
1518 t
.reqid
= ctdbd_next_reqid(conn
);
1520 data
.dptr
= (uint8_t *)&t
;
1521 data
.dsize
= sizeof(t
);
1523 status
= ctdbd_control(conn
, CTDB_CURRENT_NODE
,
1524 CTDB_CONTROL_TRAVERSE_START
, conn
->rand_srvid
, 0,
1525 data
, NULL
, NULL
, &cstatus
);
1527 if (!NT_STATUS_IS_OK(status
) || (cstatus
!= 0)) {
1529 DEBUG(0,("ctdbd_control failed: %s, %d\n", nt_errstr(status
),
1532 if (NT_STATUS_IS_OK(status
)) {
1534 * We need a mapping here
1536 status
= NT_STATUS_UNSUCCESSFUL
;
1543 struct ctdb_req_header
*hdr
= NULL
;
1544 struct ctdb_req_message
*m
;
1545 struct ctdb_rec_data
*d
;
1547 status
= ctdb_read_packet(conn
->fd
, conn
, &hdr
);
1548 if (!NT_STATUS_IS_OK(status
)) {
1549 DEBUG(0, ("ctdb_read_packet failed: %s\n",
1550 nt_errstr(status
)));
1551 cluster_fatal("ctdbd died\n");
1554 if (hdr
->operation
!= CTDB_REQ_MESSAGE
) {
1555 DEBUG(0, ("Got operation %u, expected a message\n",
1556 (unsigned)hdr
->operation
));
1558 return NT_STATUS_UNEXPECTED_IO_ERROR
;
1561 m
= (struct ctdb_req_message
*)hdr
;
1562 d
= (struct ctdb_rec_data
*)&m
->data
[0];
1563 if (m
->datalen
< sizeof(uint32_t) || m
->datalen
!= d
->length
) {
1564 DEBUG(0, ("Got invalid traverse data of length %d\n",
1567 return NT_STATUS_UNEXPECTED_IO_ERROR
;
1570 key
.dsize
= d
->keylen
;
1571 key
.dptr
= &d
->data
[0];
1572 data
.dsize
= d
->datalen
;
1573 data
.dptr
= &d
->data
[d
->keylen
];
1575 if (key
.dsize
== 0 && data
.dsize
== 0) {
1576 /* end of traverse */
1578 return NT_STATUS_OK
;
1581 if (data
.dsize
< sizeof(struct ctdb_ltdb_header
)) {
1582 DEBUG(0, ("Got invalid ltdb header length %d\n",
1585 return NT_STATUS_UNEXPECTED_IO_ERROR
;
1587 data
.dsize
-= sizeof(struct ctdb_ltdb_header
);
1588 data
.dptr
+= sizeof(struct ctdb_ltdb_header
);
1591 fn(key
, data
, private_data
);
1594 return NT_STATUS_OK
;
1598 This is used to canonicalize a ctdb_sock_addr structure.
1600 static void smbd_ctdb_canonicalize_ip(const struct sockaddr_storage
*in
,
1601 struct sockaddr_storage
*out
)
1603 memcpy(out
, in
, sizeof (*out
));
1606 if (in
->ss_family
== AF_INET6
) {
1607 const char prefix
[12] = { 0,0,0,0,0,0,0,0,0,0,0xff,0xff };
1608 const struct sockaddr_in6
*in6
=
1609 (const struct sockaddr_in6
*)in
;
1610 struct sockaddr_in
*out4
= (struct sockaddr_in
*)out
;
1611 if (memcmp(&in6
->sin6_addr
, prefix
, 12) == 0) {
1612 memset(out
, 0, sizeof(*out
));
1613 #ifdef HAVE_SOCK_SIN_LEN
1614 out4
->sin_len
= sizeof(*out
);
1616 out4
->sin_family
= AF_INET
;
1617 out4
->sin_port
= in6
->sin6_port
;
1618 memcpy(&out4
->sin_addr
, &in6
->sin6_addr
.s6_addr
[12], 4);
1625 * Register us as a server for a particular tcp connection
1628 NTSTATUS
ctdbd_register_ips(struct ctdbd_connection
*conn
,
1629 const struct sockaddr_storage
*_server
,
1630 const struct sockaddr_storage
*_client
,
1631 bool (*release_ip_handler
)(const char *ip_addr
,
1632 void *private_data
),
1636 * we still use ctdb_control_tcp for ipv4
1637 * because we want to work against older ctdb
1638 * versions at runtime
1640 struct ctdb_control_tcp p4
;
1641 struct ctdb_control_tcp_addr p
;
1644 struct sockaddr_storage client
;
1645 struct sockaddr_storage server
;
1648 * Only one connection so far
1650 SMB_ASSERT(conn
->release_ip_handler
== NULL
);
1652 smbd_ctdb_canonicalize_ip(_client
, &client
);
1653 smbd_ctdb_canonicalize_ip(_server
, &server
);
1655 switch (client
.ss_family
) {
1657 memcpy(&p4
.dest
, &server
, sizeof(p4
.dest
));
1658 memcpy(&p4
.src
, &client
, sizeof(p4
.src
));
1659 data
.dptr
= (uint8_t *)&p4
;
1660 data
.dsize
= sizeof(p4
);
1663 memcpy(&p
.dest
.ip6
, &server
, sizeof(p
.dest
.ip6
));
1664 memcpy(&p
.src
.ip6
, &client
, sizeof(p
.src
.ip6
));
1665 data
.dptr
= (uint8_t *)&p
;
1666 data
.dsize
= sizeof(p
);
1669 return NT_STATUS_INTERNAL_ERROR
;
1672 conn
->release_ip_handler
= release_ip_handler
;
1673 conn
->release_ip_priv
= private_data
;
1676 * We want to be told about IP releases
1679 status
= register_with_ctdbd(conn
, CTDB_SRVID_RELEASE_IP
);
1680 if (!NT_STATUS_IS_OK(status
)) {
1685 * inform ctdb of our tcp connection, so if IP takeover happens ctdb
1686 * can send an extra ack to trigger a reset for our client, so it
1687 * immediately reconnects
1689 return ctdbd_control(conn
, CTDB_CURRENT_NODE
,
1690 CTDB_CONTROL_TCP_CLIENT
, 0,
1691 CTDB_CTRL_FLAG_NOREPLY
, data
, NULL
, NULL
, NULL
);
1695 * We want to handle reconfigure events
1697 NTSTATUS
ctdbd_register_reconfigure(struct ctdbd_connection
*conn
)
1699 return register_with_ctdbd(conn
, CTDB_SRVID_RECONFIGURE
);
1703 call a control on the local node
1705 NTSTATUS
ctdbd_control_local(struct ctdbd_connection
*conn
, uint32_t opcode
,
1706 uint64_t srvid
, uint32_t flags
, TDB_DATA data
,
1707 TALLOC_CTX
*mem_ctx
, TDB_DATA
*outdata
,
1710 return ctdbd_control(conn
, CTDB_CURRENT_NODE
, opcode
, srvid
, flags
, data
, mem_ctx
, outdata
, cstatus
);
1713 NTSTATUS
ctdb_watch_us(struct ctdbd_connection
*conn
)
1715 struct ctdb_client_notify_register reg_data
;
1720 reg_data
.srvid
= CTDB_SRVID_SAMBA_NOTIFY
;
1722 reg_data
.notify_data
[0] = 0;
1724 struct_len
= offsetof(struct ctdb_client_notify_register
,
1725 notify_data
) + reg_data
.len
;
1727 status
= ctdbd_control_local(
1728 conn
, CTDB_CONTROL_REGISTER_NOTIFY
, conn
->rand_srvid
, 0,
1729 make_tdb_data((uint8_t *)®_data
, struct_len
),
1730 NULL
, NULL
, &cstatus
);
1731 if (!NT_STATUS_IS_OK(status
)) {
1732 DEBUG(1, ("ctdbd_control_local failed: %s\n",
1733 nt_errstr(status
)));
1738 NTSTATUS
ctdb_unwatch(struct ctdbd_connection
*conn
)
1740 struct ctdb_client_notify_deregister dereg_data
;
1744 dereg_data
.srvid
= CTDB_SRVID_SAMBA_NOTIFY
;
1746 status
= ctdbd_control_local(
1747 conn
, CTDB_CONTROL_DEREGISTER_NOTIFY
, conn
->rand_srvid
, 0,
1748 make_tdb_data((uint8_t *)&dereg_data
, sizeof(dereg_data
)),
1749 NULL
, NULL
, &cstatus
);
1750 if (!NT_STATUS_IS_OK(status
)) {
1751 DEBUG(1, ("ctdbd_control_local failed: %s\n",
1752 nt_errstr(status
)));
1757 NTSTATUS
ctdbd_probe(void)
1760 * Do a very early check if ctdbd is around to avoid an abort and core
1763 struct ctdbd_connection
*conn
= NULL
;
1766 status
= ctdbd_messaging_connection(talloc_tos(), &conn
);
1769 * We only care if we can connect.