]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/init.c
Added connection initialisation and destruction notification. Now backends can regist...
[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         bi->bi_entry_release_rw = bdb2_back_entry_release_rw;
65 #ifdef SLAPD_ACLGROUPS
66         bi->bi_acl_group = bdb2_back_group;
67 #endif
68
69         bi->bi_connection_init = 0;
70         bi->bi_connection_destroy = 0;
71
72         ret = bdb2i_back_init_private( bi );
73
74         Debug( LDAP_DEBUG_TRACE, "bdb2_back_initialize: done (%d).\n", ret, 0, 0 );
75
76         return( ret );
77 }
78
79 int
80 bdb2_back_destroy(
81     BackendInfo *bi
82 )
83 {
84         return 0;
85 }
86
87 int
88 bdb2_back_open(
89     BackendInfo *bi
90 )
91 {
92         static int initialized = 0;
93         int rc;
94
95         if ( initialized++ ) {
96
97                 Debug( LDAP_DEBUG_TRACE,
98                                 "bdb2_back_open: backend already initialized.\n", 0, 0, 0 );
99                 return 0;
100
101         }
102
103         /* initialize the underlying database system */
104         rc = bdb2i_back_startup( bi );
105
106         return rc;
107 }
108
109 int
110 bdb2_back_close(
111     BackendInfo *bi
112 )
113 {
114         int  rc;
115
116         /* close the underlying database system */
117         rc = bdb2i_back_shutdown( bi );
118
119         return rc;
120 }
121
122 /*  BDB2 changed  */
123 static int
124 bdb2i_back_db_init_internal(
125     BackendDB   *be
126 )
127 {
128         struct ldbminfo *li;
129         char            *argv[ 4 ];
130
131         /* allocate backend-database-specific stuff */
132         li = (struct ldbminfo *) ch_calloc( 1, sizeof(struct ldbminfo) );
133
134         /* arrange to read nextid later (on first request for it) */
135         li->li_nextid = NOID;
136 #if     SLAPD_NEXTID_CHUNK > 1
137         li->li_nextid_wrote = NOID;
138 #endif
139
140         /* default cache size */
141         li->li_cache.c_maxsize = DEFAULT_CACHE_SIZE;
142
143         /* default database cache size */
144         li->li_dbcachesize = DEFAULT_DBCACHE_SIZE;
145
146         /* default cache mode is sync on write */
147         li->li_dbcachewsync = 1;
148
149         /* default file creation mode */
150         li->li_mode = DEFAULT_MODE;
151
152         /* default database directory */
153         li->li_directory = DEFAULT_DB_DIRECTORY;
154
155         /* always index dn, id2children, objectclass (used in some searches) */
156         if ( !at_find( "dn" ) ) {
157                 argv[ 0 ] = "dn";
158                 argv[ 1 ] = "dn";
159                 argv[ 2 ] = NULL;
160                 attr_syntax_config( "ldbm dn initialization", 0, 2, argv );
161         }
162         argv[ 0 ] = "dn";
163         argv[ 1 ] = "sub";
164         argv[ 2 ] = "eq";
165         argv[ 3 ] = NULL;
166         bdb2i_attr_index_config( li, "ldbm dn initialization", 0, 3, argv, 1 );
167         argv[ 0 ] = "id2children";
168         argv[ 1 ] = "eq";
169         argv[ 2 ] = NULL;
170         bdb2i_attr_index_config( li, "ldbm id2children initialization", 0, 2, argv,
171             1 );
172         argv[ 0 ] = "objectclass";
173         argv[ 1 ] = ch_strdup( "pres,eq" );
174         argv[ 2 ] = NULL;
175         bdb2i_attr_index_config( li, "ldbm objectclass initialization", 0, 2, argv,
176             1 );
177         free( argv[ 1 ] );
178
179         /*  initialize the cache mutex */
180         ldap_pvt_thread_mutex_init( &li->li_cache.c_mutex );
181
182         /*  initialize the TP file head  */
183         if ( bdb2i_txn_head_init( &li->li_txn_head ) != 0 )
184                 return 1;
185
186         be->be_private = li;
187
188         return 0;
189 }
190
191
192 int
193 bdb2_back_db_init(
194     BackendDB   *be
195 )
196 {
197         struct timeval  time1;
198         int             ret;
199
200         bdb2i_start_timing( be->bd_info, &time1 );
201
202         ret = bdb2i_back_db_init_internal( be );
203         bdb2i_stop_timing( be->bd_info, time1, "DB-INIT", NULL, NULL );
204
205         return( ret );
206 }
207
208
209 int
210 bdb2_back_db_open(
211     BackendDB   *be
212 )
213 {
214         int  rc;
215
216         rc = bdb2_back_db_startup( be );
217
218         return( rc );
219 }
220
221 int
222 bdb2_back_db_destroy(
223     BackendDB   *be
224 )
225 {
226         /* should free/destroy every in be_private */
227         free( be->be_private );
228         be->be_private = NULL;
229         return 0;
230 }
231
232