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:48:44
  Branch: HEAD                             Handle: 2009052315484301

  Modified files:
    rpm                     CHANGES
    rpm/rpmdb               db3.c header.c rpmdb.c

  Log:
    - eliminate (unused) DB_DBT_MALLOC flag while loading rpmdb headers.

  Summary:
    Revision    Changes     Path
    1.2991      +1  -0      rpm/CHANGES
    1.94        +2  -0      rpm/rpmdb/db3.c
    1.189       +1  -1      rpm/rpmdb/header.c
    1.301       +67 -18     rpm/rpmdb/rpmdb.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.2990 -r1.2991 CHANGES
  --- rpm/CHANGES       21 May 2009 14:18:25 -0000      1.2990
  +++ rpm/CHANGES       23 May 2009 15:48:43 -0000      1.2991
  @@ -1,5 +1,6 @@
   
   5.2b1 -> 5.3a1
  +    - jbj: eliminate (unused) DB_DBT_MALLOC flag while loading rpmdb headers.
       - jbj: bump sonames to libfoo-5.2.
       - jbj: rpmmi: rename the other methods for the match iterator object.
       - proyvind: make it possible to set macro files to load predefines from 
by
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmdb/db3.c
  ============================================================================
  $ cvs diff -u -r1.93 -r1.94 db3.c
  --- rpm/rpmdb/db3.c   27 Mar 2009 17:42:00 -0000      1.93
  +++ rpm/rpmdb/db3.c   23 May 2009 15:48:44 -0000      1.94
  @@ -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/header.c
  ============================================================================
  $ cvs diff -u -r1.188 -r1.189 header.c
  --- rpm/rpmdb/header.c        20 May 2009 18:18:46 -0000      1.188
  +++ rpm/rpmdb/header.c        23 May 2009 15:48:44 -0000      1.189
  @@ -1333,7 +1333,7 @@
        } else {
            if (munmap(nuh, pvlen) != 0)
                fprintf(stderr, "==> munmap(%p[%u]) error(%d): %s\n",
  -             nuh, pvlen, errno, strerror(errno));
  +                     nuh, pvlen, errno, strerror(errno));
        }
       } else {
        nuh = memcpy(xmalloc(pvlen), uh, pvlen);
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmdb/rpmdb.c
  ============================================================================
  $ cvs diff -u -r1.300 -r1.301 rpmdb.c
  --- rpm/rpmdb/rpmdb.c 17 May 2009 14:33:06 -0000      1.300
  +++ rpm/rpmdb/rpmdb.c 23 May 2009 15:48:44 -0000      1.301
  @@ -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);
  +     mi->mi_h = headerLoad(uh);
   /*...@=onlytrans@*/
  -    if (mi->mi_h)
  -     mi->mi_h->flags |= HEADERFLAG_ALLOCATED;
  -#else
  -    mi->mi_h = headerCopyLoad(uh);
  -#endif
  +     if (mi->mi_h) {
  +         mi->mi_h->flags |= HEADERFLAG_MAPPED;
  +         mi->mi_h->flags |= HEADERFLAG_RDONLY;
  +     }
  +    } else
  +     mi->mi_h = headerCopyLoad(uh);
  +
       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

Reply via email to