2 Unix SMB/CIFS implementation.
3 Samba internal messaging functions
4 Copyright (C) 2007 by Volker Lendecke
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * It is not possible to include ctdb.h and tdb_compat.h (included via
26 * some other include above) without warnings. This fixes those
34 #ifdef typesafe_cb_preargs
35 #undef typesafe_cb_preargs
38 #ifdef typesafe_cb_postargs
39 #undef typesafe_cb_postargs
43 #include "ctdb_private.h"
44 #include "ctdbd_conn.h"
47 struct messaging_ctdbd_context
{
48 struct ctdbd_connection
*conn
;
52 * This is a Samba3 hack/optimization. Routines like process_exists need to
53 * talk to ctdbd, and they don't get handed a messaging context.
55 static struct ctdbd_connection
*global_ctdbd_connection
;
56 static int global_ctdb_connection_pid
;
58 struct ctdbd_connection
*messaging_ctdbd_connection(void)
60 if (!lp_clustering()) {
64 if (global_ctdb_connection_pid
== 0 &&
65 global_ctdbd_connection
== NULL
) {
66 struct tevent_context
*ev
;
67 struct messaging_context
*msg
;
69 ev
= samba_tevent_context_init(NULL
);
71 DEBUG(0,("samba_tevent_context_init failed\n"));
74 msg
= messaging_init(NULL
, ev
);
76 DEBUG(0,("messaging_init failed\n"));
81 if (global_ctdb_connection_pid
!= getpid()) {
82 DEBUG(0,("messaging_ctdbd_connection():"
83 "valid for pid[%d] but it's [%d]\n",
84 global_ctdb_connection_pid
, getpid()));
85 smb_panic("messaging_ctdbd_connection() invalid process\n");
88 return global_ctdbd_connection
;
91 static int messaging_ctdb_send(struct server_id src
,
92 struct server_id pid
, int msg_type
,
93 const struct iovec
*iov
, int iovlen
,
94 struct messaging_backend
*backend
)
96 struct messaging_ctdbd_context
*ctx
= talloc_get_type_abort(
97 backend
->private_data
, struct messaging_ctdbd_context
);
99 struct messaging_rec msg
;
103 buf
= iov_buf(talloc_tos(), iov
, iovlen
);
109 msg
.msg_version
= MESSAGE_VERSION
;
110 msg
.msg_type
= msg_type
;
113 msg
.buf
= data_blob_const(buf
, talloc_get_size(buf
));
115 status
= ctdbd_messaging_send(ctx
->conn
, pid
.vnn
, pid
.pid
, &msg
);
119 if (NT_STATUS_IS_OK(status
)) {
122 return map_errno_from_nt_status(status
);
125 static int messaging_ctdbd_destructor(struct messaging_ctdbd_context
*ctx
)
128 * The global connection just went away
130 global_ctdb_connection_pid
= 0;
131 global_ctdbd_connection
= NULL
;
135 NTSTATUS
messaging_ctdbd_init(struct messaging_context
*msg_ctx
,
137 struct messaging_backend
**presult
)
139 struct messaging_backend
*result
;
140 struct messaging_ctdbd_context
*ctx
;
143 if (!(result
= talloc(mem_ctx
, struct messaging_backend
))) {
144 DEBUG(0, ("talloc failed\n"));
145 return NT_STATUS_NO_MEMORY
;
148 if (!(ctx
= talloc(result
, struct messaging_ctdbd_context
))) {
149 DEBUG(0, ("talloc failed\n"));
151 return NT_STATUS_NO_MEMORY
;
154 status
= ctdbd_messaging_connection(ctx
, &ctx
->conn
);
156 if (!NT_STATUS_IS_OK(status
)) {
157 DEBUG(10, ("ctdbd_messaging_connection failed: %s\n",
163 status
= ctdbd_register_msg_ctx(ctx
->conn
, msg_ctx
);
165 if (!NT_STATUS_IS_OK(status
)) {
166 DEBUG(10, ("ctdbd_register_msg_ctx failed: %s\n",
172 global_ctdb_connection_pid
= getpid();
173 global_ctdbd_connection
= ctx
->conn
;
174 talloc_set_destructor(ctx
, messaging_ctdbd_destructor
);
176 set_my_vnn(ctdbd_vnn(ctx
->conn
));
178 result
->send_fn
= messaging_ctdb_send
;
179 result
->private_data
= (void *)ctx
;