[SCM] SAMBA-CTDB repository - branch v3-4-ctdb updated - 3.4.2-ctdb-14-19-g19f7461

Michael Adam obnox at samba.org
Fri Dec 18 17:41:49 MST 2009


The branch, v3-4-ctdb has been updated
       via  19f746178841c579a4db31733524f68924859262 (commit)
       via  08ef827ee483c408027ccb723c54b49504def982 (commit)
       via  6a9a4aca7762472d2cd1e930c1289314cb72a6ce (commit)
       via  494281756af631a1ea89dcb56547dc43fdf3c240 (commit)
       via  ce5ee6aa7d59bcef185be83d5f3b6cfb8d40e26d (commit)
       via  a26696918d4fcb46e19a74b57084605351e6b69b (commit)
       via  66c2268a58898033c891d14375b3f1ed25fb8b30 (commit)
       via  e76f6cd4efd8e607b0e9dae17fc0a011dbfb9601 (commit)
       via  45cc71fefa75a47c56e3714267da771b678d431d (commit)
       via  4452ca040e2d15ab5ac28787a4cffc0a650e69d2 (commit)
       via  8ba098c97b03fb45896b80ac68f2b22e3e098356 (commit)
       via  c2731e36006f54a9e000b84464ba2bf08ebbe6d7 (commit)
       via  201e6021d215d3025c0e8c26dbdb2126876ff4af (commit)
       via  6cf20428fb2d47f5c16d9e9e1f93d256442d2f65 (commit)
       via  a0f87e3cc5aaf5d4d93cd511e67fe0afee571c6c (commit)
       via  867e7ca81a00b158097d72f8d22f1b63cd872618 (commit)
       via  3247e9f96f6632180311d51f85833cd655cfff61 (commit)
       via  24ed4e16292c8cef79dc58083027ac41329d950c (commit)
       via  0793018d0d0cc7463315528e707032f88848dd7b (commit)
      from  c859996a0c424c5a7073b71dee61a43cf9ae09ef (commit)

http://gitweb.samba.org/?p=obnox/samba-ctdb.git;a=shortlog;h=v3-4-ctdb


- Log -----------------------------------------------------------------
commit 19f746178841c579a4db31733524f68924859262
Author: Michael Adam <obnox at samba.org>
Date:   Thu Dec 17 13:42:34 2009 +0100

    v3-4-ctdb: bump the ctdb vendor patch level to 16
    
    Michael

commit 08ef827ee483c408027ccb723c54b49504def982
Author: Michael Adam <obnox at samba.org>
Date:   Sat Dec 12 00:38:14 2009 +0100

    s3:dbwrap_ctdb: fix two "may be used uninitialized" warnings
    
    Michael

commit 6a9a4aca7762472d2cd1e930c1289314cb72a6ce
Author: Michael Adam <obnox at samba.org>
Date:   Sat Dec 12 00:30:37 2009 +0100

    s3:dbwrap_ctdb: fix db_ctdb_fetch_db_seqnum_from_db() when NT_STATUS_NOT_FOUND.
    
    Don't treat this as an error but return seqnum 0 instead.
    
    Michael

commit 494281756af631a1ea89dcb56547dc43fdf3c240
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Dec 11 16:51:40 2009 +0100

    s3:dbwrap: If "-n" is given to dbwrap_torture, open db with CLEAR_IF_FIRST

commit ce5ee6aa7d59bcef185be83d5f3b6cfb8d40e26d
Author: Michael Adam <obnox at samba.org>
Date:   Fri Dec 11 16:45:38 2009 +0100

    s3:build: remove checks for deprecated ctdb controls.
    
    Michael

