4 Trivial Database 2: private types and prototypes
5 Copyright (C) Rusty Russell 2010
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 3 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 #include <ccan/tdb2/tdb2.h>
32 #include <ccan/likely/likely.h>
33 #include <ccan/endian/endian.h>
39 /* #define TDB_TRACE 1 */
42 #define __STRING(x) #x
45 #ifndef __STRINGSTRING
46 #define __STRINGSTRING(x) __STRING(x)
50 #define __location__ __FILE__ ":" __STRINGSTRING(__LINE__)
53 typedef uint64_t tdb_len_t;
54 typedef uint64_t tdb_off_t;
56 #define TDB_MAGIC_FOOD "TDB file\n"
57 #define TDB_VERSION ((uint64_t)(0x26011967 + 7))
58 #define TDB1_VERSION (0x26011967 + 6)
59 #define TDB_USED_MAGIC ((uint64_t)0x1999)
60 #define TDB_HTABLE_MAGIC ((uint64_t)0x1888)
61 #define TDB_CHAIN_MAGIC ((uint64_t)0x1777)
62 #define TDB_FTABLE_MAGIC ((uint64_t)0x1666)
63 #define TDB_FREE_MAGIC ((uint64_t)0xFE)
64 #define TDB_HASH_MAGIC (0xA1ABE11A01092008ULL)
65 #define TDB_RECOVERY_MAGIC (0xf53bc0e7ad124589ULL)
66 #define TDB_RECOVERY_INVALID_MAGIC (0x0ULL)
68 #define TDB_OFF_IS_ERR(off) unlikely(off >= (tdb_off_t)TDB_ERR_LAST)
70 /* Packing errors into pointers and v.v. */
71 #define TDB_PTR_IS_ERR(ptr) \
72 unlikely((unsigned long)(ptr) >= (unsigned long)TDB_ERR_LAST)
73 #define TDB_PTR_ERR(p) ((enum TDB_ERROR)(long)(p))
74 #define TDB_ERR_PTR(err) ((void *)(long)(err))
76 /* Common case of returning true, false or -ve error. */
77 typedef int tdb_bool_err;
79 /* Prevent others from opening the file. */
80 #define TDB_OPEN_LOCK 0
82 #define TDB_EXPANSION_LOCK 2
83 /* Doing a transaction. */
84 #define TDB_TRANSACTION_LOCK 8
85 /* Hash chain locks. */
86 #define TDB_HASH_LOCK_START 64
88 /* Range for hash locks. */
89 #define TDB_HASH_LOCK_RANGE_BITS 30
90 #define TDB_HASH_LOCK_RANGE (1 << TDB_HASH_LOCK_RANGE_BITS)
92 /* We have 1024 entries in the top level. */
93 #define TDB_TOPLEVEL_HASH_BITS 10
94 /* And 64 entries in each sub-level: thus 64 bits exactly after 9 levels. */
95 #define TDB_SUBLEVEL_HASH_BITS 6
96 /* And 8 entries in each group, ie 8 groups per sublevel. */
97 #define TDB_HASH_GROUP_BITS 3
98 /* This is currently 10: beyond this we chain. */
99 #define TDB_MAX_LEVELS (1+(64-TDB_TOPLEVEL_HASH_BITS) / TDB_SUBLEVEL_HASH_BITS)
101 /* Extend file by least 100 times larger than needed. */
102 #define TDB_EXTENSION_FACTOR 100
104 /* We steal bits from the offsets to store hash info. */
105 #define TDB_OFF_HASH_GROUP_MASK ((1ULL << TDB_HASH_GROUP_BITS) - 1)
106 /* We steal this many upper bits, giving a maximum offset of 64 exabytes. */
107 #define TDB_OFF_UPPER_STEAL 8
108 #define TDB_OFF_UPPER_STEAL_EXTRA 7
109 /* The bit number where we store extra hash bits. */
110 #define TDB_OFF_HASH_EXTRA_BIT 57
111 #define TDB_OFF_UPPER_STEAL_SUBHASH_BIT 56
113 /* Additional features we understand. Currently: none. */
114 #define TDB_FEATURE_MASK ((uint64_t)0)
116 /* The bit number where we store the extra hash bits. */
117 /* Convenience mask to get actual offset. */
118 #define TDB_OFF_MASK \
119 (((1ULL << (64 - TDB_OFF_UPPER_STEAL)) - 1) - TDB_OFF_HASH_GROUP_MASK)
121 /* How many buckets in a free list: see size_to_bucket(). */
122 #define TDB_FREE_BUCKETS (64 - TDB_OFF_UPPER_STEAL)
124 /* We have to be able to fit a free record here. */
125 #define TDB_MIN_DATA_LEN \
126 (sizeof(struct tdb_free_record) - sizeof(struct tdb_used_record))
128 /* Indicates this entry is not on an flist (can happen during coalescing) */
129 #define TDB_FTABLE_NONE ((1ULL << TDB_OFF_UPPER_STEAL) - 1)
131 struct tdb_used_record {
132 /* For on-disk compatibility, we avoid bitfields:
138 uint64_t magic_and_meta;
139 /* The bottom key_len_bits*2 are key length, rest is data length. */
140 uint64_t key_and_data_len;
143 static inline unsigned rec_key_bits(const struct tdb_used_record *r)
145 return ((r->magic_and_meta >> 43) & ((1 << 5)-1)) * 2;
148 static inline uint64_t rec_key_length(const struct tdb_used_record *r)
150 return r->key_and_data_len & ((1ULL << rec_key_bits(r)) - 1);
153 static inline uint64_t rec_data_length(const struct tdb_used_record *r)
155 return r->key_and_data_len >> rec_key_bits(r);
158 static inline uint64_t rec_extra_padding(const struct tdb_used_record *r)
160 return (r->magic_and_meta >> 11) & 0xFFFFFFFF;
163 static inline uint32_t rec_hash(const struct tdb_used_record *r)
165 return r->magic_and_meta & ((1 << 11) - 1);
168 static inline uint16_t rec_magic(const struct tdb_used_record *r)
170 return (r->magic_and_meta >> 48);
173 struct tdb_free_record {
174 uint64_t magic_and_prev; /* TDB_OFF_UPPER_STEAL bits magic, then prev */
175 uint64_t ftable_and_len; /* Len not counting these two fields. */
176 /* This is why the minimum record size is 8 bytes. */
180 static inline uint64_t frec_prev(const struct tdb_free_record *f)
182 return f->magic_and_prev & ((1ULL << (64 - TDB_OFF_UPPER_STEAL)) - 1);
185 static inline uint64_t frec_magic(const struct tdb_free_record *f)
187 return f->magic_and_prev >> (64 - TDB_OFF_UPPER_STEAL);
190 static inline uint64_t frec_len(const struct tdb_free_record *f)
192 return f->ftable_and_len & ((1ULL << (64 - TDB_OFF_UPPER_STEAL))-1);
195 static inline unsigned frec_ftable(const struct tdb_free_record *f)
197 return f->ftable_and_len >> (64 - TDB_OFF_UPPER_STEAL);
200 struct tdb_recovery_record {
202 /* Length of record (add this header to get total length). */
206 /* Old length of file before transaction. */
210 /* If we bottom out of the subhashes, we chain. */
212 tdb_off_t rec[1 << TDB_HASH_GROUP_BITS];
216 /* this is stored at the front of every database */
218 char magic_food[64]; /* for /etc/magic */
219 /* FIXME: Make me 32 bit? */
220 uint64_t version; /* version of the code */
221 uint64_t hash_test; /* result of hashing HASH_MAGIC. */
222 uint64_t hash_seed; /* "random" seed written at creation time. */
223 tdb_off_t free_table; /* (First) free table. */
224 tdb_off_t recovery; /* Transaction recovery area. */
226 uint64_t features_used; /* Features all writers understand */
227 uint64_t features_offered; /* Features offered */
229 uint64_t seqnum; /* Sequence number for TDB_SEQNUM */
231 tdb_off_t reserved[23];
233 /* Top level hash table. */
234 tdb_off_t hashtable[1ULL << TDB_TOPLEVEL_HASH_BITS];
237 struct tdb_freetable {
238 struct tdb_used_record hdr;
240 tdb_off_t buckets[TDB_FREE_BUCKETS];
243 /* Information about a particular (locked) hash entry. */
245 /* Full hash value of entry. */
247 /* Start and length of lock acquired. */
248 tdb_off_t hlock_start;
249 tdb_len_t hlock_range;
250 /* Start of hash group. */
251 tdb_off_t group_start;
252 /* Bucket we belong in. */
253 unsigned int home_bucket;
254 /* Bucket we (or an empty space) were found in. */
255 unsigned int found_bucket;
256 /* How many bits of the hash are already used. */
257 unsigned int hash_used;
258 /* Current working group. */
259 tdb_off_t group[1 << TDB_HASH_GROUP_BITS];
262 struct traverse_info {
263 struct traverse_level {
265 /* We ignore groups here, and treat it as a big array. */
267 unsigned int total_buckets;
268 } levels[TDB_MAX_LEVELS + 1];
269 unsigned int num_levels;
270 unsigned int toplevel_group;
271 /* This makes delete-everything-inside-traverse work as expected. */
275 typedef uint32_t tdb1_len_t;
276 typedef uint32_t tdb1_off_t;
278 enum tdb_lock_flags {
279 /* WAIT == F_SETLKW, NOWAIT == F_SETLK */
282 /* If set, don't log an error on failure. */
284 /* If set, don't check for recovery (used by recovery code). */
285 TDB_LOCK_NOCHECK = 4,
289 struct tdb_context *owner;
295 /* This is only needed for tdb_access_commit, but used everywhere to
297 struct tdb_access_hdr {
298 struct tdb_access_hdr *next;
305 /* How many are sharing us? */
308 /* Mmap (if any), or malloc (for TDB_INTERNAL). */
311 /* How much space has been mapped (<= current file size) */
314 /* The file descriptor (-1 for TDB_INTERNAL). */
317 /* Lock information */
319 struct tdb_lock allrecord_lock;
321 struct tdb_lock *lockrecs;
323 /* Identity of this file. */
329 enum TDB_ERROR (*tread)(struct tdb_context *, tdb_off_t, void *,
331 enum TDB_ERROR (*twrite)(struct tdb_context *, tdb_off_t, const void *,
333 enum TDB_ERROR (*oob)(struct tdb_context *, tdb_off_t, bool);
334 enum TDB_ERROR (*expand_file)(struct tdb_context *, tdb_len_t);
335 void *(*direct)(struct tdb_context *, tdb_off_t, size_t, bool);
342 uint64_t tdb_jenkins_hash(const void *key, size_t length, uint64_t seed,
345 tdb_bool_err first_in_hash(struct tdb_context *tdb,
346 struct traverse_info *tinfo,
347 TDB_DATA *kbuf, size_t *dlen);
349 tdb_bool_err next_in_hash(struct tdb_context *tdb,
350 struct traverse_info *tinfo,
351 TDB_DATA *kbuf, size_t *dlen);
353 /* Hash random memory. */
354 uint64_t tdb_hash(struct tdb_context *tdb, const void *ptr, size_t len);
357 uint64_t hash_record(struct tdb_context *tdb, tdb_off_t off);
359 /* Find and lock a hash entry (or where it would be). */
360 tdb_off_t find_and_lock(struct tdb_context *tdb,
364 struct tdb_used_record *rec,
365 struct traverse_info *tinfo);
367 enum TDB_ERROR replace_in_hash(struct tdb_context *tdb,
371 enum TDB_ERROR add_to_hash(struct tdb_context *tdb, struct hash_info *h,
374 enum TDB_ERROR delete_from_hash(struct tdb_context *tdb, struct hash_info *h);
377 bool is_subhash(tdb_off_t val);
380 enum TDB_ERROR tdb_ftable_init(struct tdb_context *tdb);
382 /* check.c needs these to iterate through free lists. */
383 tdb_off_t first_ftable(struct tdb_context *tdb);
384 tdb_off_t next_ftable(struct tdb_context *tdb, tdb_off_t ftable);
386 /* This returns space or -ve error number. */
387 tdb_off_t alloc(struct tdb_context *tdb, size_t keylen, size_t datalen,
388 uint64_t hash, unsigned magic, bool growing);
390 /* Put this record in a free list. */
391 enum TDB_ERROR add_free_record(struct tdb_context *tdb,
392 tdb_off_t off, tdb_len_t len_with_header,
393 enum tdb_lock_flags waitflag,
396 /* Set up header for a used/ftable/htable/chain record. */
397 enum TDB_ERROR set_header(struct tdb_context *tdb,
398 struct tdb_used_record *rec,
399 unsigned magic, uint64_t keylen, uint64_t datalen,
400 uint64_t actuallen, unsigned hashlow);
402 /* Used by tdb_check to verify. */
403 unsigned int size_to_bucket(tdb_len_t data_len);
404 tdb_off_t bucket_off(tdb_off_t ftable_off, unsigned bucket);
406 /* Used by tdb_summary */
407 tdb_off_t dead_space(struct tdb_context *tdb, tdb_off_t off);
410 /* Initialize tdb->methods. */
411 void tdb_io_init(struct tdb_context *tdb);
413 /* Convert endian of the buffer if required. */
414 void *tdb_convert(const struct tdb_context *tdb, void *buf, tdb_len_t size);
416 /* Unmap and try to map the tdb. */
417 void tdb_munmap(struct tdb_file *file);
418 void tdb_mmap(struct tdb_context *tdb);
420 /* Either alloc a copy, or give direct access. Release frees or noop. */
421 const void *tdb_access_read(struct tdb_context *tdb,
422 tdb_off_t off, tdb_len_t len, bool convert);
423 void *tdb_access_write(struct tdb_context *tdb,
424 tdb_off_t off, tdb_len_t len, bool convert);
426 /* Release result of tdb_access_read/write. */
427 void tdb_access_release(struct tdb_context *tdb, const void *p);
428 /* Commit result of tdb_acces_write. */
429 enum TDB_ERROR tdb_access_commit(struct tdb_context *tdb, void *p);
431 /* Convenience routine to get an offset. */
432 tdb_off_t tdb_read_off(struct tdb_context *tdb, tdb_off_t off);
434 /* Write an offset at an offset. */
435 enum TDB_ERROR tdb_write_off(struct tdb_context *tdb, tdb_off_t off,
438 /* Clear an ondisk area. */
439 enum TDB_ERROR zero_out(struct tdb_context *tdb, tdb_off_t off, tdb_len_t len);
441 /* Return a non-zero offset between >= start < end in this array (or end). */
442 tdb_off_t tdb_find_nonzero_off(struct tdb_context *tdb,
447 /* Return a zero offset in this array, or num. */
448 tdb_off_t tdb_find_zero_off(struct tdb_context *tdb, tdb_off_t off,
451 /* Allocate and make a copy of some offset. */
452 void *tdb_alloc_read(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t len);
454 /* Writes a converted copy of a record. */
455 enum TDB_ERROR tdb_write_convert(struct tdb_context *tdb, tdb_off_t off,
456 const void *rec, size_t len);
458 /* Reads record and converts it */
459 enum TDB_ERROR tdb_read_convert(struct tdb_context *tdb, tdb_off_t off,
460 void *rec, size_t len);
462 /* Bump the seqnum (caller checks for tdb->flags & TDB_SEQNUM) */
463 void tdb_inc_seqnum(struct tdb_context *tdb);
466 /* Lock/unlock a range of hashes. */
467 enum TDB_ERROR tdb_lock_hashes(struct tdb_context *tdb,
468 tdb_off_t hash_lock, tdb_len_t hash_range,
469 int ltype, enum tdb_lock_flags waitflag);
470 enum TDB_ERROR tdb_unlock_hashes(struct tdb_context *tdb,
472 tdb_len_t hash_range, int ltype);
474 /* For closing the file. */
475 void tdb_lock_cleanup(struct tdb_context *tdb);
477 /* Lock/unlock a particular free bucket. */
478 enum TDB_ERROR tdb_lock_free_bucket(struct tdb_context *tdb, tdb_off_t b_off,
479 enum tdb_lock_flags waitflag);
480 void tdb_unlock_free_bucket(struct tdb_context *tdb, tdb_off_t b_off);
482 /* Serialize transaction start. */
483 enum TDB_ERROR tdb_transaction_lock(struct tdb_context *tdb, int ltype);
484 void tdb_transaction_unlock(struct tdb_context *tdb, int ltype);
486 /* Do we have any hash locks (ie. via tdb_chainlock) ? */
487 bool tdb_has_hash_locks(struct tdb_context *tdb);
489 /* Lock entire database. */
490 enum TDB_ERROR tdb_allrecord_lock(struct tdb_context *tdb, int ltype,
491 enum tdb_lock_flags flags, bool upgradable);
492 void tdb_allrecord_unlock(struct tdb_context *tdb, int ltype);
493 enum TDB_ERROR tdb_allrecord_upgrade(struct tdb_context *tdb, off_t start);
495 /* Serialize db open. */
496 enum TDB_ERROR tdb_lock_open(struct tdb_context *tdb,
497 int ltype, enum tdb_lock_flags flags);
498 void tdb_unlock_open(struct tdb_context *tdb, int ltype);
499 bool tdb_has_open_lock(struct tdb_context *tdb);
501 /* Serialize db expand. */
502 enum TDB_ERROR tdb_lock_expand(struct tdb_context *tdb, int ltype);
503 void tdb_unlock_expand(struct tdb_context *tdb, int ltype);
504 bool tdb_has_expansion_lock(struct tdb_context *tdb);
506 /* If it needs recovery, grab all the locks and do it. */
507 enum TDB_ERROR tdb_lock_and_recover(struct tdb_context *tdb);
509 /* Byte-range lock wrappers for TDB1 to access. */
510 enum TDB_ERROR tdb_brlock(struct tdb_context *tdb,
511 int rw_type, tdb_off_t offset, tdb_off_t len,
512 enum tdb_lock_flags flags);
514 enum TDB_ERROR tdb_brunlock(struct tdb_context *tdb,
515 int rw_type, tdb_off_t offset, size_t len);
517 enum TDB_ERROR tdb_nest_lock(struct tdb_context *tdb,
518 tdb_off_t offset, int ltype,
519 enum tdb_lock_flags flags);
521 enum TDB_ERROR tdb_nest_unlock(struct tdb_context *tdb,
522 tdb_off_t off, int ltype);
524 enum TDB_ERROR tdb_lock_gradual(struct tdb_context *tdb,
525 int ltype, enum tdb_lock_flags flags,
526 tdb_off_t off, tdb_off_t len);
528 /* Default lock and unlock functions. */
529 int tdb_fcntl_lock(int fd, int rw, off_t off, off_t len, bool waitflag, void *);
530 int tdb_fcntl_unlock(int fd, int rw, off_t off, off_t len, void *);
533 enum TDB_ERROR tdb_transaction_recover(struct tdb_context *tdb);
534 tdb_bool_err tdb_needs_recovery(struct tdb_context *tdb);
536 /* this is stored at the front of every database */
538 char magic_food[32]; /* for /etc/magic */
539 uint32_t version; /* version of the code */
540 uint32_t hash_size; /* number of hash entries */
541 tdb1_off_t rwlocks; /* obsolete - kept to detect old formats */
542 tdb1_off_t recovery_start; /* offset of transaction recovery region */
543 tdb1_off_t sequence_number; /* used when TDB1_SEQNUM is set */
544 uint32_t magic1_hash; /* hash of TDB_MAGIC_FOOD. */
545 uint32_t magic2_hash; /* hash of TDB1_MAGIC. */
546 tdb1_off_t reserved[27];
549 struct tdb1_traverse_lock {
550 struct tdb1_traverse_lock *next;
557 /* Single list of all TDBs, to detect multiple opens. */
558 struct tdb_context *next;
560 /* Filename of the database. */
563 /* Logging function */
564 void (*log_fn)(struct tdb_context *tdb,
565 enum tdb_log_level level,
566 enum TDB_ERROR ecode,
571 /* Open flags passed to tdb_open. */
574 /* low level (fnctl) lock functions. */
575 int (*lock_fn)(int fd, int rw, off_t off, off_t len, bool w, void *);
576 int (*unlock_fn)(int fd, int rw, off_t off, off_t len, void *);
579 /* the tdb flags passed to tdb_open. */
582 /* Our statistics. */
583 struct tdb_attribute_stats stats;
585 /* The actual file information */
586 struct tdb_file *file;
589 uint64_t (*hash_fn)(const void *key, size_t len, uint64_t seed, void *);
593 /* Our open hook, if any. */
594 enum TDB_ERROR (*openhook)(int fd, void *data);
597 /* Last error we returned. */
598 enum TDB_ERROR last_error;
602 /* Are we accessing directly? (debugging check). */
605 /* Set if we are in a transaction. */
606 struct tdb_transaction *transaction;
608 /* What free table are we using? */
609 tdb_off_t ftable_off;
612 /* IO methods: changes for transactions. */
613 const struct tdb_methods *io;
615 /* Direct access information */
616 struct tdb_access_hdr *access;
620 int traverse_read; /* read-only traversal */
621 int traverse_write; /* read-write traversal */
623 struct tdb1_header header; /* a cached copy of the header */
624 struct tdb1_traverse_lock travlocks; /* current traversal locks */
625 const struct tdb1_methods *io;
626 struct tdb1_transaction *transaction;
628 int max_dead_records;
632 #define TDB1_BYTEREV(x) (((((x)&0xff)<<24)|((x)&0xFF00)<<8)|(((x)>>8)&0xFF00)|((x)>>24))
635 int tdb1_check(struct tdb_context *tdb,
636 enum TDB_ERROR (*check)(TDB_DATA key, TDB_DATA data, void *),
641 int tdb1_new_database(struct tdb_context *tdb,
642 struct tdb_attribute_tdb1_hashsize *hashsize);
643 enum TDB_ERROR tdb1_open(struct tdb_context *tdb);
646 enum TDB_ERROR tdb1_probe_length(struct tdb_context *tdb);
649 int tdb1_allrecord_lock(struct tdb_context *tdb, int ltype,
650 enum tdb_lock_flags flags, bool upgradable);
651 int tdb1_allrecord_unlock(struct tdb_context *tdb, int ltype);
653 int tdb1_chainlock(struct tdb_context *tdb, TDB_DATA key);
654 int tdb1_chainunlock(struct tdb_context *tdb, TDB_DATA key);
655 int tdb1_chainlock_read(struct tdb_context *tdb, TDB_DATA key);
656 int tdb1_chainunlock_read(struct tdb_context *tdb, TDB_DATA key);
658 /* tdb1_transaction.c: */
659 int tdb1_transaction_recover(struct tdb_context *tdb);
660 int tdb1_transaction_cancel(struct tdb_context *tdb);
662 /* tdb1_traverse.c: */
663 int tdb1_traverse(struct tdb_context *tdb,
664 int (*)(struct tdb_context *, TDB_DATA, TDB_DATA, void *),
667 /* tdb1_summary.c: */
668 char *tdb1_summary(struct tdb_context *tdb);
671 int tdb1_store(struct tdb_context *tdb, TDB_DATA key, TDB_DATA dbuf, int flag);
672 enum TDB_ERROR tdb1_fetch(struct tdb_context *tdb, TDB_DATA key,
674 int tdb1_append(struct tdb_context *tdb, TDB_DATA key, TDB_DATA new_dbuf);
675 int tdb1_delete(struct tdb_context *tdb, TDB_DATA key);
676 int tdb1_exists(struct tdb_context *tdb, TDB_DATA key);
677 enum TDB_ERROR tdb1_parse_record(struct tdb_context *tdb, TDB_DATA key,
678 enum TDB_ERROR (*parser)(TDB_DATA key,
682 void tdb1_increment_seqnum_nonblock(struct tdb_context *tdb);
683 int tdb1_get_seqnum(struct tdb_context *tdb);
685 /* tdb1_transaction.c: */
686 int tdb1_transaction_start(struct tdb_context *tdb);
687 int tdb1_transaction_prepare_commit(struct tdb_context *tdb);
688 int tdb1_transaction_commit(struct tdb_context *tdb);
690 /* tdb1_traverse.c: */
691 TDB_DATA tdb1_firstkey(struct tdb_context *tdb);
692 TDB_DATA tdb1_nextkey(struct tdb_context *tdb, TDB_DATA key);
695 enum TDB_ERROR COLD tdb_logerr(struct tdb_context *tdb,
696 enum TDB_ERROR ecode,
697 enum tdb_log_level level,
698 const char *fmt, ...);
701 void tdb_trace(struct tdb_context *tdb, const char *op);
702 void tdb_trace_seqnum(struct tdb_context *tdb, uint32_t seqnum, const char *op);
703 void tdb_trace_open(struct tdb_context *tdb, const char *op,
704 unsigned hash_size, unsigned tdb_flags, unsigned open_flags);
705 void tdb_trace_ret(struct tdb_context *tdb, const char *op, int ret);
706 void tdb_trace_retrec(struct tdb_context *tdb, const char *op, TDB_DATA ret);
707 void tdb_trace_1rec(struct tdb_context *tdb, const char *op,
709 void tdb_trace_1rec_ret(struct tdb_context *tdb, const char *op,
710 TDB_DATA rec, int ret);
711 void tdb_trace_1rec_retrec(struct tdb_context *tdb, const char *op,
712 TDB_DATA rec, TDB_DATA ret);
713 void tdb_trace_2rec_flag_ret(struct tdb_context *tdb, const char *op,
714 TDB_DATA rec1, TDB_DATA rec2, unsigned flag,
716 void tdb_trace_2rec_retrec(struct tdb_context *tdb, const char *op,
717 TDB_DATA rec1, TDB_DATA rec2, TDB_DATA ret);
719 #define tdb_trace(tdb, op)
720 #define tdb_trace_seqnum(tdb, seqnum, op)
721 #define tdb_trace_open(tdb, op, hash_size, tdb_flags, open_flags)
722 #define tdb_trace_ret(tdb, op, ret)
723 #define tdb_trace_retrec(tdb, op, ret)
724 #define tdb_trace_1rec(tdb, op, rec)
725 #define tdb_trace_1rec_ret(tdb, op, rec, ret)
726 #define tdb_trace_1rec_retrec(tdb, op, rec, ret)
727 #define tdb_trace_2rec_flag_ret(tdb, op, rec1, rec2, flag, ret)
728 #define tdb_trace_2rec_retrec(tdb, op, rec1, rec2, ret)
729 #endif /* !TDB_TRACE */