X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Ftdb1_private.h;h=68dc39f6f8e02d1fcce98feb9a2a55b4e45c4763;hp=0d40d7a9190cc88dad9cc48334e3787a7527c369;hb=614259f13c3e694fcd6b57fc05a329066e43c76d;hpb=22d0e0dc59fc9d7e0046fec6971ef478c2d604fd diff --git a/ccan/tdb2/tdb1_private.h b/ccan/tdb2/tdb1_private.h index 0d40d7a9..68dc39f6 100644 --- a/ccan/tdb2/tdb1_private.h +++ b/ccan/tdb2/tdb1_private.h @@ -26,16 +26,6 @@ */ #include "private.h" -#include "tdb1.h" - -/**** FIXME: Type overrides for tdb2, for transition! */ -#define tdb_logerr(tdb, ecode, level, ...) \ - tdb_logerr((struct tdb_context *)(tdb), (ecode), (level), __VA_ARGS__) - -#define tdb_error(tdb) \ - tdb_error((struct tdb_context *)(tdb)) - -/***** END FIXME ***/ #include @@ -56,9 +46,6 @@ #define __location__ __FILE__ ":" __STRINGSTRING(__LINE__) #endif -typedef uint32_t tdb1_len_t; -typedef uint32_t tdb1_off_t; - #ifndef offsetof #define offsetof(t,f) ((unsigned int)&((t *)0)->f) #endif @@ -74,11 +61,10 @@ typedef uint32_t tdb1_off_t; #define TDB1_DEFAULT_HASH_SIZE 131 #define TDB1_FREELIST_TOP (sizeof(struct tdb1_header)) #define TDB1_ALIGN(x,a) (((x) + (a)-1) & ~((a)-1)) -#define TDB1_BYTEREV(x) (((((x)&0xff)<<24)|((x)&0xFF00)<<8)|(((x)>>8)&0xFF00)|((x)>>24)) #define TDB1_DEAD(r) ((r)->magic == TDB1_DEAD_MAGIC) #define TDB1_BAD_MAGIC(r) ((r)->magic != TDB1_MAGIC && !TDB1_DEAD(r)) #define TDB1_HASH_TOP(hash) (TDB1_FREELIST_TOP + (TDB1_BUCKET(hash)+1)*sizeof(tdb1_off_t)) -#define TDB1_HASHTABLE_SIZE(tdb) ((tdb->header.hash_size+1)*sizeof(tdb1_off_t)) +#define TDB1_HASHTABLE_SIZE(tdb) ((tdb->tdb1.header.hash_size+1)*sizeof(tdb1_off_t)) #define TDB1_DATA_START(hash_size) (TDB1_HASH_TOP(hash_size-1) + sizeof(tdb1_off_t)) #define TDB1_RECOVERY_HEAD offsetof(struct tdb1_header, recovery_start) #define TDB1_SEQNUM_OFS offsetof(struct tdb1_header, sequence_number) @@ -92,10 +78,10 @@ typedef uint32_t tdb1_off_t; /* free memory if the pointer is valid and zero the pointer */ #ifndef SAFE_FREE -#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); (x)=NULL;} } while(0) +#define SAFE_FREE(x) do { if ((x) != NULL) {free((void *)x); (x)=NULL;} } while(0) #endif -#define TDB1_BUCKET(hash) ((hash) % tdb->header.hash_size) +#define TDB1_BUCKET(hash) ((hash) % tdb->tdb1.header.hash_size) #define TDB1_DOCONV() (tdb->flags & TDB_CONVERT) #define TDB1_CONV(x) (TDB1_DOCONV() ? tdb1_convert(&x, sizeof(x)) : &x) @@ -122,139 +108,71 @@ struct tdb1_record { }; -/* this is stored at the front of every database */ -struct tdb1_header { - char magic_food[32]; /* for /etc/magic */ - uint32_t version; /* version of the code */ - uint32_t hash_size; /* number of hash entries */ - tdb1_off_t rwlocks; /* obsolete - kept to detect old formats */ - tdb1_off_t recovery_start; /* offset of transaction recovery region */ - tdb1_off_t sequence_number; /* used when TDB1_SEQNUM is set */ - uint32_t magic1_hash; /* hash of TDB_MAGIC_FOOD. */ - uint32_t magic2_hash; /* hash of TDB1_MAGIC. */ - tdb1_off_t reserved[27]; -}; - -struct tdb1_lock_type { - uint32_t off; - uint32_t count; - uint32_t ltype; -}; - -struct tdb1_traverse_lock { - struct tdb1_traverse_lock *next; - uint32_t off; - uint32_t hash; - int lock_rw; -}; - -struct tdb1_context; - struct tdb1_methods { - int (*tdb1_read)(struct tdb1_context *, tdb1_off_t , void *, tdb1_len_t , int ); - int (*tdb1_write)(struct tdb1_context *, tdb1_off_t, const void *, tdb1_len_t); - void (*next_hash_chain)(struct tdb1_context *, uint32_t *); - int (*tdb1_oob)(struct tdb1_context *, tdb1_off_t , int ); - int (*tdb1_expand_file)(struct tdb1_context *, tdb1_off_t , tdb1_off_t ); + int (*tdb1_read)(struct tdb_context *, tdb1_off_t , void *, tdb1_len_t , int ); + int (*tdb1_write)(struct tdb_context *, tdb1_off_t, const void *, tdb1_len_t); + void (*next_hash_chain)(struct tdb_context *, uint32_t *); + int (*tdb1_oob)(struct tdb_context *, tdb1_off_t , int ); + int (*tdb1_expand_file)(struct tdb_context *, tdb1_off_t , tdb1_off_t ); }; -struct tdb1_context { - struct tdb1_context *next; - - char *name; /* the name of the database */ - - /* Logging function */ - void (*log_fn)(struct tdb1_context *tdb, - enum tdb_log_level level, - enum TDB_ERROR ecode, - const char *message, - void *data); - void *log_data; - - /* Last error we returned. */ - enum TDB_ERROR last_error; /* error code for last tdb error */ - - void *map_ptr; /* where it is currently mapped */ - int fd; /* open file descriptor for the database */ - tdb1_len_t map_size; /* how much space has been mapped */ - int read_only; /* opened read-only */ - int traverse_read; /* read-only traversal */ - int traverse_write; /* read-write traversal */ - struct tdb1_lock_type allrecord_lock; /* .offset == upgradable */ - int num_lockrecs; - struct tdb1_lock_type *lockrecs; /* only real locks, all with count>0 */ - struct tdb1_header header; /* a cached copy of the header */ - uint32_t flags; /* the flags passed to tdb1_open */ - struct tdb1_traverse_lock travlocks; /* current traversal locks */ - dev_t device; /* uniquely identifies this tdb */ - ino_t inode; /* uniquely identifies this tdb */ - unsigned int (*hash_fn)(TDB_DATA *key); - int open_flags; /* flags used in the open - needed by reopen */ - const struct tdb1_methods *methods; - struct tdb1_transaction *transaction; - int page_size; - int max_dead_records; -}; /* internal prototypes */ -int tdb1_munmap(struct tdb1_context *tdb); -void tdb1_mmap(struct tdb1_context *tdb); -int tdb1_lock(struct tdb1_context *tdb, int list, int ltype); -int tdb1_nest_lock(struct tdb1_context *tdb, uint32_t offset, int ltype, +int tdb1_munmap(struct tdb_context *tdb); +void tdb1_mmap(struct tdb_context *tdb); +int tdb1_lock(struct tdb_context *tdb, int list, int ltype); +int tdb1_nest_lock(struct tdb_context *tdb, uint32_t offset, int ltype, enum tdb_lock_flags flags); -int tdb1_nest_unlock(struct tdb1_context *tdb, uint32_t offset, int ltype); -int tdb1_unlock(struct tdb1_context *tdb, int list, int ltype); -int tdb1_brlock(struct tdb1_context *tdb, +int tdb1_nest_unlock(struct tdb_context *tdb, uint32_t offset, int ltype); +int tdb1_unlock(struct tdb_context *tdb, int list, int ltype); +int tdb1_brlock(struct tdb_context *tdb, int rw_type, tdb1_off_t offset, size_t len, enum tdb_lock_flags flags); -int tdb1_brunlock(struct tdb1_context *tdb, +int tdb1_brunlock(struct tdb_context *tdb, int rw_type, tdb1_off_t offset, size_t len); -bool tdb1_have_extra_locks(struct tdb1_context *tdb); -void tdb1_release_transaction_locks(struct tdb1_context *tdb); -int tdb1_transaction_lock(struct tdb1_context *tdb, int ltype, +bool tdb1_have_extra_locks(struct tdb_context *tdb); +void tdb1_release_transaction_locks(struct tdb_context *tdb); +int tdb1_transaction_lock(struct tdb_context *tdb, int ltype, enum tdb_lock_flags lockflags); -int tdb1_transaction_unlock(struct tdb1_context *tdb, int ltype); -int tdb1_recovery_area(struct tdb1_context *tdb, +int tdb1_transaction_unlock(struct tdb_context *tdb, int ltype); +int tdb1_recovery_area(struct tdb_context *tdb, const struct tdb1_methods *methods, tdb1_off_t *recovery_offset, struct tdb1_record *rec); -int tdb1_allrecord_lock(struct tdb1_context *tdb, int ltype, - enum tdb_lock_flags flags, bool upgradable); -int tdb1_allrecord_unlock(struct tdb1_context *tdb, int ltype); -int tdb1_allrecord_upgrade(struct tdb1_context *tdb); -int tdb1_write_lock_record(struct tdb1_context *tdb, tdb1_off_t off); -int tdb1_write_unlock_record(struct tdb1_context *tdb, tdb1_off_t off); -int tdb1_ofs_read(struct tdb1_context *tdb, tdb1_off_t offset, tdb1_off_t *d); -int tdb1_ofs_write(struct tdb1_context *tdb, tdb1_off_t offset, tdb1_off_t *d); +int tdb1_allrecord_upgrade(struct tdb_context *tdb); +int tdb1_write_lock_record(struct tdb_context *tdb, tdb1_off_t off); +int tdb1_write_unlock_record(struct tdb_context *tdb, tdb1_off_t off); +int tdb1_ofs_read(struct tdb_context *tdb, tdb1_off_t offset, tdb1_off_t *d); +int tdb1_ofs_write(struct tdb_context *tdb, tdb1_off_t offset, tdb1_off_t *d); void *tdb1_convert(void *buf, uint32_t size); -int tdb1_free(struct tdb1_context *tdb, tdb1_off_t offset, struct tdb1_record *rec); -tdb1_off_t tdb1_allocate(struct tdb1_context *tdb, tdb1_len_t length, struct tdb1_record *rec); -int tdb1_ofs_read(struct tdb1_context *tdb, tdb1_off_t offset, tdb1_off_t *d); -int tdb1_ofs_write(struct tdb1_context *tdb, tdb1_off_t offset, tdb1_off_t *d); -int tdb1_lock_record(struct tdb1_context *tdb, tdb1_off_t off); -int tdb1_unlock_record(struct tdb1_context *tdb, tdb1_off_t off); -bool tdb1_needs_recovery(struct tdb1_context *tdb); -int tdb1_rec_read(struct tdb1_context *tdb, tdb1_off_t offset, struct tdb1_record *rec); -int tdb1_rec_write(struct tdb1_context *tdb, tdb1_off_t offset, struct tdb1_record *rec); -int tdb1_do_delete(struct tdb1_context *tdb, tdb1_off_t rec_ptr, struct tdb1_record *rec); -unsigned char *tdb1_alloc_read(struct tdb1_context *tdb, tdb1_off_t offset, tdb1_len_t len); -int tdb1_parse_data(struct tdb1_context *tdb, TDB_DATA key, - tdb1_off_t offset, tdb1_len_t len, - int (*parser)(TDB_DATA key, TDB_DATA data, - void *private_data), - void *private_data); -tdb1_off_t tdb1_find_lock_hash(struct tdb1_context *tdb, TDB_DATA key, uint32_t hash, int locktype, +int tdb1_free(struct tdb_context *tdb, tdb1_off_t offset, struct tdb1_record *rec); +tdb1_off_t tdb1_allocate(struct tdb_context *tdb, tdb1_len_t length, struct tdb1_record *rec); +int tdb1_ofs_read(struct tdb_context *tdb, tdb1_off_t offset, tdb1_off_t *d); +int tdb1_ofs_write(struct tdb_context *tdb, tdb1_off_t offset, tdb1_off_t *d); +int tdb1_lock_record(struct tdb_context *tdb, tdb1_off_t off); +int tdb1_unlock_record(struct tdb_context *tdb, tdb1_off_t off); +tdb_bool_err tdb1_needs_recovery(struct tdb_context *tdb); +int tdb1_rec_read(struct tdb_context *tdb, tdb1_off_t offset, struct tdb1_record *rec); +int tdb1_rec_write(struct tdb_context *tdb, tdb1_off_t offset, struct tdb1_record *rec); +int tdb1_do_delete(struct tdb_context *tdb, tdb1_off_t rec_ptr, struct tdb1_record *rec); +unsigned char *tdb1_alloc_read(struct tdb_context *tdb, tdb1_off_t offset, tdb1_len_t len); +enum TDB_ERROR tdb1_parse_data(struct tdb_context *tdb, TDB_DATA key, + tdb1_off_t offset, tdb1_len_t len, + enum TDB_ERROR (*parser)(TDB_DATA key, + TDB_DATA data, + void *private_data), + void *private_data); +tdb1_off_t tdb1_find_lock_hash(struct tdb_context *tdb, TDB_DATA key, uint32_t hash, int locktype, struct tdb1_record *rec); -void tdb1_io_init(struct tdb1_context *tdb); -int tdb1_expand(struct tdb1_context *tdb, tdb1_off_t size); -int tdb1_rec_free_read(struct tdb1_context *tdb, tdb1_off_t off, +void tdb1_io_init(struct tdb_context *tdb); +int tdb1_expand(struct tdb_context *tdb, tdb1_off_t size); +int tdb1_rec_free_read(struct tdb_context *tdb, tdb1_off_t off, struct tdb1_record *rec); bool tdb1_write_all(int fd, const void *buf, size_t count); -int tdb1_transaction_recover(struct tdb1_context *tdb); -void tdb1_header_hash(struct tdb1_context *tdb, +void tdb1_header_hash(struct tdb_context *tdb, uint32_t *magic1_hash, uint32_t *magic2_hash); -unsigned int tdb1_old_hash(TDB_DATA *key); -size_t tdb1_dead_space(struct tdb1_context *tdb, tdb1_off_t off); +uint64_t tdb1_old_hash(const void *key, size_t len, uint64_t seed, void *); +size_t tdb1_dead_space(struct tdb_context *tdb, tdb1_off_t off); #endif /* CCAN_TDB2_TDB1_PRIVATE_H */