tdb2: simplify logging levels, rename TDB_DEBUG_* to TDB_LOG_*
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 1 Mar 2011 12:49:20 +0000 (23:19 +1030)
It was never clear to me which levels should be used for what cases.
I can only usefully distinguish three at the moment:
(1) TDB errors, which render the TDB unreliable.
(2) TDB user errors, caused by API misuse.
(3) TDB notifications of strange behaviour, from which we have recovered.

15 files changed:
ccan/tdb2/check.c
ccan/tdb2/free.c
ccan/tdb2/hash.c
ccan/tdb2/io.c
ccan/tdb2/lock.c
ccan/tdb2/private.h
ccan/tdb2/summary.c
ccan/tdb2/tdb.c
ccan/tdb2/tdb2.h
ccan/tdb2/test/logging.c
ccan/tdb2/test/logging.h
ccan/tdb2/test/run-01-new_database.c
ccan/tdb2/test/run-seed.c
ccan/tdb2/tools/tdbtorture.c
ccan/tdb2/transaction.c

index 4cd92b43c040a30c40e4e952e05aac5deb0a13e9..41acae4e9de3aa13616fadfdd6e6696c1030849f 100644 (file)
@@ -43,7 +43,7 @@ static bool check_header(struct tdb_context *tdb, tdb_off_t *recovery)
        hash_test = TDB_HASH_MAGIC;
        hash_test = tdb_hash(tdb, &hash_test, sizeof(hash_test));
        if (hdr.hash_test != hash_test) {
-               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                           "check: hash test %llu should be %llu",
                           (long long)hdr.hash_test,
                           (long long)hash_test);
@@ -51,7 +51,7 @@ static bool check_header(struct tdb_context *tdb, tdb_off_t *recovery)
        }
 
        if (strcmp(hdr.magic_food, TDB_MAGIC_FOOD) != 0) {
-               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                           "check: bad magic '%.*s'",
                           (unsigned)sizeof(hdr.magic_food), hdr.magic_food);
                return false;
@@ -60,7 +60,7 @@ static bool check_header(struct tdb_context *tdb, tdb_off_t *recovery)
        *recovery = hdr.recovery;
        if (*recovery) {
                if (*recovery < sizeof(hdr) || *recovery > tdb->map_size) {
-                       tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_ERROR,
+                       tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                                 "tdb_check: invalid recovery offset %zu",
                                 (size_t)*recovery);
                        return false;
@@ -96,27 +96,27 @@ static bool check_hash_chain(struct tdb_context *tdb,
                return false;
 
        if (rec_magic(&rec) != TDB_CHAIN_MAGIC) {
-               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                           "tdb_check: Bad hash chain magic %llu",
                           (long long)rec_magic(&rec));
                return false;
        }
 
        if (rec_data_length(&rec) != sizeof(struct tdb_chain)) {
-               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                           "tdb_check: Bad hash chain length %llu vs %zu",
                           (long long)rec_data_length(&rec),
                           sizeof(struct tdb_chain));
                return false;
        }
        if (rec_key_length(&rec) != 0) {
-               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                         "tdb_check: Bad hash chain key length %llu",
                         (long long)rec_key_length(&rec));
                return false;
        }
        if (rec_hash(&rec) != 0) {
-               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                         "tdb_check: Bad hash chain hash value %llu",
                         (long long)rec_hash(&rec));
                return false;
@@ -157,14 +157,14 @@ static bool check_hash_record(struct tdb_context *tdb,
                return false;
 
        if (rec_magic(&rec) != TDB_HTABLE_MAGIC) {
-               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                           "tdb_check: Bad hash table magic %llu",
                           (long long)rec_magic(&rec));
                return false;
        }
        if (rec_data_length(&rec)
            != sizeof(tdb_off_t) << TDB_SUBLEVEL_HASH_BITS) {
-               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                           "tdb_check: Bad hash table length %llu vs %llu",
                           (long long)rec_data_length(&rec),
                           (long long)sizeof(tdb_off_t)
@@ -172,13 +172,13 @@ static bool check_hash_record(struct tdb_context *tdb,
                return false;
        }
        if (rec_key_length(&rec) != 0) {
-               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                         "tdb_check: Bad hash table key length %llu",
                         (long long)rec_key_length(&rec));
                return false;
        }
        if (rec_hash(&rec) != 0) {
-               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                         "tdb_check: Bad hash table hash value %llu",
                         (long long)rec_hash(&rec));
                return false;
