1 /* init.c - initialize ldbm backend */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/string.h>
13 #include <ac/socket.h>
16 #include "back-ldbm.h"
18 #ifdef SLAPD_LDBM_DYNAMIC
20 int back_ldbm_LTX_init_module(int argc, char *argv[]) {
23 memset( &bi, '\0', sizeof(bi) );
25 bi.bi_init = ldbm_back_initialize;
31 #endif /* SLAPD_LDBM_DYNAMIC */
38 static char *controls[] = {
39 LDAP_CONTROL_MANAGEDSAIT,
43 bi->bi_controls = controls;
45 bi->bi_open = ldbm_back_open;
47 bi->bi_close = ldbm_back_close;
48 bi->bi_destroy = ldbm_back_destroy;
50 bi->bi_db_init = ldbm_back_db_init;
51 bi->bi_db_config = ldbm_back_db_config;
52 bi->bi_db_open = ldbm_back_db_open;
53 bi->bi_db_close = ldbm_back_db_close;
54 bi->bi_db_destroy = ldbm_back_db_destroy;
56 bi->bi_op_bind = ldbm_back_bind;
58 bi->bi_op_search = ldbm_back_search;
59 bi->bi_op_compare = ldbm_back_compare;
60 bi->bi_op_modify = ldbm_back_modify;
61 bi->bi_op_modrdn = ldbm_back_modrdn;
62 bi->bi_op_add = ldbm_back_add;
63 bi->bi_op_delete = ldbm_back_delete;
64 bi->bi_op_abandon = 0;
66 bi->bi_extended = ldbm_back_extended;
68 bi->bi_entry_release_rw = ldbm_back_entry_release_rw;
69 bi->bi_acl_group = ldbm_back_group;
70 bi->bi_acl_attribute = ldbm_back_attribute;
71 bi->bi_chk_referrals = ldbm_back_referrals;
72 bi->bi_operational = ldbm_back_operational;
75 * hooks for slap tools
77 bi->bi_tool_entry_open = ldbm_tool_entry_open;
78 bi->bi_tool_entry_close = ldbm_tool_entry_close;
79 bi->bi_tool_entry_first = ldbm_tool_entry_first;
80 bi->bi_tool_entry_next = ldbm_tool_entry_next;
81 bi->bi_tool_entry_get = ldbm_tool_entry_get;
82 bi->bi_tool_entry_put = ldbm_tool_entry_put;
83 bi->bi_tool_entry_reindex = ldbm_tool_entry_reindex;
84 bi->bi_tool_sync = ldbm_tool_sync;
86 bi->bi_connection_init = 0;
87 bi->bi_connection_destroy = 0;
107 /* initialize the underlying database system */
108 rc = ldbm_initialize( NULL );
117 /* terminate the underlying database system */
129 /* indicate system schema supported */
130 be->be_flags |= SLAP_BFLAG_ALIASES|SLAP_BFLAG_REFERRALS;
132 /* allocate backend-database-specific stuff */
133 li = (struct ldbminfo *) ch_calloc( 1, sizeof(struct ldbminfo) );
135 /* arrange to read nextid later (on first request for it) */
136 li->li_nextid = NOID;
138 /* default cache size */
139 li->li_cache.c_maxsize = DEFAULT_CACHE_SIZE;
141 /* default database cache size */
142 li->li_dbcachesize = DEFAULT_DBCACHE_SIZE;
144 /* default db mode is with locking */
145 li->li_dblocking = 1;
147 /* default db mode is with write synchronization */
148 li->li_dbwritesync = 1;
150 /* default file creation mode */
151 li->li_mode = DEFAULT_MODE;
153 /* default database directory */
154 li->li_directory = ch_strdup( DEFAULT_DB_DIRECTORY );
156 /* DB_ENV environment pointer for DB3 */
159 /* envdirok is turned on by ldbm_initialize_env if DB3 */
162 /* syncfreq is 0 if disabled, or # seconds */
163 li->li_dbsyncfreq = 0;
165 /* wait up to dbsyncwaitn times if server is busy */
166 li->li_dbsyncwaitn = 12;
169 li->li_dbsyncwaitinterval = 5;
171 /* flag to notify ldbm_cache_sync_daemon to shut down */
172 li->li_dbshutdown = 0;
174 /* initialize various mutex locks & condition variables */
175 ldap_pvt_thread_mutex_init( &li->li_root_mutex );
176 ldap_pvt_thread_mutex_init( &li->li_add_mutex );
177 ldap_pvt_thread_mutex_init( &li->li_cache.c_mutex );
178 ldap_pvt_thread_mutex_init( &li->li_nextid_mutex );
179 ldap_pvt_thread_mutex_init( &li->li_dbcache_mutex );
180 ldap_pvt_thread_cond_init( &li->li_dbcache_cv );
192 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
193 li->li_dbenv = ldbm_initialize_env( li->li_directory,
194 li->li_dbcachesize, &li->li_envdirok );
197 if ( li->li_dbsyncfreq > 0 )
200 rc = ldap_pvt_thread_create( &li->li_dbsynctid,
201 0, ldbm_cache_sync_daemon, (void*)be );
205 Debug( LDAP_DEBUG_ANY,
206 "sync ldap_pvt_thread_create failed (%d)\n", rc, 0, 0 );
215 ldbm_back_db_destroy(
219 /* should free/destroy every in be_private */
220 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
223 ldbm_shutdown_env(li->li_dbenv);
225 free( li->li_directory );
226 attr_index_destroy( li->li_attrs );
228 ldap_pvt_thread_mutex_destroy( &li->li_root_mutex );
229 ldap_pvt_thread_mutex_destroy( &li->li_add_mutex );
230 ldap_pvt_thread_mutex_destroy( &li->li_cache.c_mutex );
231 ldap_pvt_thread_mutex_destroy( &li->li_nextid_mutex );
232 ldap_pvt_thread_mutex_destroy( &li->li_dbcache_mutex );
233 ldap_pvt_thread_cond_destroy( &li->li_dbcache_cv );
235 free( be->be_private );
236 be->be_private = NULL;