[SCM] Samba Shared Repository - branch master updated

Amitay Isaacs amitay at samba.org
Fri Dec 19 03:42:03 MST 2014


The branch, master has been updated
       via  a1a90f7 tdb: version 1.3.4
       via  f32747d tdb/toos: allow transactions with TDB_MUTEX_LOCKING
       via  5d5d91f tdb/test: add tdb1-run-mutex-transaction1 test
       via  d0839af tdb: allow transactions on on tdb's with TDB_MUTEX_LOCKING
      from  93b3c15 vfs_fruit: Avoid double ()

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit a1a90f74eb10a10ac9d508028ed998f8c843f88a
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Dec 12 12:28:47 2014 +0100

    tdb: version 1.3.4
    
    Transactions are supported with TDB_MUTEX_LOCKING.
    
    This fixes https://bugzilla.samba.org/show_bug.cgi?id=11004
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>
    
    Autobuild-User(master): Amitay Isaacs <amitay at samba.org>
    Autobuild-Date(master): Fri Dec 19 11:41:26 CET 2014 on sn-devel-104

commit f32747ddd06445b5c51aa3f1b56fead48285a735
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Dec 12 12:53:37 2014 +0100

    tdb/toos: allow transactions with TDB_MUTEX_LOCKING
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=11004
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit 5d5d91fae55a806261375b87bf7109a980471799
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Dec 12 12:24:50 2014 +0100

    tdb/test: add tdb1-run-mutex-transaction1 test
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=11004
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

commit d0839af9d60a6fdf0720cd0b1a859e0e2241903f
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Dec 12 11:22:47 2014 +0100

    tdb: allow transactions on on tdb's with TDB_MUTEX_LOCKING
    
    There's no real reason to disallow transactions as the
    allrecord lock is also available with mutexes enabled.
    
    E.g. ctdbd requires transactions also on non-persistent databases
    opened with TDB_CLEAR_IF_FIRST and TDB_MUTEX_LOCKING.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=11004
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>

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

Summary of changes:
 lib/tdb/ABI/{tdb-1.3.0.sigs => tdb-1.3.4.sigs} |   0
 lib/tdb/common/transaction.c                   |   2 +-
 lib/tdb/test/run-mutex-transaction1.c          | 236 +++++++++++++++++++++++++
 lib/tdb/tools/tdbtorture.c                     |   1 -
 lib/tdb/wscript                                |   3 +-
 5 files changed, 239 insertions(+), 3 deletions(-)
 copy lib/tdb/ABI/{tdb-1.3.0.sigs => tdb-1.3.4.sigs} (100%)
 create mode 100644 lib/tdb/test/run-mutex-transaction1.c


Changeset truncated at 500 lines:

