X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftdb2%2Flock.c;h=60ed46379aa7b6960d51e5778c907945614b7c0f;hb=49c1b2e371c2fa6c3e74cee8d8222d161454ffe4;hp=5d13a23aaec89f17e731ffc71415fb43ceb7bafb;hpb=dde924399b8e16de3e2426af8a44b4fde95c5f48;p=ccan-lca-2011.git diff --git a/ccan/tdb2/lock.c b/ccan/tdb2/lock.c index 5d13a23..60ed463 100644 --- a/ccan/tdb2/lock.c +++ b/ccan/tdb2/lock.c @@ -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); if (new_lck) { - /* - * Just increment the in-memory struct, posix locks - * don't stack. - */ + if (new_lck->ltype == F_RDLCK && ltype == F_WRLCK) { + tdb->ecode = TDB_ERR_LOCK; + 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++; return 0; } @@ -454,7 +458,8 @@ int tdb_allrecord_lock(struct tdb_context *tdb, int ltype, 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++; return 0; }