summaryrefslogtreecommitdiffstats
path: root/source4/cluster
diff options
context:
space:
mode:
Diffstat (limited to 'source4/cluster')
-rw-r--r--source4/cluster/cluster.c86
-rw-r--r--source4/cluster/cluster.h51
-rw-r--r--source4/cluster/cluster_private.h43
-rw-r--r--source4/cluster/local.c121
-rw-r--r--source4/cluster/wscript_build8
5 files changed, 309 insertions, 0 deletions
diff --git a/source4/cluster/cluster.c b/source4/cluster/cluster.c
new file mode 100644
index 0000000..11c4194
--- /dev/null
+++ b/source4/cluster/cluster.c
@@ -0,0 +1,86 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ core clustering code
+
+ Copyright (C) Andrew Tridgell 2006
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "cluster/cluster.h"
+#include "cluster/cluster_private.h"
+#include "librpc/gen_ndr/misc.h"
+#include "librpc/gen_ndr/server_id.h"
+
+static struct cluster_ops *ops;
+
+/* set cluster operations */
+void cluster_set_ops(struct cluster_ops *new_ops)
+{
+ ops = new_ops;
+}
+
+/*
+ an ugly way of getting at the backend handle (eg. ctdb context) via the cluster API
+*/
+void *cluster_backend_handle(void)
+{
+ return ops->backend_handle(ops);
+}
+
+/* by default use the local ops */
+static void cluster_init(void)
+{
+ if (ops == NULL) cluster_local_init();
+}
+
+/*
+ create a server_id for the local node
+*/
+struct server_id cluster_id(uint64_t pid, uint32_t task_id)
+{
+ cluster_init();
+ return ops->cluster_id(ops, pid, task_id);
+}
+
+/*
+ open a temporary tdb in a cluster friendly manner
+*/
+struct db_context *cluster_db_tmp_open(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, const char *dbbase, int flags)
+{
+ cluster_init();
+ return ops->cluster_db_tmp_open(ops, mem_ctx, lp_ctx, dbbase, flags);
+}
+
+
+/*
+ register a callback function for a messaging endpoint
+*/
+NTSTATUS cluster_message_init(struct imessaging_context *msg, struct server_id server,
+ cluster_message_fn_t handler)
+{
+ cluster_init();
+ return ops->message_init(ops, msg, server, handler);
+}
+
+/*
+ send a message to another node in the cluster
+*/
+NTSTATUS cluster_message_send(struct server_id server, DATA_BLOB *data)
+{
+ cluster_init();
+ return ops->message_send(ops, server, data);
+}
diff --git a/source4/cluster/cluster.h b/source4/cluster/cluster.h
new file mode 100644
index 0000000..2bbbea2
--- /dev/null
+++ b/source4/cluster/cluster.h
@@ -0,0 +1,51 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ structures for clustering
+
+ Copyright (C) Andrew Tridgell 2006
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __CLUSTER_H__
+#define __CLUSTER_H__
+
+#include "librpc/gen_ndr/server_id.h"
+
+/*
+ test for same cluster id
+*/
+#define cluster_id_equal(id_1, id_2) ((id_1)->pid == (id_2)->pid \
+ && (id_1)->task_id == (id_2)->task_id \
+ && (id_1)->vnn == (id_2)->vnn)
+
+/*
+ test for same cluster node
+*/
+#define cluster_node_equal(id1, id2) ((id1)->vnn == (id2)->vnn)
+
+struct imessaging_context;
+typedef void (*cluster_message_fn_t)(struct imessaging_context *, DATA_BLOB);
+
+/* prototypes */
+struct server_id cluster_id(uint64_t id, uint32_t task_id);
+struct db_context *cluster_db_tmp_open(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, const char *dbbase, int flags);
+void *cluster_backend_handle(void);
+
+NTSTATUS cluster_message_init(struct imessaging_context *msg, struct server_id server,
+ cluster_message_fn_t handler);
+NTSTATUS cluster_message_send(struct server_id server, DATA_BLOB *data);
+
+#endif
diff --git a/source4/cluster/cluster_private.h b/source4/cluster/cluster_private.h
new file mode 100644
index 0000000..2b79922
--- /dev/null
+++ b/source4/cluster/cluster_private.h
@@ -0,0 +1,43 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ private structures for clustering
+
+ Copyright (C) Andrew Tridgell 2006
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _CLUSTER_PRIVATE_H_
+#define _CLUSTER_PRIVATE_H_
+
+struct cluster_ops {
+ struct server_id (*cluster_id)(struct cluster_ops *ops, uint64_t id, uint32_t id2);
+ struct db_context *(*cluster_db_tmp_open)(struct cluster_ops *,
+ TALLOC_CTX *,
+ struct loadparm_context *,
+ const char *, int);
+ void *(*backend_handle)(struct cluster_ops *);
+ NTSTATUS (*message_init)(struct cluster_ops *ops,
+ struct imessaging_context *msg, struct server_id server,
+ cluster_message_fn_t handler);
+ NTSTATUS (*message_send)(struct cluster_ops *ops,
+ struct server_id server, DATA_BLOB *data);
+ void *private_data; /* backend state */
+};
+
+void cluster_set_ops(struct cluster_ops *new_ops);
+void cluster_local_init(void);
+
+#endif
diff --git a/source4/cluster/local.c b/source4/cluster/local.c
new file mode 100644
index 0000000..ea36663
--- /dev/null
+++ b/source4/cluster/local.c
@@ -0,0 +1,121 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ local (dummy) clustering operations
+
+ Copyright (C) Andrew Tridgell 2006
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "cluster/cluster.h"
+#include "cluster/cluster_private.h"
+#include "dbwrap/dbwrap.h"
+#include "system/filesys.h"
+#include "param/param.h"
+#include "librpc/gen_ndr/server_id.h"
+
+/*
+ server a server_id for the local node
+*/
+static struct server_id local_id(struct cluster_ops *ops, uint64_t pid, uint32_t task_id)
+{
+ struct server_id server_id;
+ ZERO_STRUCT(server_id);
+ server_id.pid = pid;
+ server_id.task_id = task_id;
+ server_id.vnn = NONCLUSTER_VNN;
+ /* This is because we are not in the s3 serverid database */
+ server_id.unique_id = SERVERID_UNIQUE_ID_NOT_TO_VERIFY;
+ return server_id;
+}
+
+
+/*
+ open a tmp tdb for the local node. By using smbd_tmp_path() we don't need
+ TDB_CLEAR_IF_FIRST as the tmp path is wiped at startup
+*/
+static struct db_context *local_db_tmp_open(struct cluster_ops *ops,
+ TALLOC_CTX *mem_ctx,
+ struct loadparm_context *lp_ctx,
+ const char *dbbase, int flags)
+{
+ TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
+ char *path, *dbname;
+ struct db_context *db;
+ int hash_size, tdb_flags;
+
+ dbname = talloc_asprintf(mem_ctx, "%s.tdb", dbbase);
+
+ path = smbd_tmp_path(tmp_ctx, lp_ctx, dbname);
+
+ hash_size = lpcfg_tdb_hash_size(lp_ctx, path);
+ tdb_flags = lpcfg_tdb_flags(lp_ctx, flags);
+
+ db = dbwrap_local_open(
+ mem_ctx,
+ path,
+ hash_size,
+ tdb_flags,
+ O_RDWR|O_CREAT,
+ 0600,
+ DBWRAP_LOCK_ORDER_NONE,
+ DBWRAP_FLAG_NONE);
+ talloc_free(tmp_ctx);
+ return db;
+}
+
+/*
+ dummy backend handle function
+*/
+static void *local_backend_handle(struct cluster_ops *ops)
+{
+ return NULL;
+}
+
+/*
+ dummy message init function - not needed as all messages are local
+*/
+static NTSTATUS local_message_init(struct cluster_ops *ops,
+ struct imessaging_context *msg,
+ struct server_id server,
+ cluster_message_fn_t handler)
+{
+ return NT_STATUS_OK;
+}
+
+/*
+ dummy message send
+*/
+static NTSTATUS local_message_send(struct cluster_ops *ops,
+ struct server_id server, DATA_BLOB *data)
+{
+ return NT_STATUS_INVALID_DEVICE_REQUEST;
+}
+
+static struct cluster_ops cluster_local_ops = {
+ .cluster_id = local_id,
+ .cluster_db_tmp_open = local_db_tmp_open,
+ .backend_handle = local_backend_handle,
+ .message_init = local_message_init,
+ .message_send = local_message_send,
+ .private_data = NULL
+};
+
+void cluster_local_init(void)
+{
+ cluster_set_ops(&cluster_local_ops);
+}
+
diff --git a/source4/cluster/wscript_build b/source4/cluster/wscript_build
new file mode 100644
index 0000000..b8a91cc
--- /dev/null
+++ b/source4/cluster/wscript_build
@@ -0,0 +1,8 @@
+#!/usr/bin/env python
+
+bld.SAMBA_LIBRARY('cluster',
+ source='cluster.c local.c',
+ deps='dbwrap samba-hostconfig talloc',
+ private_library=True
+ )
+