Make dbEnv a private toy of back-bdb2.

This commit is contained in:
Kurt Spanier 1999-03-05 10:25:55 +00:00
parent 3ba99a75ef
commit 3f76ee7a0b
17 changed files with 98 additions and 66 deletions

View File

@ -239,7 +239,7 @@ bdb2_back_add(
bdb2i_start_timing( be->bd_info, &time1 );
if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) {
if ( bdb2i_enter_backend_w( &lock ) != 0 ) {
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
return( -1 );
@ -261,7 +261,7 @@ bdb2_back_add(
ret = bdb2i_back_add_internal( be, conn, op, e );
bdb2i_stop_timing( be->bd_info, time2, "ADD-INTERN", conn, op );
(void) bdb2i_leave_backend_w( get_dbenv( be ), lock );
(void) bdb2i_leave_backend_w( lock );
bdb2i_stop_timing( be->bd_info, time1, "ADD", conn, op );
return( ret );

View File

@ -32,7 +32,6 @@ Entry *bdb2i_derefAlias_r ( BackendDB *be,
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
Attribute *a;
int depth;
char **pastAliases;
char *matched;
Entry *origDN = e;
@ -76,7 +75,7 @@ Entry *bdb2i_derefAlias_r ( BackendDB *be,
Debug( LDAP_DEBUG_TRACE,
"<= %s alias is same as current %s\n",
oldDN, newDN, 0 );
send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM, "",
send_ldap_result( conn, op, LDAP_ALIAS_DEREF_PROBLEM, "",
"Circular alias" );
free (newDN);
free (oldDN);
@ -88,7 +87,7 @@ Entry *bdb2i_derefAlias_r ( BackendDB *be,
Debug( LDAP_DEBUG_TRACE,
"<= %s alias is same as original %s\n",
oldDN, origDN->e_ndn, 0 );
send_ldap_result( conn, op, LDAP_ALIAS_PROBLEM, "",
send_ldap_result( conn, op, LDAP_ALIAS_DEREF_PROBLEM, "",
"Circular alias" );
free (newDN);
free (oldDN);

View File

@ -154,6 +154,9 @@ typedef struct _bdb2_txn_head {
int withDefIDX;
#define BDB2_WITH_DEF_IDX 1
/* a handle for the backend's environment */
DB_ENV **dbenvH;
} BDB2_TXN_HEAD;
@ -165,15 +168,14 @@ struct ldbtype {
char *lty_dbhome;
size_t lty_mpsize;
int lty_betiming;
/* XXX do we need a private DB_ENV for all DB2 backend types ? */
DB_ENV *lty_dbenv;
};
#define get_dbenv(be) ((struct ldbtype *) (be)->bd_info->bi_private)->lty_dbenv
#define with_timing(bi) (((struct ldbtype *) \
(bi)->bi_private)->lty_betiming == 1)
/* The DB environment */
extern DB_ENV bdb2i_dbEnv;
/* the private description of a database */
struct ldbminfo {

View File

@ -120,6 +120,7 @@ bdb2i_back_bind_internal(
goto return_results;
}
/* check for root dn/passwd */
if ( be_isroot_pw( be, dn, cred ) ) {
/* front end will send result */
if( *edn != NULL ) free( *edn );
@ -131,6 +132,8 @@ bdb2i_back_bind_internal(
if ( (a = attr_find( e->e_attrs, "userpassword" )) == NULL ) {
send_ldap_result( conn, op, LDAP_INAPPROPRIATE_AUTH,
NULL, NULL );
/* stop front end from sending result */
rc = 1;
goto return_results;
}
@ -139,6 +142,7 @@ bdb2i_back_bind_internal(
{
send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS,
NULL, NULL );
/* stop front end from sending result */
rc = 1;
goto return_results;
}
@ -224,7 +228,7 @@ bdb2_back_bind(
bdb2i_start_timing( be->bd_info, &time1 );
if ( bdb2i_enter_backend_r( get_dbenv( be ), &lock ) != 0 ) {
if ( bdb2i_enter_backend_r( &lock ) != 0 ) {
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
return( 1 );
@ -233,7 +237,7 @@ bdb2_back_bind(
ret = bdb2i_back_bind_internal( be, conn, op, dn, method, cred, edn );
(void) bdb2i_leave_backend_r( get_dbenv( be ), lock );
(void) bdb2i_leave_backend_r( lock );
bdb2i_stop_timing( be->bd_info, time1, "BIND", conn, op );

View File

@ -16,7 +16,7 @@ bdb2i_back_db_close_internal( BackendDB *be )
/* since close will probably write the NEXTID file,
wee need transaction control */
if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) {
if ( bdb2i_enter_backend_w( &lock ) != 0 ) {
return( -1 );
}
@ -31,8 +31,8 @@ bdb2i_back_db_close_internal( BackendDB *be )
/* before closing all files, leave the backend (thus commiting
all writes) and set a last checkpoint */
(void) bdb2i_leave_backend_w( get_dbenv( be ), lock );
(void) bdb2i_set_txn_checkpoint( get_dbenv( be )->tx_info, 1 );
(void) bdb2i_leave_backend_w( lock );
(void) bdb2i_set_txn_checkpoint( bdb2i_dbEnv.tx_info, 1 );
/* close all DB files */
Debug( LDAP_DEBUG_TRACE, "bdb2 backend closing DB files\n", 0, 0, 0 );

View File

@ -78,7 +78,7 @@ bdb2_back_compare(
bdb2i_start_timing( be->bd_info, &time1 );
if ( bdb2i_enter_backend_r( get_dbenv( be ), &lock ) != 0 ) {
if ( bdb2i_enter_backend_r( &lock ) != 0 ) {
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
return( 1 );
@ -86,7 +86,7 @@ bdb2_back_compare(
}
ret = bdb2i_back_compare_internal( be, conn, op, dn, ava );
(void) bdb2i_leave_backend_r( get_dbenv( be ), lock );
(void) bdb2i_leave_backend_r( lock );
bdb2i_stop_timing( be->bd_info, time1, "CMP", conn, op );
return( ret );

View File

@ -156,7 +156,7 @@ bdb2_back_delete(
bdb2i_start_timing( be->bd_info, &time1 );
if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) {
if ( bdb2i_enter_backend_w( &lock ) != 0 ) {
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
return( -1 );
@ -164,7 +164,7 @@ bdb2_back_delete(
}
ret = bdb2i_back_delete_internal( be, conn, op, dn );
(void) bdb2i_leave_backend_w( get_dbenv( be ), lock );
(void) bdb2i_leave_backend_w( lock );
bdb2i_stop_timing( be->bd_info, time1, "DEL", conn, op );
return( ret );

View File

@ -141,7 +141,7 @@ bdb2_back_group(
bdb2i_start_timing( be->bd_info, &time1 );
if ( bdb2i_enter_backend_r( get_dbenv( be ), &lock ) != 0 ) {
if ( bdb2i_enter_backend_r( &lock ) != 0 ) {
return( 1 );
@ -150,7 +150,7 @@ bdb2_back_group(
ret = bdb2i_back_group_internal( be, target, gr_ndn, op_ndn,
objectclassValue, groupattrName );
(void) bdb2i_leave_backend_r( get_dbenv( be ), lock );
(void) bdb2i_leave_backend_r( lock );
bdb2i_stop_timing( be->bd_info, time1, "GRP", NULL, NULL );
return( ret );

View File

@ -23,7 +23,6 @@ bdb2i_back_init_private(
bt->lty_dbhome = DEFAULT_DB_HOME;
bt->lty_mpsize = DEFAULT_DBCACHE_SIZE;
bt->lty_dbenv = &ldbm_Env;
if ( slapMode == SLAP_TIMEDSERVER_MODE )
bt->lty_betiming = 1;

View File

@ -128,7 +128,7 @@ bdb2_back_modify(
bdb2i_start_timing( be->bd_info, &time1 );
if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) {
if ( bdb2i_enter_backend_w( &lock ) != 0 ) {
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
return( -1 );
@ -147,7 +147,7 @@ bdb2_back_modify(
}
ret = bdb2i_back_modify_internal( be, conn, op, dn, modlist );
(void) bdb2i_leave_backend_w( get_dbenv( be ), lock );
(void) bdb2i_leave_backend_w( lock );
bdb2i_stop_timing( be->bd_info, time1, "MOD", conn, op );
return( ret );

View File

@ -214,7 +214,7 @@ bdb2_back_modrdn(
bdb2i_start_timing( be->bd_info, &time1 );
if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) {
if ( bdb2i_enter_backend_w( &lock ) != 0 ) {
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
return( -1 );
@ -225,7 +225,7 @@ bdb2_back_modrdn(
newrdn, deleteoldrdn,
newSuperior );
(void) bdb2i_leave_backend_w( get_dbenv( be ), lock );
(void) bdb2i_leave_backend_w( lock );
bdb2i_stop_timing( be->bd_info, time1, "MODRDN", conn, op );
return( ret );

View File

@ -14,7 +14,7 @@
int
bdb2i_enter_backend_rw( DB_ENV *dbEnv, DB_LOCK *lock, int writer )
bdb2i_enter_backend_rw( DB_LOCK *lock, int writer )
{
u_int32_t locker;
db_lockmode_t lock_type;
@ -27,7 +27,7 @@ bdb2i_enter_backend_rw( DB_ENV *dbEnv, DB_LOCK *lock, int writer )
case SLAP_TIMEDSERVER_MODE:
case SLAP_TOOL_MODE:
case SLAP_TOOLID_MODE:
if ( ( ret = lock_id( dbEnv->lk_info, &locker )) != 0 ) {
if ( ( ret = lock_id( bdb2i_dbEnv.lk_info, &locker )) != 0 ) {
Debug( LDAP_DEBUG_ANY,
"bdb2i_enter_backend(): unable to get locker id -- %s\n",
@ -40,8 +40,8 @@ bdb2i_enter_backend_rw( DB_ENV *dbEnv, DB_LOCK *lock, int writer )
lock_dbt.data = PORTER_OBJ;
lock_dbt.size = strlen( PORTER_OBJ );
switch ( ( ret = lock_get( dbEnv->lk_info, locker, 0, &lock_dbt,
lock_type, lock ))) {
switch ( ( ret = lock_get( bdb2i_dbEnv.lk_info, locker, 0,
&lock_dbt, lock_type, lock ))) {
case 0:
Debug( LDAP_DEBUG_TRACE,
@ -76,7 +76,7 @@ bdb2i_enter_backend_rw( DB_ENV *dbEnv, DB_LOCK *lock, int writer )
start transaction control */
if ( writer && ( ret == 0 )) {
ret = bdb2i_start_transction( dbEnv->tx_info );
ret = bdb2i_start_transction( bdb2i_dbEnv.tx_info );
}
@ -85,7 +85,7 @@ bdb2i_enter_backend_rw( DB_ENV *dbEnv, DB_LOCK *lock, int writer )
int
bdb2i_leave_backend_rw( DB_ENV *dbEnv, DB_LOCK lock, int writer )
bdb2i_leave_backend_rw( DB_LOCK lock, int writer )
{
/* since one or more error can occure,
we must have several return codes that are or'ed at the end */
@ -101,7 +101,7 @@ bdb2i_leave_backend_rw( DB_ENV *dbEnv, DB_LOCK lock, int writer )
}
/* check whether checkpointing is needed */
ret_transaction |= bdb2i_set_txn_checkpoint( dbEnv->tx_info, 0 );
ret_transaction |= bdb2i_set_txn_checkpoint( bdb2i_dbEnv.tx_info, 0 );
/* now release the lock */
switch ( slapMode ) {
@ -110,7 +110,7 @@ bdb2i_leave_backend_rw( DB_ENV *dbEnv, DB_LOCK lock, int writer )
case SLAP_TIMEDSERVER_MODE:
case SLAP_TOOL_MODE:
case SLAP_TOOLID_MODE:
switch( ( ret_lock = lock_put( dbEnv->lk_info, lock ))) {
switch( ( ret_lock = lock_put( bdb2i_dbEnv.lk_info, lock ))) {
case 0:
Debug( LDAP_DEBUG_TRACE,

View File

@ -173,12 +173,12 @@ void bdb2i_uncond_stop_timing LDAP_P(( struct timeval time1,
* porter.c
*/
int bdb2i_enter_backend_rw LDAP_P(( DB_ENV *dbEnv, DB_LOCK *lock, int writer ));
#define bdb2i_enter_backend_r(dbEnv,lock) bdb2i_enter_backend_rw( (dbEnv), (lock), 0 )
#define bdb2i_enter_backend_w(dbEnv,lock) bdb2i_enter_backend_rw( (dbEnv), (lock), 1 )
int bdb2i_leave_backend_rw LDAP_P(( DB_ENV *dbEnv, DB_LOCK lock, int writer ));
#define bdb2i_leave_backend_r(dbEnv,lock) bdb2i_leave_backend_rw( (dbEnv), (lock), 0 )
#define bdb2i_leave_backend_w(dbEnv,lock) bdb2i_leave_backend_rw( (dbEnv), (lock), 1 )
int bdb2i_enter_backend_rw LDAP_P(( DB_LOCK *lock, int writer ));
#define bdb2i_enter_backend_r(lock) bdb2i_enter_backend_rw((lock), 0 )
#define bdb2i_enter_backend_w(lock) bdb2i_enter_backend_rw((lock), 1 )
int bdb2i_leave_backend_rw LDAP_P(( DB_LOCK lock, int writer ));
#define bdb2i_leave_backend_r(lock) bdb2i_leave_backend_rw((lock), 0 )
#define bdb2i_leave_backend_w(lock) bdb2i_leave_backend_rw((lock), 1 )
/*
* txn.c
@ -203,6 +203,8 @@ void bdb2i_check_default_attr_index_mod LDAP_P((
LDAPModList *modlist ));
ID bdb2i_get_nextid LDAP_P(( BackendDB *be ));
int bdb2i_put_nextid LDAP_P(( BackendDB *be, ID id ));
LDBM bdb2i_db_open LDAP_P(( char *name, int type, int rw, int mode,
int dbcachesize ));
int bdb2i_db_store LDAP_P(( LDBM ldbm, Datum key, Datum data, int flags ));
int bdb2i_db_delete LDAP_P(( LDBM ldbm, Datum key ));
Datum bdb2i_db_fetch LDAP_P(( LDBM ldbm, Datum key ));

View File

@ -337,7 +337,7 @@ bdb2_back_search(
bdb2i_start_timing( be->bd_info, &time1 );
if ( bdb2i_enter_backend_r( get_dbenv( be ), &lock ) != 0 ) {
if ( bdb2i_enter_backend_r( &lock ) != 0 ) {
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
return( -1 );
@ -347,7 +347,7 @@ bdb2_back_search(
ret = bdb2i_back_search_internal( be, conn, op, base, scope, deref,
slimit, tlimit, filter, filterstr, attrs, attrsonly );
(void) bdb2i_leave_backend_r( get_dbenv( be ), lock );
(void) bdb2i_leave_backend_r( lock );
bdb2i_stop_timing( be->bd_info, time1, "SRCH", conn, op );
return( ret );

View File

@ -31,7 +31,6 @@ bdb2i_back_startup_internal(
)
{
struct ldbtype *lty = (struct ldbtype *) bi->bi_private;
DB_ENV *dbEnv = lty->lty_dbenv;
int envFlags;
int err = 0;
char *home;
@ -53,21 +52,21 @@ bdb2i_back_startup_internal(
home = lty->lty_dbhome;
/* general initialization of the environment */
memset( dbEnv, 0, sizeof( DB_ENV ));
dbEnv->db_errcall = bdb2i_db_errcall;
dbEnv->db_errpfx = "==>";
memset( &bdb2i_dbEnv, 0, sizeof( DB_ENV ));
bdb2i_dbEnv.db_errcall = bdb2i_db_errcall;
bdb2i_dbEnv.db_errpfx = "==>";
/* initialize the lock subsystem */
dbEnv->lk_max = 0;
bdb2i_dbEnv.lk_max = 0;
/* remove old locking tables */
remove_old_locks( home );
/* initialize the mpool subsystem */
dbEnv->mp_size = lty->lty_mpsize;
bdb2i_dbEnv.mp_size = lty->lty_mpsize;
/* now do the db_appinit */
if ( ( err = db_appinit( home, NULL, dbEnv, envFlags )) ) {
if ( ( err = db_appinit( home, NULL, &bdb2i_dbEnv, envFlags )) ) {
char error[BUFSIZ];
if ( err < 0 ) sprintf( error, "%ld\n", (long) err );
@ -90,22 +89,21 @@ bdb2i_back_shutdown_internal(
)
{
struct ldbtype *lty = (struct ldbtype *) bi->bi_private;
DB_ENV *dbEnv = lty->lty_dbenv;
int err;
/* remove old locking tables */
dbEnv->db_errpfx = "bdb2i_back_shutdown(): lock_unlink:";
if ( ( err = lock_unlink( NULL, 1, dbEnv )) != 0 )
bdb2i_dbEnv.db_errpfx = "bdb2i_back_shutdown(): lock_unlink:";
if ( ( err = lock_unlink( NULL, 1, &bdb2i_dbEnv )) != 0 )
Debug( LDAP_DEBUG_ANY, "bdb2i_back_shutdown(): lock_unlink: %s\n",
strerror( err ), 0, 0);
/* remove old memory pool */
dbEnv->db_errpfx = "bdb2i_back_shutdown(): memp_unlink:";
if ( ( err = memp_unlink( NULL, 1, dbEnv )) != 0 )
bdb2i_dbEnv.db_errpfx = "bdb2i_back_shutdown(): memp_unlink:";
if ( ( err = memp_unlink( NULL, 1, &bdb2i_dbEnv )) != 0 )
Debug( LDAP_DEBUG_ANY, "bdb2i_back_shutdown(): memp_unlink: %s\n",
strerror( err ), 0, 0);
(void) db_appexit( dbEnv );
(void) db_appexit( &bdb2i_dbEnv );
return( 0 );
}

View File

@ -137,7 +137,8 @@ bdb2i_txn_attr_config(
li->li_directory, DEFAULT_DIRSEP, p->dbc_name );
/* since we have an mpool, we should not define a cache size */
p->dbc_db = ldbm_open( fileName, LDBM_WRCREAT, li->li_mode, 0 );
p->dbc_db = bdb2i_db_open( fileName, DB_TYPE,
LDBM_WRCREAT, li->li_mode, 0 );
/* if the files could not be opened, something is wrong;
complain */
@ -177,7 +178,6 @@ bdb2i_open_nextid( BackendDB *be )
BDB2_TXN_HEAD *head = &li->li_txn_head;
LDBM db = NULL;
DB_INFO dbinfo;
DB_ENV *dbenv = get_dbenv( be );
char fileName[MAXPATHLEN];
sprintf( fileName, "%s%s%s",
@ -189,7 +189,7 @@ bdb2i_open_nextid( BackendDB *be )
dbinfo.db_malloc = ldbm_malloc;
(void) db_open( fileName, DB_RECNO, DB_CREATE | DB_THREAD,
li->li_mode, dbenv, &dbinfo, &db );
li->li_mode, &bdb2i_dbEnv, &dbinfo, &db );
if ( db == NULL ) {
@ -228,7 +228,8 @@ bdb2i_txn_open_files( BackendDB *be )
li->li_directory, DEFAULT_DIRSEP, dbFile->dbc_name );
/* since we have an mpool, we should not define a cache size */
dbFile->dbc_db = ldbm_open( fileName, LDBM_WRCREAT, li->li_mode, 0 );
dbFile->dbc_db = bdb2i_db_open( fileName, DB_TYPE,
LDBM_WRCREAT, li->li_mode, 0 );
/* if the files could not be opened, something is wrong; complain */
if ( dbFile->dbc_db == NULL ) {
@ -476,7 +477,30 @@ bdb2i_put_nextid( BackendDB *be, ID id )
}
/* BDB2 backend-private functions of ldbm_store and ldbm_delete */
/* BDB2 backend-private functions of libldbm */
LDBM
bdb2i_db_open(
char *name,
int type,
int rw,
int mode,
int dbcachesize )
{
LDBM ret = NULL;
DB_INFO dbinfo;
memset( &dbinfo, 0, sizeof( dbinfo ));
if ( bdb2i_dbEnv.mp_info == NULL )
dbinfo.db_cachesize = dbcachesize;
dbinfo.db_pagesize = DEFAULT_DB_PAGE_SIZE;
dbinfo.db_malloc = ldbm_malloc;
(void) db_open( name, type, rw, mode, &bdb2i_dbEnv, &dbinfo, &ret );
return( ret );
}
int
bdb2i_db_store( LDBM ldbm, Datum key, Datum data, int flags )
{
@ -595,11 +619,12 @@ bdb2i_db_firstkey( LDBM ldbm, DBC **dbch )
txn_do_abort = 1;
}
key.flags = 0;
return( key );
} else {
*dbch = dbci;
if ( (*dbci->c_get)( dbci, &key, &data, DB_NEXT ) == 0 ) {
if ( data.dptr ) free( data.dptr );
ldbm_datum_free( ldbm, data );
} else {
if ( txnid != NULL ) {
@ -609,7 +634,8 @@ bdb2i_db_firstkey( LDBM ldbm, DBC **dbch )
txn_do_abort = 1;
}
if ( key.dptr ) free( key.dptr );
ldbm_datum_free( ldbm, key );
key.flags = 0;
key.dptr = NULL;
key.dsize = 0;
}
@ -624,13 +650,12 @@ bdb2i_db_nextkey( LDBM ldbm, Datum key, DBC *dbcp )
{
Datum data;
int rc;
void *oldKey = key.dptr;
ldbm_datum_init( data );
data.flags = DB_DBT_MALLOC;
key.flags = data.flags = DB_DBT_MALLOC;
if ( (*dbcp->c_get)( dbcp, &key, &data, DB_NEXT ) == 0 ) {
if ( data.dptr ) free( data.dptr );
ldbm_datum_free( ldbm, data );
} else {
if ( txnid != NULL ) {
@ -640,12 +665,11 @@ bdb2i_db_nextkey( LDBM ldbm, Datum key, DBC *dbcp )
txn_do_abort = 1;
}
key.flags = 0;
key.dptr = NULL;
key.dsize = 0;
}
if ( oldKey ) free( oldKey );
return( key );
}

View File

@ -22,6 +22,10 @@
/* the DB environment for the backend */
DB_ENV bdb2i_dbEnv;
/* variables for transaction support */
DB_TXN *txnid = NULL;
int txn_do_abort = 0;