From bdc5499205367eccef5700cba8af95ba941ac9b2 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 14 Sep 2011 07:16:13 +0930 Subject: tdb2: add TDB_RDONLY flag, allow setting/unsetting it. You can only unset it if the TDB was originally opened O_RDWR. Also, cleaned up error handling in tdb_allrecord_lock() so we only get one log message on a r/o database. Signed-off-by: Rusty Russell (Imported from CCAN commit b87e14495d5b07e1b247218a72329f10ecb3da7f) --- lib/tdb2/lock.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/tdb2/lock.c') diff --git a/lib/tdb2/lock.c b/lib/tdb2/lock.c index 76b8bc3157..957adf8335 100644 --- a/lib/tdb2/lock.c +++ b/lib/tdb2/lock.c @@ -194,7 +194,7 @@ static enum TDB_ERROR tdb_brlock(struct tdb_context *tdb, return TDB_SUCCESS; } - if (rw_type == F_WRLCK && tdb->read_only) { + if (rw_type == F_WRLCK && (tdb->flags & TDB_RDONLY)) { return tdb_logerr(tdb, TDB_ERR_RDONLY, TDB_LOG_USE_ERROR, "Write lock attempted on read-only database"); } @@ -508,8 +508,9 @@ static enum TDB_ERROR tdb_lock_gradual(struct tdb_context *tdb, } /* First we try non-blocking. */ - if (tdb_brlock(tdb, ltype, off, len, nb_flags) == TDB_SUCCESS) { - return TDB_SUCCESS; + ecode = tdb_brlock(tdb, ltype, off, len, nb_flags); + if (ecode != TDB_ERR_LOCK) { + return ecode; } /* Try locking first half, then second. */ -- cgit