Commit 49c1b2e3 authored by Rusty Russell's avatar Rusty Russell

tdb2: allow nesting of read locks on top of write locks.

If we have a write lock and ask for a read lock, that's OK, but not the
other way around.  tdb_nest_lock() allowed both, tdb_allrecord_lock() allowed
neither.
parent dde92439
...@@ -270,10 +270,14 @@ static int tdb_nest_lock(struct tdb_context *tdb, tdb_off_t offset, int ltype, ...@@ -270,10 +270,14 @@ static int tdb_nest_lock(struct tdb_context *tdb, tdb_off_t offset, int ltype,
new_lck = find_nestlock(tdb, offset); new_lck = find_nestlock(tdb, offset);
if (new_lck) { if (new_lck) {
/* if (new_lck->ltype == F_RDLCK && ltype == F_WRLCK) {
* Just increment the in-memory struct, posix locks tdb->ecode = TDB_ERR_LOCK;
* don't stack. tdb->log(tdb, TDB_DEBUG_FATAL, tdb->log_priv,
*/ "tdb_nest_lock: offset %llu has read lock\n",
(long long)offset);
return -1;
}
/* Just increment the struct, posix locks don't stack. */
new_lck->count++; new_lck->count++;
return 0; return 0;
} }
...@@ -454,7 +458,8 @@ int tdb_allrecord_lock(struct tdb_context *tdb, int ltype, ...@@ -454,7 +458,8 @@ int tdb_allrecord_lock(struct tdb_context *tdb, int ltype,
return -1; return -1;
} }
if (tdb->allrecord_lock.count && tdb->allrecord_lock.ltype == ltype) { if (tdb->allrecord_lock.count
&& (ltype == F_RDLCK || tdb->allrecord_lock.ltype == F_WRLCK)) {
tdb->allrecord_lock.count++; tdb->allrecord_lock.count++;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment