X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Ftdb.c;h=7484695d7ab9a8724eb178e82bf3e1a9e52a58e2;hp=18cf2e93a598ea7c3f742bcb3e445a5985686d55;hb=6e3d9e8a66bf8b45150500f176452ee8e9ee9927;hpb=8cca0397ef6f6017b13ce9ab4999bf3d92a2dee5 diff --git a/ccan/tdb2/tdb.c b/ccan/tdb2/tdb.c index 18cf2e93..7484695d 100644 --- a/ccan/tdb2/tdb.c +++ b/ccan/tdb2/tdb.c @@ -1,3 +1,20 @@ + /* + Trivial Database 2: fetch, store and misc routines. + Copyright (C) Rusty Russell 2010 + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, see . +*/ #include "private.h" #include #include @@ -41,7 +58,8 @@ static enum TDB_ERROR replace_data(struct tdb_context *tdb, tdb->stats.frees++; ecode = add_free_record(tdb, old_off, sizeof(struct tdb_used_record) - + key.dsize + old_room); + + key.dsize + old_room, + TDB_LOCK_WAIT, true); if (ecode == TDB_SUCCESS) ecode = replace_in_hash(tdb, h, new_off); } else { @@ -290,7 +308,8 @@ enum TDB_ERROR tdb_delete(struct tdb_context *tdb, struct tdb_data key) sizeof(struct tdb_used_record) + rec_key_length(&rec) + rec_data_length(&rec) - + rec_extra_padding(&rec)); + + rec_extra_padding(&rec), + TDB_LOCK_WAIT, true); if (tdb->flags & TDB_SEQNUM) tdb_inc_seqnum(tdb); @@ -327,6 +346,9 @@ void tdb_add_flag(struct tdb_context *tdb, unsigned flag) case TDB_SEQNUM: tdb->flags |= TDB_SEQNUM; break; + case TDB_ALLOW_NESTING: + tdb->flags |= TDB_ALLOW_NESTING; + break; default: tdb->last_error = tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR, @@ -357,6 +379,9 @@ void tdb_remove_flag(struct tdb_context *tdb, unsigned flag) case TDB_SEQNUM: tdb->flags &= ~TDB_SEQNUM; break; + case TDB_ALLOW_NESTING: + tdb->flags &= ~TDB_ALLOW_NESTING; + break; default: tdb->last_error = tdb_logerr(tdb, TDB_ERR_EINVAL, TDB_LOG_USE_ERROR, @@ -406,11 +431,11 @@ enum TDB_ERROR COLD tdb_logerr(struct tdb_context *tdb, va_end(ap); if (len < 0) { - tdb->log_fn(tdb, TDB_LOG_ERROR, + tdb->log_fn(tdb, TDB_LOG_ERROR, TDB_ERR_OOM, "out of memory formatting message:", tdb->log_data); - tdb->log_fn(tdb, level, fmt, tdb->log_data); + tdb->log_fn(tdb, level, ecode, fmt, tdb->log_data); } else { - tdb->log_fn(tdb, level, message, tdb->log_data); + tdb->log_fn(tdb, level, ecode, message, tdb->log_data); free(message); } errno = saved_errno;