commit a26696918d4fcb46e19a74b57084605351e6b69b
Author: Michael Adam <obnox at samba.org>
Date:   Fri Dec 11 14:07:28 2009 +0100

    s3:dbwrap_ctdb: maintain a database sequence number that bumps in transactions
    
    For persistent databases, 64bit integer is kept in a special record
    __db_sequence_number__. This record is incremented with each completed
    transaction.
    
    The retry mechanism for failing TRANS3_COMMIT controls inside the
    db_ctdb_transaction_commit() function now relies one a modified
    behaviour of ctdbd's treatment of persistent databases in recoveries.
    Recently, a special treatment for persistent databases had been
    introduced in ctdb (1.0.108) to work around the problems with the
    orinal design of persistent transactions.
    Now with the rewrite we need to revert to the old behaviour that
    ctdb always takes the newest copies of all records.
    
    This change also paves the way for a next step, which will make
    recovery use the db seqnum to tell which node has the newest copy
    of a persistent db and use that node's copy. This will greatly
    reduce the amount of data transferred with each recovery.
    
    Michael

commit 66c2268a58898033c891d14375b3f1ed25fb8b30
Author: Michael Adam <obnox at samba.org>
Date:   Fri Dec 11 12:30:57 2009 +0100

    s3:dbwrap_ctdb: change db_ctdb_transaction_store() to return NTSTATUS.
    
    The return values calculated by the callers were wrong anyways since
    the new marshalling code does not set the local tdbs tdb error code.
    
    Michael

commit e76f6cd4efd8e607b0e9dae17fc0a011dbfb9601
Author: Michael Adam <obnox at samba.org>
Date:   Fri Dec 11 10:35:50 2009 +0100

    s3:dbwrap_ctdb: update (C)
    
    Michael

commit 45cc71fefa75a47c56e3714267da771b678d431d
Author: Michael Adam <obnox at samba.org>
Date:   Fri Dec 4 11:49:21 2009 +0100

    build: Add a configure check for CTDB_CONTROL_TRANS3_COMMIT.
    
    This is the new implementation of ctdb transactions using the
    global lock feature. It is needed by the current dbwrap_ctdb code.
    
    Michael

commit 4452ca040e2d15ab5ac28787a4cffc0a650e69d2
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Dec 11 15:37:52 2009 +0100

    s3:torture: add a test LOCAL-DBTRANS to torture dbwrap with transactions.

commit 8ba098c97b03fb45896b80ac68f2b22e3e098356
Author: Michael Adam <obnox at samba.org>
Date:   Thu Dec 3 17:29:54 2009 +0100

    s3:dbwrap_ctdb: start rewrite of transactions using the global lock (g_lock)
    
    This simplifies the transaction code a lot:
    
    * transaction_start essentially consists of acquiring a global lock.
    
    * No write operations at all are performed on the local database
      until the transaction is committed: Every store operation is just
      going into the marshall buffer.
    
    * The commit operation calls a new simplified TRANS3_COMMIT control
      in ctdb which rolls out thae changes to all nodes including the
      node that is performing the transaction.
    
    Michael

commit c2731e36006f54a9e000b84464ba2bf08ebbe6d7
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Dec 7 00:36:51 2009 +0100

    s3: setup debug for smbtorture

commit 201e6021d215d3025c0e8c26dbdb2126876ff4af
Author: Volker Lendecke <vl at samba.org>
Date:   Fri Dec 4 13:22:30 2009 +0100

    s3: Add ctdb_conn_msg_ctx()

commit 6cf20428fb2d47f5c16d9e9e1f93d256442d2f65
Author: Volker Lendecke <vl at samba.org>
Date:   Sun Oct 25 16:12:12 2009 +0100

    s3: Implement global locks in a g_lock tdb
    
    This is the basis to implement global locks in ctdb without depending on a
    shared file system. The initial goal is to make ctdb persistent transactions
    deterministic without too many timeouts.

commit a0f87e3cc5aaf5d4d93cd511e67fe0afee571c6c
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Dec 3 18:43:49 2009 +0100

    s3: Add tdb_data_equal

commit 867e7ca81a00b158097d72f8d22f1b63cd872618
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Dec 16 04:19:15 2009 +0100

    v3-4-ctdb: Bump the vendor patch level to 15

