RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson Root: /v/rpm/cvs Email: j...@rpm5.org Module: rpm Date: 23-May-2009 17:50:03 Branch: rpm-5_2 Handle: 2009052315500300 Modified files: (Branch: rpm-5_2) rpm CHANGES rpm/rpmdb db3.c rpmdb.c Log: - eliminate (unused) DB_DBT_MALLOC flag while loading rpmdb headers. Summary: Revision Changes Path 1.2970.2.17 +1 -0 rpm/CHANGES 1.93.2.1 +2 -0 rpm/rpmdb/db3.c 1.292.2.4 +65 -16 rpm/rpmdb/rpmdb.c ____________________________________________________________________________ patch -p0 <<'@@ .' Index: rpm/CHANGES ============================================================================ $ cvs diff -u -r1.2970.2.16 -r1.2970.2.17 CHANGES --- rpm/CHANGES 22 May 2009 17:40:31 -0000 1.2970.2.16 +++ rpm/CHANGES 23 May 2009 15:50:03 -0000 1.2970.2.17 @@ -1,5 +1,6 @@ 5.2a4 -> 5.2b1: + - jbj: eliminate (unused) DB_DBT_MALLOC flag while loading rpmdb headers. - jbj: remove (unused) --hdrfastdatalength and --hdrlazytagswab. - jbj: use PROT_READ for header blob's. - jbj: add --rpmmidebug. @@ . patch -p0 <<'@@ .' Index: rpm/rpmdb/db3.c ============================================================================ $ cvs diff -u -r1.93 -r1.93.2.1 db3.c --- rpm/rpmdb/db3.c 27 Mar 2009 17:42:00 -0000 1.93 +++ rpm/rpmdb/db3.c 23 May 2009 15:50:03 -0000 1.93.2.1 @@ -765,6 +765,8 @@ rc = dbcursor->get(dbcursor, key, data, flags); /* XXX DB_NOTFOUND can be returned */ _printit = (rc == DB_NOTFOUND ? 0 : _debug); + /* XXX Permit DB_BUFFER_SMALL to be returned (more restrictive?) */ + _printit = (rc == DB_BUFFER_SMALL ? 0 : _printit); rc = cvtdberr(dbi, "dbcursor->get", rc, _printit); #else /* XXX db3 does DB_FIRST on uninitialized cursor */ @@ . patch -p0 <<'@@ .' Index: rpm/rpmdb/rpmdb.c ============================================================================ $ cvs diff -u -r1.292.2.3 -r1.292.2.4 rpmdb.c --- rpm/rpmdb/rpmdb.c 22 May 2009 16:11:02 -0000 1.292.2.3 +++ rpm/rpmdb/rpmdb.c 23 May 2009 15:50:03 -0000 1.292.2.4 @@ -4,8 +4,6 @@ #include "system.h" -#define _USE_COPY_LOAD /* XXX don't use DB_DBT_MALLOC (yet) */ - #include <sys/file.h> #include <rpmiotypes.h> @@ -2451,6 +2449,55 @@ return rc; } +static int _rpmmi_usermem = 1; + +static int rpmmiGet(dbiIndex dbi, DBC * dbcursor, DBT * kp, DBT * vp, + unsigned int flags) +{ + int map; + int rc; + + switch (dbi->dbi_rpmdb->db_api) { + default: map = 0; break; + case 3: map = _rpmmi_usermem; break; /* Berkeley DB */ + } + + if (map) { + static const int _prot = PROT_READ | PROT_WRITE; + static const int _flags = MAP_PRIVATE| MAP_ANONYMOUS; + static const int _fdno = -1; + static const off_t _off = 0; + + vp->flags |= DB_DBT_USERMEM; + rc = dbiGet(dbi, dbcursor, kp, vp, flags); + if (rc == DB_BUFFER_SMALL) { + size_t uhlen = vp->size; + void * uh = mmap(NULL, uhlen, _prot, _flags, _fdno, _off); + if (uh == NULL || uh == (void *)-1) + fprintf(stderr, + "==> mmap(%p[%u], 0x%x, 0x%x, %d, 0x%x) error(%d): %s\n", + NULL, uhlen, _prot, _flags, _fdno, (unsigned)_off, + errno, strerror(errno)); + + vp->ulen = (u_int32_t)uhlen; + vp->data = uh; + rc = dbiGet(dbi, dbcursor, kp, vp, DB_SET); + if (rc == 0) { + if (mprotect(uh, uhlen, PROT_READ) != 0) + fprintf(stderr, "==> mprotect(%p[%u],0x%x) error(%d): %s\n", + uh, uhlen, PROT_READ, + errno, strerror(errno)); + } else { + if (munmap(uh, uhlen) != 0) + fprintf(stderr, "==> munmap(%p[%u]) error(%d): %s\n", + uh, uhlen, errno, strerror(errno)); + } + } + } else + rc = dbiGet(dbi, dbcursor, kp, vp, flags); + return rc; +} + Header rpmmiNext(rpmmi mi) { dbiIndex dbi; @@ -2459,6 +2506,7 @@ union _dbswap mi_offset; void * uh; size_t uhlen; + int map; int rc; int xx; @@ -2469,6 +2517,11 @@ if (dbi == NULL) return NULL; + switch (dbi->dbi_rpmdb->db_api) { + default: map = 0; break; + case 3: map = _rpmmi_usermem; break; /* Berkeley DB */ + } + /* * Cursors are per-iterator, not per-dbi, so get a cursor for the * iterator on 1st call. If the iteration is to rewrite headers, and the @@ -2497,23 +2550,17 @@ k.data = &mi_offset.ui; /*...@=immediatetrans@*/ k.size = (u_int32_t)sizeof(mi_offset.ui); -#if !defined(_USE_COPY_LOAD) - v.flags |= DB_DBT_MALLOC; -#endif - rc = dbiGet(dbi, mi->mi_dbc, &k, &v, DB_SET); + rc = rpmmiGet(dbi, mi->mi_dbc, &k, &v, DB_SET); } else { /* Iterating Packages database. */ assert(mi->mi_rpmtag == RPMDBI_PACKAGES); /* Fetch header with DB_NEXT. */ -#if !defined(_USE_COPY_LOAD) - v.flags |= DB_DBT_MALLOC; -#endif /* Instance 0 is the largest header instance in the database, * and should be skipped. */ do { - rc = dbiGet(dbi, mi->mi_dbc, &k, &v, DB_NEXT); + rc = rpmmiGet(dbi, mi->mi_dbc, &k, &v, DB_NEXT); if (rc == 0) { memcpy(&mi_offset, k.data, sizeof(mi_offset.ui)); if (dbiByteSwapped(dbi) == 1) @@ -2523,6 +2570,7 @@ } while (rc == 0 && mi_offset.ui == 0); } + /* Did the header blob load correctly? */ if (rc) return NULL; @@ -2577,16 +2625,17 @@ } } - /* Did the header blob load correctly? */ -#if !defined(_USE_COPY_LOAD) + if (map) { /*...@-onlytrans@*/ mi->mi_h = headerLoad(uh); /*...@=onlytrans@*/ - if (mi->mi_h) - mi->mi_h->flags |= HEADERFLAG_ALLOCATED; -#else + if (mi->mi_h) { + mi->mi_h->flags |= HEADERFLAG_MAPPED; + mi->mi_h->flags |= HEADERFLAG_RDONLY; + } + } else mi->mi_h = headerCopyLoad(uh); -#endif + if (mi->mi_h == NULL || !headerIsEntry(mi->mi_h, RPMTAG_NAME)) { rpmlog(RPMLOG_ERR, _("rpmdb: damaged header #%u retrieved -- skipping.\n"), @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository rpm-cvs@rpm5.org