1 /* init.c - initialize ldbm backend */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2004 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
21 #include <ac/string.h>
22 #include <ac/socket.h>
25 #include "back-ldbm.h"
28 #if SLAPD_LDBM == SLAPD_MOD_DYNAMIC
30 int init_module(int argc, char *argv[]) {
33 memset( &bi, '\0', sizeof(bi) );
35 bi.bi_init = ldbm_back_initialize;
41 #endif /* SLAPD_LDBM */
48 static char *controls[] = {
49 LDAP_CONTROL_MANAGEDSAIT,
50 LDAP_CONTROL_VALUESRETURNFILTER,
54 bi->bi_controls = controls;
57 SLAP_BFLAG_INCREMENT |
58 #ifdef LDBM_SUBENTRIES
59 SLAP_BFLAG_SUBENTRIES |
64 bi->bi_open = ldbm_back_open;
66 bi->bi_close = ldbm_back_close;
67 bi->bi_destroy = ldbm_back_destroy;
69 bi->bi_db_init = ldbm_back_db_init;
70 bi->bi_db_config = ldbm_back_db_config;
71 bi->bi_db_open = ldbm_back_db_open;
72 bi->bi_db_close = ldbm_back_db_close;
73 bi->bi_db_destroy = ldbm_back_db_destroy;
75 bi->bi_op_bind = ldbm_back_bind;
77 bi->bi_op_search = ldbm_back_search;
78 bi->bi_op_compare = ldbm_back_compare;
79 bi->bi_op_modify = ldbm_back_modify;
80 bi->bi_op_modrdn = ldbm_back_modrdn;
81 bi->bi_op_add = ldbm_back_add;
82 bi->bi_op_delete = ldbm_back_delete;
83 bi->bi_op_abandon = 0;
85 bi->bi_extended = ldbm_back_extended;
87 bi->bi_entry_release_rw = ldbm_back_entry_release_rw;
88 bi->bi_entry_get_rw = ldbm_back_entry_get;
89 bi->bi_chk_referrals = ldbm_back_referrals;
90 bi->bi_operational = ldbm_back_operational;
91 bi->bi_has_subordinates = ldbm_back_hasSubordinates;
94 * hooks for slap tools
96 bi->bi_tool_entry_open = ldbm_tool_entry_open;
97 bi->bi_tool_entry_close = ldbm_tool_entry_close;
98 bi->bi_tool_entry_first = ldbm_tool_entry_first;
99 bi->bi_tool_entry_next = ldbm_tool_entry_next;
100 bi->bi_tool_entry_get = ldbm_tool_entry_get;
101 bi->bi_tool_entry_put = ldbm_tool_entry_put;
102 bi->bi_tool_entry_reindex = ldbm_tool_entry_reindex;
103 bi->bi_tool_sync = ldbm_tool_sync;
105 bi->bi_tool_dn2id_get = 0;
106 bi->bi_tool_id2entry_get = 0;
107 bi->bi_tool_entry_modify = 0;
109 bi->bi_connection_init = 0;
110 bi->bi_connection_destroy = 0;
130 /* initialize the underlying database system */
131 rc = ldbm_initialize( NULL );
140 /* terminate the underlying database system */
152 /* allocate backend-database-specific stuff */
153 li = (struct ldbminfo *) ch_calloc( 1, sizeof(struct ldbminfo) );
155 /* arrange to read nextid later (on first request for it) */
156 li->li_nextid = NOID;
158 /* default cache size */
159 li->li_cache.c_maxsize = DEFAULT_CACHE_SIZE;
161 /* default database cache size */
162 li->li_dbcachesize = DEFAULT_DBCACHE_SIZE;
164 /* default db mode is with locking */
165 li->li_dblocking = 1;
167 /* default db mode is with write synchronization */
168 li->li_dbwritesync = 1;
170 /* default file creation mode */
171 li->li_mode = SLAPD_DEFAULT_DB_MODE;
173 /* default database directory */
174 li->li_directory = ch_strdup( SLAPD_DEFAULT_DB_DIR );
176 /* DB_ENV environment pointer for DB3 */
179 /* envdirok is turned on by ldbm_initialize_env if DB3 */
182 /* syncfreq is 0 if disabled, or # seconds */
183 li->li_dbsyncfreq = 0;
185 /* wait up to dbsyncwaitn times if server is busy */
186 li->li_dbsyncwaitn = 12;
189 li->li_dbsyncwaitinterval = 5;
191 /* flag to notify ldbm_cache_sync_daemon to shut down */
192 li->li_dbshutdown = 0;
194 /* initialize various mutex locks & condition variables */
195 ldap_pvt_thread_rdwr_init( &li->li_giant_rwlock );
196 ldap_pvt_thread_mutex_init( &li->li_cache.c_mutex );
197 ldap_pvt_thread_mutex_init( &li->li_dbcache_mutex );
198 ldap_pvt_thread_cond_init( &li->li_dbcache_cv );
210 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
211 li->li_dbenv = ldbm_initialize_env( li->li_directory,
212 li->li_dbcachesize, &li->li_envdirok );
215 if ( li->li_dbsyncfreq > 0 )
218 rc = ldap_pvt_thread_create( &li->li_dbsynctid,
219 0, ldbm_cache_sync_daemon, (void*)be );
223 Debug( LDAP_DEBUG_ANY,
224 "sync ldap_pvt_thread_create failed (%d)\n", rc, 0, 0 );
233 ldbm_back_db_destroy(
237 /* should free/destroy every in be_private */
238 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
241 ldbm_shutdown_env(li->li_dbenv);
243 free( li->li_directory );
244 attr_index_destroy( li->li_attrs );
246 ldap_pvt_thread_rdwr_destroy( &li->li_giant_rwlock );
247 ldap_pvt_thread_mutex_destroy( &li->li_cache.c_mutex );
248 ldap_pvt_thread_mutex_destroy( &li->li_dbcache_mutex );
249 ldap_pvt_thread_cond_destroy( &li->li_dbcache_cv );
251 free( be->be_private );
252 be->be_private = NULL;