summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/backend/db3.c10
-rw-r--r--lib/backend/dbi.h5
-rw-r--r--lib/rpmdb.c9
3 files changed, 19 insertions, 5 deletions
diff --git a/lib/backend/db3.c b/lib/backend/db3.c
index 06e407f19..ff458b5b3 100644
--- a/lib/backend/db3.c
+++ b/lib/backend/db3.c
@@ -156,11 +156,6 @@ static int db_init(rpmdb rdb, const char * dbhome)
xx = dbapi_err(rdb, "dbenv->set_cachesize", xx, _debug);
}
- if (cfg->db_no_fsync) {
- xx = db_env_set_func_fsync(fsync_disable);
- xx = dbapi_err(rdb, "db_env_set_func_fsync", xx, _debug);
- }
-
/*
* Actually open the environment. Fall back to private environment
* if we dont have permission to join/create shared environment.
@@ -202,6 +197,11 @@ errxit:
return rc;
}
+void dbSetFSync(void *dbenv, int enable)
+{
+ db_env_set_func_fsync(enable ? fdatasync : fsync_disable);
+}
+
int dbiSync(dbiIndex dbi, unsigned int flags)
{
DB * db = dbi->dbi_db;
diff --git a/lib/backend/dbi.h b/lib/backend/dbi.h
index bfa1d8773..793239743 100644
--- a/lib/backend/dbi.h
+++ b/lib/backend/dbi.h
@@ -82,6 +82,11 @@ struct _dbiIndex {
extern "C" {
#endif
+
+RPM_GNUC_INTERNAL
+/* Globally enable/disable fsync in the backend */
+void dbSetFSync(void *dbenv, int enable);
+
/** \ingroup dbi
* Return new configured index database handle instance.
* @param rdb rpm database
diff --git a/lib/rpmdb.c b/lib/rpmdb.c
index d73a34796..ef1f0d323 100644
--- a/lib/rpmdb.c
+++ b/lib/rpmdb.c
@@ -206,6 +206,11 @@ static dbiIndex rpmdbOpenIndex(rpmdb db, rpmTag rpmtag, int flags)
db->db_nbits = 1024 + pkgInstance(dbi, 0);
db->db_bits = PBM_ALLOC(db->db_nbits);
}
+ /* If primary got created, we can safely run without fsync */
+ if ((dbiFlags(dbi) & DBI_CREATED) || db->cfg.db_no_fsync) {
+ rpmlog(RPMLOG_DEBUG, "disabling fsync on database\n");
+ dbSetFSync(db->db_dbenv, 0);
+ }
} else { /* secondary index */
if (!verifyonly && (dbiFlags(dbi) & DBI_CREATED)) {
rpmlog(RPMLOG_DEBUG, "index %s needs creating\n", dbiName(dbi));
@@ -667,6 +672,10 @@ int rpmdbClose(rpmdb db)
if (db->nrefs > 0)
goto exit;
+ /* Always re-enable fsync on close of rw-database */
+ if ((db->db_mode & O_ACCMODE) != O_RDONLY)
+ dbSetFSync(db->db_dbenv, 1);
+
rc = dbiForeach(db->_dbi, dbiClose, 1);
db->db_root = _free(db->db_root);