1 /* config.c - bdb backend configuration file routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2005 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>.
20 #include <ac/string.h>
29 # define SLAP_BDB_ALLOW_DIRTY_READ
32 static ObjectClass *bdb_oc;
34 static ConfigDriver bdb_cf_oc, bdb_cf_gen;
47 static ConfigTable bdbcfg[] = {
48 { "", "", 0, 0, 0, ARG_MAGIC,
49 bdb_cf_oc, NULL, NULL, NULL },
50 { "directory", "dir", 2, 2, 0, ARG_STRING|ARG_MAGIC|BDB_DIRECTORY,
51 bdb_cf_gen, "( OLcfgAt:1.1 NAME 'dbDirectory' "
52 "DESC 'Directory for database content' "
53 "EQUALITY caseIgnoreMatch "
54 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
55 { "cachesize", "size", 2, 2, 0, ARG_INT|ARG_OFFSET,
56 (void *)offsetof(struct bdb_info, bi_cache.c_maxsize),
57 "( OLcfgAt:1.2 NAME 'dbCacheSize' "
58 "DESC 'Entry cache size in entries' "
59 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
60 { "checkpoint", "kbyte> <min", 3, 3, 0, ARG_MAGIC|BDB_CHKPT,
61 bdb_cf_gen, "( OLcfgAt:1.3 NAME 'dbCheckpoint' "
62 "DESC 'Database checkpoint interval in kbytes and minutes' "
63 "SYNTAX OMsDirectoryString SINGLE-VALUE )",NULL, NULL },
64 { "dbconfig", "DB_CONFIG setting", 3, 0, 0, ARG_MAGIC|BDB_CONFIG,
65 bdb_cf_gen, "( OLcfgAt:1.13 NAME 'dbConfig' "
66 "DESC 'BerkeleyDB DB_CONFIG configuration directives' "
67 "SYNTAX OMsDirectoryString )",NULL, NULL },
68 { "dbnosync", NULL, 1, 2, 0, ARG_ON_OFF|ARG_MAGIC|BDB_NOSYNC,
69 bdb_cf_gen, "( OLcfgAt:1.4 NAME 'dbNoSync' "
70 "DESC 'Disable synchronous database writes' "
71 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
72 { "dirtyread", NULL, 1, 2, 0,
73 #ifdef SLAP_BDB_ALLOW_DIRTY_READ
74 ARG_ON_OFF|ARG_MAGIC|BDB_DIRTYR, bdb_cf_gen,
78 "( OLcfgAt:1.5 NAME 'dbDirtyRead' "
79 "DESC 'Allow reads of uncommitted data' "
80 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
81 { "idlcachesize", "size", 2, 2, 0, ARG_INT|ARG_OFFSET,
82 (void *)offsetof(struct bdb_info,bi_idl_cache_max_size),
83 "( OLcfgAt:1.6 NAME 'dbIDLcacheSize' "
84 "DESC 'IDL cache size in IDLs' "
85 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
86 { "index", "attr> <[pres,eq,approx,sub]", 3, 3, 0, ARG_MAGIC|BDB_INDEX,
87 bdb_cf_gen, "( OLcfgAt:1.7 NAME 'dbIndex' "
88 "DESC 'Attribute index parameters' "
89 "SYNTAX OMsDirectoryString )", NULL, NULL },
90 { "linearindex", NULL, 1, 2, 0, ARG_ON_OFF|ARG_OFFSET,
91 (void *)offsetof(struct bdb_info, bi_linear_index),
92 "( OLcfgAt:1.8 NAME 'dbLinearIndex' "
93 "DESC 'Index attributes one at a time' "
94 "SYNTAX OMsBoolean SINGLE-VALUE )", NULL, NULL },
95 { "lockdetect", "policy", 2, 2, 0, ARG_MAGIC|BDB_LOCKD,
96 bdb_cf_gen, "( OLcfgAt:1.9 NAME 'dbLockDetect' "
97 "DESC 'Deadlock detection algorithm' "
98 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
99 { "mode", "mode", 2, 2, 0, ARG_INT|ARG_OFFSET,
100 (void *)offsetof(struct bdb_info, bi_dbenv_mode),
101 "( OLcfgAt:1.10 NAME 'dbMode' "
102 "DESC 'Unix permissions of database files' "
103 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
104 { "searchstack", "depth", 2, 2, 0, ARG_INT|ARG_MAGIC|BDB_SSTACK,
105 bdb_cf_gen, "( OLcfgAt:1.11 NAME 'dbSearchStack' "
106 "DESC 'Depth of search stack in IDLs' "
107 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
108 { "shm_key", "key", 2, 2, 0, ARG_INT|ARG_OFFSET,
109 (void *)offsetof(struct bdb_info, bi_shm_key),
110 "( OLcfgAt:1.12 NAME 'dbShmKey' "
111 "DESC 'Key for shared memory region' "
112 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
113 { NULL, NULL, 0, 0, 0, ARG_IGNORED,
114 NULL, NULL, NULL, NULL }
117 static ConfigOCs bdbocs[] = {
120 "DESC 'BDB backend configuration' "
121 "SUP olcDatabaseConfig "
123 "MAY ( dbCacheSize $ dbCheckpoint $ dbConfig $ dbNoSync $ "
124 "dbDirtyRead $ dbIDLcacheSize $ dbIndex $ dbLinearIndex $ "
125 "dbLockDetect $ dbMode $ dbSearchStack $ dbShmKey ) )",
126 Cft_Database, &bdb_oc },
131 bdb_cf_oc(ConfigArgs *c)
133 if ( c->op == SLAP_CONFIG_EMIT ) {
134 value_add_one( &c->rvalue_vals, &bdb_oc->soc_cname );
140 static slap_verbmasks bdb_lockd[] = {
141 { BER_BVC("default"), DB_LOCK_DEFAULT },
142 { BER_BVC("oldest"), DB_LOCK_OLDEST },
143 { BER_BVC("random"), DB_LOCK_RANDOM },
144 { BER_BVC("youngest"), DB_LOCK_YOUNGEST },
145 { BER_BVC("fewest"), DB_LOCK_MINLOCKS },
150 bdb_cf_gen(ConfigArgs *c)
152 struct bdb_info *bdb = c->be->be_private;
155 if ( c->op == SLAP_CONFIG_EMIT ) {
159 if (bdb->bi_txn_cp ) {
162 bv.bv_len = sprintf( buf, "%d %d", bdb->bi_txn_cp_kbyte,
163 bdb->bi_txn_cp_min );
165 value_add_one( &c->rvalue_vals, &bv );
172 if ( bdb->bi_dbenv_home ) {
173 c->value_string = ch_strdup( bdb->bi_dbenv_home );
180 if ( bdb->bi_db_config ) {
185 for (i=0; !BER_BVISNULL(&bdb->bi_db_config[i]); i++) {
186 bv.bv_len = sprintf( bv.bv_val, "{%d}%s", i,
187 bdb->bi_db_config[i].bv_val );
188 value_add_one( &c->rvalue_vals, &bv );
191 if ( !c->rvalue_vals ) rc = 1;
195 if ( bdb->bi_dbenv_xflags & DB_TXN_NOSYNC )
200 bdb_attr_index_unparse( bdb, &c->rvalue_vals );
201 if ( !c->rvalue_vals ) rc = 1;
206 if ( bdb->bi_lock_detect != DB_LOCK_DEFAULT ) {
208 for (i=0; !BER_BVISNULL(&bdb_lockd[i].word); i++) {
209 if ( bdb->bi_lock_detect == bdb_lockd[i].mask ) {
210 value_add_one( &c->rvalue_vals, &bdb_lockd[i].word );
219 c->value_int = bdb->bi_search_stack_depth;
227 bdb->bi_txn_cp_kbyte = strtol( c->argv[1], NULL, 0 );
228 bdb->bi_txn_cp_min = strtol( c->argv[2], NULL, 0 );
232 char *ptr = c->line + STRLENOF("dbconfig");
234 while (!isspace(*ptr)) ptr++;
235 while (isspace(*ptr)) ptr++;
237 /* If we're just starting up...
239 if ( !bdb->bi_db_is_open ) {
241 /* If a DB_CONFIG file exists, or we don't know the path
242 * to the DB_CONFIG file, ignore these directives
244 if ( bdb->bi_db_has_config || !bdb->bi_db_config_path )
246 f = fopen( bdb->bi_db_config_path, "a" );
248 /* FIXME: EBCDIC probably needs special handling */
249 fprintf( f, "%s\n", ptr );
253 ber_str2bv( ptr, 0, 1, &bv );
254 ber_bvarray_add( &bdb->bi_db_config, &bv );
258 case BDB_DIRECTORY: {
262 bdb->bi_dbenv_home = c->value_string;
264 /* See if a DB_CONFIG file already exists here */
265 bdb->bi_db_config_path = ch_malloc( strlen( bdb->bi_dbenv_home ) +
266 STRLENOF(LDAP_DIRSEP) + STRLENOF("DB_CONFIG") + 1 );
267 ptr = lutil_strcopy( bdb->bi_db_config_path, bdb->bi_dbenv_home );
268 *ptr++ = LDAP_DIRSEP[0];
269 strcpy( ptr, "DB_CONFIG" );
271 f = fopen( bdb->bi_db_config_path, "r" );
273 bdb->bi_db_has_config = 1;
281 bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
283 bdb->bi_dbenv_xflags &= ~DB_TXN_NOSYNC;
287 rc = bdb_attr_index_config( bdb, c->fname, c->lineno,
288 c->argc - 1, &c->argv[1] );
290 if( rc != LDAP_SUCCESS ) return 1;
294 rc = verb_to_mask( c->argv[1], bdb_lockd );
295 if ( BER_BVISNULL(&bdb_lockd[rc].word) ) {
296 fprintf( stderr, "%s: "
297 "bad policy (%s) in \"lockDetect <policy>\" line\n",
298 c->log, c->argv[1] );
301 bdb->bi_lock_detect = rc;
305 if ( c->value_int < MINIMUM_SEARCH_STACK_DEPTH ) {
307 "%s: depth %d too small, using %d\n",
308 c->log, c->value_int, MINIMUM_SEARCH_STACK_DEPTH );
309 c->value_int = MINIMUM_SEARCH_STACK_DEPTH;
311 bdb->bi_search_stack_depth = c->value_int;
317 int bdb_back_init_cf( BackendInfo *bi )
320 bi->bi_cf_table = bdbcfg;
322 rc = config_register_schema( bdbcfg, bdbocs );
324 bdbcfg[0].ad = slap_schema.si_ad_objectClass;