1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1996, 1997, 1998, 1999
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
static const char sccsid[] = "@(#)mp_fset.c 11.1 (Sleepycat) 7/25/99";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
#include <errno.h>
#endif
#include "db_int.h"
#include "db_shash.h"
#include "mp.h"
/*
* CDB_memp_fset --
* Mpool page set-flag routine.
*/
int
CDB_memp_fset(dbmfp, pgaddr, flags)
DB_MPOOLFILE *dbmfp;
void *pgaddr;
u_int32_t flags;
{
BH *bhp;
DB_ENV *dbenv;
DB_MPOOL *dbmp;
MCACHE *mc;
MPOOL *mp;
int ret;
dbmp = dbmfp->dbmp;
dbenv = dbmp->dbenv;
mp = dbmp->reginfo.primary;
PANIC_CHECK(dbenv);
/* Validate arguments. */
if (flags == 0)
return (CDB___db_ferr(dbenv, "CDB_memp_fset", 1));
if ((ret = CDB___db_fchk(dbenv, "CDB_memp_fset", flags,
DB_MPOOL_DIRTY | DB_MPOOL_CLEAN | DB_MPOOL_DISCARD)) != 0)
return (ret);
if ((ret = CDB___db_fcchk(dbenv, "CDB_memp_fset",
flags, DB_MPOOL_CLEAN, DB_MPOOL_DIRTY)) != 0)
return (ret);
if (LF_ISSET(DB_MPOOL_DIRTY) && F_ISSET(dbmfp, MP_READONLY)) {
CDB___db_err(dbenv, "%s: dirty flag set for readonly file page",
CDB___memp_fn(dbmfp));
return (EACCES);
}
/* Convert the page address to a buffer header. */
bhp = (BH *)((u_int8_t *)pgaddr - SSZA(BH, buf));
/* Convert the buffer header to a cache. */
mc = BH_TO_CACHE(dbmp, bhp);
R_LOCK(dbenv, &dbmp->reginfo);
if (LF_ISSET(DB_MPOOL_CLEAN) && F_ISSET(bhp, BH_DIRTY)) {
++mc->stat.st_page_clean;
--mc->stat.st_page_dirty;
F_CLR(bhp, BH_DIRTY);
}
if (LF_ISSET(DB_MPOOL_DIRTY) && !F_ISSET(bhp, BH_DIRTY)) {
--mc->stat.st_page_clean;
++mc->stat.st_page_dirty;
F_SET(bhp, BH_DIRTY);
}
if (LF_ISSET(DB_MPOOL_DISCARD))
F_SET(bhp, BH_DISCARD);
R_UNLOCK(dbenv, &dbmp->reginfo);
return (0);
}
|