From: Kurt Spanier Date: Wed, 10 Feb 1999 13:19:11 +0000 (+0000) Subject: Elimination of un-used code in bdb2i_cache_open and friends. X-Git-Tag: OPENLDAP_SLAPD_BACK_LDAP~602 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=529caeddd05463045cb44b60fa314d2f5dc8791a;p=openldap Elimination of un-used code in bdb2i_cache_open and friends. Provision for a bdb2 backend-specific DB file suffix. Fix of the double-open of backend types. --- diff --git a/servers/slapd/back-bdb2/back-bdb2.h b/servers/slapd/back-bdb2/back-bdb2.h index 31acd5a7ac..715dfd6485 100644 --- a/servers/slapd/back-bdb2/back-bdb2.h +++ b/servers/slapd/back-bdb2/back-bdb2.h @@ -20,6 +20,9 @@ LDAP_BEGIN_DECL #define SUBLEN 3 +#define BDB2_SUFFIX ".dbb" + + /* * there is a single index for each attribute. these prefixes insure * that there is no collision among keys. diff --git a/servers/slapd/back-bdb2/dbcache.c b/servers/slapd/back-bdb2/dbcache.c index 038d4b050e..5044fbb860 100644 --- a/servers/slapd/back-bdb2/dbcache.c +++ b/servers/slapd/back-bdb2/dbcache.c @@ -27,15 +27,10 @@ bdb2i_cache_open( int flags ) { - struct ldbminfo *li = (struct ldbminfo *) be->be_private; - int i, lru; - time_t oldtime, curtime; - char buf[MAXPATHLEN]; - LDBM db; - struct stat st; - - /* if in slapd, all files are open, so return handle from file cache */ + /* all files are open, so return handle from file cache */ if ( ( slapMode == SLAP_SERVER_MODE ) || ( slapMode == SLAP_TOOL_MODE ) ) { + struct ldbminfo *li = (struct ldbminfo *) be->be_private; + char buf[MAXPATHLEN]; /* use short name */ sprintf( buf, "%s%s", name, suffix ); @@ -43,111 +38,29 @@ bdb2i_cache_open( } - /* use the absolute path */ - sprintf( buf, "%s%s%s%s", li->li_directory, DEFAULT_DIRSEP, name, suffix ); - - Debug( LDAP_DEBUG_TRACE, "=> bdb2i_cache_open( \"%s\", %d, %o )\n", buf, - flags, li->li_mode ); - - lru = 0; - ldap_pvt_thread_mutex_lock( ¤ttime_mutex ); - curtime = currenttime; - ldap_pvt_thread_mutex_unlock( ¤ttime_mutex ); - oldtime = curtime; - - ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex ); - for ( i = 0; i < MAXDBCACHE && li->li_dbcache[i].dbc_name != NULL; - i++ ) { - /* already open - return it */ - if ( strcmp( li->li_dbcache[i].dbc_name, buf ) == 0 ) { - li->li_dbcache[i].dbc_refcnt++; - Debug( LDAP_DEBUG_TRACE, - "<= bdb2i_cache_open (cache %d)\n", i, 0, 0 ); - ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex ); - return( &li->li_dbcache[i] ); - } - - /* keep track of lru db */ - if ( li->li_dbcache[i].dbc_lastref < oldtime && - li->li_dbcache[i].dbc_refcnt == 0 ) { - lru = i; - oldtime = li->li_dbcache[i].dbc_lastref; - } - } - - /* no empty slots, not already open - close lru and use that slot */ - if ( i == MAXDBCACHE ) { - i = lru; - if ( li->li_dbcache[i].dbc_refcnt != 0 ) { - Debug( LDAP_DEBUG_ANY, - "bdb2i_cache_open no unused db to close - waiting\n", - 0, 0, 0 ); - lru = -1; - while ( lru == -1 ) { - ldap_pvt_thread_cond_wait( &li->li_dbcache_cv, - &li->li_dbcache_mutex ); - for ( i = 0; i < MAXDBCACHE; i++ ) { - if ( li->li_dbcache[i].dbc_refcnt - == 0 ) { - lru = i; - break; - } - } - } - i = lru; - } - ldbm_close( li->li_dbcache[i].dbc_db ); - free( li->li_dbcache[i].dbc_name ); - li->li_dbcache[i].dbc_name = NULL; - } + /* if not SERVER or TOOL, who else would ask? + NO ONE, so return error */ - if ( (li->li_dbcache[i].dbc_db = ldbm_open( buf, flags, li->li_mode, - 0 )) == NULL ) { + Debug( LDAP_DEBUG_ANY, + "bdb2i_cache_open: database user (%d) unknown -- cannot open \"%s%s\".\n", + slapMode, name, suffix ); - Debug( LDAP_DEBUG_TRACE, - "<= bdb2i_cache_open NULL \"%s\" errno %d reason \"%s\")\n", - buf, errno, errno > -1 && errno < sys_nerr ? - sys_errlist[errno] : "unknown" ); - ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex ); - return( NULL ); - } - li->li_dbcache[i].dbc_name = ch_strdup( buf ); - li->li_dbcache[i].dbc_refcnt = 1; - li->li_dbcache[i].dbc_lastref = curtime; - if ( stat( buf, &st ) == 0 ) { - li->li_dbcache[i].dbc_blksize = st.st_blksize; - } else { - li->li_dbcache[i].dbc_blksize = DEFAULT_BLOCKSIZE; - } - li->li_dbcache[i].dbc_maxids = (li->li_dbcache[i].dbc_blksize / - sizeof(ID)) - ID_BLOCK_IDS_OFFSET; - li->li_dbcache[i].dbc_maxindirect = (SLAPD_LDBM_MIN_MAXIDS / - li->li_dbcache[i].dbc_maxids) + 1; - - Debug( LDAP_DEBUG_ARGS, - "bdb2i_cache_open (blksize %ld) (maxids %d) (maxindirect %d)\n", - li->li_dbcache[i].dbc_blksize, li->li_dbcache[i].dbc_maxids, - li->li_dbcache[i].dbc_maxindirect ); - Debug( LDAP_DEBUG_TRACE, "<= bdb2i_cache_open (opened %d)\n", i, 0, 0 ); - ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex ); - return( &li->li_dbcache[i] ); + return( NULL ); } void bdb2i_cache_close( BackendDB *be, struct dbcache *db ) { - struct ldbminfo *li = (struct ldbminfo *) be->be_private; - - /* if in slapd, all files stay open and we have only - readers or one writer */ + /* all files stay open until SERVER or TOOL shut down */ if ( ( slapMode == SLAP_SERVER_MODE ) || ( slapMode == SLAP_TOOL_MODE ) ) return; - ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex ); - if ( --db->dbc_refcnt == 0 ) { - ldap_pvt_thread_cond_signal( &li->li_dbcache_cv ); - } - ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex ); + /* if unknown user, complain */ + Debug( LDAP_DEBUG_ANY, + "bdb2i_cache_close: database user (%d) unknown -- ignored.\n", + slapMode, 0, 0 ); + + return; } void @@ -155,19 +68,16 @@ bdb2i_cache_really_close( BackendDB *be, struct dbcache *db ) { struct ldbminfo *li = (struct ldbminfo *) be->be_private; - /* if in slapd, all files stay open and we have only - readers or one writer */ + /* all files stay open until SERVER or TOOL shut down */ if ( ( slapMode == SLAP_SERVER_MODE ) || ( slapMode == SLAP_TOOL_MODE ) ) return; - ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex ); - if ( --db->dbc_refcnt == 0 ) { - ldap_pvt_thread_cond_signal( &li->li_dbcache_cv ); - ldbm_close( db->dbc_db ); - free( db->dbc_name ); - db->dbc_name = NULL; - } - ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex ); + /* if unknown user, complain */ + Debug( LDAP_DEBUG_ANY, + "bdb2i_cache_really_close: database user (%d) unknown -- ignored.\n", + slapMode, 0, 0 ); + + return; } void @@ -176,19 +86,16 @@ bdb2i_cache_flush_all( BackendDB *be ) struct ldbminfo *li = (struct ldbminfo *) be->be_private; int i; - /* if in slapd, syncing is done by TP */ + /* if SERVER or TOOL, syncing is done by TP, or during shutdown */ if ( ( slapMode == SLAP_SERVER_MODE ) || ( slapMode == SLAP_TOOL_MODE ) ) return; - ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex ); - for ( i = 0; i < MAXDBCACHE; i++ ) { - if ( li->li_dbcache[i].dbc_name != NULL ) { - Debug( LDAP_DEBUG_TRACE, "ldbm flushing db (%s)\n", - li->li_dbcache[i].dbc_name, 0, 0 ); - ldbm_sync( li->li_dbcache[i].dbc_db ); - } - } - ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex ); + /* if unknown user, complain */ + Debug( LDAP_DEBUG_ANY, + "bdb2i_cache_really_close: database user (%d) unknown -- ignored.\n", + slapMode, 0, 0 ); + + return; } Datum diff --git a/servers/slapd/back-bdb2/dn2id.c b/servers/slapd/back-bdb2/dn2id.c index 49e192ba74..1450775135 100644 --- a/servers/slapd/back-bdb2/dn2id.c +++ b/servers/slapd/back-bdb2/dn2id.c @@ -28,10 +28,10 @@ bdb2i_dn2id_add( Debug( LDAP_DEBUG_TRACE, "=> bdb2i_dn2id_add( \"%s\", %ld )\n", dn, id, 0 ); - if ( (db = bdb2i_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_WRCREAT )) + if ( (db = bdb2i_cache_open( be, "dn2id", BDB2_SUFFIX, LDBM_WRCREAT )) == NULL ) { Debug( LDAP_DEBUG_ANY, "Could not open/create dn2id%s\n", - LDBM_SUFFIX, 0, 0 ); + BDB2_SUFFIX, 0, 0 ); return( -1 ); } @@ -81,11 +81,11 @@ bdb2i_dn2id( return( id ); } - if ( (db = bdb2i_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_WRCREAT )) + if ( (db = bdb2i_cache_open( be, "dn2id", BDB2_SUFFIX, LDBM_WRCREAT )) == NULL ) { free( dn ); Debug( LDAP_DEBUG_ANY, "<= bdb2i_dn2id could not open dn2id%s\n", - LDBM_SUFFIX, 0, 0 ); + BDB2_SUFFIX, 0, 0 ); return( NOID ); } @@ -125,10 +125,10 @@ bdb2i_dn2id_delete( Debug( LDAP_DEBUG_TRACE, "=> bdb2i_dn2id_delete( \"%s\" )\n", dn, 0, 0 ); - if ( (db = bdb2i_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_WRCREAT )) + if ( (db = bdb2i_cache_open( be, "dn2id", BDB2_SUFFIX, LDBM_WRCREAT )) == NULL ) { Debug( LDAP_DEBUG_ANY, - "<= bdb2i_dn2id_delete could not open dn2id%s\n", LDBM_SUFFIX, + "<= bdb2i_dn2id_delete could not open dn2id%s\n", BDB2_SUFFIX, 0, 0 ); return( -1 ); } diff --git a/servers/slapd/back-bdb2/id2children.c b/servers/slapd/back-bdb2/id2children.c index c1fc26e252..82a295efdb 100644 --- a/servers/slapd/back-bdb2/id2children.c +++ b/servers/slapd/back-bdb2/id2children.c @@ -28,11 +28,11 @@ bdb2i_id2children_add( Debug( LDAP_DEBUG_TRACE, "=> bdb2i_id2children_add( %lu, %lu )\n", p ? p->e_id : 0, e->e_id, 0 ); - if ( (db = bdb2i_cache_open( be, "id2children", LDBM_SUFFIX, + if ( (db = bdb2i_cache_open( be, "id2children", BDB2_SUFFIX, LDBM_WRCREAT )) == NULL ) { Debug( LDAP_DEBUG_ANY, "<= bdb2i_id2children_add -1 could not open \"id2children%s\"\n", - LDBM_SUFFIX, 0, 0 ); + BDB2_SUFFIX, 0, 0 ); return( -1 ); } @@ -70,11 +70,11 @@ bdb2i_id2children_remove( Debug( LDAP_DEBUG_TRACE, "=> bdb2i_id2children_remove( %lu, %lu )\n", p ? p->e_id : 0, e->e_id, 0 ); - if ( (db = bdb2i_cache_open( be, "id2children", LDBM_SUFFIX, + if ( (db = bdb2i_cache_open( be, "id2children", BDB2_SUFFIX, LDBM_WRCREAT )) == NULL ) { Debug( LDAP_DEBUG_ANY, "<= bdb2i_id2children_remove -1 could not open \"id2children%s\"\n", - LDBM_SUFFIX, 0, 0 ); + BDB2_SUFFIX, 0, 0 ); return( -1 ); } @@ -112,11 +112,11 @@ bdb2i_has_children( Debug( LDAP_DEBUG_TRACE, "=> bdb2i_has_children( %lu )\n", p->e_id , 0, 0 ); - if ( (db = bdb2i_cache_open( be, "id2children", LDBM_SUFFIX, + if ( (db = bdb2i_cache_open( be, "id2children", BDB2_SUFFIX, LDBM_WRCREAT )) == NULL ) { Debug( LDAP_DEBUG_ANY, "<= bdb2i_has_children -1 could not open \"id2children%s\"\n", - LDBM_SUFFIX, 0, 0 ); + BDB2_SUFFIX, 0, 0 ); return( 0 ); } diff --git a/servers/slapd/back-bdb2/id2entry.c b/servers/slapd/back-bdb2/id2entry.c index c397e198cd..8507567055 100644 --- a/servers/slapd/back-bdb2/id2entry.c +++ b/servers/slapd/back-bdb2/id2entry.c @@ -23,10 +23,10 @@ bdb2i_id2entry_add( BackendDB *be, Entry *e ) Debug( LDAP_DEBUG_TRACE, "=> bdb2i_id2entry_add( %lu, \"%s\" )\n", e->e_id, e->e_dn, 0 ); - if ( (db = bdb2i_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_WRCREAT )) + if ( (db = bdb2i_cache_open( be, "id2entry", BDB2_SUFFIX, LDBM_WRCREAT )) == NULL ) { Debug( LDAP_DEBUG_ANY, "Could not open/create id2entry%s\n", - LDBM_SUFFIX, 0, 0 ); + BDB2_SUFFIX, 0, 0 ); return( -1 ); } @@ -71,10 +71,10 @@ bdb2i_id2entry_delete( BackendDB *be, Entry *e ) ldbm_datum_init( key ); - if ( (db = bdb2i_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_WRCREAT )) + if ( (db = bdb2i_cache_open( be, "id2entry", BDB2_SUFFIX, LDBM_WRCREAT )) == NULL ) { Debug( LDAP_DEBUG_ANY, "Could not open/create id2entry%s\n", - LDBM_SUFFIX, 0, 0 ); + BDB2_SUFFIX, 0, 0 ); return( -1 ); } @@ -115,10 +115,10 @@ bdb2i_id2entry( BackendDB *be, ID id, int rw ) return( e ); } - if ( (db = bdb2i_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_WRCREAT )) + if ( (db = bdb2i_cache_open( be, "id2entry", BDB2_SUFFIX, LDBM_WRCREAT )) == NULL ) { Debug( LDAP_DEBUG_ANY, "Could not open id2entry%s\n", - LDBM_SUFFIX, 0, 0 ); + BDB2_SUFFIX, 0, 0 ); return( NULL ); } diff --git a/servers/slapd/back-bdb2/index.c b/servers/slapd/back-bdb2/index.c index e8c0c7a0a9..15c82cf5ad 100644 --- a/servers/slapd/back-bdb2/index.c +++ b/servers/slapd/back-bdb2/index.c @@ -117,11 +117,11 @@ bdb2i_index_read( } attr_normalize( type ); - if ( (db = bdb2i_cache_open( be, type, LDBM_SUFFIX, LDBM_WRCREAT )) + if ( (db = bdb2i_cache_open( be, type, BDB2_SUFFIX, LDBM_WRCREAT )) == NULL ) { Debug( LDAP_DEBUG_ANY, "<= bdb2i_index_read NULL (could not open %s%s)\n", type, - LDBM_SUFFIX, 0 ); + BDB2_SUFFIX, 0 ); return( NULL ); } @@ -236,11 +236,11 @@ bdb2i_index_add_values( return( 0 ); } - if ( (db = bdb2i_cache_open( be, type, LDBM_SUFFIX, LDBM_WRCREAT )) + if ( (db = bdb2i_cache_open( be, type, BDB2_SUFFIX, LDBM_WRCREAT )) == NULL ) { Debug( LDAP_DEBUG_ANY, "<= bdb2i_index_add_values -1 (could not open/create %s%s)\n", - type, LDBM_SUFFIX, 0 ); + type, BDB2_SUFFIX, 0 ); return( -1 ); } diff --git a/servers/slapd/back-bdb2/nextid.c b/servers/slapd/back-bdb2/nextid.c index 88013e6d9b..11c11e5cb1 100644 --- a/servers/slapd/back-bdb2/nextid.c +++ b/servers/slapd/back-bdb2/nextid.c @@ -86,7 +86,7 @@ int bdb2i_next_id_save( BackendDB *be ) { struct ldbminfo *li = (struct ldbminfo *) be->be_private; - ID id = next_id_get( be ); + ID id = bdb2i_next_id_get( be ); int rc = next_id_write( be, id ); if (rc == 0) { diff --git a/servers/slapd/back-bdb2/txn.c b/servers/slapd/back-bdb2/txn.c index a5df7a9724..493dfa87fc 100644 --- a/servers/slapd/back-bdb2/txn.c +++ b/servers/slapd/back-bdb2/txn.c @@ -25,7 +25,7 @@ bdb2i_txn_head_init( BDB2_TXN_HEAD *head ) } - sprintf( fileName, "%s%s", bdb2i_fixed_filenames[dbFile], LDBM_SUFFIX ); + sprintf( fileName, "%s%s", bdb2i_fixed_filenames[dbFile], BDB2_SUFFIX ); (*fileNodeH)->dbc_name = strdup( fileName ); fileNodeH = &(*fileNodeH)->next; @@ -81,7 +81,7 @@ bdb2i_txn_attr_config( BDB2_TXN_FILES **fileNodeH; char fileName[MAXPATHLEN]; - sprintf( fileName, "%s%s", attr, LDBM_SUFFIX ); + sprintf( fileName, "%s%s", attr, BDB2_SUFFIX ); /* search for the end of the list or a node describing the current attribute */ @@ -261,12 +261,12 @@ bdb2i_check_additional_attr_index( struct ldbminfo *li ) strcpy( filename, file->d_name ); namelen = strlen( filename ); - if ( namelen > strlen( LDBM_SUFFIX )) { + if ( namelen > strlen( BDB2_SUFFIX )) { - if ( !strcasecmp( filename + namelen - strlen( LDBM_SUFFIX ), - LDBM_SUFFIX )) { + if ( !strcasecmp( filename + namelen - strlen( BDB2_SUFFIX ), + BDB2_SUFFIX )) { - *(filename + namelen - strlen( LDBM_SUFFIX )) = '\0'; + *(filename + namelen - strlen( BDB2_SUFFIX )) = '\0'; bdb2i_txn_attr_config( li, filename, 0 ); Debug( LDAP_DEBUG_TRACE, "INDEX FILE: %s\n", filename, 0, 0 ); diff --git a/servers/slapd/backend.c b/servers/slapd/backend.c index 8001fc4b12..1bf064541b 100644 --- a/servers/slapd/backend.c +++ b/servers/slapd/backend.c @@ -179,20 +179,6 @@ int backend_startup(int n) /* open each backend database */ for( i = 0; i < nBackendDB; i++ ) { - BackendInfo *bi; - - /* open the backend type, if not done already */ - bi = backendDB[i].bd_info; - - if( bi->bi_nDB == 0) { - /* no database of this type, don't open */ - Debug(LDAP_DEBUG_ANY, - "backend_startup: there should be no database (%d) of %s type.!\n", - i, bi->bi_type, 0 ); - - return -1; - } - if ( backendDB[i].bd_info->bi_db_open ) { rc = backendDB[i].bd_info->bi_db_open( &backendDB[i] ); diff --git a/servers/slapd/tools/ldif2id2children-bdb2.c b/servers/slapd/tools/ldif2id2children-bdb2.c index be5a435bef..78dc964f85 100644 --- a/servers/slapd/tools/ldif2id2children-bdb2.c +++ b/servers/slapd/tools/ldif2id2children-bdb2.c @@ -117,7 +117,7 @@ main( int argc, char **argv ) * first, make the dn2id index */ - if ( (db = bdb2i_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_NEWDB )) + if ( (db = bdb2i_cache_open( be, "dn2id", BDB2_SUFFIX, LDBM_NEWDB )) == NULL ) { perror( "dn2id file" ); exit( 1 ); @@ -202,7 +202,7 @@ main( int argc, char **argv ) * next, make the id2children index */ - if ( (db2 = bdb2i_cache_open( be, "id2children", LDBM_SUFFIX, + if ( (db2 = bdb2i_cache_open( be, "id2children", BDB2_SUFFIX, LDBM_NEWDB )) == NULL ) { perror( "id2children file" ); exit( 1 ); diff --git a/servers/slapd/tools/ldif2id2entry-bdb2.c b/servers/slapd/tools/ldif2id2entry-bdb2.c index 5ca1120621..6dec9bd943 100644 --- a/servers/slapd/tools/ldif2id2entry-bdb2.c +++ b/servers/slapd/tools/ldif2id2entry-bdb2.c @@ -112,7 +112,7 @@ main( int argc, char **argv ) li = (struct ldbminfo *) be->be_private; li->li_dbcachewsync = 0; - if ( (db = bdb2i_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_NEWDB )) + if ( (db = bdb2i_cache_open( be, "id2entry", BDB2_SUFFIX, LDBM_NEWDB )) == NULL ) { perror( "id2entry file" ); exit( 1 );