Reorganized config/bconfig. Migrated back-bdb config.

This commit is contained in:
Howard Chu 2005-03-02 04:46:50 +00:00
parent a2a9ae725f
commit 44521fd902
6 changed files with 2737 additions and 2621 deletions

View File

@ -21,175 +21,229 @@
#include "back-bdb.h"
#include "config.h"
#ifdef DB_DIRTY_READ
# define SLAP_BDB_ALLOW_DIRTY_READ
#endif
int
bdb_db_config(
BackendDB *be,
const char *fname,
int lineno,
int argc,
char **argv )
{
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
static ObjectClass *bdb_oc;
if ( bdb == NULL ) {
fprintf( stderr, "%s: line %d: "
"bdb database info is null!\n",
fname, lineno );
return 1;
}
static ConfigDriver bdb_cf_oc, bdb_cf_gen;
/* directory is the DB_HOME */
if ( strcasecmp( argv[0], "directory" ) == 0 ) {
if ( argc < 2 ) {
fprintf( stderr, "%s: line %d: "
"missing dir in \"directory <dir>\" line\n",
fname, lineno );
return 1;
}
if ( bdb->bi_dbenv_home ) {
free( bdb->bi_dbenv_home );
}
bdb->bi_dbenv_home = ch_strdup( argv[1] );
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
} else if ( strcasecmp( argv[0], "dirtyread" ) == 0 ) {
bdb->bi_db_opflags |= DB_DIRTY_READ;
ARG_ON_OFF|ARG_MAGIC|BDB_DIRTYR, bdb_cf_gen,
#else
ARG_IGNORED, NULL,
#endif
/* transaction logging configuration */
} else if ( strcasecmp( argv[0], "dbnosync" ) == 0 ) {
bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
"( 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 }
};
/* slapindex algorithm tuning */
} else if ( strcasecmp( argv[0], "linearindex" ) == 0 ) {
bdb->bi_linear_index = 1;
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 }
};
/* transaction checkpoint configuration */
} else if ( strcasecmp( argv[0], "checkpoint" ) == 0 ) {
if ( argc < 3 ) {
fprintf( stderr, "%s: line %d: "
"missing parameters in \"checkpoint <kbyte> <min>\" line\n",
fname, lineno );
return 1;
static int
bdb_cf_oc(ConfigArgs *c)
{
if ( c->emit ) {
value_add_one( &c->rvalue_vals, &bdb_oc->soc_cname );
return 0;
}
return 1;
}
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;
}
return rc;
}
switch( c->type ) {
case BDB_CHKPT:
bdb->bi_txn_cp = 1;
bdb->bi_txn_cp_kbyte = strtol( argv[1], NULL, 0 );
bdb->bi_txn_cp_min = strtol( argv[2], NULL, 0 );
bdb->bi_txn_cp_kbyte = strtol( c->argv[1], NULL, 0 );
bdb->bi_txn_cp_min = strtol( c->argv[2], NULL, 0 );
break;
/* lock detect configuration */
} else if ( strcasecmp( argv[0], "lockdetect" ) == 0 ) {
if ( argc < 2 ) {
fprintf( stderr, "%s: line %d: "
"missing parameters in \"lockDetect <policy>\" line\n",
fname, lineno );
return 1;
}
case BDB_NOSYNC:
if ( c->value_int )
bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
else
bdb->bi_dbenv_xflags &= ~DB_TXN_NOSYNC;
break;
if( strcasecmp( argv[1], "default" ) == 0 ) {
bdb->bi_lock_detect = DB_LOCK_DEFAULT;
} else if( strcasecmp( argv[1], "oldest" ) == 0 ) {
bdb->bi_lock_detect = DB_LOCK_OLDEST;
} else if( strcasecmp( argv[1], "random" ) == 0 ) {
bdb->bi_lock_detect = DB_LOCK_RANDOM;
} else if( strcasecmp( argv[1], "youngest" ) == 0 ) {
bdb->bi_lock_detect = DB_LOCK_YOUNGEST;
} else if( strcasecmp( argv[1], "fewest" ) == 0 ) {
bdb->bi_lock_detect = DB_LOCK_MINLOCKS;
} else {
fprintf( stderr, "%s: line %d: "
"bad policy (%s) in \"lockDetect <policy>\" line\n",
fname, lineno, argv[1] );
return 1;
}
/* mode with which to create new database files */
} else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
if ( argc < 2 ) {
fprintf( stderr, "%s: line %d: "
"missing mode in \"mode <mode>\" line\n",
fname, lineno );
return 1;
}
bdb->bi_dbenv_mode = strtol( argv[1], NULL, 0 );
/* attribute to index */
} else if ( strcasecmp( argv[0], "index" ) == 0 ) {
int rc;
if ( argc < 2 ) {
fprintf( stderr, "%s: line %d: "
"missing attr in \"index <attr> [pres,eq,approx,sub]\" line\n",
fname, lineno );
return 1;
} else if ( argc > 3 ) {
fprintf( stderr, "%s: line %d: "
"extra junk after \"index <attr> [pres,eq,approx,sub]\" "
"line (ignored)\n",
fname, lineno );
}
rc = bdb_attr_index_config( bdb, fname, lineno, argc - 1, &argv[1] );
case BDB_INDEX:
rc = bdb_attr_index_config( bdb, c->fname, c->lineno,
c->argc - 1, &c->argv[1] );
if( rc != LDAP_SUCCESS ) return 1;
break;
/* unique key for shared memory regions */
} else if ( strcasecmp( argv[0], "shm_key" ) == 0 ) {
if ( argc < 2 ) {
fprintf( stderr,
"%s: line %d: missing key in \"shm_key <key>\" line\n",
fname, lineno );
return( 1 );
case BDB_LOCKD:
rc = verb_to_mask( c, bdb_lockd, 1 );
if ( !bdb_lockd[rc].word ) {
fprintf( stderr, "%s: "
"bad policy (%s) in \"lockDetect <policy>\" line\n",
c->log, c->argv[1] );
return 1;
}
bdb->bi_shm_key = atoi( argv[1] );
bdb->bi_lock_detect = rc;
break;
/* size of the cache in entries */
} else if ( strcasecmp( argv[0], "cachesize" ) == 0 ) {
if ( argc < 2 ) {
case BDB_SSTACK:
if ( c->value_int < MINIMUM_SEARCH_STACK_DEPTH ) {
fprintf( stderr,
"%s: line %d: missing size in \"cachesize <size>\" line\n",
fname, lineno );
return( 1 );
"%s: depth %d too small, using %d\n",
c->log, c->value_int, MINIMUM_SEARCH_STACK_DEPTH );
c->value_int = MINIMUM_SEARCH_STACK_DEPTH;
}
bdb->bi_cache.c_maxsize = atoi( argv[1] );
/* depth of search stack cache in units of (IDL)s */
} else if ( strcasecmp( argv[0], "searchstack" ) == 0 ) {
if ( argc < 2 ) {
fprintf( stderr,
"%s: line %d: missing depth in \"searchstack <depth>\" line\n",
fname, lineno );
return( 1 );
}
bdb->bi_search_stack_depth = atoi( argv[1] );
if ( bdb->bi_search_stack_depth < MINIMUM_SEARCH_STACK_DEPTH ) {
fprintf( stderr,
"%s: line %d: depth %d too small, using %d\n",
fname, lineno, bdb->bi_search_stack_depth,
MINIMUM_SEARCH_STACK_DEPTH );
bdb->bi_search_stack_depth = MINIMUM_SEARCH_STACK_DEPTH;
}
/* size of the IDL cache in entries */
} else if ( strcasecmp( argv[0], "idlcachesize" ) == 0 ) {
if ( argc < 2 ) {
fprintf( stderr,
"%s: line %d: missing size in \"idlcachesize <size>\" line\n",
fname, lineno );
return( 1 );
}
if ( !( slapMode & SLAP_TOOL_MODE ) )
bdb->bi_idl_cache_max_size = atoi( argv[1] );
/* anything else */
} else {
return SLAP_CONF_UNKNOWN;
bdb->bi_search_stack_depth = c->value_int;
break;
}
return 0;
}
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;
}

