X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftdb2%2Fprivate.h;h=5e71bc2da46e1af4ec97c37489e1142cb62f9fe8;hb=e984ef661368582f7b6e7a8d2a2d709356ac7963;hp=a241210bebc0a559a087881f11d1d413c364656d;hpb=6804501c350181dea8f531142b28c620b70edbd9;p=ccan diff --git a/ccan/tdb2/private.h b/ccan/tdb2/private.h index a241210b..5e71bc2d 100644 --- a/ccan/tdb2/private.h +++ b/ccan/tdb2/private.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -60,14 +61,11 @@ typedef uint64_t tdb_len_t; typedef uint64_t tdb_off_t; -#ifndef offsetof -#define offsetof(t,f) ((unsigned int)&((t *)0)->f) -#endif - #define TDB_MAGIC_FOOD "TDB file\n" #define TDB_VERSION ((uint64_t)(0x26011967 + 7)) #define TDB_MAGIC ((uint64_t)0x1999) #define TDB_FREE_MAGIC ((~(uint64_t)TDB_MAGIC) << 6) +#define TDB_COALESCING_MAGIC (0xBAD1DEA2FEEDULL << 6) #define TDB_HASH_MAGIC (0xA1ABE11A01092008ULL) #define TDB_RECOVERY_MAGIC (0xf53bc0e7U) #define TDB_RECOVERY_INVALID_MAGIC (0x0) @@ -113,6 +111,10 @@ typedef uint64_t tdb_off_t; #define TDB_OFF_MASK \ (((1ULL << (64 - TDB_OFF_UPPER_STEAL)) - 1) - TDB_OFF_HASH_GROUP_MASK) +/* We have to be able to fit a free record here. */ +#define TDB_MIN_DATA_LEN \ + (sizeof(struct tdb_free_record) - sizeof(struct tdb_used_record)) + /* We ensure buckets up to size 1 << (zone_bits - TDB_COMFORT_FACTOR_BITS). */ /* FIXME: test this matches size_to_bucket! */ #define BUCKETS_FOR_ZONE(zone_bits) ((zone_bits) + 2 - TDB_COMFORT_FACTOR_BITS) @@ -242,7 +244,6 @@ struct hash_info { struct traverse_info { struct traverse_level { tdb_off_t hashtable; - const tdb_off_t *entries; /* We ignore groups here, and treat it as a big array. */ unsigned entry; unsigned int total_buckets; @@ -283,9 +284,12 @@ struct tdb_context { /* How much space has been mapped (<= current file size) */ tdb_len_t map_size; - /* Opened read-only? */ + /* Operating read-only? (Opened O_RDONLY, or in traverse_read) */ bool read_only; + /* mmap read only? */ + int mmap_flags; + /* Error code for last tdb error. */ enum TDB_ERROR ecode; @@ -328,6 +332,7 @@ struct tdb_methods { 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); + void *(*direct)(struct tdb_context *, tdb_off_t, size_t); }; /* @@ -347,7 +352,8 @@ tdb_off_t find_and_lock(struct tdb_context *tdb, struct tdb_data key, int ltype, struct hash_info *h, - struct tdb_used_record *rec); + struct tdb_used_record *rec, + struct traverse_info *tinfo); int replace_in_hash(struct tdb_context *tdb, struct hash_info *h, @@ -376,7 +382,7 @@ int add_free_record(struct tdb_context *tdb, unsigned int zone_bits, int set_header(struct tdb_context *tdb, struct tdb_used_record *rec, uint64_t keylen, uint64_t datalen, - uint64_t actuallen, uint64_t hash, + uint64_t actuallen, unsigned hashlow, unsigned int zone_bits); /* Used by tdb_check to verify. */ @@ -418,9 +424,11 @@ int tdb_write_off(struct tdb_context *tdb, tdb_off_t off, tdb_off_t val); /* Clear an ondisk area. */ int zero_out(struct tdb_context *tdb, tdb_off_t off, tdb_len_t len); -/* Return a non-zero offset in this array, or num. */ -tdb_off_t tdb_find_nonzero_off(struct tdb_context *tdb, tdb_off_t off, - uint64_t num); +/* Return a non-zero offset between >= start < end in this array (or end). */ +tdb_off_t tdb_find_nonzero_off(struct tdb_context *tdb, + tdb_off_t base, + uint64_t start, + uint64_t end); /* Return a zero offset in this array, or num. */ tdb_off_t tdb_find_zero_off(struct tdb_context *tdb, tdb_off_t off,