X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;ds=inline;f=ccan%2Ftdb2%2Fprivate.h;h=86cfd7777bdd7dbcb6c0fdeafa627fe4c01e76e9;hb=4916bc0a12ede1bf81c6895be9e7df39199f3290;hp=6b15636e6efa346996ea94e3ec17dad5e3b517c0;hpb=ebdd6451e2d7aa185e62a59fa2c72ffe36772d9a;p=ccan diff --git a/ccan/tdb2/private.h b/ccan/tdb2/private.h index 6b15636e..86cfd777 100644 --- a/ccan/tdb2/private.h +++ b/ccan/tdb2/private.h @@ -136,7 +136,7 @@ static inline uint64_t rec_extra_padding(const struct tdb_used_record *r) static inline uint64_t rec_hash(const struct tdb_used_record *r) { - return ((r->magic_and_meta >> 32) & ((1ULL << 11) - 1)) << (64 - 11); + return ((r->magic_and_meta >> 32) & ((1ULL << 11) - 1)); } static inline uint16_t rec_magic(const struct tdb_used_record *r) @@ -223,6 +223,9 @@ struct tdb_context { tdb_hashfn_t khash; void *hash_priv; + /* Set if we are in a transaction. */ + struct tdb_transaction *transaction; + /* What zone of the tdb to use, for spreading load. */ uint64_t last_zone; @@ -234,9 +237,6 @@ struct tdb_context { uint64_t num_lockrecs; struct tdb_lock_type *lockrecs; - /* Set if we are in a transaction. */ - struct tdb_transaction *transaction; - /* Single list of all TDBs, to avoid multiple opens. */ struct tdb_context *next; dev_t device; @@ -247,22 +247,25 @@ struct tdb_methods { int (*read)(struct tdb_context *, tdb_off_t, void *, tdb_len_t); int (*write)(struct tdb_context *, tdb_off_t, const void *, tdb_len_t); int (*oob)(struct tdb_context *, tdb_off_t, bool); - int (*expand_file)(struct tdb_context *, tdb_len_t, tdb_len_t); + int (*expand_file)(struct tdb_context *, tdb_len_t); }; /* internal prototypes */ /* tdb.c: */ -/* Returns true if header changed. */ -bool update_header(struct tdb_context *tdb); +/* Returns true if header changed (and updates it). */ +bool header_changed(struct tdb_context *tdb); + +/* Commit header to disk. */ +int write_header(struct tdb_context *tdb); /* Hash random memory. */ uint64_t tdb_hash(struct tdb_context *tdb, const void *ptr, size_t len); /* free.c: */ -uint64_t random_free_zone(struct tdb_context *tdb); +void tdb_zone_init(struct tdb_context *tdb); /* If this fails, try tdb_expand. */ tdb_off_t alloc(struct tdb_context *tdb, size_t keylen, size_t datalen, @@ -346,9 +349,11 @@ int tdb_read_convert(struct tdb_context *tdb, tdb_off_t off, uint64_t hash_record(struct tdb_context *tdb, tdb_off_t off); /* lock.c: */ +void tdb_lock_init(struct tdb_context *tdb); + /* Lock/unlock a particular hash list. */ -int tdb_lock_list(struct tdb_context *tdb, tdb_off_t list, - int ltype, enum tdb_lock_flags waitflag); +tdb_off_t tdb_lock_list(struct tdb_context *tdb, uint64_t hash, + int ltype, enum tdb_lock_flags waitflag); int tdb_unlock_list(struct tdb_context *tdb, tdb_off_t list, int ltype); /* Lock/unlock a particular free list. */