mirror of
https://github.com/MariaDB/server.git
synced 2025-01-30 18:41:56 +01:00
155e78f014
BitKeeper/deleted/.del-ex_access.wpj~3df6ae8c99bf7c5f: Delete: bdb/build_vxworks/ex_access/ex_access.wpj BitKeeper/deleted/.del-ex_btrec.wpj~a7622f1c6f432dc6: Delete: bdb/build_vxworks/ex_btrec/ex_btrec.wpj BitKeeper/deleted/.del-ex_dbclient.wpj~7345440f3b204cdd: Delete: bdb/build_vxworks/ex_dbclient/ex_dbclient.wpj BitKeeper/deleted/.del-ex_env.wpj~fbe1ab10b04e8b74: Delete: bdb/build_vxworks/ex_env/ex_env.wpj BitKeeper/deleted/.del-ex_mpool.wpj~4479cfd5c45f327d: Delete: bdb/build_vxworks/ex_mpool/ex_mpool.wpj BitKeeper/deleted/.del-ex_tpcb.wpj~f78093006e14bf41: Delete: bdb/build_vxworks/ex_tpcb/ex_tpcb.wpj BitKeeper/deleted/.del-db_buildall.dsp~bd749ff6da11682: Delete: bdb/build_win32/db_buildall.dsp BitKeeper/deleted/.del-cxx_app.cpp~ad8df8e0791011ed: Delete: bdb/cxx/cxx_app.cpp BitKeeper/deleted/.del-cxx_log.cpp~a50ff3118fe06952: Delete: bdb/cxx/cxx_log.cpp BitKeeper/deleted/.del-cxx_table.cpp~ecd751e79b055556: Delete: bdb/cxx/cxx_table.cpp BitKeeper/deleted/.del-namemap.txt~796a3acd3885d8fd: Delete: bdb/cxx/namemap.txt BitKeeper/deleted/.del-Design.fileop~3ca4da68f1727373: Delete: bdb/db/Design.fileop BitKeeper/deleted/.del-db185_int.h~61bee3736e7959ef: Delete: bdb/db185/db185_int.h BitKeeper/deleted/.del-acconfig.h~411e8854d67ad8b5: Delete: bdb/dist/acconfig.h BitKeeper/deleted/.del-mutex.m4~a13383cde18a64e1: Delete: bdb/dist/aclocal/mutex.m4 BitKeeper/deleted/.del-options.m4~b9d0ca637213750a: Delete: bdb/dist/aclocal/options.m4 BitKeeper/deleted/.del-programs.m4~3ce7890b47732b30: Delete: bdb/dist/aclocal/programs.m4 BitKeeper/deleted/.del-tcl.m4~f944e2db93c3b6db: Delete: bdb/dist/aclocal/tcl.m4 BitKeeper/deleted/.del-types.m4~59cae158c9a32cff: Delete: bdb/dist/aclocal/types.m4 BitKeeper/deleted/.del-script~d38f6d3a4f159cb4: Delete: bdb/dist/build/script BitKeeper/deleted/.del-configure.in~ac795a92c8fe049c: Delete: bdb/dist/configure.in BitKeeper/deleted/.del-ltconfig~66bbd007d8024af: Delete: bdb/dist/ltconfig BitKeeper/deleted/.del-rec_ctemp~a28554362534f00a: Delete: bdb/dist/rec_ctemp BitKeeper/deleted/.del-s_tcl~2ffe4326459fcd9f: Delete: bdb/dist/s_tcl BitKeeper/deleted/.del-.IGNORE_ME~d8148b08fa7d5d15: Delete: bdb/dist/template/.IGNORE_ME BitKeeper/deleted/.del-btree.h~179f2aefec1753d: Delete: bdb/include/btree.h BitKeeper/deleted/.del-cxx_int.h~6b649c04766508f8: Delete: bdb/include/cxx_int.h BitKeeper/deleted/.del-db.src~6b433ae615b16a8d: Delete: bdb/include/db.src BitKeeper/deleted/.del-db_185.h~ad8b373d9391d35c: Delete: bdb/include/db_185.h BitKeeper/deleted/.del-db_am.h~a714912b6b75932f: Delete: bdb/include/db_am.h BitKeeper/deleted/.del-db_cxx.h~fcafadf45f5d19e9: Delete: bdb/include/db_cxx.h BitKeeper/deleted/.del-db_dispatch.h~6844f20f7eb46904: Delete: bdb/include/db_dispatch.h BitKeeper/deleted/.del-db_int.src~419a3f48b6a01da7: Delete: bdb/include/db_int.src BitKeeper/deleted/.del-db_join.h~76f9747a42c3399a: Delete: bdb/include/db_join.h BitKeeper/deleted/.del-db_page.h~e302ca3a4db3abdc: Delete: bdb/include/db_page.h BitKeeper/deleted/.del-db_server_int.h~e1d20b6ba3bca1ab: Delete: bdb/include/db_server_int.h BitKeeper/deleted/.del-db_shash.h~5fbf2d696fac90f3: Delete: bdb/include/db_shash.h BitKeeper/deleted/.del-db_swap.h~1e60887550864a59: Delete: bdb/include/db_swap.h BitKeeper/deleted/.del-db_upgrade.h~c644eee73701fc8d: Delete: bdb/include/db_upgrade.h BitKeeper/deleted/.del-db_verify.h~b8d6c297c61f342e: Delete: bdb/include/db_verify.h BitKeeper/deleted/.del-debug.h~dc2b4f2cf27ccebc: Delete: bdb/include/debug.h BitKeeper/deleted/.del-hash.h~2aaa548b28882dfb: Delete: bdb/include/hash.h BitKeeper/deleted/.del-lock.h~a761c1b7de57b77f: Delete: bdb/include/lock.h BitKeeper/deleted/.del-log.h~ff20184238e35e4d: Delete: bdb/include/log.h BitKeeper/deleted/.del-mp.h~7e317597622f3411: Delete: bdb/include/mp.h BitKeeper/deleted/.del-mutex.h~d3ae7a2977a68137: Delete: bdb/include/mutex.h BitKeeper/deleted/.del-os.h~91867cc8757cd0e3: Delete: bdb/include/os.h BitKeeper/deleted/.del-os_jump.h~e1b939fa5151d4be: Delete: bdb/include/os_jump.h BitKeeper/deleted/.del-qam.h~6fad0c1b5723d597: Delete: bdb/include/qam.h BitKeeper/deleted/.del-queue.h~4c72c0826c123d5: Delete: bdb/include/queue.h BitKeeper/deleted/.del-region.h~513fe04d977ca0fc: Delete: bdb/include/region.h BitKeeper/deleted/.del-shqueue.h~525fc3e6c2025c36: Delete: bdb/include/shqueue.h BitKeeper/deleted/.del-tcl_db.h~c536fd61a844f23f: Delete: bdb/include/tcl_db.h BitKeeper/deleted/.del-txn.h~c8d94b221ec147e4: Delete: bdb/include/txn.h BitKeeper/deleted/.del-xa.h~ecc466493aae9d9a: Delete: bdb/include/xa.h BitKeeper/deleted/.del-DbRecoveryInit.java~756b52601a0b9023: Delete: bdb/java/src/com/sleepycat/db/DbRecoveryInit.java BitKeeper/deleted/.del-DbTxnRecover.java~74607cba7ab89d6d: Delete: bdb/java/src/com/sleepycat/db/DbTxnRecover.java BitKeeper/deleted/.del-lock_conflict.c~fc5e0f14cf597a2b: Delete: bdb/lock/lock_conflict.c BitKeeper/deleted/.del-log.src~53ac9e7b5cb023f2: Delete: bdb/log/log.src BitKeeper/deleted/.del-log_findckp.c~24287f008916e81f: Delete: bdb/log/log_findckp.c BitKeeper/deleted/.del-log_rec.c~d51711f2cac09297: Delete: bdb/log/log_rec.c BitKeeper/deleted/.del-log_register.c~b40bb4efac75ca15: Delete: bdb/log/log_register.c BitKeeper/deleted/.del-Design~b3d0f179f2767b: Delete: bdb/mp/Design BitKeeper/deleted/.del-os_finit.c~95dbefc6fe79b26c: Delete: bdb/os/os_finit.c BitKeeper/deleted/.del-os_abs.c~df95d1e7db81924: Delete: bdb/os_vxworks/os_abs.c BitKeeper/deleted/.del-os_finit.c~803b484bdb9d0122: Delete: bdb/os_vxworks/os_finit.c BitKeeper/deleted/.del-os_map.c~3a6d7926398b76d3: Delete: bdb/os_vxworks/os_map.c BitKeeper/deleted/.del-os_finit.c~19a227c6d3c78ad: Delete: bdb/os_win32/os_finit.c BitKeeper/deleted/.del-log-corruption.patch~1cf2ecc7c6408d5d: Delete: bdb/patches/log-corruption.patch BitKeeper/deleted/.del-Btree.pm~af6d0c5eaed4a98e: Delete: bdb/perl.BerkeleyDB/BerkeleyDB/Btree.pm BitKeeper/deleted/.del-BerkeleyDB.pm~7244036d4482643: Delete: bdb/perl.BerkeleyDB/BerkeleyDB.pm BitKeeper/deleted/.del-BerkeleyDB.pod~e7b18fd6132448e3: Delete: bdb/perl.BerkeleyDB/BerkeleyDB.pod BitKeeper/deleted/.del-Hash.pm~10292a26c06a5c95: Delete: bdb/perl.BerkeleyDB/BerkeleyDB/Hash.pm BitKeeper/deleted/.del-BerkeleyDB.pod.P~79f76a1495eda203: Delete: bdb/perl.BerkeleyDB/BerkeleyDB.pod.P BitKeeper/deleted/.del-BerkeleyDB.xs~80c99afbd98e392c: Delete: bdb/perl.BerkeleyDB/BerkeleyDB.xs BitKeeper/deleted/.del-Changes~729c1891efa60de9: Delete: bdb/perl.BerkeleyDB/Changes BitKeeper/deleted/.del-MANIFEST~63a1e34aecf157a0: Delete: bdb/perl.BerkeleyDB/MANIFEST BitKeeper/deleted/.del-Makefile.PL~c68797707d8df87a: Delete: bdb/perl.BerkeleyDB/Makefile.PL BitKeeper/deleted/.del-README~5f2f579b1a241407: Delete: bdb/perl.BerkeleyDB/README BitKeeper/deleted/.del-Todo~dca3c66c193adda9: Delete: bdb/perl.BerkeleyDB/Todo BitKeeper/deleted/.del-config.in~ae81681e450e0999: Delete: bdb/perl.BerkeleyDB/config.in BitKeeper/deleted/.del-dbinfo~28ad67d83be4f68e: Delete: bdb/perl.BerkeleyDB/dbinfo BitKeeper/deleted/.del-mkconsts~543ab60669c7a04e: Delete: bdb/perl.BerkeleyDB/mkconsts BitKeeper/deleted/.del-mkpod~182c0ca54e439afb: Delete: bdb/perl.BerkeleyDB/mkpod BitKeeper/deleted/.del-5.004~e008cb5a48805543: Delete: bdb/perl.BerkeleyDB/patches/5.004 BitKeeper/deleted/.del-irix_6_5.pl~61662bb08afcdec8: Delete: bdb/perl.BerkeleyDB/hints/irix_6_5.pl BitKeeper/deleted/.del-solaris.pl~6771e7182394e152: Delete: bdb/perl.BerkeleyDB/hints/solaris.pl BitKeeper/deleted/.del-typemap~783b8f5295b05f3d: Delete: bdb/perl.BerkeleyDB/typemap BitKeeper/deleted/.del-5.004_01~6081ce2fff7b0bc: Delete: bdb/perl.BerkeleyDB/patches/5.004_01 BitKeeper/deleted/.del-5.004_02~87214eac35ad9e6: Delete: bdb/perl.BerkeleyDB/patches/5.004_02 BitKeeper/deleted/.del-5.004_03~9a672becec7cb40f: Delete: bdb/perl.BerkeleyDB/patches/5.004_03 BitKeeper/deleted/.del-5.004_04~e326cb51af09d154: Delete: bdb/perl.BerkeleyDB/patches/5.004_04 BitKeeper/deleted/.del-5.004_05~7ab457a1e41a92fe: Delete: bdb/perl.BerkeleyDB/patches/5.004_05 BitKeeper/deleted/.del-5.005~f9e2d59b5964cd4b: Delete: bdb/perl.BerkeleyDB/patches/5.005 BitKeeper/deleted/.del-5.005_01~3eb9fb7b5842ea8e: Delete: bdb/perl.BerkeleyDB/patches/5.005_01 BitKeeper/deleted/.del-5.005_02~67477ce0bef717cb: Delete: bdb/perl.BerkeleyDB/patches/5.005_02 BitKeeper/deleted/.del-5.005_03~c4c29a1fb21e290a: Delete: bdb/perl.BerkeleyDB/patches/5.005_03 BitKeeper/deleted/.del-5.6.0~e1fb9897d124ee22: Delete: bdb/perl.BerkeleyDB/patches/5.6.0 BitKeeper/deleted/.del-btree.t~e4a1a3c675ddc406: Delete: bdb/perl.BerkeleyDB/t/btree.t BitKeeper/deleted/.del-db-3.0.t~d2c60991d84558f2: Delete: bdb/perl.BerkeleyDB/t/db-3.0.t BitKeeper/deleted/.del-db-3.1.t~6ee88cd13f55e018: Delete: bdb/perl.BerkeleyDB/t/db-3.1.t BitKeeper/deleted/.del-db-3.2.t~f73b6461f98fd1cf: Delete: bdb/perl.BerkeleyDB/t/db-3.2.t BitKeeper/deleted/.del-destroy.t~cc6a2ae1980a2ecd: Delete: bdb/perl.BerkeleyDB/t/destroy.t BitKeeper/deleted/.del-env.t~a8604a4499c4bd07: Delete: bdb/perl.BerkeleyDB/t/env.t BitKeeper/deleted/.del-examples.t~2571b77c3cc75574: Delete: bdb/perl.BerkeleyDB/t/examples.t BitKeeper/deleted/.del-examples.t.T~8228bdd75ac78b88: Delete: bdb/perl.BerkeleyDB/t/examples.t.T BitKeeper/deleted/.del-examples3.t.T~66a186897a87026d: Delete: bdb/perl.BerkeleyDB/t/examples3.t.T BitKeeper/deleted/.del-examples3.t~fe3822ba2f2d7f83: Delete: bdb/perl.BerkeleyDB/t/examples3.t BitKeeper/deleted/.del-filter.t~f87b045c1b708637: Delete: bdb/perl.BerkeleyDB/t/filter.t BitKeeper/deleted/.del-hash.t~616bfb4d644de3a3: Delete: bdb/perl.BerkeleyDB/t/hash.t BitKeeper/deleted/.del-join.t~29fc39f74a83ca22: Delete: bdb/perl.BerkeleyDB/t/join.t BitKeeper/deleted/.del-mldbm.t~31f5015341eea040: Delete: bdb/perl.BerkeleyDB/t/mldbm.t BitKeeper/deleted/.del-queue.t~8f338034ce44a641: Delete: bdb/perl.BerkeleyDB/t/queue.t BitKeeper/deleted/.del-recno.t~d4ddbd3743add63e: Delete: bdb/perl.BerkeleyDB/t/recno.t BitKeeper/deleted/.del-strict.t~6885cdd2ea71ca2d: Delete: bdb/perl.BerkeleyDB/t/strict.t BitKeeper/deleted/.del-subdb.t~aab62a5d5864c603: Delete: bdb/perl.BerkeleyDB/t/subdb.t BitKeeper/deleted/.del-txn.t~65033b8558ae1216: Delete: bdb/perl.BerkeleyDB/t/txn.t BitKeeper/deleted/.del-unknown.t~f3710458682665e1: Delete: bdb/perl.BerkeleyDB/t/unknown.t BitKeeper/deleted/.del-Changes~436f74a5c414c65b: Delete: bdb/perl.DB_File/Changes BitKeeper/deleted/.del-DB_File.pm~ae0951c6c7665a82: Delete: bdb/perl.DB_File/DB_File.pm BitKeeper/deleted/.del-DB_File.xs~89e49a0b5556f1d8: Delete: bdb/perl.DB_File/DB_File.xs BitKeeper/deleted/.del-DB_File_BS~290fad5dbbb87069: Delete: bdb/perl.DB_File/DB_File_BS BitKeeper/deleted/.del-MANIFEST~90ee581572bdd4ac: Delete: bdb/perl.DB_File/MANIFEST BitKeeper/deleted/.del-Makefile.PL~ac0567bb5a377e38: Delete: bdb/perl.DB_File/Makefile.PL BitKeeper/deleted/.del-README~77e924a5a9bae6b3: Delete: bdb/perl.DB_File/README BitKeeper/deleted/.del-config.in~ab4c2792b86a810b: Delete: bdb/perl.DB_File/config.in BitKeeper/deleted/.del-dbinfo~461c43b30fab2cb: Delete: bdb/perl.DB_File/dbinfo BitKeeper/deleted/.del-dynixptx.pl~50dcddfae25d17e9: Delete: bdb/perl.DB_File/hints/dynixptx.pl BitKeeper/deleted/.del-typemap~55cffb3288a9e587: Delete: bdb/perl.DB_File/typemap BitKeeper/deleted/.del-version.c~a4df0e646f8b3975: Delete: bdb/perl.DB_File/version.c BitKeeper/deleted/.del-5.004_01~d6830d0082702af7: Delete: bdb/perl.DB_File/patches/5.004_01 BitKeeper/deleted/.del-5.004_02~78b082dc80c91031: Delete: bdb/perl.DB_File/patches/5.004_02 BitKeeper/deleted/.del-5.004~4411ec2e3c9e008b: Delete: bdb/perl.DB_File/patches/5.004 BitKeeper/deleted/.del-sco.pl~1e795fe14fe4dcfe: Delete: bdb/perl.DB_File/hints/sco.pl BitKeeper/deleted/.del-5.004_03~33f274648b160d95: Delete: bdb/perl.DB_File/patches/5.004_03 BitKeeper/deleted/.del-5.004_04~8f3d1b3cf18bb20a: Delete: bdb/perl.DB_File/patches/5.004_04 BitKeeper/deleted/.del-5.004_05~9c0f02e7331e142: Delete: bdb/perl.DB_File/patches/5.004_05 BitKeeper/deleted/.del-5.005~c2108cb2e3c8d951: Delete: bdb/perl.DB_File/patches/5.005 BitKeeper/deleted/.del-5.005_01~3b45e9673afc4cfa: Delete: bdb/perl.DB_File/patches/5.005_01 BitKeeper/deleted/.del-5.005_02~9fe5766bb02a4522: Delete: bdb/perl.DB_File/patches/5.005_02 BitKeeper/deleted/.del-5.005_03~ffa1c38c19ae72ea: Delete: bdb/perl.DB_File/patches/5.005_03 BitKeeper/deleted/.del-5.6.0~373be3a5ce47be85: Delete: bdb/perl.DB_File/patches/5.6.0 BitKeeper/deleted/.del-db-btree.t~3231595a1c241eb3: Delete: bdb/perl.DB_File/t/db-btree.t BitKeeper/deleted/.del-db-hash.t~7c4ad0c795c7fad2: Delete: bdb/perl.DB_File/t/db-hash.t BitKeeper/deleted/.del-db-recno.t~6c2d3d80b9ba4a50: Delete: bdb/perl.DB_File/t/db-recno.t BitKeeper/deleted/.del-db_server.sed~cdb00ebcd48a64e2: Delete: bdb/rpc_server/db_server.sed BitKeeper/deleted/.del-db_server_proc.c~d46c8f409c3747f4: Delete: bdb/rpc_server/db_server_proc.c BitKeeper/deleted/.del-db_server_svc.sed~3f5e59f334fa4607: Delete: bdb/rpc_server/db_server_svc.sed BitKeeper/deleted/.del-db_server_util.c~a809f3a4629acda: Delete: bdb/rpc_server/db_server_util.c BitKeeper/deleted/.del-log.tcl~ff1b41f1355b97d7: Delete: bdb/test/log.tcl BitKeeper/deleted/.del-mpool.tcl~b0df4dc1b04db26c: Delete: bdb/test/mpool.tcl BitKeeper/deleted/.del-mutex.tcl~52fd5c73a150565: Delete: bdb/test/mutex.tcl BitKeeper/deleted/.del-txn.tcl~c4ff071550b5446e: Delete: bdb/test/txn.tcl BitKeeper/deleted/.del-README~e800a12a5392010a: Delete: bdb/test/upgrade/README BitKeeper/deleted/.del-pack-2.6.6.pl~89d5076d758d3e98: Delete: bdb/test/upgrade/generate-2.X/pack-2.6.6.pl BitKeeper/deleted/.del-test-2.6.patch~4a52dc83d447547b: Delete: bdb/test/upgrade/generate-2.X/test-2.6.patch
1015 lines
26 KiB
C
1015 lines
26 KiB
C
/*-
|
|
* See the file LICENSE for redistribution information.
|
|
*
|
|
* Copyright (c) 1996-2002
|
|
* Sleepycat Software. All rights reserved.
|
|
*/
|
|
#include "db_config.h"
|
|
|
|
#ifndef lint
|
|
static const char revid[] = "$Id: mp_fopen.c,v 11.90 2002/08/26 15:22:01 bostic Exp $";
|
|
#endif /* not lint */
|
|
|
|
#ifndef NO_SYSTEM_INCLUDES
|
|
#include <sys/types.h>
|
|
|
|
#include <string.h>
|
|
#endif
|
|
|
|
#include "db_int.h"
|
|
#include "dbinc/db_shash.h"
|
|
#include "dbinc/mp.h"
|
|
|
|
static int __memp_fclose __P((DB_MPOOLFILE *, u_int32_t));
|
|
static int __memp_fopen __P((DB_MPOOLFILE *,
|
|
const char *, u_int32_t, int, size_t));
|
|
static void __memp_get_fileid __P((DB_MPOOLFILE *, u_int8_t *));
|
|
static void __memp_last_pgno __P((DB_MPOOLFILE *, db_pgno_t *));
|
|
static void __memp_refcnt __P((DB_MPOOLFILE *, db_pgno_t *));
|
|
static int __memp_set_clear_len __P((DB_MPOOLFILE *, u_int32_t));
|
|
static int __memp_set_fileid __P((DB_MPOOLFILE *, u_int8_t *));
|
|
static int __memp_set_ftype __P((DB_MPOOLFILE *, int));
|
|
static int __memp_set_lsn_offset __P((DB_MPOOLFILE *, int32_t));
|
|
static int __memp_set_pgcookie __P((DB_MPOOLFILE *, DBT *));
|
|
static int __memp_set_priority __P((DB_MPOOLFILE *, DB_CACHE_PRIORITY));
|
|
static void __memp_set_unlink __P((DB_MPOOLFILE *, int));
|
|
|
|
/* Initialization methods cannot be called after open is called. */
|
|
#define MPF_ILLEGAL_AFTER_OPEN(dbmfp, name) \
|
|
if (F_ISSET(dbmfp, MP_OPEN_CALLED)) \
|
|
return (__db_mi_open((dbmfp)->dbmp->dbenv, name, 1));
|
|
|
|
/*
|
|
* __memp_fcreate --
|
|
* Create a DB_MPOOLFILE handle.
|
|
*
|
|
* PUBLIC: int __memp_fcreate __P((DB_ENV *, DB_MPOOLFILE **, u_int32_t));
|
|
*/
|
|
int
|
|
__memp_fcreate(dbenv, retp, flags)
|
|
DB_ENV *dbenv;
|
|
DB_MPOOLFILE **retp;
|
|
u_int32_t flags;
|
|
{
|
|
DB_MPOOL *dbmp;
|
|
DB_MPOOLFILE *dbmfp;
|
|
int ret;
|
|
|
|
PANIC_CHECK(dbenv);
|
|
ENV_REQUIRES_CONFIG(dbenv,
|
|
dbenv->mp_handle, "memp_fcreate", DB_INIT_MPOOL);
|
|
|
|
dbmp = dbenv->mp_handle;
|
|
|
|
/* Validate arguments. */
|
|
if ((ret = __db_fchk(dbenv, "memp_fcreate", flags, 0)) != 0)
|
|
return (ret);
|
|
|
|
/* Allocate and initialize the per-process structure. */
|
|
if ((ret = __os_calloc(dbenv, 1, sizeof(DB_MPOOLFILE), &dbmfp)) != 0)
|
|
return (ret);
|
|
if ((ret = __os_calloc(dbenv, 1, sizeof(DB_FH), &dbmfp->fhp)) != 0)
|
|
goto err;
|
|
|
|
/* Allocate and initialize a mutex if necessary. */
|
|
if (F_ISSET(dbenv, DB_ENV_THREAD) &&
|
|
(ret = __db_mutex_setup(dbenv, dbmp->reginfo, &dbmfp->mutexp,
|
|
MUTEX_ALLOC | MUTEX_THREAD)) != 0)
|
|
goto err;
|
|
|
|
dbmfp->ref = 1;
|
|
dbmfp->lsn_offset = -1;
|
|
dbmfp->dbmp = dbmp;
|
|
dbmfp->mfp = INVALID_ROFF;
|
|
|
|
dbmfp->close = __memp_fclose;
|
|
dbmfp->get = __memp_fget;
|
|
dbmfp->get_fileid = __memp_get_fileid;
|
|
dbmfp->last_pgno = __memp_last_pgno;
|
|
dbmfp->open = __memp_fopen;
|
|
dbmfp->put = __memp_fput;
|
|
dbmfp->refcnt = __memp_refcnt;
|
|
dbmfp->set = __memp_fset;
|
|
dbmfp->set_clear_len = __memp_set_clear_len;
|
|
dbmfp->set_fileid = __memp_set_fileid;
|
|
dbmfp->set_ftype = __memp_set_ftype;
|
|
dbmfp->set_lsn_offset = __memp_set_lsn_offset;
|
|
dbmfp->set_pgcookie = __memp_set_pgcookie;
|
|
dbmfp->set_priority = __memp_set_priority;
|
|
dbmfp->set_unlink = __memp_set_unlink;
|
|
dbmfp->sync = __memp_fsync;
|
|
|
|
*retp = dbmfp;
|
|
return (0);
|
|
|
|
err: if (dbmfp != NULL) {
|
|
if (dbmfp->fhp != NULL)
|
|
(void)__os_free(dbenv, dbmfp->fhp);
|
|
(void)__os_free(dbenv, dbmfp);
|
|
}
|
|
return (ret);
|
|
}
|
|
|
|
/*
|
|
* __memp_set_clear_len --
|
|
* Set the clear length.
|
|
*/
|
|
static int
|
|
__memp_set_clear_len(dbmfp, clear_len)
|
|
DB_MPOOLFILE *dbmfp;
|
|
u_int32_t clear_len;
|
|
{
|
|
MPF_ILLEGAL_AFTER_OPEN(dbmfp, "set_clear_len");
|
|
|
|
dbmfp->clear_len = clear_len;
|
|
return (0);
|
|
}
|
|
|
|
/*
|
|
* __memp_set_fileid --
|
|
* Set the file ID.
|
|
*/
|
|
static int
|
|
__memp_set_fileid(dbmfp, fileid)
|
|
DB_MPOOLFILE *dbmfp;
|
|
u_int8_t *fileid;
|
|
{
|
|
MPF_ILLEGAL_AFTER_OPEN(dbmfp, "set_fileid");
|
|
|
|
/*
|
|
* XXX
|
|
* This is dangerous -- we're saving the caller's pointer instead
|
|
* of allocating memory and copying the contents.
|
|
*/
|
|
dbmfp->fileid = fileid;
|
|
return (0);
|
|
}
|
|
|
|
/*
|
|
* __memp_set_ftype --
|
|
* Set the file type (as registered).
|
|
*/
|
|
static int
|
|
__memp_set_ftype(dbmfp, ftype)
|
|
DB_MPOOLFILE *dbmfp;
|
|
int ftype;
|
|
{
|
|
MPF_ILLEGAL_AFTER_OPEN(dbmfp, "set_ftype");
|
|
|
|
dbmfp->ftype = ftype;
|
|
return (0);
|
|
}
|
|
|
|
/*
|
|
* __memp_set_lsn_offset --
|
|
* Set the page's LSN offset.
|
|
*/
|
|
static int
|
|
__memp_set_lsn_offset(dbmfp, lsn_offset)
|
|
DB_MPOOLFILE *dbmfp;
|
|
int32_t lsn_offset;
|
|
{
|
|
MPF_ILLEGAL_AFTER_OPEN(dbmfp, "set_lsn_offset");
|
|
|
|
dbmfp->lsn_offset = lsn_offset;
|
|
return (0);
|
|
}
|
|
|
|
/*
|
|
* __memp_set_pgcookie --
|
|
* Set the pgin/pgout cookie.
|
|
*/
|
|
static int
|
|
__memp_set_pgcookie(dbmfp, pgcookie)
|
|
DB_MPOOLFILE *dbmfp;
|
|
DBT *pgcookie;
|
|
{
|
|
MPF_ILLEGAL_AFTER_OPEN(dbmfp, "set_pgcookie");
|
|
|
|
dbmfp->pgcookie = pgcookie;
|
|
return (0);
|
|
}
|
|
|
|
/*
|
|
* __memp_set_priority --
|
|
* Set the cache priority for pages from this file.
|
|
*/
|
|
static int
|
|
__memp_set_priority(dbmfp, priority)
|
|
DB_MPOOLFILE *dbmfp;
|
|
DB_CACHE_PRIORITY priority;
|
|
{
|
|
switch (priority) {
|
|
case DB_PRIORITY_VERY_LOW:
|
|
dbmfp->mfp->priority = MPOOL_PRI_VERY_LOW;
|
|
break;
|
|
case DB_PRIORITY_LOW:
|
|
dbmfp->mfp->priority = MPOOL_PRI_LOW;
|
|
break;
|
|
case DB_PRIORITY_DEFAULT:
|
|
dbmfp->mfp->priority = MPOOL_PRI_DEFAULT;
|
|
break;
|
|
case DB_PRIORITY_HIGH:
|
|
dbmfp->mfp->priority = MPOOL_PRI_HIGH;
|
|
break;
|
|
case DB_PRIORITY_VERY_HIGH:
|
|
dbmfp->mfp->priority = MPOOL_PRI_VERY_HIGH;
|
|
break;
|
|
default:
|
|
__db_err(dbmfp->dbmp->dbenv,
|
|
"Unknown priority value: %d", priority);
|
|
return (EINVAL);
|
|
}
|
|
|
|
return (0);
|
|
}
|
|
|
|
/*
|
|
* __memp_fopen --
|
|
* Open a backing file for the memory pool.
|
|
*/
|
|
static int
|
|
__memp_fopen(dbmfp, path, flags, mode, pagesize)
|
|
DB_MPOOLFILE *dbmfp;
|
|
const char *path;
|
|
u_int32_t flags;
|
|
int mode;
|
|
size_t pagesize;
|
|
{
|
|
DB_ENV *dbenv;
|
|
DB_MPOOL *dbmp;
|
|
int ret;
|
|
|
|
dbmp = dbmfp->dbmp;
|
|
dbenv = dbmp->dbenv;
|
|
|
|
PANIC_CHECK(dbenv);
|
|
|
|
/* Validate arguments. */
|
|
if ((ret = __db_fchk(dbenv, "memp_fopen", flags,
|
|
DB_CREATE | DB_DIRECT | DB_EXTENT |
|
|
DB_NOMMAP | DB_ODDFILESIZE | DB_RDONLY | DB_TRUNCATE)) != 0)
|
|
return (ret);
|
|
|
|
/*
|
|
* Require a non-zero, power-of-two pagesize, smaller than the
|
|
* clear length.
|
|
*/
|
|
if (pagesize == 0 || !POWER_OF_TWO(pagesize)) {
|
|
__db_err(dbenv,
|
|
"memp_fopen: page sizes must be a power-of-2");
|
|
return (EINVAL);
|
|
}
|
|
if (dbmfp->clear_len > pagesize) {
|
|
__db_err(dbenv,
|
|
"memp_fopen: clear length larger than page size");
|
|
return (EINVAL);
|
|
}
|
|
|
|
/* Read-only checks, and local flag. */
|
|
if (LF_ISSET(DB_RDONLY) && path == NULL) {
|
|
__db_err(dbenv,
|
|
"memp_fopen: temporary files can't be readonly");
|
|
return (EINVAL);
|
|
}
|
|
|
|
return (__memp_fopen_int(dbmfp, NULL, path, flags, mode, pagesize));
|
|
}
|
|
|
|
/*
|
|
* __memp_fopen_int --
|
|
* Open a backing file for the memory pool; internal version.
|
|
*
|
|
* PUBLIC: int __memp_fopen_int __P((DB_MPOOLFILE *,
|
|
* PUBLIC: MPOOLFILE *, const char *, u_int32_t, int, size_t));
|
|
*/
|
|
int
|
|
__memp_fopen_int(dbmfp, mfp, path, flags, mode, pagesize)
|
|
DB_MPOOLFILE *dbmfp;
|
|
MPOOLFILE *mfp;
|
|
const char *path;
|
|
u_int32_t flags;
|
|
int mode;
|
|
size_t pagesize;
|
|
{
|
|
DB_ENV *dbenv;
|
|
DB_MPOOL *dbmp;
|
|
MPOOL *mp;
|
|
db_pgno_t last_pgno;
|
|
size_t maxmap;
|
|
u_int32_t mbytes, bytes, oflags;
|
|
int mfp_alloc, ret;
|
|
u_int8_t idbuf[DB_FILE_ID_LEN];
|
|
char *rpath;
|
|
void *p;
|
|
|
|
dbmp = dbmfp->dbmp;
|
|
dbenv = dbmp->dbenv;
|
|
mp = dbmp->reginfo[0].primary;
|
|
mfp_alloc = ret = 0;
|
|
rpath = NULL;
|
|
|
|
/*
|
|
* Set the page size so os_open can decide whether to turn buffering
|
|
* off if the DB_DIRECT_DB flag is set.
|
|
*/
|
|
dbmfp->fhp->pagesize = (u_int32_t)pagesize;
|
|
|
|
/*
|
|
* If it's a temporary file, delay the open until we actually need
|
|
* to write the file, and we know we can't join any existing files.
|
|
*/
|
|
if (path == NULL)
|
|
goto alloc;
|
|
|
|
/*
|
|
* Get the real name for this file and open it. If it's a Queue extent
|
|
* file, it may not exist, and that's OK.
|
|
*/
|
|
oflags = 0;
|
|
if (LF_ISSET(DB_CREATE))
|
|
oflags |= DB_OSO_CREATE;
|
|
if (LF_ISSET(DB_DIRECT))
|
|
oflags |= DB_OSO_DIRECT;
|
|
if (LF_ISSET(DB_RDONLY)) {
|
|
F_SET(dbmfp, MP_READONLY);
|
|
oflags |= DB_OSO_RDONLY;
|
|
}
|
|
if ((ret =
|
|
__db_appname(dbenv, DB_APP_DATA, path, 0, NULL, &rpath)) != 0)
|
|
goto err;
|
|
if ((ret = __os_open(dbenv, rpath, oflags, mode, dbmfp->fhp)) != 0) {
|
|
if (!LF_ISSET(DB_EXTENT))
|
|
__db_err(dbenv, "%s: %s", rpath, db_strerror(ret));
|
|
goto err;
|
|
}
|
|
|
|
/*
|
|
* Get the file id if we weren't given one. Generated file id's
|
|
* don't use timestamps, otherwise there'd be no chance of any
|
|
* other process joining the party.
|
|
*/
|
|
if (dbmfp->fileid == NULL) {
|
|
if ((ret = __os_fileid(dbenv, rpath, 0, idbuf)) != 0)
|
|
goto err;
|
|
dbmfp->fileid = idbuf;
|
|
}
|
|
|
|
/*
|
|
* If our caller knows what mfp we're using, increment the ref count,
|
|
* no need to search.
|
|
*
|
|
* We don't need to acquire a lock other than the mfp itself, because
|
|
* we know there's another reference and it's not going away.
|
|
*/
|
|
if (mfp != NULL) {
|
|
MUTEX_LOCK(dbenv, &mfp->mutex);
|
|
++mfp->mpf_cnt;
|
|
MUTEX_UNLOCK(dbenv, &mfp->mutex);
|
|
goto check_map;
|
|
}
|
|
|
|
/*
|
|
* If not creating a temporary file, walk the list of MPOOLFILE's,
|
|
* looking for a matching file. Files backed by temporary files
|
|
* or previously removed files can't match.
|
|
*
|
|
* DB_TRUNCATE support.
|
|
*
|
|
* The fileID is a filesystem unique number (e.g., a UNIX dev/inode
|
|
* pair) plus a timestamp. If files are removed and created in less
|
|
* than a second, the fileID can be repeated. The problem with
|
|
* repetition happens when the file that previously had the fileID
|
|
* value still has pages in the pool, since we don't want to use them
|
|
* to satisfy requests for the new file.
|
|
*
|
|
* Because the DB_TRUNCATE flag reuses the dev/inode pair, repeated
|
|
* opens with that flag set guarantees matching fileIDs when the
|
|
* machine can open a file and then re-open with truncate within a
|
|
* second. For this reason, we pass that flag down, and, if we find
|
|
* a matching entry, we ensure that it's never found again, and we
|
|
* create a new entry for the current request.
|
|
*/
|
|
R_LOCK(dbenv, dbmp->reginfo);
|
|
for (mfp = SH_TAILQ_FIRST(&mp->mpfq, __mpoolfile);
|
|
mfp != NULL; mfp = SH_TAILQ_NEXT(mfp, q, __mpoolfile)) {
|
|
/* Skip dead files and temporary files. */
|
|
if (F_ISSET(mfp, MP_DEADFILE | MP_TEMP))
|
|
continue;
|
|
|
|
/* Skip non-matching files. */
|
|
if (memcmp(dbmfp->fileid, R_ADDR(dbmp->reginfo,
|
|
mfp->fileid_off), DB_FILE_ID_LEN) != 0)
|
|
continue;
|
|
|
|
/*
|
|
* If the file is being truncated, remove it from the system
|
|
* and create a new entry.
|
|
*
|
|
* !!!
|
|
* We should be able to set mfp to NULL and break out of the
|
|
* loop, but I like the idea of checking all the entries.
|
|
*/
|
|
if (LF_ISSET(DB_TRUNCATE)) {
|
|
MUTEX_LOCK(dbenv, &mfp->mutex);
|
|
MPOOLFILE_IGNORE(mfp);
|
|
MUTEX_UNLOCK(dbenv, &mfp->mutex);
|
|
continue;
|
|
}
|
|
|
|
/*
|
|
* Some things about a file cannot be changed: the clear length,
|
|
* page size, or lSN location.
|
|
*
|
|
* The file type can change if the application's pre- and post-
|
|
* processing needs change. For example, an application that
|
|
* created a hash subdatabase in a database that was previously
|
|
* all btree.
|
|
*
|
|
* XXX
|
|
* We do not check to see if the pgcookie information changed,
|
|
* or update it if it is, this might be a bug.
|
|
*/
|
|
if (dbmfp->clear_len != mfp->clear_len ||
|
|
pagesize != mfp->stat.st_pagesize ||
|
|
dbmfp->lsn_offset != mfp->lsn_off) {
|
|
__db_err(dbenv,
|
|
"%s: clear length, page size or LSN location changed",
|
|
path);
|
|
R_UNLOCK(dbenv, dbmp->reginfo);
|
|
ret = EINVAL;
|
|
goto err;
|
|
}
|
|
|
|
if (dbmfp->ftype != 0)
|
|
mfp->ftype = dbmfp->ftype;
|
|
|
|
MUTEX_LOCK(dbenv, &mfp->mutex);
|
|
++mfp->mpf_cnt;
|
|
MUTEX_UNLOCK(dbenv, &mfp->mutex);
|
|
break;
|
|
}
|
|
R_UNLOCK(dbenv, dbmp->reginfo);
|
|
|
|
if (mfp != NULL)
|
|
goto check_map;
|
|
|
|
alloc: /* Allocate and initialize a new MPOOLFILE. */
|
|
if ((ret = __memp_alloc(
|
|
dbmp, dbmp->reginfo, NULL, sizeof(MPOOLFILE), NULL, &mfp)) != 0)
|
|
goto err;
|
|
mfp_alloc = 1;
|
|
memset(mfp, 0, sizeof(MPOOLFILE));
|
|
mfp->mpf_cnt = 1;
|
|
mfp->ftype = dbmfp->ftype;
|
|
mfp->stat.st_pagesize = pagesize;
|
|
mfp->lsn_off = dbmfp->lsn_offset;
|
|
mfp->clear_len = dbmfp->clear_len;
|
|
|
|
if (LF_ISSET(DB_DIRECT))
|
|
F_SET(mfp, MP_DIRECT);
|
|
if (LF_ISSET(DB_EXTENT))
|
|
F_SET(mfp, MP_EXTENT);
|
|
|
|
if (path == NULL)
|
|
F_SET(mfp, MP_TEMP);
|
|
else {
|
|
/*
|
|
* Don't permit files that aren't a multiple of the pagesize,
|
|
* and find the number of the last page in the file, all the
|
|
* time being careful not to overflow 32 bits.
|
|
*
|
|
* !!!
|
|
* We can't use off_t's here, or in any code in the mainline
|
|
* library for that matter. (We have to use them in the os
|
|
* stubs, of course, as there are system calls that take them
|
|
* as arguments.) The reason is that some customers build in
|
|
* environments where an off_t is 32-bits, but still run where
|
|
* offsets are 64-bits, and they pay us a lot of money.
|
|
*/
|
|
if ((ret = __os_ioinfo(
|
|
dbenv, rpath, dbmfp->fhp, &mbytes, &bytes, NULL)) != 0) {
|
|
__db_err(dbenv, "%s: %s", rpath, db_strerror(ret));
|
|
goto err;
|
|
}
|
|
|
|
/*
|
|
* During verify or recovery, we might have to cope with a
|
|
* truncated file; if the file size is not a multiple of the
|
|
* page size, round down to a page, we'll take care of the
|
|
* partial page outside the mpool system.
|
|
*/
|
|
if (bytes % pagesize != 0) {
|
|
if (LF_ISSET(DB_ODDFILESIZE))
|
|
bytes -= (u_int32_t)(bytes % pagesize);
|
|
else {
|
|
__db_err(dbenv,
|
|
"%s: file size not a multiple of the pagesize", rpath);
|
|
ret = EINVAL;
|
|
goto err;
|
|
}
|
|
}
|
|
|
|
/*
|
|
* If the user specifies DB_MPOOL_LAST or DB_MPOOL_NEW on a
|
|
* page get, we have to increment the last page in the file.
|
|
* Figure it out and save it away.
|
|
*
|
|
* Note correction: page numbers are zero-based, not 1-based.
|
|
*/
|
|
last_pgno = (db_pgno_t)(mbytes * (MEGABYTE / pagesize));
|
|
last_pgno += (db_pgno_t)(bytes / pagesize);
|
|
if (last_pgno != 0)
|
|
--last_pgno;
|
|
mfp->orig_last_pgno = mfp->last_pgno = last_pgno;
|
|
|
|
/* Copy the file path into shared memory. */
|
|
if ((ret = __memp_alloc(dbmp, dbmp->reginfo,
|
|
NULL, strlen(path) + 1, &mfp->path_off, &p)) != 0)
|
|
goto err;
|
|
memcpy(p, path, strlen(path) + 1);
|
|
|
|
/* Copy the file identification string into shared memory. */
|
|
if ((ret = __memp_alloc(dbmp, dbmp->reginfo,
|
|
NULL, DB_FILE_ID_LEN, &mfp->fileid_off, &p)) != 0)
|
|
goto err;
|
|
memcpy(p, dbmfp->fileid, DB_FILE_ID_LEN);
|
|
}
|
|
|
|
/* Copy the page cookie into shared memory. */
|
|
if (dbmfp->pgcookie == NULL || dbmfp->pgcookie->size == 0) {
|
|
mfp->pgcookie_len = 0;
|
|
mfp->pgcookie_off = 0;
|
|
} else {
|
|
if ((ret = __memp_alloc(dbmp, dbmp->reginfo,
|
|
NULL, dbmfp->pgcookie->size, &mfp->pgcookie_off, &p)) != 0)
|
|
goto err;
|
|
memcpy(p, dbmfp->pgcookie->data, dbmfp->pgcookie->size);
|
|
mfp->pgcookie_len = dbmfp->pgcookie->size;
|
|
}
|
|
|
|
/*
|
|
* Prepend the MPOOLFILE to the list of MPOOLFILE's.
|
|
*/
|
|
R_LOCK(dbenv, dbmp->reginfo);
|
|
ret = __db_mutex_setup(dbenv, dbmp->reginfo, &mfp->mutex,
|
|
MUTEX_NO_RLOCK);
|
|
if (ret == 0)
|
|
SH_TAILQ_INSERT_HEAD(&mp->mpfq, mfp, q, __mpoolfile);
|
|
R_UNLOCK(dbenv, dbmp->reginfo);
|
|
if (ret != 0)
|
|
goto err;
|
|
|
|
check_map:
|
|
/*
|
|
* If a file:
|
|
* + isn't temporary
|
|
* + is read-only
|
|
* + doesn't require any pgin/pgout support
|
|
* + the DB_NOMMAP flag wasn't set (in either the file open or
|
|
* the environment in which it was opened)
|
|
* + and is less than mp_mmapsize bytes in size
|
|
*
|
|
* 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.
|
|
*
|
|
* 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. */
|
|
if (F_ISSET(mfp, MP_CAN_MMAP)) {
|
|
if (path == NULL)
|
|
F_CLR(mfp, MP_CAN_MMAP);
|
|
if (!F_ISSET(dbmfp, MP_READONLY))
|
|
F_CLR(mfp, MP_CAN_MMAP);
|
|
if (dbmfp->ftype != 0)
|
|
F_CLR(mfp, MP_CAN_MMAP);
|
|
if (LF_ISSET(DB_NOMMAP) || F_ISSET(dbenv, DB_ENV_NOMMAP))
|
|
F_CLR(mfp, MP_CAN_MMAP);
|
|
maxmap = dbenv->mp_mmapsize == 0 ?
|
|
DB_MAXMMAPSIZE : dbenv->mp_mmapsize;
|
|
if (mbytes > maxmap / MEGABYTE ||
|
|
(mbytes == maxmap / MEGABYTE && bytes >= maxmap % MEGABYTE))
|
|
F_CLR(mfp, MP_CAN_MMAP);
|
|
|
|
dbmfp->addr = NULL;
|
|
if (F_ISSET(mfp, MP_CAN_MMAP)) {
|
|
dbmfp->len = (size_t)mbytes * MEGABYTE + bytes;
|
|
if (__os_mapfile(dbenv, rpath,
|
|
dbmfp->fhp, dbmfp->len, 1, &dbmfp->addr) != 0) {
|
|
dbmfp->addr = NULL;
|
|
F_CLR(mfp, MP_CAN_MMAP);
|
|
}
|
|
}
|
|
}
|
|
|
|
dbmfp->mfp = mfp;
|
|
|
|
F_SET(dbmfp, MP_OPEN_CALLED);
|
|
|
|
/* Add the file to the process' list of DB_MPOOLFILEs. */
|
|
MUTEX_THREAD_LOCK(dbenv, dbmp->mutexp);
|
|
TAILQ_INSERT_TAIL(&dbmp->dbmfq, dbmfp, q);
|
|
MUTEX_THREAD_UNLOCK(dbenv, dbmp->mutexp);
|
|
|
|
if (0) {
|
|
err: if (F_ISSET(dbmfp->fhp, DB_FH_VALID))
|
|
(void)__os_closehandle(dbenv, dbmfp->fhp);
|
|
|
|
if (mfp_alloc) {
|
|
R_LOCK(dbenv, dbmp->reginfo);
|
|
if (mfp->path_off != 0)
|
|
__db_shalloc_free(dbmp->reginfo[0].addr,
|
|
R_ADDR(dbmp->reginfo, mfp->path_off));
|
|
if (mfp->fileid_off != 0)
|
|
__db_shalloc_free(dbmp->reginfo[0].addr,
|
|
R_ADDR(dbmp->reginfo, mfp->fileid_off));
|
|
__db_shalloc_free(dbmp->reginfo[0].addr, mfp);
|
|
R_UNLOCK(dbenv, dbmp->reginfo);
|
|
}
|
|
|
|
}
|
|
if (rpath != NULL)
|
|
__os_free(dbenv, rpath);
|
|
return (ret);
|
|
}
|
|
|
|
/*
|
|
* __memp_get_fileid --
|
|
* Return the file ID.
|
|
*
|
|
* XXX
|
|
* Undocumented interface: DB private.
|
|
*/
|
|
static void
|
|
__memp_get_fileid(dbmfp, fidp)
|
|
DB_MPOOLFILE *dbmfp;
|
|
u_int8_t *fidp;
|
|
{
|
|
/*
|
|
* No lock needed -- we're using the handle, it had better not
|
|
* be going away.
|
|
*
|
|
* !!!
|
|
* Get the fileID out of the region, not out of the DB_MPOOLFILE
|
|
* structure because the DB_MPOOLFILE reference is possibly short
|
|
* lived, and isn't to be trusted.
|
|
*/
|
|
memcpy(fidp, R_ADDR(
|
|
dbmfp->dbmp->reginfo, dbmfp->mfp->fileid_off), DB_FILE_ID_LEN);
|
|
}
|
|
|
|
/*
|
|
* __memp_last_pgno --
|
|
* Return the page number of the last page in the file.
|
|
*
|
|
* XXX
|
|
* Undocumented interface: DB private.
|
|
*/
|
|
static void
|
|
__memp_last_pgno(dbmfp, pgnoaddr)
|
|
DB_MPOOLFILE *dbmfp;
|
|
db_pgno_t *pgnoaddr;
|
|
{
|
|
DB_ENV *dbenv;
|
|
DB_MPOOL *dbmp;
|
|
|
|
dbmp = dbmfp->dbmp;
|
|
dbenv = dbmp->dbenv;
|
|
|
|
R_LOCK(dbenv, dbmp->reginfo);
|
|
*pgnoaddr = dbmfp->mfp->last_pgno;
|
|
R_UNLOCK(dbenv, dbmp->reginfo);
|
|
}
|
|
|
|
/*
|
|
* __memp_refcnt --
|
|
* Return the current reference count.
|
|
*
|
|
* XXX
|
|
* Undocumented interface: DB private.
|
|
*/
|
|
static void
|
|
__memp_refcnt(dbmfp, cntp)
|
|
DB_MPOOLFILE *dbmfp;
|
|
db_pgno_t *cntp;
|
|
{
|
|
DB_ENV *dbenv;
|
|
|
|
dbenv = dbmfp->dbmp->dbenv;
|
|
|
|
MUTEX_LOCK(dbenv, &dbmfp->mfp->mutex);
|
|
*cntp = dbmfp->mfp->mpf_cnt;
|
|
MUTEX_UNLOCK(dbenv, &dbmfp->mfp->mutex);
|
|
}
|
|
|
|
/*
|
|
* __memp_set_unlink --
|
|
* Set unlink on last close flag.
|
|
*
|
|
* XXX
|
|
* Undocumented interface: DB private.
|
|
*/
|
|
static void
|
|
__memp_set_unlink(dbmpf, set)
|
|
DB_MPOOLFILE *dbmpf;
|
|
int set;
|
|
{
|
|
DB_ENV *dbenv;
|
|
|
|
dbenv = dbmpf->dbmp->dbenv;
|
|
|
|
MUTEX_LOCK(dbenv, &dbmpf->mfp->mutex);
|
|
if (set)
|
|
F_SET(dbmpf->mfp, MP_UNLINK);
|
|
else
|
|
F_CLR(dbmpf->mfp, MP_UNLINK);
|
|
MUTEX_UNLOCK(dbenv, &dbmpf->mfp->mutex);
|
|
}
|
|
|
|
/*
|
|
* memp_fclose --
|
|
* Close a backing file for the memory pool.
|
|
*/
|
|
static int
|
|
__memp_fclose(dbmfp, flags)
|
|
DB_MPOOLFILE *dbmfp;
|
|
u_int32_t flags;
|
|
{
|
|
DB_ENV *dbenv;
|
|
int ret, t_ret;
|
|
|
|
dbenv = dbmfp->dbmp->dbenv;
|
|
|
|
PANIC_CHECK(dbenv);
|
|
|
|
/*
|
|
* XXX
|
|
* DB_MPOOL_DISCARD: Undocumented flag: DB private.
|
|
*/
|
|
ret = __db_fchk(dbenv, "DB_MPOOLFILE->close", flags, DB_MPOOL_DISCARD);
|
|
|
|
if ((t_ret = __memp_fclose_int(dbmfp, flags)) != 0 && ret == 0)
|
|
ret = t_ret;
|
|
|
|
return (ret);
|
|
}
|
|
|
|
/*
|
|
* __memp_fclose_int --
|
|
* Internal version of __memp_fclose.
|
|
*
|
|
* PUBLIC: int __memp_fclose_int __P((DB_MPOOLFILE *, u_int32_t));
|
|
*/
|
|
int
|
|
__memp_fclose_int(dbmfp, flags)
|
|
DB_MPOOLFILE *dbmfp;
|
|
u_int32_t flags;
|
|
{
|
|
DB_ENV *dbenv;
|
|
DB_MPOOL *dbmp;
|
|
MPOOLFILE *mfp;
|
|
char *rpath;
|
|
int deleted, ret, t_ret;
|
|
|
|
dbmp = dbmfp->dbmp;
|
|
dbenv = dbmp->dbenv;
|
|
ret = 0;
|
|
|
|
/*
|
|
* We have to reference count DB_MPOOLFILE structures as other threads
|
|
* in the process may be using them. Here's the problem:
|
|
*
|
|
* Thread A opens a database.
|
|
* Thread B uses thread A's DB_MPOOLFILE to write a buffer
|
|
* in order to free up memory in the mpool cache.
|
|
* Thread A closes the database while thread B is using the
|
|
* DB_MPOOLFILE structure.
|
|
*
|
|
* By opening all databases before creating any threads, and closing
|
|
* the databases after all the threads have exited, applications get
|
|
* better performance and avoid the problem path entirely.
|
|
*
|
|
* Regardless, holding the DB_MPOOLFILE to flush a dirty buffer is a
|
|
* short-term lock, even in worst case, since we better be the only
|
|
* thread of control using the DB_MPOOLFILE structure to read pages
|
|
* *into* the cache. Wait until we're the only reference holder and
|
|
* remove the DB_MPOOLFILE structure from the list, so nobody else can
|
|
* find it. We do this, rather than have the last reference holder
|
|
* (whoever that might be) discard the DB_MPOOLFILE structure, because
|
|
* we'd rather write error messages to the application in the close
|
|
* routine, not in the checkpoint/sync routine.
|
|
*
|
|
* !!!
|
|
* It's possible the DB_MPOOLFILE was never added to the DB_MPOOLFILE
|
|
* file list, check the DB_OPEN_CALLED flag to be sure.
|
|
*/
|
|
for (deleted = 0;;) {
|
|
MUTEX_THREAD_LOCK(dbenv, dbmp->mutexp);
|
|
if (dbmfp->ref == 1) {
|
|
if (F_ISSET(dbmfp, MP_OPEN_CALLED))
|
|
TAILQ_REMOVE(&dbmp->dbmfq, dbmfp, q);
|
|
deleted = 1;
|
|
}
|
|
MUTEX_THREAD_UNLOCK(dbenv, dbmp->mutexp);
|
|
|
|
if (deleted)
|
|
break;
|
|
__os_sleep(dbenv, 1, 0);
|
|
}
|
|
|
|
/* Complain if pinned blocks never returned. */
|
|
if (dbmfp->pinref != 0) {
|
|
__db_err(dbenv, "%s: close: %lu blocks left pinned",
|
|
__memp_fn(dbmfp), (u_long)dbmfp->pinref);
|
|
ret = __db_panic(dbenv, DB_RUNRECOVERY);
|
|
}
|
|
|
|
/* Discard any mmap information. */
|
|
if (dbmfp->addr != NULL &&
|
|
(ret = __os_unmapfile(dbenv, dbmfp->addr, dbmfp->len)) != 0)
|
|
__db_err(dbenv, "%s: %s", __memp_fn(dbmfp), db_strerror(ret));
|
|
|
|
/* Close the file; temporary files may not yet have been created. */
|
|
if (F_ISSET(dbmfp->fhp, DB_FH_VALID) &&
|
|
(t_ret = __os_closehandle(dbenv, dbmfp->fhp)) != 0) {
|
|
__db_err(dbenv, "%s: %s", __memp_fn(dbmfp), db_strerror(t_ret));
|
|
if (ret == 0)
|
|
ret = t_ret;
|
|
}
|
|
|
|
/* Discard the thread mutex. */
|
|
if (dbmfp->mutexp != NULL)
|
|
__db_mutex_free(dbenv, dbmp->reginfo, dbmfp->mutexp);
|
|
|
|
/*
|
|
* Discard our reference on the the underlying MPOOLFILE, and close
|
|
* it if it's no longer useful to anyone. It possible the open of
|
|
* the file never happened or wasn't successful, in which case, mpf
|
|
* will be NULL;
|
|
*/
|
|
if ((mfp = dbmfp->mfp) == NULL)
|
|
goto done;
|
|
|
|
/*
|
|
* If it's a temp file, all outstanding references belong to unflushed
|
|
* buffers. (A temp file can only be referenced by one DB_MPOOLFILE).
|
|
* We don't care about preserving any of those buffers, so mark the
|
|
* MPOOLFILE as dead so that even the dirty ones just get discarded
|
|
* when we try to flush them.
|
|
*/
|
|
deleted = 0;
|
|
MUTEX_LOCK(dbenv, &mfp->mutex);
|
|
if (--mfp->mpf_cnt == 0 || LF_ISSET(DB_MPOOL_DISCARD)) {
|
|
if (LF_ISSET(DB_MPOOL_DISCARD) ||
|
|
F_ISSET(mfp, MP_TEMP | MP_UNLINK))
|
|
MPOOLFILE_IGNORE(mfp);
|
|
if (F_ISSET(mfp, MP_UNLINK)) {
|
|
if ((t_ret = __db_appname(dbmp->dbenv,
|
|
DB_APP_DATA, R_ADDR(dbmp->reginfo,
|
|
mfp->path_off), 0, NULL, &rpath)) != 0 && ret == 0)
|
|
ret = t_ret;
|
|
if (t_ret == 0) {
|
|
if ((t_ret = __os_unlink(
|
|
dbmp->dbenv, rpath) != 0) && ret == 0)
|
|
ret = t_ret;
|
|
__os_free(dbenv, rpath);
|
|
}
|
|
}
|
|
if (mfp->block_cnt == 0) {
|
|
if ((t_ret =
|
|
__memp_mf_discard(dbmp, mfp)) != 0 && ret == 0)
|
|
ret = t_ret;
|
|
deleted = 1;
|
|
}
|
|
}
|
|
if (deleted == 0)
|
|
MUTEX_UNLOCK(dbenv, &mfp->mutex);
|
|
|
|
/* Discard the DB_MPOOLFILE structure. */
|
|
done: __os_free(dbenv, dbmfp->fhp);
|
|
__os_free(dbenv, dbmfp);
|
|
|
|
return (ret);
|
|
}
|
|
|
|
/*
|
|
* __memp_mf_discard --
|
|
* Discard an MPOOLFILE.
|
|
*
|
|
* PUBLIC: int __memp_mf_discard __P((DB_MPOOL *, MPOOLFILE *));
|
|
*/
|
|
int
|
|
__memp_mf_discard(dbmp, mfp)
|
|
DB_MPOOL *dbmp;
|
|
MPOOLFILE *mfp;
|
|
{
|
|
DB_ENV *dbenv;
|
|
DB_FH fh;
|
|
DB_MPOOL_STAT *sp;
|
|
MPOOL *mp;
|
|
char *rpath;
|
|
int ret;
|
|
|
|
dbenv = dbmp->dbenv;
|
|
mp = dbmp->reginfo[0].primary;
|
|
ret = 0;
|
|
|
|
/*
|
|
* Expects caller to be holding the MPOOLFILE mutex.
|
|
*
|
|
* When discarding a file, we have to flush writes from it to disk.
|
|
* The scenario is that dirty buffers from this file need to be
|
|
* flushed to satisfy a future checkpoint, but when the checkpoint
|
|
* calls mpool sync, the sync code won't know anything about them.
|
|
*/
|
|
if (!F_ISSET(mfp, MP_DEADFILE) &&
|
|
(ret = __db_appname(dbenv, DB_APP_DATA,
|
|
R_ADDR(dbmp->reginfo, mfp->path_off), 0, NULL, &rpath)) == 0) {
|
|
if ((ret = __os_open(dbenv, rpath, 0, 0, &fh)) == 0) {
|
|
ret = __os_fsync(dbenv, &fh);
|
|
(void)__os_closehandle(dbenv, &fh);
|
|
}
|
|
__os_free(dbenv, rpath);
|
|
}
|
|
|
|
/*
|
|
* We have to release the MPOOLFILE lock before acquiring the region
|
|
* lock so that we don't deadlock. Make sure nobody ever looks at
|
|
* this structure again.
|
|
*/
|
|
MPOOLFILE_IGNORE(mfp);
|
|
|
|
/* Discard the mutex we're holding. */
|
|
MUTEX_UNLOCK(dbenv, &mfp->mutex);
|
|
|
|
/* Delete from the list of MPOOLFILEs. */
|
|
R_LOCK(dbenv, dbmp->reginfo);
|
|
SH_TAILQ_REMOVE(&mp->mpfq, mfp, q, __mpoolfile);
|
|
|
|
/* Copy the statistics into the region. */
|
|
sp = &mp->stat;
|
|
sp->st_cache_hit += mfp->stat.st_cache_hit;
|
|
sp->st_cache_miss += mfp->stat.st_cache_miss;
|
|
sp->st_map += mfp->stat.st_map;
|
|
sp->st_page_create += mfp->stat.st_page_create;
|
|
sp->st_page_in += mfp->stat.st_page_in;
|
|
sp->st_page_out += mfp->stat.st_page_out;
|
|
|
|
/* Clear the mutex this MPOOLFILE recorded. */
|
|
__db_shlocks_clear(&mfp->mutex, dbmp->reginfo,
|
|
(REGMAINT *)R_ADDR(dbmp->reginfo, mp->maint_off));
|
|
|
|
/* Free the space. */
|
|
if (mfp->path_off != 0)
|
|
__db_shalloc_free(dbmp->reginfo[0].addr,
|
|
R_ADDR(dbmp->reginfo, mfp->path_off));
|
|
if (mfp->fileid_off != 0)
|
|
__db_shalloc_free(dbmp->reginfo[0].addr,
|
|
R_ADDR(dbmp->reginfo, mfp->fileid_off));
|
|
if (mfp->pgcookie_off != 0)
|
|
__db_shalloc_free(dbmp->reginfo[0].addr,
|
|
R_ADDR(dbmp->reginfo, mfp->pgcookie_off));
|
|
__db_shalloc_free(dbmp->reginfo[0].addr, mfp);
|
|
|
|
R_UNLOCK(dbenv, dbmp->reginfo);
|
|
|
|
return (ret);
|
|
}
|
|
|
|
/*
|
|
* __memp_fn --
|
|
* On errors we print whatever is available as the file name.
|
|
*
|
|
* PUBLIC: char * __memp_fn __P((DB_MPOOLFILE *));
|
|
*/
|
|
char *
|
|
__memp_fn(dbmfp)
|
|
DB_MPOOLFILE *dbmfp;
|
|
{
|
|
return (__memp_fns(dbmfp->dbmp, dbmfp->mfp));
|
|
}
|
|
|
|
/*
|
|
* __memp_fns --
|
|
* On errors we print whatever is available as the file name.
|
|
*
|
|
* PUBLIC: char * __memp_fns __P((DB_MPOOL *, MPOOLFILE *));
|
|
*
|
|
*/
|
|
char *
|
|
__memp_fns(dbmp, mfp)
|
|
DB_MPOOL *dbmp;
|
|
MPOOLFILE *mfp;
|
|
{
|
|
if (mfp->path_off == 0)
|
|
return ((char *)"temporary");
|
|
|
|
return ((char *)R_ADDR(dbmp->reginfo, mfp->path_off));
|
|
}
|