10 #define _RPMDB_INTERNAL
18 #if (DB_VERSION_MAJOR == 3) || (DB_VERSION_MAJOR == 4)
23 struct _dbiIndex db3dbi;
27 static int dbi_use_cursors;
30 static int dbi_tear_down;
36 struct poptOption rdbOptions[] = {
38 #if defined(DB_CLIENT)
39 {
"client", 0,POPT_BIT_SET, &db3dbi.dbi_ecflags,
DB_CLIENT,
42 #if defined(DB_RPCCLIENT)
43 {
"client", 0,POPT_BIT_SET, &db3dbi.dbi_ecflags, DB_RPCCLIENT,
45 {
"rpcclient", 0,POPT_BIT_SET, &db3dbi.dbi_ecflags, DB_RPCCLIENT,
50 {
"xa_create", 0,POPT_BIT_SET, &db3dbi.dbi_cflags, DB_XA_CREATE,
55 #if defined(DB_AUTO_COMMIT)
56 {
"auto_commit", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_AUTO_COMMIT,
59 {
"create", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_CREATE,
61 #if defined(DB_MULTIVERSION)
62 {
"multiversion", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_MULTIVERSION,
65 {
"nommap", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_NOMMAP,
67 {
"thread", 0,POPT_BIT_SET, &db3dbi.dbi_oeflags, DB_THREAD,
70 {
"force", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_FORCE,
75 {
"cdb", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_CDB,
77 {
"lock", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_LOCK,
79 {
"log", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_LOG,
81 {
"mpool", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_MPOOL,
83 #if defined(DB_INIT_REP)
84 {
"rep", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_REP,
87 {
"txn", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_INIT_TXN,
91 {
"joinenv", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_JOINENV,
94 {
"lockdown", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_LOCKDOWN,
96 {
"private", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_PRIVATE,
98 {
"recover", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_RECOVER,
100 {
"recover_fatal", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_RECOVER_FATAL,
102 #if defined(DB_REGISTER)
103 {
"register", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_REGISTER,
106 {
"shared", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_SYSTEM_MEM,
108 {
"txn_nosync", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_TXN_NOSYNC,
110 {
"use_environ_root", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_USE_ENVIRON_ROOT,
112 {
"use_environ", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_USE_ENVIRON,
114 #if defined(DB_IGNORE_LEASE)
115 {
"ignore_lease", 0,POPT_BIT_SET, &db3dbi.dbi_eflags, DB_IGNORE_LEASE,
119 {
"txn_sync", 0,POPT_BIT_SET, &db3dbi.dbi_tflags, DB_TXN_SYNC,
121 {
"txn_nowait",0,POPT_BIT_SET, &db3dbi.dbi_tflags, DB_TXN_NOWAIT,
123 #if defined(DB_TXN_WAIT)
124 {
"txn_wait",0,POPT_BIT_SET, &db3dbi.dbi_tflags, DB_TXN_WAIT,
136 DB_LOG_BUFFER_FULL ???
160 DB_DUPSORT BTREE HASH
170 {
"excl", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_EXCL,
172 {
"fcntl_locking",0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_FCNTL_LOCKING,
174 #if defined(DB_NO_AUTO_COMMIT) && defined(NOTYET)
175 {
"noautocommit", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_NO_AUTO_COMMIT,
178 {
"rdonly", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_RDONLY,
180 #if defined(DB_RDWRMASTER) && defined(NOTYET)
181 {
"rdwrmaster", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_RDWRMASTER,
187 {
"truncate", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_TRUNCATE,
189 #if defined(DB_WRITEOPEN)
190 {
"writeopen", 0,POPT_BIT_SET, &db3dbi.dbi_oflags, DB_WRITEOPEN,
194 {
"btree", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_BTREE,
196 {
"hash", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_HASH,
198 {
"recno", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_RECNO,
200 {
"queue", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_QUEUE,
202 {
"unknown", 0,POPT_ARG_VAL, &db3dbi.dbi_type, DB_UNKNOWN,
205 {
"root", 0,POPT_ARG_STRING, &db3dbi.dbi_root, 0,
207 {
"home", 0,POPT_ARG_STRING, &db3dbi.dbi_home, 0,
209 {
"file", 0,POPT_ARG_STRING, &db3dbi.dbi_file, 0,
211 {
"subfile", 0,POPT_ARG_STRING, &db3dbi.dbi_subfile, 0,
213 {
"mode", 0,POPT_ARG_INT, &db3dbi.dbi_mode, 0,
215 {
"perms", 0,POPT_ARG_INT, &db3dbi.dbi_perms, 0,
217 {
"shmkey", 0,POPT_ARG_LONG, &db3dbi.dbi_shmkey, 0,
219 {
"tmpdir", 0,POPT_ARG_STRING, &db3dbi.dbi_tmpdir, 0,
222 {
"host", 0,POPT_ARG_STRING, &db3dbi.dbi_host, 0,
224 {
"server", 0,POPT_ARG_STRING, &db3dbi.dbi_host, 0,
226 {
"cl_timeout", 0,POPT_ARG_LONG, &db3dbi.dbi_cl_timeout, 0,
228 {
"sv_timeout", 0,POPT_ARG_LONG, &db3dbi.dbi_sv_timeout, 0,
231 {
"verify", 0,POPT_ARG_NONE, &db3dbi.dbi_verify_on_close, 0,
233 {
"teardown", 0,POPT_ARG_NONE, &dbi_tear_down, 0,
235 {
"usecursors",0,POPT_ARG_NONE, &dbi_use_cursors, 0,
237 {
"usedbenv", 0,POPT_ARG_NONE, &db3dbi.dbi_use_dbenv, 0,
239 {
"nofsync", 0,POPT_ARG_NONE, &db3dbi.dbi_no_fsync, 0,
241 {
"nodbsync", 0,POPT_ARG_NONE, &db3dbi.dbi_no_dbsync, 0,
243 {
"lockdbfd", 0,POPT_ARG_NONE, &db3dbi.dbi_lockdbfd, 0,
245 {
"temporary", 0,POPT_ARG_NONE, &db3dbi.dbi_temporary, 0,
247 {
"debug", 0,POPT_ARG_NONE, &db3dbi.dbi_debug, 0,
251 {
"cachesize", 0,POPT_ARG_INT, &db3dbi.dbi_cachesize, 0,
255 {
"errpfx", 0,POPT_ARG_STRING, &db3dbi.dbi_errpfx, 0,
258 {
"lorder", 0,POPT_ARG_INT, &db3dbi.dbi_lorder, 0,
260 {
"pagesize", 0,POPT_ARG_INT, &db3dbi.dbi_pagesize, 0,
263 {
"region_init", 0,POPT_ARG_VAL, &db3dbi.dbi_region_init, 1,
266 {
"thread_count", 0,POPT_ARG_INT, &db3dbi.dbi_thread_count, 0,
269 #if defined(DB_VERB_CHKPOINT)
270 {
"chkpoint", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_CHKPOINT,
273 {
"deadlock", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_DEADLOCK,
275 {
"recovery", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_RECOVERY,
277 #if defined(DB_VERB_REGISTER)
278 {
"register", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_REGISTER,
281 #if defined(DB_VERB_REPLICATION)
282 {
"replication", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_REPLICATION,
285 {
"waitsfor", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_WAITSFOR,
287 #if defined(DB_VERB_FILEOPS)
288 {
"fileops", 0,POPT_BIT_SET, &db3dbi.dbi_verbose, DB_VERB_FILEOPS,
291 #if defined(DB_VERB_FILEOPS_ALL)
292 {
"fileops_all",0,POPT_BIT_SET,&db3dbi.dbi_verbose, DB_VERB_FILEOPS_ALL,
295 {
"verbose", 0,POPT_ARG_VAL, &db3dbi.dbi_verbose, -1,
302 {
"lk_default",0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_DEFAULT,
304 {
"lk_expire", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_EXPIRE,
306 #if defined(DB_LOCK_MAXLOCKS)
307 {
"lk_maxlocks", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_MAXLOCKS,
310 #if defined(DB_LOCK_MAXWRITE)
311 {
"lk_maxwrite", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_MAXWRITE,
314 #if defined(DB_LOCK_MINLOCKS)
315 {
"lk_minlocks", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_MINLOCKS,
318 #if defined(DB_LOCK_MINWRITE)
319 {
"lk_minwrite", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_MINWRITE,
322 {
"lk_oldest", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_OLDEST,
324 {
"lk_random", 0,POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_RANDOM,
326 {
"lk_youngest",0, POPT_ARG_VAL, &db3dbi.dbi_lk_detect, DB_LOCK_YOUNGEST,
344 {
"lk_max_lockers", 0,POPT_ARG_INT, &db3dbi.dbi_lk_max_lockers, 0,
348 {
"lk_max_locks", 0,POPT_ARG_INT, &db3dbi.dbi_lk_max_locks, 0,
352 {
"lk_max_objects", 0,POPT_ARG_INT, &db3dbi.dbi_lk_max_objects, 0,
366 {
"lg_bsize", 0,POPT_ARG_INT, &db3dbi.dbi_lg_bsize, 0,
370 {
"lg_dir", 0,POPT_ARG_STRING, &db3dbi.dbi_lg_dir, 0,
374 {
"lg_filemode", 0,POPT_ARG_INT, &db3dbi.dbi_lg_filemode, 0,
378 {
"lg_max", 0,POPT_ARG_INT, &db3dbi.dbi_lg_max, 0,
382 {
"lg_regionmax", 0,POPT_ARG_INT, &db3dbi.dbi_lg_regionmax, 0,
386 {
"mp_size", 0,POPT_ARG_INT, &db3dbi.dbi_cachesize, 0,
390 {
"mmapsize", 0,POPT_ARG_INT, &db3dbi.dbi_mmapsize, 0,
392 {
"mp_mmapsize", 0,POPT_ARG_INT, &db3dbi.dbi_mmapsize, 0,
404 DB_MUTEX_PROCESS_ONLY mutex_alloc
405 DB_MUTEX_SELF_BLOCK mutex_alloc
406 DB_STAT_CLEAR mutex_stat*
410 {
"mutex_align", 0,POPT_ARG_INT, &db3dbi.dbi_mutex_align, 0,
414 {
"mutex_increment", 0,POPT_ARG_INT, &db3dbi.dbi_mutex_increment, 0,
418 {
"mutex_max", 0,POPT_ARG_INT, &db3dbi.dbi_mutex_max, 0,
422 {
"mutex_tas_spins", 0,POPT_ARG_INT, &db3dbi.dbi_mutex_tas_spins, 0,
436 {
"seq_cachesize", 0,POPT_ARG_INT, &db3dbi.dbi_seq_cachesize, 0,
440 #if defined(DB_SEQ_DEC)
441 {
"seq_dec", 0,POPT_BIT_SET, &db3dbi.dbi_seq_flags, DB_SEQ_DEC,
444 #if defined(DB_SEQ_INC)
445 {
"seq_inc", 0,POPT_BIT_SET, &db3dbi.dbi_seq_flags, DB_SEQ_INC,
448 #if defined(DB_SEQ_WRAP)
449 {
"seq_wrap", 0,POPT_BIT_SET, &db3dbi.dbi_seq_flags, DB_SEQ_WRAP,
455 {
"seq_min", 0,POPT_ARG_INT, &db3dbi.dbi_seq_min, 0,
457 {
"seq_max", 0,POPT_ARG_INT, &db3dbi.dbi_seq_max, 0,
467 {
"tx_max", 0,POPT_ARG_INT, &db3dbi.dbi_tx_max, 0,
476 {
"bt_dup", 0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_DUP,
478 {
"bt_dupsort",0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_DUPSORT,
480 {
"bt_recnum", 0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_RECNUM,
482 {
"bt_revsplitoff", 0,POPT_BIT_SET, &db3dbi.dbi_bt_flags, DB_REVSPLITOFF,
485 {
"h_dup", 0,POPT_BIT_SET, &db3dbi.dbi_h_flags, DB_DUP,
487 {
"h_dupsort", 0,POPT_BIT_SET, &db3dbi.dbi_h_flags, DB_DUPSORT,
489 {
"h_ffactor", 0,POPT_ARG_INT, &db3dbi.dbi_h_ffactor, 0,
491 {
"h_nelem", 0,POPT_ARG_INT, &db3dbi.dbi_h_nelem, 0,
494 {
"re_renumber", 0,POPT_BIT_SET, &db3dbi.dbi_re_flags, DB_RENUMBER,
496 {
"re_snapshot",0,POPT_BIT_SET, &db3dbi.dbi_re_flags, DB_SNAPSHOT,
498 {
"re_delim", 0,POPT_ARG_INT, &db3dbi.dbi_re_delim, 0,
500 {
"re_len", 0,POPT_ARG_INT, &db3dbi.dbi_re_len, 0,
502 {
"re_pad", 0,POPT_ARG_INT, &db3dbi.dbi_re_pad, 0,
504 {
"re_source", 0,POPT_ARG_STRING, &db3dbi.dbi_re_source, 0,
507 {
"q_extentsize", 0,POPT_ARG_INT, &db3dbi.dbi_q_extentsize, 0,
517 dbi->dbi_root =
_free(dbi->dbi_root);
518 dbi->dbi_home =
_free(dbi->dbi_home);
519 dbi->dbi_file =
_free(dbi->dbi_file);
520 dbi->dbi_subfile =
_free(dbi->dbi_subfile);
521 dbi->dbi_tmpdir =
_free(dbi->dbi_tmpdir);
522 dbi->dbi_host =
_free(dbi->dbi_host);
523 dbi->dbi_errpfx =
_free(dbi->dbi_errpfx);
524 dbi->dbi_re_source =
_free(dbi->dbi_re_source);
525 dbi->dbi_stats =
_free(dbi->dbi_stats);
532 static const char *db3_config_default =
533 "hash tmpdir=/var/tmp create cdb mpool mp_mmapsize=16Mb mp_size=1Mb perms=0644";
539 char dbiTagMacro[128];
542 sprintf(dbiTagMacro,
"%%{_dbi_config_%s}",
tagName(rpmtag));
544 if (!(dbOpts && *dbOpts && *dbOpts !=
'%')) {
545 dbOpts =
_free(dbOpts);
546 dbOpts =
rpmExpand(
"%{_dbi_config}", NULL);
547 if (!(dbOpts && *dbOpts && *dbOpts !=
'%')) {
548 dbOpts =
rpmExpand(db3_config_default, NULL);
554 if (dbOpts && *dbOpts && *dbOpts !=
'%') {
558 memset(&db3dbi, 0,
sizeof(db3dbi));
560 for (o = dbOpts; o && *o; o = oe) {
561 struct poptOption *opt;
570 for (oe = o; oe && *oe; oe++) {
573 if (oe[0] ==
':' && !(oe[1] ==
'/' && oe[2] ==
'/'))
582 for (pe = o; pe && *pe && *pe !=
'='; pe++)
584 p = (pe ? *pe++ =
'\0', pe : NULL);
587 for (tok = o; *tok ==
'!'; tok++)
591 for (opt = rdbOptions; opt->longName != NULL; opt++) {
592 if (strcmp(tok, opt->longName))
596 if (opt->longName == NULL) {
598 _(
"unrecognized db option: \"%s\" ignored.\n"), o);
603 argInfo = opt->argInfo;
604 if (argInfo == POPT_BIT_SET && *o ==
'!' && ((tok - o) % 2))
605 argInfo = POPT_BIT_CLR;
608 switch (argInfo & POPT_ARG_MASK) {
611 (void) poptSaveInt((
int *)opt->arg, argInfo, 1L);
614 (void) poptSaveInt((
int *)opt->arg, argInfo, (long)opt->val);
616 case POPT_ARG_STRING:
617 {
const char ** t = opt->arg;
630 {
long aLong = strtol(p, &pe, 0);
633 aLong *= 1024 * 1024;
636 else if (*pe !=
'\0') {
638 _(
"%s has invalid numeric value, skipped\n"),
644 if ((argInfo & POPT_ARG_MASK) == POPT_ARG_LONG) {
645 if (aLong == LONG_MIN || aLong == LONG_MAX) {
647 _(
"%s has too large or too small long value, skipped\n"),
651 (void) poptSaveLong((
long *)opt->arg, argInfo, aLong);
654 if (aLong > INT_MAX || aLong < INT_MIN) {
656 _(
"%s has too large or too small integer value, skipped\n"),
660 (void) poptSaveInt((
int *)opt->arg, argInfo, aLong);
671 dbOpts =
_free(dbOpts);
676 memset(&db3dbi, 0,
sizeof(db3dbi));
678 if (!(dbi->dbi_perms & 0600))
679 dbi->dbi_perms = 0644;
680 dbi->dbi_mode = rpmdb->db_mode;
682 dbi->dbi_rpmdb =
rpmdb;
684 dbi->dbi_rpmtag = rpmtag;
693 dbi->dbi_jlen = 1 *
sizeof(
int_32);
696 dbi->dbi_jlen = 2 *
sizeof(
int_32);
701 dbi->dbi_byteswapped = -1;
703 if (!dbi->dbi_use_dbenv) {
704 dbi->dbi_use_dbenv = 1;
705 dbi->dbi_eflags |= (DB_INIT_MPOOL|DB_JOINENV);
706 dbi->dbi_mmapsize = 16 * 1024 * 1024;
707 dbi->dbi_cachesize = 1 * 1024 * 1024;
710 if ((dbi->dbi_bt_flags | dbi->dbi_h_flags) & DB_DUP)
711 dbi->dbi_permit_dups = 1;
720 const char * prDbiOpenFlags(
int dbflags,
int print_dbenv_flags)
722 static char buf[256];
723 struct poptOption *opt;
728 for (opt = rdbOptions; opt->longName != NULL; opt++) {
729 if (opt->argInfo != POPT_BIT_SET)
731 if (print_dbenv_flags) {
732 if (!(opt->arg == &db3dbi.dbi_oeflags ||
733 opt->arg == &db3dbi.dbi_eflags))
736 if (!(opt->arg == &db3dbi.dbi_oeflags ||
737 opt->arg == &db3dbi.dbi_oflags))
740 if ((dbflags & opt->val) != opt->val)
744 oe =
stpcpy(oe, opt->longName);
745 dbflags &= ~opt->val;
750 sprintf(oe,
"0x%x", (
unsigned)dbflags);