From: Randy Kunkee Date: Thu, 21 Jun 2001 18:54:56 +0000 (+0000) Subject: Patches from Mark Whitehouse (with changes from myself) to make the X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~1298 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=1656f2c774d36a725999761f3a7b903f90b435d2;p=openldap Patches from Mark Whitehouse (with changes from myself) to make the dbcachesize setting actually work for db-3.2.9. --- diff --git a/include/ldbm.h b/include/ldbm.h index b306c0e9ee..56e9282983 100644 --- a/include/ldbm.h +++ b/include/ldbm.h @@ -16,6 +16,11 @@ #include +/* dummy DB_ENV for non Berkeley DB */ +#if !defined( LDBM_USE_DBBTREE ) && !defined( LDBM_USE_DBHASH ) +# define DB_ENV void +#endif + #if defined( LDBM_USE_DBBTREE ) || defined( LDBM_USE_DBHASH ) /***************************************************************** @@ -49,6 +54,8 @@ # ifndef DEFAULT_DB_PAGE_SIZE # define DEFAULT_DB_PAGE_SIZE 4096 # endif +#else +# define DB_ENV void #endif @@ -240,8 +247,11 @@ LDAP_BEGIN_DECL LDAP_LDBM_F (int) ldbm_initialize( const char * ); LDAP_LDBM_F (int) ldbm_shutdown( void ); +LDAP_LDBM_F (DB_ENV*) ldbm_initialize_env(const char *, int dbcachesize, int *envdirok); +LDAP_LDBM_F (void) ldbm_shutdown_env(DB_ENV *); + LDAP_LDBM_F (int) ldbm_errno( LDBM ldbm ); -LDAP_LDBM_F (LDBM) ldbm_open( char *name, int rw, int mode, int dbcachesize ); +LDAP_LDBM_F (LDBM) ldbm_open( DB_ENV *env, char *name, int rw, int mode, int dbcachesize ); LDAP_LDBM_F (void) ldbm_close( LDBM ldbm ); LDAP_LDBM_F (void) ldbm_sync( LDBM ldbm ); LDAP_LDBM_F (void) ldbm_datum_free( LDBM ldbm, Datum data ); diff --git a/libraries/libldbm/ldbm.c b/libraries/libldbm/ldbm.c index baaa1c7922..8b09ff6e6a 100644 --- a/libraries/libldbm/ldbm.c +++ b/libraries/libldbm/ldbm.c @@ -69,6 +69,11 @@ static ldap_pvt_thread_mutex_t ldbm_big_mutex; #define LDBM_UNLOCK (ldap_pvt_thread_mutex_unlock(&ldbm_big_mutex)) #endif +#if !defined( HAVE_BERKELEY_DB ) || (DB_VERSION_MAJOR < 3) + /* a dbEnv for BERKELEYv2 */ +DB_ENV *ldbm_Env = NULL; /* real or fake, depending on db and version */ +#endif + /******************************************************************* * * @@ -96,8 +101,7 @@ ldbm_db_errcall( const char *prefix, char *message ) #endif } -/* a dbEnv for BERKELEYv2 */ -DB_ENV *ldbm_Env = NULL; +#if DB_VERSION_MAJOR < 3 int ldbm_initialize( const char* home ) { @@ -133,16 +137,12 @@ int ldbm_initialize( const char* home ) ldap_pvt_thread_mutex_init( &ldbm_big_mutex ); #endif -#if DB_VERSION_MAJOR < 3 ldbm_Env = calloc( 1, sizeof( DB_ENV )); if( ldbm_Env == NULL ) return 1; ldbm_Env->db_errcall = ldbm_db_errcall; ldbm_Env->db_errpfx = "==>"; -#else - ldbm_Env = NULL; -#endif envFlags = DB_CREATE; @@ -158,12 +158,8 @@ int ldbm_initialize( const char* home ) #endif #endif -#if DB_VERSION_MAJOR >= 3 - err = db_env_create( &ldbm_Env, 0 ); -#else envFlags |= DB_USE_ENVIRON; err = db_appinit( home, NULL, ldbm_Env, envFlags ); -#endif if ( err ) { #ifdef LDAP_SYSLOG @@ -172,45 +168,12 @@ int ldbm_initialize( const char* home ) sprintf( error, "%s (%d)\n", STRERROR( err ), err ); syslog( LOG_INFO, -#if DB_VERSION_MAJOR >= 3 - "ldbm_initialize(): FATAL error in db_env_create() : %s\n", -#else "ldbm_initialize(): FATAL error in db_appinit() : %s\n", -#endif error ); #endif return( 1 ); } -#if DB_VERSION_MAJOR > 2 - ldbm_Env->set_errcall( ldbm_Env, ldbm_db_errcall ); - ldbm_Env->set_errpfx( ldbm_Env, "==>" ); - -#ifdef HAVE_BERKELEY_DB_THREAD - envFlags |= DB_INIT_CDB | DB_INIT_MPOOL; -#endif - envFlags |= DB_USE_ENVIRON; - -#if (DB_VERSION_MAJOR > 3) || (DB_VERSION_MINOR >= 1) - err = ldbm_Env->open( ldbm_Env, home, envFlags, 0 ); -#else - err = ldbm_Env->open( ldbm_Env, home, NULL, envFlags, 0 ); -#endif - - if ( err != 0 ) { -#ifdef LDAP_SYSLOG - char error[BUFSIZ]; - - sprintf( error, "%s (%d)\n", STRERROR( err ), err ); - syslog( LOG_INFO, - "ldbm_initialize(): FATAL error in dbEnv->open() : %s\n", - error ); -#endif - ldbm_Env->close( ldbm_Env, 0 ); - return( 1 ); - } -#endif - return 0; } @@ -218,11 +181,7 @@ int ldbm_shutdown( void ) { if( !ldbm_initialized ) return 1; -#if DB_VERSION_MAJOR >= 3 - ldbm_Env->close( ldbm_Env, 0 ); -#else db_appexit( ldbm_Env ); -#endif #ifndef HAVE_BERKELEY_DB_THREAD ldap_pvt_thread_mutex_destroy( &ldbm_big_mutex ); @@ -231,6 +190,26 @@ int ldbm_shutdown( void ) return 0; } +#else /* Berkeley v3 or greater */ + + +int ldbm_initialize( const char * home ) +{ + /* v3 uses ldbm_initialize_env */ + return 0; +} + + +int ldbm_shutdown( void ) +{ + return 0; +} + + +#endif + + + #else /* some DB other than Berkeley V2 or greater */ int ldbm_initialize( const char * home ) @@ -254,6 +233,86 @@ int ldbm_shutdown( void ) #endif /* HAVE_BERKELEY_DB */ +#if defined( HAVE_BERKELEY_DB ) && (DB_VERSION_MAJOR >= 3) + + +DB_ENV *ldbm_initialize_env(const char *home, int dbcachesize, int *envdirok) +{ + DB_ENV *env = NULL; + int err; + u_int32_t envFlags; + + envFlags = +#if defined( DB_PRIVATE ) + DB_PRIVATE | +#endif +#if defined( HAVE_BERKELEY_DB_THREAD ) + DB_THREAD | +#endif + DB_CREATE; + + err = db_env_create( &env, 0 ); + + if ( err ) { + char error[BUFSIZ]; + + sprintf( error, "%s (%d)\n", STRERROR( err ), err ); + +#ifdef LDAP_SYSLOG + syslog( LOG_INFO, "ldbm_initialize_env(): FATAL error in db_env_create() : %s\n", error ); +#endif + return( NULL ); + } + + env->set_cachesize( env, 0, dbcachesize, 0 ); + + env->set_errcall( env, ldbm_db_errcall ); + env->set_errpfx( env, "==>" ); + + envFlags |= DB_INIT_MPOOL | DB_INIT_CDB | DB_USE_ENVIRON; + + err = env->open( env, home, envFlags, 0 ); + + if ( err != 0 ) + { + char error[BUFSIZ]; + + sprintf( error, "%s (%d)\n", STRERROR( err ), err ); + +#ifdef LDAP_SYSLOG + syslog( LOG_INFO, + "ldbm_initialize_env(): FATAL error in dbEnv->open() : %s\n", + error ); +#endif + env->close( env, 0 ); + return( NULL ); + } + + *envdirok = 1; + return env; +} + +void ldbm_shutdown_env(DB_ENV *env) +{ + env->close( env, 0 ); +} + + +#else + +DB_ENV *ldbm_initialize_env(const char *home, int dbcachesize, int *envdirok) +{ + return ldbm_Env; +} + +void ldbm_shutdown_env(DB_ENV *env) +{ +} + + +#endif + + #if defined( LDBM_USE_DBHASH ) || defined( LDBM_USE_DBBTREE ) /***************************************************************** @@ -263,7 +322,7 @@ int ldbm_shutdown( void ) *****************************************************************/ LDBM -ldbm_open( char *name, int rw, int mode, int dbcachesize ) +ldbm_open( DB_ENV *env, char *name, int rw, int mode, int dbcachesize ) { LDBM ret = NULL; @@ -272,7 +331,7 @@ ldbm_open( char *name, int rw, int mode, int dbcachesize ) LDBM_LOCK; - err = db_create( &ret, ldbm_Env, 0 ); + err = db_create( &ret, env, 0 ); if ( err != 0 ) { (void)ret->close(ret, 0); LDBM_UNLOCK; @@ -282,6 +341,7 @@ ldbm_open( char *name, int rw, int mode, int dbcachesize ) ret->set_pagesize( ret, DEFAULT_DB_PAGE_SIZE ); ret->set_malloc( ret, ldbm_malloc ); + ret->set_cachesize( ret, 0, dbcachesize, 0 ); err = ret->open( ret, name, NULL, DB_TYPE, rw, mode); @@ -581,7 +641,7 @@ ldbm_errno( LDBM ldbm ) *****************************************************************/ LDBM -ldbm_open( char *name, int rw, int mode, int dbcachesize ) +ldbm_open( DB_ENV *env, char *name, int rw, int mode, int dbcachesize ) { LDBM db; #ifdef HAVE_ST_BLKSIZE @@ -755,7 +815,7 @@ ldbm_errno( LDBM ldbm ) *****************************************************************/ LDBM -ldbm_open( char *name, int rw, int mode, int dbcachesize ) +ldbm_open( DB_ENV *env, char *name, int rw, int mode, int dbcachesize ) { LDBM db; @@ -1063,7 +1123,7 @@ ldbm_errno( LDBM ldbm ) /* ARGSUSED */ LDBM -ldbm_open( char *name, int rw, int mode, int dbcachesize ) +ldbm_open( DB_ENV *env, char *name, int rw, int mode, int dbcachesize ) { LDBM ldbm; diff --git a/servers/slapd/back-ldbm/back-ldbm.h b/servers/slapd/back-ldbm/back-ldbm.h index 04ef6c4637..2272579d1b 100644 --- a/servers/slapd/back-ldbm/back-ldbm.h +++ b/servers/slapd/back-ldbm/back-ldbm.h @@ -117,6 +117,8 @@ struct ldbminfo { DBCache li_dbcache[MAXDBCACHE]; ldap_pvt_thread_mutex_t li_dbcache_mutex; ldap_pvt_thread_cond_t li_dbcache_cv; + DB_ENV *li_dbenv; + int li_envdirok; }; struct ldbm_backend_info { diff --git a/servers/slapd/back-ldbm/dbcache.c b/servers/slapd/back-ldbm/dbcache.c index 2a57127a3e..3646d6967d 100644 --- a/servers/slapd/back-ldbm/dbcache.c +++ b/servers/slapd/back-ldbm/dbcache.c @@ -34,8 +34,11 @@ ldbm_cache_open( struct stat st; #endif - sprintf( buf, "%s" LDAP_DIRSEP "%s%s", - li->li_directory, name, suffix ); + if (li->li_envdirok) + sprintf( buf, "%s%s", name, suffix ); + else + sprintf( buf, "%s" LDAP_DIRSEP "%s%s", + li->li_directory, name, suffix ); if( li->li_dblocking ) { flags |= LDBM_LOCKING; @@ -146,7 +149,7 @@ ldbm_cache_open( } } while (i == MAXDBCACHE); - if ( (li->li_dbcache[i].dbc_db = ldbm_open( buf, flags, li->li_mode, + if ( (li->li_dbcache[i].dbc_db = ldbm_open( li->li_dbenv, buf, flags, li->li_mode, li->li_dbcachesize )) == NULL ) { int err = errno; diff --git a/servers/slapd/back-ldbm/init.c b/servers/slapd/back-ldbm/init.c index 0d339543d4..72eae52437 100644 --- a/servers/slapd/back-ldbm/init.c +++ b/servers/slapd/back-ldbm/init.c @@ -160,6 +160,12 @@ ldbm_back_db_init( /* default database directory */ li->li_directory = ch_strdup( DEFAULT_DB_DIRECTORY ); + /* DB_ENV environment pointer for DB3 */ + li->li_dbenv = 0; + + /* envdirok is turned on by ldbm_initialize_env if DB3 */ + li->li_envdirok = 0; + /* initialize various mutex locks & condition variables */ ldap_pvt_thread_mutex_init( &li->li_root_mutex ); ldap_pvt_thread_mutex_init( &li->li_add_mutex ); @@ -178,6 +184,9 @@ ldbm_back_db_open( BackendDB *be ) { + struct ldbminfo *li = (struct ldbminfo *) be->be_private; + li->li_dbenv = ldbm_initialize_env(li->li_directory, + li->li_dbcachesize, &li->li_envdirok); return 0; } @@ -188,6 +197,9 @@ ldbm_back_db_destroy( { /* should free/destroy every in be_private */ struct ldbminfo *li = (struct ldbminfo *) be->be_private; + + ldbm_shutdown_env(li->li_dbenv); + free( li->li_directory ); attr_index_destroy( li->li_attrs );