default_pager.c revision 12767
1214571Sdim/*
2214571Sdim * Copyright (c) 1995, David Greenman
3214571Sdim * All rights reserved.
4214571Sdim *
5214571Sdim * Redistribution and use in source and binary forms, with or without
6214571Sdim * modification, are permitted provided that the following conditions
7214571Sdim * are met:
8214571Sdim * 1. Redistributions of source code must retain the above copyright
9214571Sdim *    notice, this list of conditions and the following disclaimer.
10214571Sdim * 2. Redistributions in binary form must reproduce the above copyright
11214571Sdim *    notice, this list of conditions and the following disclaimer in the
12214571Sdim *    documentation and/or other materials provided with the distribution.
13214571Sdim * 3. All advertising materials mentioning features or use of this software
14214571Sdim *    must display the following acknowledgement:
15214571Sdim *	This product includes software developed by David Greenman.
16214571Sdim * 4. The name of the author may not be used to endorse or promote products
17214571Sdim *    derived from this software without specific prior written permission.
18214571Sdim *
19214571Sdim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20214571Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21214571Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22214571Sdim * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23214571Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24214571Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25214571Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26214571Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27214571Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28214571Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29214571Sdim * SUCH DAMAGE.
30214571Sdim *
31214571Sdim *	$Id: default_pager.c,v 1.3 1995/12/07 12:48:00 davidg Exp $
32214571Sdim */
33214571Sdim
34214571Sdim#include <sys/param.h>
35214571Sdim#include <sys/systm.h>
36214571Sdim#include <sys/kernel.h>
37214571Sdim#include <sys/malloc.h>
38214571Sdim#include <sys/queue.h>
39214571Sdim
40214571Sdim#include <vm/vm.h>
41214571Sdim#include <vm/vm_param.h>
42214571Sdim#include <vm/vm_prot.h>
43214571Sdim#include <vm/vm_object.h>
44214571Sdim#include <vm/vm_page.h>
45214571Sdim#include <vm/vm_pager.h>
46214571Sdim#include <vm/default_pager.h>
47214571Sdim#include <vm/swap_pager.h>
48214571Sdim
49214571Sdim/*
50214571Sdim * pagerops for OBJT_DEFAULT - "default pager".
51214571Sdim */
52214571Sdimstruct pagerops defaultpagerops = {
53214571Sdim	NULL,
54214571Sdim	default_pager_alloc,
55214571Sdim	default_pager_dealloc,
56214571Sdim	default_pager_getpages,
57214571Sdim	default_pager_putpages,
58214571Sdim	default_pager_haspage,
59214571Sdim	NULL
60214571Sdim};
61214571Sdim
62214571Sdim/*
63214571Sdim * no_pager_alloc just returns an initialized object.
64214571Sdim */
65214571Sdimvm_object_t
66214571Sdimdefault_pager_alloc(handle, size, prot, offset)
67214571Sdim	void *handle;
68214571Sdim	register vm_size_t size;
69214571Sdim	vm_prot_t prot;
70214571Sdim	vm_ooffset_t offset;
71214571Sdim{
72214571Sdim	if (handle != NULL)
73214571Sdim		panic("default_pager_alloc: handle specified");
74214571Sdim
75214571Sdim	return vm_object_allocate(OBJT_DEFAULT, offset + size);
76214571Sdim}
77214571Sdim
78214571Sdimvoid
79214571Sdimdefault_pager_dealloc(object)
80214571Sdim	vm_object_t object;
81214571Sdim{
82214571Sdim	/*
83214571Sdim	 * OBJT_DEFAULT objects have no special resources allocated to them.
84214571Sdim	 */
85214571Sdim}
86214571Sdim
87214571Sdim/*
88214571Sdim * The default pager has no backing store, so we always return
89214571Sdim * failure.
90214571Sdim */
91214571Sdimint
92214571Sdimdefault_pager_getpages(object, m, count, reqpage)
93214571Sdim	vm_object_t object;
94214571Sdim	vm_page_t *m;
95214571Sdim	int count;
96214571Sdim	int reqpage;
97214571Sdim{
98214571Sdim	return VM_PAGER_FAIL;
99214571Sdim}
100214571Sdim
101214571Sdimint
102214571Sdimdefault_pager_putpages(object, m, c, sync, rtvals)
103214571Sdim	vm_object_t object;
104214571Sdim	vm_page_t *m;
105214571Sdim	int c;
106214571Sdim	boolean_t sync;
107214571Sdim	int *rtvals;
108214571Sdim{
109214571Sdim	int i;
110214571Sdim
111214571Sdim	/*
112214571Sdim	 * Try to convert the object type into a OBJT_SWAP.
113214571Sdim	 * If the swp structure allocation fails, convert it
114214571Sdim	 * back to OBJT_DEFAULT and return failure. Otherwise
115214571Sdim	 * pass this putpages to the swap pager.
116214571Sdim	 */
117214571Sdim	object->type = OBJT_SWAP;
118214571Sdim
119214571Sdim	if (swap_pager_swp_alloc(object, M_KERNEL) != 0) {
120214571Sdim		object->type = OBJT_DEFAULT;
121214571Sdim		for (i = 0; i < c; i++)
122214571Sdim			rtvals[i] = VM_PAGER_FAIL;
123214571Sdim		return VM_PAGER_FAIL;
124214571Sdim	}
125214571Sdim
126214571Sdim	return swap_pager_putpages(object, m, c, sync, rtvals);
127214571Sdim}
128214571Sdim
129214571Sdimboolean_t
130214571Sdimdefault_pager_haspage(object, pindex, before, after)
131214571Sdim	vm_object_t object;
132214571Sdim	vm_pindex_t pindex;
133214571Sdim	int *before;
134214571Sdim	int *after;
135214571Sdim{
136214571Sdim	return FALSE;
137214571Sdim}
138214571Sdim