From b77f41d58b05101e02d8ac0e54cb0e30807d89c2 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 22 Oct 2009 00:09:43 +1030 Subject: lib/tdb: wean off TDB_ERRCODE. It was a regrettable hack which I used to reduce line count in tdb; in fact it caused confusion as can be seen in this patch. In particular, ecode now needs to be set before TDB_LOG anyway, and having it exposed in the header is useless (the struct tdb_context isn't defined, so it's doubly useless). Also, we should never set errno, as io.c was doing. Signed-off-by: Rusty Russell --- lib/tdb/common/lock.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'lib/tdb/common/lock.c') diff --git a/lib/tdb/common/lock.c b/lib/tdb/common/lock.c index 3414049cb6..0984e516ea 100644 --- a/lib/tdb/common/lock.c +++ b/lib/tdb/common/lock.c @@ -75,16 +75,15 @@ int tdb_brlock(struct tdb_context *tdb, tdb_off_t offset, } while (ret == -1 && errno == EINTR); if (ret == -1) { + tdb->ecode = TDB_ERR_LOCK; /* Generic lock error. errno set by fcntl. * EAGAIN is an expected return from non-blocking * locks. */ if (!probe && lck_type != F_SETLK) { - /* Ensure error code is set for log fun to examine. */ - tdb->ecode = TDB_ERR_LOCK; TDB_LOG((tdb, TDB_DEBUG_TRACE,"tdb_brlock failed (fd=%d) at offset %d rw_type=%d lck_type=%d len=%d\n", tdb->fd, offset, rw_type, lck_type, (int)len)); } - return TDB_ERRCODE(TDB_ERR_LOCK, -1); + return -1; } return 0; } @@ -133,10 +132,12 @@ static int _tdb_lock(struct tdb_context *tdb, int list, int ltype, int op) } if (tdb->global_lock.count) { - return TDB_ERRCODE(TDB_ERR_LOCK, -1); + tdb->ecode = TDB_ERR_LOCK; + return -1; } if (list < -1 || list >= (int)tdb->header.hash_size) { + tdb->ecode = TDB_ERR_LOCK; TDB_LOG((tdb, TDB_DEBUG_ERROR,"tdb_lock: invalid list %d for ltype=%d\n", list, ltype)); return -1; @@ -228,7 +229,8 @@ int tdb_unlock(struct tdb_context *tdb, int list, int ltype) } if (tdb->global_lock.count) { - return TDB_ERRCODE(TDB_ERR_LOCK, -1); + tdb->ecode = TDB_ERR_LOCK; + return -1; } if (tdb->flags & TDB_NOLOCK) @@ -350,8 +352,10 @@ static int _tdb_lockall(struct tdb_context *tdb, int ltype, int op) ltype &= ~TDB_MARK_LOCK; /* There are no locks on read-only dbs */ - if (tdb->read_only || tdb->traverse_read) - return TDB_ERRCODE(TDB_ERR_LOCK, -1); + if (tdb->read_only || tdb->traverse_read) { + tdb->ecode = TDB_ERR_LOCK; + return -1; + } if (tdb->global_lock.count && tdb->global_lock.ltype == ltype) { tdb->global_lock.count++; @@ -360,12 +364,14 @@ static int _tdb_lockall(struct tdb_context *tdb, int ltype, int op) if (tdb->global_lock.count) { /* a global lock of a different type exists */ - return TDB_ERRCODE(TDB_ERR_LOCK, -1); + tdb->ecode = TDB_ERR_LOCK; + return -1; } if (tdb->num_locks != 0) { /* can't combine global and chain locks */ - return TDB_ERRCODE(TDB_ERR_LOCK, -1); + tdb->ecode = TDB_ERR_LOCK; + return -1; } if (!mark_lock && @@ -394,11 +400,13 @@ static int _tdb_unlockall(struct tdb_context *tdb, int ltype) /* There are no locks on read-only dbs */ if (tdb->read_only || tdb->traverse_read) { - return TDB_ERRCODE(TDB_ERR_LOCK, -1); + tdb->ecode = TDB_ERR_LOCK; + return -1; } if (tdb->global_lock.ltype != ltype || tdb->global_lock.count == 0) { - return TDB_ERRCODE(TDB_ERR_LOCK, -1); + tdb->ecode = TDB_ERR_LOCK; + return -1; } if (tdb->global_lock.count > 1) { -- cgit