]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/open.c
tdb2: make jenkins_hash function non-static, rename to tdb_jenkins_hash.
[ccan] / ccan / tdb2 / open.c
index 5ee2ed7844105d7c8e753e7e79d5b7885ba1d5e0..49804acfba427236382eb5e76d9790e05833eea7 100644 (file)
@@ -16,7 +16,6 @@
    License along with this library; if not, see <http://www.gnu.org/licenses/>.
 */
 #include "private.h"
-#include <ccan/hash/hash.h>
 #include <assert.h>
 
 /* all tdbs, to detect double-opens (fcntl file don't nest!) */
@@ -242,16 +241,6 @@ enum TDB_ERROR tdb_set_attribute(struct tdb_context *tdb,
        return TDB_SUCCESS;
 }
 
-static uint64_t jenkins_hash(const void *key, size_t length, uint64_t seed,
-                            void *unused)
-{
-       uint64_t ret;
-       /* hash64_stable assumes lower bits are more important; they are a
-        * slightly better hash.  We use the upper bits first, so swap them. */
-       ret = hash64_stable((const unsigned char *)key, length, seed);
-       return (ret >> 32) | (ret << 32);
-}
-
 enum TDB_ERROR tdb_get_attribute(struct tdb_context *tdb,
                                 union tdb_attribute *attr)
 {
@@ -363,22 +352,22 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
        } else {
                tdb->name = NULL;
        }
-       tdb->direct_access = 0;
        tdb->flags = tdb_flags;
        tdb->log_fn = NULL;
-       tdb->transaction = NULL;
-       tdb->access = NULL;
        tdb->open_flags = open_flags;
        tdb->last_error = TDB_SUCCESS;
        tdb->file = NULL;
        tdb->openhook = NULL;
        tdb->lock_fn = tdb_fcntl_lock;
        tdb->unlock_fn = tdb_fcntl_unlock;
-       tdb->hash_fn = jenkins_hash;
+       tdb->hash_fn = tdb_jenkins_hash;
        memset(&tdb->stats, 0, sizeof(tdb->stats));
        tdb->stats.base.attr = TDB_ATTRIBUTE_STATS;
        tdb->stats.size = sizeof(tdb->stats);
        tdb_io_init(tdb);
+       tdb->tdb2.direct_access = 0;
+       tdb->tdb2.transaction = NULL;
+       tdb->tdb2.access = NULL;
 
        while (attr) {
                switch (attr->base.attr) {
@@ -573,7 +562,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
        tdb_unlock_open(tdb, openlock);
 
        /* This make sure we have current map_size and mmap. */
-       ecode = tdb->methods->oob(tdb, tdb->file->map_size + 1, true);
+       ecode = tdb->tdb2.io->oob(tdb, tdb->file->map_size + 1, true);
        if (unlikely(ecode != TDB_SUCCESS))
                goto fail;
 
@@ -655,7 +644,7 @@ int tdb_close(struct tdb_context *tdb)
 
        tdb_trace(tdb, "tdb_close");
 
-       if (tdb->transaction) {
+       if (tdb->tdb2.transaction) {
                tdb_transaction_cancel(tdb);
        }
 
@@ -689,3 +678,13 @@ int tdb_close(struct tdb_context *tdb)
 
        return ret;
 }
+
+void tdb_foreach_(int (*fn)(struct tdb_context *, void *), void *p)
+{
+       struct tdb_context *i;
+
+       for (i = tdbs; i; i = i->next) {
+               if (fn(i, p) != 0)
+                       break;
+       }
+}