ndb: do not map the index databases read-write all the time

Pass the flags to rpmidxOpenXdb and use read only mode if the
user specified O_RDONLY. We already did that for rpmidxOpen in
the past but we always used read-write mode when using the Xdb.

We still open the Xdb itself in read-write mode so that we can
regenerate missing index databases.
This commit is contained in:
Michael Schroeder 2020-04-14 10:58:34 +02:00 committed by Panu Matilainen
parent 85b51e2dcf
commit 3cfd298e9d
3 changed files with 11 additions and 10 deletions

View File

@ -147,9 +147,6 @@ static int ndb_Open(rpmdb rdb, rpmDbiTagVal rpmtag, dbiIndex * dbip, int flags)
free(path); free(path);
dbi->dbi_db = ndbenv->pkgdb = pkgdb; dbi->dbi_db = ndbenv->pkgdb = pkgdb;
rpmpkgSetFsync(pkgdb, ndbenv->dofsync); rpmpkgSetFsync(pkgdb, ndbenv->dofsync);
if ((oflags & (O_RDWR | O_RDONLY)) == O_RDONLY)
dbi->dbi_flags |= DBI_RDONLY;
} else { } else {
unsigned int id; unsigned int id;
rpmidxdb idxdb = 0; rpmidxdb idxdb = 0;
@ -188,20 +185,20 @@ static int ndb_Open(rpmdb rdb, rpmDbiTagVal rpmtag, dbiIndex * dbip, int flags)
ndb_CheckIndexSync(ndbenv->pkgdb, ndbenv->xdb); ndb_CheckIndexSync(ndbenv->pkgdb, ndbenv->xdb);
} }
if (rpmxdbLookupBlob(ndbenv->xdb, &id, rpmtag, 0, 0) == RPMRC_NOTFOUND) { if (rpmxdbLookupBlob(ndbenv->xdb, &id, rpmtag, 0, 0) == RPMRC_NOTFOUND) {
oflags = O_RDWR|O_CREAT;
dbi->dbi_flags |= DBI_CREATED; dbi->dbi_flags |= DBI_CREATED;
} }
rpmlog(RPMLOG_DEBUG, "opening db index %s tag=%d\n", dbiName(dbi), rpmtag); rpmlog(RPMLOG_DEBUG, "opening db index %s tag=%d\n", dbiName(dbi), rpmtag);
if (rpmidxOpenXdb(&idxdb, rdb->db_pkgs->dbi_db, ndbenv->xdb, rpmtag)) { if (rpmidxOpenXdb(&idxdb, rdb->db_pkgs->dbi_db, ndbenv->xdb, rpmtag, oflags)) {
perror("rpmidxOpenXdb"); perror("rpmidxOpenXdb");
ndb_Close(dbi, 0); ndb_Close(dbi, 0);
return 1; return 1;
} }
dbi->dbi_db = idxdb; dbi->dbi_db = idxdb;
if (rpmxdbIsRdonly(ndbenv->xdb))
dbi->dbi_flags |= DBI_RDONLY;
} }
if ((oflags & (O_RDWR | O_RDONLY)) == O_RDONLY)
dbi->dbi_flags |= DBI_RDONLY;
if (dbip != NULL) if (dbip != NULL)
*dbip = dbi; *dbip = dbi;

View File

@ -885,13 +885,17 @@ int rpmidxOpen(rpmidxdb *idxdbp, rpmpkgdb pkgdb, const char *filename, int flags
return RPMRC_FAIL; return RPMRC_FAIL;
} }
int rpmidxOpenXdb(rpmidxdb *idxdbp, rpmpkgdb pkgdb, rpmxdb xdb, unsigned int xdbtag) int rpmidxOpenXdb(rpmidxdb *idxdbp, rpmpkgdb pkgdb, rpmxdb xdb, unsigned int xdbtag, int flags)
{ {
rpmidxdb idxdb; rpmidxdb idxdb;
unsigned int id; unsigned int id;
*idxdbp = 0; *idxdbp = 0;
int rc; int rc;
if (rpmxdbIsRdonly(xdb) && (flags & (O_RDONLY|O_RDWR)) != O_RDONLY) {
errno = EACCES;
return RPMRC_FAIL;
}
if (rpmxdbLock(xdb, 0)) if (rpmxdbLock(xdb, 0))
return RPMRC_FAIL; return RPMRC_FAIL;
rc = rpmxdbLookupBlob(xdb, &id, xdbtag, IDXDB_XDB_SUBTAG, 0); rc = rpmxdbLookupBlob(xdb, &id, xdbtag, IDXDB_XDB_SUBTAG, 0);
@ -907,7 +911,7 @@ int rpmidxOpenXdb(rpmidxdb *idxdbp, rpmpkgdb pkgdb, rpmxdb xdb, unsigned int xdb
idxdb->xdbid = id; idxdb->xdbid = id;
idxdb->pkgdb = pkgdb; idxdb->pkgdb = pkgdb;
idxdb->pagesize = rpmxdbPagesize(xdb); idxdb->pagesize = rpmxdbPagesize(xdb);
idxdb->rdonly = rpmxdbIsRdonly(xdb) ? 1 : 0; idxdb->rdonly = (flags & (O_RDONLY|O_RDWR)) == O_RDONLY ? 1 : 0;
if (!id) { if (!id) {
if (rpmidxInit(idxdb)) { if (rpmidxInit(idxdb)) {
free(idxdb); free(idxdb);

View File

@ -5,7 +5,7 @@ struct rpmidxdb_s;
typedef struct rpmidxdb_s *rpmidxdb; typedef struct rpmidxdb_s *rpmidxdb;
int rpmidxOpen(rpmidxdb *idxdbp, rpmpkgdb pkgdb, const char *filename, int flags, int mode); int rpmidxOpen(rpmidxdb *idxdbp, rpmpkgdb pkgdb, const char *filename, int flags, int mode);
int rpmidxOpenXdb(rpmidxdb *idxdbp, rpmpkgdb pkgdb, rpmxdb xdb, unsigned int xdbtag); int rpmidxOpenXdb(rpmidxdb *idxdbp, rpmpkgdb pkgdb, rpmxdb xdb, unsigned int xdbtag, int flags);
int rpmidxDelXdb(rpmpkgdb pkgdb, rpmxdb xdb, unsigned int xdbtag); int rpmidxDelXdb(rpmpkgdb pkgdb, rpmxdb xdb, unsigned int xdbtag);
void rpmidxClose(rpmidxdb idxdbp); void rpmidxClose(rpmidxdb idxdbp);