@@ -240,7 +240,7 @@ static bool check_hash_tree(struct tdb_context *tdb,
                        p = asearch(&off, used, num_used, off_cmp);
                        if (!p) {
                                tdb_logerr(tdb, TDB_ERR_CORRUPT,
-                                          TDB_DEBUG_ERROR,
+                                          TDB_LOG_ERROR,
                                           "tdb_check: Invalid offset %llu "
                                           "in hash", (long long)off);
                                goto fail;
@@ -253,7 +253,7 @@ static bool check_hash_tree(struct tdb_context *tdb,
                                /* Chained entries are unordered. */
                                if (is_subhash(group[b])) {
                                        tdb_logerr(tdb, TDB_ERR_CORRUPT,
-                                                  TDB_DEBUG_ERROR,
+                                                  TDB_LOG_ERROR,
                                                   "tdb_check: Invalid chain"
                                                   " entry subhash");
                                        goto fail;
@@ -261,7 +261,7 @@ static bool check_hash_tree(struct tdb_context *tdb,
                                h = hash_record(tdb, off);
                                if (h != hprefix) {
                                        tdb_logerr(tdb, TDB_ERR_CORRUPT,
-                                                  TDB_DEBUG_ERROR,
+                                                  TDB_LOG_ERROR,
                                                   "check: bad hash chain"
                                                   " placement"
                                                   " 0x%llx vs 0x%llx",
@@ -300,7 +300,7 @@ static bool check_hash_tree(struct tdb_context *tdb,
                        if (get_bits(h, hprefix_bits, &used_bits) != hprefix
                            && hprefix_bits) {
                                tdb_logerr(tdb, TDB_ERR_CORRUPT,
-                                          TDB_DEBUG_ERROR,
+                                          TDB_LOG_ERROR,
                                           "check: bad hash placement"
                                           " 0x%llx vs 0x%llx",
                                         (long long)h, (long long)hprefix);
@@ -310,7 +310,7 @@ static bool check_hash_tree(struct tdb_context *tdb,
                        /* Does it belong in this group? */
                        if (get_bits(h, group_bits, &used_bits) != g) {
                                tdb_logerr(tdb, TDB_ERR_CORRUPT,
-                                          TDB_DEBUG_ERROR,
+                                          TDB_LOG_ERROR,
                                           "check: bad group %llu vs %u",
                                           (long long)h, g);
                                goto fail;
@@ -322,7 +322,7 @@ static bool check_hash_tree(struct tdb_context *tdb,
                            != bucket) {
                                used_bits -= TDB_HASH_GROUP_BITS;
                                tdb_logerr(tdb, TDB_ERR_CORRUPT,
-                                          TDB_DEBUG_ERROR,
+                                          TDB_LOG_ERROR,
                                         "check: bad bucket %u vs %u",
                                         (unsigned)get_bits(h,
                                                        TDB_HASH_GROUP_BITS,
@@ -338,7 +338,7 @@ static bool check_hash_tree(struct tdb_context *tdb,
                             i = (i + 1) % (1 << TDB_HASH_GROUP_BITS)) {
                                if (group[i] == 0) {
                                        tdb_logerr(tdb, TDB_ERR_CORRUPT,
-                                                  TDB_DEBUG_ERROR,
+                                                  TDB_LOG_ERROR,
                                                   "check: bad group placement"
                                                   " %u vs %u",
                                                   b, bucket);
@@ -352,7 +352,7 @@ static bool check_hash_tree(struct tdb_context *tdb,
                        /* Bottom bits must match header. */
                        if ((h & ((1 << 11)-1)) != rec_hash(&rec)) {
                                tdb_logerr(tdb, TDB_ERR_CORRUPT,
-                                          TDB_DEBUG_ERROR,
+                                          TDB_LOG_ERROR,
                                           "tdb_check: Bad hash magic at"
                                           " offset %llu (0x%llx vs 0x%llx)",
                                           (long long)off,
@@ -403,7 +403,7 @@ static bool check_hash(struct tdb_context *tdb,
                return false;
 
        if (num_found != num_used) {
-               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                           "tdb_check: Not all entries are in hash");
                return false;
        }
@@ -417,13 +417,13 @@ static bool check_free(struct tdb_context *tdb,
                       unsigned int bucket)
 {
        if (frec_magic(frec) != TDB_FREE_MAGIC) {
-               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                           "tdb_check: offset %llu bad magic 0x%llx",
                           (long long)off, (long long)frec->magic_and_prev);
                return false;
        }
        if (frec_ftable(frec) != ftable) {
-               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                           "tdb_check: offset %llu bad freetable %u",
                           (long long)off, frec_ftable(frec));
                return false;
@@ -434,14 +434,14 @@ static bool check_free(struct tdb_context *tdb,
                              false))
                return false;
        if (size_to_bucket(frec_len(frec)) != bucket) {
-               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                           "tdb_check: offset %llu in wrong bucket %u vs %u",
                           (long long)off,
                           bucket, size_to_bucket(frec_len(frec)));
                return false;
        }
        if (prev != frec_prev(frec)) {
-               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                           "tdb_check: offset %llu bad prev %llu vs %llu",
                           (long long)off,
                           (long long)prev, (long long)frec_len(frec));
@@ -468,7 +468,7 @@ static bool check_free_table(struct tdb_context *tdb,
            || rec_key_length(&ft.hdr) != 0
            || rec_data_length(&ft.hdr) != sizeof(ft) - sizeof(ft.hdr)
            || rec_hash(&ft.hdr) != 0) {
-               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                           "tdb_check: Invalid header on free table");
                return false;
        }
@@ -490,7 +490,7 @@ static bool check_free_table(struct tdb_context *tdb,
                        p = asearch(&off, fr, num_free, off_cmp);
                        if (!p) {
                                tdb_logerr(tdb, TDB_ERR_CORRUPT,
-                                          TDB_DEBUG_ERROR,
+                                          TDB_LOG_ERROR,
                                           "tdb_check: Invalid offset"
                                           " %llu in free table",
                                           (long long)off);
@@ -552,14 +552,14 @@ static bool check_linear(struct tdb_context *tdb,
                                len = dead_space(tdb, off);
                                if (len < sizeof(rec.r)) {
                                        tdb_logerr(tdb, TDB_ERR_CORRUPT,
-                                                  TDB_DEBUG_ERROR,
+                                                  TDB_LOG_ERROR,
                                                   "tdb_check: invalid dead"
                                                   " space at %zu",
                                                   (size_t)off);
                                        return false;
                                }
 
-                               tdb_logerr(tdb, TDB_SUCCESS, TDB_DEBUG_WARNING,
+                               tdb_logerr(tdb, TDB_SUCCESS, TDB_LOG_WARNING,
                                           "Dead space at %zu-%zu (of %zu)",
                                           (size_t)off, (size_t)(off + len),
                                           (size_t)tdb->map_size);
@@ -569,7 +569,7 @@ static bool check_linear(struct tdb_context *tdb,
                                return false;
                        if (recovery != off) {
                                tdb_logerr(tdb, TDB_ERR_CORRUPT,
-                                          TDB_DEBUG_ERROR,
+                                          TDB_LOG_ERROR,
                                           "tdb_check: unexpected recovery"
                                           " record at offset %zu",
                                           (size_t)off);
@@ -577,14 +577,14 @@ static bool check_linear(struct tdb_context *tdb,
                        }
                        if (rec.r.len > rec.r.max_len) {
                                tdb_logerr(tdb, TDB_ERR_CORRUPT,
-                                          TDB_DEBUG_ERROR,
+                                          TDB_LOG_ERROR,
                                           "tdb_check: invalid recovery length"
                                           " %zu", (size_t)rec.r.len);
                                return false;
                        }
                        if (rec.r.eof > tdb->map_size) {
                                tdb_logerr(tdb, TDB_ERR_CORRUPT,
-                                          TDB_DEBUG_ERROR,
+                                          TDB_LOG_ERROR,
                                           "tdb_check: invalid old EOF"
                                           " %zu", (size_t)rec.r.eof);
                                return false;
@@ -595,7 +595,7 @@ static bool check_linear(struct tdb_context *tdb,
                        len = sizeof(rec.u) + frec_len(&rec.f);
                        if (off + len > tdb->map_size) {
                                tdb_logerr(tdb, TDB_ERR_CORRUPT,
-                                          TDB_DEBUG_ERROR,
+                                          TDB_LOG_ERROR,
                                           "tdb_check: free overlength %llu"
                                           " at offset %llu",
                                           (long long)len, (long long)off);
@@ -605,7 +605,7 @@ static bool check_linear(struct tdb_context *tdb,
                        if (frec_ftable(&rec.f) != TDB_FTABLE_NONE
                            && !append(fr, num_free, off)) {
                                tdb_logerr(tdb, TDB_ERR_OOM,
-                                          TDB_DEBUG_ERROR,
+                                          TDB_LOG_ERROR,
                                           "tdb_check: tracking %zu'th"
                                           " free record.", *num_free);
                                return false;
@@ -619,7 +619,7 @@ static bool check_linear(struct tdb_context *tdb,
                        /* This record is used! */
                        if (!append(used, num_used, off)) {
                                tdb_logerr(tdb, TDB_ERR_OOM,
-                                          TDB_DEBUG_ERROR,
+                                          TDB_LOG_ERROR,
                                           "tdb_check: tracking %zu'th"
                                           " used record.", *num_used);
                                return false;
@@ -632,7 +632,7 @@ static bool check_linear(struct tdb_context *tdb,
                        len = sizeof(rec.u) + klen + dlen + extra;
                        if (off + len > tdb->map_size) {
                                tdb_logerr(tdb, TDB_ERR_CORRUPT,
-                                          TDB_DEBUG_ERROR,
+                                          TDB_LOG_ERROR,
                                           "tdb_check: used overlength %llu"
                                           " at offset %llu",
                                           (long long)len, (long long)off);
@@ -641,7 +641,7 @@ static bool check_linear(struct tdb_context *tdb,
 
                        if (len < sizeof(rec.f)) {
                                tdb_logerr(tdb, TDB_ERR_CORRUPT,
-                                          TDB_DEBUG_ERROR,
+                                          TDB_LOG_ERROR,
                                           "tdb_check: too short record %llu"
                                           " at %llu",
                                           (long long)len, (long long)off);
@@ -649,7 +649,7 @@ static bool check_linear(struct tdb_context *tdb,
                        }
                } else {
                        tdb_logerr(tdb, TDB_ERR_CORRUPT,
-                                  TDB_DEBUG_ERROR,
+                                  TDB_LOG_ERROR,
                                   "tdb_check: Bad magic 0x%llx at offset %zu",
                                   (long long)rec_magic(&rec.u), (size_t)off);
                        return false;
@@ -658,7 +658,7 @@ static bool check_linear(struct tdb_context *tdb,
 
        /* We must have found recovery area if there was one. */
        if (recovery != 0 && !found_recovery) {
-               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                           "tdb_check: expected a recovery area at %zu",
                           (size_t)recovery);
                return false;
@@ -703,7 +703,7 @@ int tdb_check(struct tdb_context *tdb,
                goto fail;
 
        if (num_found != num_free) {
-               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                           "tdb_check: Not all entries are in free table");
                return -1;
        }
index 4930400d50f7cabd560d5b31461b6485bea0ab8a..70a7b6703434b32af5aee81f82db5f439255d0e0 100644 (file)
@@ -118,7 +118,7 @@ static int remove_from_list(struct tdb_context *tdb,
 
 #ifdef CCAN_TDB2_DEBUG
        if (tdb_read_off(tdb, off) != r_off) {
-               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                         "remove_from_list: %llu bad prev in list %llu",
                         (long long)r_off, (long long)b_off);
                return -1;
@@ -136,7 +136,7 @@ static int remove_from_list(struct tdb_context *tdb,
 
 #ifdef CCAN_TDB2_DEBUG
                if (tdb_read_off(tdb, off) & TDB_OFF_MASK != r_off) {
-                       tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                                   "remove_from_list: %llu bad list %llu",
                                   (long long)r_off, (long long)b_off);
                        return -1;
@@ -176,7 +176,7 @@ static int enqueue_in_free(struct tdb_context *tdb,
                                 new.next + offsetof(struct tdb_free_record,
                                                     magic_and_prev))
                    != magic) {
-                       tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                                   "enqueue_in_free: %llu bad head"
                                   " prev %llu",
                                   (long long)new.next, (long long)b_off);
@@ -333,7 +333,7 @@ static int coalesce(struct tdb_context *tdb,
                goto err;
 
        if (frec_len(&rec) != data_len) {
-               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                           "coalesce: expected data len %zu not %zu",
                           (size_t)data_len, (size_t)frec_len(&rec));
                goto err;
@@ -414,7 +414,7 @@ again:
 
                if (frec_magic(r) != TDB_FREE_MAGIC) {
                        tdb_access_release(tdb, r);
-                       tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                                 "lock_and_alloc: %llu non-free 0x%llx",
                                 (long long)off, (long long)r->magic_and_prev);
                        goto unlock_err;
@@ -567,7 +567,7 @@ int set_header(struct tdb_context *tdb,
        if (rec_key_length(rec) != keylen
            || rec_data_length(rec) != datalen
            || rec_extra_padding(rec) != actuallen - (keylen + datalen)) {
-               tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
                         "Could not encode k=%llu,d=%llu,a=%llu",
                         (long long)keylen, (long long)datalen,
                         (long long)actuallen);
@@ -588,7 +588,7 @@ static int tdb_expand(struct tdb_context *tdb, tdb_len_t size)
        /* Need to hold a hash lock to expand DB: transactions rely on it. */
        if (!(tdb->flags & TDB_NOLOCK)
            && !tdb->allrecord_lock.count && !tdb_has_hash_locks(tdb)) {
-               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR,
                           "tdb_expand: must hold lock during expand");
                return -1;
        }
index d242d531780d1d41b7e330b0abfcf894012c82de..17601c0c8bf3fc2bf3ed2496735c3dc725e8e7fd 100644 (file)
@@ -704,7 +704,7 @@ int next_in_hash(struct tdb_context *tdb, int ltype,
                        }
                        if (rec_magic(&rec) != TDB_USED_MAGIC) {
                                tdb_logerr(tdb, TDB_ERR_CORRUPT,
-                                          TDB_DEBUG_FATAL,
+                                          TDB_LOG_ERROR,
                                           "next_in_hash:"
                                           " corrupt record at %llu",
                                           (long long)off);
index 7fc268ea551bc8dcaed8cc05a3c04999e09a9cfb..3c24be6774a3f0a4b841809e5a20a9cfe7f417da 100644 (file)
@@ -56,7 +56,7 @@ void tdb_mmap(struct tdb_context *tdb)
         */
        if (tdb->map_ptr == MAP_FAILED) {
                tdb->map_ptr = NULL;
-               tdb_logerr(tdb, TDB_SUCCESS, TDB_DEBUG_WARNING,
+               tdb_logerr(tdb, TDB_SUCCESS, TDB_LOG_WARNING,
                           "tdb_mmap failed for size %lld (%s)",
                           (long long)tdb->map_size, strerror(errno));
        }
@@ -80,7 +80,7 @@ static int tdb_oob(struct tdb_context *tdb, tdb_off_t len, bool probe)
                return 0;
        if (tdb->flags & TDB_INTERNAL) {
                if (!probe) {
-                       tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
                                 "tdb_oob len %lld beyond internal"
                                 " malloc size %lld",
                                 (long long)len,
@@ -93,7 +93,7 @@ static int tdb_oob(struct tdb_context *tdb, tdb_off_t len, bool probe)
                return -1;
 
        if (fstat(tdb->fd, &st) != 0) {
-               tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
                           "Failed to fstat file: %s", strerror(errno));
                tdb_unlock_expand(tdb, F_RDLCK);
                return -1;
@@ -103,7 +103,7 @@ static int tdb_oob(struct tdb_context *tdb, tdb_off_t len, bool probe)
 
        if (st.st_size < (size_t)len) {
                if (!probe) {
-                       tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
                                   "tdb_oob len %zu beyond eof at %zu",
                                   (size_t)len, st.st_size);
                }
@@ -211,7 +211,7 @@ static int tdb_write(struct tdb_context *tdb, tdb_off_t off,
                     const void *buf, tdb_len_t len)
 {
        if (tdb->read_only) {
-               tdb_logerr(tdb, TDB_ERR_RDONLY, TDB_DEBUG_WARNING,
+               tdb_logerr(tdb, TDB_ERR_RDONLY, TDB_LOG_USE_ERROR,
                           "Write to read-only database");
                return -1;
        }
@@ -234,7 +234,7 @@ static int tdb_write(struct tdb_context *tdb, tdb_off_t off,
                        if (ret >= 0)
                                errno = ENOSPC;
 
-                       tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
                                   "tdb_write: %zi at %zu len=%zu (%s)",
                                   ret, (size_t)off, (size_t)len,
                                   strerror(errno));
@@ -257,7 +257,7 @@ static int tdb_read(struct tdb_context *tdb, tdb_off_t off, void *buf,
        } else {
                ssize_t r = pread(tdb->fd, buf, len, off);
                if (r != len) {
-                       tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
                                   "tdb_read failed with %zi at %zu "
                                   "len=%zu (%s) map_size=%zu",
                                   r, (size_t)off, (size_t)len,
@@ -276,7 +276,7 @@ int tdb_write_convert(struct tdb_context *tdb, tdb_off_t off,
        if (unlikely((tdb->flags & TDB_CONVERT))) {
                void *conv = malloc(len);
                if (!conv) {
-                       tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
                                   "tdb_write: no memory converting"
                                   " %zu bytes", len);
                        return -1;
@@ -302,7 +302,7 @@ int tdb_read_convert(struct tdb_context *tdb, tdb_off_t off,
 int tdb_write_off(struct tdb_context *tdb, tdb_off_t off, tdb_off_t val)
 {
        if (tdb->read_only) {
-               tdb_logerr(tdb, TDB_ERR_RDONLY, TDB_DEBUG_WARNING,
+               tdb_logerr(tdb, TDB_ERR_RDONLY, TDB_LOG_USE_ERROR,
                           "Write to read-only database");
                return -1;
        }
@@ -326,7 +326,7 @@ static void *_tdb_alloc_read(struct tdb_context *tdb, tdb_off_t offset,
        /* some systems don't like zero length malloc */
        buf = malloc(prefix + len ? prefix + len : 1);
        if (!buf) {
-               tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_USE_ERROR,
                           "tdb_alloc_read malloc failed len=%zu",
                           (size_t)(prefix + len));
        } else if (unlikely(tdb->methods->tread(tdb, offset, buf+prefix, len)
@@ -354,7 +354,7 @@ static int fill(struct tdb_context *tdb,
                        if (ret >= 0)
                                errno = ENOSPC;
 
-                       tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
                                   "fill failed: %zi at %zu len=%zu (%s)",
                                   ret, (size_t)off, (size_t)len,
                                   strerror(errno));
@@ -373,7 +373,7 @@ static int tdb_expand_file(struct tdb_context *tdb, tdb_len_t addition)
        char buf[8192];
 
        if (tdb->read_only) {
-               tdb_logerr(tdb, TDB_ERR_RDONLY, TDB_DEBUG_WARNING,
+               tdb_logerr(tdb, TDB_ERR_RDONLY, TDB_LOG_USE_ERROR,
                           "Expand on read-only database");
                return -1;
        }
@@ -381,7 +381,7 @@ static int tdb_expand_file(struct tdb_context *tdb, tdb_len_t addition)
        if (tdb->flags & TDB_INTERNAL) {
                char *new = realloc(tdb->map_ptr, tdb->map_size + addition);
                if (!new) {
-                       tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
                                   "No memory to expand database");
                        return -1;
                }
@@ -438,7 +438,7 @@ void *tdb_access_write(struct tdb_context *tdb,
        void *ret = NULL;
 
        if (tdb->read_only) {
-               tdb_logerr(tdb, TDB_ERR_RDONLY, TDB_DEBUG_WARNING,
+               tdb_logerr(tdb, TDB_ERR_RDONLY, TDB_LOG_USE_ERROR,
                           "Write to read-only database");
                return NULL;
        }
index 476b98f3f7ba0d9318edeedafc01ab717f6fe594..5984984b346da0a2bbbca05e0b2164d6b39d9e7e 100644 (file)
@@ -135,7 +135,7 @@ static int tdb_brlock(struct tdb_context *tdb,
        }
 
        if (rw_type == F_WRLCK && tdb->read_only) {
-               tdb_logerr(tdb, TDB_ERR_RDONLY, TDB_DEBUG_WARNING,
+               tdb_logerr(tdb, TDB_ERR_RDONLY, TDB_LOG_USE_ERROR,
                           "Write lock attempted on read-only database");
                return -1;
        }
@@ -143,7 +143,7 @@ static int tdb_brlock(struct tdb_context *tdb,
        /* A 32 bit system cannot open a 64-bit file, but it could have
         * expanded since then: check here. */
        if ((size_t)(offset + len) != offset + len) {
-               tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
                         "tdb_brlock: lock on giant offset %llu",
                         (long long)(offset + len));
                return -1;
@@ -160,7 +160,7 @@ static int tdb_brlock(struct tdb_context *tdb,
                 * EAGAIN is an expected return from non-blocking
                 * locks. */
                if (!(flags & TDB_LOCK_PROBE) && errno != EAGAIN) {
-                       tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_ERROR,
+                       tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR,
                                   "tdb_brlock failed (fd=%d) at"
                                   " offset %zu rw_type=%d flags=%d len=%zu:"
                                   " %s",
@@ -186,7 +186,7 @@ static int tdb_brunlock(struct tdb_context *tdb,
        } while (ret == -1 && errno == EINTR);
 
        if (ret == -1) {
-               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR,
                           "tdb_brunlock failed (fd=%d) at offset %zu"
                           " rw_type=%d len=%zu",
                           tdb->fd, (size_t)offset, rw_type, (size_t)len);
@@ -205,14 +205,14 @@ int tdb_allrecord_upgrade(struct tdb_context *tdb)
        int count = 1000;
 
        if (tdb->allrecord_lock.count != 1) {
-               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR,
                           "tdb_allrecord_upgrade failed: count %u too high",
                           tdb->allrecord_lock.count);
                return -1;
        }
 
        if (tdb->allrecord_lock.off != 1) {
-               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR,
                           "tdb_allrecord_upgrade failed: already upgraded?");
                return -1;
        }
@@ -234,7 +234,7 @@ int tdb_allrecord_upgrade(struct tdb_context *tdb)
                tv.tv_usec = 1;
                select(0, NULL, NULL, NULL, &tv);
        }
-       tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_ERROR,
+       tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR,
                   "tdb_allrecord_upgrade failed");
        return -1;
 }
@@ -280,7 +280,7 @@ static int tdb_nest_lock(struct tdb_context *tdb, tdb_off_t offset, int ltype,
        struct tdb_lock_type *new_lck;
 
        if (offset > TDB_HASH_LOCK_START + TDB_HASH_LOCK_RANGE + tdb->map_size / 8) {
-               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR,
                           "tdb_nest_lock: invalid offset %zu ltype=%d",
                           (size_t)offset, ltype);
                return -1;
@@ -294,7 +294,7 @@ static int tdb_nest_lock(struct tdb_context *tdb, tdb_off_t offset, int ltype,
        new_lck = find_nestlock(tdb, offset);
        if (new_lck) {
                if (new_lck->ltype == F_RDLCK && ltype == F_WRLCK) {
-                       tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR,
                                   "tdb_nest_lock: offset %zu has read lock",
                                   (size_t)offset);
                        return -1;
@@ -307,7 +307,7 @@ static int tdb_nest_lock(struct tdb_context *tdb, tdb_off_t offset, int ltype,
        if (tdb->num_lockrecs
            && offset >= TDB_HASH_LOCK_START
            && offset < TDB_HASH_LOCK_START + TDB_HASH_LOCK_RANGE) {
-               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR,
                           "tdb_nest_lock: already have a hash lock?");
                return -1;
        }
@@ -316,7 +316,7 @@ static int tdb_nest_lock(struct tdb_context *tdb, tdb_off_t offset, int ltype,
                tdb->lockrecs,
                sizeof(*tdb->lockrecs) * (tdb->num_lockrecs+1));
        if (new_lck == NULL) {
-               tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
                         "tdb_nest_lock: unable to allocate %zu lock struct",
                         tdb->num_lockrecs + 1);
                errno = ENOMEM;
@@ -363,7 +363,7 @@ static int tdb_nest_unlock(struct tdb_context *tdb, tdb_off_t off, int ltype)
 
        lck = find_nestlock(tdb, off);
        if ((lck == NULL) || (lck->count == 0)) {
-               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR,
                           "tdb_nest_unlock: no lock for %zu", (size_t)off);
                return -1;
        }
@@ -449,7 +449,7 @@ int tdb_allrecord_lock(struct tdb_context *tdb, int ltype,
 {
        /* FIXME: There are no locks on read-only dbs */
        if (tdb->read_only) {
-               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_USE_ERROR,
                           "tdb_allrecord_lock: read-only");
                return -1;
        }
@@ -462,7 +462,7 @@ int tdb_allrecord_lock(struct tdb_context *tdb, int ltype,
 
        if (tdb->allrecord_lock.count) {
                /* a global lock of a different type exists */
-               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_USE_ERROR,
                           "tdb_allrecord_lock: already have %s lock",
                           tdb->allrecord_lock.ltype == F_RDLCK
                           ? "read" : "write");
@@ -471,14 +471,14 @@ int tdb_allrecord_lock(struct tdb_context *tdb, int ltype,
 
        if (tdb_has_hash_locks(tdb)) {
                /* can't combine global and chain locks */
-               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_USE_ERROR,
                         "tdb_allrecord_lock: already have chain lock");
                return -1;
        }
 
        if (upgradable && ltype != F_RDLCK) {
                /* tdb error: you can't upgrade a write lock! */
-               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR,
                           "tdb_allrecord_lock: can't upgrade a write lock");
                return -1;
        }
@@ -489,7 +489,7 @@ again:
        if (tdb_lock_gradual(tdb, ltype, flags, TDB_HASH_LOCK_START,
                             TDB_HASH_LOCK_RANGE)) {
                if (!(flags & TDB_LOCK_PROBE)) {
-                       tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_ERROR,
+                       tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                                   "tdb_allrecord_lock hashes failed");
                }
                return -1;
@@ -499,7 +499,7 @@ again:
        if (tdb_brlock(tdb, ltype, TDB_HASH_LOCK_START + TDB_HASH_LOCK_RANGE,
                       0, flags)) {
                if (!(flags & TDB_LOCK_PROBE)) {
-                       tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_ERROR,
+                       tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                                 "tdb_allrecord_lock freetables failed");
                }
                tdb_brunlock(tdb, ltype, TDB_HASH_LOCK_START,
@@ -556,7 +556,7 @@ void tdb_unlock_expand(struct tdb_context *tdb, int ltype)
 int tdb_allrecord_unlock(struct tdb_context *tdb, int ltype)
 {
        if (tdb->allrecord_lock.count == 0) {
-               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_USE_ERROR,
                           "tdb_allrecord_unlock: not locked!");
                return -1;
        }
@@ -564,7 +564,7 @@ int tdb_allrecord_unlock(struct tdb_context *tdb, int ltype)
        /* Upgradable locks are marked as write locks. */
        if (tdb->allrecord_lock.ltype != ltype
            && (!tdb->allrecord_lock.off || ltype != F_RDLCK)) {
-               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR,
                         "tdb_allrecord_unlock: have %s lock",
                           tdb->allrecord_lock.ltype == F_RDLCK
                           ? "read" : "write");
@@ -628,7 +628,7 @@ int tdb_lock_hashes(struct tdb_context *tdb,
        }
 
        if (tdb->allrecord_lock.count) {
-               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_USE_ERROR,
                           "tdb_lock_hashes: already have %s allrecordlock",
                           tdb->allrecord_lock.ltype == F_RDLCK
                           ? "read" : "write");
@@ -636,13 +636,13 @@ int tdb_lock_hashes(struct tdb_context *tdb,
        }
 
        if (tdb_has_free_lock(tdb)) {
-               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR,
                           "tdb_lock_hashes: already have free lock");
                return -1;
        }
 
        if (tdb_has_expansion_lock(tdb)) {
-               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR,
                           "tdb_lock_hashes: already have expansion lock");
                return -1;
        }
@@ -661,7 +661,7 @@ int tdb_unlock_hashes(struct tdb_context *tdb,
        if (tdb->allrecord_lock.count) {
                if (tdb->allrecord_lock.ltype == F_RDLCK
                    && ltype == F_WRLCK) {
-                       tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR,
                                   "tdb_unlock_hashes RO allrecord!");
                        return -1;
                }
@@ -691,14 +691,14 @@ int tdb_lock_free_bucket(struct tdb_context *tdb, tdb_off_t b_off,
        if (tdb->allrecord_lock.count) {
                if (tdb->allrecord_lock.ltype == F_WRLCK)
                        return 0;
-               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR,
                         "tdb_lock_free_bucket with RO allrecordlock!");
                return -1;
        }
 
 #if 0 /* FIXME */
        if (tdb_has_expansion_lock(tdb)) {
-               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_ERROR,
                           "tdb_lock_free_bucket: already have expansion lock");
                return -1;
        }
index c4f8cebd1de4abd354d432a502d0f395479013d8..d32c7546e092d648e4a3a156c54358aaaa30c134 100644 (file)
@@ -331,7 +331,10 @@ struct tdb_context {
        uint32_t flags;
 
        /* Logging function */
-       tdb_logfn_t logfn;
+       void (*logfn)(struct tdb_context *tdb,
+                     enum tdb_log_level level,
+                     void *log_private,
+                     const char *message);
        void *log_private;
 
        /* Hash function. */
@@ -550,7 +553,7 @@ bool tdb_needs_recovery(struct tdb_context *tdb);
 /* tdb.c: */
 void COLD tdb_logerr(struct tdb_context *tdb,
                     enum TDB_ERROR ecode,
-                    enum tdb_debug_level level,
+                    enum tdb_log_level level,
                     const char *fmt, ...);
 
 #ifdef TDB_TRACE
index 25be07b0083e7252cfdf7560f9344d83d076159a..182738c41f59129e53a59da2c881d8badd703198 100644 (file)
@@ -175,7 +175,7 @@ char *tdb_summary(struct tdb_context *tdb, enum tdb_summary_flags flags)
        chains = tally_new(HISTO_HEIGHT);
        if (!ftables || !hashes || !freet || !keys || !data || !extra
            || !uncoal || !buckets || !chains) {
-               tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
                           "tdb_summary: failed to allocate tally structures");
                goto unlock;
        }
index def2642e5560b84d059cb14e8c6542adc5e76585..58a62cb400da905dba1fbae3845ed4a0d1f47dbe 100644 (file)
@@ -49,8 +49,6 @@ static uint64_t random_number(struct tdb_context *tdb)
        fd = open("/dev/urandom", O_RDONLY);
        if (fd >= 0) {
                if (read_all(fd, &ret, sizeof(ret))) {
-                       tdb_logerr(tdb, TDB_SUCCESS, TDB_DEBUG_TRACE,
-                                "tdb_open: random from /dev/urandom");
                        close(fd);
                        return ret;
                }
@@ -65,9 +63,6 @@ static uint64_t random_number(struct tdb_context *tdb)
                        char reply[1 + sizeof(uint64_t)];
                        int r = read(fd, reply, sizeof(reply));
                        if (r > 1) {
-                               tdb_logerr(tdb, TDB_SUCCESS, TDB_DEBUG_TRACE,
-                                          "tdb_open: %u random bytes from"
-                                          " /dev/egd-pool", r-1);
                                /* Copy at least some bytes. */
                                memcpy(&ret, reply+1, r - 1);
                                if (reply[0] == sizeof(uint64_t)
@@ -83,7 +78,7 @@ static uint64_t random_number(struct tdb_context *tdb)
        /* Fallback: pid and time. */
        gettimeofday(&now, NULL);
        ret = getpid() * 100132289ULL + now.tv_sec * 1000000ULL + now.tv_usec;
-       tdb_logerr(tdb, TDB_SUCCESS, TDB_DEBUG_TRACE,
+       tdb_logerr(tdb, TDB_SUCCESS, TDB_LOG_WARNING,
                   "tdb_open: random from getpid and time");
        return ret;
 }
@@ -141,7 +136,7 @@ static int tdb_new_database(struct tdb_context *tdb,
                tdb->map_size = sizeof(newdb);
                tdb->map_ptr = malloc(tdb->map_size);
                if (!tdb->map_ptr) {
-                       tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
                                   "tdb_new_database: failed to allocate");
                        return -1;
                }
@@ -158,7 +153,7 @@ static int tdb_new_database(struct tdb_context *tdb,
        if (rlen != sizeof(newdb)) {
                if (rlen >= 0)
                        errno = ENOSPC;
-               tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
                           "tdb_new_database: %zi writing header: %s",
                           rlen, strerror(errno));
                return -1;
@@ -220,7 +215,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
                                tdb->stats->size = sizeof(attr->stats);
                        break;
                default:
-                       tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_DEBUG_ERROR,
+                       tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR,
                                   "tdb_open: unknown attribute type %u",
                                   attr->base.attr);
                        goto fail;
@@ -229,7 +224,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
        }
 
        if ((open_flags & O_ACCMODE) == O_WRONLY) {
-               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR,
                           "tdb_open: can't open tdb %s write-only", name);
                goto fail;
        }
@@ -259,7 +254,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
        if ((tdb->fd = open(name, open_flags, mode)) == -1) {
                /* errno set by open(2) */
                saved_errno = errno;
-               tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
                           "tdb_open: could not open file %s: %s",
                           name, strerror(errno));
                goto fail;
@@ -283,13 +278,13 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
                        goto fail;
                }
        } else if (rlen < 0) {
-               tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
                           "tdb_open: error %s reading %s",
                           strerror(errno), name);
                goto fail;
        } else if (rlen < sizeof(hdr)
                   || strcmp(hdr.magic_food, TDB_MAGIC_FOOD) != 0) {
-               tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
                           "tdb_open: %s is not a tdb file", name);
                goto fail;
        }
@@ -299,7 +294,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
                        tdb->flags |= TDB_CONVERT;
                else {
                        /* wrong version */
-                       tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_ERROR,
+                       tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
                                   "tdb_open: %s is unknown version 0x%llx",
                                   name, (long long)hdr.version);
                        goto fail;
@@ -312,7 +307,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
        hash_test = tdb_hash(tdb, &hash_test, sizeof(hash_test));
        if (hdr.hash_test != hash_test) {
                /* wrong hash variant */
-               tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
                           "tdb_open: %s uses a different hash function",
                           name);
                goto fail;
@@ -320,7 +315,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
 
        if (fstat(tdb->fd, &st) == -1) {
                saved_errno = errno;
-               tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
                           "tdb_open: could not stat open %s: %s",
                           name, strerror(errno));
                goto fail;
@@ -329,7 +324,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
        /* Is it already in the open list?  If so, fail. */
        if (tdb_already_open(st.st_dev, st.st_ino)) {
                /* FIXME */
-               tdb_logerr(tdb, TDB_ERR_NESTING, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_NESTING, TDB_LOG_USE_ERROR,
                           "tdb_open: %s (%d,%d) is already open in this"
                           " process",
                           name, (int)st.st_dev, (int)st.st_ino);
@@ -338,7 +333,7 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
 
        tdb->name = strdup(name);
        if (!tdb->name) {
-               tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
                           "tdb_open: failed to allocate name");
                goto fail;
        }
@@ -401,9 +396,9 @@ struct tdb_context *tdb_open(const char *name, int tdb_flags,
        free((char *)tdb->name);
        if (tdb->fd != -1)
                if (close(tdb->fd) != 0)
-                       tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_ERROR,
+                       tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
                                   "tdb_open: failed to close tdb->fd"
-                                  " on error!");
+                                  " on error: %s", strerror(errno));
        free(tdb);
        errno = saved_errno;
        return NULL;
@@ -562,7 +557,7 @@ int tdb_append(struct tdb_context *tdb,
                /* Slow path. */
                newdata = malloc(key.dsize + old_dlen + dbuf.dsize);
                if (!newdata) {
-                       tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
                                   "tdb_append: failed to allocate %zu bytes",
                                   (size_t)(key.dsize+old_dlen+dbuf.dsize));
                        goto fail;
@@ -717,7 +712,7 @@ const char *tdb_errorstr(const struct tdb_context *tdb)
 
 void COLD tdb_logerr(struct tdb_context *tdb,
                     enum TDB_ERROR ecode,
-                    enum tdb_debug_level level,
+                    enum tdb_log_level level,
                     const char *fmt, ...)
 {
        char *message;
@@ -738,7 +733,7 @@ void COLD tdb_logerr(struct tdb_context *tdb,
 
        message = malloc(len + 1);
        if (!message) {
-               tdb->logfn(tdb, TDB_DEBUG_ERROR, tdb->log_private,
+               tdb->logfn(tdb, TDB_LOG_ERROR, tdb->log_private,
                           "out of memory formatting message:");
                tdb->logfn(tdb, level, tdb->log_private, fmt);
                return;
index f738d1ceafddfc0cefc034c1f7ca1497ebf1553e..3577cc3500702f21891df64095bbc883a1648f17 100644 (file)
@@ -68,8 +68,7 @@ enum TDB_ERROR {TDB_SUCCESS=0, TDB_ERR_CORRUPT, TDB_ERR_IO, TDB_ERR_LOCK,
 enum tdb_summary_flags { TDB_SUMMARY_HISTOGRAMS = 1 };
 
 /* logging uses one of the following levels */
-enum tdb_debug_level {TDB_DEBUG_FATAL = 0, TDB_DEBUG_ERROR,
-                     TDB_DEBUG_WARNING, TDB_DEBUG_TRACE};
+enum tdb_log_level {TDB_LOG_ERROR = 0, TDB_LOG_USE_ERROR, TDB_LOG_WARNING};
 
 typedef struct tdb_data {
        unsigned char *dptr;
@@ -80,7 +79,6 @@ struct tdb_context;
 
 /* FIXME: Make typesafe */
 typedef int (*tdb_traverse_func)(struct tdb_context *, TDB_DATA, TDB_DATA, void *);
-typedef void (*tdb_logfn_t)(struct tdb_context *, enum tdb_debug_level, void *, const char *);
 typedef uint64_t (*tdb_hashfn_t)(const void *key, size_t len, uint64_t seed,
                                 void *priv);
 
@@ -98,7 +96,10 @@ struct tdb_attribute_base {
 
 struct tdb_attribute_log {
        struct tdb_attribute_base base; /* .attr = TDB_ATTRIBUTE_LOG */
-       tdb_logfn_t log_fn;
+       void (*log_fn)(struct tdb_context *tdb,
+                      enum tdb_log_level level,
+                      void *log_private,
+                      const char *message);
        void *log_private;
 };
 
index 8284be13439b6dd9f48556a94d934caf3c6671a6..dfb332474a24b3eb462278685a19da2126f01abe 100644 (file)
@@ -13,14 +13,13 @@ union tdb_attribute tap_log_attr = {
 };
 
 void tap_log_fn(struct tdb_context *tdb,
-               enum tdb_debug_level level, void *priv,
+               enum tdb_log_level level, void *priv,
                const char *message)
 {
        if (suppress_logging)
                return;
 
        diag("tdb log level %u: %s%s", level, log_prefix, message);
-       if (level != TDB_DEBUG_TRACE)
-               tap_log_messages++;
+       tap_log_messages++;
 }
 
index 655c00a5957b71b131eda80de6ec0334af5416c9..07d4e10aedee10b112a061212e854a0d4d9bae2d 100644 (file)
@@ -10,7 +10,7 @@ extern unsigned tap_log_messages;
 extern union tdb_attribute tap_log_attr;
 
 void tap_log_fn(struct tdb_context *tdb,
-               enum tdb_debug_level level, void *priv,
+               enum tdb_log_level level, void *priv,
                const char *message);
 
 static inline bool data_equal(struct tdb_data a, struct tdb_data b)
index defba0b00f3a2a3f794b299468b3bc03caa3868d..5f454cf06162b0bb21f4e2872173e57847884cae 100644 (file)
@@ -11,8 +11,8 @@
 #include "logging.h"
 
 /* FIXME: Check these! */
-#define INITIAL_TDB_MALLOC     "tdb.c", 182, FAILTEST_MALLOC
-#define LOGGING_MALLOC         "tdb.c", 739, FAILTEST_MALLOC
+#define INITIAL_TDB_MALLOC     "tdb.c", 177, FAILTEST_MALLOC
+#define LOGGING_MALLOC         "tdb.c", 734, FAILTEST_MALLOC
 #define URANDOM_OPEN           "tdb.c", 49, FAILTEST_OPEN
 #define URANDOM_READ           "tdb.c", 29, FAILTEST_READ
 
index 6abf5e9a73ce7ce1c3fd5e843a04304d38db566f..98a6b0b3f81bafe441b1d707eaa79b4a6a075483 100644 (file)
@@ -12,7 +12,7 @@ static int log_count = 0;
 
 /* Normally we get a log when setting random seed. */
 static void my_log_fn(struct tdb_context *tdb,
-                     enum tdb_debug_level level, void *priv,
+                     enum tdb_log_level level, void *priv,
                      const char *message)
 {
        log_count++;
index 1696d4a355d1e85bb6dcba7ff72e44dbc26a0d77..5dddf99a7cfa47d8807df251c3bc902a8e890fc5 100644 (file)
@@ -50,15 +50,12 @@ static void tdb_log(struct tdb_context *tdb, enum tdb_debug_level level, void *p
 {
        va_list ap;
 
-       if (level != TDB_DEBUG_TRACE)
-               error_count++;
-
        va_start(ap, format);
        vfprintf(stdout, format, ap);
        va_end(ap);
        fflush(stdout);
 #if 0
-       if (level != TDB_DEBUG_TRACE) {
+       {
                char *ptr;
                signal(SIGUSR1, SIG_IGN);
                asprintf(&ptr,"xterm -e gdb /proc/%d/exe %d", getpid(), getpid());
index 66be5bdc8e533cf67c49fddea59e2951ca10e863..5772fb44028cb832c041b233b24548e7f352f644 100644 (file)
@@ -170,7 +170,7 @@ static int transaction_read(struct tdb_context *tdb, tdb_off_t off, void *buf,
        return 0;
 
 fail:
-       tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_FATAL,
+       tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
                   "transaction_read: failed at off=%zu len=%zu",
                   (size_t)off, (size_t)len);
        tdb->transaction->transaction_error = 1;
@@ -188,7 +188,7 @@ static int transaction_write(struct tdb_context *tdb, tdb_off_t off,
 
        /* Only a commit is allowed on a prepared transaction */
        if (tdb->transaction->prepared) {
-               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_ERROR,
                         "transaction_write: transaction already prepared,"
                         " write not allowed");
                goto fail;
@@ -226,7 +226,7 @@ static int transaction_write(struct tdb_context *tdb, tdb_off_t off,
                                (blk+1)*sizeof(uint8_t *));
                }
                if (new_blocks == NULL) {
-                       tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
                                   "transaction_write: failed to allocate");
                        goto fail;
                }
@@ -241,7 +241,7 @@ static int transaction_write(struct tdb_context *tdb, tdb_off_t off,
        if (tdb->transaction->blocks[blk] == NULL) {
                tdb->transaction->blocks[blk] = (uint8_t *)calloc(getpagesize(), 1);
                if (tdb->transaction->blocks[blk] == NULL) {
-                       tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
                                   "transaction_write: failed to allocate");
                        goto fail;
                }
@@ -253,7 +253,7 @@ static int transaction_write(struct tdb_context *tdb, tdb_off_t off,
                        if (tdb->transaction->io_methods->tread(tdb, blk * getpagesize(),
                                                                tdb->transaction->blocks[blk],
                                                                len2) != 0) {
-                               tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_FATAL,
+                               tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
                                           "transaction_write: failed to"
                                           " read old block: %s",
                                           strerror(errno));
@@ -341,7 +341,7 @@ static int transaction_oob(struct tdb_context *tdb, tdb_off_t len, bool probe)
        }
        tdb->ecode = TDB_ERR_IO;
        if (!probe) {
-               tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
                           "tdb_oob len %lld beyond transaction size %lld",
                           (long long)len,
                           (long long)tdb->map_size);
@@ -417,7 +417,7 @@ static int transaction_sync(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t
        }
 
        if (fsync(tdb->fd) != 0) {
-               tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
                           "tdb_transaction: fsync failed: %s",
                           strerror(errno));
                return -1;
@@ -427,7 +427,7 @@ static int transaction_sync(struct tdb_context *tdb, tdb_off_t offset, tdb_len_t
                tdb_off_t moffset = offset & ~(getpagesize()-1);
                if (msync(moffset + (char *)tdb->map_ptr,
                          length + (offset - moffset), MS_SYNC) != 0) {
-                       tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
                                   "tdb_transaction: msync failed: %s",
                                   strerror(errno));
                        return -1;
@@ -443,7 +443,7 @@ static void _tdb_transaction_cancel(struct tdb_context *tdb)
        int i;
 
        if (tdb->transaction == NULL) {
-               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR,
                           "tdb_transaction_cancel: no transaction");
                return;
        }
@@ -473,7 +473,7 @@ static void _tdb_transaction_cancel(struct tdb_context *tdb)
                                    &invalid, sizeof(invalid)) == -1 ||
                    transaction_sync(tdb, tdb->transaction->magic_offset,
                                     sizeof(invalid)) == -1) {
-                       tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                                   "tdb_transaction_cancel: failed to remove"
                                   " recovery magic");
                }
@@ -501,7 +501,7 @@ int tdb_transaction_start(struct tdb_context *tdb)
 {
        /* some sanity checks */
        if (tdb->read_only || (tdb->flags & TDB_INTERNAL)) {
-               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR,
                           "tdb_transaction_start: cannot start a transaction"
                           " on a read-only or internal db");
                return -1;
@@ -509,7 +509,7 @@ int tdb_transaction_start(struct tdb_context *tdb)
 
        /* cope with nested tdb_transaction_start() calls */
        if (tdb->transaction != NULL) {
-               tdb_logerr(tdb, TDB_ERR_NESTING, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_NESTING, TDB_LOG_USE_ERROR,
                           "tdb_transaction_start:"
                           " already inside transaction");
                return -1;
@@ -519,7 +519,7 @@ int tdb_transaction_start(struct tdb_context *tdb)
                /* the caller must not have any locks when starting a
                   transaction as otherwise we'll be screwed by lack
                   of nested locks in posix */
-               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_LOCK, TDB_LOG_USE_ERROR,
                           "tdb_transaction_start: cannot start a transaction"
                           " with locks held");
                return -1;
@@ -528,7 +528,7 @@ int tdb_transaction_start(struct tdb_context *tdb)
        tdb->transaction = (struct tdb_transaction *)
                calloc(sizeof(struct tdb_transaction), 1);
        if (tdb->transaction == NULL) {
-               tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
                           "tdb_transaction_start: cannot allocate");
                return -1;
        }
@@ -618,7 +618,7 @@ static int tdb_recovery_allocate(struct tdb_context *tdb,
 
        recovery_head = tdb_read_off(tdb, offsetof(struct tdb_header,recovery));
        if (recovery_head == TDB_OFF_ERR) {
-               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                         "tdb_recovery_allocate:"
                         " failed to read recovery head");
                return -1;
@@ -626,7 +626,7 @@ static int tdb_recovery_allocate(struct tdb_context *tdb,
 
        if (recovery_head != 0) {
                if (methods->tread(tdb, recovery_head, &rec, sizeof(rec))) {
-                       tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                                 "tdb_recovery_allocate:"
                                 " failed to read recovery record");
                        return -1;
@@ -657,7 +657,7 @@ static int tdb_recovery_allocate(struct tdb_context *tdb,
                add_stat(tdb, frees, 1);
                if (add_free_record(tdb, recovery_head,
                                    sizeof(rec) + rec.max_len) != 0) {
-                       tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                                   "tdb_recovery_allocate:"
                                   " failed to free previous recovery area");
                        return -1;
@@ -683,7 +683,7 @@ static int tdb_recovery_allocate(struct tdb_context *tdb,
                sizeof(rec) + *recovery_max_size;
        tdb->map_size = tdb->transaction->old_map_size;
        if (methods->expand_file(tdb, addition) == -1) {
-               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                         "tdb_recovery_allocate:"
                         " failed to create recovery area");
                return -1;
@@ -699,7 +699,7 @@ static int tdb_recovery_allocate(struct tdb_context *tdb,
        tdb_convert(tdb, &recovery_head, sizeof(recovery_head));
        if (methods->twrite(tdb, offsetof(struct tdb_header, recovery),
                            &recovery_head, sizeof(tdb_off_t)) == -1) {
-               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                         "tdb_recovery_allocate:"
                         " failed to write recovery head");
                return -1;
@@ -747,7 +747,7 @@ static int transaction_setup_recovery(struct tdb_context *tdb,
 
        data = (unsigned char *)malloc(recovery_size + sizeof(*rec));
        if (data == NULL) {
-               tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
                           "transaction_setup_recovery: cannot allocate");
                return -1;
        }
@@ -778,7 +778,7 @@ static int transaction_setup_recovery(struct tdb_context *tdb,
                        continue;
                }
                if (offset + length > tdb->map_size) {
-                       tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                                   "tdb_transaction_setup_recovery:"
                                   " transaction data over new region boundary");
                        free(data);
@@ -808,7 +808,7 @@ static int transaction_setup_recovery(struct tdb_context *tdb,
        /* write the recovery data to the recovery area */
        if (methods->twrite(tdb, recovery_offset, data,
                            sizeof(*rec) + recovery_size) == -1) {
-               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                         "tdb_transaction_setup_recovery:"
                         " failed to write recovery data");
                free(data);
@@ -835,7 +835,7 @@ static int transaction_setup_recovery(struct tdb_context *tdb,
                                                   magic);
 
        if (methods->twrite(tdb, *magic_offset, &magic, sizeof(magic)) == -1) {
-               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                         "tdb_transaction_setup_recovery:"
                         " failed to write recovery magic");
                return -1;
@@ -855,14 +855,14 @@ static int _tdb_transaction_prepare_commit(struct tdb_context *tdb)
        const struct tdb_methods *methods;
 
        if (tdb->transaction == NULL) {
-               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR,
                           "tdb_transaction_prepare_commit: no transaction");
                return -1;
        }
 
        if (tdb->transaction->prepared) {
                _tdb_transaction_cancel(tdb);
-               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR,
                           "tdb_transaction_prepare_commit:"
                           " transaction already prepared");
                return -1;
@@ -870,7 +870,7 @@ static int _tdb_transaction_prepare_commit(struct tdb_context *tdb)
 
        if (tdb->transaction->transaction_error) {
                _tdb_transaction_cancel(tdb);
-               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_ERROR,
                           "tdb_transaction_prepare_commit:"
                           " transaction error pending");
                return -1;
@@ -891,7 +891,7 @@ static int _tdb_transaction_prepare_commit(struct tdb_context *tdb)
 
        /* upgrade the main transaction lock region to a write lock */
        if (tdb_allrecord_upgrade(tdb) == -1) {
-               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                         "tdb_transaction_prepare_commit:"
                         " failed to upgrade hash locks");
                _tdb_transaction_cancel(tdb);
@@ -901,7 +901,7 @@ static int _tdb_transaction_prepare_commit(struct tdb_context *tdb)
        /* get the open lock - this prevents new users attaching to the database
           during the commit */
        if (tdb_lock_open(tdb, TDB_LOCK_WAIT|TDB_LOCK_NOCHECK) == -1) {
-               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                         "tdb_transaction_prepare_commit:"
                         " failed to get open lock");
                _tdb_transaction_cancel(tdb);
@@ -912,7 +912,7 @@ static int _tdb_transaction_prepare_commit(struct tdb_context *tdb)
        if (!(tdb->flags & TDB_NOSYNC)) {
                /* write the recovery data to the end of the file */
                if (transaction_setup_recovery(tdb, &tdb->transaction->magic_offset) == -1) {
-                       tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                                 "tdb_transaction_prepare_commit:"
                                 " failed to setup recovery data");
                        _tdb_transaction_cancel(tdb);
@@ -928,7 +928,7 @@ static int _tdb_transaction_prepare_commit(struct tdb_context *tdb)
                /* Restore original map size for tdb_expand_file */
                tdb->map_size = tdb->transaction->old_map_size;
                if (methods->expand_file(tdb, add) == -1) {
-                       tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_ERROR,
+                       tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                                 "tdb_transaction_prepare_commit:"
                                 " expansion failed");
                        _tdb_transaction_cancel(tdb);
@@ -958,7 +958,7 @@ int tdb_transaction_commit(struct tdb_context *tdb)
        int i;
 
        if (tdb->transaction == NULL) {
-               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR,
                         "tdb_transaction_commit: no transaction");
                return -1;
        }
@@ -967,7 +967,7 @@ int tdb_transaction_commit(struct tdb_context *tdb)
 
        if (tdb->transaction->transaction_error) {
                tdb_transaction_cancel(tdb);
-               tdb_logerr(tdb, TDB_ERR_IO, TDB_DEBUG_ERROR,
+               tdb_logerr(tdb, TDB_ERR_IO, TDB_LOG_ERROR,
                           "tdb_transaction_commit:"
                           " transaction error pending");
                return -1;
@@ -1010,7 +1010,7 @@ int tdb_transaction_commit(struct tdb_context *tdb)
 
                if (methods->twrite(tdb, offset, tdb->transaction->blocks[i],
                                    length) == -1) {
-                       tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                                   "tdb_transaction_commit:"
                                   " write failed during commit");
 
@@ -1072,7 +1072,7 @@ int tdb_transaction_recover(struct tdb_context *tdb)
        /* find the recovery area */
        recovery_head = tdb_read_off(tdb, offsetof(struct tdb_header,recovery));
        if (recovery_head == TDB_OFF_ERR) {
-               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                         "tdb_transaction_recover:"
                         " failed to read recovery head");
                return -1;
@@ -1085,7 +1085,7 @@ int tdb_transaction_recover(struct tdb_context *tdb)
 
        /* read the recovery record */
        if (tdb_read_convert(tdb, recovery_head, &rec, sizeof(rec)) == -1) {
-               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                           "tdb_transaction_recover:"
                           " failed to read recovery record");
                return -1;
@@ -1097,7 +1097,7 @@ int tdb_transaction_recover(struct tdb_context *tdb)
        }
 
        if (tdb->read_only) {
-               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_LOG_ERROR,
                           "tdb_transaction_recover:"
                           " attempt to recover read only database");
                return -1;
@@ -1107,7 +1107,7 @@ int tdb_transaction_recover(struct tdb_context *tdb)
 
        data = (unsigned char *)malloc(rec.len);
        if (data == NULL) {
-               tdb_logerr(tdb, TDB_ERR_OOM, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, TDB_ERR_OOM, TDB_LOG_ERROR,
                           "tdb_transaction_recover:"
                           " failed to allocate recovery data");
                return -1;
@@ -1116,7 +1116,7 @@ int tdb_transaction_recover(struct tdb_context *tdb)
        /* read the full recovery data */
        if (tdb->methods->tread(tdb, recovery_head + sizeof(rec), data,
                                rec.len) == -1) {
-               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                           "tdb_transaction_recover:"
                           " failed to read recovery data");
                return -1;
@@ -1134,7 +1134,7 @@ int tdb_transaction_recover(struct tdb_context *tdb)
 
                if (tdb->methods->twrite(tdb, ofs, p, len) == -1) {
                        free(data);
-                       tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                                 "tdb_transaction_recover:"
                                 " failed to recover %zu bytes at offset %zu",
                                 (size_t)len, (size_t)ofs);
@@ -1146,7 +1146,7 @@ int tdb_transaction_recover(struct tdb_context *tdb)
        free(data);
 
        if (transaction_sync(tdb, 0, tdb->map_size) == -1) {
-               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                           "tdb_transaction_recover: failed to sync recovery");
                return -1;
        }
@@ -1155,7 +1155,7 @@ int tdb_transaction_recover(struct tdb_context *tdb)
        if (recovery_eof <= recovery_head) {
                if (tdb_write_off(tdb, offsetof(struct tdb_header,recovery), 0)
                    == -1) {
-                       tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+                       tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                                 "tdb_transaction_recover:"
                                 " failed to remove recovery head");
                        return -1;
@@ -1167,19 +1167,19 @@ int tdb_transaction_recover(struct tdb_context *tdb)
                          recovery_head
                          + offsetof(struct tdb_recovery_record, magic),
                          TDB_RECOVERY_INVALID_MAGIC) == -1) {
-               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                         "tdb_transaction_recover:"
                         " failed to remove recovery magic");
                return -1;
        }
 
        if (transaction_sync(tdb, 0, recovery_eof) == -1) {
-               tdb_logerr(tdb, tdb->ecode, TDB_DEBUG_FATAL,
+               tdb_logerr(tdb, tdb->ecode, TDB_LOG_ERROR,
                         "tdb_transaction_recover: failed to sync2 recovery");
                return -1;
        }
 
-       tdb_logerr(tdb, TDB_SUCCESS, TDB_DEBUG_TRACE,
+       tdb_logerr(tdb, TDB_SUCCESS, TDB_LOG_WARNING,
                   "tdb_transaction_recover: recovered %zu byte database",
                   (size_t)recovery_eof);