diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1999-02-15 05:11:26 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1999-02-15 05:11:26 +0000 |
commit | 3941e90b879e925d0fef8f0733e1d9c2e1861db5 (patch) | |
tree | 82b3c2fe01e0932c532b9e2a3f038a110315707d /lib/libc/db/mpool | |
parent | 0584840a66631455c4c44387526ce706056faee0 (diff) |
o Minor changes from db.1.86 (sleepycat). Does not include the new hash
routines since they cannot read a hashed .db file from the old code.
Most of these files just have their RCS/SCCS tags standardized.
Note that mpool.3 has not been updated to reflect the new mpool interface.
o Add a real dbm(3) manpage
Diffstat (limited to 'lib/libc/db/mpool')
-rw-r--r-- | lib/libc/db/mpool/README | 3 | ||||
-rw-r--r-- | lib/libc/db/mpool/mpool.c | 82 | ||||
-rw-r--r-- | lib/libc/db/mpool/mpool.libtp | 2 |
3 files changed, 68 insertions, 19 deletions
diff --git a/lib/libc/db/mpool/README b/lib/libc/db/mpool/README index 916ea935ef6..b8b2eaf4ec9 100644 --- a/lib/libc/db/mpool/README +++ b/lib/libc/db/mpool/README @@ -1,4 +1,5 @@ -# $OpenBSD: README,v 1.2 1996/08/19 08:20:51 tholo Exp $ +# $OpenBSD: README,v 1.3 1999/02/15 05:11:25 millert Exp $ +# @(#)README 8.1 (Berkeley) 6/4/93 These are the current memory pool routines. They aren't ready for prime time, yet, and diff --git a/lib/libc/db/mpool/mpool.c b/lib/libc/db/mpool/mpool.c index ab98c8e5c59..008132644f1 100644 --- a/lib/libc/db/mpool/mpool.c +++ b/lib/libc/db/mpool/mpool.c @@ -1,3 +1,5 @@ +/* $OpenBSD: mpool.c,v 1.6 1999/02/15 05:11:25 millert Exp $ */ + /*- * Copyright (c) 1990, 1993, 1994 * The Regents of the University of California. All rights reserved. @@ -32,7 +34,11 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: mpool.c,v 1.5 1998/08/28 20:49:11 deraadt Exp $"; +#if 0 +static char sccsid[] = "@(#)mpool.c 8.7 (Berkeley) 11/2/95"; +#else +static char rcsid[] = "$OpenBSD: mpool.c,v 1.6 1999/02/15 05:11:25 millert Exp $"; +#endif #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -116,9 +122,10 @@ mpool_filter(mp, pgin, pgout, pgcookie) * Get a new page of memory. */ void * -mpool_new(mp, pgnoaddr) +mpool_new(mp, pgnoaddr, flags) MPOOL *mp; pgno_t *pgnoaddr; + u_int flags; { struct _hqh *head; BKT *bp; @@ -137,8 +144,13 @@ mpool_new(mp, pgnoaddr) */ if ((bp = mpool_bkt(mp)) == NULL) return (NULL); - *pgnoaddr = bp->pgno = mp->npages++; - bp->flags = MPOOL_PINNED; + if (flags == MPOOL_PAGE_REQUEST) { + mp->npages++; + bp->pgno = *pgnoaddr; + } else + bp->pgno = *pgnoaddr = mp->npages++; + + bp->flags = MPOOL_PINNED | MPOOL_INUSE; head = &mp->hqh[HASHKEY(bp->pgno)]; CIRCLEQ_INSERT_HEAD(head, bp, hq); @@ -146,6 +158,33 @@ mpool_new(mp, pgnoaddr) return (bp->page); } +int +mpool_delete(mp, page) + MPOOL *mp; + void *page; +{ + struct _hqh *head; + BKT *bp; + + bp = (BKT *)((char *)page - sizeof(BKT)); + +#ifdef DEBUG + if (!(bp->flags & MPOOL_PINNED)) { + (void)fprintf(stderr, + "mpool_delete: page %d not pinned\n", bp->pgno); + abort(); + } +#endif + + /* Remove from the hash and lru queues. */ + head = &mp->hqh[HASHKEY(bp->pgno)]; + CIRCLEQ_REMOVE(head, bp, hq); + CIRCLEQ_REMOVE(&mp->lqh, bp, q); + + free(bp); + return (RET_SUCCESS); +} + /* * mpool_get * Get a page. @@ -162,12 +201,6 @@ mpool_get(mp, pgno, flags) off_t off; int nr; - /* Check for attempt to retrieve a non-existent page. */ - if (pgno >= mp->npages) { - errno = EINVAL; - return (NULL); - } - #ifdef STATISTICS ++mp->pageget; #endif @@ -175,7 +208,7 @@ mpool_get(mp, pgno, flags) /* Check for a page that is cached. */ if ((bp = mpool_look(mp, pgno)) != NULL) { #ifdef DEBUG - if (bp->flags & MPOOL_PINNED) { + if (!(flags & MPOOL_IGNOREPIN) && bp->flags & MPOOL_PINNED) { (void)fprintf(stderr, "mpool_get: page %d already pinned\n", bp->pgno); abort(); @@ -207,15 +240,26 @@ mpool_get(mp, pgno, flags) off = mp->pagesize * pgno; if (lseek(mp->fd, off, SEEK_SET) != off) return (NULL); + if ((nr = read(mp->fd, bp->page, mp->pagesize)) != mp->pagesize) { - if (nr >= 0) - errno = EFTYPE; - return (NULL); + if (nr > 0) { + /* A partial read is definitely bad. */ + errno = EINVAL; + return (NULL); + } else { + /* + * A zero-length reads, means you need to create a + * new page. + */ + memset(bp->page, 0, mp->pagesize); + } } /* Set the page number, pin the page. */ bp->pgno = pgno; - bp->flags = MPOOL_PINNED; + if (!(flags & MPOOL_IGNOREPIN)) + bp->flags = MPOOL_PINNED; + bp->flags |= MPOOL_INUSE; /* * Add the page to the head of the hash chain and the tail @@ -257,7 +301,8 @@ mpool_put(mp, page, flags) } #endif bp->flags &= ~MPOOL_PINNED; - bp->flags |= flags & MPOOL_DIRTY; + if (flags & MPOOL_DIRTY) + bp->flags |= flags & MPOOL_DIRTY; return (RET_SUCCESS); } @@ -345,6 +390,7 @@ mpool_bkt(mp) bp->page = spage; } #endif + bp->flags = 0; return (bp); } @@ -355,6 +401,7 @@ new: if ((bp = (BKT *)malloc(sizeof(BKT) + mp->pagesize)) == NULL) #endif memset(bp, 0xff, sizeof(BKT) + mp->pagesize); bp->page = (char *)bp + sizeof(BKT); + bp->flags = 0; ++mp->curcache; return (bp); } @@ -402,7 +449,8 @@ mpool_look(mp, pgno) head = &mp->hqh[HASHKEY(pgno)]; for (bp = head->cqh_first; bp != (void *)head; bp = bp->hq.cqe_next) - if (bp->pgno == pgno) { + if ((bp->pgno == pgno) && + (bp->flags & MPOOL_INUSE == MPOOL_INUSE)) { #ifdef STATISTICS ++mp->cachehit; #endif diff --git a/lib/libc/db/mpool/mpool.libtp b/lib/libc/db/mpool/mpool.libtp index 8eb7715b0d2..160f7369a8a 100644 --- a/lib/libc/db/mpool/mpool.libtp +++ b/lib/libc/db/mpool/mpool.libtp @@ -1,6 +1,6 @@ /****************************************************************************** -VERSION $Id: mpool.libtp,v 1.2 1998/07/13 02:11:10 millert Exp $ +VERSION $OpenBSD: mpool.libtp,v 1.3 1999/02/15 05:11:25 millert Exp $ PACKAGE: User Level Shared Memory Manager DESCRIPTION: |