r22422: merged tdb changes from ctdb
authorAndrew Tridgell <tridge@samba.org>
Sat, 21 Apr 2007 07:25:40 +0000 (07:25 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:51:17 +0000 (14:51 -0500)
(This used to be commit a0ff739bcab32065d9d3957eb1d93f7791f84f04)

source4/lib/tdb/autogen.sh
source4/lib/tdb/common/lock.c
source4/lib/tdb/common/tdb_private.h
source4/lib/tdb/include/tdb.h
source4/lib/tdb/tools/tdbtest.c

index bf84eeee19a9116f3dc79177449a91321b3e8c31..1691689e10c9f3b5889a50f6939dfdcd0d51ba59 100755 (executable)
@@ -3,7 +3,7 @@
 rm -rf autom4te.cache
 rm -f configure config.h.in
 
-IPATHS="-I libreplace -I lib/replace -I ../libreplace -I ../replace"
+IPATHS="-I libreplace -I lib/replace -I ../libreplace -I ../replace -I ../lib/replace"
 autoconf $IPATHS || exit 1
 autoheader $IPATHS || exit 1
 
index 8a964371d3aa846510c90edc7e95a7c7c11eec67..14ccbe39765d53f046f3d1db12e8558981a18ba3 100644 (file)
@@ -105,7 +105,7 @@ int tdb_brlock_upgrade(struct tdb_context *tdb, tdb_off_t offset, size_t len)
 
 
 /* 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 @@ int tdb_lock(struct tdb_context *tdb, int list, int ltype)
 
        /* 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 @@ int tdb_lock(struct tdb_context *tdb, int list, int ltype)
        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 @@ int tdb_chainlock(struct tdb_context *tdb, TDB_DATA key)
        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);
index 02a23d0387e3ccac1d9a6eea87450e52a53374ef..9d39de020031a4d432ab05f30202653473d55ef1 100644 (file)
@@ -206,7 +206,7 @@ tdb_off_t tdb_find_lock_hash(struct tdb_context *tdb, TDB_DATA key, u32 hash, in
                           struct list_struct *rec);
 void tdb_io_init(struct tdb_context *tdb);
 int tdb_expand(struct tdb_context *tdb, tdb_off_t size);
-int tdb_rec_free_read(struct tdb_context *tdb, tdb_off_t off,
-                     struct list_struct *rec);
+int rec_free_read(struct tdb_context *tdb, tdb_off_t off,
+                 struct list_struct *rec);
 
 
index dafe2a130ece79865c2a2aeea20a4ecc172f2f04..e77b78f7ed0258cd26e39990405ee7e1931b99f0 100644 (file)
@@ -134,6 +134,7 @@ int tdb_get_flags(struct tdb_context *tdb);
 
 /* 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);
index 1564a42bc41c56977730acfc7c539f37349b1bf2..416bc50a5b073c07fad11c2d10a7a08fdb9253ae 100644 (file)
@@ -214,7 +214,7 @@ static void merge_test(void)
        key.dptr = keys[3];
        tdb_delete(db, key);
 }
-       
+
  int main(int argc, const char *argv[])
 {
        int i, seed=0;