ffs_vnops.c revision 1.16.2.5 1 1.16.2.5 chs /* $NetBSD: ffs_vnops.c,v 1.16.2.5 1999/05/30 15:16:01 chs Exp $ */
2 1.3 cgd
3 1.1 mycroft /*
4 1.1 mycroft * Copyright (c) 1982, 1986, 1989, 1993
5 1.1 mycroft * The Regents of the University of California. All rights reserved.
6 1.1 mycroft *
7 1.1 mycroft * Redistribution and use in source and binary forms, with or without
8 1.1 mycroft * modification, are permitted provided that the following conditions
9 1.1 mycroft * are met:
10 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
11 1.1 mycroft * notice, this list of conditions and the following disclaimer.
12 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
14 1.1 mycroft * documentation and/or other materials provided with the distribution.
15 1.1 mycroft * 3. All advertising materials mentioning features or use of this software
16 1.1 mycroft * must display the following acknowledgement:
17 1.1 mycroft * This product includes software developed by the University of
18 1.1 mycroft * California, Berkeley and its contributors.
19 1.1 mycroft * 4. Neither the name of the University nor the names of its contributors
20 1.1 mycroft * may be used to endorse or promote products derived from this software
21 1.1 mycroft * without specific prior written permission.
22 1.1 mycroft *
23 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 mycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 mycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 mycroft * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 mycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 mycroft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 mycroft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 mycroft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 mycroft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 mycroft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 mycroft * SUCH DAMAGE.
34 1.1 mycroft *
35 1.12 fvdl * @(#)ffs_vnops.c 8.15 (Berkeley) 5/14/95
36 1.1 mycroft */
37 1.11 mrg
38 1.13 scottr #if defined(_KERNEL) && !defined(_LKM)
39 1.11 mrg #include "opt_uvm.h"
40 1.16.2.3 chs #include "opt_uvmhist.h"
41 1.13 scottr #endif
42 1.1 mycroft
43 1.1 mycroft #include <sys/param.h>
44 1.1 mycroft #include <sys/systm.h>
45 1.1 mycroft #include <sys/resourcevar.h>
46 1.1 mycroft #include <sys/kernel.h>
47 1.1 mycroft #include <sys/file.h>
48 1.1 mycroft #include <sys/stat.h>
49 1.1 mycroft #include <sys/buf.h>
50 1.1 mycroft #include <sys/proc.h>
51 1.1 mycroft #include <sys/conf.h>
52 1.1 mycroft #include <sys/mount.h>
53 1.1 mycroft #include <sys/vnode.h>
54 1.1 mycroft #include <sys/malloc.h>
55 1.16 thorpej #include <sys/pool.h>
56 1.6 christos #include <sys/signalvar.h>
57 1.1 mycroft
58 1.1 mycroft #include <vm/vm.h>
59 1.10 mrg
60 1.10 mrg #if defined(UVM)
61 1.10 mrg #include <uvm/uvm_extern.h>
62 1.10 mrg #endif
63 1.1 mycroft
64 1.8 mycroft #include <miscfs/fifofs/fifo.h>
65 1.8 mycroft #include <miscfs/genfs/genfs.h>
66 1.1 mycroft #include <miscfs/specfs/specdev.h>
67 1.1 mycroft
68 1.1 mycroft #include <ufs/ufs/quota.h>
69 1.1 mycroft #include <ufs/ufs/inode.h>
70 1.1 mycroft #include <ufs/ufs/dir.h>
71 1.1 mycroft #include <ufs/ufs/ufs_extern.h>
72 1.2 mycroft #include <ufs/ufs/ufsmount.h>
73 1.1 mycroft
74 1.1 mycroft #include <ufs/ffs/fs.h>
75 1.1 mycroft #include <ufs/ffs/ffs_extern.h>
76 1.1 mycroft
77 1.1 mycroft /* Global vfs data structures for ufs. */
78 1.6 christos int (**ffs_vnodeop_p) __P((void *));
79 1.1 mycroft struct vnodeopv_entry_desc ffs_vnodeop_entries[] = {
80 1.1 mycroft { &vop_default_desc, vn_default_error },
81 1.1 mycroft { &vop_lookup_desc, ufs_lookup }, /* lookup */
82 1.1 mycroft { &vop_create_desc, ufs_create }, /* create */
83 1.5 mycroft { &vop_whiteout_desc, ufs_whiteout }, /* whiteout */
84 1.1 mycroft { &vop_mknod_desc, ufs_mknod }, /* mknod */
85 1.1 mycroft { &vop_open_desc, ufs_open }, /* open */
86 1.1 mycroft { &vop_close_desc, ufs_close }, /* close */
87 1.1 mycroft { &vop_access_desc, ufs_access }, /* access */
88 1.1 mycroft { &vop_getattr_desc, ufs_getattr }, /* getattr */
89 1.1 mycroft { &vop_setattr_desc, ufs_setattr }, /* setattr */
90 1.1 mycroft { &vop_read_desc, ffs_read }, /* read */
91 1.1 mycroft { &vop_write_desc, ffs_write }, /* write */
92 1.4 mycroft { &vop_lease_desc, ufs_lease_check }, /* lease */
93 1.1 mycroft { &vop_ioctl_desc, ufs_ioctl }, /* ioctl */
94 1.9 mycroft { &vop_poll_desc, ufs_poll }, /* poll */
95 1.12 fvdl { &vop_revoke_desc, ufs_revoke }, /* revoke */
96 1.1 mycroft { &vop_mmap_desc, ufs_mmap }, /* mmap */
97 1.1 mycroft { &vop_fsync_desc, ffs_fsync }, /* fsync */
98 1.1 mycroft { &vop_seek_desc, ufs_seek }, /* seek */
99 1.1 mycroft { &vop_remove_desc, ufs_remove }, /* remove */
100 1.1 mycroft { &vop_link_desc, ufs_link }, /* link */
101 1.1 mycroft { &vop_rename_desc, ufs_rename }, /* rename */
102 1.1 mycroft { &vop_mkdir_desc, ufs_mkdir }, /* mkdir */
103 1.1 mycroft { &vop_rmdir_desc, ufs_rmdir }, /* rmdir */
104 1.1 mycroft { &vop_symlink_desc, ufs_symlink }, /* symlink */
105 1.1 mycroft { &vop_readdir_desc, ufs_readdir }, /* readdir */
106 1.1 mycroft { &vop_readlink_desc, ufs_readlink }, /* readlink */
107 1.1 mycroft { &vop_abortop_desc, ufs_abortop }, /* abortop */
108 1.1 mycroft { &vop_inactive_desc, ufs_inactive }, /* inactive */
109 1.1 mycroft { &vop_reclaim_desc, ffs_reclaim }, /* reclaim */
110 1.1 mycroft { &vop_lock_desc, ufs_lock }, /* lock */
111 1.1 mycroft { &vop_unlock_desc, ufs_unlock }, /* unlock */
112 1.1 mycroft { &vop_bmap_desc, ufs_bmap }, /* bmap */
113 1.1 mycroft { &vop_strategy_desc, ufs_strategy }, /* strategy */
114 1.1 mycroft { &vop_print_desc, ufs_print }, /* print */
115 1.1 mycroft { &vop_islocked_desc, ufs_islocked }, /* islocked */
116 1.1 mycroft { &vop_pathconf_desc, ufs_pathconf }, /* pathconf */
117 1.1 mycroft { &vop_advlock_desc, ufs_advlock }, /* advlock */
118 1.1 mycroft { &vop_blkatoff_desc, ffs_blkatoff }, /* blkatoff */
119 1.1 mycroft { &vop_valloc_desc, ffs_valloc }, /* valloc */
120 1.1 mycroft { &vop_reallocblks_desc, ffs_reallocblks }, /* reallocblks */
121 1.1 mycroft { &vop_vfree_desc, ffs_vfree }, /* vfree */
122 1.1 mycroft { &vop_truncate_desc, ffs_truncate }, /* truncate */
123 1.1 mycroft { &vop_update_desc, ffs_update }, /* update */
124 1.8 mycroft { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
125 1.16.2.1 chs #ifdef UBC
126 1.16.2.1 chs { &vop_getpages_desc, ffs_getpages }, /* getpages */
127 1.16.2.1 chs { &vop_putpages_desc, ffs_putpages }, /* putpages */
128 1.16.2.1 chs #endif
129 1.16.2.1 chs { NULL, NULL }
130 1.1 mycroft };
131 1.1 mycroft struct vnodeopv_desc ffs_vnodeop_opv_desc =
132 1.1 mycroft { &ffs_vnodeop_p, ffs_vnodeop_entries };
133 1.1 mycroft
134 1.6 christos int (**ffs_specop_p) __P((void *));
135 1.1 mycroft struct vnodeopv_entry_desc ffs_specop_entries[] = {
136 1.1 mycroft { &vop_default_desc, vn_default_error },
137 1.1 mycroft { &vop_lookup_desc, spec_lookup }, /* lookup */
138 1.1 mycroft { &vop_create_desc, spec_create }, /* create */
139 1.1 mycroft { &vop_mknod_desc, spec_mknod }, /* mknod */
140 1.1 mycroft { &vop_open_desc, spec_open }, /* open */
141 1.1 mycroft { &vop_close_desc, ufsspec_close }, /* close */
142 1.1 mycroft { &vop_access_desc, ufs_access }, /* access */
143 1.1 mycroft { &vop_getattr_desc, ufs_getattr }, /* getattr */
144 1.1 mycroft { &vop_setattr_desc, ufs_setattr }, /* setattr */
145 1.1 mycroft { &vop_read_desc, ufsspec_read }, /* read */
146 1.1 mycroft { &vop_write_desc, ufsspec_write }, /* write */
147 1.4 mycroft { &vop_lease_desc, spec_lease_check }, /* lease */
148 1.1 mycroft { &vop_ioctl_desc, spec_ioctl }, /* ioctl */
149 1.9 mycroft { &vop_poll_desc, spec_poll }, /* poll */
150 1.12 fvdl { &vop_revoke_desc, spec_revoke }, /* revoke */
151 1.1 mycroft { &vop_mmap_desc, spec_mmap }, /* mmap */
152 1.1 mycroft { &vop_fsync_desc, ffs_fsync }, /* fsync */
153 1.1 mycroft { &vop_seek_desc, spec_seek }, /* seek */
154 1.1 mycroft { &vop_remove_desc, spec_remove }, /* remove */
155 1.1 mycroft { &vop_link_desc, spec_link }, /* link */
156 1.1 mycroft { &vop_rename_desc, spec_rename }, /* rename */
157 1.1 mycroft { &vop_mkdir_desc, spec_mkdir }, /* mkdir */
158 1.1 mycroft { &vop_rmdir_desc, spec_rmdir }, /* rmdir */
159 1.1 mycroft { &vop_symlink_desc, spec_symlink }, /* symlink */
160 1.1 mycroft { &vop_readdir_desc, spec_readdir }, /* readdir */
161 1.1 mycroft { &vop_readlink_desc, spec_readlink }, /* readlink */
162 1.1 mycroft { &vop_abortop_desc, spec_abortop }, /* abortop */
163 1.1 mycroft { &vop_inactive_desc, ufs_inactive }, /* inactive */
164 1.1 mycroft { &vop_reclaim_desc, ffs_reclaim }, /* reclaim */
165 1.1 mycroft { &vop_lock_desc, ufs_lock }, /* lock */
166 1.1 mycroft { &vop_unlock_desc, ufs_unlock }, /* unlock */
167 1.1 mycroft { &vop_bmap_desc, spec_bmap }, /* bmap */
168 1.1 mycroft { &vop_strategy_desc, spec_strategy }, /* strategy */
169 1.1 mycroft { &vop_print_desc, ufs_print }, /* print */
170 1.1 mycroft { &vop_islocked_desc, ufs_islocked }, /* islocked */
171 1.1 mycroft { &vop_pathconf_desc, spec_pathconf }, /* pathconf */
172 1.1 mycroft { &vop_advlock_desc, spec_advlock }, /* advlock */
173 1.1 mycroft { &vop_blkatoff_desc, spec_blkatoff }, /* blkatoff */
174 1.1 mycroft { &vop_valloc_desc, spec_valloc }, /* valloc */
175 1.1 mycroft { &vop_reallocblks_desc, spec_reallocblks }, /* reallocblks */
176 1.1 mycroft { &vop_vfree_desc, ffs_vfree }, /* vfree */
177 1.1 mycroft { &vop_truncate_desc, spec_truncate }, /* truncate */
178 1.1 mycroft { &vop_update_desc, ffs_update }, /* update */
179 1.8 mycroft { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
180 1.6 christos { (struct vnodeop_desc*)NULL, (int(*) __P((void *)))NULL }
181 1.1 mycroft };
182 1.1 mycroft struct vnodeopv_desc ffs_specop_opv_desc =
183 1.1 mycroft { &ffs_specop_p, ffs_specop_entries };
184 1.1 mycroft
185 1.6 christos int (**ffs_fifoop_p) __P((void *));
186 1.1 mycroft struct vnodeopv_entry_desc ffs_fifoop_entries[] = {
187 1.1 mycroft { &vop_default_desc, vn_default_error },
188 1.1 mycroft { &vop_lookup_desc, fifo_lookup }, /* lookup */
189 1.1 mycroft { &vop_create_desc, fifo_create }, /* create */
190 1.1 mycroft { &vop_mknod_desc, fifo_mknod }, /* mknod */
191 1.1 mycroft { &vop_open_desc, fifo_open }, /* open */
192 1.1 mycroft { &vop_close_desc, ufsfifo_close }, /* close */
193 1.1 mycroft { &vop_access_desc, ufs_access }, /* access */
194 1.1 mycroft { &vop_getattr_desc, ufs_getattr }, /* getattr */
195 1.1 mycroft { &vop_setattr_desc, ufs_setattr }, /* setattr */
196 1.1 mycroft { &vop_read_desc, ufsfifo_read }, /* read */
197 1.1 mycroft { &vop_write_desc, ufsfifo_write }, /* write */
198 1.4 mycroft { &vop_lease_desc, fifo_lease_check }, /* lease */
199 1.1 mycroft { &vop_ioctl_desc, fifo_ioctl }, /* ioctl */
200 1.9 mycroft { &vop_poll_desc, fifo_poll }, /* poll */
201 1.12 fvdl { &vop_revoke_desc, fifo_revoke }, /* revoke */
202 1.1 mycroft { &vop_mmap_desc, fifo_mmap }, /* mmap */
203 1.1 mycroft { &vop_fsync_desc, ffs_fsync }, /* fsync */
204 1.1 mycroft { &vop_seek_desc, fifo_seek }, /* seek */
205 1.1 mycroft { &vop_remove_desc, fifo_remove }, /* remove */
206 1.1 mycroft { &vop_link_desc, fifo_link }, /* link */
207 1.1 mycroft { &vop_rename_desc, fifo_rename }, /* rename */
208 1.1 mycroft { &vop_mkdir_desc, fifo_mkdir }, /* mkdir */
209 1.1 mycroft { &vop_rmdir_desc, fifo_rmdir }, /* rmdir */
210 1.1 mycroft { &vop_symlink_desc, fifo_symlink }, /* symlink */
211 1.1 mycroft { &vop_readdir_desc, fifo_readdir }, /* readdir */
212 1.1 mycroft { &vop_readlink_desc, fifo_readlink }, /* readlink */
213 1.1 mycroft { &vop_abortop_desc, fifo_abortop }, /* abortop */
214 1.1 mycroft { &vop_inactive_desc, ufs_inactive }, /* inactive */
215 1.1 mycroft { &vop_reclaim_desc, ffs_reclaim }, /* reclaim */
216 1.1 mycroft { &vop_lock_desc, ufs_lock }, /* lock */
217 1.1 mycroft { &vop_unlock_desc, ufs_unlock }, /* unlock */
218 1.1 mycroft { &vop_bmap_desc, fifo_bmap }, /* bmap */
219 1.1 mycroft { &vop_strategy_desc, fifo_strategy }, /* strategy */
220 1.1 mycroft { &vop_print_desc, ufs_print }, /* print */
221 1.1 mycroft { &vop_islocked_desc, ufs_islocked }, /* islocked */
222 1.1 mycroft { &vop_pathconf_desc, fifo_pathconf }, /* pathconf */
223 1.1 mycroft { &vop_advlock_desc, fifo_advlock }, /* advlock */
224 1.1 mycroft { &vop_blkatoff_desc, fifo_blkatoff }, /* blkatoff */
225 1.1 mycroft { &vop_valloc_desc, fifo_valloc }, /* valloc */
226 1.1 mycroft { &vop_reallocblks_desc, fifo_reallocblks }, /* reallocblks */
227 1.1 mycroft { &vop_vfree_desc, ffs_vfree }, /* vfree */
228 1.1 mycroft { &vop_truncate_desc, fifo_truncate }, /* truncate */
229 1.1 mycroft { &vop_update_desc, ffs_update }, /* update */
230 1.8 mycroft { &vop_bwrite_desc, vn_bwrite }, /* bwrite */
231 1.6 christos { (struct vnodeop_desc*)NULL, (int(*) __P((void *)))NULL }
232 1.1 mycroft };
233 1.1 mycroft struct vnodeopv_desc ffs_fifoop_opv_desc =
234 1.1 mycroft { &ffs_fifoop_p, ffs_fifoop_entries };
235 1.1 mycroft
236 1.16.2.4 chs int doclusterread = 0;
237 1.16.2.4 chs int doclusterwrite = 0;
238 1.1 mycroft
239 1.1 mycroft #include <ufs/ufs/ufs_readwrite.c>
240 1.1 mycroft
241 1.1 mycroft /*
242 1.1 mycroft * Reclaim an inode so that it can be used for other purposes.
243 1.1 mycroft */
244 1.1 mycroft int
245 1.6 christos ffs_reclaim(v)
246 1.6 christos void *v;
247 1.6 christos {
248 1.1 mycroft struct vop_reclaim_args /* {
249 1.1 mycroft struct vnode *a_vp;
250 1.12 fvdl struct proc *a_p;
251 1.6 christos } */ *ap = v;
252 1.1 mycroft register struct vnode *vp = ap->a_vp;
253 1.1 mycroft int error;
254 1.1 mycroft
255 1.12 fvdl if ((error = ufs_reclaim(vp, ap->a_p)) != 0)
256 1.1 mycroft return (error);
257 1.16.2.1 chs
258 1.16 thorpej /*
259 1.16 thorpej * XXX MFS ends up here, too, to free an inode. Should we create
260 1.16 thorpej * XXX a separate pool for MFS inodes?
261 1.16 thorpej */
262 1.16 thorpej pool_put(&ffs_inode_pool, vp->v_data);
263 1.1 mycroft vp->v_data = NULL;
264 1.1 mycroft return (0);
265 1.1 mycroft }
266 1.16.2.1 chs
267 1.16.2.1 chs #ifdef UBC
268 1.16.2.1 chs #include <uvm/uvm.h>
269 1.16.2.1 chs
270 1.16.2.1 chs int
271 1.16.2.1 chs ffs_getpages(v)
272 1.16.2.1 chs void *v;
273 1.16.2.1 chs {
274 1.16.2.1 chs struct vop_getpages_args /* {
275 1.16.2.1 chs struct vnode *a_vp;
276 1.16.2.1 chs vaddr_t a_offset;
277 1.16.2.1 chs vm_page_t *a_m;
278 1.16.2.1 chs int *a_count;
279 1.16.2.1 chs int a_centeridx;
280 1.16.2.1 chs vm_prot_t a_access_type;
281 1.16.2.1 chs int a_advice;
282 1.16.2.1 chs int a_flags;
283 1.16.2.1 chs } */ *ap = v;
284 1.16.2.1 chs
285 1.16.2.5 chs int error, npages;
286 1.16.2.1 chs struct buf tmpbuf, *bp;
287 1.16.2.1 chs struct vnode *vp = ap->a_vp;
288 1.16.2.1 chs struct uvm_object *uobj = &vp->v_uvm.u_obj;
289 1.16.2.1 chs struct inode *ip = VTOI(vp);
290 1.16.2.1 chs struct fs *fs = ip->i_fs;
291 1.16.2.5 chs struct vm_page *pg;
292 1.16.2.5 chs off_t offset;
293 1.16.2.1 chs UVMHIST_FUNC("ffs_getpages"); UVMHIST_CALLED(ubchist);
294 1.16.2.1 chs
295 1.16.2.3 chs #ifdef DIAGNOSTIC
296 1.16.2.3 chs if (ap->a_centeridx < 0 || ap->a_centeridx > *ap->a_count) {
297 1.16.2.3 chs panic("ffs_getpages: centeridx %d out of range",
298 1.16.2.3 chs ap->a_centeridx);
299 1.16.2.3 chs }
300 1.16.2.3 chs #endif
301 1.16.2.3 chs
302 1.16.2.1 chs if (ap->a_flags & PGO_LOCKED) {
303 1.16.2.3 chs uvn_findpages(uobj, ap->a_offset, ap->a_count, ap->a_m,
304 1.16.2.3 chs UFP_NOWAIT|UFP_NOALLOC);
305 1.16.2.3 chs
306 1.16.2.3 chs /* XXX PGO_ALLPAGES? */
307 1.16.2.3 chs return ap->a_m[ap->a_centeridx] == NULL ?
308 1.16.2.3 chs VM_PAGER_UNLOCK : VM_PAGER_OK;
309 1.16.2.1 chs }
310 1.16.2.1 chs
311 1.16.2.1 chs /* vnode is VOP_LOCKed, uobj is locked */
312 1.16.2.1 chs
313 1.16.2.5 chs
314 1.16.2.3 chs /*
315 1.16.2.5 chs * XXX do the findpages for our 1 page first,
316 1.16.2.5 chs * change asyncget to take the one page as an arg and
317 1.16.2.5 chs * pretend that its findpages found it.
318 1.16.2.3 chs */
319 1.16.2.1 chs
320 1.16.2.5 chs /*
321 1.16.2.5 chs * kick off a big read first to get some readahead, then
322 1.16.2.5 chs * get the one page we wanted.
323 1.16.2.5 chs */
324 1.16.2.5 chs
325 1.16.2.5 chs if ((ap->a_flags & PGO_OVERWRITE) == 0 &&
326 1.16.2.5 chs (ap->a_offset & (MAXBSIZE - 1)) == 0) {
327 1.16.2.5 chs /*
328 1.16.2.5 chs * XXX pretty sure unlocking here is wrong.
329 1.16.2.5 chs */
330 1.16.2.3 chs simple_unlock(&uobj->vmobjlock);
331 1.16.2.5 chs uvm_vnp_asyncget(vp, ap->a_offset, MAXBSIZE, fs->fs_bsize);
332 1.16.2.5 chs simple_lock(&uobj->vmobjlock);
333 1.16.2.1 chs }
334 1.16.2.1 chs
335 1.16.2.5 chs /*
336 1.16.2.5 chs * the desired page isn't resident, we'll have to read it.
337 1.16.2.5 chs */
338 1.16.2.1 chs
339 1.16.2.5 chs offset = ap->a_offset + (ap->a_centeridx << PAGE_SHIFT);
340 1.16.2.5 chs npages = 1;
341 1.16.2.5 chs pg = NULL;
342 1.16.2.5 chs uvn_findpages(uobj, offset, &npages, &pg, 0);
343 1.16.2.1 chs simple_unlock(&uobj->vmobjlock);
344 1.16.2.1 chs
345 1.16.2.5 chs /*
346 1.16.2.5 chs * if the page is already resident, just return it.
347 1.16.2.5 chs */
348 1.16.2.5 chs
349 1.16.2.5 chs if (pg && (pg->flags & PG_FAKE) == 0) {
350 1.16.2.5 chs ap->a_m[ap->a_centeridx] = pg;
351 1.16.2.3 chs return VM_PAGER_OK;
352 1.16.2.1 chs }
353 1.16.2.1 chs
354 1.16.2.5 chs /*
355 1.16.2.5 chs * ok, really read the desired page.
356 1.16.2.5 chs */
357 1.16.2.5 chs
358 1.16.2.1 chs bp = &tmpbuf;
359 1.16.2.1 chs bzero(bp, sizeof *bp);
360 1.16.2.1 chs
361 1.16.2.5 chs bp->b_lblkno = lblkno(fs, offset);
362 1.16.2.5 chs error = VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL);
363 1.16.2.5 chs if (error) {
364 1.16.2.5 chs UVMHIST_LOG(ubchist, "VOP_BMAP lbn 0x%x -> %d\n",
365 1.16.2.5 chs bp->b_lblkno, error,0,0);
366 1.16.2.5 chs goto out;
367 1.16.2.5 chs }
368 1.16.2.5 chs if (bp->b_blkno == (daddr_t)-1) {
369 1.16.2.5 chs
370 1.16.2.5 chs /*
371 1.16.2.5 chs * XXX pre-allocate blocks here someday?
372 1.16.2.5 chs * ... only for write accesses.
373 1.16.2.5 chs * for read accesses we can skip the block allocation
374 1.16.2.5 chs * if we can arrange to be called again
375 1.16.2.5 chs * when a subsequent write access occurs.
376 1.16.2.5 chs * needs support in uvm_fault().
377 1.16.2.5 chs */
378 1.16.2.5 chs
379 1.16.2.5 chs uvm_pagezero(pg);
380 1.16.2.5 chs UVMHIST_LOG(ubchist, "VOP_BMAP lbn 0x%x -> blkno 0x%x\n",
381 1.16.2.5 chs bp->b_lblkno, bp->b_blkno,0,0);
382 1.16.2.5 chs goto out;
383 1.16.2.1 chs }
384 1.16.2.1 chs
385 1.16.2.1 chs /* adjust physical blkno for partial blocks */
386 1.16.2.5 chs bp->b_blkno += (offset - lblktosize(fs, bp->b_lblkno)) >> DEV_BSHIFT;
387 1.16.2.1 chs
388 1.16.2.3 chs UVMHIST_LOG(ubchist, "vp %p lblkno 0x%x blkno 0x%x",
389 1.16.2.3 chs vp, bp->b_lblkno, bp->b_blkno, 0);
390 1.16.2.3 chs
391 1.16.2.3 chs /*
392 1.16.2.3 chs * don't bother reading the pages if we're just going to
393 1.16.2.3 chs * overwrite them.
394 1.16.2.3 chs */
395 1.16.2.3 chs if (ap->a_flags & PGO_OVERWRITE) {
396 1.16.2.3 chs
397 1.16.2.5 chs UVMHIST_LOG(ubchist, "PGO_OVERWRITE",0,0,0,0);
398 1.16.2.5 chs
399 1.16.2.5 chs /* XXX for now, zero the page */
400 1.16.2.5 chs if (pg->flags & PG_FAKE) {
401 1.16.2.5 chs uvm_pagezero(pg);
402 1.16.2.5 chs pg->flags &= ~(PG_FAKE);
403 1.16.2.5 chs uvm_pageactivate(pg);
404 1.16.2.3 chs }
405 1.16.2.3 chs
406 1.16.2.5 chs UVMHIST_LOG(ubchist, "m[%d] <- pg %p", ap->a_centeridx, pg,0,0);
407 1.16.2.5 chs
408 1.16.2.5 chs /* XXX what about *ap->a_count > 1 ? */
409 1.16.2.5 chs ap->a_m[ap->a_centeridx] = pg;
410 1.16.2.5 chs return VM_PAGER_OK;
411 1.16.2.3 chs }
412 1.16.2.3 chs
413 1.16.2.3 chs bp->b_bufsize = PAGE_SIZE;
414 1.16.2.5 chs bp->b_data = (void *)uvm_pagermapin(&pg, 1, NULL, M_WAITOK);
415 1.16.2.3 chs bp->b_bcount = bp->b_lblkno < 0 ? bp->b_bufsize :
416 1.16.2.5 chs min(bp->b_bufsize, fragroundup(fs, vp->v_uvm.u_size - offset));
417 1.16.2.3 chs bp->b_vp = vp;
418 1.16.2.3 chs bp->b_flags = B_BUSY|B_READ;
419 1.16.2.3 chs
420 1.16.2.5 chs UVMHIST_LOG(ubchist, "bp %p vp %p lblkno 0x%x", bp, vp, bp->b_lblkno, 0);
421 1.16.2.1 chs
422 1.16.2.1 chs VOP_STRATEGY(bp);
423 1.16.2.1 chs error = biowait(bp);
424 1.16.2.1 chs
425 1.16.2.5 chs uvm_pagermapout((vaddr_t)bp->b_data, *ap->a_count);
426 1.16.2.1 chs
427 1.16.2.5 chs out:
428 1.16.2.1 chs if (error) {
429 1.16.2.1 chs simple_lock(&uobj->vmobjlock);
430 1.16.2.5 chs if (pg->flags & PG_WANTED) {
431 1.16.2.5 chs wakeup(pg);
432 1.16.2.5 chs }
433 1.16.2.5 chs UVM_PAGE_OWN(pg, NULL);
434 1.16.2.1 chs uvm_lock_pageq();
435 1.16.2.5 chs uvm_pagefree(pg);
436 1.16.2.1 chs uvm_unlock_pageq();
437 1.16.2.1 chs simple_unlock(&uobj->vmobjlock);
438 1.16.2.1 chs } else {
439 1.16.2.5 chs pg->flags &= ~(PG_FAKE);
440 1.16.2.5 chs pmap_clear_modify(PMAP_PGARG(pg));
441 1.16.2.5 chs pmap_clear_reference(PMAP_PGARG(pg));
442 1.16.2.5 chs uvm_pageactivate(pg);
443 1.16.2.5 chs ap->a_m[ap->a_centeridx] = pg;
444 1.16.2.1 chs }
445 1.16.2.1 chs
446 1.16.2.5 chs UVMHIST_LOG(ubchist, "returning, error %d", error,0,0,0);
447 1.16.2.5 chs
448 1.16.2.3 chs return error ? VM_PAGER_ERROR : VM_PAGER_OK;
449 1.16.2.1 chs }
450 1.16.2.1 chs
451 1.16.2.1 chs /*
452 1.16.2.1 chs * Vnode op for VM putpages.
453 1.16.2.1 chs */
454 1.16.2.1 chs int
455 1.16.2.1 chs ffs_putpages(v)
456 1.16.2.1 chs void *v;
457 1.16.2.1 chs {
458 1.16.2.1 chs struct vop_putpages_args /* {
459 1.16.2.1 chs struct vnode *a_vp;
460 1.16.2.3 chs struct vm_page **a_m;
461 1.16.2.1 chs int a_count;
462 1.16.2.1 chs int a_sync;
463 1.16.2.1 chs int *a_rtvals;
464 1.16.2.1 chs } */ *ap = v;
465 1.16.2.1 chs
466 1.16.2.3 chs int s, error;
467 1.16.2.5 chs int bsize;
468 1.16.2.3 chs vaddr_t kva, offset;
469 1.16.2.3 chs struct vm_page *pg;
470 1.16.2.1 chs struct buf tmpbuf, *bp;
471 1.16.2.1 chs struct vnode *vp = ap->a_vp;
472 1.16.2.1 chs struct inode *ip = VTOI(vp);
473 1.16.2.1 chs struct fs *fs = ip->i_fs;
474 1.16.2.1 chs struct ucred *cred = curproc->p_ucred; /* XXX curproc */
475 1.16.2.1 chs UVMHIST_FUNC("ffs_putpages"); UVMHIST_CALLED(ubchist);
476 1.16.2.1 chs
477 1.16.2.3 chs pg = ap->a_m[0];
478 1.16.2.3 chs
479 1.16.2.5 chs #ifdef DEBUG
480 1.16.2.5 chs /* XXX verify that pages given are in fact physically contiguous. */
481 1.16.2.3 chs #endif
482 1.16.2.1 chs
483 1.16.2.1 chs kva = uvm_pagermapin(ap->a_m, ap->a_count, NULL, M_WAITOK);
484 1.16.2.2 chs if (kva == 0) {
485 1.16.2.3 chs return VM_PAGER_AGAIN;
486 1.16.2.1 chs }
487 1.16.2.1 chs
488 1.16.2.3 chs if (ap->a_sync) {
489 1.16.2.3 chs bp = &tmpbuf;
490 1.16.2.3 chs bzero(bp, sizeof *bp);
491 1.16.2.3 chs }
492 1.16.2.3 chs else {
493 1.16.2.3 chs struct uvm_aiobuf *abp = pool_get(uvm_aiobuf_pool, PR_WAITOK);
494 1.16.2.3 chs abp->aio.aiodone = uvm_aio_aiodone;
495 1.16.2.3 chs abp->aio.kva = kva;
496 1.16.2.3 chs abp->aio.npages = ap->a_count;
497 1.16.2.3 chs abp->aio.pd_ptr = abp;
498 1.16.2.5 chs /* XXX pagedaemon */
499 1.16.2.5 chs abp->aio.flags = (curproc == uvm.pagedaemon_proc) ?
500 1.16.2.5 chs UVM_AIO_PAGEDAEMON : 0;
501 1.16.2.3 chs bp = &abp->buf;
502 1.16.2.3 chs bzero(bp, sizeof *bp);
503 1.16.2.3 chs bp->b_flags = B_CALL|B_ASYNC;
504 1.16.2.3 chs bp->b_iodone = uvm_aio_biodone;
505 1.16.2.3 chs }
506 1.16.2.1 chs
507 1.16.2.3 chs offset = pg->offset;
508 1.16.2.3 chs bp->b_bufsize = ap->a_count << PAGE_SHIFT;
509 1.16.2.1 chs bp->b_data = (void *)kva;
510 1.16.2.3 chs bp->b_lblkno = lblkno(fs, offset);
511 1.16.2.3 chs bp->b_bcount = min(bp->b_bufsize,
512 1.16.2.3 chs fragroundup(fs, vp->v_uvm.u_size - offset));
513 1.16.2.3 chs bp->b_flags |= B_BUSY|B_WRITE;
514 1.16.2.1 chs bp->b_vp = vp;
515 1.16.2.1 chs
516 1.16.2.1 chs /*
517 1.16.2.1 chs * if the blkno wasn't set in the page, do a bmap to find it.
518 1.16.2.3 chs * this should only happen if the block is unallocated.
519 1.16.2.1 chs * we'll always want to set the page's blkno if it's allocated
520 1.16.2.1 chs * to help prevent memory deadlocks. we probably even want to
521 1.16.2.3 chs * allocate blocks in VOP_GETPAGES() for this same reason.
522 1.16.2.1 chs *
523 1.16.2.1 chs * once we switch to doing that, the page should always have a blkno.
524 1.16.2.1 chs * but for now, we'll handle allocating blocks here too.
525 1.16.2.3 chs *
526 1.16.2.3 chs * XXX this doesn't handle blocksizes smaller than PAGE_SIZE.
527 1.16.2.1 chs */
528 1.16.2.1 chs
529 1.16.2.5 chs bp->b_blkno = 0;
530 1.16.2.5 chs bsize = blksize(fs, ip, lblkno(fs, offset));
531 1.16.2.5 chs error = ffs_balloc(ip, bp->b_lblkno, bsize, cred, NULL,
532 1.16.2.5 chs &bp->b_blkno, 0);
533 1.16.2.5 chs if (error) {
534 1.16.2.5 chs UVMHIST_LOG(ubchist, "ffs_balloc -> %d", error, 0,0,0);
535 1.16.2.5 chs goto out;
536 1.16.2.5 chs }
537 1.16.2.1 chs
538 1.16.2.5 chs if (bp->b_blkno == (daddr_t)-1) {
539 1.16.2.5 chs panic("XXX alloc from putpages vp %p", vp);
540 1.16.2.1 chs }
541 1.16.2.1 chs
542 1.16.2.5 chs /* adjust physical blkno for partial blocks */
543 1.16.2.5 chs bp->b_blkno += (offset - lblktosize(fs, bp->b_lblkno))
544 1.16.2.5 chs >> DEV_BSHIFT;
545 1.16.2.5 chs
546 1.16.2.3 chs UVMHIST_LOG(ubchist, "pg %p vp %p lblkno 0x%x blkno 0x%x",
547 1.16.2.3 chs pg, vp, bp->b_lblkno, bp->b_blkno);
548 1.16.2.1 chs
549 1.16.2.3 chs s = splbio();
550 1.16.2.1 chs vp->v_numoutput++;
551 1.16.2.3 chs splx(s);
552 1.16.2.1 chs
553 1.16.2.1 chs VOP_STRATEGY(bp);
554 1.16.2.3 chs if (!ap->a_sync) {
555 1.16.2.3 chs return VM_PAGER_PEND;
556 1.16.2.3 chs }
557 1.16.2.1 chs
558 1.16.2.1 chs error = biowait(bp);
559 1.16.2.1 chs
560 1.16.2.3 chs out:
561 1.16.2.5 chs UVMHIST_LOG(ubchist, "error %d", error,0,0,0);
562 1.16.2.1 chs uvm_pagermapout(kva, ap->a_count);
563 1.16.2.1 chs
564 1.16.2.3 chs return error ? VM_PAGER_ERROR : VM_PAGER_OK;
565 1.16.2.1 chs }
566 1.16.2.1 chs #endif
567