svn commit: samba r20919 - in branches/SAMBA_4_0/source/cluster: . ctdb

tridge at samba.org tridge at samba.org
Sat Jan 20 00:48:32 GMT 2007


Author: tridge
Date: 2007-01-20 00:48:31 +0000 (Sat, 20 Jan 2007)
New Revision: 20919

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=20919

Log:

add a function cluster_tdb_tmp_open() which can be used in a cluster
environment for subsystems that have not yet been converted to use
ctdb to get a shared temporary tdb

Modified:
   branches/SAMBA_4_0/source/cluster/cluster.c
   branches/SAMBA_4_0/source/cluster/cluster.h
   branches/SAMBA_4_0/source/cluster/cluster_private.h
   branches/SAMBA_4_0/source/cluster/ctdb/brlock_ctdb.c
   branches/SAMBA_4_0/source/cluster/ctdb/ctdb_cluster.c
   branches/SAMBA_4_0/source/cluster/local.c


Changeset:
Modified: branches/SAMBA_4_0/source/cluster/cluster.c
===================================================================
--- branches/SAMBA_4_0/source/cluster/cluster.c	2007-01-19 23:17:28 UTC (rev 20918)
+++ branches/SAMBA_4_0/source/cluster/cluster.c	2007-01-20 00:48:31 UTC (rev 20919)
@@ -66,3 +66,13 @@
 	cluster_init();
 	return ops->cluster_id_string(ops, mem_ctx, id);
 }
+
+
+/*
+  open a temporary tdb in a cluster friendly manner
+*/
+struct tdb_wrap *cluster_tdb_tmp_open(TALLOC_CTX *mem_ctx, const char *dbname, int flags)
+{
+	cluster_init();
+	return ops->cluster_tdb_tmp_open(ops, mem_ctx, dbname, flags);
+}

Modified: branches/SAMBA_4_0/source/cluster/cluster.h
===================================================================
--- branches/SAMBA_4_0/source/cluster/cluster.h	2007-01-19 23:17:28 UTC (rev 20918)
+++ branches/SAMBA_4_0/source/cluster/cluster.h	2007-01-20 00:48:31 UTC (rev 20919)
@@ -31,6 +31,7 @@
 /* prototypes */
 struct server_id cluster_id(uint32_t id);
 const char *cluster_id_string(TALLOC_CTX *mem_ctx, struct server_id id);
+struct tdb_wrap *cluster_tdb_tmp_open(TALLOC_CTX *mem_ctx, const char *dbname, int flags);
 void *cluster_private(void);
 
 #endif

Modified: branches/SAMBA_4_0/source/cluster/cluster_private.h
===================================================================
--- branches/SAMBA_4_0/source/cluster/cluster_private.h	2007-01-19 23:17:28 UTC (rev 20918)
+++ branches/SAMBA_4_0/source/cluster/cluster_private.h	2007-01-20 00:48:31 UTC (rev 20919)
@@ -27,6 +27,8 @@
 	struct server_id (*cluster_id)(struct cluster_ops *ops, uint32_t id);
 	const char *(*cluster_id_string)(struct cluster_ops *ops, 
 					 TALLOC_CTX *, struct server_id );
+	struct tdb_wrap *(*cluster_tdb_tmp_open)(struct cluster_ops *,
+						 TALLOC_CTX *, const char *, int);
 	void *private; /* backend state */
 };
 

Modified: branches/SAMBA_4_0/source/cluster/ctdb/brlock_ctdb.c
===================================================================
--- branches/SAMBA_4_0/source/cluster/ctdb/brlock_ctdb.c	2007-01-19 23:17:28 UTC (rev 20918)
+++ branches/SAMBA_4_0/source/cluster/ctdb/brlock_ctdb.c	2007-01-20 00:48:31 UTC (rev 20919)
@@ -116,6 +116,9 @@
 		return NULL;
 	}
 
+	DEBUG(0,("file_key\n"));
+	dump_data(0,file_key->data, file_key->length);
+
 	brlh->key = *file_key;
 	brlh->ntvfs = ntvfs;
 	ZERO_STRUCT(brlh->last_lock);

