/* * Class: jmdb_DatabaseWrapper * Method: envSetFlags * Signature: (J*Z)V */ JNIEXPORT void JNICALL Java_jmdb_DatabaseWrapper_envSetFlags(JNIEnv *vm, jclass clazz, jlong envL, jint flags, jboolean onoff) { MDB_env *envC = (MDB_env*) envL; int code = mdb_env_set_flags(envC, flags, onoff); if (code) { throwDatabaseException(vm, code); } }
static int mdb_cf_gen( ConfigArgs *c ) { struct mdb_info *mdb = c->be->be_private; int rc; if ( c->op == SLAP_CONFIG_EMIT ) { rc = 0; switch( c->type ) { case MDB_MODE: { char buf[64]; struct berval bv; bv.bv_len = snprintf( buf, sizeof(buf), "0%o", mdb->mi_dbenv_mode ); if ( bv.bv_len > 0 && bv.bv_len < sizeof(buf) ) { bv.bv_val = buf; value_add_one( &c->rvalue_vals, &bv ); } else { rc = 1; } } break; case MDB_CHKPT: if ( mdb->mi_txn_cp ) { char buf[64]; struct berval bv; bv.bv_len = snprintf( buf, sizeof(buf), "%ld %ld", (long) mdb->mi_txn_cp_kbyte, (long) mdb->mi_txn_cp_min ); if ( bv.bv_len > 0 && bv.bv_len < sizeof(buf) ) { bv.bv_val = buf; value_add_one( &c->rvalue_vals, &bv ); } else { rc = 1; } } else { rc = 1; } break; case MDB_DIRECTORY: if ( mdb->mi_dbenv_home ) { c->value_string = ch_strdup( mdb->mi_dbenv_home ); } else { rc = 1; } break; case MDB_DBNOSYNC: if ( mdb->mi_dbenv_flags & MDB_NOSYNC ) c->value_int = 1; break; case MDB_ENVFLAGS: if ( mdb->mi_dbenv_flags ) { mask_to_verbs( mdb_envflags, mdb->mi_dbenv_flags, &c->rvalue_vals ); } if ( !c->rvalue_vals ) rc = 1; break; case MDB_INDEX: mdb_attr_index_unparse( mdb, &c->rvalue_vals ); if ( !c->rvalue_vals ) rc = 1; break; case MDB_SSTACK: c->value_int = mdb->mi_search_stack_depth; break; case MDB_MAXREADERS: c->value_int = mdb->mi_readers; break; case MDB_MAXSIZE: c->value_ulong = mdb->mi_mapsize; break; } return rc; } else if ( c->op == LDAP_MOD_DELETE ) { rc = 0; switch( c->type ) { case MDB_MODE: #if 0 /* FIXME: does it make any sense to change the mode, * if we don't exec a chmod()? */ mdb->bi_dbenv_mode = SLAPD_DEFAULT_DB_MODE; break; #endif /* single-valued no-ops */ case MDB_SSTACK: case MDB_MAXREADERS: case MDB_MAXSIZE: break; case MDB_CHKPT: if ( mdb->mi_txn_cp_task ) { struct re_s *re = mdb->mi_txn_cp_task; mdb->mi_txn_cp_task = NULL; ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex ); if ( ldap_pvt_runqueue_isrunning( &slapd_rq, re ) ) ldap_pvt_runqueue_stoptask( &slapd_rq, re ); ldap_pvt_runqueue_remove( &slapd_rq, re ); ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex ); } mdb->mi_txn_cp = 0; break; case MDB_DIRECTORY: mdb->mi_flags |= MDB_RE_OPEN; ch_free( mdb->mi_dbenv_home ); mdb->mi_dbenv_home = NULL; c->cleanup = mdb_cf_cleanup; ldap_pvt_thread_pool_purgekey( mdb->mi_dbenv ); break; case MDB_DBNOSYNC: mdb_env_set_flags( mdb->mi_dbenv, MDB_NOSYNC, 0 ); mdb->mi_dbenv_flags &= ~MDB_NOSYNC; break; case MDB_ENVFLAGS: if ( c->valx == -1 ) { int i; for ( i=0; mdb_envflags[i].mask; i++) { if ( mdb->mi_dbenv_flags & mdb_envflags[i].mask ) { /* not all flags are runtime resettable */ rc = mdb_env_set_flags( mdb->mi_dbenv, mdb_envflags[i].mask, 0 ); if ( rc ) { mdb->mi_flags |= MDB_RE_OPEN; c->cleanup = mdb_cf_cleanup; rc = 0; } mdb->mi_dbenv_flags ^= mdb_envflags[i].mask; } } } else { int i = verb_to_mask( c->line, mdb_envflags ); if ( mdb_envflags[i].mask & mdb->mi_dbenv_flags ) { rc = mdb_env_set_flags( mdb->mi_dbenv, mdb_envflags[i].mask, 0 ); if ( rc ) { mdb->mi_flags |= MDB_RE_OPEN; c->cleanup = mdb_cf_cleanup; rc = 0; } mdb->mi_dbenv_flags ^= mdb_envflags[i].mask; } else { /* unknown keyword */ rc = 1; } } break; case MDB_INDEX: if ( c->valx == -1 ) { int i; /* delete all (FIXME) */ for ( i = 0; i < mdb->mi_nattrs; i++ ) { mdb->mi_attrs[i]->ai_indexmask |= MDB_INDEX_DELETING; } mdb->mi_flags |= MDB_DEL_INDEX; c->cleanup = mdb_cf_cleanup; } else { struct berval bv, def = BER_BVC("default"); char *ptr; for (ptr = c->line; !isspace( (unsigned char) *ptr ); ptr++); bv.bv_val = c->line; bv.bv_len = ptr - bv.bv_val; if ( bvmatch( &bv, &def )) { mdb->mi_defaultmask = 0; } else { int i; char **attrs; char sep; sep = bv.bv_val[ bv.bv_len ]; bv.bv_val[ bv.bv_len ] = '\0'; attrs = ldap_str2charray( bv.bv_val, "," ); for ( i = 0; attrs[ i ]; i++ ) { AttributeDescription *ad = NULL; const char *text; AttrInfo *ai; slap_str2ad( attrs[ i ], &ad, &text ); /* if we got here... */ assert( ad != NULL ); ai = mdb_attr_mask( mdb, ad ); /* if we got here... */ assert( ai != NULL ); ai->ai_indexmask |= MDB_INDEX_DELETING; mdb->mi_flags |= MDB_DEL_INDEX; c->cleanup = mdb_cf_cleanup; } bv.bv_val[ bv.bv_len ] = sep; ldap_charray_free( attrs ); } } break; } return rc; } switch( c->type ) { case MDB_MODE: if ( ASCII_DIGIT( c->argv[1][0] ) ) { long mode; char *next; errno = 0; mode = strtol( c->argv[1], &next, 0 ); if ( errno != 0 || next == c->argv[1] || next[0] != '\0' ) { fprintf( stderr, "%s: " "unable to parse mode=\"%s\".\n", c->log, c->argv[1] ); return 1; } mdb->mi_dbenv_mode = mode; } else { char *m = c->argv[1]; int who, what, mode = 0; if ( strlen( m ) != STRLENOF("-rwxrwxrwx") ) { return 1; } if ( m[0] != '-' ) { return 1; } m++; for ( who = 0; who < 3; who++ ) { for ( what = 0; what < 3; what++, m++ ) { if ( m[0] == '-' ) { continue; } else if ( m[0] != "rwx"[what] ) { return 1; } mode += ((1 << (2 - what)) << 3*(2 - who)); } } mdb->mi_dbenv_mode = mode; } break; case MDB_CHKPT: { long l; mdb->mi_txn_cp = 1; if ( lutil_atolx( &l, c->argv[1], 0 ) != 0 ) { fprintf( stderr, "%s: " "invalid kbyte \"%s\" in \"checkpoint\".\n", c->log, c->argv[1] ); return 1; } mdb->mi_txn_cp_kbyte = l; if ( lutil_atolx( &l, c->argv[2], 0 ) != 0 ) { fprintf( stderr, "%s: " "invalid minutes \"%s\" in \"checkpoint\".\n", c->log, c->argv[2] ); return 1; } mdb->mi_txn_cp_min = l; /* If we're in server mode and time-based checkpointing is enabled, * submit a task to perform periodic checkpoints. */ if ((slapMode & SLAP_SERVER_MODE) && mdb->mi_txn_cp_min ) { struct re_s *re = mdb->mi_txn_cp_task; if ( re ) { re->interval.tv_sec = mdb->mi_txn_cp_min * 60; } else { if ( c->be->be_suffix == NULL || BER_BVISNULL( &c->be->be_suffix[0] ) ) { fprintf( stderr, "%s: " "\"checkpoint\" must occur after \"suffix\".\n", c->log ); return 1; } ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex ); mdb->mi_txn_cp_task = ldap_pvt_runqueue_insert( &slapd_rq, mdb->mi_txn_cp_min * 60, mdb_checkpoint, mdb, LDAP_XSTRING(mdb_checkpoint), c->be->be_suffix[0].bv_val ); ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex ); } } } break; case MDB_DIRECTORY: { FILE *f; char *ptr, *testpath; int len; len = strlen( c->value_string ); testpath = ch_malloc( len + STRLENOF(LDAP_DIRSEP) + STRLENOF("DUMMY") + 1 ); ptr = lutil_strcopy( testpath, c->value_string ); *ptr++ = LDAP_DIRSEP[0]; strcpy( ptr, "DUMMY" ); f = fopen( testpath, "w" ); if ( f ) { fclose( f ); unlink( testpath ); } ch_free( testpath ); if ( !f ) { snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: invalid path: %s", c->log, strerror( errno )); Debug( LDAP_DEBUG_ANY, "%s\n", c->cr_msg, 0, 0 ); return -1; } if ( mdb->mi_dbenv_home ) ch_free( mdb->mi_dbenv_home ); mdb->mi_dbenv_home = c->value_string; } break; case MDB_DBNOSYNC: if ( c->value_int ) mdb->mi_dbenv_flags |= MDB_NOSYNC; else mdb->mi_dbenv_flags ^= MDB_NOSYNC; if ( mdb->mi_flags & MDB_IS_OPEN ) { mdb_env_set_flags( mdb->mi_dbenv, MDB_NOSYNC, c->value_int ); } break; case MDB_ENVFLAGS: { int i, j; for ( i=1; i<c->argc; i++ ) { j = verb_to_mask( c->argv[i], mdb_envflags ); if ( mdb_envflags[j].mask ) { if ( mdb->mi_flags & MDB_IS_OPEN ) rc = mdb_env_set_flags( mdb->mi_dbenv, mdb_envflags[j].mask, 1 ); else rc = 0; if ( rc ) { mdb->mi_flags |= MDB_RE_OPEN; c->cleanup = mdb_cf_cleanup; rc = 0; } mdb->mi_dbenv_flags |= mdb_envflags[j].mask; } else { /* unknown keyword */ rc = 1; } } } break; case MDB_INDEX: rc = mdb_attr_index_config( mdb, c->fname, c->lineno, c->argc - 1, &c->argv[1], &c->reply); if( rc != LDAP_SUCCESS ) return 1; c->cleanup = mdb_cf_cleanup; mdb->mi_flags |= MDB_OPEN_INDEX; if (( mdb->mi_flags & MDB_IS_OPEN ) && !mdb->mi_index_task ) { /* Start the task as soon as we finish here. Set a long * interval (10 hours) so that it only gets scheduled once. */ if ( c->be->be_suffix == NULL || BER_BVISNULL( &c->be->be_suffix[0] ) ) { fprintf( stderr, "%s: " "\"index\" must occur after \"suffix\".\n", c->log ); return 1; } ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex ); mdb->mi_index_task = ldap_pvt_runqueue_insert( &slapd_rq, 36000, mdb_online_index, c->be, LDAP_XSTRING(mdb_online_index), c->be->be_suffix[0].bv_val ); ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex ); } break; case MDB_SSTACK: if ( c->value_int < MINIMUM_SEARCH_STACK_DEPTH ) { fprintf( stderr, "%s: depth %d too small, using %d\n", c->log, c->value_int, MINIMUM_SEARCH_STACK_DEPTH ); c->value_int = MINIMUM_SEARCH_STACK_DEPTH; } mdb->mi_search_stack_depth = c->value_int; break; case MDB_MAXREADERS: mdb->mi_readers = c->value_int; if ( mdb->mi_flags & MDB_IS_OPEN ) { mdb->mi_flags |= MDB_RE_OPEN; c->cleanup = mdb_cf_cleanup; } break; case MDB_MAXSIZE: mdb->mi_mapsize = c->value_ulong; if ( mdb->mi_flags & MDB_IS_OPEN ) { mdb->mi_flags |= MDB_RE_OPEN; c->cleanup = mdb_cf_cleanup; } break; } return 0; }