Rev 114: added a tdb_chainlock_nonblock() call to tdb in
http://samba.org/~tridge/ctdb
tridge at samba.org
tridge at samba.org
Mon Apr 16 13:03:36 GMT 2007
------------------------------------------------------------
revno: 114
revision-id: tridge at samba.org-20070416130336-89ba103e570a8324
parent: tridge at samba.org-20070416125258-ea015571e2818a42
committer: Andrew Tridgell <tridge at samba.org>
branch nick: tridge
timestamp: Mon 2007-04-16 23:03:36 +1000
message:
added a tdb_chainlock_nonblock() call to tdb
modified:
lib/tdb/common/lock.c lock.c-20070220022425-m1wibgjq7n5hahs6-7
lib/tdb/include/tdb.h tdb.h-20070125040949-7t3f5zdl1q4z9hyv-101
=== modified file 'lib/tdb/common/lock.c'
--- a/lib/tdb/common/lock.c 2007-04-16 12:52:58 +0000
+++ b/lib/tdb/common/lock.c 2007-04-16 13:03:36 +0000
@@ -105,7 +105,7 @@
/* lock a list in the database. list -1 is the alloc list */
-int tdb_lock(struct tdb_context *tdb, int list, int ltype)
+static int _tdb_lock(struct tdb_context *tdb, int list, int ltype, int op)
{
struct tdb_lock_type *new_lck;
int i;
@@ -158,10 +158,8 @@
/* Since fcntl locks don't nest, we do a lock for the first one,
and simply bump the count for future ones */
- if (tdb->methods->tdb_brlock(tdb,FREELIST_TOP+4*list,ltype,F_SETLKW,
+ if (tdb->methods->tdb_brlock(tdb,FREELIST_TOP+4*list,ltype, op,
0, 1)) {
- TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_lock failed on list %d "
- "ltype=%d (%s)\n", list, ltype, strerror(errno)));
return -1;
}
@@ -175,6 +173,25 @@
return 0;
}
+/* lock a list in the database. list -1 is the alloc list */
+int tdb_lock(struct tdb_context *tdb, int list, int ltype)
+{
+ int ret;
+ ret = _tdb_lock(tdb, list, ltype, F_SETLKW);
+ if (ret) {
+ TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_lock failed on list %d "
+ "ltype=%d (%s)\n", list, ltype, strerror(errno)));
+ }
+ return ret;
+}
+
+/* lock a list in the database. list -1 is the alloc list. non-blocking lock */
+int tdb_lock_nonblock(struct tdb_context *tdb, int list, int ltype)
+{
+ return _tdb_lock(tdb, list, ltype, F_SETLK);
+}
+
+
/* unlock the database: returns void because it's too late for errors. */
/* changed to return int it may be interesting to know there
has been an error --simo */
@@ -351,6 +368,14 @@
return tdb_lock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK);
}
+/* lock/unlock one hash chain, non-blocking. This is meant to be used
+ to reduce contention - it cannot guarantee how many records will be
+ locked */
+int tdb_chainlock_nonblock(struct tdb_context *tdb, TDB_DATA key)
+{
+ return tdb_lock_nonblock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK);
+}
+
int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key)
{
return tdb_unlock(tdb, BUCKET(tdb->hash_fn(&key)), F_WRLCK);
=== modified file 'lib/tdb/include/tdb.h'
--- a/lib/tdb/include/tdb.h 2007-04-16 12:52:58 +0000
+++ b/lib/tdb/include/tdb.h 2007-04-16 13:03:36 +0000
@@ -134,6 +134,7 @@
/* Low level locking functions: use with care */
int tdb_chainlock(struct tdb_context *tdb, TDB_DATA key);
+int tdb_chainlock_nonblock(struct tdb_context *tdb, TDB_DATA key);
int tdb_chainunlock(struct tdb_context *tdb, TDB_DATA key);
int tdb_chainlock_read(struct tdb_context *tdb, TDB_DATA key);
int tdb_chainunlock_read(struct tdb_context *tdb, TDB_DATA key);
More information about the samba-cvs
mailing list