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/>.
24 #ifdef CLUSTER_SUPPORT
27 #include "ctdb_private.h"
28 #include "ctdbd_conn.h"
31 struct messaging_ctdbd_context {
32 struct ctdbd_connection *conn;
36 * This is a Samba3 hack/optimization. Routines like process_exists need to
37 * talk to ctdbd, and they don't get handed a messaging context.
39 static struct ctdbd_connection *global_ctdbd_connection;
40 static int global_ctdb_connection_pid;
42 struct ctdbd_connection *messaging_ctdbd_connection(void)
44 if (global_ctdb_connection_pid == 0 &&
45 global_ctdbd_connection == NULL) {
46 struct event_context *ev;
47 struct messaging_context *msg;
49 ev = event_context_init(NULL);
51 DEBUG(0,("event_context_init failed\n"));
54 msg = messaging_init(NULL, procid_self(), ev);
56 DEBUG(0,("messaging_init failed\n"));
61 if (global_ctdb_connection_pid != getpid()) {
62 DEBUG(0,("messaging_ctdbd_connection():"
63 "valid for pid[%d] but it's [%d]\n",
64 global_ctdb_connection_pid, getpid()));
65 smb_panic("messaging_ctdbd_connection() invalid process\n");
68 return global_ctdbd_connection;
71 static NTSTATUS messaging_ctdb_send(struct messaging_context *msg_ctx,
72 struct server_id pid, int msg_type,
73 const DATA_BLOB *data,
74 struct messaging_backend *backend)
76 struct messaging_ctdbd_context *ctx = talloc_get_type_abort(
77 backend->private_data, struct messaging_ctdbd_context);
79 struct messaging_rec msg;
81 msg.msg_version = MESSAGE_VERSION;
82 msg.msg_type = msg_type;
84 msg.src = msg_ctx->id;
87 return ctdbd_messaging_send(ctx->conn, pid.vnn, pid.pid, &msg);
90 static int messaging_ctdbd_destructor(struct messaging_ctdbd_context *ctx)
93 * The global connection just went away
95 global_ctdb_connection_pid = 0;
96 global_ctdbd_connection = NULL;
100 NTSTATUS messaging_ctdbd_init(struct messaging_context *msg_ctx,
102 struct messaging_backend **presult)
104 struct messaging_backend *result;
105 struct messaging_ctdbd_context *ctx;
108 if (!(result = talloc(mem_ctx, struct messaging_backend))) {
109 DEBUG(0, ("talloc failed\n"));
110 return NT_STATUS_NO_MEMORY;
113 if (!(ctx = talloc(result, struct messaging_ctdbd_context))) {
114 DEBUG(0, ("talloc failed\n"));
116 return NT_STATUS_NO_MEMORY;
119 status = ctdbd_messaging_connection(ctx, &ctx->conn);
121 if (!NT_STATUS_IS_OK(status)) {
122 DEBUG(10, ("ctdbd_messaging_connection failed: %s\n",
128 status = ctdbd_register_msg_ctx(ctx->conn, msg_ctx);
130 if (!NT_STATUS_IS_OK(status)) {
131 DEBUG(10, ("ctdbd_register_msg_ctx failed: %s\n",
137 global_ctdb_connection_pid = getpid();
138 global_ctdbd_connection = ctx->conn;
139 talloc_set_destructor(ctx, messaging_ctdbd_destructor);
141 set_my_vnn(ctdbd_vnn(ctx->conn));
143 result->send_fn = messaging_ctdb_send;
144 result->private_data = (void *)ctx;
152 NTSTATUS messaging_ctdbd_init(struct messaging_context *msg_ctx,
154 struct messaging_backend **presult)
156 return NT_STATUS_NOT_IMPLEMENTED;