commit 3247e9f96f6632180311d51f85833cd655cfff61
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Dec 16 17:22:48 2009 +0100

    s3: Correctly handle timeouts for the ping-dc operation
    
    When a DC is too slow responding to the logonCtrl operation, we have to
    invalidate the connection. Right now we can not recover from that condition
    very well.

commit 24ed4e16292c8cef79dc58083027ac41329d950c
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Dec 15 20:17:01 2009 +0100

    s3: Add "net registry getvaluesraw"

commit 0793018d0d0cc7463315528e707032f88848dd7b
Author: Christian Ambach <christian.ambach at de.ibm.com>
Date:   Wed Dec 2 20:06:37 2009 +0100

    streamline some log levels for invalid servicenames
    
    I don't think we need to log the fact that a user gave a wrong sharename in Explorer with the highest log level.
    The level of this was not very consistent:
    service.c:		DEBUG(3,("find_service() failed to find service %s\n", service));
    service.c:		DEBUG(0,("%s (%s) couldn't find service %s\n",
    smb2_tcon.c:		DEBUG(1,("smbd_smb2_tree_connect: couldn't find service %s\n",
    
    This changes the last two to 3 as the first one.
    
    Signed-off-by: Christian Ambach <christian.ambach at de.ibm.com>

-----------------------------------------------------------------------

Summary of changes:
 lib/util/util_tdb.c                    |    8 +
 lib/util/util_tdb.h                    |    1 +
 source3/Makefile.in                    |    2 +
 source3/VERSION                        |    2 +-
 source3/configure.in                   |   23 +-
 source3/include/ctdbd_conn.h           |    3 +
 source3/include/g_lock.h               |   55 +++
 source3/lib/ctdbd_conn.c               |   79 ++++-
 source3/lib/dbwrap_ctdb.c              |  585 +++++++++++++++-----------------
 source3/lib/g_lock.c                   |  594 ++++++++++++++++++++++++++++++++
 source3/librpc/gen_ndr/messaging.h     |    6 +-
 source3/librpc/gen_ndr/ndr_messaging.c |    1 +
 source3/librpc/idl/messaging.idl       |    3 +-
 source3/smbd/service.c                 |    2 +-
 source3/torture/torture.c              |  133 +++++++
 source3/utils/dbwrap_torture.c         |    4 +
 source3/utils/net.c                    |    7 +
 source3/utils/net_g_lock.c             |  213 ++++++++++++
 source3/utils/net_proto.h              |    3 +
 source3/utils/net_registry.c           |   51 +++
 source3/winbindd/winbindd_misc.c       |    6 +
 21 files changed, 1435 insertions(+), 346 deletions(-)
 create mode 100644 source3/include/g_lock.h
 create mode 100644 source3/lib/g_lock.c
 create mode 100644 source3/utils/net_g_lock.c


Changeset truncated at 500 lines:

diff --git a/lib/util/util_tdb.c b/lib/util/util_tdb.c
index e107cbd..b4f9f07 100644
--- a/lib/util/util_tdb.c
+++ b/lib/util/util_tdb.c
@@ -38,6 +38,14 @@ TDB_DATA make_tdb_data(const uint8_t *dptr, size_t dsize)
 	return ret;
 }
 
+bool tdb_data_equal(TDB_DATA t1, TDB_DATA t2)
+{
+	if (t1.dsize != t2.dsize) {
+		return false;
+	}
+	return (memcmp(t1.dptr, t2.dptr, t1.dsize) == 0);
+}
+
 TDB_DATA string_tdb_data(const char *string)
 {
 	return make_tdb_data((const uint8_t *)string, string ? strlen(string) : 0 );
diff --git a/lib/util/util_tdb.h b/lib/util/util_tdb.h
index da6378e..79c4671 100644
--- a/lib/util/util_tdb.h
+++ b/lib/util/util_tdb.h
@@ -6,6 +6,7 @@
  Make a TDB_DATA and keep the const warning in one place
 ****************************************************************/
 TDB_DATA make_tdb_data(const uint8_t *dptr, size_t dsize);
+bool tdb_data_equal(TDB_DATA t1, TDB_DATA t2);
 TDB_DATA string_tdb_data(const char *string);
 TDB_DATA string_term_tdb_data(const char *string);
 
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 50aedb0..5795e45 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -254,6 +254,7 @@ EXTRA_ALL_TARGETS = @EXTRA_ALL_TARGETS@
 TDB_LIB_OBJ = lib/util_tdb.o ../lib/util/util_tdb.o \
 	  lib/dbwrap.o lib/dbwrap_tdb.o \
 	  lib/dbwrap_ctdb.o \
+	  lib/g_lock.o \
 	  lib/dbwrap_rbt.o
 
 TDB_VALIDATE_OBJ = lib/tdb_validate.o
@@ -934,6 +935,7 @@ NET_OBJ1 = utils/net.o utils/net_ads.o utils/net_help.o \
 	   utils/net_conf.o utils/net_join.o utils/net_user.o \
 	   utils/net_group.o utils/net_file.o utils/net_registry.o \
 	   auth/token_util.o utils/net_dom.o utils/net_share.o \
+	   utils/net_g_lock.o \
 	   utils/net_eventlog.o
 
 # these are not processed by make proto
diff --git a/source3/VERSION b/source3/VERSION
index 37b31cb..4b54a33 100644
--- a/source3/VERSION
+++ b/source3/VERSION
@@ -85,7 +85,7 @@ SAMBA_VERSION_IS_GIT_SNAPSHOT=no
 #                                                      #
 ########################################################
 SAMBA_VERSION_VENDOR_SUFFIX="ctdb"
-SAMBA_VERSION_VENDOR_PATCH=14
+SAMBA_VERSION_VENDOR_PATCH=16
 
 ########################################################
 # This can be set by vendors if they want..            #
diff --git a/source3/configure.in b/source3/configure.in
index 5e4bb86..9ddf1be 100644
--- a/source3/configure.in
+++ b/source3/configure.in
@@ -5038,7 +5038,7 @@ AC_CHECK_HEADERS(ctdb.h ctdb_private.h,,,[
 #include <ctdb.h>
 ])
 
-AC_HAVE_DECL(CTDB_CONTROL_TRANS2_COMMIT_RETRY,[
+AC_HAVE_DECL(CTDB_CONTROL_TRANS3_COMMIT,[
 #include "confdefs.h"
 #define NO_CONFIG_H
 #include "replace.h"
@@ -5049,27 +5049,10 @@ AC_HAVE_DECL(CTDB_CONTROL_TRANS2_COMMIT_RETRY,[
 #include <ctdb.h>
 #include <ctdb_private.h>
 ])
-if test x"$ac_cv_have_CTDB_CONTROL_TRANS2_COMMIT_RETRY_decl" = x"yes"; then
+if test x"$ac_cv_have_CTDB_CONTROL_TRANS3_COMMIT_decl" = x"yes"; then
 	ctdb_broken=no
 else
-	ctdb_broken="missing transaction support"
-fi
-
-AC_HAVE_DECL(CTDB_CONTROL_TRANS2_ACTIVE,[
-#include "confdefs.h"
-#define NO_CONFIG_H
-#include "replace.h"
-#include "system/wait.h"
-#include "system/network.h"
-#include <talloc.h>
-#include <tdb.h>
-#include <ctdb.h>
-#include <ctdb_private.h>
-])
-if test x"$ac_cv_have_CTDB_CONTROL_TRANS2_ACTIVE_decl" = x"yes"; then
-	ctdb_broken=no
-else
-	ctdb_broken="transaction support too old"
+	ctdb_broken="ctdb transaction support missing or too old"
 fi
 
 # in ctdb 1.0.57 ctdb_control_tcp was temparary renamed to ctdb_tcp_client
diff --git a/source3/include/ctdbd_conn.h b/source3/include/ctdbd_conn.h
index d721235..71516c7 100644
--- a/source3/include/ctdbd_conn.h
+++ b/source3/include/ctdbd_conn.h
@@ -31,6 +31,7 @@ uint32 ctdbd_vnn(const struct ctdbd_connection *conn);
 
 NTSTATUS ctdbd_register_msg_ctx(struct ctdbd_connection *conn,
 				struct messaging_context *msg_ctx);
+struct messaging_context *ctdb_conn_msg_ctx(struct ctdbd_connection *conn);
 
 NTSTATUS ctdbd_messaging_send(struct ctdbd_connection *conn,
 			      uint32 dst_vnn, uint64 dst_srvid,
@@ -73,5 +74,7 @@ NTSTATUS ctdbd_control_local(struct ctdbd_connection *conn, uint32 opcode,
 			     uint64_t srvid, uint32_t flags, TDB_DATA data, 
 			     TALLOC_CTX *mem_ctx, TDB_DATA *outdata,
 			     int *cstatus);
+NTSTATUS ctdb_watch_us(struct ctdbd_connection *conn);
+NTSTATUS ctdb_unwatch(struct ctdbd_connection *conn);
 
 #endif /* _CTDBD_CONN_H */
diff --git a/source3/include/g_lock.h b/source3/include/g_lock.h
new file mode 100644
index 0000000..c0eed38
--- /dev/null
+++ b/source3/include/g_lock.h
@@ -0,0 +1,55 @@
+/*
+   Unix SMB/CIFS implementation.
+   global locks based on ctdb
+   Copyright (C) 2009 by Volker Lendecke
+
+   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 _G_LOCK_H_
+#define _G_LOCK_H_
+
+#include "dbwrap.h"
+
+struct g_lock_ctx;
+
+enum g_lock_type {
+	G_LOCK_READ = 0,
+	G_LOCK_WRITE = 1,
+};
+
+/*
+ * Or'ed with g_lock_type
+ */
+#define G_LOCK_PENDING (2)
+
+struct g_lock_ctx *g_lock_ctx_init(TALLOC_CTX *mem_ctx,
+				   struct messaging_context *msg);
+
+NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, const char *name,
+		     enum g_lock_type lock_type, struct timeval timeout);
+NTSTATUS g_lock_unlock(struct g_lock_ctx *ctx, const char *name);
+NTSTATUS g_lock_get(struct g_lock_ctx *ctx, const char *name,
+		struct server_id *pid);
+
+int g_lock_locks(struct g_lock_ctx *ctx,
+		 int (*fn)(const char *name, void *private_data),
+		 void *private_data);
+NTSTATUS g_lock_dump(struct g_lock_ctx *ctx, const char *name,
+		     int (*fn)(struct server_id pid,
+			       enum g_lock_type lock_type,
+			       void *private_data),
+		     void *private_data);
+
+#endif
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index 05c41c1..a00c510 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -414,10 +414,18 @@ static NTSTATUS ctdb_read_req(struct ctdbd_connection *conn, uint32 reqid,
 			goto next_pkt;
 		}
 
-		if (msg->srvid == CTDB_SRVID_RECONFIGURE) {
-			DEBUG(0,("Got cluster reconfigure message in ctdb_read_req\n"));
+		if ((msg->srvid == CTDB_SRVID_RECONFIGURE)
+		    || (msg->srvid == CTDB_SRVID_SAMBA_NOTIFY)) {
+
+			DEBUG(1, ("ctdb_read_req: Got %s message\n",
+				  (msg->srvid == CTDB_SRVID_RECONFIGURE)
+				  ? "cluster reconfigure" : "SAMBA_NOTIFY"));
+
 			messaging_send(conn->msg_ctx, procid_self(),
 				       MSG_SMB_BRL_VALIDATE, &data_blob_null);
+			messaging_send(conn->msg_ctx, procid_self(),
+				       MSG_DBWRAP_G_LOCK_RETRY,
+				       &data_blob_null);
 			TALLOC_FREE(hdr);
 			goto next_pkt;
 		}
@@ -552,6 +560,11 @@ NTSTATUS ctdbd_messaging_connection(TALLOC_CTX *mem_ctx,
 		goto fail;
 	}
 
+	status = register_with_ctdbd(conn, CTDB_SRVID_SAMBA_NOTIFY);
+	if (!NT_STATUS_IS_OK(status)) {
+		goto fail;
+	}
+
 	*pconn = conn;
 	return NT_STATUS_OK;
 
@@ -560,6 +573,11 @@ NTSTATUS ctdbd_messaging_connection(TALLOC_CTX *mem_ctx,
 	return status;
 }
 
+struct messaging_context *ctdb_conn_msg_ctx(struct ctdbd_connection *conn)
+{
+	return conn->msg_ctx;
+}
+
 /*
  * Packet handler to receive and handle a ctdb message
  */
@@ -592,11 +610,13 @@ static NTSTATUS ctdb_handle_message(uint8_t *buf, size_t length,
 
 	SMB_ASSERT(conn->msg_ctx != NULL);
 
-	if (msg->srvid == CTDB_SRVID_RECONFIGURE) {
+	if ((msg->srvid == CTDB_SRVID_RECONFIGURE)
+	    || (msg->srvid == CTDB_SRVID_SAMBA_NOTIFY)){
 		DEBUG(0,("Got cluster reconfigure message\n"));
 		/*
-		 * when the cluster is reconfigured, we need to clean the brl
-		 * database
+		 * when the cluster is reconfigured or someone of the
+		 * family has passed away (SAMBA_NOTIFY), we need to
+		 * clean the brl database
 		 */
 		messaging_send(conn->msg_ctx, procid_self(),
 			       MSG_SMB_BRL_VALIDATE, &data_blob_null);
@@ -608,10 +628,13 @@ static NTSTATUS ctdb_handle_message(uint8_t *buf, size_t length,
 		 */
 		message_send_all(conn->msg_ctx, MSG_SMB_UNLOCK, NULL, 0, NULL);
 
+		messaging_send(conn->msg_ctx, procid_self(),
+			       MSG_DBWRAP_G_LOCK_RETRY,
+			       &data_blob_null);
+
 		TALLOC_FREE(buf);
 
 		return NT_STATUS_OK;
-		
 	}
 
 	/* only messages to our pid or the broadcast are valid here */
@@ -1370,6 +1393,50 @@ NTSTATUS ctdbd_control_local(struct ctdbd_connection *conn, uint32 opcode,
 	return ctdbd_control(conn, CTDB_CURRENT_NODE, opcode, srvid, flags, data, mem_ctx, outdata, cstatus);
 }
 
+NTSTATUS ctdb_watch_us(struct ctdbd_connection *conn)
+{
+	struct ctdb_client_notify_register reg_data;
+	size_t struct_len;
+	NTSTATUS status;
+	int cstatus;
+
+	reg_data.srvid = CTDB_SRVID_SAMBA_NOTIFY;
+	reg_data.len = 1;
+	reg_data.notify_data[0] = 0;
+
+	struct_len = offsetof(struct ctdb_client_notify_register,
+			      notify_data) + reg_data.len;
+
+	status = ctdbd_control_local(
+		conn, CTDB_CONTROL_REGISTER_NOTIFY, conn->rand_srvid, 0,
+		make_tdb_data((uint8_t *)&reg_data, struct_len),
+		NULL, NULL, &cstatus);
+	if (!NT_STATUS_IS_OK(status)) {
+		DEBUG(1, ("ctdbd_control_local failed: %s\n",
+			  nt_errstr(status)));
+	}
+	return status;
+}
+
+NTSTATUS ctdb_unwatch(struct ctdbd_connection *conn)
+{
+	struct ctdb_client_notify_deregister dereg_data;
+	NTSTATUS status;
+	int cstatus;
+
+	dereg_data.srvid = CTDB_SRVID_SAMBA_NOTIFY;
+
+	status = ctdbd_control_local(
+		conn, CTDB_CONTROL_DEREGISTER_NOTIFY, conn->rand_srvid, 0,
+		make_tdb_data((uint8_t *)&dereg_data, sizeof(dereg_data)),
+		NULL, NULL, &cstatus);
+	if (!NT_STATUS_IS_OK(status)) {
+		DEBUG(1, ("ctdbd_control_local failed: %s\n",
+			  nt_errstr(status)));
+	}
+	return status;
+}
+
 #else
 
 NTSTATUS ctdbd_init_connection(TALLOC_CTX *mem_ctx,
diff --git a/source3/lib/dbwrap_ctdb.c b/source3/lib/dbwrap_ctdb.c
index 8e188d0..d70637e 100644
--- a/source3/lib/dbwrap_ctdb.c
+++ b/source3/lib/dbwrap_ctdb.c
@@ -1,7 +1,8 @@
 /* 
    Unix SMB/CIFS implementation.
    Database interface wrapper around ctdbd
-   Copyright (C) Volker Lendecke 2007
+   Copyright (C) Volker Lendecke 2007-2009
+   Copyright (C) Michael Adam 2009
 
    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
@@ -22,10 +23,10 @@
 #include "ctdb.h"
 #include "ctdb_private.h"
 #include "ctdbd_conn.h"
+#include "g_lock.h"
 
 struct db_ctdb_transaction_handle {
 	struct db_ctdb_ctx *ctx;
-	bool in_replay;
 	/*
 	 * we store the reads and writes done under a transaction:
 	 * - one list stores both reads and writes (m_all),
@@ -35,6 +36,7 @@ struct db_ctdb_transaction_handle {
 	struct ctdb_marshall_buffer *m_write;
 	uint32_t nesting;
 	bool nested_cancel;
+	char *lock_name;
 };
 
 struct db_ctdb_ctx {
@@ -42,6 +44,7 @@ struct db_ctdb_ctx {
 	struct tdb_wrap *wtdb;
 	uint32 db_id;
 	struct db_ctdb_transaction_handle *transaction;
+	struct g_lock_ctx *lock_ctx;
 };
 
 struct db_ctdb_rec {
@@ -297,145 +300,21 @@ static struct ctdb_rec_data *db_ctdb_marshall_loop_next(struct ctdb_marshall_buf
 	return r;
 }
 
-
-static int32_t db_ctdb_transaction_active(uint32_t db_id)
-{
-	int32_t status;
-	NTSTATUS ret;
-	TDB_DATA indata;
-
-	indata.dptr = (uint8_t *)&db_id;
-	indata.dsize = sizeof(db_id);
-
-	ret = ctdbd_control_local(messaging_ctdbd_connection(),
-				  CTDB_CONTROL_TRANS2_ACTIVE, 0, 0,
-				  indata, NULL, NULL, &status);
-
-	if (!NT_STATUS_IS_OK(ret)) {
-		DEBUG(2, ("ctdb control TRANS2_ACTIVE failed\n"));
-		return -1;
-	}
-
-	return status;
-}
-
-
 /**
  * CTDB transaction destructor
  */
 static int db_ctdb_transaction_destructor(struct db_ctdb_transaction_handle *h)
 {
-	tdb_transaction_cancel(h->ctx->wtdb->tdb);
-	return 0;
-}
-
-/**
- * start a transaction on a ctdb database:
- * - lock the transaction lock key
- * - start the tdb transaction
- */
-static int db_ctdb_transaction_fetch_start(struct db_ctdb_transaction_handle *h)
-{
-	struct db_record *rh;
-	struct db_ctdb_rec *crec;
-	TDB_DATA key;
-	TALLOC_CTX *tmp_ctx;
-	const char *keyname = CTDB_TRANSACTION_LOCK_KEY;
-	int ret;
-	struct db_ctdb_ctx *ctx = h->ctx;
-	TDB_DATA data;
-	pid_t pid;
 	NTSTATUS status;
-	struct ctdb_ltdb_header header;
-	int32_t transaction_status;
-
-	key.dptr = (uint8_t *)discard_const(keyname);
-	key.dsize = strlen(keyname);
-
-again:
-	tmp_ctx = talloc_new(h);
-
-	rh = fetch_locked_internal(ctx, tmp_ctx, key, true);
-	if (rh == NULL) {
-		DEBUG(0,(__location__ " Failed to fetch_lock database\n"));		
-		talloc_free(tmp_ctx);
-		return -1;
-	}
-	crec = talloc_get_type_abort(rh->private_data, struct db_ctdb_rec);
-
-	transaction_status = db_ctdb_transaction_active(ctx->db_id);
-	if (transaction_status == 1) {
-		unsigned long int usec = (1000 + random()) % 100000;
-		DEBUG(3, ("Transaction already active on db_id[0x%08x]."
-			  "Re-trying after %lu microseconds...",
-			  ctx->db_id, usec));
-		talloc_free(tmp_ctx);
-		usleep(usec);
-		goto again;
-	}
 
-	/*
-	 * store the pid in the database:
-	 * it is not enought that the node is dmaster...
-	 */
-	pid = getpid();
-	data.dptr = (unsigned char *)&pid;
-	data.dsize = sizeof(pid_t);
-	crec->header.rsn++;
-	crec->header.dmaster = get_my_vnn();
-	status = db_ctdb_ltdb_store(ctx, key, &(crec->header), data);
+	status = g_lock_unlock(h->ctx->lock_ctx, h->lock_name);
 	if (!NT_STATUS_IS_OK(status)) {
-		DEBUG(0, (__location__ " Failed to store pid in transaction "
-			  "record: %s\n", nt_errstr(status)));
-		talloc_free(tmp_ctx);
+		DEBUG(0, ("g_lock_unlock failed: %s\n", nt_errstr(status)));
 		return -1;
 	}
-
-	talloc_free(rh);
-
-	ret = tdb_transaction_start(ctx->wtdb->tdb);
-	if (ret != 0) {
-		DEBUG(0,(__location__ " Failed to start tdb transaction\n"));
-		talloc_free(tmp_ctx);
-		return -1;
-	}
-
-	status = db_ctdb_ltdb_fetch(ctx, key, &header, tmp_ctx, &data);
-	if (!NT_STATUS_IS_OK(status)) {
-		DEBUG(0, (__location__ " failed to refetch transaction lock "
-			  "record inside transaction: %s - retrying\n",
-			  nt_errstr(status)));
-		tdb_transaction_cancel(ctx->wtdb->tdb);
-		talloc_free(tmp_ctx);
-		goto again;
-	}
-
-	if (header.dmaster != get_my_vnn()) {
-		DEBUG(3, (__location__ " refetch transaction lock record : "
-			  "we are not dmaster any more "
-			  "(dmaster[%u] != my_vnn[%u]) - retrying\n",
-			  header.dmaster, get_my_vnn()));
-		tdb_transaction_cancel(ctx->wtdb->tdb);
-		talloc_free(tmp_ctx);
-		goto again;
-	}
-
-	if ((data.dsize != sizeof(pid_t)) || (*(pid_t *)(data.dptr) != pid)) {
-		DEBUG(3, (__location__ " refetch transaction lock record: "
-			  "another local process has started a transaction "
-			  "(stored pid [%u] != my pid [%u]) - retrying\n",
-			  *(pid_t *)(data.dptr), pid));
-		tdb_transaction_cancel(ctx->wtdb->tdb);
-		talloc_free(tmp_ctx);
-		goto again;
-	}


-- 
SAMBA-CTDB repository


More information about the samba-cvs mailing list