svn commit: samba r10492 - in branches/SAMBA_4_0/source/lib/tdb/common: .

tridge at samba.org tridge at samba.org
Mon Sep 26 01:12:13 GMT 2005


Author: tridge
Date: 2005-09-26 01:12:12 +0000 (Mon, 26 Sep 2005)
New Revision: 10492

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

Log:

work around a bug in solaris which cases lock upgrades to fail with
EDEADLK even when progress can be made. This is not a good solution,
but I can't find anything better.

Modified:
   branches/SAMBA_4_0/source/lib/tdb/common/lock.c
   branches/SAMBA_4_0/source/lib/tdb/common/tdb_private.h
   branches/SAMBA_4_0/source/lib/tdb/common/transaction.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/tdb/common/lock.c
===================================================================
--- branches/SAMBA_4_0/source/lib/tdb/common/lock.c	2005-09-25 21:01:56 UTC (rev 10491)
+++ branches/SAMBA_4_0/source/lib/tdb/common/lock.c	2005-09-26 01:12:12 UTC (rev 10492)
@@ -81,6 +81,32 @@
 }
 
 
+/*
+  upgrade a read lock to a write lock. This needs to be handled in a
+  special way as some OSes (such as solaris) have too conservative
+  deadlock detection and claim a deadlock when progress can be
+  made. For those OSes we may loop for a while.  
+*/
+int tdb_brlock_upgrade(struct tdb_context *tdb, tdb_off_t offset, size_t len)
+{
+	int count = 1000;
+	while (count--) {
+		struct timeval tv;
+		if (tdb_brlock_len(tdb, offset, F_WRLCK, F_SETLKW, 1, len) == 0) {
+			return 0;
+		}
+		if (errno != EDEADLK) {
+			break;
+		}
+		/* sleep for as short a time as we can - more portable than usleep() */
+		tv.tv_sec = 0;
+		tv.tv_usec = 1;
+		select(0, NULL, NULL, NULL, &tv);
+	}
+	return -1;
+}
+
+
 /* a byte range locking function - return 0 on success
    this functions locks/unlocks 1 byte at the specified offset.
 

Modified: branches/SAMBA_4_0/source/lib/tdb/common/tdb_private.h
===================================================================
--- branches/SAMBA_4_0/source/lib/tdb/common/tdb_private.h	2005-09-25 21:01:56 UTC (rev 10491)
+++ branches/SAMBA_4_0/source/lib/tdb/common/tdb_private.h	2005-09-26 01:12:12 UTC (rev 10492)
@@ -216,6 +216,7 @@
 int tdb_lock(struct tdb_context *tdb, int list, int ltype);
 int tdb_unlock(struct tdb_context *tdb, int list, int ltype);
 int tdb_brlock(struct tdb_context *tdb, tdb_off_t offset, int rw_type, int lck_type, int probe);
+int tdb_brlock_upgrade(struct tdb_context *tdb, tdb_off_t offset, size_t len);
 int tdb_brlock_len(struct tdb_context *tdb, tdb_off_t offset, 
 		   int rw_type, int lck_type, int probe, size_t len);
 int tdb_write_lock_record(struct tdb_context *tdb, tdb_off_t off);

Modified: branches/SAMBA_4_0/source/lib/tdb/common/transaction.c
===================================================================
--- branches/SAMBA_4_0/source/lib/tdb/common/transaction.c	2005-09-25 21:01:56 UTC (rev 10491)
+++ branches/SAMBA_4_0/source/lib/tdb/common/transaction.c	2005-09-26 01:12:12 UTC (rev 10492)
@@ -772,7 +772,7 @@
 	}
 
 	/* upgrade the main transaction lock region to a write lock */
-	if (tdb_brlock_len(tdb, FREELIST_TOP, F_WRLCK, F_SETLKW, 0, 0) == -1) {
+	if (tdb_brlock_upgrade(tdb, FREELIST_TOP, 0) == -1) {
 		TDB_LOG((tdb, 0, "tdb_transaction_start: failed to upgrade hash locks\n"));
 		tdb->ecode = TDB_ERR_LOCK;
 		tdb_transaction_cancel(tdb);



More information about the samba-cvs mailing list