diff options
author | Andrew Tridgell <tridge@samba.org> | 2005-09-26 01:12:12 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:38:55 -0500 |
commit | be27946d84dbf9155d9505d00abe91089a9b8125 (patch) | |
tree | 90ed05cc9e2f8394822579f2fc9bc0cefa671ba1 /source4/lib/tdb/common/lock.c | |
parent | 9593101ec118dd242bf25fabf3e17c58269e632c (diff) | |
download | samba-be27946d84dbf9155d9505d00abe91089a9b8125.tar.gz samba-be27946d84dbf9155d9505d00abe91089a9b8125.tar.bz2 samba-be27946d84dbf9155d9505d00abe91089a9b8125.zip |
r10492: 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.
(This used to be commit 980dd17f7d0a622cd772afc9ba15e50007ad9c6e)
Diffstat (limited to 'source4/lib/tdb/common/lock.c')
-rw-r--r-- | source4/lib/tdb/common/lock.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/source4/lib/tdb/common/lock.c b/source4/lib/tdb/common/lock.c index 703cfe9dc5..04135a2274 100644 --- a/source4/lib/tdb/common/lock.c +++ b/source4/lib/tdb/common/lock.c @@ -81,6 +81,32 @@ int tdb_brlock_len(struct tdb_context *tdb, tdb_off_t offset, } +/* + 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. |