tdb: suppress record write locks when allrecord lock is taken.
[ira/wip.git] / lib / tdb / common / traverse.c
index 3c88c871434cee1d2a53b8c6ec0ff64596c8f8ef..d329ef4da4030c095e530b0d7b05b344c2256305 100644 (file)
@@ -32,7 +32,7 @@
 /* Uses traverse lock: 0 = finish, TDB_NEXT_LOCK_ERR = error,
    other = record offset */
 static tdb_off_t tdb_next_lock(struct tdb_context *tdb, struct tdb_traverse_lock *tlock,
-                        struct list_struct *rec)
+                        struct tdb_record *rec)
 {
        int want_next = (tlock->off != 0);
 
@@ -125,7 +125,8 @@ static tdb_off_t tdb_next_lock(struct tdb_context *tdb, struct tdb_traverse_lock
                want_next = 0;
        }
        /* We finished iteration without finding anything */
-       return TDB_ERRCODE(TDB_SUCCESS, 0);
+       tdb->ecode = TDB_SUCCESS;
+       return 0;
 
  fail:
        tlock->off = 0;
@@ -144,7 +145,7 @@ static int tdb_traverse_internal(struct tdb_context *tdb,
                                 struct tdb_traverse_lock *tl)
 {
        TDB_DATA key, dbuf;
-       struct list_struct rec;
+       struct tdb_record rec;
        int ret = 0, count = 0;
        tdb_off_t off;
 
@@ -228,7 +229,7 @@ int tdb_traverse_read(struct tdb_context *tdb,
        ret = tdb_traverse_internal(tdb, fn, private_data, &tl);
        tdb->traverse_read--;
 
-       tdb_transaction_unlock(tdb);
+       tdb_transaction_unlock(tdb, F_RDLCK);
 
        return ret;
 }
@@ -259,7 +260,7 @@ int tdb_traverse(struct tdb_context *tdb,
        ret = tdb_traverse_internal(tdb, fn, private_data, &tl);
        tdb->traverse_write--;
 
-       tdb_transaction_unlock(tdb);
+       tdb_transaction_unlock(tdb, F_WRLCK);
 
        return ret;
 }
@@ -269,7 +270,7 @@ int tdb_traverse(struct tdb_context *tdb,
 TDB_DATA tdb_firstkey(struct tdb_context *tdb)
 {
        TDB_DATA key;
-       struct list_struct rec;
+       struct tdb_record rec;
        tdb_off_t off;
 
        /* release any old lock */
@@ -301,7 +302,7 @@ TDB_DATA tdb_nextkey(struct tdb_context *tdb, TDB_DATA oldkey)
 {
        uint32_t oldhash;
        TDB_DATA key = tdb_null;
-       struct list_struct rec;
+       struct tdb_record rec;
        unsigned char *k = NULL;
        tdb_off_t off;