]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/tdb1_tdb.c
tdb2: unify tdb1_chainlock et al. into tdb_chainlock
[ccan] / ccan / tdb2 / tdb1_tdb.c
index bba16338e97ec937dd66d1b41e1ac0e02eb96003..0a4f8b5503a7841fe0420e523a27a3d3ae42fd31 100644 (file)
@@ -275,6 +275,7 @@ int tdb1_exists(struct tdb_context *tdb, TDB_DATA key)
        uint32_t hash = tdb_hash(tdb, key.dptr, key.dsize);
        int ret;
 
+       assert(tdb->flags & TDB_VERSION1);
        ret = tdb1_exists_hash(tdb, key, hash);
        return ret;
 }
@@ -434,6 +435,7 @@ int tdb1_delete(struct tdb_context *tdb, TDB_DATA key)
        uint32_t hash = tdb_hash(tdb, key.dptr, key.dsize);
        int ret;
 
+       assert(tdb->flags & TDB_VERSION1);
        ret = tdb1_delete_hash(tdb, key, hash);
        return ret;
 }
@@ -627,6 +629,8 @@ int tdb1_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf)
        TDB_DATA dbuf;
        int ret = -1;
 
+       assert(tdb->flags & TDB_VERSION1);
+
        /* find which hash bucket it is in */
        hash = tdb_hash(tdb, key.dptr, key.dsize);
        if (tdb1_lock(tdb, TDB1_BUCKET(hash), F_WRLCK) == -1)
@@ -728,7 +732,7 @@ int tdb1_wipe_all(struct tdb_context *tdb)
        tdb1_off_t recovery_head;
        tdb1_len_t recovery_size = 0;
 
-       if (tdb1_lockall(tdb) != 0) {
+       if (tdb_lockall(tdb) != TDB_SUCCESS) {
                return -1;
        }
 
@@ -797,16 +801,11 @@ int tdb1_wipe_all(struct tdb_context *tdb)
                }
        }
 
-       if (tdb1_unlockall(tdb) != 0) {
-               tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
-                          "tdb1_wipe_all: failed to unlock");
-               goto failed;
-       }
-
+       tdb_unlockall(tdb);
        return 0;
 
 failed:
-       tdb1_unlockall(tdb);
+       tdb_unlockall(tdb);
        return -1;
 }
 
@@ -858,7 +857,7 @@ int tdb1_repack(struct tdb_context *tdb)
        state.error = TDB_SUCCESS;
        state.dest_db = tmp_db;
 
-       if (tdb1_traverse_read(tdb, repack_traverse, &state) == -1) {
+       if (tdb1_traverse(tdb, repack_traverse, &state) == -1) {
                tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
                           __location__ " Failed to traverse copying out");
                tdb1_transaction_cancel(tdb);
@@ -885,7 +884,7 @@ int tdb1_repack(struct tdb_context *tdb)
        state.error = TDB_SUCCESS;
        state.dest_db = tdb;
 
-       if (tdb1_traverse_read(tmp_db, repack_traverse, &state) == -1) {
+       if (tdb1_traverse(tmp_db, repack_traverse, &state) == -1) {
                tdb_logerr(tdb, tdb->last_error, TDB_LOG_ERROR,
                           __location__ " Failed to traverse copying back");
                tdb1_transaction_cancel(tdb);