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