diff --git a/lib/tdb/ABI/tdb-1.3.0.sigs b/lib/tdb/ABI/tdb-1.3.4.sigs
similarity index 100%
copy from lib/tdb/ABI/tdb-1.3.0.sigs
copy to lib/tdb/ABI/tdb-1.3.4.sigs
diff --git a/lib/tdb/common/transaction.c b/lib/tdb/common/transaction.c
index caef0be..0dd057b 100644
--- a/lib/tdb/common/transaction.c
+++ b/lib/tdb/common/transaction.c
@@ -421,7 +421,7 @@ static int _tdb_transaction_start(struct tdb_context *tdb,
 				  enum tdb_lock_flags lockflags)
 {
 	/* some sanity checks */
-	if (tdb->read_only || (tdb->flags & (TDB_INTERNAL|TDB_MUTEX_LOCKING))
+	if (tdb->read_only || (tdb->flags & TDB_INTERNAL)
 	    || tdb->traverse_read) {
 		TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_transaction_start: cannot start a transaction on a read-only or internal db\n"));
 		tdb->ecode = TDB_ERR_EINVAL;
diff --git a/lib/tdb/test/run-mutex-transaction1.c b/lib/tdb/test/run-mutex-transaction1.c
new file mode 100644
index 0000000..7b9f7b1
--- /dev/null
+++ b/lib/tdb/test/run-mutex-transaction1.c
@@ -0,0 +1,236 @@
+#include "../common/tdb_private.h"
+#include "../common/io.c"
+#include "../common/tdb.c"
+#include "../common/lock.c"
+#include "../common/freelist.c"
+#include "../common/traverse.c"
+#include "../common/transaction.c"
+#include "../common/error.c"
+#include "../common/open.c"
+#include "../common/check.c"
+#include "../common/hash.c"
+#include "../common/mutex.c"
+#include "tap-interface.h"
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <stdarg.h>
+
+static TDB_DATA key, data;
+
+static void log_fn(struct tdb_context *tdb, enum tdb_debug_level level,
+		   const char *fmt, ...)
+{
+	va_list ap;
+	va_start(ap, fmt);
+	vfprintf(stderr, fmt, ap);
+	va_end(ap);
+}
+
+static int do_child(int tdb_flags, int to, int from)
+{
+	struct tdb_context *tdb;
+	unsigned int log_count;
+	struct tdb_logging_context log_ctx = { log_fn, &log_count };
+	int ret;
+	char c = 0;
+
+	tdb = tdb_open_ex("mutex-transaction1.tdb", 3, tdb_flags,
+			  O_RDWR|O_CREAT, 0755, &log_ctx, NULL);
+	ok(tdb, "tdb_open_ex should succeed");
+
+	ret = tdb_transaction_start(tdb);
+	ok(ret == 0, "tdb_transaction_start should succeed");
+
+	ret = tdb_store(tdb, key, data, TDB_INSERT);
+	ok(ret == 0, "tdb_store(tdb, key, data, TDB_INSERT) should succeed");
+
+	write(to, &c, sizeof(c));
+	read(from, &c, sizeof(c));
+
+	ret = tdb_transaction_cancel(tdb);
+	ok(ret == 0, "tdb_transaction_cancel should succeed");
+
+	write(to, &c, sizeof(c));
+	read(from, &c, sizeof(c));
+
+	ret = tdb_transaction_start(tdb);
+	ok(ret == 0, "tdb_transaction_start should succeed");
+
+	ret = tdb_store(tdb, key, data, TDB_INSERT);
+	ok(ret == 0, "tdb_store(tdb, key, data, TDB_INSERT) should succeed");
+
+	write(to, &c, sizeof(c));
+	read(from, &c, sizeof(c));
+
+	ret = tdb_transaction_commit(tdb);
+	ok(ret == 0, "tdb_transaction_commit should succeed");
+
+	write(to, &c, sizeof(c));
+	read(from, &c, sizeof(c));
+
+	ret = tdb_transaction_start(tdb);
+	ok(ret == 0, "tdb_transaction_start should succeed");
+
+	ret = tdb_store(tdb, key, key, TDB_REPLACE);
+	ok(ret == 0, "tdb_store(tdb, key, data, TDB_REPLACE) should succeed");
+
+	write(to, &c, sizeof(c));
+	read(from, &c, sizeof(c));
+
+	ret = tdb_transaction_commit(tdb);
+	ok(ret == 0, "tdb_transaction_commit should succeed");
+
+	write(to, &c, sizeof(c));
+	read(from, &c, sizeof(c));
+
+	return 0;
+}
+
+/* The code should barf on TDBs created with rwlocks. */
+int main(int argc, char *argv[])
+{
+	struct tdb_context *tdb;
+	unsigned int log_count;
+	struct tdb_logging_context log_ctx = { log_fn, &log_count };
+	int ret, status;
+	pid_t child, wait_ret;
+	int fromchild[2];
+	int tochild[2];
+	TDB_DATA val;
+	char c;
+	int tdb_flags;
+	bool runtime_support;
+
+	runtime_support = tdb_runtime_check_for_robust_mutexes();
+
+	if (!runtime_support) {
+		skip(1, "No robust mutex support");
+		return exit_status();
+	}
+
+	key.dsize = strlen("hi");
+	key.dptr = discard_const_p(uint8_t, "hi");
+	data.dsize = strlen("world");
+	data.dptr = discard_const_p(uint8_t, "world");
+
+	pipe(fromchild);
+	pipe(tochild);
+
+	tdb_flags = TDB_INCOMPATIBLE_HASH|
+		TDB_MUTEX_LOCKING|
+		TDB_CLEAR_IF_FIRST;
+
+	child = fork();
+	if (child == 0) {
+		close(fromchild[0]);
+		close(tochild[1]);
+		return do_child(tdb_flags, fromchild[1], tochild[0]);
+	}
+	close(fromchild[1]);
+	close(tochild[0]);
+
+	read(fromchild[0], &c, sizeof(c));
+
+	tdb = tdb_open_ex("mutex-transaction1.tdb", 0,
+			  tdb_flags, O_RDWR|O_CREAT, 0755,
+			  &log_ctx, NULL);
+	ok(tdb, "tdb_open_ex should succeed");
+
+	/*
+	 * The child has the transaction running
+	 */
+	ret = tdb_transaction_start_nonblock(tdb);
+	ok(ret == -1, "tdb_transaction_start_nonblock not succeed");
+
+	ret = tdb_chainlock_nonblock(tdb, key);
+	ok(ret == -1, "tdb_chainlock_nonblock should not succeed");
+
+	/*
+	 * We can still read
+	 */
+	ret = tdb_exists(tdb, key);
+	ok(ret == 0, "tdb_exists(tdb, key) should return 0");
+
+	val = tdb_fetch(tdb, key);
+	ok(val.dsize == 0, "tdb_fetch(tdb, key) should return an empty value");
+
+	write(tochild[1], &c, sizeof(c));
+
+	/*
+	 * When the child canceled we can start...
+	 */
+	ret = tdb_transaction_start(tdb);
+	ok(ret == 0, "tdb_transaction_start should succeed");
+
+	read(fromchild[0], &c, sizeof(c));
+	write(tochild[1], &c, sizeof(c));
+
+	ret = tdb_transaction_cancel(tdb);
+	ok(ret == 0, "tdb_transaction_cancel should succeed");
+
+	/*
+	 * When we canceled the child can start and store...
+	 */
+	read(fromchild[0], &c, sizeof(c));
+
+	/*
+	 * We still see the old values before the child commits...
+	 */
+	ret = tdb_exists(tdb, key);
+	ok(ret == 0, "tdb_exists(tdb, key) should return 0");
+
+	val = tdb_fetch(tdb, key);
+	ok(val.dsize == 0, "tdb_fetch(tdb, key) should return an empty value");
+
+	write(tochild[1], &c, sizeof(c));
+	read(fromchild[0], &c, sizeof(c));
+
+	/*
+	 * We see the new values after the commit...
+	 */
+	ret = tdb_exists(tdb, key);
+	ok(ret == 1, "tdb_exists(tdb, key) should return 1");
+
+	val = tdb_fetch(tdb, key);
+	ok(val.dsize != 0, "tdb_fetch(tdb, key) should return a value");
+	ok(val.dsize == data.dsize, "tdb_fetch(tdb, key) should return a value");
+	ok(memcmp(val.dptr, data.dptr, data.dsize) == 0, "tdb_fetch(tdb, key) should return a value");
+
+	write(tochild[1], &c, sizeof(c));
+	read(fromchild[0], &c, sizeof(c));
+
+	/*
+	 * The child started a new transaction and replaces the value,
+	 * but we still see the old values before the child commits...
+	 */
+	ret = tdb_exists(tdb, key);
+	ok(ret == 1, "tdb_exists(tdb, key) should return 1");
+
+	val = tdb_fetch(tdb, key);
+	ok(val.dsize != 0, "tdb_fetch(tdb, key) should return a value");
+	ok(val.dsize == data.dsize, "tdb_fetch(tdb, key) should return a value");
+	ok(memcmp(val.dptr, data.dptr, data.dsize) == 0, "tdb_fetch(tdb, key) should return a value");
+
+	write(tochild[1], &c, sizeof(c));
+	read(fromchild[0], &c, sizeof(c));
+
+	/*
+	 * We see the new values after the commit...
+	 */
+	ret = tdb_exists(tdb, key);
+	ok(ret == 1, "tdb_exists(tdb, key) should return 1");
+
+	val = tdb_fetch(tdb, key);
+	ok(val.dsize != 0, "tdb_fetch(tdb, key) should return a value");
+	ok(val.dsize == key.dsize, "tdb_fetch(tdb, key) should return a value");
+	ok(memcmp(val.dptr, key.dptr, key.dsize) == 0, "tdb_fetch(tdb, key) should return a value");
+
+	write(tochild[1], &c, sizeof(c));
+
+	wait_ret = wait(&status);
+	ok(wait_ret == child, "child should have exited correctly");
+
+	diag("done");
+	return exit_status();
+}
diff --git a/lib/tdb/tools/tdbtorture.c b/lib/tdb/tools/tdbtorture.c
index 9278688..e4b8f69 100644
--- a/lib/tdb/tools/tdbtorture.c
+++ b/lib/tdb/tools/tdbtorture.c
@@ -120,7 +120,6 @@ static void addrec_db(void)
 
 #if TRANSACTION_PROB
 	if (in_transaction == 0 &&
-	    ((tdb_get_flags(db) & TDB_MUTEX_LOCKING) == 0) &&
 	    (always_transaction || random() % TRANSACTION_PROB == 0)) {
 		if (tdb_transaction_start(db) != 0) {
 			fatal("tdb_transaction_start failed");
diff --git a/lib/tdb/wscript b/lib/tdb/wscript
index d129b24..b283795 100644
--- a/lib/tdb/wscript
+++ b/lib/tdb/wscript
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 
 APPNAME = 'tdb'
-VERSION = '1.3.3'
+VERSION = '1.3.4'
 
 blddir = 'bin'
 
@@ -46,6 +46,7 @@ tdb1_unit_tests = [
     'run-mutex-allrecord-bench',
     'run-mutex-allrecord-trylock',
     'run-mutex-allrecord-block',
+    'run-mutex-transaction1',
     'run-mutex-die',
     'run-mutex1',
 ]


-- 
Samba Shared Repository


More information about the samba-cvs mailing list