2001-10-05 09:19:58 +08:00
|
|
|
/* config.c - bdb backend configuration file routine */
|
2000-09-26 05:10:21 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-29 05:08:20 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2005-01-02 04:49:32 +08:00
|
|
|
* Copyright 2000-2005 The OpenLDAP Foundation.
|
2003-11-29 05:08:20 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
2000-09-26 05:10:21 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
|
|
|
#include "back-bdb.h"
|
|
|
|
|
2005-03-02 12:46:50 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2001-12-09 10:34:45 +08:00
|
|
|
#ifdef DB_DIRTY_READ
|
|
|
|
# define SLAP_BDB_ALLOW_DIRTY_READ
|
|
|
|
#endif
|
2001-11-27 12:35:58 +08:00
|
|
|
|
2005-03-02 12:46:50 +08:00
|
|
|
static ObjectClass *bdb_oc;
|
|
|
|
|
|
|
|
static ConfigDriver bdb_cf_oc, bdb_cf_gen;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
BDB_CHKPT = 1,
|
|
|
|
BDB_NOSYNC,
|
|
|
|
BDB_DIRTYR,
|
|
|
|
BDB_INDEX,
|
|
|
|
BDB_LOCKD,
|
|
|
|
BDB_SSTACK
|
|
|
|
};
|
|
|
|
|
|
|
|
static ConfigTable bdbcfg[] = {
|
|
|
|
{ "", "", 0, 0, 0, ARG_MAGIC,
|
|
|
|
bdb_cf_oc, NULL, NULL, NULL },
|
|
|
|
{ "directory", "dir", 2, 2, 0, ARG_STRING|ARG_OFFSET,
|
|
|
|
(void *)offsetof(struct bdb_info, bi_dbenv_home),
|
|
|
|
"( OLcfgAt:1.1 NAME 'dbDirectory' "
|
|
|
|
"DESC 'Directory for database content' "
|
|
|
|
"EQUALITY caseIgnoreMatch "
|
|
|
|
"SYNTAX OMsDirectoryString )", NULL, NULL },
|
|
|
|
{ "cachesize", "size", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_OFFSET,
|
|
|
|
(void *)offsetof(struct bdb_info, bi_cache.c_maxsize),
|
|
|
|
"( OLcfgAt:1.2 NAME 'dbCacheSize' "
|
|
|
|
"DESC 'Entry cache size in entries' "
|
|
|
|
"SYNTAX OMsInteger )", NULL, NULL },
|
|
|
|
{ "checkpoint", "kbyte> <min", 3, 3, 0, ARG_MAGIC|BDB_CHKPT,
|
|
|
|
bdb_cf_gen, "( OLcfgAt:1.3 NAME 'dbCheckpoint' "
|
|
|
|
"DESC 'Database checkpoint interval in kbytes and minutes' "
|
|
|
|
"SYNTAX OMsDirectoryString )",NULL, NULL },
|
|
|
|
{ "dbnosync", NULL, 1, 2, 0, ARG_ON_OFF|ARG_MAGIC|BDB_NOSYNC,
|
|
|
|
bdb_cf_gen, "( OLcfgAt:1.4 NAME 'dbNoSync' "
|
|
|
|
"DESC 'Disable synchronous database writes' "
|
|
|
|
"SYNTAX OMsBoolean )", NULL, NULL },
|
|
|
|
{ "dirtyread", NULL, 1, 2, 0,
|
|
|
|
#ifdef SLAP_BDB_ALLOW_DIRTY_READ
|
|
|
|
ARG_ON_OFF|ARG_MAGIC|BDB_DIRTYR, bdb_cf_gen,
|
|
|
|
#else
|
|
|
|
ARG_IGNORED, NULL,
|
|
|
|
#endif
|
|
|
|
"( OLcfgAt:1.5 NAME 'dbDirtyRead' "
|
|
|
|
"DESC 'Allow reads of uncommitted data' "
|
|
|
|
"SYNTAX OMsBoolean )", NULL, NULL },
|
|
|
|
{ "idlcachesize", "size", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_OFFSET,
|
|
|
|
(void *)offsetof(struct bdb_info,bi_idl_cache_max_size),
|
|
|
|
"( OLcfgAt:1.6 NAME 'dbIDLcacheSize' "
|
|
|
|
"DESC 'IDL cache size in IDLs' "
|
|
|
|
"SYNTAX OMsInteger )", NULL, NULL },
|
|
|
|
{ "index", "attr> <[pres,eq,approx,sub]", 3, 3, 0, ARG_MAGIC|BDB_INDEX,
|
|
|
|
bdb_cf_gen, "( OLcfgAt:1.7 NAME 'dbIndex' "
|
|
|
|
"DESC 'Attribute index parameters' "
|
|
|
|
"SYNTAX OMsDirectoryString )", NULL, NULL },
|
|
|
|
{ "linearindex", NULL, 1, 2, 0, ARG_ON_OFF|ARG_OFFSET,
|
|
|
|
(void *)offsetof(struct bdb_info, bi_linear_index),
|
|
|
|
"( OLcfgAt:1.8 NAME 'dbLinearIndex' "
|
|
|
|
"DESC 'Index attributes one at a time' "
|
|
|
|
"SYNTAX OMsBoolean )", NULL, NULL },
|
|
|
|
{ "lockdetect", "policy", 2, 2, 0, ARG_MAGIC|BDB_LOCKD,
|
|
|
|
bdb_cf_gen, "( OLcfgAt:1.9 NAME 'dbLockDetect' "
|
|
|
|
"DESC 'Deadlock detection algorithm' "
|
|
|
|
"SYNTAX OMsDirectoryString )", NULL, NULL },
|
|
|
|
{ "mode", "mode", 2, 2, 0, ARG_LONG|ARG_OFFSET,
|
|
|
|
(void *)offsetof(struct bdb_info, bi_dbenv_mode),
|
|
|
|
"( OLcfgAt:1.10 NAME 'dbMode' "
|
|
|
|
"DESC 'Unix permissions of database files' "
|
|
|
|
"SYNTAX OMsInteger )", NULL, NULL },
|
|
|
|
{ "searchstack", "depth", 2, 2, 0, ARG_INT|ARG_MAGIC|BDB_SSTACK,
|
|
|
|
bdb_cf_gen, "( OLcfgAt:1.11 NAME 'dbSearchStack' "
|
|
|
|
"DESC 'Depth of search stack in IDLs' "
|
|
|
|
"SYNTAX OMsInteger )", NULL, NULL },
|
|
|
|
{ "shm_key", "key", 2, 2, 0, ARG_INT|ARG_NONZERO|ARG_OFFSET,
|
|
|
|
(void *)offsetof(struct bdb_info, bi_shm_key),
|
|
|
|
"( OLcfgAt:1.12 NAME 'dbShmKey' "
|
|
|
|
"DESC 'Key for shared memory region' "
|
|
|
|
"SYNTAX OMsInteger )", NULL, NULL },
|
|
|
|
{ NULL, NULL, 0, 0, 0, ARG_IGNORED,
|
|
|
|
NULL, NULL, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static ConfigOCs bdbocs[] = {
|
|
|
|
{ "( OLcfgOc:1.1 "
|
|
|
|
"NAME 'bdbConfig' "
|
|
|
|
"DESC 'BDB backend configuration' "
|
|
|
|
"AUXILIARY "
|
|
|
|
"MAY ( dbDirectory $ dbCacheSize $ dbCheckpoint $ dbNoSync $ "
|
|
|
|
"dbDirtyRead $ dbIDLcacheSize $ dbIndex $ dbLinearIndex $ "
|
|
|
|
"dbLockDetect $ dbMode $ dbSearchStack $ dbShmKey ) )",
|
|
|
|
&bdb_oc },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
bdb_cf_oc(ConfigArgs *c)
|
2000-09-26 05:10:21 +08:00
|
|
|
{
|
2005-03-02 12:46:50 +08:00
|
|
|
if ( c->emit ) {
|
|
|
|
value_add_one( &c->rvalue_vals, &bdb_oc->soc_cname );
|
|
|
|
return 0;
|
2000-09-26 05:10:21 +08:00
|
|
|
}
|
2005-03-02 12:46:50 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2000-09-26 05:10:21 +08:00
|
|
|
|
2005-03-02 12:46:50 +08:00
|
|
|
static struct verb_mask_list bdb_lockd[] = {
|
|
|
|
{ "default", DB_LOCK_DEFAULT },
|
|
|
|
{ "oldest", DB_LOCK_OLDEST },
|
|
|
|
{ "random", DB_LOCK_RANDOM },
|
|
|
|
{ "youngest", DB_LOCK_YOUNGEST },
|
|
|
|
{ "fewest", DB_LOCK_MINLOCKS },
|
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
bdb_cf_gen(ConfigArgs *c)
|
|
|
|
{
|
|
|
|
struct bdb_info *bdb = c->be->be_private;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if ( c->emit ) {
|
|
|
|
rc = 0;
|
|
|
|
switch( c->type ) {
|
|
|
|
case BDB_CHKPT:
|
|
|
|
if (bdb->bi_txn_cp ) {
|
|
|
|
char buf[64];
|
|
|
|
struct berval bv;
|
|
|
|
bv.bv_len = sprintf( buf, "%d %d", bdb->bi_txn_cp_kbyte,
|
|
|
|
bdb->bi_txn_cp_min );
|
|
|
|
bv.bv_val = buf;
|
|
|
|
value_add_one( &c->rvalue_vals, &bv );
|
|
|
|
} else{
|
|
|
|
rc = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BDB_NOSYNC:
|
|
|
|
if ( bdb->bi_dbenv_xflags & DB_TXN_NOSYNC )
|
|
|
|
c->value_int = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BDB_INDEX:
|
|
|
|
rc = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BDB_LOCKD:
|
|
|
|
rc = 1;
|
|
|
|
if ( bdb->bi_lock_detect != DB_LOCK_DEFAULT ) {
|
|
|
|
int i;
|
|
|
|
for (i=0; bdb_lockd[i].word; i++) {
|
|
|
|
if ( bdb->bi_lock_detect == bdb_lockd[i].mask ) {
|
|
|
|
struct berval bv;
|
|
|
|
ber_str2bv( bdb_lockd[i].word, 0, 1, &bv );
|
|
|
|
ber_bvarray_add( &c->rvalue_vals, &bv );
|
|
|
|
rc = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BDB_SSTACK:
|
|
|
|
c->value_int = bdb->bi_search_stack_depth;
|
|
|
|
break;
|
2000-09-28 12:09:13 +08:00
|
|
|
}
|
2005-03-02 12:46:50 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
switch( c->type ) {
|
|
|
|
case BDB_CHKPT:
|
2000-09-28 12:09:13 +08:00
|
|
|
bdb->bi_txn_cp = 1;
|
2005-03-02 12:46:50 +08:00
|
|
|
bdb->bi_txn_cp_kbyte = strtol( c->argv[1], NULL, 0 );
|
|
|
|
bdb->bi_txn_cp_min = strtol( c->argv[2], NULL, 0 );
|
|
|
|
break;
|
2000-09-29 08:18:29 +08:00
|
|
|
|
2005-03-02 12:46:50 +08:00
|
|
|
case BDB_NOSYNC:
|
|
|
|
if ( c->value_int )
|
|
|
|
bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
|
|
|
|
else
|
|
|
|
bdb->bi_dbenv_xflags &= ~DB_TXN_NOSYNC;
|
|
|
|
break;
|
2000-09-29 08:18:29 +08:00
|
|
|
|
2005-03-02 12:46:50 +08:00
|
|
|
case BDB_INDEX:
|
|
|
|
rc = bdb_attr_index_config( bdb, c->fname, c->lineno,
|
|
|
|
c->argc - 1, &c->argv[1] );
|
2000-09-29 08:18:29 +08:00
|
|
|
|
2005-03-02 12:46:50 +08:00
|
|
|
if( rc != LDAP_SUCCESS ) return 1;
|
|
|
|
break;
|
2002-01-18 21:32:01 +08:00
|
|
|
|
2005-03-02 12:46:50 +08:00
|
|
|
case BDB_LOCKD:
|
|
|
|
rc = verb_to_mask( c, bdb_lockd, 1 );
|
|
|
|
if ( !bdb_lockd[rc].word ) {
|
|
|
|
fprintf( stderr, "%s: "
|
2002-09-19 09:13:27 +08:00
|
|
|
"bad policy (%s) in \"lockDetect <policy>\" line\n",
|
2005-03-02 12:46:50 +08:00
|
|
|
c->log, c->argv[1] );
|
2000-09-26 05:10:21 +08:00
|
|
|
return 1;
|
2003-11-10 10:44:25 +08:00
|
|
|
}
|
2005-03-02 12:46:50 +08:00
|
|
|
bdb->bi_lock_detect = rc;
|
|
|
|
break;
|
2002-01-25 15:19:01 +08:00
|
|
|
|
2005-03-02 12:46:50 +08:00
|
|
|
case BDB_SSTACK:
|
|
|
|
if ( c->value_int < MINIMUM_SEARCH_STACK_DEPTH ) {
|
2003-04-05 18:05:27 +08:00
|
|
|
fprintf( stderr,
|
2005-03-02 12:46:50 +08:00
|
|
|
"%s: depth %d too small, using %d\n",
|
|
|
|
c->log, c->value_int, MINIMUM_SEARCH_STACK_DEPTH );
|
|
|
|
c->value_int = MINIMUM_SEARCH_STACK_DEPTH;
|
2003-04-05 18:05:27 +08:00
|
|
|
}
|
2005-03-02 12:46:50 +08:00
|
|
|
bdb->bi_search_stack_depth = c->value_int;
|
|
|
|
break;
|
2000-09-26 05:10:21 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2005-03-02 12:46:50 +08:00
|
|
|
|
|
|
|
int bdb_back_init_cf( BackendInfo *bi )
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
bi->bi_cf_table = bdbcfg;
|
|
|
|
|
|
|
|
rc = init_config_attrs( bdbcfg );
|
|
|
|
if ( rc ) return rc;
|
|
|
|
bdbcfg[0].ad = slap_schema.si_ad_objectClass;
|
|
|
|
rc = init_config_ocs( bdbocs );
|
|
|
|
return rc;
|
|
|
|
}
|