genfs_vnops.c revision 1.11.4.6 1 1.11.4.6 chs /* $NetBSD: genfs_vnops.c,v 1.11.4.6 1999/08/09 00:05:54 chs Exp $ */
2 1.6 fvdl
3 1.6 fvdl /*
4 1.6 fvdl * Copyright (c) 1982, 1986, 1989, 1993
5 1.6 fvdl * The Regents of the University of California. All rights reserved.
6 1.6 fvdl *
7 1.6 fvdl * Redistribution and use in source and binary forms, with or without
8 1.6 fvdl * modification, are permitted provided that the following conditions
9 1.6 fvdl * are met:
10 1.6 fvdl * 1. Redistributions of source code must retain the above copyright
11 1.6 fvdl * notice, this list of conditions and the following disclaimer.
12 1.6 fvdl * 2. Redistributions in binary form must reproduce the above copyright
13 1.6 fvdl * notice, this list of conditions and the following disclaimer in the
14 1.6 fvdl * documentation and/or other materials provided with the distribution.
15 1.6 fvdl * 3. All advertising materials mentioning features or use of this software
16 1.6 fvdl * must display the following acknowledgement:
17 1.6 fvdl * This product includes software developed by the University of
18 1.6 fvdl * California, Berkeley and its contributors.
19 1.6 fvdl * 4. Neither the name of the University nor the names of its contributors
20 1.6 fvdl * may be used to endorse or promote products derived from this software
21 1.6 fvdl * without specific prior written permission.
22 1.6 fvdl *
23 1.6 fvdl * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.6 fvdl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.6 fvdl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.6 fvdl * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.6 fvdl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.6 fvdl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.6 fvdl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.6 fvdl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.6 fvdl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.6 fvdl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.6 fvdl * SUCH DAMAGE.
34 1.6 fvdl *
35 1.6 fvdl */
36 1.5 perry
37 1.8 thorpej #include "opt_nfsserver.h"
38 1.8 thorpej
39 1.1 mycroft #include <sys/param.h>
40 1.1 mycroft #include <sys/systm.h>
41 1.6 fvdl #include <sys/proc.h>
42 1.1 mycroft #include <sys/kernel.h>
43 1.1 mycroft #include <sys/mount.h>
44 1.1 mycroft #include <sys/namei.h>
45 1.1 mycroft #include <sys/vnode.h>
46 1.1 mycroft #include <sys/malloc.h>
47 1.3 mycroft #include <sys/poll.h>
48 1.1 mycroft
49 1.1 mycroft #include <miscfs/genfs/genfs.h>
50 1.6 fvdl #include <miscfs/specfs/specdev.h>
51 1.1 mycroft
52 1.11.4.1 chs #include <vm/vm.h>
53 1.11.4.1 chs #include <uvm/uvm.h>
54 1.11.4.1 chs
55 1.8 thorpej #ifdef NFSSERVER
56 1.8 thorpej #include <nfs/rpcv2.h>
57 1.8 thorpej #include <nfs/nfsproto.h>
58 1.8 thorpej #include <nfs/nfs.h>
59 1.8 thorpej #include <nfs/nqnfs.h>
60 1.8 thorpej #include <nfs/nfs_var.h>
61 1.8 thorpej #endif
62 1.8 thorpej
63 1.1 mycroft int
64 1.3 mycroft genfs_poll(v)
65 1.1 mycroft void *v;
66 1.1 mycroft {
67 1.3 mycroft struct vop_poll_args /* {
68 1.1 mycroft struct vnode *a_vp;
69 1.3 mycroft int a_events;
70 1.1 mycroft struct proc *a_p;
71 1.1 mycroft } */ *ap = v;
72 1.1 mycroft
73 1.3 mycroft return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
74 1.1 mycroft }
75 1.1 mycroft
76 1.1 mycroft int
77 1.1 mycroft genfs_fsync(v)
78 1.1 mycroft void *v;
79 1.1 mycroft {
80 1.1 mycroft struct vop_fsync_args /* {
81 1.1 mycroft struct vnode *a_vp;
82 1.1 mycroft struct ucred *a_cred;
83 1.7 kleink int a_flags;
84 1.1 mycroft struct proc *a_p;
85 1.1 mycroft } */ *ap = v;
86 1.1 mycroft register struct vnode *vp = ap->a_vp;
87 1.11 mycroft int wait;
88 1.1 mycroft
89 1.11 mycroft wait = (ap->a_flags & FSYNC_WAIT) != 0;
90 1.11 mycroft vflushbuf(vp, wait);
91 1.11 mycroft if ((ap->a_flags & FSYNC_DATAONLY) != 0)
92 1.7 kleink return (0);
93 1.11 mycroft else
94 1.11 mycroft return (VOP_UPDATE(ap->a_vp, NULL, NULL, wait));
95 1.1 mycroft }
96 1.1 mycroft
97 1.1 mycroft int
98 1.4 kleink genfs_seek(v)
99 1.4 kleink void *v;
100 1.4 kleink {
101 1.4 kleink struct vop_seek_args /* {
102 1.4 kleink struct vnode *a_vp;
103 1.4 kleink off_t a_oldoff;
104 1.4 kleink off_t a_newoff;
105 1.4 kleink struct ucred *a_ucred;
106 1.4 kleink } */ *ap = v;
107 1.4 kleink
108 1.4 kleink if (ap->a_newoff < 0)
109 1.4 kleink return (EINVAL);
110 1.4 kleink
111 1.4 kleink return (0);
112 1.4 kleink }
113 1.4 kleink
114 1.4 kleink int
115 1.1 mycroft genfs_abortop(v)
116 1.1 mycroft void *v;
117 1.1 mycroft {
118 1.1 mycroft struct vop_abortop_args /* {
119 1.1 mycroft struct vnode *a_dvp;
120 1.1 mycroft struct componentname *a_cnp;
121 1.1 mycroft } */ *ap = v;
122 1.1 mycroft
123 1.1 mycroft if ((ap->a_cnp->cn_flags & (HASBUF | SAVESTART)) == HASBUF)
124 1.1 mycroft FREE(ap->a_cnp->cn_pnbuf, M_NAMEI);
125 1.1 mycroft return (0);
126 1.1 mycroft }
127 1.1 mycroft
128 1.1 mycroft /*ARGSUSED*/
129 1.1 mycroft int
130 1.1 mycroft genfs_badop(v)
131 1.1 mycroft void *v;
132 1.1 mycroft {
133 1.1 mycroft
134 1.1 mycroft panic("genfs: bad op");
135 1.1 mycroft }
136 1.1 mycroft
137 1.1 mycroft /*ARGSUSED*/
138 1.1 mycroft int
139 1.1 mycroft genfs_nullop(v)
140 1.1 mycroft void *v;
141 1.1 mycroft {
142 1.1 mycroft
143 1.1 mycroft return (0);
144 1.10 kleink }
145 1.10 kleink
146 1.10 kleink /*ARGSUSED*/
147 1.10 kleink int
148 1.10 kleink genfs_einval(v)
149 1.10 kleink void *v;
150 1.10 kleink {
151 1.10 kleink
152 1.10 kleink return (EINVAL);
153 1.1 mycroft }
154 1.1 mycroft
155 1.1 mycroft /*ARGSUSED*/
156 1.1 mycroft int
157 1.1 mycroft genfs_eopnotsupp(v)
158 1.1 mycroft void *v;
159 1.1 mycroft {
160 1.1 mycroft
161 1.1 mycroft return (EOPNOTSUPP);
162 1.1 mycroft }
163 1.1 mycroft
164 1.11.4.5 thorpej /*
165 1.11.4.5 thorpej * Called when an fs doesn't support a particular vop but the vop needs to
166 1.11.4.5 thorpej * vrele, vput, or vunlock passed in vnodes.
167 1.11.4.5 thorpej */
168 1.11.4.5 thorpej int
169 1.11.4.5 thorpej genfs_eopnotsupp_rele(v)
170 1.11.4.5 thorpej void *v;
171 1.11.4.5 thorpej {
172 1.11.4.5 thorpej struct vop_generic_args /*
173 1.11.4.5 thorpej struct vnodeop_desc *a_desc;
174 1.11.4.5 thorpej / * other random data follows, presumably * /
175 1.11.4.5 thorpej } */ *ap = v;
176 1.11.4.5 thorpej struct vnodeop_desc *desc = ap->a_desc;
177 1.11.4.5 thorpej struct vnode *vp;
178 1.11.4.5 thorpej int flags, i, j, offset;
179 1.11.4.5 thorpej
180 1.11.4.5 thorpej flags = desc->vdesc_flags;
181 1.11.4.5 thorpej for (i = 0; i < VDESC_MAX_VPS; flags >>=1, i++) {
182 1.11.4.5 thorpej if ((offset = desc->vdesc_vp_offsets[i]) == VDESC_NO_OFFSET)
183 1.11.4.5 thorpej break; /* stop at end of list */
184 1.11.4.5 thorpej if ((j = flags & VDESC_VP0_WILLPUT)) {
185 1.11.4.5 thorpej vp = *VOPARG_OFFSETTO(struct vnode**,offset,ap);
186 1.11.4.5 thorpej switch (j) {
187 1.11.4.5 thorpej case VDESC_VP0_WILLPUT:
188 1.11.4.5 thorpej vput(vp);
189 1.11.4.5 thorpej break;
190 1.11.4.5 thorpej case VDESC_VP0_WILLUNLOCK:
191 1.11.4.5 thorpej VOP_UNLOCK(vp, 0);
192 1.11.4.5 thorpej break;
193 1.11.4.5 thorpej case VDESC_VP0_WILLRELE:
194 1.11.4.5 thorpej vrele(vp);
195 1.11.4.5 thorpej break;
196 1.11.4.5 thorpej }
197 1.11.4.5 thorpej }
198 1.11.4.5 thorpej }
199 1.11.4.5 thorpej
200 1.11.4.5 thorpej return (EOPNOTSUPP);
201 1.11.4.5 thorpej }
202 1.11.4.5 thorpej
203 1.1 mycroft /*ARGSUSED*/
204 1.1 mycroft int
205 1.1 mycroft genfs_ebadf(v)
206 1.1 mycroft void *v;
207 1.1 mycroft {
208 1.1 mycroft
209 1.1 mycroft return (EBADF);
210 1.9 matthias }
211 1.9 matthias
212 1.9 matthias /* ARGSUSED */
213 1.9 matthias int
214 1.9 matthias genfs_enoioctl(v)
215 1.9 matthias void *v;
216 1.9 matthias {
217 1.9 matthias
218 1.9 matthias return (ENOTTY);
219 1.6 fvdl }
220 1.6 fvdl
221 1.6 fvdl
222 1.6 fvdl /*
223 1.6 fvdl * Eliminate all activity associated with the requested vnode
224 1.6 fvdl * and with all vnodes aliased to the requested vnode.
225 1.6 fvdl */
226 1.6 fvdl int
227 1.6 fvdl genfs_revoke(v)
228 1.6 fvdl void *v;
229 1.6 fvdl {
230 1.6 fvdl struct vop_revoke_args /* {
231 1.6 fvdl struct vnode *a_vp;
232 1.6 fvdl int a_flags;
233 1.6 fvdl } */ *ap = v;
234 1.6 fvdl struct vnode *vp, *vq;
235 1.6 fvdl struct proc *p = curproc; /* XXX */
236 1.6 fvdl
237 1.6 fvdl #ifdef DIAGNOSTIC
238 1.6 fvdl if ((ap->a_flags & REVOKEALL) == 0)
239 1.6 fvdl panic("genfs_revoke: not revokeall");
240 1.6 fvdl #endif
241 1.6 fvdl
242 1.6 fvdl vp = ap->a_vp;
243 1.6 fvdl simple_lock(&vp->v_interlock);
244 1.6 fvdl
245 1.6 fvdl if (vp->v_flag & VALIASED) {
246 1.6 fvdl /*
247 1.6 fvdl * If a vgone (or vclean) is already in progress,
248 1.6 fvdl * wait until it is done and return.
249 1.6 fvdl */
250 1.6 fvdl if (vp->v_flag & VXLOCK) {
251 1.6 fvdl vp->v_flag |= VXWANT;
252 1.6 fvdl simple_unlock(&vp->v_interlock);
253 1.6 fvdl tsleep((caddr_t)vp, PINOD, "vop_revokeall", 0);
254 1.6 fvdl return (0);
255 1.6 fvdl }
256 1.6 fvdl /*
257 1.6 fvdl * Ensure that vp will not be vgone'd while we
258 1.6 fvdl * are eliminating its aliases.
259 1.6 fvdl */
260 1.6 fvdl vp->v_flag |= VXLOCK;
261 1.6 fvdl simple_unlock(&vp->v_interlock);
262 1.6 fvdl while (vp->v_flag & VALIASED) {
263 1.6 fvdl simple_lock(&spechash_slock);
264 1.6 fvdl for (vq = *vp->v_hashchain; vq; vq = vq->v_specnext) {
265 1.6 fvdl if (vq->v_rdev != vp->v_rdev ||
266 1.6 fvdl vq->v_type != vp->v_type || vp == vq)
267 1.6 fvdl continue;
268 1.6 fvdl simple_unlock(&spechash_slock);
269 1.6 fvdl vgone(vq);
270 1.6 fvdl break;
271 1.6 fvdl }
272 1.6 fvdl if (vq == NULLVP)
273 1.6 fvdl simple_unlock(&spechash_slock);
274 1.6 fvdl }
275 1.6 fvdl /*
276 1.6 fvdl * Remove the lock so that vgone below will
277 1.6 fvdl * really eliminate the vnode after which time
278 1.6 fvdl * vgone will awaken any sleepers.
279 1.6 fvdl */
280 1.6 fvdl simple_lock(&vp->v_interlock);
281 1.6 fvdl vp->v_flag &= ~VXLOCK;
282 1.6 fvdl }
283 1.6 fvdl vgonel(vp, p);
284 1.6 fvdl return (0);
285 1.6 fvdl }
286 1.6 fvdl
287 1.6 fvdl /*
288 1.11.4.5 thorpej * Lock the node.
289 1.6 fvdl */
290 1.6 fvdl int
291 1.11.4.5 thorpej genfs_lock(v)
292 1.6 fvdl void *v;
293 1.6 fvdl {
294 1.6 fvdl struct vop_lock_args /* {
295 1.6 fvdl struct vnode *a_vp;
296 1.6 fvdl int a_flags;
297 1.6 fvdl struct proc *a_p;
298 1.6 fvdl } */ *ap = v;
299 1.6 fvdl struct vnode *vp = ap->a_vp;
300 1.6 fvdl
301 1.11.4.5 thorpej return (lockmgr(&vp->v_lock, ap->a_flags, &vp->v_interlock));
302 1.6 fvdl }
303 1.6 fvdl
304 1.6 fvdl /*
305 1.11.4.5 thorpej * Unlock the node.
306 1.6 fvdl */
307 1.6 fvdl int
308 1.11.4.5 thorpej genfs_unlock(v)
309 1.6 fvdl void *v;
310 1.6 fvdl {
311 1.6 fvdl struct vop_unlock_args /* {
312 1.6 fvdl struct vnode *a_vp;
313 1.6 fvdl int a_flags;
314 1.6 fvdl struct proc *a_p;
315 1.6 fvdl } */ *ap = v;
316 1.6 fvdl struct vnode *vp = ap->a_vp;
317 1.6 fvdl
318 1.11.4.5 thorpej return (lockmgr(&vp->v_lock, ap->a_flags | LK_RELEASE,
319 1.11.4.5 thorpej &vp->v_interlock));
320 1.6 fvdl }
321 1.6 fvdl
322 1.6 fvdl /*
323 1.11.4.5 thorpej * Return whether or not the node is locked.
324 1.6 fvdl */
325 1.6 fvdl int
326 1.11.4.5 thorpej genfs_islocked(v)
327 1.6 fvdl void *v;
328 1.6 fvdl {
329 1.6 fvdl struct vop_islocked_args /* {
330 1.6 fvdl struct vnode *a_vp;
331 1.6 fvdl } */ *ap = v;
332 1.6 fvdl struct vnode *vp = ap->a_vp;
333 1.6 fvdl
334 1.11.4.5 thorpej return (lockstatus(&vp->v_lock));
335 1.11.4.5 thorpej }
336 1.11.4.5 thorpej
337 1.11.4.5 thorpej /*
338 1.11.4.5 thorpej * Stubs to use when there is no locking to be done on the underlying object.
339 1.11.4.5 thorpej */
340 1.11.4.5 thorpej int
341 1.11.4.5 thorpej genfs_nolock(v)
342 1.11.4.5 thorpej void *v;
343 1.11.4.5 thorpej {
344 1.11.4.5 thorpej struct vop_lock_args /* {
345 1.11.4.5 thorpej struct vnode *a_vp;
346 1.11.4.5 thorpej int a_flags;
347 1.11.4.5 thorpej struct proc *a_p;
348 1.11.4.5 thorpej } */ *ap = v;
349 1.11.4.5 thorpej
350 1.11.4.5 thorpej /*
351 1.11.4.5 thorpej * Since we are not using the lock manager, we must clear
352 1.11.4.5 thorpej * the interlock here.
353 1.11.4.5 thorpej */
354 1.11.4.5 thorpej if (ap->a_flags & LK_INTERLOCK)
355 1.11.4.5 thorpej simple_unlock(&ap->a_vp->v_interlock);
356 1.11.4.5 thorpej return (0);
357 1.11.4.5 thorpej }
358 1.11.4.5 thorpej
359 1.11.4.5 thorpej int
360 1.11.4.5 thorpej genfs_nounlock(v)
361 1.11.4.5 thorpej void *v;
362 1.11.4.5 thorpej {
363 1.11.4.5 thorpej return (0);
364 1.11.4.5 thorpej }
365 1.11.4.5 thorpej
366 1.11.4.5 thorpej int
367 1.11.4.5 thorpej genfs_noislocked(v)
368 1.11.4.5 thorpej void *v;
369 1.11.4.5 thorpej {
370 1.11.4.5 thorpej return (0);
371 1.8 thorpej }
372 1.8 thorpej
373 1.8 thorpej /*
374 1.8 thorpej * Local lease check for NFS servers. Just set up args and let
375 1.8 thorpej * nqsrv_getlease() do the rest. If NFSSERVER is not in the kernel,
376 1.8 thorpej * this is a null operation.
377 1.8 thorpej */
378 1.8 thorpej int
379 1.8 thorpej genfs_lease_check(v)
380 1.8 thorpej void *v;
381 1.8 thorpej {
382 1.8 thorpej #ifdef NFSSERVER
383 1.8 thorpej struct vop_lease_args /* {
384 1.8 thorpej struct vnode *a_vp;
385 1.8 thorpej struct proc *a_p;
386 1.8 thorpej struct ucred *a_cred;
387 1.8 thorpej int a_flag;
388 1.8 thorpej } */ *ap = v;
389 1.8 thorpej u_int32_t duration = 0;
390 1.8 thorpej int cache;
391 1.8 thorpej u_quad_t frev;
392 1.8 thorpej
393 1.8 thorpej (void) nqsrv_getlease(ap->a_vp, &duration, ND_CHECK | ap->a_flag,
394 1.8 thorpej NQLOCALSLP, ap->a_p, (struct mbuf *)0, &cache, &frev, ap->a_cred);
395 1.8 thorpej return (0);
396 1.8 thorpej #else
397 1.8 thorpej return (0);
398 1.8 thorpej #endif /* NFSSERVER */
399 1.11.4.1 chs }
400 1.11.4.1 chs
401 1.11.4.1 chs /*
402 1.11.4.1 chs * generic VM getpages routine.
403 1.11.4.1 chs * Return PG_BUSY pages for the given range,
404 1.11.4.1 chs * reading from backing store if necessary.
405 1.11.4.1 chs */
406 1.11.4.4 chs
407 1.11.4.1 chs int
408 1.11.4.1 chs genfs_getpages(v)
409 1.11.4.1 chs void *v;
410 1.11.4.1 chs {
411 1.11.4.1 chs struct vop_getpages_args /* {
412 1.11.4.1 chs struct vnode *a_vp;
413 1.11.4.6 chs voff_t a_offset;
414 1.11.4.1 chs vm_page_t *a_m;
415 1.11.4.1 chs int *a_count;
416 1.11.4.1 chs int a_centeridx;
417 1.11.4.1 chs vm_prot_t a_access_type;
418 1.11.4.1 chs int a_advice;
419 1.11.4.1 chs int a_flags;
420 1.11.4.1 chs } */ *ap = v;
421 1.11.4.1 chs
422 1.11.4.4 chs off_t eof, offset, origoffset, startoffset, endoffset;
423 1.11.4.1 chs daddr_t lbn, blkno;
424 1.11.4.4 chs int s, i, error, npages, npgs, run, ridx, pidx, pcount;
425 1.11.4.2 chs int bsize, bshift, dev_bshift, dev_bsize;
426 1.11.4.1 chs int flags = ap->a_flags;
427 1.11.4.2 chs size_t bytes, iobytes, tailbytes, totalbytes, skipbytes;
428 1.11.4.2 chs boolean_t sawhole = FALSE;
429 1.11.4.1 chs char *kva;
430 1.11.4.1 chs struct buf *bp, *mbp;
431 1.11.4.1 chs struct vnode *vp = ap->a_vp;
432 1.11.4.1 chs struct uvm_object *uobj = &vp->v_uvm.u_obj;
433 1.11.4.4 chs struct vm_page *pgs[16]; /* XXX 16 */
434 1.11.4.2 chs struct ucred *cred = curproc->p_ucred; /* XXX curproc */
435 1.11.4.1 chs UVMHIST_FUNC("genfs_getpages"); UVMHIST_CALLED(ubchist);
436 1.11.4.1 chs
437 1.11.4.1 chs #ifdef DIAGNOSTIC
438 1.11.4.1 chs if (ap->a_centeridx < 0 || ap->a_centeridx > *ap->a_count) {
439 1.11.4.1 chs panic("genfs_getpages: centeridx %d out of range",
440 1.11.4.1 chs ap->a_centeridx);
441 1.11.4.1 chs }
442 1.11.4.1 chs if (ap->a_offset & (PAGE_SIZE - 1)) {
443 1.11.4.1 chs panic("genfs_getpages: offset 0x%x", (int)ap->a_offset);
444 1.11.4.1 chs }
445 1.11.4.4 chs if (*ap->a_count < 0) {
446 1.11.4.4 chs panic("genfs_getpages: count %d < 0", *ap->a_count);
447 1.11.4.4 chs }
448 1.11.4.1 chs #endif
449 1.11.4.1 chs
450 1.11.4.1 chs /*
451 1.11.4.1 chs * Bounds-check the request.
452 1.11.4.1 chs */
453 1.11.4.1 chs
454 1.11.4.4 chs eof = vp->v_uvm.u_size;
455 1.11.4.4 chs if (ap->a_offset >= eof) {
456 1.11.4.1 chs if ((flags & PGO_LOCKED) == 0) {
457 1.11.4.1 chs simple_unlock(&uobj->vmobjlock);
458 1.11.4.1 chs }
459 1.11.4.4 chs UVMHIST_LOG(ubchist, "off 0x%x count %d goes past EOF 0x%x",
460 1.11.4.4 chs (int)ap->a_offset, *ap->a_count, (int)eof,0);
461 1.11.4.2 chs return EINVAL;
462 1.11.4.1 chs }
463 1.11.4.1 chs
464 1.11.4.1 chs /*
465 1.11.4.1 chs * For PGO_LOCKED requests, just return whatever's in memory.
466 1.11.4.1 chs */
467 1.11.4.1 chs
468 1.11.4.1 chs if (flags & PGO_LOCKED) {
469 1.11.4.1 chs uvn_findpages(uobj, ap->a_offset, ap->a_count, ap->a_m,
470 1.11.4.1 chs UFP_NOWAIT|UFP_NOALLOC|UFP_NORDONLY);
471 1.11.4.1 chs
472 1.11.4.2 chs return ap->a_m[ap->a_centeridx] == NULL ? EBUSY : 0;
473 1.11.4.1 chs }
474 1.11.4.1 chs
475 1.11.4.4 chs if (ap->a_offset + ((*ap->a_count - 1) << PAGE_SHIFT) >= eof) {
476 1.11.4.4 chs panic("genfs_getpages: non LOCKED req past EOF vp %p", vp);
477 1.11.4.4 chs }
478 1.11.4.4 chs
479 1.11.4.1 chs /* vnode is VOP_LOCKed, uobj is locked */
480 1.11.4.1 chs
481 1.11.4.1 chs error = 0;
482 1.11.4.1 chs
483 1.11.4.1 chs /*
484 1.11.4.4 chs * find the requested pages and make some simple checks.
485 1.11.4.4 chs * leave space in the page array for a whole block.
486 1.11.4.1 chs */
487 1.11.4.1 chs
488 1.11.4.4 chs bshift = vp->v_mount->mnt_fs_bshift;
489 1.11.4.4 chs bsize = 1 << bshift;
490 1.11.4.4 chs dev_bshift = vp->v_mount->mnt_dev_bshift;
491 1.11.4.4 chs dev_bsize = 1 << dev_bshift;
492 1.11.4.4 chs
493 1.11.4.4 chs npages = *ap->a_count;
494 1.11.4.4 chs origoffset = ap->a_offset;
495 1.11.4.4 chs startoffset = origoffset & ~((off_t)bsize - 1);
496 1.11.4.4 chs endoffset = round_page((origoffset + (npages << PAGE_SHIFT)
497 1.11.4.4 chs + bsize - 1) & ~((off_t)bsize - 1));
498 1.11.4.4 chs ridx = (origoffset - startoffset) >> PAGE_SHIFT;
499 1.11.4.4 chs
500 1.11.4.4 chs memset(pgs, 0, sizeof(pgs));
501 1.11.4.4 chs uvn_findpages(uobj, origoffset, &npages, &pgs[ridx], UFP_ALL);
502 1.11.4.2 chs
503 1.11.4.1 chs /*
504 1.11.4.4 chs * if PGO_OVERWRITE is set, don't bother reading the pages.
505 1.11.4.2 chs * PGO_OVERWRITE also means that the caller guarantees
506 1.11.4.4 chs * that the pages already have backing store allocated.
507 1.11.4.1 chs */
508 1.11.4.1 chs
509 1.11.4.2 chs if (flags & PGO_OVERWRITE) {
510 1.11.4.2 chs UVMHIST_LOG(ubchist, "PGO_OVERWRITE",0,0,0,0);
511 1.11.4.1 chs
512 1.11.4.2 chs /* XXX for now, zero the page if we allocated it */
513 1.11.4.4 chs for (i = 0; i < npages; i++) {
514 1.11.4.4 chs struct vm_page *pg = pgs[ridx + i];
515 1.11.4.4 chs if (pg->flags & PG_FAKE) {
516 1.11.4.4 chs uvm_pagezero(pg);
517 1.11.4.4 chs pg->flags &= ~PG_FAKE;
518 1.11.4.4 chs }
519 1.11.4.2 chs }
520 1.11.4.1 chs
521 1.11.4.2 chs simple_unlock(&uobj->vmobjlock);
522 1.11.4.2 chs goto out;
523 1.11.4.2 chs }
524 1.11.4.1 chs
525 1.11.4.1 chs /*
526 1.11.4.4 chs * if the pages are already resident, just return them.
527 1.11.4.1 chs */
528 1.11.4.1 chs
529 1.11.4.4 chs for (i = 0; i < npages; i++) {
530 1.11.4.4 chs struct vm_page *pg = pgs[ridx + i];
531 1.11.4.3 chs
532 1.11.4.4 chs if ((pg->flags & PG_FAKE) != 0 ||
533 1.11.4.4 chs ((ap->a_access_type & VM_PROT_WRITE) &&
534 1.11.4.4 chs (pg->flags & PG_RDONLY))) {
535 1.11.4.4 chs break;
536 1.11.4.4 chs }
537 1.11.4.4 chs }
538 1.11.4.4 chs if (i == npages) {
539 1.11.4.4 chs UVMHIST_LOG(ubchist, "returning cached pages", 0,0,0,0);
540 1.11.4.2 chs simple_unlock(&uobj->vmobjlock);
541 1.11.4.3 chs goto out;
542 1.11.4.1 chs }
543 1.11.4.1 chs
544 1.11.4.1 chs /*
545 1.11.4.2 chs * the page wasn't resident and we're not overwriting,
546 1.11.4.2 chs * so we're going to have to do some i/o.
547 1.11.4.4 chs * find any additional pages needed to cover the expanded range.
548 1.11.4.1 chs */
549 1.11.4.1 chs
550 1.11.4.4 chs if (startoffset != origoffset) {
551 1.11.4.4 chs UVMHIST_LOG(ubchist, "reset npages start 0x%x end 0x%x",
552 1.11.4.4 chs (int)startoffset, (int)endoffset, 0,0);
553 1.11.4.4 chs npages = (endoffset - startoffset) >> PAGE_SHIFT;
554 1.11.4.4 chs if (npages == 0) {
555 1.11.4.4 chs panic("XXX getpages npages = 0");
556 1.11.4.4 chs }
557 1.11.4.4 chs npgs = npages;
558 1.11.4.4 chs uvn_findpages(uobj, startoffset, &npgs, pgs, UFP_ALL);
559 1.11.4.1 chs }
560 1.11.4.2 chs simple_unlock(&uobj->vmobjlock);
561 1.11.4.1 chs
562 1.11.4.1 chs /*
563 1.11.4.2 chs * read the desired page(s).
564 1.11.4.1 chs */
565 1.11.4.1 chs
566 1.11.4.2 chs totalbytes = npages << PAGE_SHIFT;
567 1.11.4.4 chs bytes = min(totalbytes,
568 1.11.4.4 chs (vp->v_uvm.u_size - startoffset + dev_bsize - 1) &
569 1.11.4.1 chs ~(dev_bsize - 1));
570 1.11.4.2 chs tailbytes = totalbytes - bytes;
571 1.11.4.2 chs skipbytes = 0;
572 1.11.4.1 chs
573 1.11.4.2 chs kva = (void *)uvm_pagermapin(pgs, npages, M_WAITOK);
574 1.11.4.1 chs
575 1.11.4.1 chs s = splbio();
576 1.11.4.1 chs mbp = pool_get(&bufpool, PR_WAITOK);
577 1.11.4.1 chs splx(s);
578 1.11.4.1 chs mbp->b_bufsize = bytes;
579 1.11.4.4 chs mbp->b_data = kva;
580 1.11.4.2 chs mbp->b_resid = mbp->b_bcount = bytes;
581 1.11.4.1 chs mbp->b_flags = B_BUSY|B_READ| (flags & PGO_SYNCIO ? 0 : B_CALL);
582 1.11.4.1 chs mbp->b_iodone = uvm_aio_biodone;
583 1.11.4.1 chs mbp->b_vp = vp;
584 1.11.4.1 chs
585 1.11.4.4 chs /*
586 1.11.4.4 chs * if EOF is in the middle of the last page, zero the part past EOF.
587 1.11.4.4 chs */
588 1.11.4.4 chs
589 1.11.4.4 chs if (tailbytes > 0) {
590 1.11.4.4 chs memset(kva + bytes, 0, tailbytes);
591 1.11.4.4 chs }
592 1.11.4.4 chs
593 1.11.4.4 chs /*
594 1.11.4.4 chs * now loop over the pages, reading as needed.
595 1.11.4.4 chs */
596 1.11.4.4 chs
597 1.11.4.1 chs bp = NULL;
598 1.11.4.4 chs offset = startoffset;
599 1.11.4.1 chs for (; bytes > 0; offset += iobytes, bytes -= iobytes) {
600 1.11.4.2 chs
601 1.11.4.2 chs /*
602 1.11.4.2 chs * skip pages which don't need to be read.
603 1.11.4.2 chs */
604 1.11.4.2 chs
605 1.11.4.2 chs pidx = (offset - startoffset) >> PAGE_SHIFT;
606 1.11.4.2 chs while ((pgs[pidx]->flags & PG_FAKE) == 0) {
607 1.11.4.2 chs size_t b;
608 1.11.4.2 chs
609 1.11.4.2 chs if (offset & (PAGE_SIZE - 1)) {
610 1.11.4.2 chs panic("genfs_getpages: skipping from middle "
611 1.11.4.2 chs "of page");
612 1.11.4.2 chs }
613 1.11.4.2 chs
614 1.11.4.2 chs b = min(PAGE_SIZE, bytes);
615 1.11.4.2 chs offset += b;
616 1.11.4.2 chs bytes -= b;
617 1.11.4.2 chs skipbytes += b;
618 1.11.4.2 chs pidx++;
619 1.11.4.4 chs UVMHIST_LOG(ubchist, "skipping, new offset 0x%x",
620 1.11.4.4 chs (int)offset, 0,0,0);
621 1.11.4.2 chs if (bytes == 0) {
622 1.11.4.2 chs goto loopdone;
623 1.11.4.2 chs }
624 1.11.4.2 chs }
625 1.11.4.1 chs
626 1.11.4.1 chs /*
627 1.11.4.1 chs * bmap the file to find out the blkno to read from and
628 1.11.4.4 chs * how much we can read in one i/o. if bmap returns an error,
629 1.11.4.4 chs * skip the rest of the top-level i/o.
630 1.11.4.1 chs */
631 1.11.4.1 chs
632 1.11.4.2 chs lbn = offset >> bshift;
633 1.11.4.1 chs error = VOP_BMAP(vp, lbn, NULL, &blkno, &run);
634 1.11.4.1 chs if (error) {
635 1.11.4.1 chs UVMHIST_LOG(ubchist, "VOP_BMAP lbn 0x%x -> %d\n",
636 1.11.4.1 chs lbn, error,0,0);
637 1.11.4.4 chs skipbytes += bytes;
638 1.11.4.4 chs tailbytes = 0;
639 1.11.4.4 chs goto loopdone;
640 1.11.4.1 chs }
641 1.11.4.1 chs
642 1.11.4.2 chs /*
643 1.11.4.4 chs * see how many pages can be read with this i/o.
644 1.11.4.2 chs * reduce the i/o size if necessary.
645 1.11.4.2 chs */
646 1.11.4.1 chs
647 1.11.4.2 chs iobytes = min(((lbn + 1 + run) << bshift) - offset, bytes);
648 1.11.4.2 chs if (offset + iobytes > round_page(offset)) {
649 1.11.4.2 chs pcount = 1;
650 1.11.4.2 chs while (pidx + pcount < npages &&
651 1.11.4.2 chs pgs[pidx + pcount]->flags & PG_FAKE) {
652 1.11.4.2 chs pcount++;
653 1.11.4.1 chs }
654 1.11.4.2 chs iobytes = min(iobytes, (pcount << PAGE_SHIFT) -
655 1.11.4.2 chs (offset - trunc_page(offset)));
656 1.11.4.2 chs }
657 1.11.4.1 chs
658 1.11.4.2 chs /*
659 1.11.4.2 chs * if this block isn't allocated, zero it instead of reading it.
660 1.11.4.4 chs * if this is a read access, mark the pages we zeroed PG_RDONLY.
661 1.11.4.2 chs */
662 1.11.4.1 chs
663 1.11.4.2 chs if (blkno == (daddr_t)-1) {
664 1.11.4.2 chs UVMHIST_LOG(ubchist, "lbn 0x%x -> HOLE", lbn,0,0,0);
665 1.11.4.1 chs
666 1.11.4.2 chs sawhole = TRUE;
667 1.11.4.4 chs memset(kva + (offset - startoffset), 0, iobytes);
668 1.11.4.4 chs
669 1.11.4.4 chs if (ap->a_access_type == VM_PROT_READ) {
670 1.11.4.4 chs int holepages =
671 1.11.4.4 chs (round_page(offset + iobytes) -
672 1.11.4.4 chs trunc_page(offset)) >> PAGE_SHIFT;
673 1.11.4.4 chs for (i = 0; i < holepages; i++) {
674 1.11.4.4 chs pgs[pidx + i]->flags |= PG_RDONLY;
675 1.11.4.4 chs }
676 1.11.4.4 chs }
677 1.11.4.1 chs continue;
678 1.11.4.1 chs }
679 1.11.4.1 chs
680 1.11.4.1 chs /*
681 1.11.4.1 chs * allocate a sub-buf for this piece of the i/o
682 1.11.4.1 chs * (or just use mbp if there's only 1 piece),
683 1.11.4.1 chs * and start it going.
684 1.11.4.1 chs */
685 1.11.4.1 chs
686 1.11.4.4 chs if (offset == startoffset && iobytes == bytes) {
687 1.11.4.1 chs bp = mbp;
688 1.11.4.1 chs } else {
689 1.11.4.1 chs s = splbio();
690 1.11.4.1 chs bp = pool_get(&bufpool, PR_WAITOK);
691 1.11.4.1 chs splx(s);
692 1.11.4.4 chs bp->b_data = kva + offset - startoffset;
693 1.11.4.2 chs bp->b_resid = bp->b_bcount = iobytes;
694 1.11.4.1 chs bp->b_flags = B_BUSY|B_READ|B_CALL;
695 1.11.4.1 chs bp->b_iodone = uvm_aio_biodone1;
696 1.11.4.1 chs bp->b_vp = vp;
697 1.11.4.1 chs }
698 1.11.4.1 chs bp->b_lblkno = 0;
699 1.11.4.1 chs bp->b_private = mbp;
700 1.11.4.1 chs
701 1.11.4.1 chs /* adjust physical blkno for partial blocks */
702 1.11.4.1 chs bp->b_blkno = blkno + ((offset - (lbn << bshift)) >>
703 1.11.4.1 chs dev_bshift);
704 1.11.4.2 chs
705 1.11.4.2 chs UVMHIST_LOG(ubchist, "bp %p offset 0x%x bcount 0x%x blkno 0x%x",
706 1.11.4.2 chs bp, (int)offset, (int)iobytes, bp->b_blkno);
707 1.11.4.1 chs
708 1.11.4.1 chs VOP_STRATEGY(bp);
709 1.11.4.1 chs }
710 1.11.4.2 chs
711 1.11.4.4 chs loopdone:
712 1.11.4.4 chs s = splbio();
713 1.11.4.2 chs if (skipbytes) {
714 1.11.4.2 chs mbp->b_resid -= skipbytes;
715 1.11.4.2 chs if (mbp->b_resid == 0) {
716 1.11.4.2 chs biodone(mbp);
717 1.11.4.2 chs }
718 1.11.4.2 chs }
719 1.11.4.4 chs splx(s);
720 1.11.4.1 chs if ((flags & PGO_SYNCIO) == 0) {
721 1.11.4.2 chs UVMHIST_LOG(ubchist, "returning PEND",0,0,0,0);
722 1.11.4.2 chs return EINPROGRESS;
723 1.11.4.1 chs }
724 1.11.4.1 chs if (bp != NULL) {
725 1.11.4.1 chs error = biowait(mbp);
726 1.11.4.1 chs }
727 1.11.4.1 chs s = splbio();
728 1.11.4.1 chs pool_put(&bufpool, mbp);
729 1.11.4.1 chs splx(s);
730 1.11.4.4 chs for (i = 0; i < npages; i++) {
731 1.11.4.4 chs UVMHIST_LOG(ubchist, "pgs[%d][0] = 0x%x",
732 1.11.4.4 chs i, *(int *)(kva + (i << PAGE_SHIFT)), 0,0);
733 1.11.4.4 chs }
734 1.11.4.2 chs uvm_pagermapout((vaddr_t)kva, npages);
735 1.11.4.2 chs
736 1.11.4.2 chs /*
737 1.11.4.2 chs * if this we encountered a hole then we have to do a little more work.
738 1.11.4.2 chs * for read faults, we must mark the page PG_RDONLY so that future
739 1.11.4.2 chs * write accesses to the page will fault again.
740 1.11.4.2 chs * for write faults, we must make sure that the backing store for
741 1.11.4.2 chs * the page is completely allocated.
742 1.11.4.2 chs */
743 1.11.4.2 chs
744 1.11.4.4 chs if (sawhole && ap->a_access_type == VM_PROT_WRITE) {
745 1.11.4.4 chs error = VOP_BALLOC(vp, startoffset, npages << PAGE_SHIFT,
746 1.11.4.4 chs cred, 0);
747 1.11.4.4 chs if (error) {
748 1.11.4.4 chs UVMHIST_LOG(ubchist, "balloc lbn 0x%x -> %d",
749 1.11.4.4 chs lbn, error,0,0);
750 1.11.4.4 chs goto out;
751 1.11.4.2 chs }
752 1.11.4.2 chs }
753 1.11.4.2 chs
754 1.11.4.2 chs /*
755 1.11.4.2 chs * see if we want to start any readahead.
756 1.11.4.2 chs * XXX writeme
757 1.11.4.2 chs */
758 1.11.4.2 chs
759 1.11.4.2 chs /*
760 1.11.4.2 chs * we're almost done! release the pages...
761 1.11.4.2 chs * for errors, we free the pages.
762 1.11.4.2 chs * otherwise we activate them and mark them as valid and clean.
763 1.11.4.2 chs * also, unbusy all but the center page.
764 1.11.4.2 chs */
765 1.11.4.1 chs
766 1.11.4.1 chs out:
767 1.11.4.1 chs if (error) {
768 1.11.4.1 chs simple_lock(&uobj->vmobjlock);
769 1.11.4.2 chs for (i = 0; i < npages; i++) {
770 1.11.4.2 chs UVMHIST_LOG(ubchist, "examining pg %p flags 0x%x",
771 1.11.4.2 chs pgs[i], pgs[i]->flags, 0,0);
772 1.11.4.2 chs if (pgs[i]->flags & PG_FAKE) {
773 1.11.4.2 chs if (pgs[i]->flags & PG_WANTED) {
774 1.11.4.2 chs wakeup(pgs[i]);
775 1.11.4.2 chs }
776 1.11.4.2 chs uvm_pagefree(pgs[i]);
777 1.11.4.2 chs }
778 1.11.4.1 chs }
779 1.11.4.1 chs simple_unlock(&uobj->vmobjlock);
780 1.11.4.2 chs UVMHIST_LOG(ubchist, "returning error %d", error,0,0,0);
781 1.11.4.2 chs return error;
782 1.11.4.1 chs }
783 1.11.4.2 chs
784 1.11.4.2 chs UVMHIST_LOG(ubchist, "succeeding, npages %d", npages,0,0,0);
785 1.11.4.2 chs simple_lock(&uobj->vmobjlock);
786 1.11.4.2 chs for (i = 0; i < npages; i++) {
787 1.11.4.4 chs if (pgs[i] == NULL) {
788 1.11.4.4 chs continue;
789 1.11.4.4 chs }
790 1.11.4.2 chs UVMHIST_LOG(ubchist, "examining pg %p flags 0x%x",
791 1.11.4.2 chs pgs[i], pgs[i]->flags, 0,0);
792 1.11.4.2 chs if (pgs[i]->flags & PG_FAKE) {
793 1.11.4.2 chs UVMHIST_LOG(ubchist, "unfaking pg %p offset 0x%x",
794 1.11.4.2 chs pgs[i], (int)pgs[i]->offset,0,0);
795 1.11.4.2 chs pgs[i]->flags &= ~(PG_FAKE);
796 1.11.4.2 chs pmap_clear_modify(PMAP_PGARG(pgs[i]));
797 1.11.4.2 chs pmap_clear_reference(PMAP_PGARG(pgs[i]));
798 1.11.4.2 chs }
799 1.11.4.4 chs if (i < ridx || i >= ridx + *ap->a_count) {
800 1.11.4.2 chs UVMHIST_LOG(ubchist, "unbusy pg %p offset 0x%x",
801 1.11.4.2 chs pgs[i], (int)pgs[i]->offset,0,0);
802 1.11.4.2 chs /*
803 1.11.4.2 chs KASSERT((pgs[i]->flags & PG_RELEASED) == 0);
804 1.11.4.2 chs */
805 1.11.4.2 chs
806 1.11.4.2 chs if (pgs[i]->flags & PG_WANTED) {
807 1.11.4.2 chs wakeup(pgs[i]);
808 1.11.4.2 chs }
809 1.11.4.2 chs pgs[i]->flags &= ~(PG_WANTED|PG_BUSY);
810 1.11.4.2 chs UVM_PAGE_OWN(pgs[i], NULL);
811 1.11.4.2 chs }
812 1.11.4.2 chs }
813 1.11.4.2 chs simple_unlock(&uobj->vmobjlock);
814 1.11.4.4 chs memcpy(ap->a_m, &pgs[ridx], *ap->a_count * sizeof(struct vm_page *));
815 1.11.4.2 chs return 0;
816 1.11.4.1 chs }
817 1.11.4.1 chs
818 1.11.4.1 chs /*
819 1.11.4.1 chs * generic VM putpages routine.
820 1.11.4.1 chs * Write the given range of pages to backing store.
821 1.11.4.1 chs */
822 1.11.4.1 chs int
823 1.11.4.1 chs genfs_putpages(v)
824 1.11.4.1 chs void *v;
825 1.11.4.1 chs {
826 1.11.4.1 chs struct vop_putpages_args /* {
827 1.11.4.1 chs struct vnode *a_vp;
828 1.11.4.1 chs struct vm_page **a_m;
829 1.11.4.1 chs int a_count;
830 1.11.4.1 chs int a_sync;
831 1.11.4.1 chs int *a_rtvals;
832 1.11.4.1 chs } */ *ap = v;
833 1.11.4.1 chs
834 1.11.4.4 chs int s, error, npages, bshift, dev_bshift, dev_bsize, run;
835 1.11.4.4 chs char * kva;
836 1.11.4.4 chs off_t offset, startoffset;
837 1.11.4.4 chs size_t bytes, iobytes, skipbytes;
838 1.11.4.1 chs daddr_t lbn, blkno;
839 1.11.4.1 chs struct vm_page *pg;
840 1.11.4.1 chs struct buf *mbp, *bp;
841 1.11.4.1 chs struct vnode *vp = ap->a_vp;
842 1.11.4.1 chs UVMHIST_FUNC("genfs_putpages"); UVMHIST_CALLED(ubchist);
843 1.11.4.1 chs
844 1.11.4.2 chs error = 0;
845 1.11.4.4 chs npages = ap->a_count;
846 1.11.4.1 chs bshift = vp->v_mount->mnt_fs_bshift;
847 1.11.4.1 chs dev_bshift = vp->v_mount->mnt_dev_bshift;
848 1.11.4.1 chs dev_bsize = 1 << dev_bshift;
849 1.11.4.1 chs
850 1.11.4.1 chs pg = ap->a_m[0];
851 1.11.4.4 chs startoffset = pg->offset;
852 1.11.4.4 chs bytes = min(npages << PAGE_SHIFT,
853 1.11.4.4 chs (vp->v_uvm.u_size - startoffset + dev_bsize - 1) &
854 1.11.4.4 chs ~((off_t)dev_bsize - 1));
855 1.11.4.4 chs skipbytes = 0;
856 1.11.4.1 chs
857 1.11.4.4 chs if (bytes == 0) {
858 1.11.4.4 chs panic("genfs_putpages: bytes == 0??? vp %p", vp);
859 1.11.4.4 chs }
860 1.11.4.4 chs
861 1.11.4.4 chs kva = (void *)uvm_pagermapin(ap->a_m, npages, M_WAITOK);
862 1.11.4.2 chs
863 1.11.4.1 chs s = splbio();
864 1.11.4.1 chs vp->v_numoutput++;
865 1.11.4.1 chs mbp = pool_get(&bufpool, PR_WAITOK);
866 1.11.4.4 chs UVMHIST_LOG(ubchist, "master vp %p bp %p num now %d",
867 1.11.4.4 chs vp, mbp, vp->v_numoutput, 0);
868 1.11.4.1 chs splx(s);
869 1.11.4.4 chs mbp->b_bufsize = npages << PAGE_SHIFT;
870 1.11.4.4 chs mbp->b_data = kva;
871 1.11.4.2 chs mbp->b_resid = mbp->b_bcount = bytes;
872 1.11.4.1 chs mbp->b_flags = B_BUSY|B_WRITE| (ap->a_sync ? 0 : B_CALL) |
873 1.11.4.1 chs (curproc == uvm.pagedaemon_proc ? B_PDAEMON : 0);
874 1.11.4.1 chs mbp->b_iodone = uvm_aio_biodone;
875 1.11.4.1 chs mbp->b_vp = vp;
876 1.11.4.1 chs
877 1.11.4.1 chs bp = NULL;
878 1.11.4.4 chs offset = startoffset;
879 1.11.4.1 chs for (; bytes > 0; offset += iobytes, bytes -= iobytes) {
880 1.11.4.1 chs lbn = offset >> bshift;
881 1.11.4.1 chs error = VOP_BMAP(vp, lbn, NULL, &blkno, &run);
882 1.11.4.1 chs if (error) {
883 1.11.4.4 chs UVMHIST_LOG(ubchist, "VOP_BMAP() -> %d", error,0,0,0);
884 1.11.4.1 chs goto errout;
885 1.11.4.1 chs }
886 1.11.4.1 chs
887 1.11.4.4 chs iobytes = min(((lbn + 1 + run) << bshift) - offset, bytes);
888 1.11.4.1 chs if (blkno == (daddr_t)-1) {
889 1.11.4.4 chs skipbytes += iobytes;
890 1.11.4.4 chs continue;
891 1.11.4.1 chs }
892 1.11.4.1 chs
893 1.11.4.1 chs /* if it's really one i/o, don't make a second buf */
894 1.11.4.4 chs if (offset == startoffset && iobytes == bytes) {
895 1.11.4.1 chs bp = mbp;
896 1.11.4.1 chs } else {
897 1.11.4.1 chs s = splbio();
898 1.11.4.1 chs vp->v_numoutput++;
899 1.11.4.1 chs bp = pool_get(&bufpool, PR_WAITOK);
900 1.11.4.4 chs UVMHIST_LOG(ubchist, "vp %p bp %p num now %d",
901 1.11.4.4 chs vp, bp, vp->v_numoutput, 0);
902 1.11.4.1 chs splx(s);
903 1.11.4.4 chs bp->b_data = kva + offset - pg->offset;
904 1.11.4.2 chs bp->b_resid = bp->b_bcount = iobytes;
905 1.11.4.1 chs bp->b_flags = B_BUSY|B_WRITE|B_CALL;
906 1.11.4.1 chs bp->b_iodone = uvm_aio_biodone1;
907 1.11.4.1 chs bp->b_vp = vp;
908 1.11.4.1 chs }
909 1.11.4.1 chs bp->b_lblkno = 0;
910 1.11.4.1 chs bp->b_private = mbp;
911 1.11.4.1 chs
912 1.11.4.1 chs /* adjust physical blkno for partial blocks */
913 1.11.4.1 chs bp->b_blkno = blkno + ((offset - (lbn << bshift)) >>
914 1.11.4.1 chs dev_bshift);
915 1.11.4.2 chs UVMHIST_LOG(ubchist, "vp %p offset 0x%x bcount 0x%x blkno 0x%x",
916 1.11.4.4 chs vp, (int)offset, (int)bp->b_bcount,
917 1.11.4.4 chs (int)bp->b_blkno);
918 1.11.4.1 chs VOP_STRATEGY(bp);
919 1.11.4.1 chs }
920 1.11.4.4 chs s = splbio();
921 1.11.4.4 chs if (skipbytes) {
922 1.11.4.4 chs mbp->b_resid -= skipbytes;
923 1.11.4.4 chs if (mbp->b_resid == 0) {
924 1.11.4.4 chs biodone(mbp);
925 1.11.4.4 chs }
926 1.11.4.4 chs }
927 1.11.4.4 chs splx(s);
928 1.11.4.1 chs if (!ap->a_sync) {
929 1.11.4.2 chs return EINPROGRESS;
930 1.11.4.1 chs }
931 1.11.4.1 chs
932 1.11.4.1 chs errout:
933 1.11.4.1 chs if (bp != NULL) {
934 1.11.4.1 chs error = biowait(mbp);
935 1.11.4.1 chs }
936 1.11.4.1 chs s = splbio();
937 1.11.4.1 chs pool_put(&bufpool, mbp);
938 1.11.4.1 chs splx(s);
939 1.11.4.4 chs uvm_pagermapout((vaddr_t)kva, npages);
940 1.11.4.1 chs UVMHIST_LOG(ubchist, "returning, error %d", error,0,0,0);
941 1.11.4.2 chs return error;
942 1.1 mycroft }
943