mariadb/storage/bdb/mp/mp_fset.c

114 lines
2.5 KiB
C
Raw Normal View History

2001-03-04 19:42:05 -05:00
/*-
* See the file LICENSE for redistribution information.
*
2005-12-05 10:27:46 -08:00
* Copyright (c) 1996-2005
2001-03-04 19:42:05 -05:00
* Sleepycat Software. All rights reserved.
2005-07-20 15:48:22 -07:00
*
2005-12-05 10:27:46 -08:00
* $Id: mp_fset.c,v 12.5 2005/10/07 20:21:33 ubell Exp $
2001-03-04 19:42:05 -05:00
*/
2005-07-20 15:48:22 -07:00
#include "db_config.h"
2001-03-04 19:42:05 -05:00
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#endif
#include "db_int.h"
2002-10-30 15:57:05 +04:00
#include "dbinc/db_shash.h"
2005-07-20 15:48:22 -07:00
#include "dbinc/log.h"
2002-10-30 15:57:05 +04:00
#include "dbinc/mp.h"
2001-03-04 19:42:05 -05:00
/*
2005-07-20 15:48:22 -07:00
* __memp_fset_pp --
* DB_MPOOLFILE->set pre/post processing.
2002-10-30 15:57:05 +04:00
*
2005-07-20 15:48:22 -07:00
* PUBLIC: int __memp_fset_pp __P((DB_MPOOLFILE *, void *, u_int32_t));
2001-03-04 19:42:05 -05:00
*/
int
2005-07-20 15:48:22 -07:00
__memp_fset_pp(dbmfp, pgaddr, flags)
2001-03-04 19:42:05 -05:00
DB_MPOOLFILE *dbmfp;
void *pgaddr;
u_int32_t flags;
{
DB_ENV *dbenv;
2005-12-05 10:27:46 -08:00
DB_THREAD_INFO *ip;
int ret;
2001-03-04 19:42:05 -05:00
2005-07-20 15:48:22 -07:00
dbenv = dbmfp->dbenv;
2001-03-04 19:42:05 -05:00
PANIC_CHECK(dbenv);
2005-07-20 15:48:22 -07:00
MPF_ILLEGAL_BEFORE_OPEN(dbmfp, "DB_MPOOLFILE->set");
2001-03-04 19:42:05 -05:00
/* Validate arguments. */
if (flags == 0)
return (__db_ferr(dbenv, "memp_fset", 1));
if ((ret = __db_fchk(dbenv, "memp_fset", flags,
2002-10-30 15:57:05 +04:00
DB_MPOOL_CLEAN | DB_MPOOL_DIRTY | DB_MPOOL_DISCARD)) != 0)
2001-03-04 19:42:05 -05:00
return (ret);
if ((ret = __db_fcchk(dbenv, "memp_fset",
flags, DB_MPOOL_CLEAN, DB_MPOOL_DIRTY)) != 0)
return (ret);
if (LF_ISSET(DB_MPOOL_DIRTY) && F_ISSET(dbmfp, MP_READONLY)) {
__db_err(dbenv, "%s: dirty flag set for readonly file page",
__memp_fn(dbmfp));
return (EACCES);
}
2005-12-05 10:27:46 -08:00
ENV_ENTER(dbenv, ip);
REPLICATION_WRAP(dbenv, (__memp_fset(dbmfp, pgaddr, flags)), ret);
ENV_LEAVE(dbenv, ip);
2005-07-20 15:48:22 -07:00
return (ret);
}
/*
* __memp_fset --
* DB_MPOOLFILE->set.
*
* PUBLIC: int __memp_fset __P((DB_MPOOLFILE *, void *, u_int32_t));
*/
int
__memp_fset(dbmfp, pgaddr, flags)
DB_MPOOLFILE *dbmfp;
void *pgaddr;
u_int32_t flags;
{
BH *bhp;
DB_ENV *dbenv;
DB_MPOOL *dbmp;
DB_MPOOL_HASH *hp;
MPOOL *c_mp;
u_int32_t n_cache;
dbenv = dbmfp->dbenv;
dbmp = dbenv->mp_handle;
2002-10-30 15:57:05 +04:00
/* Convert the page address to a buffer header and hash bucket. */
2001-03-04 19:42:05 -05:00
bhp = (BH *)((u_int8_t *)pgaddr - SSZA(BH, buf));
2002-10-30 15:57:05 +04:00
n_cache = NCACHE(dbmp->reginfo[0].primary, bhp->mf_offset, bhp->pgno);
c_mp = dbmp->reginfo[n_cache].primary;
hp = R_ADDR(&dbmp->reginfo[n_cache], c_mp->htab);
hp = &hp[NBUCKET(c_mp, bhp->mf_offset, bhp->pgno)];
2005-12-05 10:27:46 -08:00
MUTEX_LOCK(dbenv, hp->mtx_hash);
2002-10-30 15:57:05 +04:00
/* Set/clear the page bits. */
if (LF_ISSET(DB_MPOOL_CLEAN) &&
F_ISSET(bhp, BH_DIRTY) && !F_ISSET(bhp, BH_DIRTY_CREATE)) {
DB_ASSERT(hp->hash_page_dirty != 0);
--hp->hash_page_dirty;
2001-03-04 19:42:05 -05:00
F_CLR(bhp, BH_DIRTY);
}
if (LF_ISSET(DB_MPOOL_DIRTY) && !F_ISSET(bhp, BH_DIRTY)) {
2002-10-30 15:57:05 +04:00
++hp->hash_page_dirty;
2001-03-04 19:42:05 -05:00
F_SET(bhp, BH_DIRTY);
}
if (LF_ISSET(DB_MPOOL_DISCARD))
F_SET(bhp, BH_DISCARD);
2005-12-05 10:27:46 -08:00
MUTEX_UNLOCK(dbenv, hp->mtx_hash);
2001-03-04 19:42:05 -05:00
return (0);
}