From bff244da5b3a8137141114279750179ba1805781 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Fri, 1 Apr 2005 11:26:43 +0000 Subject: [PATCH] Add dbconfig directive for creating/writing the DB_CONFIG file --- servers/slapd/back-bdb/back-bdb.h | 4 ++ servers/slapd/back-bdb/config.c | 106 ++++++++++++++++++++++++++---- servers/slapd/back-bdb/init.c | 28 ++++++++ 3 files changed, 124 insertions(+), 14 deletions(-) diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index eb8cb02080..27a261d1e1 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -191,6 +191,10 @@ struct bdb_info { ldap_pvt_thread_rdwr_t bi_idl_tree_rwlock; ldap_pvt_thread_mutex_t bi_idl_tree_lrulock; alock_info_t bi_alock_info; + char *bi_db_config_path; + BerVarray bi_db_config; + int bi_db_is_open; + int bi_db_has_config; }; #define bi_id2entry bi_databases[BDB_ID2ENTRY] diff --git a/servers/slapd/back-bdb/config.c b/servers/slapd/back-bdb/config.c index 0ddb2d4f0c..785bd7e3da 100644 --- a/servers/slapd/back-bdb/config.c +++ b/servers/slapd/back-bdb/config.c @@ -23,6 +23,8 @@ #include "config.h" +#include "lutil.h" + #ifdef DB_DIRTY_READ # define SLAP_BDB_ALLOW_DIRTY_READ #endif @@ -33,6 +35,8 @@ static ConfigDriver bdb_cf_oc, bdb_cf_gen; enum { BDB_CHKPT = 1, + BDB_CONFIG, + BDB_DIRECTORY, BDB_NOSYNC, BDB_DIRTYR, BDB_INDEX, @@ -43,25 +47,28 @@ enum { 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' " + { "directory", "dir", 2, 2, 0, ARG_STRING|ARG_MAGIC|BDB_DIRECTORY, + bdb_cf_gen, "( OLcfgAt:1.1 NAME 'dbDirectory' " "DESC 'Directory for database content' " "EQUALITY caseIgnoreMatch " - "SYNTAX OMsDirectoryString )", NULL, NULL }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "cachesize", "size", 2, 2, 0, ARG_INT|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 }, + "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL }, { "checkpoint", "kbyte> <[pres,eq,approx,sub]", 3, 3, 0, ARG_MAGIC|BDB_INDEX, bdb_cf_gen, "( OLcfgAt:1.7 NAME 'dbIndex' " "DESC 'Attribute index parameters' " @@ -84,25 +91,25 @@ static ConfigTable bdbcfg[] = { (void *)offsetof(struct bdb_info, bi_linear_index), "( OLcfgAt:1.8 NAME 'dbLinearIndex' " "DESC 'Index attributes one at a time' " - "SYNTAX OMsBoolean )", NULL, NULL }, + "SYNTAX OMsBoolean SINGLE-VALUE )", 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 }, + "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL }, { "mode", "mode", 2, 2, 0, ARG_INT|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 }, + "SYNTAX OMsInteger SINGLE-VALUE )", 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 }, + "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL }, { "shm_key", "key", 2, 2, 0, ARG_INT|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 }, + "SYNTAX OMsInteger SINGLE-VALUE )", NULL, NULL }, { NULL, NULL, 0, 0, 0, ARG_IGNORED, NULL, NULL, NULL, NULL } }; @@ -113,7 +120,7 @@ static ConfigOCs bdbocs[] = { "DESC 'BDB backend configuration' " "SUP olcDatabaseConfig " "MUST dbDirectory " - "MAY ( dbCacheSize $ dbCheckpoint $ dbNoSync $ " + "MAY ( dbCacheSize $ dbCheckpoint $ dbConfig $ dbNoSync $ " "dbDirtyRead $ dbIDLcacheSize $ dbIndex $ dbLinearIndex $ " "dbLockDetect $ dbMode $ dbSearchStack $ dbShmKey ) )", Cft_Database, &bdb_oc }, @@ -161,6 +168,29 @@ bdb_cf_gen(ConfigArgs *c) } break; + case BDB_DIRECTORY: + if ( bdb->bi_dbenv_home ) { + c->value_string = ch_strdup( bdb->bi_dbenv_home ); + } else { + rc = 1; + } + break; + + case BDB_CONFIG: + if ( bdb->bi_db_config ) { + int i; + struct berval bv; + + bv.bv_val = c->log; + for (i=0; !BER_BVISNULL(&bdb->bi_db_config[i]); i++) { + bv.bv_len = sprintf( bv.bv_val, "{%d}%s", i, + bdb->bi_db_config[i].bv_val ); + value_add_one( &c->rvalue_vals, &bv ); + } + } + if ( !c->rvalue_vals ) rc = 1; + break; + case BDB_NOSYNC: if ( bdb->bi_dbenv_xflags & DB_TXN_NOSYNC ) c->value_int = 1; @@ -198,6 +228,54 @@ bdb_cf_gen(ConfigArgs *c) bdb->bi_txn_cp_min = strtol( c->argv[2], NULL, 0 ); break; + case BDB_CONFIG: { + char *ptr = c->line + STRLENOF("dbconfig"); + struct berval bv; + while (!isspace(*ptr)) ptr++; + while (isspace(*ptr)) ptr++; + + /* If we're just starting up... + */ + if ( !bdb->bi_db_is_open ) { + FILE *f; + /* If a DB_CONFIG file exists, or we don't know the path + * to the DB_CONFIG file, ignore these directives + */ + if ( bdb->bi_db_has_config || !bdb->bi_db_config_path ) + break; + f = fopen( bdb->bi_db_config_path, "a" ); + if ( f ) { + /* FIXME: EBCDIC probably needs special handling */ + fprintf( f, "%s\n", ptr ); + fclose( f ); + } + } + ber_str2bv( ptr, 0, 1, &bv ); + ber_bvarray_add( &bdb->bi_db_config, &bv ); + } + break; + + case BDB_DIRECTORY: { + FILE *f; + char *ptr; + + bdb->bi_dbenv_home = c->value_string; + + /* See if a DB_CONFIG file already exists here */ + bdb->bi_db_config_path = ch_malloc( strlen( bdb->bi_dbenv_home ) + + STRLENOF(LDAP_DIRSEP) + STRLENOF("DB_CONFIG")); + ptr = lutil_strcopy( bdb->bi_db_config_path, bdb->bi_dbenv_home ); + *ptr++ = LDAP_DIRSEP[0]; + strcpy( ptr, "DB_CONFIG" ); + + f = fopen( bdb->bi_db_config_path, "r" ); + if ( f ) { + bdb->bi_db_has_config = 1; + fclose(f); + } + } + break; + case BDB_NOSYNC: if ( c->value_int ) bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC; diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c index 962aa47f39..81899ed2d5 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -381,6 +381,29 @@ bdb_db_open( BackendDB *be ) ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex ); } + if ( slapMode & SLAP_SERVER_MODE && bdb->bi_db_has_config ) { + char buf[SLAP_TEXT_BUFLEN]; + FILE *f = fopen( bdb->bi_db_config_path, "r" ); + struct berval bv; + + if ( f ) { + while ( fgets( buf, sizeof(buf), f )) { + ber_str2bv( buf, 0, 1, &bv ); + if ( bv.bv_val[bv.bv_len-1] == '\n' ) { + bv.bv_len--; + bv.bv_val[bv.bv_len] = '\0'; + } + ber_bvarray_add( &bdb->bi_db_config, &bv ); + } + fclose( f ); + } else { + /* Eh? It disappeared between config and open?? */ + bdb->bi_db_has_config = 0; + } + + } + bdb->bi_db_is_open = 1; + return 0; } @@ -392,6 +415,10 @@ bdb_db_close( BackendDB *be ) struct bdb_db_info *db; bdb_idl_cache_entry_t *entry, *next_entry; + bdb->bi_db_is_open = 0; + + ber_bvarray_free( bdb->bi_db_config ); + while( bdb->bi_ndatabases-- ) { db = bdb->bi_databases[bdb->bi_ndatabases]; rc = db->bdi_db->close( db->bdi_db, 0 ); @@ -463,6 +490,7 @@ bdb_db_destroy( BackendDB *be ) } if( bdb->bi_dbenv_home ) ch_free( bdb->bi_dbenv_home ); + if( bdb->bi_db_config_path ) ch_free( bdb->bi_db_config_path ); ldap_pvt_thread_rdwr_destroy ( &bdb->bi_cache.c_rwlock ); ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.lru_mutex ); -- 2.39.5