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, "( OLcfgDbAt:0.1 NAME 'olcDbDirectory' "
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 "( OLcfgDbAt:1.1 NAME 'olcDbCacheSize' "
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, "( OLcfgDbAt:1.2 NAME 'olcDbCheckpoint' "
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, "( OLcfgDbAt:1.3 NAME 'olcDbConfig' "
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, "( OLcfgDbAt:1.4 NAME 'olcDbNoSync' "
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 "( OLcfgDbAt:1.5 NAME 'olcDbDirtyRead' "
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 "( OLcfgDbAt:1.6 NAME 'olcDbIDLcacheSize' "
84 "DESC 'IDL cache size in IDLs' "
85 "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL },
86 { "index", "attr> <[pres,eq,approx,sub]", 2, 3, 0, ARG_MAGIC|BDB_INDEX,
87 bdb_cf_gen, "( OLcfgDbAt:0.2 NAME 'olcDbIndex' "
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 "( OLcfgDbAt:1.7 NAME 'olcDbLinearIndex' "
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, "( OLcfgDbAt:1.8 NAME 'olcDbLockDetect' "
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 "( OLcfgDbAt:0.3 NAME 'olcDbMode' "
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, "( OLcfgDbAt:1.9 NAME 'olcDbSearchStack' "
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 "( OLcfgDbAt:1.10 NAME 'olcDbShmKey' "
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[] = {
119 "NAME 'olcBdbConfig' "
120 "DESC 'BDB backend configuration' "
121 "SUP olcDatabaseConfig "
122 "MUST olcDbDirectory "
123 "MAY ( olcDbCacheSize $ olcDbCheckpoint $ olcDbConfig $ "
124 "olcDbNoSync $ olcDbDirtyRead $ olcDbIDLcacheSize $ "
125 "olcDbIndex $ olcDbLinearIndex $ olcDbLockDetect $ "
126 "olcDbMode $ olcDbSearchStack $ olcDbShmKey ) )",
127 Cft_Database, &bdb_oc },
132 bdb_cf_oc(ConfigArgs *c)
134 if ( c->op == SLAP_CONFIG_EMIT ) {
135 value_add_one( &c->rvalue_vals, &bdb_oc->soc_cname );
141 static slap_verbmasks bdb_lockd[] = {
142 { BER_BVC("default"), DB_LOCK_DEFAULT },
143 { BER_BVC("oldest"), DB_LOCK_OLDEST },
144 { BER_BVC("random"), DB_LOCK_RANDOM },
145 { BER_BVC("youngest"), DB_LOCK_YOUNGEST },
146 { BER_BVC("fewest"), DB_LOCK_MINLOCKS },
151 bdb_cf_gen(ConfigArgs *c)
153 struct bdb_info *bdb = c->be->be_private;
156 if ( c->op == SLAP_CONFIG_EMIT ) {
160 if (bdb->bi_txn_cp ) {
163 bv.bv_len = sprintf( buf, "%d %d", bdb->bi_txn_cp_kbyte,
164 bdb->bi_txn_cp_min );
166 value_add_one( &c->rvalue_vals, &bv );
173 if ( bdb->bi_dbenv_home ) {
174 c->value_string = ch_strdup( bdb->bi_dbenv_home );
181 if ( bdb->bi_db_config ) {
186 for (i=0; !BER_BVISNULL(&bdb->bi_db_config[i]); i++) {
187 bv.bv_len = sprintf( bv.bv_val, "{%d}%s", i,
188 bdb->bi_db_config[i].bv_val );
189 value_add_one( &c->rvalue_vals, &bv );
192 if ( !c->rvalue_vals ) rc = 1;
196 if ( bdb->bi_dbenv_xflags & DB_TXN_NOSYNC )
201 bdb_attr_index_unparse( bdb, &c->rvalue_vals );
202 if ( !c->rvalue_vals ) rc = 1;
207 if ( bdb->bi_lock_detect != DB_LOCK_DEFAULT ) {
209 for (i=0; !BER_BVISNULL(&bdb_lockd[i].word); i++) {
210 if ( bdb->bi_lock_detect == bdb_lockd[i].mask ) {
211 value_add_one( &c->rvalue_vals, &bdb_lockd[i].word );
220 c->value_int = bdb->bi_search_stack_depth;
228 bdb->bi_txn_cp_kbyte = strtol( c->argv[1], NULL, 0 );
229 bdb->bi_txn_cp_min = strtol( c->argv[2], NULL, 0 );
233 char *ptr = c->line + STRLENOF("dbconfig");
235 while (!isspace(*ptr)) ptr++;
236 while (isspace(*ptr)) ptr++;
238 /* If we're just starting up...
240 if ( !bdb->bi_db_is_open ) {
242 /* If a DB_CONFIG file exists, or we don't know the path
243 * to the DB_CONFIG file, ignore these directives
245 if ( bdb->bi_db_has_config || !bdb->bi_db_config_path )
247 f = fopen( bdb->bi_db_config_path, "a" );
249 /* FIXME: EBCDIC probably needs special handling */
250 fprintf( f, "%s\n", ptr );
254 ber_str2bv( ptr, 0, 1, &bv );
255 ber_bvarray_add( &bdb->bi_db_config, &bv );
259 case BDB_DIRECTORY: {
263 bdb->bi_dbenv_home = c->value_string;
265 /* See if a DB_CONFIG file already exists here */
266 bdb->bi_db_config_path = ch_malloc( strlen( bdb->bi_dbenv_home ) +
267 STRLENOF(LDAP_DIRSEP) + STRLENOF("DB_CONFIG") + 1 );
268 ptr = lutil_strcopy( bdb->bi_db_config_path, bdb->bi_dbenv_home );
269 *ptr++ = LDAP_DIRSEP[0];
270 strcpy( ptr, "DB_CONFIG" );
272 f = fopen( bdb->bi_db_config_path, "r" );
274 bdb->bi_db_has_config = 1;
282 bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
284 bdb->bi_dbenv_xflags &= ~DB_TXN_NOSYNC;
288 rc = bdb_attr_index_config( bdb, c->fname, c->lineno,
289 c->argc - 1, &c->argv[1] );
291 if( rc != LDAP_SUCCESS ) return 1;
295 rc = verb_to_mask( c->argv[1], bdb_lockd );
296 if ( BER_BVISNULL(&bdb_lockd[rc].word) ) {
297 fprintf( stderr, "%s: "
298 "bad policy (%s) in \"lockDetect <policy>\" line\n",
299 c->log, c->argv[1] );
302 bdb->bi_lock_detect = rc;
306 if ( c->value_int < MINIMUM_SEARCH_STACK_DEPTH ) {
308 "%s: depth %d too small, using %d\n",
309 c->log, c->value_int, MINIMUM_SEARCH_STACK_DEPTH );
310 c->value_int = MINIMUM_SEARCH_STACK_DEPTH;
312 bdb->bi_search_stack_depth = c->value_int;
318 int bdb_back_init_cf( BackendInfo *bi )
321 bi->bi_cf_table = bdbcfg;
323 rc = config_register_schema( bdbcfg, bdbocs );
325 bdbcfg[0].ad = slap_schema.si_ad_objectClass;