mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-20 09:41:18 +00:00
92f1da4da0
1997-08-10 19:17 Philip Blundell <Philip.Blundell@pobox.com> * nss/nss_db/db-XXX.c: Include <db_185.h> not <db.h>. Somebody should update this to use the new db API. * nss/nss_db/db-netgrp.c: Likewise. * nss/nss_db/db-alias.c: Likewise. * db2/Makefile: Makefile for db-2.x in glibc. 1997-08-27 21:20 Ulrich Drepper <drepper@cygnus.com> * csu/Makefile (before-compile): New goal. Make sure abi-tag.h is generated. [$(elf)=yes] (asm-CPPFLAGS): Make sure abi-tag.h file can be found. * Makeconfig [$(build-omitfp)=yes] (CFLAGS-.o): Add -D__USE_STRING_INLINES. * string/string.f: Move strnlen optimization after inclusion of <bits/string.h>. Include <bits/string.h> only if __USE_STRING_INLINES is defined. * sysdeps/generic/memcpy.c: Undef memcpy to allow macro of this name in <bits/string.h>. * sysdeps/generic/memset.c: Likewise. * sysdeps/i386/string.h: i386 optimized string functions. * sysdeps/i386/i486string.h: i486+ optimized string functions. * Makefile (subdirs): Change db to db2. * shlib-versions: Bump libdb verion number to 3. * include/db.h: Include from db2 directory. * include/db_185.h: New file. * sysdeps/i386/Makefile [$(subdirs)=db2] (CPPFLAGS): Add macros to provide spinlock information for db2. * sysdeps/m68k/m68020/Makefile: New file. Likewise. * sysdeps/sparc/Makefile: New file. Likewise. * sysdeps/unix/sysv/linux/Makefile [$(subdirs)=db2] (CPPFLAGS): Add -DHAVE_LLSEEK. * db2/config.h: Hand-edited config file for db2 in glibc. * db2/compat.h: New file from db-2.3.4. * db2/db.h: Likewise. * db2/db_185.h: Likewise. * db2/db_int.h: Likewise. * db2/makedb.c: Likewise. * db2/btree/bt_close.c: Likewise. * db2/btree/bt_compare.c: Likewise. * db2/btree/bt_conv.c: Likewise. * db2/btree/bt_cursor.c: Likewise. * db2/btree/bt_delete.c: Likewise. * db2/btree/bt_open.c: Likewise. * db2/btree/bt_page.c: Likewise. * db2/btree/bt_put.c: Likewise. * db2/btree/bt_rec.c: Likewise. * db2/btree/bt_recno.c: Likewise. * db2/btree/btree_auto.c: Likewise. * db2/btree/bt_rsearch.c: Likewise. * db2/btree/bt_search.c: Likewise. * db2/btree/bt_split.c: Likewise. * db2/btree/bt_stat.c: Likewise. * db2/btree/btree.src: Likewise. * db2/common/db_appinit.c: Likewise. * db2/common/db_err.c: Likewise. * db2/common/db_byteorder.c: Likewise. * db2/common/db_apprec.c: Likewise. * db2/common/db_salloc.c: Likewise. * db2/common/db_log2.c: Likewise. * db2/common/db_region.c: Likewise. * db2/common/db_shash.c: Likewise. * db2/db/db.c: Likewise. * db2/db/db.src: Likewise. * db2/db/db_conv.c: Likewise. * db2/db/db_dispatch.c: Likewise. * db2/db/db_dup.c: Likewise. * db2/db/db_overflow.c: Likewise. * db2/db/db_pr.c: Likewise. * db2/db/db_rec.c: Likewise. * db2/db/db_ret.c: Likewise. * db2/db/db_thread.c: Likewise. * db2/db/db_auto.c: Likewise. * db2/db185/db185.c: Likewise. * db2/db185/db185_int.h: Likewise. * db2/dbm/dbm.c: Likewise. * db2/hash/hash.c: Likewise. * db2/hash/hash.src: Likewise. * db2/hash/hash_page.c: Likewise. * db2/hash/hash_conv.c: Likewise. * db2/hash/hash_debug.c: Likewise. * db2/hash/hash_stat.c: Likewise. * db2/hash/hash_rec.c: Likewise. * db2/hash/hash_dup.c: Likewise. * db2/hash/hash_func.c: Likewise. * db2/hash/hash_auto.c: Likewise. * db2/include/mp.h: Likewise. * db2/include/btree.h: Likewise. * db2/include/db.h.src: Likewise. * db2/include/db_int.h.src: Likewise. * db2/include/db_shash.h: Likewise. * db2/include/db_swap.h: Likewise. * db2/include/db_185.h.src: Likewise. * db2/include/txn.h: Likewise. * db2/include/db_am.h: Likewise. * db2/include/shqueue.h: Likewise. * db2/include/hash.h: Likewise. * db2/include/db_dispatch.h: Likewise. * db2/include/lock.h: Likewise. * db2/include/db_page.h: Likewise. * db2/include/log.h: Likewise. * db2/include/db_auto.h: Likewise. * db2/include/btree_auto.h: Likewise. * db2/include/hash_auto.h: Likewise. * db2/include/log_auto.h: Likewise. * db2/include/txn_auto.h: Likewise. * db2/include/db_ext.h: Likewise. * db2/include/btree_ext.h: Likewise. * db2/include/clib_ext.h: Likewise. * db2/include/common_ext.h: Likewise. * db2/include/hash_ext.h: Likewise. * db2/include/lock_ext.h: Likewise. * db2/include/log_ext.h: Likewise. * db2/include/mp_ext.h: Likewise. * db2/include/mutex_ext.h: Likewise. * db2/include/os_ext.h: Likewise. * db2/include/txn_ext.h: Likewise. * db2/include/cxx_int.h: Likewise. * db2/include/db_cxx.h: Likewise. * db2/include/queue.h: Likewise. * db2/lock/lock.c: Likewise. * db2/lock/lock_conflict.c: Likewise. * db2/lock/lock_util.c: Likewise. * db2/lock/lock_deadlock.c: Likewise. * db2/log/log.c: Likewise. * db2/log/log_get.c: Likewise. * db2/log/log.src: Likewise. * db2/log/log_compare.c: Likewise. * db2/log/log_put.c: Likewise. * db2/log/log_rec.c: Likewise. * db2/log/log_archive.c: Likewise. * db2/log/log_register.c: Likewise. * db2/log/log_auto.c: Likewise. * db2/log/log_findckp.c: Likewise. * db2/mp/mp_bh.c: Likewise. * db2/mp/mp_fget.c: Likewise. * db2/mp/mp_fopen.c: Likewise. * db2/mp/mp_fput.c: Likewise. * db2/mp/mp_fset.c: Likewise. * db2/mp/mp_open.c: Likewise. * db2/mp/mp_region.c: Likewise. * db2/mp/mp_pr.c: Likewise. * db2/mp/mp_sync.c: Likewise. * db2/mutex/68020.gcc: Likewise. * db2/mutex/mutex.c: Likewise. * db2/mutex/README: Likewise. * db2/mutex/x86.gcc: Likewise. * db2/mutex/sparc.gcc: Likewise. * db2/mutex/uts4.cc.s: Likewise. * db2/mutex/alpha.dec: Likewise. * db2/mutex/alpha.gcc: Likewise. * db2/mutex/parisc.gcc: Likewise. * db2/mutex/parisc.hp: Likewise. * db2/os/db_os_abs.c: Likewise. * db2/os/db_os_dir.c: Likewise. * db2/os/db_os_fid.c: Likewise. * db2/os/db_os_lseek.c: Likewise. * db2/os/db_os_mmap.c: Likewise. * db2/os/db_os_open.c: Likewise. * db2/os/db_os_rw.c: Likewise. * db2/os/db_os_sleep.c: Likewise. * db2/os/db_os_stat.c: Likewise. * db2/os/db_os_unlink.c: Likewise. * db2/txn/txn.c: Likewise. * db2/txn/txn.src: Likewise. * db2/txn/txn_rec.c: Likewise. * db2/txn/txn_auto.c: Likewise. * db2/clib/getlong.c: Likewise. * db2/progs/db_archive/db_archive.c: Likewise. * db2/progs/db_checkpoint/db_checkpoint.c: Likewise. * db2/progs/db_deadlock/db_deadlock.c: Likewise. * db2/progs/db_dump/db_dump.c: Likewise. * db2/progs/db_dump185/db_dump185.c: Likewise. * db2/progs/db_load/db_load.c: Likewise. * db2/progs/db_printlog/db_printlog.c: Likewise. * db2/progs/db_recover/db_recover.c: Likewise. * db2/progs/db_stat/db_stat.c: Likewise. * libio/stdio.h [__cplusplus] (__STDIO_INLINE): Define as inline. * po/de.po, po/sv.po: Update from 2.0.5 translations. * sysdeps/unix/sysv/linux/netinet/tcp.h: Pretty print. * sunrpc/rpc/xdr.h (XDR): Don't define argument of x_destroy callback as const. * sunrpc/xdr_mem.c (xdrmem_destroy): Don't define argument as const. * sunrpx/xdr_rec.c (xdrrec_destroy): Likewise. * sunrpx/xdr_stdio.c (xdrstdio_destroy): Likewise. 1997-08-27 18:47 Ulrich Drepper <drepper@cygnus.com> * sysdeps/unix/sysv/linux/if_index.c: Include <errno.h>. Reported by Benjamin Kosnik <bkoz@cygnus.com>. 1997-08-27 02:27 Roland McGrath <roland@baalperazim.frob.com> * abi-tags: New file. * csu/Makefile (distribute): Remove abi-tag.h. ($(objpfx)abi-tag.h): New target. * Makefile (distribute): Add abi-tags. * sysdeps/unix/sysv/linux/abi-tag.h: File removed. * sysdeps/mach/hurd/abi-tag.h: File removed. * sysdeps/stub/abi-tag.h: File removed. 1997-08-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> * sysdeps/unix/make-syscalls.sh: Change output so that it generates compilation rules only for the currently selected object suffixes. 1997-08-25 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> * sysdeps/m68k/dl-machine.h (RTLD_START): Switch back to previous section to avoid confusing the compiler. * sysdeps/alpha/dl-machine.h (RTLD_START): Likewise. * sysdeps/i386/dl-machine.h (RTLD_START): Likewise. * sysdeps/mips/dl-machine.h (RTLD_START): Likewise. * sysdeps/mips/mips64/dl-machine.h (RTLD_START): Likewise. * sysdeps/sparc/sparc32/dl-machine.h (RTLD_START): Likewise. * sysdeps/m68k/dl-machine.h (elf_machine_load_address): Use a GOT relocation instead of a constant to avoid text relocation. (ELF_MACHINE_BEFORE_RTLD_RELOC): Removed. (RTLD_START): Declare global labels as functions and add size directive. 1997-08-25 17:01 Ulrich Drepper <drepper@cygnus.com> * sysdeps/i386/bits/select.h: Correct assembler versions to work even for descriptors >= 32. * stdlib/alloca.h: Don't define alloca to __alloca since if gcc is used __alloca is not defined to __builtin_alloca and so might not be available. Reported by Uwe Ohse <uwe@ohse.de>. * sysdeps/unix/sysv/linux/sys/sysmacros.h: Define macros in a special way if gcc is not used and so dev_t is an array. Reported by Uwe Ohse <uwe@ohse.de>. 1997-08-23 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> * manual/libc.texinfo: Reorder chapters to match logical order. 1997-08-25 12:22 Ulrich Drepper <drepper@cygnus.com> * sunrpc/rpc/xdr.h: Change name of parameters in prototypes of xdr_reference, xdrmem_create, and xdrstdio_create because of clash with g++ internal symbols. Patch by Sudish Joseph <sj@eng.mindspring.net>. * elf/dl-deps.c: Implement handling of DT_FILTER.
438 lines
11 KiB
C
438 lines
11 KiB
C
/*-
|
|
* See the file LICENSE for redistribution information.
|
|
*
|
|
* Copyright (c) 1996, 1997
|
|
* Sleepycat Software. All rights reserved.
|
|
*/
|
|
#include "config.h"
|
|
|
|
#ifndef lint
|
|
static const char sccsid[] = "@(#)mp_fopen.c 10.24 (Sleepycat) 8/20/97";
|
|
#endif /* not lint */
|
|
|
|
#ifndef NO_SYSTEM_INCLUDES
|
|
#include <sys/types.h>
|
|
#include <sys/mman.h>
|
|
#include <sys/stat.h>
|
|
|
|
#include <errno.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
#include "db_int.h"
|
|
#include "shqueue.h"
|
|
#include "db_shash.h"
|
|
#include "mp.h"
|
|
#include "common_ext.h"
|
|
|
|
static int __memp_mf_close __P((DB_MPOOL *, DB_MPOOLFILE *));
|
|
static int __memp_mf_open __P((DB_MPOOL *, DB_MPOOLFILE *,
|
|
int, int, size_t, int, DBT *, u_int8_t *, int, MPOOLFILE **));
|
|
|
|
/*
|
|
* memp_fopen --
|
|
* Open a backing file for the memory pool.
|
|
*/
|
|
int
|
|
memp_fopen(dbmp, path, ftype,
|
|
flags, mode, pagesize, lsn_offset, pgcookie, fileid, retp)
|
|
DB_MPOOL *dbmp;
|
|
const char *path;
|
|
int ftype, flags, mode, lsn_offset;
|
|
size_t pagesize;
|
|
DBT *pgcookie;
|
|
u_int8_t *fileid;
|
|
DB_MPOOLFILE **retp;
|
|
{
|
|
int ret;
|
|
|
|
/* Validate arguments. */
|
|
if ((ret = __db_fchk(dbmp->dbenv,
|
|
"memp_fopen", flags, DB_CREATE | DB_NOMMAP | DB_RDONLY)) != 0)
|
|
return (ret);
|
|
|
|
return (__memp_fopen(dbmp, path, ftype,
|
|
flags, mode, pagesize, lsn_offset, pgcookie, fileid, 1, retp));
|
|
}
|
|
|
|
/*
|
|
* __memp_fopen --
|
|
* Open a backing file for the memory pool; internal version.
|
|
*
|
|
* PUBLIC: int __memp_fopen __P((DB_MPOOL *, const char *, int, int,
|
|
* PUBLIC: int, size_t, int, DBT *, u_int8_t *, int, DB_MPOOLFILE **));
|
|
*/
|
|
int
|
|
__memp_fopen(dbmp, path,
|
|
ftype, flags, mode, pagesize, lsn_offset, pgcookie, fileid, needlock, retp)
|
|
DB_MPOOL *dbmp;
|
|
const char *path;
|
|
int ftype, flags, mode, lsn_offset, needlock;
|
|
size_t pagesize;
|
|
DBT *pgcookie;
|
|
u_int8_t *fileid;
|
|
DB_MPOOLFILE **retp;
|
|
{
|
|
DB_ENV *dbenv;
|
|
DB_MPOOLFILE *dbmfp;
|
|
MPOOLFILE *mfp;
|
|
off_t size;
|
|
int ret;
|
|
|
|
dbenv = dbmp->dbenv;
|
|
ret = 0;
|
|
|
|
/* Require a non-zero pagesize. */
|
|
if (pagesize == 0) {
|
|
__db_err(dbenv, "memp_fopen: pagesize not specified");
|
|
return (EINVAL);
|
|
}
|
|
|
|
/* Allocate and initialize the per-process structure. */
|
|
if ((dbmfp =
|
|
(DB_MPOOLFILE *)calloc(1, sizeof(DB_MPOOLFILE))) == NULL) {
|
|
__db_err(dbenv, "%s: %s",
|
|
path == NULL ? TEMPORARY : path, strerror(ENOMEM));
|
|
return (ENOMEM);
|
|
}
|
|
LOCKINIT(dbmp, &dbmfp->mutex);
|
|
dbmfp->dbmp = dbmp;
|
|
dbmfp->fd = -1;
|
|
if (LF_ISSET(DB_RDONLY))
|
|
F_SET(dbmfp, MP_READONLY);
|
|
|
|
if (path == NULL) {
|
|
if (LF_ISSET(DB_RDONLY)) {
|
|
__db_err(dbenv,
|
|
"memp_fopen: temporary files can't be readonly");
|
|
ret = EINVAL;
|
|
goto err;
|
|
}
|
|
dbmfp->path = (char *) TEMPORARY;
|
|
F_SET(dbmfp, MP_PATH_TEMP);
|
|
} else {
|
|
/* Calculate the real name for this file. */
|
|
if ((ret = __db_appname(dbenv,
|
|
DB_APP_DATA, NULL, path, NULL, &dbmfp->path)) != 0)
|
|
goto err;
|
|
F_SET(dbmfp, MP_PATH_ALLOC);
|
|
|
|
|
|
/* Open the file. */
|
|
if ((ret = __db_fdopen(dbmfp->path,
|
|
LF_ISSET(DB_CREATE | DB_RDONLY), DB_CREATE | DB_RDONLY,
|
|
mode, &dbmfp->fd)) != 0) {
|
|
__db_err(dbenv, "%s: %s", dbmfp->path, strerror(ret));
|
|
goto err;
|
|
}
|
|
|
|
/* Don't permit files that aren't a multiple of the pagesize. */
|
|
if ((ret = __db_stat(dbenv,
|
|
dbmfp->path, dbmfp->fd, &size, NULL)) != 0)
|
|
goto err;
|
|
if (size % pagesize) {
|
|
__db_err(dbenv,
|
|
"%s: file size not a multiple of the pagesize",
|
|
dbmfp->path);
|
|
ret = EINVAL;
|
|
goto err;
|
|
}
|
|
}
|
|
|
|
/* Find/allocate the shared file object. */
|
|
if (needlock)
|
|
LOCKREGION(dbmp);
|
|
ret = __memp_mf_open(dbmp, dbmfp, ftype,
|
|
F_ISSET(dbmfp, MP_READONLY), pagesize,
|
|
lsn_offset, pgcookie, fileid, F_ISSET(dbmfp, MP_PATH_TEMP), &mfp);
|
|
if (needlock)
|
|
UNLOCKREGION(dbmp);
|
|
if (ret != 0)
|
|
goto err;
|
|
|
|
dbmfp->mfp = mfp;
|
|
|
|
/*
|
|
* If a file:
|
|
*
|
|
* + is read-only
|
|
* + doesn't require any pgin/pgout support
|
|
* + is less than mp_mmapsize bytes in size.
|
|
* + and the DB_NOMMAP flag wasn't set
|
|
*
|
|
* we can mmap it instead of reading/writing buffers. Don't do error
|
|
* checking based on the mmap call failure. We want to do normal I/O
|
|
* on the file if the reason we failed was because the file was on an
|
|
* NFS mounted partition, and we can fail in buffer I/O just as easily
|
|
* as here.
|
|
*
|
|
* XXX
|
|
* We'd like to test to see if the file is too big to mmap. Since we
|
|
* don't know what size or type off_t's or size_t's are, or the largest
|
|
* unsigned integral type is, or what random insanity the local C
|
|
* compiler will perpetrate, doing the comparison in a portable way is
|
|
* flatly impossible. Hope that mmap fails if the file is too large.
|
|
*/
|
|
#define DB_MAXMMAPSIZE (10 * 1024 * 1024) /* 10 Mb. */
|
|
dbmfp->addr = NULL;
|
|
mfp->can_mmap = F_ISSET(dbmfp, MP_READONLY) &&
|
|
ftype == 0 && !LF_ISSET(DB_NOMMAP) && path != NULL &&
|
|
size <= (dbenv == NULL || dbenv->mp_mmapsize == 0 ?
|
|
DB_MAXMMAPSIZE : (off_t)dbenv->mp_mmapsize);
|
|
if (mfp->can_mmap) {
|
|
dbmfp->len = size;
|
|
if (__db_mmap(dbmfp->fd, dbmfp->len, 1, 1, &dbmfp->addr) != 0) {
|
|
mfp->can_mmap = 0;
|
|
dbmfp->addr = NULL;
|
|
}
|
|
}
|
|
|
|
LOCKHANDLE(dbmp, &dbmp->mutex);
|
|
TAILQ_INSERT_TAIL(&dbmp->dbmfq, dbmfp, q);
|
|
UNLOCKHANDLE(dbmp, &dbmp->mutex);
|
|
|
|
*retp = dbmfp;
|
|
return (0);
|
|
|
|
err: if (F_ISSET(dbmfp, MP_PATH_ALLOC))
|
|
FREES(dbmfp->path);
|
|
if (dbmfp->fd != -1)
|
|
(void)__db_close(dbmfp->fd);
|
|
if (dbmfp != NULL)
|
|
FREE(dbmfp, sizeof(DB_MPOOLFILE));
|
|
return (ret);
|
|
}
|
|
|
|
/*
|
|
* __memp_mf_open --
|
|
* Open an MPOOLFILE.
|
|
*/
|
|
static int
|
|
__memp_mf_open(dbmp, dbmfp,
|
|
ftype, readonly, pagesize, lsn_offset, pgcookie, fileid, istemp, retp)
|
|
DB_MPOOL *dbmp;
|
|
DB_MPOOLFILE *dbmfp;
|
|
int ftype, readonly, lsn_offset, istemp;
|
|
size_t pagesize;
|
|
DBT *pgcookie;
|
|
u_int8_t *fileid;
|
|
MPOOLFILE **retp;
|
|
{
|
|
MPOOLFILE *mfp;
|
|
int ret;
|
|
u_int8_t idbuf[DB_FILE_ID_LEN];
|
|
void *p;
|
|
|
|
/* Temporary files can't match previous files. */
|
|
if (istemp)
|
|
goto alloc;
|
|
|
|
/*
|
|
* Get the file id if we weren't give one. Generated file id's don't
|
|
* use timestamps, otherwise there'd be no chance of anyone joining
|
|
* the party.
|
|
*/
|
|
if (fileid == NULL) {
|
|
if ((ret =
|
|
__db_fileid(dbmp->dbenv, dbmfp->path, 0, idbuf)) != 0)
|
|
return (ret);
|
|
fileid = idbuf;
|
|
}
|
|
|
|
/* Walk the list of MPOOLFILE's, looking for a matching file. */
|
|
for (mfp = SH_TAILQ_FIRST(&dbmp->mp->mpfq, __mpoolfile);
|
|
mfp != NULL; mfp = SH_TAILQ_NEXT(mfp, q, __mpoolfile))
|
|
if (!memcmp(fileid,
|
|
ADDR(dbmp, mfp->fileid_off), DB_FILE_ID_LEN)) {
|
|
if (ftype != mfp->ftype ||
|
|
pagesize != mfp->stat.st_pagesize) {
|
|
__db_err(dbmp->dbenv,
|
|
"%s: ftype or pagesize changed",
|
|
dbmfp->path);
|
|
ret = EINVAL;
|
|
mfp = NULL;
|
|
goto ret1;
|
|
}
|
|
/*
|
|
* Found it: increment the reference count and update
|
|
* the mmap-able status.
|
|
*/
|
|
++mfp->ref;
|
|
if (!readonly)
|
|
mfp->can_mmap = 0;
|
|
goto ret1;
|
|
}
|
|
|
|
/* Allocate a new MPOOLFILE. */
|
|
alloc: if ((ret = __memp_ralloc(dbmp, sizeof(MPOOLFILE), NULL, &mfp)) != 0)
|
|
goto ret1;
|
|
|
|
/* Initialize the structure. */
|
|
memset(mfp, 0, sizeof(MPOOLFILE));
|
|
mfp->ref = 1;
|
|
mfp->ftype = ftype;
|
|
mfp->lsn_off = lsn_offset;
|
|
mfp->stat.st_pagesize = pagesize;
|
|
|
|
/* Copy the file path into shared memory. */
|
|
if ((ret = __memp_ralloc(dbmp,
|
|
strlen(dbmfp->path) + 1, &mfp->path_off, &p)) != 0)
|
|
goto err;
|
|
memcpy(p, dbmfp->path, strlen(dbmfp->path) + 1);
|
|
|
|
/* Copy the file identification string into shared memory. */
|
|
if (istemp)
|
|
mfp->fileid_off = 0;
|
|
else {
|
|
if ((ret = __memp_ralloc(dbmp,
|
|
DB_FILE_ID_LEN, &mfp->fileid_off, &p)) != 0)
|
|
goto err;
|
|
memcpy(p, fileid, DB_FILE_ID_LEN);
|
|
}
|
|
|
|
/* Copy the page cookie into shared memory. */
|
|
if (pgcookie == NULL || pgcookie->size == 0) {
|
|
mfp->pgcookie_len = 0;
|
|
mfp->pgcookie_off = 0;
|
|
} else {
|
|
if ((ret = __memp_ralloc(dbmp,
|
|
pgcookie->size, &mfp->pgcookie_off, &p)) != 0)
|
|
goto err;
|
|
memcpy(p, pgcookie->data, pgcookie->size);
|
|
mfp->pgcookie_len = pgcookie->size;
|
|
}
|
|
|
|
/* Prepend the MPOOLFILE to the list of MPOOLFILE's. */
|
|
SH_TAILQ_INSERT_HEAD(&dbmp->mp->mpfq, mfp, q, __mpoolfile);
|
|
|
|
if (0) {
|
|
err: if (mfp->path_off != 0)
|
|
__db_shalloc_free(dbmp->addr,
|
|
ADDR(dbmp, mfp->path_off));
|
|
if (!istemp)
|
|
__db_shalloc_free(dbmp->addr,
|
|
ADDR(dbmp, mfp->fileid_off));
|
|
if (mfp != NULL)
|
|
__db_shalloc_free(dbmp->addr, mfp);
|
|
mfp = NULL;
|
|
}
|
|
|
|
ret1: *retp = mfp;
|
|
return (0);
|
|
}
|
|
|
|
/*
|
|
* memp_fclose --
|
|
* Close a backing file for the memory pool.
|
|
*/
|
|
int
|
|
memp_fclose(dbmfp)
|
|
DB_MPOOLFILE *dbmfp;
|
|
{
|
|
DB_MPOOL *dbmp;
|
|
int ret, t_ret;
|
|
|
|
dbmp = dbmfp->dbmp;
|
|
ret = 0;
|
|
|
|
/* Complain if pinned blocks never returned. */
|
|
if (dbmfp->pinref != 0)
|
|
__db_err(dbmp->dbenv, "%s: close: %lu blocks left pinned",
|
|
dbmfp->path, (u_long)dbmfp->pinref);
|
|
|
|
/* Remove the DB_MPOOLFILE structure from the list. */
|
|
LOCKHANDLE(dbmp, &dbmp->mutex);
|
|
TAILQ_REMOVE(&dbmp->dbmfq, dbmfp, q);
|
|
UNLOCKHANDLE(dbmp, &dbmp->mutex);
|
|
|
|
/* Close the underlying MPOOLFILE. */
|
|
(void)__memp_mf_close(dbmp, dbmfp);
|
|
|
|
/* Discard any mmap information. */
|
|
if (dbmfp->addr != NULL &&
|
|
(ret = __db_munmap(dbmfp->addr, dbmfp->len)) != 0)
|
|
__db_err(dbmp->dbenv, "%s: %s", dbmfp->path, strerror(ret));
|
|
|
|
/* Close the file; temporary files may not yet have been created. */
|
|
if (dbmfp->fd != -1 && (t_ret = __db_close(dbmfp->fd)) != 0) {
|
|
__db_err(dbmp->dbenv, "%s: %s", dbmfp->path, strerror(t_ret));
|
|
if (ret != 0)
|
|
t_ret = ret;
|
|
}
|
|
|
|
/* Potentially allocated path. */
|
|
if (F_ISSET(dbmfp, MP_PATH_ALLOC))
|
|
FREES(dbmfp->path);
|
|
|
|
/* Free the DB_MPOOLFILE structure. */
|
|
FREE(dbmfp, sizeof(DB_MPOOLFILE));
|
|
|
|
return (ret);
|
|
}
|
|
|
|
/*
|
|
* __memp_mf_close --
|
|
* Close down an MPOOLFILE.
|
|
*/
|
|
static int
|
|
__memp_mf_close(dbmp, dbmfp)
|
|
DB_MPOOL *dbmp;
|
|
DB_MPOOLFILE *dbmfp;
|
|
{
|
|
BH *bhp, *nbhp;
|
|
MPOOL *mp;
|
|
MPOOLFILE *mfp;
|
|
size_t mf_offset;
|
|
|
|
mp = dbmp->mp;
|
|
mfp = dbmfp->mfp;
|
|
|
|
LOCKREGION(dbmp);
|
|
|
|
/* If more than a single reference, simply decrement. */
|
|
if (mfp->ref > 1) {
|
|
--mfp->ref;
|
|
goto ret1;
|
|
}
|
|
|
|
/*
|
|
* Move any BH's held by the file to the free list. We don't free the
|
|
* memory itself because we may be discarding the memory pool, and it's
|
|
* fairly expensive to reintegrate the buffers back into the region for
|
|
* no purpose.
|
|
*/
|
|
mf_offset = OFFSET(dbmp, mfp);
|
|
for (bhp = SH_TAILQ_FIRST(&mp->bhq, __bh); bhp != NULL; bhp = nbhp) {
|
|
nbhp = SH_TAILQ_NEXT(bhp, q, __bh);
|
|
|
|
#ifdef DEBUG_NO_DIRTY
|
|
/* Complain if we find any blocks that were left dirty. */
|
|
if (F_ISSET(bhp, BH_DIRTY))
|
|
__db_err(dbmp->dbenv,
|
|
"%s: close: pgno %lu left dirty; ref %lu",
|
|
dbmfp->path, (u_long)bhp->pgno, (u_long)bhp->ref);
|
|
#endif
|
|
|
|
if (bhp->mf_offset == mf_offset) {
|
|
__memp_bhfree(dbmp, mfp, bhp, 0);
|
|
SH_TAILQ_INSERT_HEAD(&mp->bhfq, bhp, q, __bh);
|
|
}
|
|
}
|
|
|
|
/* Delete from the list of MPOOLFILEs. */
|
|
SH_TAILQ_REMOVE(&mp->mpfq, mfp, q, __mpoolfile);
|
|
|
|
/* Free the space. */
|
|
__db_shalloc_free(dbmp->addr, mfp);
|
|
__db_shalloc_free(dbmp->addr, ADDR(dbmp, mfp->path_off));
|
|
if (mfp->fileid_off != 0)
|
|
__db_shalloc_free(dbmp->addr, ADDR(dbmp, mfp->fileid_off));
|
|
if (mfp->pgcookie_off != 0)
|
|
__db_shalloc_free(dbmp->addr, ADDR(dbmp, mfp->pgcookie_off));
|
|
|
|
ret1: UNLOCKREGION(dbmp);
|
|
return (0);
|
|
}
|