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