summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2010-10-19 16:44:46 +0300
committerPanu Matilainen <pmatilai@redhat.com>2010-10-19 16:44:46 +0300
commitf5808135b70be9ea742a2dce4e2ec87d8932b9de (patch)
tree1c95a8ee27031a58f517cef9806e87dfa4f295a8
parent738c6e0ca76665387ef817fe25ded4f9ead5060b (diff)
downloadlibrpm-tizen-f5808135b70be9ea742a2dce4e2ec87d8932b9de.tar.gz
librpm-tizen-f5808135b70be9ea742a2dce4e2ec87d8932b9de.tar.bz2
librpm-tizen-f5808135b70be9ea742a2dce4e2ec87d8932b9de.zip
Move db environment-level configuration out of per-dbi structs
- Carrying global configuration in all dbi's is just dumb. First step towards fixing the stupidity.
-rw-r--r--lib/backend/db3.c31
-rw-r--r--lib/backend/dbconfig.c52
-rw-r--r--lib/backend/dbi.h31
3 files changed, 60 insertions, 54 deletions
diff --git a/lib/backend/db3.c b/lib/backend/db3.c
index 9464d9ef8..9e32bcb1e 100644
--- a/lib/backend/db3.c
+++ b/lib/backend/db3.c
@@ -99,6 +99,7 @@ static int db_init(dbiIndex dbi, const char * dbhome)
DB_ENV *dbenv = NULL;
int rc, xx;
int retry_open = 2;
+ struct _dbConfig * cfg = &rdb->cfg;
if (rdb->db_dbenv != NULL) {
rdb->db_opens++;
@@ -122,23 +123,23 @@ static int db_init(dbiIndex dbi, const char * dbhome)
dbenv->set_isalive(dbenv, isalive);
dbenv->set_verbose(dbenv, DB_VERB_DEADLOCK,
- (dbi->dbi_verbose & DB_VERB_DEADLOCK));
+ (cfg->db_verbose & DB_VERB_DEADLOCK));
dbenv->set_verbose(dbenv, DB_VERB_RECOVERY,
- (dbi->dbi_verbose & DB_VERB_RECOVERY));
+ (cfg->db_verbose & DB_VERB_RECOVERY));
dbenv->set_verbose(dbenv, DB_VERB_WAITSFOR,
- (dbi->dbi_verbose & DB_VERB_WAITSFOR));
+ (cfg->db_verbose & DB_VERB_WAITSFOR));
- if (dbi->dbi_mmapsize) {
- xx = dbenv->set_mp_mmapsize(dbenv, dbi->dbi_mmapsize);
+ if (cfg->db_mmapsize) {
+ xx = dbenv->set_mp_mmapsize(dbenv, cfg->db_mmapsize);
xx = cvtdberr(dbi, "dbenv->set_mp_mmapsize", xx, _debug);
}
- if (dbi->dbi_cachesize) {
- xx = dbenv->set_cachesize(dbenv, 0, dbi->dbi_cachesize, 0);
+ if (cfg->db_cachesize) {
+ xx = dbenv->set_cachesize(dbenv, 0, cfg->db_cachesize, 0);
xx = cvtdberr(dbi, "dbenv->set_cachesize", xx, _debug);
}
- if (dbi->dbi_no_fsync) {
+ if (cfg->db_no_fsync) {
xx = db_env_set_func_fsync(fsync_disable);
xx = cvtdberr(dbi, "db_env_set_func_fsync", xx, _debug);
}
@@ -148,14 +149,14 @@ static int db_init(dbiIndex dbi, const char * dbhome)
* if we dont have permission to join/create shared environment.
*/
while (retry_open) {
- char *fstr = prDbiOpenFlags(dbi->dbi_eflags, 1);
+ char *fstr = prDbiOpenFlags(cfg->db_eflags, 1);
rpmlog(RPMLOG_DEBUG, "opening db environment %s %s\n", dbhome, fstr);
free(fstr);
rc = (dbenv->open)(dbenv, dbhome,
- dbi->dbi_eflags, dbi->dbi_rpmdb->db_perms);
+ cfg->db_eflags, dbi->dbi_rpmdb->db_perms);
if (rc == EACCES) {
- dbi->dbi_eflags |= DB_PRIVATE;
+ cfg->db_eflags |= DB_PRIVATE;
retry_open--;
} else {
retry_open = 0;
@@ -216,11 +217,12 @@ int dbiCopen(dbiIndex dbi, DBC ** dbcp, unsigned int dbiflags)
DBC * dbcursor = NULL;
int flags;
int rc;
+ const struct _dbConfig * cfg = &dbi->dbi_rpmdb->cfg;
/* XXX DB_WRITECURSOR cannot be used with sunrpc dbenv. */
assert(db != NULL);
if ((dbiflags & DB_WRITECURSOR) &&
- (dbi->dbi_eflags & DB_INIT_CDB) && !(dbi->dbi_oflags & DB_RDONLY))
+ (cfg->db_eflags & DB_INIT_CDB) && !(dbi->dbi_oflags & DB_RDONLY))
{
flags = DB_WRITECURSOR;
} else
@@ -449,9 +451,10 @@ static int dbiFlock(dbiIndex dbi, int mode)
rc = fcntl(fdno, F_SETLK, (void *) &l);
if (rc) {
+ const struct _dbConfig *cfg = &dbi->dbi_rpmdb->cfg;
/* Warning iff using non-private CDB locking. */
- rc = (((dbi->dbi_eflags & DB_INIT_CDB) &&
- !(dbi->dbi_eflags & DB_PRIVATE))
+ rc = (((cfg->db_eflags & DB_INIT_CDB) &&
+ !(cfg->db_eflags & DB_PRIVATE))
? 0 : 1);
rpmlog( (rc ? RPMLOG_ERR : RPMLOG_WARNING),
_("cannot get %s lock on %s/%s\n"),
diff --git a/lib/backend/dbconfig.c b/lib/backend/dbconfig.c
index 86edbcf3f..b6cd25913 100644
--- a/lib/backend/dbconfig.c
+++ b/lib/backend/dbconfig.c
@@ -15,48 +15,49 @@
#include "debug.h"
static struct _dbiIndex staticdbi;
+static struct _dbConfig staticcfg;
/** \ingroup dbi
*/
static const struct poptOption rdbOptions[] = {
/* Environment options */
- { "cdb", 0,POPT_BIT_SET, &staticdbi.dbi_eflags, DB_INIT_CDB,
+ { "cdb", 0,POPT_BIT_SET, &staticcfg.db_eflags, DB_INIT_CDB,
NULL, NULL },
- { "lock", 0,POPT_BIT_SET, &staticdbi.dbi_eflags, DB_INIT_LOCK,
+ { "lock", 0,POPT_BIT_SET, &staticcfg.db_eflags, DB_INIT_LOCK,
NULL, NULL },
- { "log", 0,POPT_BIT_SET, &staticdbi.dbi_eflags, DB_INIT_LOG,
+ { "log", 0,POPT_BIT_SET, &staticcfg.db_eflags, DB_INIT_LOG,
NULL, NULL },
- { "txn", 0,POPT_BIT_SET, &staticdbi.dbi_eflags, DB_INIT_TXN,
+ { "txn", 0,POPT_BIT_SET, &staticcfg.db_eflags, DB_INIT_TXN,
NULL, NULL },
- { "recover", 0,POPT_BIT_SET, &staticdbi.dbi_eflags, DB_RECOVER,
+ { "recover", 0,POPT_BIT_SET, &staticcfg.db_eflags, DB_RECOVER,
NULL, NULL },
- { "recover_fatal", 0,POPT_BIT_SET, &staticdbi.dbi_eflags, DB_RECOVER_FATAL,
+ { "recover_fatal", 0,POPT_BIT_SET, &staticcfg.db_eflags, DB_RECOVER_FATAL,
NULL, NULL },
- { "lockdown", 0,POPT_BIT_SET, &staticdbi.dbi_eflags, DB_LOCKDOWN,
+ { "lockdown", 0,POPT_BIT_SET, &staticcfg.db_eflags, DB_LOCKDOWN,
NULL, NULL },
- { "private", 0,POPT_BIT_SET, &staticdbi.dbi_eflags, DB_PRIVATE,
+ { "private", 0,POPT_BIT_SET, &staticcfg.db_eflags, DB_PRIVATE,
NULL, NULL },
- { "deadlock", 0,POPT_BIT_SET, &staticdbi.dbi_verbose, DB_VERB_DEADLOCK,
+ { "deadlock", 0,POPT_BIT_SET, &staticcfg.db_verbose, DB_VERB_DEADLOCK,
NULL, NULL },
- { "recovery", 0,POPT_BIT_SET, &staticdbi.dbi_verbose, DB_VERB_RECOVERY,
+ { "recovery", 0,POPT_BIT_SET, &staticcfg.db_verbose, DB_VERB_RECOVERY,
NULL, NULL },
- { "waitsfor", 0,POPT_BIT_SET, &staticdbi.dbi_verbose, DB_VERB_WAITSFOR,
+ { "waitsfor", 0,POPT_BIT_SET, &staticcfg.db_verbose, DB_VERB_WAITSFOR,
NULL, NULL },
- { "verbose", 0,POPT_ARG_VAL, &staticdbi.dbi_verbose, -1,
+ { "verbose", 0,POPT_ARG_VAL, &staticcfg.db_verbose, -1,
NULL, NULL },
- { "cachesize", 0,POPT_ARG_INT, &staticdbi.dbi_cachesize, 0,
+ { "cachesize", 0,POPT_ARG_INT, &staticcfg.db_cachesize, 0,
NULL, NULL },
- { "mmapsize", 0,POPT_ARG_INT, &staticdbi.dbi_mmapsize, 0,
+ { "mmapsize", 0,POPT_ARG_INT, &staticcfg.db_mmapsize, 0,
NULL, NULL },
- { "mp_mmapsize", 0,POPT_ARG_INT, &staticdbi.dbi_mmapsize, 0,
+ { "mp_mmapsize", 0,POPT_ARG_INT, &staticcfg.db_mmapsize, 0,
NULL, NULL },
- { "mp_size", 0,POPT_ARG_INT, &staticdbi.dbi_cachesize, 0,
+ { "mp_size", 0,POPT_ARG_INT, &staticcfg.db_cachesize, 0,
NULL, NULL },
- { "nofsync", 0,POPT_ARG_NONE, &staticdbi.dbi_no_fsync, 0,
+ { "nofsync", 0,POPT_ARG_NONE, &staticcfg.db_no_fsync, 0,
NULL, NULL },
/* Per-dbi options */
@@ -232,12 +233,15 @@ dbiIndex dbiNew(rpmdb rdb, rpmTag rpmtag)
dbi->dbi_type = (rpmtag == RPMDBI_PACKAGES) ? DBI_PRIMARY : DBI_SECONDARY;
dbi->dbi_byteswapped = -1; /* -1 unknown, 0 native order, 1 alien order */
- /* XXX FIXME: These all are environment, not per-dbi configuration */
- dbi->dbi_eflags |= (DB_INIT_MPOOL|DB_CREATE);
- /* Throw in some defaults if configuration didn't set any */
- if (!dbi->dbi_mmapsize) dbi->dbi_mmapsize = 16 * 1024 * 1024;
- if (!dbi->dbi_cachesize) dbi->dbi_cachesize = 1 * 1024 * 1024;
-
+ /* XXX FIXME: Get environment configuration out of here! */
+ if (rdb->db_dbenv == NULL) {
+ struct _dbConfig * cfg = &rdb->cfg;
+ *cfg = staticcfg; /* structure assignment */
+ cfg->db_eflags |= (DB_INIT_MPOOL|DB_CREATE);
+ /* Throw in some defaults if configuration didn't set any */
+ if (!cfg->db_mmapsize) cfg->db_mmapsize = 16 * 1024 * 1024;
+ if (!cfg->db_cachesize) cfg->db_cachesize = 1 * 1024 * 1024;
+ }
/* FIX: *(rdbOptions->arg) reachable */
return dbi;
@@ -253,7 +257,7 @@ char * prDbiOpenFlags(int dbflags, int print_dbenv_flags)
if (opt->argInfo != POPT_BIT_SET)
continue;
if (print_dbenv_flags) {
- if (!(opt->arg == &staticdbi.dbi_eflags))
+ if (!(opt->arg == &staticcfg.db_eflags))
continue;
} else {
if (!(opt->arg == &staticdbi.dbi_oflags))
diff --git a/lib/backend/dbi.h b/lib/backend/dbi.h
index dba314a3a..63233a8b8 100644
--- a/lib/backend/dbi.h
+++ b/lib/backend/dbi.h
@@ -9,6 +9,14 @@ enum rpmdbFlags {
typedef struct _dbiIndex * dbiIndex;
+struct _dbConfig {
+ int db_eflags; /*!< dbenv->open flags */
+ int db_mmapsize; /*!< (10Mb) */
+ int db_cachesize; /*!< (128Kb) */
+ int db_verbose;
+ int db_no_fsync; /*!< no-op fsync for db */
+};
+
/** \ingroup rpmdb
* Describes the collection of index databases used by rpm.
*/
@@ -20,16 +28,19 @@ struct rpmdb_s {
int db_mode; /*!< open mode */
int db_perms; /*!< open permissions */
int db_api; /*!< Berkeley API type */
- int db_remove_env;
unsigned char * db_bits; /*!< package instance bit mask. */
int db_nbits; /*!< no. of bits in mask. */
rpmdb db_next;
int db_opens;
- void * db_dbenv; /*!< Berkeley DB_ENV handle. */
int db_ndbi; /*!< No. of tag indices. */
dbiIndex * _dbi; /*!< Tag indices. */
int db_buildindex; /*!< Index rebuild indicator */
+ /* dbenv and related parameters */
+ void * db_dbenv; /*!< Berkeley DB_ENV handle. */
+ struct _dbConfig cfg;
+ int db_remove_env;
+
struct rpmop_s db_getops;
struct rpmop_s db_putops;
struct rpmop_s db_delops;
@@ -49,26 +60,14 @@ typedef enum dbiIndexType_e {
struct _dbiIndex {
const char * dbi_file; /*!< file component of path */
- int dbi_eflags; /*!< dbenv->open flags */
- int dbi_oflags; /*!< db->open flags */
-
DBTYPE dbi_dbtype; /*!< db index type */
-
+ int dbi_oflags; /*!< db->open flags */
+ int dbi_pagesize; /*!< (fs blksize) */
int dbi_permit_dups; /*!< permit duplicate entries? */
- int dbi_no_fsync; /*!< no-op fsync for db */
int dbi_no_dbsync; /*!< don't call dbiSync */
int dbi_lockdbfd; /*!< do fcntl lock on db fd */
int dbi_byteswapped;
- /* dbenv parameters */
- /* XXX db-4.3.14 adds dbenv as 1st arg. */
- int dbi_verbose;
- /* mpool sub-system parameters */
- int dbi_mmapsize; /*!< (10Mb) */
- int dbi_cachesize; /*!< (128Kb) */
- /* dbinfo parameters */
- int dbi_pagesize; /*!< (fs blksize) */
-
rpmdb dbi_rpmdb; /*!< the parent rpm database */
dbiIndexType dbi_type; /*! Type of dbi (primary / index) */