]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/init.c
use slab memory for proxyauthz
[openldap] / servers / slapd / back-bdb / init.c
index 36af08c8e5d03e6fe3e42ff3949172c949718b4b..eff1b5db620375bf5c7791fa3c0187ca1d9fc391 100644 (file)
@@ -2,7 +2,7 @@
 /* $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
@@ -69,7 +69,8 @@ bdb_db_init( BackendDB *be )
 #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 );
@@ -81,6 +82,9 @@ bdb_db_init( BackendDB *be )
        return 0;
 }
 
+static int
+bdb_db_close( BackendDB *be );
+
 static int
 bdb_db_open( BackendDB *be )
 {
@@ -180,7 +184,7 @@ 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 );
@@ -198,7 +202,7 @@ bdb_db_open( BackendDB *be )
                        Debug( LDAP_DEBUG_ANY,
                                "bdb_db_open: dbenv_set_flags failed: %s (%d)\n",
                                db_strerror(rc), rc, 0 );
-                       return rc;
+                       goto fail;
                }
        }
 
@@ -248,7 +252,8 @@ bdb_db_open( BackendDB *be )
                                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.
@@ -261,7 +266,7 @@ 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 );
@@ -272,7 +277,7 @@ bdb_db_open( BackendDB *be )
                                        Debug( LDAP_DEBUG_ANY,
                                                "bdb_db_open: recovery failed: %s (%d)\n",
                                                db_strerror(rc), rc, 0 );
-                                       return rc;
+                                       goto fail;
                                }
                                do_recover = 0;
                        }
@@ -285,7 +290,7 @@ 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->remove( bdb->bi_dbenv, dbhome, 0 );
                                bdb->bi_dbenv = NULL;
@@ -297,7 +302,8 @@ bdb_db_open( BackendDB *be )
                                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 ) {
@@ -321,7 +327,7 @@ 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 );
@@ -338,7 +344,7 @@ bdb_db_open( BackendDB *be )
                                        Debug( LDAP_DEBUG_ANY,
                                                "bdb_db_open: dbenv_set_flags failed: %s (%d)\n",
                                                db_strerror(rc), rc, 0 );
-                                       return rc;
+                                       goto fail;
                                }
                        }
                }
@@ -375,7 +381,7 @@ bdb_db_open( BackendDB *be )
                        Debug( LDAP_DEBUG_ANY,
                                "bdb_db_open: dbenv_open failed: %s (%d)\n",
                                db_strerror(rc), rc, 0 );
-                       return rc;
+                       goto fail;
                }
        }
 
@@ -383,7 +389,8 @@ bdb_db_open( BackendDB *be )
                Debug( LDAP_DEBUG_ANY,
                        "bdb_db_open: alock_recover failed\n",
                        0, 0, 0 );
-               return -1;
+               rc = -1;
+               goto fail;
        }
 
 #ifdef SLAP_ZONE_ALLOC
@@ -422,10 +429,14 @@ bdb_db_open( BackendDB *be )
                        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 ) {
+                       if ( slapMode & SLAP_TOOL_MODE )
+                               db->bdi_db->mpf->set_priority( db->bdi_db->mpf,
+                                       DB_PRIORITY_VERY_LOW );
+
                        rc = db->bdi_db->set_pagesize( db->bdi_db,
                                BDB_ID2ENTRY_PAGESIZE );
                        if ( slapMode & SLAP_TOOL_READMAIN ) {
@@ -479,16 +490,10 @@ bdb_db_open( BackendDB *be )
                        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;
                }
 
-#if 0
-               if( i == BDB_ID2ENTRY && ( slapMode & SLAP_TOOL_MODE )) {
-                       db->bdi_db->mpf->set_priority( db->bdi_db->mpf,
-                               DB_PRIORITY_VERY_LOW );
-               }
-#endif
-
                flags &= ~(DB_CREATE | DB_RDONLY);
                db->bdi_name = bdbi_databases[i].name;
                bdb->bi_databases[i] = db;
@@ -503,7 +508,7 @@ bdb_db_open( BackendDB *be )
                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 )) {
@@ -513,6 +518,10 @@ bdb_db_open( BackendDB *be )
        bdb->bi_flags |= BDB_IS_OPEN;
 
        return 0;
+
+fail:
+       bdb_db_close( be );
+       return rc;
 }
 
 static int
@@ -523,10 +532,6 @@ bdb_db_close( BackendDB *be )
        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 );
@@ -546,7 +551,6 @@ bdb_db_close( BackendDB *be )
        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;
@@ -559,16 +563,16 @@ bdb_db_close( BackendDB *be )
                        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.
                 */
@@ -609,10 +613,11 @@ bdb_db_destroy( BackendDB *be )
        if( bdb->bi_dbenv_home ) ch_free( bdb->bi_dbenv_home );
        if( bdb->bi_db_config_path ) ch_free( bdb->bi_db_config_path );
 
-       bdb_attr_index_destroy( bdb->bi_attrs );
+       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 );
@@ -639,12 +644,8 @@ bdb_back_initialize(
                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
        };
 
@@ -655,9 +656,7 @@ bdb_back_initialize(
 
        bi->bi_flags |=
                SLAP_BFLAG_INCREMENT |
-#ifdef BDB_SUBENTRIES
                SLAP_BFLAG_SUBENTRIES |
-#endif
                SLAP_BFLAG_ALIASES |
                SLAP_BFLAG_REFERRALS;