Raise WARNS to 6:
[dragonfly.git] / sys / vm / vm_pager.h
1 /*
2  * Copyright (c) 1990 University of Utah.
3  * Copyright (c) 1991, 1993
4  *      The Regents of the University of California.  All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * the Systems Programming Group of the University of Utah Computer
8  * Science Department.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *      This product includes software developed by the University of
21  *      California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *      @(#)vm_pager.h  8.4 (Berkeley) 1/12/94
39  * $FreeBSD: src/sys/vm/vm_pager.h,v 1.24.2.2 2002/12/31 09:34:51 dillon Exp $
40  * $DragonFly: src/sys/vm/vm_pager.h,v 1.5 2005/01/23 13:24:20 joerg Exp $
41  */
42
43 /*
44  * Pager routine interface definition.
45  */
46
47 #ifndef _VM_PAGER_
48 #define _VM_PAGER_
49
50 #include <sys/queue.h>
51
52 TAILQ_HEAD(pagerlst, vm_object);
53
54 struct buf;
55
56 struct pagerops {
57         void (*pgo_init) (void);                /* Initialize pager. */
58         vm_object_t (*pgo_alloc) (void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t);       /* Allocate pager. */
59         void (*pgo_dealloc) (vm_object_t);      /* Disassociate. */
60         int (*pgo_getpages) (vm_object_t, vm_page_t *, int, int);       /* Get (read) page. */
61         void (*pgo_putpages) (vm_object_t, vm_page_t *, int, int, int *); /* Put (write) page. */
62         boolean_t (*pgo_haspage) (vm_object_t, vm_pindex_t, int *, int *); /* Does pager have page? */
63         void (*pgo_pageunswapped) (vm_page_t);
64         void (*pgo_strategy) (vm_object_t, struct buf *);
65 };
66
67 /*
68  * get/put return values
69  * OK    operation was successful
70  * BAD   specified data was out of the accepted range
71  * FAIL  specified data was in range, but doesn't exist
72  * PEND  operations was initiated but not completed
73  * ERROR error while accessing data that is in range and exists
74  * AGAIN temporary resource shortage prevented operation from happening
75  */
76 #define VM_PAGER_OK     0
77 #define VM_PAGER_BAD    1
78 #define VM_PAGER_FAIL   2
79 #define VM_PAGER_PEND   3
80 #define VM_PAGER_ERROR  4
81 #define VM_PAGER_AGAIN  5
82
83 #define VM_PAGER_PUT_SYNC               0x0001
84 #define VM_PAGER_PUT_INVAL              0x0002
85 #define VM_PAGER_IGNORE_CLEANCHK        0x0004
86 #define VM_PAGER_CLUSTER_OK             0x0008
87
88 #ifdef _KERNEL
89
90 #ifdef MALLOC_DECLARE
91 MALLOC_DECLARE(M_VMPGDATA);
92 #endif
93
94 struct vnode;
95
96 extern vm_map_t pager_map;
97 extern int pager_map_size;
98 extern struct pagerops *pagertab[];
99
100 vm_object_t vm_pager_allocate (objtype_t, void *, vm_ooffset_t, vm_prot_t, vm_ooffset_t);
101 void vm_pager_bufferinit (void);
102 void vm_pager_deallocate (vm_object_t);
103 static __inline int vm_pager_get_pages (vm_object_t, vm_page_t *, int, int);
104 static __inline boolean_t vm_pager_has_page (vm_object_t, vm_pindex_t, int *, int *);
105 void vm_pager_init (void);
106 vm_object_t vm_pager_object_lookup (struct pagerlst *, void *);
107 void vm_pager_sync (void);
108 void vm_pager_strategy (vm_object_t object, struct buf *bp);
109 struct buf *getchainbuf(struct buf *bp, struct vnode *vp, int flags);
110 void flushchainbuf(struct buf *nbp);
111 void waitchainbuf(struct buf *bp, int count, int done);
112 void autochaindone(struct buf *bp);
113
114 /*
115  *      vm_page_get_pages:
116  *
117  *      Retrieve pages from the VM system in order to map them into an object
118  *      ( or into VM space somewhere ).  If the pagein was successful, we
119  *      must fully validate it.
120  */
121
122 static __inline int
123 vm_pager_get_pages(
124         vm_object_t object,
125         vm_page_t *m,
126         int count,
127         int reqpage
128 ) {
129         int r;
130
131         r = (*pagertab[object->type]->pgo_getpages)(object, m, count, reqpage);
132         if (r == VM_PAGER_OK && m[reqpage]->valid != VM_PAGE_BITS_ALL) {
133                 vm_page_zero_invalid(m[reqpage], TRUE);
134         }
135         return(r);
136 }
137
138 static __inline void
139 vm_pager_put_pages(
140         vm_object_t object,
141         vm_page_t *m,
142         int count,
143         int flags,
144         int *rtvals
145 ) {
146         (*pagertab[object->type]->pgo_putpages)
147             (object, m, count, flags, rtvals);
148 }
149
150 /*
151  *      vm_pager_haspage
152  *
153  *      Check to see if an object's pager has the requested page.  The
154  *      object's pager will also set before and after to give the caller
155  *      some idea of the number of pages before and after the requested
156  *      page can be I/O'd efficiently.
157  *
158  *      This routine does not have to be called at any particular spl.
159  */
160
161 static __inline boolean_t
162 vm_pager_has_page(
163         vm_object_t object,
164         vm_pindex_t offset, 
165         int *before,
166         int *after
167 ) {
168         return ((*pagertab[object->type]->pgo_haspage) (object, offset, before, after));
169
170
171 /* 
172  *      vm_pager_page_unswapped
173  * 
174  *      called at splvm() to destroy swap associated with the page.
175  * 
176  *      This function may not block.
177  */
178  
179 static __inline void
180 vm_pager_page_unswapped(vm_page_t m)
181 {
182         if (pagertab[m->object->type]->pgo_pageunswapped)
183                 (*pagertab[m->object->type]->pgo_pageunswapped)(m);
184 }
185
186 #endif
187
188 #endif                          /* _VM_PAGER_ */