Modified: branches/SAMBA_4_0/source/cluster/ctdb/ctdb_cluster.c
===================================================================
--- branches/SAMBA_4_0/source/cluster/ctdb/ctdb_cluster.c	2007-01-19 23:17:28 UTC (rev 20918)
+++ branches/SAMBA_4_0/source/cluster/ctdb/ctdb_cluster.c	2007-01-20 00:48:31 UTC (rev 20919)
@@ -27,6 +27,7 @@
 #include "cluster/cluster_private.h"
 #include "lib/tdb/include/tdb.h"
 #include "cluster/ctdb/include/ctdb.h"
+#include "db_wrap.h"
 
 struct cluster_state {
 	struct ctdb_context *ctdb;
@@ -55,9 +56,35 @@
 	return talloc_asprintf(mem_ctx, "%u.%u", id.node, id.id);
 }
 
+/*
+  this is an interim method for subsystems that have not yet been
+  converted to use the ctdb api. It opens a shared database in the
+  cluster temporary area, using TDB_CLEAR_IF_FIRST which relies on
+  correct operation of fcntl locks on the shared fileystem.
+*/
+static struct tdb_wrap *ctdb_tdb_tmp_open(struct cluster_ops *ops,
+					  TALLOC_CTX *mem_ctx, const char *dbname, 
+					  int flags)
+{
+	const char *dir = lp_parm_string(-1, "ctdb", "shared data");
+	char *path;
+	struct tdb_wrap *w;
+	if (dir == NULL) {
+		DEBUG(0,("ERROR: You must set 'ctdb:shared data' to a cluster shared path\n"));
+		return NULL;
+	}
+	path = talloc_asprintf(mem_ctx, "%s/%s", dir, dbname);
+	w = tdb_wrap_open(mem_ctx, path, 0,  
+			  flags | TDB_CLEAR_IF_FIRST,
+			  O_RDWR|O_CREAT, 0600);
+	talloc_free(path);
+	return w;
+}
+
 static struct cluster_ops cluster_ctdb_ops = {
-	.cluster_id        = ctdb_id,
-	.cluster_id_string = ctdb_id_string,
+	.cluster_id           = ctdb_id,
+	.cluster_id_string    = ctdb_id_string,
+	.cluster_tdb_tmp_open = ctdb_tdb_tmp_open,
 	.private           = NULL
 };
 

Modified: branches/SAMBA_4_0/source/cluster/local.c
===================================================================
--- branches/SAMBA_4_0/source/cluster/local.c	2007-01-19 23:17:28 UTC (rev 20918)
+++ branches/SAMBA_4_0/source/cluster/local.c	2007-01-20 00:48:31 UTC (rev 20919)
@@ -23,6 +23,9 @@
 #include "includes.h"
 #include "cluster/cluster.h"
 #include "cluster/cluster_private.h"
+#include "lib/tdb/include/tdb.h"
+#include "db_wrap.h"
+#include "system/filesys.h"
 
 /*
   server a server_id for the local node
@@ -45,10 +48,28 @@
 	return talloc_asprintf(mem_ctx, "%u.%u", id.node, id.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 tdb_wrap *local_tdb_tmp_open(struct cluster_ops *ops,
+					   TALLOC_CTX *mem_ctx, const char *dbname, 
+					   int flags)
+{
+	char *path = smbd_tmp_path(mem_ctx, dbname);
+	struct tdb_wrap *w;
+	w = tdb_wrap_open(mem_ctx, path, 0, flags,
+			  O_RDWR|O_CREAT, 0600);
+	talloc_free(path);
+	return w;
+}
+
 static struct cluster_ops cluster_local_ops = {
-	.cluster_id        = local_id,
-	.cluster_id_string = local_id_string,
-	.private           = NULL
+	.cluster_id           = local_id,
+	.cluster_id_string    = local_id_string,
+	.cluster_tdb_tmp_open = local_tdb_tmp_open,
+	.private              = NULL
 };
 
 void cluster_local_init(void)



More information about the samba-cvs mailing list