]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/init.c
Integration of the BDB2 backend into the new init/startup/shutdown schema.
[openldap] / servers / slapd / back-bdb2 / init.c
1 /* init.c - initialize bdb2 backend */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6
7 #include <ac/string.h>
8 #include <ac/socket.h>
9
10 #include "slap.h"
11 #include "back-bdb2.h"
12
13
14 static int
15 bdb2i_back_init_private(
16     BackendInfo *bi
17 )
18 {
19         struct ldbtype  *bt;
20
21         /*  allocate backend-type-specific stuff */
22         bt = (struct ldbtype *) ch_calloc( 1, sizeof(struct ldbtype) );
23
24         bt->lty_dbhome = DEFAULT_DB_HOME;
25         bt->lty_mpsize = DEFAULT_DBCACHE_SIZE;
26         bt->lty_dbenv  = &ldbm_Env;
27
28         bi->bi_private = bt;
29
30         return 0;
31 }
32
33
34 int
35 bdb2_back_initialize(
36     BackendInfo *bi
37 )
38 {
39         int  ret;
40
41         bi->bi_open = bdb2_back_open;
42         bi->bi_config = bdb2_back_config;
43         bi->bi_close = bdb2_back_close;
44         bi->bi_destroy = bdb2_back_destroy;
45
46         bi->bi_db_init = bdb2_back_db_init;
47         bi->bi_db_config = bdb2_back_db_config;
48         bi->bi_db_open = bdb2_back_db_open;
49         bi->bi_db_close = bdb2_back_db_close;
50         bi->bi_db_destroy = bdb2_back_db_destroy;
51
52         bi->bi_op_bind = bdb2_back_bind;
53         bi->bi_op_unbind = bdb2_back_unbind;
54         bi->bi_op_search = bdb2_back_search;
55         bi->bi_op_compare = bdb2_back_compare;
56         bi->bi_op_modify = bdb2_back_modify;
57         bi->bi_op_modrdn = bdb2_back_modrdn;
58         bi->bi_op_add = bdb2_back_add;
59         bi->bi_op_delete = bdb2_back_delete;
60         bi->bi_op_abandon = bdb2_back_abandon;
61
62 #ifdef SLAPD_ACLGROUPS
63         bi->bi_acl_group = bdb2_back_group;
64 #endif
65
66         ret = bdb2i_back_init_private( bi );
67
68         Debug( LDAP_DEBUG_TRACE, "bdb2_back_initialize: done (%d).\n", ret, 0, 0 );
69
70         return( ret );
71 }
72
73 int
74 bdb2_back_destroy(
75     BackendInfo *bi
76 )
77 {
78         return 0;
79 }
80
81 int
82 bdb2_back_open(
83     BackendInfo *bi
84 )
85 {
86         static int initialized = 0;
87         int rc;
88
89         if ( initialized++ ) {
90
91                 Debug( LDAP_DEBUG_TRACE,
92                                 "bdb2_back_open: backend already initialized.\n", 0, 0, 0 );
93                 return 0;
94
95         }
96
97         /* initialize the underlying database system */
98         rc = bdb2i_back_startup( bi );
99
100         return rc;
101 }
102
103 int
104 bdb2_back_close(
105     BackendInfo *bi
106 )
107 {
108         int  rc;
109
110         /* close the underlying database system */
111         rc = bdb2i_back_shutdown( bi );
112
113         return rc;
114 }
115
116 /*  BDB2 changed  */
117 static int
118 bdb2i_back_db_init_internal(
119     BackendDB   *be
120 )
121 {
122         struct ldbminfo *li;
123         char            *argv[ 4 ];
124         int             i;
125
126         /* allocate backend-database-specific stuff */
127         li = (struct ldbminfo *) ch_calloc( 1, sizeof(struct ldbminfo) );
128
129         /* arrange to read nextid later (on first request for it) */
130         li->li_nextid = NOID;
131 #if     SLAPD_NEXTID_CHUNCK > 1
132         li->li_nextid_wrote = NOID
133 #endif
134
135         /* default cache size */
136         li->li_cache.c_maxsize = DEFAULT_CACHE_SIZE;
137
138         /* default database cache size */
139         li->li_dbcachesize = DEFAULT_DBCACHE_SIZE;
140
141         /* default cache mode is sync on write */
142         li->li_dbcachewsync = 1;
143
144         /* default file creation mode */
145         li->li_mode = DEFAULT_MODE;
146
147         /* default database directory */
148         li->li_directory = DEFAULT_DB_DIRECTORY;
149
150         /* always index dn, id2children, objectclass (used in some searches) */
151         argv[ 0 ] = "dn";
152         argv[ 1 ] = "dn";
153         argv[ 2 ] = NULL;
154         attr_syntax_config( "ldbm dn initialization", 0, 2, argv );
155         argv[ 0 ] = "dn";
156         argv[ 1 ] = "sub";
157         argv[ 2 ] = "eq";
158         argv[ 3 ] = NULL;
159         bdb2i_attr_index_config( li, "ldbm dn initialization", 0, 3, argv, 1 );
160         argv[ 0 ] = "id2children";
161         argv[ 1 ] = "eq";
162         argv[ 2 ] = NULL;
163         bdb2i_attr_index_config( li, "ldbm id2children initialization", 0, 2, argv,
164             1 );
165         argv[ 0 ] = "objectclass";
166         argv[ 1 ] = ch_strdup( "pres,eq" );
167         argv[ 2 ] = NULL;
168         bdb2i_attr_index_config( li, "ldbm objectclass initialization", 0, 2, argv,
169             1 );
170         free( argv[ 1 ] );
171
172         /* initialize various mutex locks & condition variables */
173         ldap_pvt_thread_mutex_init( &li->li_root_mutex );
174         ldap_pvt_thread_mutex_init( &li->li_add_mutex );
175         ldap_pvt_thread_mutex_init( &li->li_cache.c_mutex );
176         ldap_pvt_thread_mutex_init( &li->li_nextid_mutex );
177         ldap_pvt_thread_mutex_init( &li->li_dbcache_mutex );
178         ldap_pvt_thread_cond_init( &li->li_dbcache_cv );
179
180         /*  initialize the TP file head  */
181         if ( bdb2i_txn_head_init( &li->li_txn_head ) != 0 )
182                 return 1;
183
184         be->be_private = li;
185
186         return 0;
187 }
188
189
190 int
191 bdb2_back_db_init(
192     BackendDB   *be
193 )
194 {
195         struct timeval  time1, time2;
196         char   *elapsed_time;
197         int    ret;
198
199         gettimeofday( &time1, NULL );
200
201         ret = bdb2i_back_db_init_internal( be );
202
203         if ( bdb2i_do_timing ) {
204
205                 gettimeofday( &time2, NULL);
206                 elapsed_time = bdb2i_elapsed( time1, time2 );
207                 Debug( LDAP_DEBUG_ANY, "DB-INIT elapsed=%s\n",
208                                 elapsed_time, 0, 0 );
209                 free( elapsed_time );
210
211         }
212
213         return( ret );
214 }
215
216
217 int
218 bdb2_back_db_open(
219     BackendDB   *be
220 )
221 {
222         int  rc;
223
224         rc = bdb2_back_db_startup( be );
225
226         return( rc );
227 }
228
229 int
230 bdb2_back_db_destroy(
231     BackendDB   *be
232 )
233 {
234         /* should free/destroy every in be_private */
235         free( be->be_private );
236         be->be_private = NULL;
237         return 0;
238 }
239
240