View File

@ -36,8 +36,6 @@ static const struct bdbi_database {
{ NULL, NULL, 0, 0 }
};
struct berval bdb_uuid = BER_BVNULL;
typedef void * db_malloc(size_t);
typedef void * db_realloc(void *, size_t);
@ -71,6 +69,7 @@ bdb_db_init( BackendDB *be )
ldap_pvt_thread_rdwr_init ( &bdb->bi_cache.c_rwlock );
be->be_private = bdb;
be->be_cf_table = be->bd_info->bi_cf_table;
return 0;
}
@ -461,6 +460,8 @@ int
bdb_back_initialize(
BackendInfo *bi )
{
int rc;
static char *controls[] = {
LDAP_CONTROL_ASSERT,
LDAP_CONTROL_MANAGEDSAIT,
@ -529,20 +530,13 @@ bdb_back_initialize(
db_env_set_func_yield( ldap_pvt_thread_yield );
#endif
{
static char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
bdb_uuid.bv_len = lutil_uuidstr( uuidbuf, sizeof( uuidbuf ));
bdb_uuid.bv_val = uuidbuf;
}
bi->bi_open = 0;
bi->bi_close = 0;
bi->bi_config = 0;
bi->bi_destroy = 0;
bi->bi_db_init = bdb_db_init;
bi->bi_db_config = bdb_db_config;
bi->bi_db_config = 0;
bi->bi_db_open = bdb_db_open;
bi->bi_db_close = bdb_db_close;
bi->bi_db_destroy = bdb_db_destroy;
@ -583,7 +577,9 @@ bdb_back_initialize(
bi->bi_connection_init = 0;
bi->bi_connection_destroy = 0;
return 0;
rc = bdb_back_init_cf(bi);
return rc;
}
#if (SLAPD_BDB == SLAPD_MOD_DYNAMIC && !defined(BDB_HIER)) || \

View File

@ -56,6 +56,14 @@ int bdb_attr_index_config LDAP_P(( struct bdb_info *bdb,
void bdb_attr_index_destroy LDAP_P(( Avlnode *tree ));
/*
* config.c
*/
#define bdb_back_init_cf BDB_SYMBOL(back_init_cf)
int bdb_back_init_cf( BackendInfo *bi );
/*
* dbcache.c
*/
@ -324,13 +332,6 @@ int bdb_index_entry LDAP_P(( Operation *op, DB_TXN *t, int r, Entry *e ));
#define bdb_index_entry_del(op,t,e) \
bdb_index_entry((op),(t),SLAP_INDEX_DELETE_OP,(e))
/*
* init.c
*/
#define bdb_uuid BDB_SYMBOL(uuid)
extern struct berval bdb_uuid;
/*
* key.c
*/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -56,6 +56,13 @@ typedef struct ConfigTable {
#define ARG_BAD_CONF 0xdead0000 /* overload return values */
#define ARG_UNKNOWN 0xc0de0000
extern ConfigTable config_back_cf_table[];
typedef struct ConfigOCs {
char *def;
ObjectClass **oc;
} ConfigOCs;
typedef struct config_args_s {
int argc;
char **argv;
@ -94,24 +101,6 @@ typedef struct config_args_s {
typedef int (ConfigDriver)(ConfigArgs *c);
#ifdef SLAPD_MODULES
typedef struct modpath_s {
struct modpath_s *mp_next;
struct berval mp_path;
BerVarray mp_loads;
} ModPaths;
#endif
struct verb_mask_list { char *word; int mask; };
typedef struct ConfigFile {
struct ConfigFile *c_sibs;
struct ConfigFile *c_kids;
struct berval c_file;
#ifdef SLAPD_MODULES
ModPaths c_modpaths;
ModPaths *c_modlast;
#endif
BerVarray c_dseFiles;
} ConfigFile;
int config_back_init( ConfigFile *cfp, ConfigTable *ct );
int config_get_vals(ConfigTable *ct, ConfigArgs *c);