/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2000-2005 The OpenLDAP Foundation.
+ * Copyright 2000-2006 The OpenLDAP Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#ifdef BDB_HIER
ldap_pvt_thread_mutex_init( &bdb->bi_modrdns_mutex );
#endif
- ldap_pvt_thread_mutex_init( &bdb->bi_cache.lru_mutex );
+ ldap_pvt_thread_mutex_init( &bdb->bi_cache.lru_head_mutex );
+ ldap_pvt_thread_mutex_init( &bdb->bi_cache.lru_tail_mutex );
ldap_pvt_thread_mutex_init( &bdb->bi_cache.c_dntree.bei_kids_mutex );
ldap_pvt_thread_rdwr_init ( &bdb->bi_cache.c_rwlock );
ldap_pvt_thread_rdwr_init( &bdb->bi_idl_tree_rwlock );
return 0;
}
+static int
+bdb_db_close( BackendDB *be );
+
static int
bdb_db_open( BackendDB *be )
{
Debug( LDAP_DEBUG_ANY,
"bdb_db_open: db_env_create failed: %s (%d)\n",
db_strerror(rc), rc, 0 );
- return rc;
+ goto fail;
}
bdb->bi_dbenv->set_errpfx( bdb->bi_dbenv, be->be_suffix[0].bv_val );
Debug( LDAP_DEBUG_ANY,
"bdb_db_open: dbenv_set_flags failed: %s (%d)\n",
db_strerror(rc), rc, 0 );
- return rc;
+ goto fail;
}
}
Debug( LDAP_DEBUG_ANY,
"bdb_db_open: Database cannot be recovered. "
"Restore from backup!\n", 0, 0, 0);
- return -1;
+ rc = -1;
+ goto fail;
}
/* We need to recover, and we had TXN support before:
* Close this env, open a new one with recovery flags.
Debug( LDAP_DEBUG_ANY,
"bdb_db_open: db_env_create failed: %s (%d)\n",
db_strerror(rc), rc, 0 );
- return rc;
+ goto fail;
}
bdb->bi_dbenv->set_errpfx( bdb->bi_dbenv,
be->be_suffix[0].bv_val );
Debug( LDAP_DEBUG_ANY,
"bdb_db_open: recovery failed: %s (%d)\n",
db_strerror(rc), rc, 0 );
- return rc;
+ goto fail;
}
do_recover = 0;
}
Debug( LDAP_DEBUG_ANY,
"bdb_db_open: db_env_create failed: %s (%d)\n",
db_strerror(rc), rc, 0 );
- return rc;
+ goto fail;
}
bdb->bi_dbenv->remove( bdb->bi_dbenv, dbhome, 0 );
bdb->bi_dbenv = NULL;
Debug( LDAP_DEBUG_ANY,
"bdb_db_open: Database cannot be recovered. "
"Restore from backup!\n", 0, 0, 0);
- return -1;
+ rc = -1;
+ goto fail;
}
/* Prev environment had no TXN support, close it */
if ( !flags_ok ) {
Debug( LDAP_DEBUG_ANY,
"bdb_db_open: db_env_create failed: %s (%d)\n",
db_strerror(rc), rc, 0 );
- return rc;
+ goto fail;
}
bdb->bi_dbenv->set_errpfx( bdb->bi_dbenv, be->be_suffix[0].bv_val );
Debug( LDAP_DEBUG_ANY,
"bdb_db_open: dbenv_set_flags failed: %s (%d)\n",
db_strerror(rc), rc, 0 );
- return rc;
+ goto fail;
}
}
}
Debug( LDAP_DEBUG_ANY,
"bdb_db_open: dbenv_open failed: %s (%d)\n",
db_strerror(rc), rc, 0 );
- return rc;
+ goto fail;
}
}
Debug( LDAP_DEBUG_ANY,
"bdb_db_open: alock_recover failed\n",
0, 0, 0 );
- return -1;
+ rc = -1;
+ goto fail;
}
#ifdef SLAP_ZONE_ALLOC
Debug( LDAP_DEBUG_ANY,
"bdb_db_open: db_create(%s) failed: %s (%d)\n",
bdb->bi_dbenv_home, db_strerror(rc), rc );
- return rc;
+ goto fail;
}
if( i == BDB_ID2ENTRY ) {
Debug( LDAP_DEBUG_ANY,
"bdb_db_open: db_open(%s) failed: %s (%d)\n",
buf, db_strerror(rc), rc );
- return rc;
+ db->bdi_db->close( db->bdi_db, 0 );
+ goto fail;
}
flags &= ~(DB_CREATE | DB_RDONLY);
Debug( LDAP_DEBUG_ANY,
"bdb_db_open: last_id(%s) failed: %s (%d)\n",
bdb->bi_dbenv_home, db_strerror(rc), rc );
- return rc;
+ goto fail;
}
if ( !( slapMode & SLAP_TOOL_QUICK )) {
bdb->bi_flags |= BDB_IS_OPEN;
return 0;
+
+fail:
+ bdb_db_close( be );
+ return rc;
}
static int
struct bdb_db_info *db;
bdb_idl_cache_entry_t *entry, *next_entry;
- /* backend_shutdown closes everything, even if not all were opened */
- if ( !( bdb->bi_flags & BDB_IS_OPEN ))
- return 0;
-
bdb->bi_flags &= ~BDB_IS_OPEN;
ber_bvarray_free( bdb->bi_db_config );
bdb_cache_release_all (&bdb->bi_cache);
if ( bdb->bi_idl_cache_max_size ) {
- ldap_pvt_thread_rdwr_wlock ( &bdb->bi_idl_tree_rwlock );
avl_free( bdb->bi_idl_tree, NULL );
bdb->bi_idl_tree = NULL;
entry = bdb->bi_idl_lru_head;
entry = next_entry;
}
bdb->bi_idl_lru_head = bdb->bi_idl_lru_tail = NULL;
- ldap_pvt_thread_rdwr_wunlock ( &bdb->bi_idl_tree_rwlock );
- }
-
- if ( !( slapMode & SLAP_TOOL_QUICK ) && bdb->bi_dbenv ) {
- XLOCK_ID_FREE(bdb->bi_dbenv, bdb->bi_cache.c_locker);
- bdb->bi_cache.c_locker = 0;
}
/* close db environment */
if( bdb->bi_dbenv ) {
+ /* Free cache locker if we enabled locking */
+ if ( !( slapMode & SLAP_TOOL_QUICK )) {
+ XLOCK_ID_FREE(bdb->bi_dbenv, bdb->bi_cache.c_locker);
+ bdb->bi_cache.c_locker = 0;
+ }
+
/* force a checkpoint, but not if we were ReadOnly,
* and not in Quick mode since there are no transactions there.
*/
bdb_attr_index_destroy( bdb );
ldap_pvt_thread_rdwr_destroy ( &bdb->bi_cache.c_rwlock );
- ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.lru_mutex );
+ ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.lru_head_mutex );
+ ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.lru_tail_mutex );
ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.c_dntree.bei_kids_mutex );
#ifdef BDB_HIER
ldap_pvt_thread_mutex_destroy( &bdb->bi_modrdns_mutex );
LDAP_CONTROL_MANAGEDSAIT,
LDAP_CONTROL_NOOP,
LDAP_CONTROL_PAGEDRESULTS,
-#ifdef LDAP_CONTROL_SUBENTRIES
LDAP_CONTROL_SUBENTRIES,
-#endif
-#ifdef LDAP_CONTROL_X_PERMISSIVE_MODIFY
LDAP_CONTROL_X_PERMISSIVE_MODIFY,
-#endif
NULL
};
bi->bi_flags |=
SLAP_BFLAG_INCREMENT |
-#ifdef BDB_SUBENTRIES
SLAP_BFLAG_SUBENTRIES |
-#endif
SLAP_BFLAG_ALIASES |
SLAP_BFLAG_REFERRALS;