2006-12-19 00:17:44 +01:00
|
|
|
Fix global (DB_PRIVATE) lock code: fix recursion counter, retry
|
|
|
|
failed lock operations for up to 3 minutes.
|
2010-03-26 11:56:28 +01:00
|
|
|
|
2012-08-28 15:31:44 +02:00
|
|
|
--- ./lib/backend/db3.c.orig 2012-05-04 09:47:17.000000000 +0000
|
|
|
|
+++ ./lib/backend/db3.c 2012-06-01 10:47:01.000000000 +0000
|
|
|
|
@@ -422,6 +422,8 @@ int dbiVerify(dbiIndex dbi, unsigned int
|
2009-08-28 15:54:03 +02:00
|
|
|
return rc;
|
2006-12-19 00:17:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
+static int _lockdbfd = 0;
|
|
|
|
+
|
2011-05-16 18:07:44 +02:00
|
|
|
int dbiClose(dbiIndex dbi, unsigned int flags)
|
2009-08-28 15:54:03 +02:00
|
|
|
{
|
2011-05-16 18:07:44 +02:00
|
|
|
rpmdb rdb = dbi->dbi_rpmdb;
|
2012-08-28 15:31:44 +02:00
|
|
|
@@ -439,6 +441,8 @@ int dbiClose(dbiIndex dbi, unsigned int
|
2011-05-16 18:07:44 +02:00
|
|
|
|
2009-08-28 15:54:03 +02:00
|
|
|
rpmlog(RPMLOG_DEBUG, "closed db index %s/%s\n",
|
2010-03-26 11:56:28 +01:00
|
|
|
dbhome, dbi->dbi_file);
|
2011-05-16 18:07:44 +02:00
|
|
|
+ if (dbi->dbi_lockdbfd && _lockdbfd)
|
2006-12-19 00:17:44 +01:00
|
|
|
+ _lockdbfd--;
|
|
|
|
}
|
|
|
|
|
2012-08-28 15:31:44 +02:00
|
|
|
db_fini(rdb, dbhome ? dbhome : "");
|
|
|
|
@@ -478,6 +482,7 @@ static int dbiFlock(dbiIndex dbi, int mo
|
2011-05-16 18:07:44 +02:00
|
|
|
rc = 1;
|
|
|
|
} else {
|
|
|
|
const char *dbhome = rpmdbHome(dbi->dbi_rpmdb);
|
|
|
|
+ int tries;
|
|
|
|
struct flock l;
|
|
|
|
memset(&l, 0, sizeof(l));
|
|
|
|
l.l_whence = 0;
|
2012-08-28 15:31:44 +02:00
|
|
|
@@ -487,20 +492,38 @@ static int dbiFlock(dbiIndex dbi, int mo
|
2011-05-16 18:07:44 +02:00
|
|
|
? F_RDLCK : F_WRLCK;
|
|
|
|
l.l_pid = 0;
|
|
|
|
|
|
|
|
- rc = fcntl(fdno, F_SETLK, (void *) &l);
|
|
|
|
- if (rc) {
|
|
|
|
- uint32_t eflags = db_envflags(db);
|
|
|
|
- /* Warning iff using non-private CDB locking. */
|
|
|
|
- rc = (((eflags & DB_INIT_CDB) && !(eflags & DB_PRIVATE)) ? 0 : 1);
|
|
|
|
- rpmlog( (rc ? RPMLOG_ERR : RPMLOG_WARNING),
|
|
|
|
- _("cannot get %s lock on %s/%s\n"),
|
|
|
|
- ((mode & O_ACCMODE) == O_RDONLY)
|
|
|
|
- ? _("shared") : _("exclusive"),
|
|
|
|
- dbhome, dbi->dbi_file);
|
|
|
|
- } else {
|
|
|
|
- rpmlog(RPMLOG_DEBUG,
|
|
|
|
- "locked db index %s/%s\n",
|
|
|
|
- dbhome, dbi->dbi_file);
|
|
|
|
+ for (tries = 0; ; tries++) {
|
|
|
|
+ rc = fcntl(fdno, F_SETLK, (void *) &l);
|
|
|
|
+ if (rc) {
|
|
|
|
+ uint32_t eflags = db_envflags(db);
|
|
|
|
+ /* Warning iff using non-private CDB locking. */
|
|
|
|
+ rc = (((eflags & DB_INIT_CDB) && !(eflags & DB_PRIVATE)) ? 0 : 1);
|
|
|
|
+ if (errno == EAGAIN && rc) {
|
|
|
|
+ struct timespec ts;
|
|
|
|
+ if (tries == 0)
|
|
|
|
+ rpmlog(RPMLOG_WARNING,
|
|
|
|
+ _("waiting for %s lock on %s/%s\n"),
|
|
|
|
+ ((mode & O_ACCMODE) == O_RDONLY)
|
|
|
|
+ ? _("shared") : _("exclusive"),
|
|
|
|
+ dbhome, dbi->dbi_file);
|
|
|
|
+ ts.tv_sec = (time_t)0;
|
|
|
|
+ ts.tv_nsec = 100000000; /* .1 seconds */
|
|
|
|
+ if (tries < 10*60*3) { /* 3 minutes */
|
|
|
|
+ nanosleep(&ts, (struct timespec *)0);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ rpmlog( (rc ? RPMLOG_ERR : RPMLOG_WARNING),
|
|
|
|
+ _("cannot get %s lock on %s/%s\n"),
|
|
|
|
+ ((mode & O_ACCMODE) == O_RDONLY)
|
|
|
|
+ ? _("shared") : _("exclusive"),
|
|
|
|
+ dbhome, dbi->dbi_file);
|
|
|
|
+ } else {
|
|
|
|
+ rpmlog(RPMLOG_DEBUG,
|
|
|
|
+ "locked db index %s/%s\n",
|
|
|
|
+ dbhome, dbi->dbi_file);
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
}
|
2009-08-28 15:54:03 +02:00
|
|
|
}
|
2011-05-16 18:07:44 +02:00
|
|
|
return rc;
|
2012-08-28 15:31:44 +02:00
|
|
|
@@ -517,7 +540,6 @@ int dbiOpen(rpmdb rdb, rpmDbiTagVal rpmt
|
2011-05-16 18:07:44 +02:00
|
|
|
DB * db = NULL;
|
|
|
|
DBTYPE dbtype = DB_UNKNOWN;
|
|
|
|
uint32_t oflags;
|
|
|
|
- static int _lockdbfd = 0;
|
2006-12-19 00:17:44 +01:00
|
|
|
|
2011-05-16 18:07:44 +02:00
|
|
|
if (dbip)
|
|
|
|
*dbip = NULL;
|
2012-08-28 15:31:44 +02:00
|
|
|
@@ -591,7 +613,10 @@ int dbiOpen(rpmdb rdb, rpmDbiTagVal rpmt
|
2011-05-16 18:07:44 +02:00
|
|
|
dbi->dbi_db = db;
|
|
|
|
dbi->dbi_oflags = oflags;
|
2006-12-19 00:17:44 +01:00
|
|
|
|
2011-05-16 18:07:44 +02:00
|
|
|
- if (!verifyonly && rc == 0 && dbi->dbi_lockdbfd && _lockdbfd++ == 0) {
|
|
|
|
+ if (verifyonly)
|
|
|
|
+ dbi->dbi_lockdbfd = 0; /* disable locking in verify mode */
|
|
|
|
+
|
|
|
|
+ if (rc == 0 && dbi->dbi_lockdbfd && _lockdbfd++ == 0) {
|
|
|
|
rc = dbiFlock(dbi, rdb->db_mode);
|
2006-12-19 00:17:44 +01:00
|
|
|
}
|
2011-05-16 18:07:44 +02:00
|
|
|
|