Commit b8309b4c authored by Howard Chu's avatar Howard Chu
Browse files

Cleanup db_lock/unlock parameters

parent a720011c
......@@ -136,7 +136,7 @@ retry: /* transaction retry */
if( p ) {
/* free parent and reader lock */
if ( p != (Entry *)&slap_entry_root ) {
bdb_unlocked_cache_return_entry_r( &bdb->bi_cache, p );
bdb_unlocked_cache_return_entry_r( bdb, p );
}
p = NULL;
}
......@@ -218,7 +218,7 @@ retry: /* transaction retry */
rs->sr_ref = is_entry_referral( p )
? get_entry_referrals( op, p )
: NULL;
bdb_unlocked_cache_return_entry_r( &bdb->bi_cache, p );
bdb_unlocked_cache_return_entry_r( bdb, p );
p = NULL;
Debug( LDAP_DEBUG_TRACE,
LDAP_XSTRING(bdb_add) ": parent "
......@@ -273,7 +273,7 @@ retry: /* transaction retry */
rs->sr_matched = ber_strdup_x( p->e_name.bv_val,
op->o_tmpmemctx );
rs->sr_ref = get_entry_referrals( op, p );
bdb_unlocked_cache_return_entry_r( &bdb->bi_cache, p );
bdb_unlocked_cache_return_entry_r( bdb, p );
p = NULL;
Debug( LDAP_DEBUG_TRACE,
LDAP_XSTRING(bdb_add) ": parent is referral\n",
......@@ -292,7 +292,7 @@ retry: /* transaction retry */
/* free parent and reader lock */
if ( p != (Entry *)&slap_entry_root ) {
bdb_unlocked_cache_return_entry_r( &bdb->bi_cache, p );
bdb_unlocked_cache_return_entry_r( bdb, p );
}
p = NULL;
......@@ -471,7 +471,7 @@ return_results:
* Possibly a callback may have mucked with it, although
* in general callbacks should treat the entry as read-only.
*/
bdb_cache_return_entry_r( bdb->bi_dbenv, &bi->bi_cache, oe, &lock );
bdb_cache_return_entry_r( bdb, oe, &lock );
if ( op->ora_e == oe )
op->ora_e = NULL;
......
......@@ -88,8 +88,7 @@ dn2entry_retry:
e = ei->bei_e;
if ( rs->sr_err == DB_NOTFOUND ) {
if( e != NULL ) {
bdb_cache_return_entry_r( bdb->bi_dbenv,
&bdb->bi_cache, e, &lock );
bdb_cache_return_entry_r( bdb, e, &lock );
e = NULL;
}
......@@ -196,7 +195,7 @@ dn2entry_retry:
done:
/* free entry and reader lock */
if( e != NULL ) {
bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
bdb_cache_return_entry_r( bdb, e, &lock );
}
LOCK_ID_FREE(bdb->bi_dbenv, locker);
......
......@@ -120,7 +120,7 @@ bdb_cache_lru_link( Cache *cache, EntryInfo *ei )
/* Atomically release and reacquire a lock */
int
bdb_cache_entry_db_relock(
DB_ENV *env,
struct bdb_info *bdb,
u_int32_t locker,
EntryInfo *ei,
int rw,
......@@ -145,7 +145,7 @@ bdb_cache_entry_db_relock(
list[1].lock = *lock;
list[1].mode = rw ? DB_LOCK_WRITE : DB_LOCK_READ;
list[1].obj = &lockobj;
rc = env->lock_vec(env, locker, tryOnly ? DB_LOCK_NOWAIT : 0,
rc = bdb->bi_dbenv->lock_vec(bdb->bi_dbenv, locker, tryOnly ? DB_LOCK_NOWAIT : 0,
list, 2, NULL );
if (rc && !tryOnly) {
......@@ -160,7 +160,7 @@ bdb_cache_entry_db_relock(
}
static int
bdb_cache_entry_db_lock( DB_ENV *env, u_int32_t locker, EntryInfo *ei,
bdb_cache_entry_db_lock( struct bdb_info *bdb, u_int32_t locker, EntryInfo *ei,
int rw, int tryOnly, DB_LOCK *lock )
{
#ifdef NO_DB_LOCK
......@@ -180,7 +180,7 @@ bdb_cache_entry_db_lock( DB_ENV *env, u_int32_t locker, EntryInfo *ei,
lockobj.data = &ei->bei_id;
lockobj.size = sizeof(ei->bei_id) + 1;
rc = LOCK_GET(env, locker, tryOnly ? DB_LOCK_NOWAIT : 0,
rc = LOCK_GET(bdb->bi_dbenv, locker, tryOnly ? DB_LOCK_NOWAIT : 0,
&lockobj, db_rw, lock);
if (rc && !tryOnly) {
Debug( LDAP_DEBUG_TRACE,
......@@ -192,7 +192,7 @@ bdb_cache_entry_db_lock( DB_ENV *env, u_int32_t locker, EntryInfo *ei,
}
int
bdb_cache_entry_db_unlock ( DB_ENV *env, DB_LOCK *lock )
bdb_cache_entry_db_unlock ( struct bdb_info *bdb, DB_LOCK *lock )
{
#ifdef NO_DB_LOCK
return 0;
......@@ -201,7 +201,7 @@ bdb_cache_entry_db_unlock ( DB_ENV *env, DB_LOCK *lock )
if ( !lock || lock->mode == DB_LOCK_NG ) return 0;
rc = LOCK_PUT ( env, lock );
rc = LOCK_PUT ( bdb->bi_dbenv, lock );
return rc;
#endif
}
......@@ -759,16 +759,16 @@ load1:
bdb_cache_entryinfo_unlock( *eip );
islocked = 0;
}
rc = bdb_cache_entry_db_lock( bdb->bi_dbenv, locker, *eip, 0, 0, lock );
rc = bdb_cache_entry_db_lock( bdb, locker, *eip, 0, 0, lock );
if ( (*eip)->bei_state & CACHE_ENTRY_DELETED ) {
rc = DB_NOTFOUND;
bdb_cache_entry_db_unlock( bdb->bi_dbenv, lock );
bdb_cache_entry_db_unlock( bdb, lock );
} else if ( rc == 0 ) {
if ( load ) {
/* Give up original read lock, obtain write lock
*/
if ( rc == 0 ) {
rc = bdb_cache_entry_db_relock( bdb->bi_dbenv, locker,
rc = bdb_cache_entry_db_relock( bdb, locker,
*eip, 1, 0, lock );
}
if ( rc == 0 && !ep) {
......@@ -790,18 +790,17 @@ load1:
bdb_cache_entryinfo_unlock( *eip );
if ( rc == 0 ) {
/* If we succeeded, downgrade back to a readlock. */
rc = bdb_cache_entry_db_relock( bdb->bi_dbenv, locker,
rc = bdb_cache_entry_db_relock( bdb, locker,
*eip, 0, 0, lock );
} else {
/* Otherwise, release the lock. */
bdb_cache_entry_db_unlock( bdb->bi_dbenv, lock );
bdb_cache_entry_db_unlock( bdb, lock );
}
} else if ( !(*eip)->bei_e ) {
/* Some other thread is trying to load the entry,
* give it a chance to finish.
* wait for it to finish.
*/
bdb_cache_entry_db_unlock( bdb->bi_dbenv, lock );
ldap_pvt_thread_yield();
bdb_cache_entry_db_unlock( bdb, lock );
bdb_cache_entryinfo_lock( *eip );
islocked = 1;
goto load1;
......@@ -811,12 +810,12 @@ load1:
*/
rc = bdb_fix_dn( (*eip)->bei_e, 1 );
if ( rc ) {
bdb_cache_entry_db_relock( bdb->bi_dbenv,
bdb_cache_entry_db_relock( bdb,
locker, *eip, 1, 0, lock );
/* check again in case other modifier did it already */
if ( bdb_fix_dn( (*eip)->bei_e, 1 ) )
rc = bdb_fix_dn( (*eip)->bei_e, 2 );
bdb_cache_entry_db_relock( bdb->bi_dbenv,
bdb_cache_entry_db_relock( bdb,
locker, *eip, 0, 0, lock );
}
#endif
......@@ -904,7 +903,7 @@ bdb_cache_add(
/* Lock this entry so that bdb_add can run to completion.
* It can only fail if BDB has run out of lock resources.
*/
rc = bdb_cache_entry_db_lock( bdb->bi_dbenv, locker, &ei, 0, 0, lock );
rc = bdb_cache_entry_db_lock( bdb, locker, &ei, 0, 0, lock );
if ( rc ) {
bdb_cache_entryinfo_unlock( eip );
return rc;
......@@ -954,16 +953,16 @@ bdb_cache_add(
int
bdb_cache_modify(
struct bdb_info *bdb,
Entry *e,
Attribute *newAttrs,
DB_ENV *env,
u_int32_t locker,
DB_LOCK *lock )
{
EntryInfo *ei = BEI(e);
int rc;
/* Get write lock on data */
rc = bdb_cache_entry_db_relock( env, locker, ei, 1, 0, lock );
rc = bdb_cache_entry_db_relock( bdb, locker, ei, 1, 0, lock );
/* If we've done repeated mods on a cached entry, then e_attrs
* is no longer contiguous with the entry, and must be freed.
......@@ -997,7 +996,7 @@ bdb_cache_modrdn(
#endif
/* Get write lock on data */
rc = bdb_cache_entry_db_relock( bdb->bi_dbenv, locker, ei, 1, 0, lock );
rc = bdb_cache_entry_db_relock( bdb, locker, ei, 1, 0, lock );
if ( rc ) return rc;
/* If we've done repeated mods on a cached entry, then e_attrs
......@@ -1080,9 +1079,8 @@ bdb_cache_modrdn(
*/
int
bdb_cache_delete(
Cache *cache,
struct bdb_info *bdb,
Entry *e,
DB_ENV *env,
u_int32_t locker,
DB_LOCK *lock )
{
......@@ -1098,7 +1096,7 @@ bdb_cache_delete(
bdb_cache_entryinfo_lock( ei );
/* Get write lock on the data */
rc = bdb_cache_entry_db_relock( env, locker, ei, 1, 0, lock );
rc = bdb_cache_entry_db_relock( bdb, locker, ei, 1, 0, lock );
if ( rc ) {
/* couldn't lock, undo and give up */
ei->bei_state ^= CACHE_ENTRY_DELETED;
......@@ -1110,12 +1108,12 @@ bdb_cache_delete(
e->e_id, 0, 0 );
/* set lru mutex */
ldap_pvt_thread_mutex_lock( &cache->lru_head_mutex );
ldap_pvt_thread_mutex_lock( &bdb->bi_cache.lru_head_mutex );
rc = bdb_cache_delete_internal( cache, e->e_private, 1 );
rc = bdb_cache_delete_internal( &bdb->bi_cache, e->e_private, 1 );
/* free lru mutex */
ldap_pvt_thread_mutex_unlock( &cache->lru_head_mutex );
ldap_pvt_thread_mutex_unlock( &bdb->bi_cache.lru_head_mutex );
/* Leave entry info locked */
......
......@@ -80,7 +80,7 @@ dn2entry_retry:
rs->sr_err = LDAP_REFERRAL;
}
bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
bdb_cache_return_entry_r( bdb, e, &lock );
e = NULL;
} else {
......@@ -182,8 +182,7 @@ return_results:
done:
/* free entry */
if ( e != NULL ) {
bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache,
e, &lock );
bdb_cache_return_entry_r( bdb, e, &lock );
}
LOCK_ID_FREE ( bdb->bi_dbenv, locker );
......
......@@ -517,8 +517,7 @@ retry: /* transaction retry */
goto return_results;
}
} else {
rc = bdb_cache_delete( &bdb->bi_cache, e, bdb->bi_dbenv,
locker, &lock );
rc = bdb_cache_delete( bdb, e, locker, &lock );
switch( rc ) {
case DB_LOCK_DEADLOCK:
case DB_LOCK_NOTGRANTED:
......
......@@ -260,14 +260,13 @@ int bdb_entry_release(
/* lock is freed with txn */
if ( !boi || boi->boi_txn ) {
bdb_unlocked_cache_return_entry_rw( &bdb->bi_cache, e, rw );
bdb_unlocked_cache_return_entry_rw( bdb, e, rw );
} else {
struct bdb_lock_info *bli, *prev;
for ( prev=(struct bdb_lock_info *)&boi->boi_locks,
bli = boi->boi_locks; bli; prev=bli, bli=bli->bli_next ) {
if ( bli->bli_id == e->e_id ) {
bdb_cache_return_entry_rw( bdb->bi_dbenv, &bdb->bi_cache,
e, rw, &bli->bli_lock );
bdb_cache_return_entry_rw( bdb, e, rw, &bli->bli_lock );
prev->bli_next = bli->bli_next;
op->o_tmpfree( bli, op->o_tmpmemctx );
break;
......@@ -411,7 +410,7 @@ dn2entry_retry:
return_results:
if( rc != LDAP_SUCCESS ) {
/* free entry */
bdb_cache_return_entry_rw(bdb->bi_dbenv, &bdb->bi_cache, e, rw, &lock);
bdb_cache_return_entry_rw(bdb, e, rw, &lock);
} else {
if ( slapMode == SLAP_SERVER_MODE ) {
......@@ -438,7 +437,7 @@ return_results:
}
} else {
*ent = entry_dup( e );
bdb_cache_return_entry_rw(bdb->bi_dbenv, &bdb->bi_cache, e, rw, &lock);
bdb_cache_return_entry_rw(bdb, e, rw, &lock);
}
}
......
......@@ -600,7 +600,7 @@ retry: /* transaction retry */
attrs_free( dummy.e_attrs );
} else {
rc = bdb_cache_modify( e, dummy.e_attrs, bdb->bi_dbenv, locker, &lock );
rc = bdb_cache_modify( bdb, e, dummy.e_attrs, locker, &lock );
switch( rc ) {
case DB_LOCK_DEADLOCK:
case DB_LOCK_NOTGRANTED:
......
......@@ -454,20 +454,20 @@ int bdb_monitor_db_destroy( BackendDB *be );
* and we can trim out all of this stuff.
*/
#if 0
void bdb_cache_return_entry_rw( DB_ENV *env, Cache *cache, Entry *e,
void bdb_cache_return_entry_rw( struct bdb_info *bdb, Entry *e,
int rw, DB_LOCK *lock );
#else
#define bdb_cache_return_entry_rw( env, cache, e, rw, lock ) \
bdb_cache_entry_db_unlock( env, lock )
#define bdb_cache_return_entry( env, lock ) \
bdb_cache_entry_db_unlock( env, lock )
#define bdb_cache_return_entry_rw( bdb, e, rw, lock ) \
bdb_cache_entry_db_unlock( bdb, lock )
#define bdb_cache_return_entry( bdb, lock ) \
bdb_cache_entry_db_unlock( bdb, lock )
#endif
#define bdb_cache_return_entry_r(env, c, e, l) \
bdb_cache_return_entry_rw((env), (c), (e), 0, (l))
#define bdb_cache_return_entry_w(env, c, e, l) \
bdb_cache_return_entry_rw((env), (c), (e), 1, (l))
#define bdb_cache_return_entry_r(bdb, e, l) \
bdb_cache_return_entry_rw((bdb), (e), 0, (l))
#define bdb_cache_return_entry_w(bdb, e, l) \
bdb_cache_return_entry_rw((bdb), (e), 1, (l))
#if 0
void bdb_unlocked_cache_return_entry_rw( Cache *cache, Entry *e, int rw );
void bdb_unlocked_cache_return_entry_rw( struct bdb_info *bdb, Entry *e, int rw );
#else
#define bdb_unlocked_cache_return_entry_rw( a, b, c ) ((void)0)
#endif
......@@ -512,9 +512,9 @@ int bdb_cache_modrdn(
DB_LOCK *lock
);
int bdb_cache_modify(
struct bdb_info *bdb,
Entry *e,
Attribute *newAttrs,
DB_ENV *env,
u_int32_t locker,
DB_LOCK *lock
);
......@@ -546,9 +546,8 @@ bdb_cache_find_parent(
EntryInfo **res
);
int bdb_cache_delete(
Cache *cache,
struct bdb_info *bdb,
Entry *e,
DB_ENV *env,
u_int32_t locker,
DB_LOCK *lock
);
......@@ -557,12 +556,6 @@ void bdb_cache_delete_cleanup(
EntryInfo *ei
);
void bdb_cache_release_all( Cache *cache );
void bdb_cache_delete_entry(
struct bdb_info *bdb,
EntryInfo *ei,
u_int32_t locker,
DB_LOCK *lock
);
#ifdef BDB_HIER
int hdb_cache_load(
......@@ -574,7 +567,7 @@ int hdb_cache_load(
#define bdb_cache_entry_db_relock BDB_SYMBOL(cache_entry_db_relock)
int bdb_cache_entry_db_relock(
DB_ENV *env,
struct bdb_info *bdb,
u_int32_t locker,
EntryInfo *ei,
int rw,
......@@ -582,7 +575,7 @@ int bdb_cache_entry_db_relock(
DB_LOCK *lock );
int bdb_cache_entry_db_unlock(
DB_ENV *env,
struct bdb_info *bdb,
DB_LOCK *lock );
#ifdef BDB_REUSE_LOCKERS
......
......@@ -102,7 +102,7 @@ dn2entry_retry:
}
}
bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
bdb_cache_return_entry_r (bdb, e, &lock);
e = NULL;
} else if ( !be_issuffix( op->o_bd, &op->o_req_ndn ) && default_referral != NULL ) {
rc = LDAP_OTHER;
......@@ -156,7 +156,7 @@ dn2entry_retry:
ber_bvarray_free( refs );
}
bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
bdb_cache_return_entry_r(bdb, e, &lock);
LOCK_ID_FREE ( bdb->bi_dbenv, locker );
return rc;
}
......@@ -119,8 +119,7 @@ static Entry * deref_base (
/* Free the previous entry, continue to work with the
* one we just retrieved.
*/
bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache,
*matched, lock);
bdb_cache_return_entry_r( bdb, *matched, lock);
*lock = lockr;
/* We found a regular entry. Return this to the caller. The
......@@ -212,7 +211,7 @@ static int search_aliases(
if (first) {
first = 0;
} else {
bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache, e, &locka);
bdb_cache_return_entry_r (bdb, e, &locka);
}
BDB_IDL_CPY(subscop2, subscop);
rs->sr_err = bdb_idl_intersection(curscop, subscop);
......@@ -238,8 +237,7 @@ retry1:
* turned into a range that spans IDs indiscriminately
*/
if (!is_entry_alias(a)) {
bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache,
a, &lockr);
bdb_cache_return_entry_r (bdb, a, &lockr);
continue;
}
......@@ -257,15 +255,13 @@ retry1:
bdb_idl_insert(newsubs, a->e_id);
bdb_idl_insert(scopes, a->e_id);
}
bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache,
a, &lockr);
bdb_cache_return_entry_r( bdb, a, &lockr);
} else if (matched) {
/* Alias could not be dereferenced, or it deref'd to
* an ID we've already seen. Ignore it.
*/
bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache,
matched, &lockr );
bdb_cache_return_entry_r( bdb, matched, &lockr );
rs->sr_text = NULL;
}
}
......@@ -405,8 +401,7 @@ dn2entry_retry:
if ( e ) {
build_new_dn( &op->o_req_ndn, &e->e_nname, &stub,
op->o_tmpmemctx );
bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache,
e, &lock);
bdb_cache_return_entry_r (bdb, e, &lock);
matched = NULL;
goto dn2entry_retry;
}
......@@ -444,8 +439,7 @@ dn2entry_retry:
#ifdef SLAP_ZONE_ALLOC
slap_zn_runlock(bdb->bi_cache.c_zctx, matched);
#endif
bdb_cache_return_entry_r (bdb->bi_dbenv, &bdb->bi_cache,
matched, &lock);
bdb_cache_return_entry_r (bdb, matched, &lock);
matched = NULL;
if ( erefs ) {
......@@ -493,7 +487,7 @@ dn2entry_retry:
slap_zn_runlock(bdb->bi_cache.c_zctx, e);
#endif
if ( e != &e_root ) {
bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
bdb_cache_return_entry_r(bdb, e, &lock);
}
send_ldap_result( op, rs );
return rs->sr_err;
......@@ -512,7 +506,7 @@ dn2entry_retry:
#ifdef SLAP_ZONE_ALLOC
slap_zn_runlock(bdb->bi_cache.c_zctx, e);
#endif
bdb_cache_return_entry_r( bdb->bi_dbenv, &bdb->bi_cache, e, &lock );
bdb_cache_return_entry_r( bdb, e, &lock );
e = NULL;
if ( erefs ) {
......@@ -550,7 +544,7 @@ dn2entry_retry:
slap_zn_runlock(bdb->bi_cache.c_zctx, e);
#endif
if ( e != &e_root ) {
bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
bdb_cache_return_entry_r(bdb, e, &lock);
}
send_ldap_result( op, rs );
return 1;
......@@ -573,7 +567,7 @@ dn2entry_retry:
slap_zn_runlock(bdb->bi_cache.c_zctx, e);
#endif
if ( e != &e_root ) {
bdb_cache_return_entry_r(bdb->bi_dbenv, &bdb->bi_cache, e, &lock);
bdb_cache_return_entry_r(bdb, e, &lock);
}
e = NULL;
......@@ -852,8 +846,7 @@ fetch_entry_retry:
#ifdef SLAP_ZONE_ALLOC
slap_zn_runlock(bdb->bi_cache.c_zctx, e);
#endif
bdb_cache_return_entry_r( bdb->bi_dbenv,
&bdb->bi_cache, e, &lock );
bdb_cache_return_entry_r( bdb, e, &lock );
e = NULL;
send_paged_response( op, rs, &lastid, tentries );
goto done;
......@@ -880,8 +873,7 @@ fetch_entry_retry:
#ifdef SLAP_ZONE_ALLOC
slap_zn_runlock(bdb->bi_cache.c_zctx, e);
#endif
bdb_cache_return_entry_r(bdb->bi_dbenv,
&bdb->bi_cache, e, &lock);
bdb_cache_return_entry_r(bdb, e, &lock);
e = NULL;
rs->sr_entry = NULL;
if ( rs->sr_err == LDAP_SIZELIMIT_EXCEEDED ) {
......@@ -909,8 +901,7 @@ loop_continue:
#ifdef SLAP_ZONE_ALLOC
slap_zn_runlock(bdb->bi_cache.c_zctx, e);
#endif
bdb_cache_return_entry_r( bdb->bi_dbenv,
&bdb->bi_cache, e , &lock );
bdb_cache_return_entry_r( bdb, e , &lock );
e = NULL;
rs->sr_entry = NULL;
}
......
Supports Markdown
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