]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb/config.c
Declare bdb_cache_entry_db_unlock().
[openldap] / servers / slapd / back-bdb / config.c
1 /* config.c - bdb backend configuration file routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11 #include <ac/string.h>
12
13 #include "back-bdb.h"
14 #include "external.h"
15
16 #ifdef DB_DIRTY_READ
17 #       define  SLAP_BDB_ALLOW_DIRTY_READ
18 #endif
19
20 int
21 bdb_db_config(
22         BackendDB       *be,
23         const char      *fname,
24         int             lineno,
25         int             argc,
26         char    **argv )
27 {
28         struct bdb_info *bdb = (struct bdb_info *) be->be_private;
29
30         if ( bdb == NULL ) {
31                 fprintf( stderr, "%s: line %d: "
32                         "bdb database info is null!\n",
33                         fname, lineno );
34                 return 1;
35         }
36
37         /* directory is the DB_HOME */
38         if ( strcasecmp( argv[0], "directory" ) == 0 ) {
39                 if ( argc < 2 ) {
40                         fprintf( stderr, "%s: line %d: "
41                                 "missing dir in \"directory <dir>\" line\n",
42                                 fname, lineno );
43                         return 1;
44                 }
45                 if ( bdb->bi_dbenv_home ) {
46                         free( bdb->bi_dbenv_home );
47                 }
48                 bdb->bi_dbenv_home = ch_strdup( argv[1] );
49
50 #ifdef SLAP_BDB_ALLOW_DIRTY_READ
51         } else if ( strcasecmp( argv[0], "dirtyread" ) == 0 ) {
52                 bdb->bi_db_opflags |= DB_DIRTY_READ;
53 #endif
54         /* transaction logging configuration */
55         } else if ( strcasecmp( argv[0], "dbnosync" ) == 0 ) {
56                 bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
57
58         /* transaction checkpoint configuration */
59         } else if ( strcasecmp( argv[0], "checkpoint" ) == 0 ) {
60                 if ( argc < 3 ) {
61                         fprintf( stderr, "%s: line %d: "
62                                 "missing parameters in \"checkpoint <kbyte> <min>\" line\n",
63                                 fname, lineno );
64                         return 1;
65                 }
66                 bdb->bi_txn_cp = 1;
67                 bdb->bi_txn_cp_kbyte = strtol( argv[1], NULL, 0 );
68                 bdb->bi_txn_cp_min = strtol( argv[2], NULL, 0 );
69
70         /* lock detect configuration */
71         } else if ( strcasecmp( argv[0], "lockdetect" ) == 0 ) {
72                 if ( argc < 2 ) {
73                         fprintf( stderr, "%s: line %d: "
74                                 "missing parameters in \"lockDetect <policy>\" line\n",
75                                 fname, lineno );
76                         return 1;
77                 }
78
79                 if( strcasecmp( argv[1], "default" ) == 0 ) {
80                         bdb->bi_lock_detect = DB_LOCK_DEFAULT;
81
82                 } else if( strcasecmp( argv[1], "oldest" ) == 0 ) {
83                         bdb->bi_lock_detect = DB_LOCK_OLDEST;
84
85                 } else if( strcasecmp( argv[1], "random" ) == 0 ) {
86                         bdb->bi_lock_detect = DB_LOCK_RANDOM;
87
88                 } else if( strcasecmp( argv[1], "youngest" ) == 0 ) {
89                         bdb->bi_lock_detect = DB_LOCK_YOUNGEST;
90
91                 } else if( strcasecmp( argv[1], "fewest" ) == 0 ) {
92                         bdb->bi_lock_detect = DB_LOCK_MINLOCKS;
93
94                 } else {
95                         fprintf( stderr, "%s: line %d: "
96                                 "bad policy (%s) in \"lockDetect <policy>\" line\n",
97                                 fname, lineno, argv[1] );
98                         return 1;
99                 }
100
101         /* mode with which to create new database files */
102         } else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
103                 if ( argc < 2 ) {
104                         fprintf( stderr, "%s: line %d: "
105                                 "missing mode in \"mode <mode>\" line\n",
106                                 fname, lineno );
107                         return 1;
108                 }
109                 bdb->bi_dbenv_mode = strtol( argv[1], NULL, 0 );
110
111         /* attribute to index */
112         } else if ( strcasecmp( argv[0], "index" ) == 0 ) {
113                 int rc;
114                 if ( argc < 2 ) {
115                         fprintf( stderr, "%s: line %d: "
116                                 "missing attr in \"index <attr> [pres,eq,approx,sub]\" line\n",
117                                 fname, lineno );
118                         return 1;
119                 } else if ( argc > 3 ) {
120                         fprintf( stderr, "%s: line %d: "
121                                 "extra junk after \"index <attr> [pres,eq,approx,sub]\" "
122                                 "line (ignored)\n",
123                                 fname, lineno );
124                 }
125                 rc = bdb_attr_index_config( bdb, fname, lineno, argc - 1, &argv[1] );
126
127                 if( rc != LDAP_SUCCESS ) return 1;
128
129         /* unique key for shared memory regions */
130         } else if ( strcasecmp( argv[0], "shm_key" ) == 0 ) {
131                  if ( argc < 2 ) {
132                          fprintf( stderr,
133                  "%s: line %d: missing key in \"shm_key <key>\" line\n",
134                              fname, lineno );
135                          return( 1 );
136                  }
137                  bdb->bi_shm_key = atoi( argv[1] );
138
139         /* size of the cache in entries */
140         } else if ( strcasecmp( argv[0], "cachesize" ) == 0 ) {
141                  if ( argc < 2 ) {
142                          fprintf( stderr,
143                  "%s: line %d: missing size in \"cachesize <size>\" line\n",
144                              fname, lineno );
145                          return( 1 );
146                  }
147                  bdb->bi_cache.c_maxsize = atoi( argv[1] );
148
149         /* depth of search stack cache in units of (IDL)s */
150         } else if ( strcasecmp( argv[0], "searchstack" ) == 0 ) {
151                 if ( argc < 2 ) {
152                         fprintf( stderr,
153                 "%s: line %d: missing depth in \"searchstack <depth>\" line\n",
154                         fname, lineno );
155                         return( 1 );
156                 }
157                 bdb->bi_search_stack_depth = atoi( argv[1] );
158                 if ( bdb->bi_search_stack_depth < MINIMUM_SEARCH_STACK_DEPTH ) {
159                         fprintf( stderr,
160                 "%s: line %d: depth %d too small, using %d\n",
161                         fname, lineno, bdb->bi_search_stack_depth,
162                         MINIMUM_SEARCH_STACK_DEPTH );
163                         bdb->bi_search_stack_depth = MINIMUM_SEARCH_STACK_DEPTH;
164                 }
165
166 #ifdef SLAP_IDL_CACHE
167         /* size of the IDL cache in entries */
168         } else if ( strcasecmp( argv[0], "idlcachesize" ) == 0 ) {
169                  if ( argc < 2 ) {
170                          fprintf( stderr,
171                  "%s: line %d: missing size in \"idlcachesize <size>\" line\n",
172                              fname, lineno );
173                          return( 1 );
174                  }
175                  if ( !( slapMode & SLAP_TOOL_MODE ) )
176                          bdb->bi_idl_cache_max_size = atoi( argv[1] );
177 #endif
178
179         /* anything else */
180         } else {
181                 fprintf( stderr, "%s: line %d: "
182                         "unknown directive \"%s\" in bdb database definition (ignored)\n",
183                         fname, lineno, argv[0] );
184         }
185
186         return 0;
187 }