genfs_vnops.c revision 1.37 1 1.37 chs /* $NetBSD: genfs_vnops.c,v 1.37 2001/09/15 20:36:38 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.13 wrstuden #include <sys/fcntl.h>
47 1.1 mycroft #include <sys/malloc.h>
48 1.3 mycroft #include <sys/poll.h>
49 1.37 chs #include <sys/mman.h>
50 1.1 mycroft
51 1.1 mycroft #include <miscfs/genfs/genfs.h>
52 1.37 chs #include <miscfs/genfs/genfs_node.h>
53 1.6 fvdl #include <miscfs/specfs/specdev.h>
54 1.1 mycroft
55 1.21 chs #include <uvm/uvm.h>
56 1.21 chs #include <uvm/uvm_pager.h>
57 1.21 chs
58 1.8 thorpej #ifdef NFSSERVER
59 1.8 thorpej #include <nfs/rpcv2.h>
60 1.8 thorpej #include <nfs/nfsproto.h>
61 1.8 thorpej #include <nfs/nfs.h>
62 1.8 thorpej #include <nfs/nqnfs.h>
63 1.8 thorpej #include <nfs/nfs_var.h>
64 1.8 thorpej #endif
65 1.8 thorpej
66 1.1 mycroft int
67 1.3 mycroft genfs_poll(v)
68 1.1 mycroft void *v;
69 1.1 mycroft {
70 1.3 mycroft struct vop_poll_args /* {
71 1.1 mycroft struct vnode *a_vp;
72 1.3 mycroft int a_events;
73 1.1 mycroft struct proc *a_p;
74 1.1 mycroft } */ *ap = v;
75 1.1 mycroft
76 1.3 mycroft return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
77 1.1 mycroft }
78 1.1 mycroft
79 1.1 mycroft int
80 1.1 mycroft genfs_fsync(v)
81 1.1 mycroft void *v;
82 1.1 mycroft {
83 1.1 mycroft struct vop_fsync_args /* {
84 1.1 mycroft struct vnode *a_vp;
85 1.1 mycroft struct ucred *a_cred;
86 1.7 kleink int a_flags;
87 1.20 fvdl off_t offlo;
88 1.20 fvdl off_t offhi;
89 1.1 mycroft struct proc *a_p;
90 1.1 mycroft } */ *ap = v;
91 1.16 augustss struct vnode *vp = ap->a_vp;
92 1.11 mycroft int wait;
93 1.1 mycroft
94 1.11 mycroft wait = (ap->a_flags & FSYNC_WAIT) != 0;
95 1.11 mycroft vflushbuf(vp, wait);
96 1.11 mycroft if ((ap->a_flags & FSYNC_DATAONLY) != 0)
97 1.7 kleink return (0);
98 1.11 mycroft else
99 1.18 mycroft return (VOP_UPDATE(vp, NULL, NULL, wait ? UPDATE_WAIT : 0));
100 1.1 mycroft }
101 1.1 mycroft
102 1.1 mycroft int
103 1.4 kleink genfs_seek(v)
104 1.4 kleink void *v;
105 1.4 kleink {
106 1.4 kleink struct vop_seek_args /* {
107 1.4 kleink struct vnode *a_vp;
108 1.4 kleink off_t a_oldoff;
109 1.4 kleink off_t a_newoff;
110 1.4 kleink struct ucred *a_ucred;
111 1.4 kleink } */ *ap = v;
112 1.4 kleink
113 1.4 kleink if (ap->a_newoff < 0)
114 1.4 kleink return (EINVAL);
115 1.4 kleink
116 1.4 kleink return (0);
117 1.4 kleink }
118 1.4 kleink
119 1.4 kleink int
120 1.1 mycroft genfs_abortop(v)
121 1.1 mycroft void *v;
122 1.1 mycroft {
123 1.1 mycroft struct vop_abortop_args /* {
124 1.1 mycroft struct vnode *a_dvp;
125 1.1 mycroft struct componentname *a_cnp;
126 1.1 mycroft } */ *ap = v;
127 1.1 mycroft
128 1.1 mycroft if ((ap->a_cnp->cn_flags & (HASBUF | SAVESTART)) == HASBUF)
129 1.19 thorpej PNBUF_PUT(ap->a_cnp->cn_pnbuf);
130 1.1 mycroft return (0);
131 1.13 wrstuden }
132 1.13 wrstuden
133 1.13 wrstuden int
134 1.13 wrstuden genfs_fcntl(v)
135 1.13 wrstuden void *v;
136 1.13 wrstuden {
137 1.13 wrstuden struct vop_fcntl_args /* {
138 1.13 wrstuden struct vnode *a_vp;
139 1.13 wrstuden u_int a_command;
140 1.13 wrstuden caddr_t a_data;
141 1.13 wrstuden int a_fflag;
142 1.13 wrstuden struct ucred *a_cred;
143 1.13 wrstuden struct proc *a_p;
144 1.13 wrstuden } */ *ap = v;
145 1.13 wrstuden
146 1.13 wrstuden if (ap->a_command == F_SETFL)
147 1.13 wrstuden return (0);
148 1.13 wrstuden else
149 1.13 wrstuden return (EOPNOTSUPP);
150 1.1 mycroft }
151 1.1 mycroft
152 1.1 mycroft /*ARGSUSED*/
153 1.1 mycroft int
154 1.1 mycroft genfs_badop(v)
155 1.1 mycroft void *v;
156 1.1 mycroft {
157 1.1 mycroft
158 1.1 mycroft panic("genfs: bad op");
159 1.1 mycroft }
160 1.1 mycroft
161 1.1 mycroft /*ARGSUSED*/
162 1.1 mycroft int
163 1.1 mycroft genfs_nullop(v)
164 1.1 mycroft void *v;
165 1.1 mycroft {
166 1.1 mycroft
167 1.1 mycroft return (0);
168 1.10 kleink }
169 1.10 kleink
170 1.10 kleink /*ARGSUSED*/
171 1.10 kleink int
172 1.10 kleink genfs_einval(v)
173 1.10 kleink void *v;
174 1.10 kleink {
175 1.10 kleink
176 1.10 kleink return (EINVAL);
177 1.1 mycroft }
178 1.1 mycroft
179 1.1 mycroft /*ARGSUSED*/
180 1.1 mycroft int
181 1.1 mycroft genfs_eopnotsupp(v)
182 1.1 mycroft void *v;
183 1.1 mycroft {
184 1.1 mycroft
185 1.1 mycroft return (EOPNOTSUPP);
186 1.1 mycroft }
187 1.1 mycroft
188 1.12 wrstuden /*
189 1.12 wrstuden * Called when an fs doesn't support a particular vop but the vop needs to
190 1.12 wrstuden * vrele, vput, or vunlock passed in vnodes.
191 1.12 wrstuden */
192 1.12 wrstuden int
193 1.12 wrstuden genfs_eopnotsupp_rele(v)
194 1.12 wrstuden void *v;
195 1.12 wrstuden {
196 1.12 wrstuden struct vop_generic_args /*
197 1.12 wrstuden struct vnodeop_desc *a_desc;
198 1.12 wrstuden / * other random data follows, presumably * /
199 1.12 wrstuden } */ *ap = v;
200 1.12 wrstuden struct vnodeop_desc *desc = ap->a_desc;
201 1.12 wrstuden struct vnode *vp;
202 1.12 wrstuden int flags, i, j, offset;
203 1.12 wrstuden
204 1.12 wrstuden flags = desc->vdesc_flags;
205 1.12 wrstuden for (i = 0; i < VDESC_MAX_VPS; flags >>=1, i++) {
206 1.12 wrstuden if ((offset = desc->vdesc_vp_offsets[i]) == VDESC_NO_OFFSET)
207 1.12 wrstuden break; /* stop at end of list */
208 1.12 wrstuden if ((j = flags & VDESC_VP0_WILLPUT)) {
209 1.12 wrstuden vp = *VOPARG_OFFSETTO(struct vnode**,offset,ap);
210 1.12 wrstuden switch (j) {
211 1.12 wrstuden case VDESC_VP0_WILLPUT:
212 1.12 wrstuden vput(vp);
213 1.12 wrstuden break;
214 1.12 wrstuden case VDESC_VP0_WILLUNLOCK:
215 1.12 wrstuden VOP_UNLOCK(vp, 0);
216 1.12 wrstuden break;
217 1.12 wrstuden case VDESC_VP0_WILLRELE:
218 1.12 wrstuden vrele(vp);
219 1.12 wrstuden break;
220 1.12 wrstuden }
221 1.12 wrstuden }
222 1.12 wrstuden }
223 1.12 wrstuden
224 1.12 wrstuden return (EOPNOTSUPP);
225 1.12 wrstuden }
226 1.12 wrstuden
227 1.1 mycroft /*ARGSUSED*/
228 1.1 mycroft int
229 1.1 mycroft genfs_ebadf(v)
230 1.1 mycroft void *v;
231 1.1 mycroft {
232 1.1 mycroft
233 1.1 mycroft return (EBADF);
234 1.9 matthias }
235 1.9 matthias
236 1.9 matthias /* ARGSUSED */
237 1.9 matthias int
238 1.9 matthias genfs_enoioctl(v)
239 1.9 matthias void *v;
240 1.9 matthias {
241 1.9 matthias
242 1.9 matthias return (ENOTTY);
243 1.6 fvdl }
244 1.6 fvdl
245 1.6 fvdl
246 1.6 fvdl /*
247 1.15 fvdl * Eliminate all activity associated with the requested vnode
248 1.6 fvdl * and with all vnodes aliased to the requested vnode.
249 1.6 fvdl */
250 1.6 fvdl int
251 1.6 fvdl genfs_revoke(v)
252 1.6 fvdl void *v;
253 1.6 fvdl {
254 1.6 fvdl struct vop_revoke_args /* {
255 1.6 fvdl struct vnode *a_vp;
256 1.6 fvdl int a_flags;
257 1.6 fvdl } */ *ap = v;
258 1.6 fvdl struct vnode *vp, *vq;
259 1.6 fvdl struct proc *p = curproc; /* XXX */
260 1.6 fvdl
261 1.6 fvdl #ifdef DIAGNOSTIC
262 1.6 fvdl if ((ap->a_flags & REVOKEALL) == 0)
263 1.6 fvdl panic("genfs_revoke: not revokeall");
264 1.6 fvdl #endif
265 1.6 fvdl
266 1.6 fvdl vp = ap->a_vp;
267 1.6 fvdl simple_lock(&vp->v_interlock);
268 1.6 fvdl
269 1.6 fvdl if (vp->v_flag & VALIASED) {
270 1.6 fvdl /*
271 1.6 fvdl * If a vgone (or vclean) is already in progress,
272 1.6 fvdl * wait until it is done and return.
273 1.6 fvdl */
274 1.6 fvdl if (vp->v_flag & VXLOCK) {
275 1.6 fvdl vp->v_flag |= VXWANT;
276 1.6 fvdl simple_unlock(&vp->v_interlock);
277 1.6 fvdl tsleep((caddr_t)vp, PINOD, "vop_revokeall", 0);
278 1.6 fvdl return (0);
279 1.6 fvdl }
280 1.6 fvdl /*
281 1.6 fvdl * Ensure that vp will not be vgone'd while we
282 1.6 fvdl * are eliminating its aliases.
283 1.6 fvdl */
284 1.6 fvdl vp->v_flag |= VXLOCK;
285 1.6 fvdl simple_unlock(&vp->v_interlock);
286 1.6 fvdl while (vp->v_flag & VALIASED) {
287 1.6 fvdl simple_lock(&spechash_slock);
288 1.6 fvdl for (vq = *vp->v_hashchain; vq; vq = vq->v_specnext) {
289 1.6 fvdl if (vq->v_rdev != vp->v_rdev ||
290 1.6 fvdl vq->v_type != vp->v_type || vp == vq)
291 1.6 fvdl continue;
292 1.6 fvdl simple_unlock(&spechash_slock);
293 1.6 fvdl vgone(vq);
294 1.6 fvdl break;
295 1.6 fvdl }
296 1.6 fvdl if (vq == NULLVP)
297 1.6 fvdl simple_unlock(&spechash_slock);
298 1.6 fvdl }
299 1.6 fvdl /*
300 1.6 fvdl * Remove the lock so that vgone below will
301 1.6 fvdl * really eliminate the vnode after which time
302 1.6 fvdl * vgone will awaken any sleepers.
303 1.6 fvdl */
304 1.6 fvdl simple_lock(&vp->v_interlock);
305 1.6 fvdl vp->v_flag &= ~VXLOCK;
306 1.6 fvdl }
307 1.6 fvdl vgonel(vp, p);
308 1.6 fvdl return (0);
309 1.6 fvdl }
310 1.6 fvdl
311 1.6 fvdl /*
312 1.12 wrstuden * Lock the node.
313 1.6 fvdl */
314 1.6 fvdl int
315 1.12 wrstuden genfs_lock(v)
316 1.6 fvdl void *v;
317 1.6 fvdl {
318 1.6 fvdl struct vop_lock_args /* {
319 1.6 fvdl struct vnode *a_vp;
320 1.6 fvdl int a_flags;
321 1.6 fvdl } */ *ap = v;
322 1.6 fvdl struct vnode *vp = ap->a_vp;
323 1.6 fvdl
324 1.12 wrstuden return (lockmgr(&vp->v_lock, ap->a_flags, &vp->v_interlock));
325 1.6 fvdl }
326 1.6 fvdl
327 1.6 fvdl /*
328 1.12 wrstuden * Unlock the node.
329 1.6 fvdl */
330 1.6 fvdl int
331 1.12 wrstuden genfs_unlock(v)
332 1.6 fvdl void *v;
333 1.6 fvdl {
334 1.6 fvdl struct vop_unlock_args /* {
335 1.6 fvdl struct vnode *a_vp;
336 1.6 fvdl int a_flags;
337 1.6 fvdl } */ *ap = v;
338 1.6 fvdl struct vnode *vp = ap->a_vp;
339 1.6 fvdl
340 1.12 wrstuden return (lockmgr(&vp->v_lock, ap->a_flags | LK_RELEASE,
341 1.12 wrstuden &vp->v_interlock));
342 1.6 fvdl }
343 1.6 fvdl
344 1.6 fvdl /*
345 1.12 wrstuden * Return whether or not the node is locked.
346 1.6 fvdl */
347 1.6 fvdl int
348 1.12 wrstuden genfs_islocked(v)
349 1.6 fvdl void *v;
350 1.6 fvdl {
351 1.6 fvdl struct vop_islocked_args /* {
352 1.6 fvdl struct vnode *a_vp;
353 1.6 fvdl } */ *ap = v;
354 1.6 fvdl struct vnode *vp = ap->a_vp;
355 1.6 fvdl
356 1.12 wrstuden return (lockstatus(&vp->v_lock));
357 1.12 wrstuden }
358 1.12 wrstuden
359 1.12 wrstuden /*
360 1.12 wrstuden * Stubs to use when there is no locking to be done on the underlying object.
361 1.12 wrstuden */
362 1.12 wrstuden int
363 1.12 wrstuden genfs_nolock(v)
364 1.12 wrstuden void *v;
365 1.12 wrstuden {
366 1.12 wrstuden struct vop_lock_args /* {
367 1.12 wrstuden struct vnode *a_vp;
368 1.12 wrstuden int a_flags;
369 1.12 wrstuden struct proc *a_p;
370 1.12 wrstuden } */ *ap = v;
371 1.12 wrstuden
372 1.12 wrstuden /*
373 1.12 wrstuden * Since we are not using the lock manager, we must clear
374 1.12 wrstuden * the interlock here.
375 1.12 wrstuden */
376 1.12 wrstuden if (ap->a_flags & LK_INTERLOCK)
377 1.12 wrstuden simple_unlock(&ap->a_vp->v_interlock);
378 1.12 wrstuden return (0);
379 1.12 wrstuden }
380 1.12 wrstuden
381 1.12 wrstuden int
382 1.12 wrstuden genfs_nounlock(v)
383 1.12 wrstuden void *v;
384 1.12 wrstuden {
385 1.12 wrstuden return (0);
386 1.12 wrstuden }
387 1.12 wrstuden
388 1.12 wrstuden int
389 1.12 wrstuden genfs_noislocked(v)
390 1.12 wrstuden void *v;
391 1.12 wrstuden {
392 1.12 wrstuden return (0);
393 1.8 thorpej }
394 1.8 thorpej
395 1.8 thorpej /*
396 1.8 thorpej * Local lease check for NFS servers. Just set up args and let
397 1.8 thorpej * nqsrv_getlease() do the rest. If NFSSERVER is not in the kernel,
398 1.8 thorpej * this is a null operation.
399 1.8 thorpej */
400 1.8 thorpej int
401 1.8 thorpej genfs_lease_check(v)
402 1.8 thorpej void *v;
403 1.8 thorpej {
404 1.8 thorpej #ifdef NFSSERVER
405 1.8 thorpej struct vop_lease_args /* {
406 1.8 thorpej struct vnode *a_vp;
407 1.8 thorpej struct proc *a_p;
408 1.8 thorpej struct ucred *a_cred;
409 1.8 thorpej int a_flag;
410 1.8 thorpej } */ *ap = v;
411 1.8 thorpej u_int32_t duration = 0;
412 1.8 thorpej int cache;
413 1.8 thorpej u_quad_t frev;
414 1.8 thorpej
415 1.8 thorpej (void) nqsrv_getlease(ap->a_vp, &duration, ND_CHECK | ap->a_flag,
416 1.8 thorpej NQLOCALSLP, ap->a_p, (struct mbuf *)0, &cache, &frev, ap->a_cred);
417 1.8 thorpej return (0);
418 1.8 thorpej #else
419 1.8 thorpej return (0);
420 1.8 thorpej #endif /* NFSSERVER */
421 1.34 chs }
422 1.34 chs
423 1.34 chs int
424 1.34 chs genfs_mmap(v)
425 1.34 chs void *v;
426 1.34 chs {
427 1.34 chs return 0;
428 1.21 chs }
429 1.21 chs
430 1.21 chs /*
431 1.21 chs * generic VM getpages routine.
432 1.21 chs * Return PG_BUSY pages for the given range,
433 1.21 chs * reading from backing store if necessary.
434 1.21 chs */
435 1.21 chs
436 1.21 chs int
437 1.21 chs genfs_getpages(v)
438 1.21 chs void *v;
439 1.21 chs {
440 1.21 chs struct vop_getpages_args /* {
441 1.21 chs struct vnode *a_vp;
442 1.21 chs voff_t a_offset;
443 1.33 chs struct vm_page **a_m;
444 1.21 chs int *a_count;
445 1.21 chs int a_centeridx;
446 1.21 chs vm_prot_t a_access_type;
447 1.21 chs int a_advice;
448 1.21 chs int a_flags;
449 1.21 chs } */ *ap = v;
450 1.21 chs
451 1.30 chs off_t newsize, diskeof, memeof;
452 1.26 chs off_t offset, origoffset, startoffset, endoffset, raoffset;
453 1.21 chs daddr_t lbn, blkno;
454 1.21 chs int s, i, error, npages, orignpages, npgs, run, ridx, pidx, pcount;
455 1.37 chs int fs_bshift, fs_bsize, dev_bshift;
456 1.21 chs int flags = ap->a_flags;
457 1.21 chs size_t bytes, iobytes, tailbytes, totalbytes, skipbytes;
458 1.21 chs vaddr_t kva;
459 1.21 chs struct buf *bp, *mbp;
460 1.21 chs struct vnode *vp = ap->a_vp;
461 1.36 chs struct vnode *devvp;
462 1.37 chs struct genfs_node *gp = VTOG(vp);
463 1.37 chs struct uvm_object *uobj = &vp->v_uobj;
464 1.37 chs struct vm_page *pg, *pgs[16]; /* XXXUBC 16 */
465 1.21 chs struct ucred *cred = curproc->p_ucred; /* XXXUBC curproc */
466 1.21 chs boolean_t async = (flags & PGO_SYNCIO) == 0;
467 1.21 chs boolean_t write = (ap->a_access_type & VM_PROT_WRITE) != 0;
468 1.21 chs boolean_t sawhole = FALSE;
469 1.37 chs boolean_t overwrite = (flags & PGO_OVERWRITE) != 0;
470 1.21 chs UVMHIST_FUNC("genfs_getpages"); UVMHIST_CALLED(ubchist);
471 1.21 chs
472 1.30 chs UVMHIST_LOG(ubchist, "vp %p off 0x%x/%x count %d",
473 1.30 chs vp, ap->a_offset >> 32, ap->a_offset, *ap->a_count);
474 1.30 chs
475 1.21 chs /* XXXUBC temp limit */
476 1.21 chs if (*ap->a_count > 16) {
477 1.37 chs panic("genfs_getpages: too many pages");
478 1.21 chs }
479 1.21 chs
480 1.26 chs error = 0;
481 1.26 chs origoffset = ap->a_offset;
482 1.26 chs orignpages = *ap->a_count;
483 1.37 chs GOP_SIZE(vp, vp->v_size, &diskeof);
484 1.26 chs if (flags & PGO_PASTEOF) {
485 1.37 chs newsize = MAX(vp->v_size,
486 1.26 chs origoffset + (orignpages << PAGE_SHIFT));
487 1.37 chs GOP_SIZE(vp, newsize, &memeof);
488 1.26 chs } else {
489 1.30 chs memeof = diskeof;
490 1.21 chs }
491 1.30 chs KASSERT(ap->a_centeridx >= 0 || ap->a_centeridx <= orignpages);
492 1.30 chs KASSERT((origoffset & (PAGE_SIZE - 1)) == 0 && origoffset >= 0);
493 1.30 chs KASSERT(orignpages > 0);
494 1.21 chs
495 1.21 chs /*
496 1.21 chs * Bounds-check the request.
497 1.21 chs */
498 1.21 chs
499 1.30 chs if (origoffset + (ap->a_centeridx << PAGE_SHIFT) >= memeof) {
500 1.21 chs if ((flags & PGO_LOCKED) == 0) {
501 1.21 chs simple_unlock(&uobj->vmobjlock);
502 1.21 chs }
503 1.21 chs UVMHIST_LOG(ubchist, "off 0x%x count %d goes past EOF 0x%x",
504 1.30 chs origoffset, *ap->a_count, memeof,0);
505 1.21 chs return EINVAL;
506 1.21 chs }
507 1.21 chs
508 1.21 chs /*
509 1.21 chs * For PGO_LOCKED requests, just return whatever's in memory.
510 1.21 chs */
511 1.21 chs
512 1.21 chs if (flags & PGO_LOCKED) {
513 1.21 chs uvn_findpages(uobj, origoffset, ap->a_count, ap->a_m,
514 1.21 chs UFP_NOWAIT|UFP_NOALLOC|UFP_NORDONLY);
515 1.21 chs
516 1.21 chs return ap->a_m[ap->a_centeridx] == NULL ? EBUSY : 0;
517 1.21 chs }
518 1.21 chs
519 1.21 chs /* vnode is VOP_LOCKed, uobj is locked */
520 1.21 chs
521 1.21 chs if (write && (vp->v_flag & VONWORKLST) == 0) {
522 1.21 chs vn_syncer_add_to_worklist(vp, filedelay);
523 1.21 chs }
524 1.21 chs
525 1.21 chs /*
526 1.21 chs * find the requested pages and make some simple checks.
527 1.21 chs * leave space in the page array for a whole block.
528 1.21 chs */
529 1.21 chs
530 1.36 chs if (vp->v_type == VREG) {
531 1.36 chs fs_bshift = vp->v_mount->mnt_fs_bshift;
532 1.36 chs dev_bshift = vp->v_mount->mnt_dev_bshift;
533 1.36 chs } else {
534 1.36 chs fs_bshift = DEV_BSHIFT;
535 1.36 chs dev_bshift = DEV_BSHIFT;
536 1.36 chs }
537 1.21 chs fs_bsize = 1 << fs_bshift;
538 1.21 chs
539 1.30 chs orignpages = MIN(orignpages,
540 1.30 chs round_page(memeof - origoffset) >> PAGE_SHIFT);
541 1.21 chs npages = orignpages;
542 1.21 chs startoffset = origoffset & ~(fs_bsize - 1);
543 1.21 chs endoffset = round_page((origoffset + (npages << PAGE_SHIFT)
544 1.21 chs + fs_bsize - 1) & ~(fs_bsize - 1));
545 1.30 chs endoffset = MIN(endoffset, round_page(memeof));
546 1.21 chs ridx = (origoffset - startoffset) >> PAGE_SHIFT;
547 1.21 chs
548 1.21 chs memset(pgs, 0, sizeof(pgs));
549 1.21 chs uvn_findpages(uobj, origoffset, &npages, &pgs[ridx], UFP_ALL);
550 1.21 chs
551 1.21 chs /*
552 1.21 chs * if the pages are already resident, just return them.
553 1.21 chs */
554 1.21 chs
555 1.21 chs for (i = 0; i < npages; i++) {
556 1.21 chs struct vm_page *pg = pgs[ridx + i];
557 1.21 chs
558 1.21 chs if ((pg->flags & PG_FAKE) ||
559 1.21 chs (write && (pg->flags & PG_RDONLY))) {
560 1.21 chs break;
561 1.21 chs }
562 1.21 chs }
563 1.21 chs if (i == npages) {
564 1.21 chs UVMHIST_LOG(ubchist, "returning cached pages", 0,0,0,0);
565 1.21 chs raoffset = origoffset + (orignpages << PAGE_SHIFT);
566 1.26 chs npages += ridx;
567 1.21 chs goto raout;
568 1.21 chs }
569 1.21 chs
570 1.21 chs /*
571 1.37 chs * if PGO_OVERWRITE is set, don't bother reading the pages.
572 1.37 chs */
573 1.37 chs
574 1.37 chs if (flags & PGO_OVERWRITE) {
575 1.37 chs UVMHIST_LOG(ubchist, "PGO_OVERWRITE",0,0,0,0);
576 1.37 chs
577 1.37 chs for (i = 0; i < npages; i++) {
578 1.37 chs struct vm_page *pg = pgs[ridx + i];
579 1.37 chs
580 1.37 chs pg->flags &= ~(PG_RDONLY|PG_CLEAN);
581 1.37 chs }
582 1.37 chs npages += ridx;
583 1.37 chs goto out;
584 1.37 chs }
585 1.37 chs
586 1.37 chs /*
587 1.21 chs * the page wasn't resident and we're not overwriting,
588 1.21 chs * so we're going to have to do some i/o.
589 1.21 chs * find any additional pages needed to cover the expanded range.
590 1.21 chs */
591 1.21 chs
592 1.35 chs npages = (endoffset - startoffset) >> PAGE_SHIFT;
593 1.35 chs if (startoffset != origoffset || npages != orignpages) {
594 1.21 chs
595 1.21 chs /*
596 1.37 chs * we need to avoid deadlocks caused by locking
597 1.21 chs * additional pages at lower offsets than pages we
598 1.37 chs * already have locked. unlock them all and start over.
599 1.21 chs */
600 1.21 chs
601 1.35 chs for (i = 0; i < orignpages; i++) {
602 1.21 chs struct vm_page *pg = pgs[ridx + i];
603 1.21 chs
604 1.21 chs if (pg->flags & PG_FAKE) {
605 1.21 chs pg->flags |= PG_RELEASED;
606 1.21 chs }
607 1.21 chs }
608 1.35 chs uvm_page_unbusy(&pgs[ridx], orignpages);
609 1.21 chs memset(pgs, 0, sizeof(pgs));
610 1.21 chs
611 1.21 chs UVMHIST_LOG(ubchist, "reset npages start 0x%x end 0x%x",
612 1.21 chs startoffset, endoffset, 0,0);
613 1.21 chs npgs = npages;
614 1.21 chs uvn_findpages(uobj, startoffset, &npgs, pgs, UFP_ALL);
615 1.21 chs }
616 1.21 chs simple_unlock(&uobj->vmobjlock);
617 1.21 chs
618 1.21 chs /*
619 1.21 chs * read the desired page(s).
620 1.21 chs */
621 1.21 chs
622 1.21 chs totalbytes = npages << PAGE_SHIFT;
623 1.30 chs bytes = MIN(totalbytes, MAX(diskeof - startoffset, 0));
624 1.21 chs tailbytes = totalbytes - bytes;
625 1.21 chs skipbytes = 0;
626 1.21 chs
627 1.21 chs kva = uvm_pagermapin(pgs, npages, UVMPAGER_MAPIN_WAITOK |
628 1.21 chs UVMPAGER_MAPIN_READ);
629 1.21 chs
630 1.21 chs s = splbio();
631 1.21 chs mbp = pool_get(&bufpool, PR_WAITOK);
632 1.21 chs splx(s);
633 1.21 chs mbp->b_bufsize = totalbytes;
634 1.21 chs mbp->b_data = (void *)kva;
635 1.21 chs mbp->b_resid = mbp->b_bcount = bytes;
636 1.21 chs mbp->b_flags = B_BUSY|B_READ| (async ? B_CALL : 0);
637 1.37 chs mbp->b_iodone = (async ? uvm_aio_biodone : 0);
638 1.21 chs mbp->b_vp = vp;
639 1.21 chs LIST_INIT(&mbp->b_dep);
640 1.21 chs
641 1.21 chs /*
642 1.31 chs * if EOF is in the middle of the range, zero the part past EOF.
643 1.21 chs */
644 1.21 chs
645 1.31 chs if (tailbytes > 0) {
646 1.37 chs UVMHIST_LOG(ubchist, "tailbytes %p 0x%x 0x%x",
647 1.37 chs kva, bytes, tailbytes,0);
648 1.21 chs memset((void *)(kva + bytes), 0, tailbytes);
649 1.21 chs }
650 1.21 chs
651 1.21 chs /*
652 1.21 chs * now loop over the pages, reading as needed.
653 1.21 chs */
654 1.21 chs
655 1.21 chs if (write) {
656 1.37 chs lockmgr(&gp->g_glock, LK_EXCLUSIVE, NULL);
657 1.21 chs } else {
658 1.37 chs lockmgr(&gp->g_glock, LK_SHARED, NULL);
659 1.21 chs }
660 1.21 chs
661 1.21 chs bp = NULL;
662 1.21 chs for (offset = startoffset;
663 1.21 chs bytes > 0;
664 1.21 chs offset += iobytes, bytes -= iobytes) {
665 1.21 chs
666 1.21 chs /*
667 1.21 chs * skip pages which don't need to be read.
668 1.21 chs */
669 1.21 chs
670 1.21 chs pidx = (offset - startoffset) >> PAGE_SHIFT;
671 1.35 chs while ((pgs[pidx]->flags & (PG_FAKE|PG_RDONLY)) == 0) {
672 1.21 chs size_t b;
673 1.21 chs
674 1.24 chs KASSERT((offset & (PAGE_SIZE - 1)) == 0);
675 1.26 chs b = MIN(PAGE_SIZE, bytes);
676 1.21 chs offset += b;
677 1.21 chs bytes -= b;
678 1.21 chs skipbytes += b;
679 1.21 chs pidx++;
680 1.21 chs UVMHIST_LOG(ubchist, "skipping, new offset 0x%x",
681 1.21 chs offset, 0,0,0);
682 1.21 chs if (bytes == 0) {
683 1.21 chs goto loopdone;
684 1.21 chs }
685 1.21 chs }
686 1.21 chs
687 1.21 chs /*
688 1.21 chs * bmap the file to find out the blkno to read from and
689 1.21 chs * how much we can read in one i/o. if bmap returns an error,
690 1.21 chs * skip the rest of the top-level i/o.
691 1.21 chs */
692 1.21 chs
693 1.21 chs lbn = offset >> fs_bshift;
694 1.36 chs error = VOP_BMAP(vp, lbn, &devvp, &blkno, &run);
695 1.21 chs if (error) {
696 1.21 chs UVMHIST_LOG(ubchist, "VOP_BMAP lbn 0x%x -> %d\n",
697 1.21 chs lbn, error,0,0);
698 1.21 chs skipbytes += bytes;
699 1.21 chs goto loopdone;
700 1.21 chs }
701 1.21 chs
702 1.21 chs /*
703 1.21 chs * see how many pages can be read with this i/o.
704 1.21 chs * reduce the i/o size if necessary to avoid
705 1.21 chs * overwriting pages with valid data.
706 1.21 chs */
707 1.21 chs
708 1.26 chs iobytes = MIN((((off_t)lbn + 1 + run) << fs_bshift) - offset,
709 1.26 chs bytes);
710 1.21 chs if (offset + iobytes > round_page(offset)) {
711 1.21 chs pcount = 1;
712 1.21 chs while (pidx + pcount < npages &&
713 1.21 chs pgs[pidx + pcount]->flags & PG_FAKE) {
714 1.21 chs pcount++;
715 1.21 chs }
716 1.26 chs iobytes = MIN(iobytes, (pcount << PAGE_SHIFT) -
717 1.21 chs (offset - trunc_page(offset)));
718 1.21 chs }
719 1.21 chs
720 1.21 chs /*
721 1.21 chs * if this block isn't allocated, zero it instead of reading it.
722 1.21 chs * if this is a read access, mark the pages we zeroed PG_RDONLY.
723 1.21 chs */
724 1.21 chs
725 1.21 chs if (blkno < 0) {
726 1.35 chs int holepages = (round_page(offset + iobytes) -
727 1.35 chs trunc_page(offset)) >> PAGE_SHIFT;
728 1.21 chs UVMHIST_LOG(ubchist, "lbn 0x%x -> HOLE", lbn,0,0,0);
729 1.21 chs
730 1.21 chs sawhole = TRUE;
731 1.21 chs memset((char *)kva + (offset - startoffset), 0,
732 1.21 chs iobytes);
733 1.21 chs skipbytes += iobytes;
734 1.21 chs
735 1.35 chs for (i = 0; i < holepages; i++) {
736 1.35 chs if (write) {
737 1.35 chs pgs[pidx + i]->flags &= ~PG_CLEAN;
738 1.35 chs } else {
739 1.21 chs pgs[pidx + i]->flags |= PG_RDONLY;
740 1.21 chs }
741 1.21 chs }
742 1.21 chs continue;
743 1.21 chs }
744 1.21 chs
745 1.21 chs /*
746 1.21 chs * allocate a sub-buf for this piece of the i/o
747 1.21 chs * (or just use mbp if there's only 1 piece),
748 1.21 chs * and start it going.
749 1.21 chs */
750 1.21 chs
751 1.21 chs if (offset == startoffset && iobytes == bytes) {
752 1.21 chs bp = mbp;
753 1.21 chs } else {
754 1.21 chs s = splbio();
755 1.21 chs bp = pool_get(&bufpool, PR_WAITOK);
756 1.21 chs splx(s);
757 1.21 chs bp->b_data = (char *)kva + offset - startoffset;
758 1.21 chs bp->b_resid = bp->b_bcount = iobytes;
759 1.21 chs bp->b_flags = B_BUSY|B_READ|B_CALL;
760 1.21 chs bp->b_iodone = uvm_aio_biodone1;
761 1.21 chs bp->b_vp = vp;
762 1.37 chs bp->b_proc = NULL;
763 1.21 chs LIST_INIT(&bp->b_dep);
764 1.21 chs }
765 1.21 chs bp->b_lblkno = 0;
766 1.21 chs bp->b_private = mbp;
767 1.37 chs if (devvp->v_type == VBLK) {
768 1.37 chs bp->b_dev = devvp->v_rdev;
769 1.37 chs }
770 1.21 chs
771 1.21 chs /* adjust physical blkno for partial blocks */
772 1.25 fvdl bp->b_blkno = blkno + ((offset - ((off_t)lbn << fs_bshift)) >>
773 1.21 chs dev_bshift);
774 1.21 chs
775 1.21 chs UVMHIST_LOG(ubchist, "bp %p offset 0x%x bcount 0x%x blkno 0x%x",
776 1.21 chs bp, offset, iobytes, bp->b_blkno);
777 1.21 chs
778 1.21 chs VOP_STRATEGY(bp);
779 1.21 chs }
780 1.21 chs
781 1.21 chs loopdone:
782 1.21 chs if (skipbytes) {
783 1.21 chs s = splbio();
784 1.21 chs if (error) {
785 1.21 chs mbp->b_flags |= B_ERROR;
786 1.21 chs mbp->b_error = error;
787 1.21 chs }
788 1.21 chs mbp->b_resid -= skipbytes;
789 1.21 chs if (mbp->b_resid == 0) {
790 1.21 chs biodone(mbp);
791 1.21 chs }
792 1.21 chs splx(s);
793 1.21 chs }
794 1.21 chs
795 1.21 chs if (async) {
796 1.32 chs UVMHIST_LOG(ubchist, "returning 0 (async)",0,0,0,0);
797 1.37 chs lockmgr(&gp->g_glock, LK_RELEASE, NULL);
798 1.32 chs return 0;
799 1.21 chs }
800 1.21 chs if (bp != NULL) {
801 1.21 chs error = biowait(mbp);
802 1.21 chs }
803 1.21 chs s = splbio();
804 1.21 chs pool_put(&bufpool, mbp);
805 1.21 chs splx(s);
806 1.21 chs uvm_pagermapout(kva, npages);
807 1.24 chs raoffset = startoffset + totalbytes;
808 1.21 chs
809 1.21 chs /*
810 1.21 chs * if this we encountered a hole then we have to do a little more work.
811 1.21 chs * for read faults, we marked the page PG_RDONLY so that future
812 1.21 chs * write accesses to the page will fault again.
813 1.21 chs * for write faults, we must make sure that the backing store for
814 1.21 chs * the page is completely allocated while the pages are locked.
815 1.21 chs */
816 1.21 chs
817 1.37 chs if (!error && sawhole && write) {
818 1.37 chs for (i = 0; i < npages; i++) {
819 1.37 chs if (pgs[i] == NULL) {
820 1.37 chs continue;
821 1.37 chs }
822 1.37 chs pgs[i]->flags &= ~PG_CLEAN;
823 1.37 chs UVMHIST_LOG(ubchist, "mark dirty pg %p", pgs[i],0,0,0);
824 1.21 chs }
825 1.37 chs error = GOP_ALLOC(vp, startoffset, npages << PAGE_SHIFT, 0,
826 1.37 chs cred);
827 1.37 chs UVMHIST_LOG(ubchist, "gop_alloc off 0x%x/0x%x -> %d",
828 1.37 chs startoffset, npages << PAGE_SHIFT, error,0);
829 1.21 chs }
830 1.37 chs lockmgr(&gp->g_glock, LK_RELEASE, NULL);
831 1.21 chs simple_lock(&uobj->vmobjlock);
832 1.21 chs
833 1.21 chs /*
834 1.21 chs * see if we want to start any readahead.
835 1.21 chs * XXXUBC for now, just read the next 128k on 64k boundaries.
836 1.21 chs * this is pretty nonsensical, but it is 50% faster than reading
837 1.21 chs * just the next 64k.
838 1.21 chs */
839 1.21 chs
840 1.21 chs raout:
841 1.24 chs if (!error && !async && !write && ((int)raoffset & 0xffff) == 0 &&
842 1.21 chs PAGE_SHIFT <= 16) {
843 1.21 chs int racount;
844 1.21 chs
845 1.21 chs racount = 1 << (16 - PAGE_SHIFT);
846 1.21 chs (void) VOP_GETPAGES(vp, raoffset, NULL, &racount, 0,
847 1.21 chs VM_PROT_READ, 0, 0);
848 1.21 chs simple_lock(&uobj->vmobjlock);
849 1.21 chs
850 1.21 chs racount = 1 << (16 - PAGE_SHIFT);
851 1.21 chs (void) VOP_GETPAGES(vp, raoffset + 0x10000, NULL, &racount, 0,
852 1.21 chs VM_PROT_READ, 0, 0);
853 1.21 chs simple_lock(&uobj->vmobjlock);
854 1.21 chs }
855 1.21 chs
856 1.21 chs /*
857 1.21 chs * we're almost done! release the pages...
858 1.21 chs * for errors, we free the pages.
859 1.21 chs * otherwise we activate them and mark them as valid and clean.
860 1.21 chs * also, unbusy pages that were not actually requested.
861 1.21 chs */
862 1.21 chs
863 1.21 chs if (error) {
864 1.21 chs for (i = 0; i < npages; i++) {
865 1.21 chs if (pgs[i] == NULL) {
866 1.21 chs continue;
867 1.21 chs }
868 1.21 chs UVMHIST_LOG(ubchist, "examining pg %p flags 0x%x",
869 1.21 chs pgs[i], pgs[i]->flags, 0,0);
870 1.26 chs if (pgs[i]->flags & PG_FAKE) {
871 1.37 chs pgs[i]->flags |= PG_RELEASED;
872 1.21 chs }
873 1.21 chs }
874 1.37 chs uvm_lock_pageq();
875 1.37 chs uvm_page_unbusy(pgs, npages);
876 1.21 chs uvm_unlock_pageq();
877 1.21 chs simple_unlock(&uobj->vmobjlock);
878 1.21 chs UVMHIST_LOG(ubchist, "returning error %d", error,0,0,0);
879 1.21 chs return error;
880 1.21 chs }
881 1.21 chs
882 1.37 chs out:
883 1.21 chs UVMHIST_LOG(ubchist, "succeeding, npages %d", npages,0,0,0);
884 1.26 chs uvm_lock_pageq();
885 1.21 chs for (i = 0; i < npages; i++) {
886 1.37 chs pg = pgs[i];
887 1.37 chs if (pg == NULL) {
888 1.21 chs continue;
889 1.21 chs }
890 1.21 chs UVMHIST_LOG(ubchist, "examining pg %p flags 0x%x",
891 1.37 chs pg, pg->flags, 0,0);
892 1.37 chs if (pg->flags & PG_FAKE && !overwrite) {
893 1.37 chs pg->flags &= ~(PG_FAKE);
894 1.21 chs pmap_clear_modify(pgs[i]);
895 1.21 chs }
896 1.21 chs if (write) {
897 1.37 chs pg->flags &= ~(PG_RDONLY);
898 1.21 chs }
899 1.21 chs if (i < ridx || i >= ridx + orignpages || async) {
900 1.21 chs UVMHIST_LOG(ubchist, "unbusy pg %p offset 0x%x",
901 1.37 chs pg, pg->offset,0,0);
902 1.37 chs if (pg->flags & PG_WANTED) {
903 1.37 chs wakeup(pg);
904 1.37 chs }
905 1.37 chs if (pg->flags & PG_FAKE) {
906 1.37 chs KASSERT(overwrite);
907 1.37 chs uvm_pagezero(pg);
908 1.37 chs }
909 1.37 chs if (pg->flags & PG_RELEASED) {
910 1.37 chs uvm_pagefree(pg);
911 1.26 chs continue;
912 1.21 chs }
913 1.37 chs uvm_pageactivate(pg);
914 1.37 chs pg->flags &= ~(PG_WANTED|PG_BUSY|PG_FAKE);
915 1.37 chs UVM_PAGE_OWN(pg, NULL);
916 1.21 chs }
917 1.21 chs }
918 1.26 chs uvm_unlock_pageq();
919 1.21 chs simple_unlock(&uobj->vmobjlock);
920 1.21 chs if (ap->a_m != NULL) {
921 1.21 chs memcpy(ap->a_m, &pgs[ridx],
922 1.21 chs orignpages * sizeof(struct vm_page *));
923 1.21 chs }
924 1.21 chs return 0;
925 1.21 chs }
926 1.21 chs
927 1.21 chs /*
928 1.21 chs * generic VM putpages routine.
929 1.21 chs * Write the given range of pages to backing store.
930 1.37 chs *
931 1.37 chs * => "offhi == 0" means flush all pages at or after "offlo".
932 1.37 chs * => object should be locked by caller. we may _unlock_ the object
933 1.37 chs * if (and only if) we need to clean a page (PGO_CLEANIT), or
934 1.37 chs * if PGO_SYNCIO is set and there are pages busy.
935 1.37 chs * we return with the object locked.
936 1.37 chs * => if PGO_CLEANIT or PGO_SYNCIO is set, we may block (due to I/O).
937 1.37 chs * thus, a caller might want to unlock higher level resources
938 1.37 chs * (e.g. vm_map) before calling flush.
939 1.37 chs * => if neither PGO_CLEANIT nor PGO_SYNCIO is set, then we will neither
940 1.37 chs * unlock the object nor block.
941 1.37 chs * => if PGO_ALLPAGES is set, then all pages in the object will be processed.
942 1.37 chs * => NOTE: we rely on the fact that the object's memq is a TAILQ and
943 1.37 chs * that new pages are inserted on the tail end of the list. thus,
944 1.37 chs * we can make a complete pass through the object in one go by starting
945 1.37 chs * at the head and working towards the tail (new pages are put in
946 1.37 chs * front of us).
947 1.37 chs * => NOTE: we are allowed to lock the page queues, so the caller
948 1.37 chs * must not be holding the page queue lock.
949 1.37 chs *
950 1.37 chs * note on "cleaning" object and PG_BUSY pages:
951 1.37 chs * this routine is holding the lock on the object. the only time
952 1.37 chs * that it can run into a PG_BUSY page that it does not own is if
953 1.37 chs * some other process has started I/O on the page (e.g. either
954 1.37 chs * a pagein, or a pageout). if the PG_BUSY page is being paged
955 1.37 chs * in, then it can not be dirty (!PG_CLEAN) because no one has
956 1.37 chs * had a chance to modify it yet. if the PG_BUSY page is being
957 1.37 chs * paged out then it means that someone else has already started
958 1.37 chs * cleaning the page for us (how nice!). in this case, if we
959 1.37 chs * have syncio specified, then after we make our pass through the
960 1.37 chs * object we need to wait for the other PG_BUSY pages to clear
961 1.37 chs * off (i.e. we need to do an iosync). also note that once a
962 1.37 chs * page is PG_BUSY it must stay in its object until it is un-busyed.
963 1.37 chs *
964 1.37 chs * note on page traversal:
965 1.37 chs * we can traverse the pages in an object either by going down the
966 1.37 chs * linked list in "uobj->memq", or we can go over the address range
967 1.37 chs * by page doing hash table lookups for each address. depending
968 1.37 chs * on how many pages are in the object it may be cheaper to do one
969 1.37 chs * or the other. we set "by_list" to true if we are using memq.
970 1.37 chs * if the cost of a hash lookup was equal to the cost of the list
971 1.37 chs * traversal we could compare the number of pages in the start->stop
972 1.37 chs * range to the total number of pages in the object. however, it
973 1.37 chs * seems that a hash table lookup is more expensive than the linked
974 1.37 chs * list traversal, so we multiply the number of pages in the
975 1.37 chs * range by an estimate of the relatively higher cost of the hash lookup.
976 1.21 chs */
977 1.21 chs
978 1.21 chs int
979 1.21 chs genfs_putpages(v)
980 1.21 chs void *v;
981 1.21 chs {
982 1.21 chs struct vop_putpages_args /* {
983 1.21 chs struct vnode *a_vp;
984 1.37 chs voff_t a_offlo;
985 1.37 chs voff_t a_offhi;
986 1.21 chs int a_flags;
987 1.21 chs } */ *ap = v;
988 1.37 chs struct vnode *vp = ap->a_vp;
989 1.37 chs struct uvm_object *uobj = &vp->v_uobj;
990 1.37 chs off_t startoff = ap->a_offlo;
991 1.37 chs off_t endoff = ap->a_offhi;
992 1.37 chs off_t off;
993 1.37 chs int flags = ap->a_flags;
994 1.37 chs int n = MAXBSIZE >> PAGE_SHIFT;
995 1.37 chs int i, s, error, npages, nback;
996 1.37 chs int freeflag;
997 1.37 chs struct vm_page *pgs[n], *pg, *nextpg, *tpg, curmp, endmp;
998 1.37 chs boolean_t wasclean, by_list, needs_clean;
999 1.37 chs boolean_t async = (flags & PGO_SYNCIO) == 0;
1000 1.37 chs UVMHIST_FUNC("genfs_putpages"); UVMHIST_CALLED(ubchist);
1001 1.37 chs
1002 1.37 chs KASSERT(flags & (PGO_CLEANIT|PGO_FREE|PGO_DEACTIVATE));
1003 1.37 chs KASSERT((startoff & PAGE_MASK) == 0 && (endoff & PAGE_MASK) == 0);
1004 1.37 chs KASSERT(startoff < endoff || endoff == 0);
1005 1.37 chs
1006 1.37 chs UVMHIST_LOG(ubchist, "vp %p pages %d off 0x%x len 0x%x",
1007 1.37 chs vp, uobj->uo_npages, startoff, endoff - startoff);
1008 1.37 chs if (uobj->uo_npages == 0) {
1009 1.37 chs if (LIST_FIRST(&vp->v_dirtyblkhd) == NULL &&
1010 1.37 chs (vp->v_flag & VONWORKLST)) {
1011 1.37 chs vp->v_flag &= ~VONWORKLST;
1012 1.37 chs LIST_REMOVE(vp, v_synclist);
1013 1.37 chs }
1014 1.37 chs simple_unlock(&uobj->vmobjlock);
1015 1.37 chs return 0;
1016 1.37 chs }
1017 1.37 chs
1018 1.37 chs /*
1019 1.37 chs * the vnode has pages, set up to process the request.
1020 1.37 chs */
1021 1.37 chs
1022 1.37 chs error = 0;
1023 1.37 chs wasclean = TRUE;
1024 1.37 chs off = startoff;
1025 1.37 chs if (endoff == 0 || flags & PGO_ALLPAGES) {
1026 1.37 chs endoff = trunc_page(LLONG_MAX);
1027 1.37 chs }
1028 1.37 chs by_list = (uobj->uo_npages <=
1029 1.37 chs ((endoff - startoff) >> PAGE_SHIFT) * UVM_PAGE_HASH_PENALTY);
1030 1.37 chs
1031 1.37 chs /*
1032 1.37 chs * start the loop. when scanning by list, hold the last page
1033 1.37 chs * in the list before we start. pages allocated after we start
1034 1.37 chs * will be added to the end of the list, so we can stop at the
1035 1.37 chs * current last page.
1036 1.37 chs */
1037 1.37 chs
1038 1.37 chs freeflag = (curproc == uvm.pagedaemon_proc) ? PG_PAGEOUT : PG_RELEASED;
1039 1.37 chs curmp.uobject = uobj;
1040 1.37 chs curmp.offset = (voff_t)-1;
1041 1.37 chs curmp.flags = PG_BUSY;
1042 1.37 chs endmp.uobject = uobj;
1043 1.37 chs endmp.offset = (voff_t)-1;
1044 1.37 chs endmp.flags = PG_BUSY;
1045 1.37 chs if (by_list) {
1046 1.37 chs pg = TAILQ_FIRST(&uobj->memq);
1047 1.37 chs TAILQ_INSERT_TAIL(&uobj->memq, &endmp, listq);
1048 1.37 chs PHOLD(curproc);
1049 1.37 chs } else {
1050 1.37 chs pg = uvm_pagelookup(uobj, off);
1051 1.37 chs }
1052 1.37 chs nextpg = NULL;
1053 1.37 chs while (by_list || off < endoff) {
1054 1.37 chs
1055 1.37 chs /*
1056 1.37 chs * if the current page is not interesting, move on to the next.
1057 1.37 chs */
1058 1.37 chs
1059 1.37 chs KASSERT(pg == NULL || pg->uobject == uobj);
1060 1.37 chs KASSERT(pg == NULL ||
1061 1.37 chs (pg->flags & (PG_RELEASED|PG_PAGEOUT)) == 0 ||
1062 1.37 chs (pg->flags & PG_BUSY) != 0);
1063 1.37 chs if (by_list) {
1064 1.37 chs if (pg == &endmp) {
1065 1.37 chs break;
1066 1.37 chs }
1067 1.37 chs if (pg->offset < startoff || pg->offset >= endoff ||
1068 1.37 chs pg->flags & (PG_RELEASED|PG_PAGEOUT)) {
1069 1.37 chs pg = TAILQ_NEXT(pg, listq);
1070 1.37 chs continue;
1071 1.37 chs }
1072 1.37 chs off = pg->offset;
1073 1.37 chs } else if (pg == NULL || pg->flags & (PG_RELEASED|PG_PAGEOUT)) {
1074 1.37 chs off += PAGE_SIZE;
1075 1.37 chs if (off < endoff) {
1076 1.37 chs pg = uvm_pagelookup(uobj, off);
1077 1.37 chs }
1078 1.37 chs continue;
1079 1.37 chs }
1080 1.21 chs
1081 1.37 chs /*
1082 1.37 chs * if the current page needs to be cleaned and it's busy,
1083 1.37 chs * wait for it to become unbusy.
1084 1.37 chs */
1085 1.37 chs
1086 1.37 chs if (flags & PGO_FREE) {
1087 1.37 chs pmap_page_protect(pg, VM_PROT_NONE);
1088 1.37 chs }
1089 1.37 chs if (flags & PGO_CLEANIT) {
1090 1.37 chs needs_clean = pmap_clear_modify(pg) ||
1091 1.37 chs (pg->flags & PG_CLEAN) == 0;
1092 1.37 chs pg->flags |= PG_CLEAN;
1093 1.37 chs } else {
1094 1.37 chs needs_clean = FALSE;
1095 1.37 chs }
1096 1.37 chs if (needs_clean && pg->flags & PG_BUSY) {
1097 1.37 chs KASSERT(curproc != uvm.pagedaemon_proc);
1098 1.37 chs UVMHIST_LOG(ubchist, "busy %p", pg,0,0,0);
1099 1.37 chs if (by_list) {
1100 1.37 chs TAILQ_INSERT_BEFORE(pg, &curmp, listq);
1101 1.37 chs UVMHIST_LOG(ubchist, "curmp next %p",
1102 1.37 chs TAILQ_NEXT(&curmp, listq), 0,0,0);
1103 1.37 chs }
1104 1.37 chs pg->flags |= PG_WANTED;
1105 1.37 chs pg->flags &= ~PG_CLEAN;
1106 1.37 chs UVM_UNLOCK_AND_WAIT(pg, &uobj->vmobjlock, 0,
1107 1.37 chs "genput", 0);
1108 1.37 chs simple_lock(&uobj->vmobjlock);
1109 1.37 chs if (by_list) {
1110 1.37 chs UVMHIST_LOG(ubchist, "after next %p",
1111 1.37 chs TAILQ_NEXT(&curmp, listq), 0,0,0);
1112 1.37 chs pg = TAILQ_NEXT(&curmp, listq);
1113 1.37 chs TAILQ_REMOVE(&uobj->memq, &curmp, listq);
1114 1.37 chs } else {
1115 1.37 chs pg = uvm_pagelookup(uobj, off);
1116 1.37 chs }
1117 1.37 chs continue;
1118 1.37 chs }
1119 1.37 chs
1120 1.37 chs /*
1121 1.37 chs * if we're cleaning, build a cluster.
1122 1.37 chs * the cluster will consist of pages which are currently dirty,
1123 1.37 chs * but they will be returned to us marked clean.
1124 1.37 chs * if not cleaning, just operate on the one page.
1125 1.37 chs */
1126 1.37 chs
1127 1.37 chs if (needs_clean) {
1128 1.37 chs wasclean = FALSE;
1129 1.37 chs memset(pgs, 0, sizeof(pgs));
1130 1.37 chs pg->flags |= PG_BUSY;
1131 1.37 chs UVM_PAGE_OWN(pg, "genfs_putpages");
1132 1.37 chs
1133 1.37 chs /*
1134 1.37 chs * first look backward.
1135 1.37 chs */
1136 1.37 chs
1137 1.37 chs npages = MIN(n >> 1, off >> PAGE_SHIFT);
1138 1.37 chs nback = npages;
1139 1.37 chs uvn_findpages(uobj, off - PAGE_SIZE, &nback, &pgs[0],
1140 1.37 chs UFP_NOWAIT|UFP_NOALLOC|UFP_DIRTYONLY|UFP_BACKWARD);
1141 1.37 chs if (nback) {
1142 1.37 chs memmove(&pgs[0], &pgs[npages - nback],
1143 1.37 chs nback * sizeof(pgs[0]));
1144 1.37 chs }
1145 1.37 chs n -= nback;
1146 1.37 chs
1147 1.37 chs /*
1148 1.37 chs * then plug in our page of interest.
1149 1.37 chs */
1150 1.37 chs
1151 1.37 chs pgs[nback] = pg;
1152 1.37 chs
1153 1.37 chs /*
1154 1.37 chs * then look forward to fill in the remaining space in
1155 1.37 chs * the array of pages.
1156 1.37 chs */
1157 1.37 chs
1158 1.37 chs npages = MIN(n, (endoff - off) >> PAGE_SHIFT) - 1;
1159 1.37 chs uvn_findpages(uobj, off + PAGE_SIZE, &npages,
1160 1.37 chs &pgs[nback + 1],
1161 1.37 chs UFP_NOWAIT|UFP_NOALLOC|UFP_DIRTYONLY);
1162 1.37 chs npages += nback + 1;
1163 1.37 chs } else {
1164 1.37 chs pgs[0] = pg;
1165 1.37 chs npages = 1;
1166 1.37 chs }
1167 1.37 chs
1168 1.37 chs /*
1169 1.37 chs * apply FREE or DEACTIVATE options if requested.
1170 1.37 chs */
1171 1.37 chs
1172 1.37 chs if (flags & (PGO_DEACTIVATE|PGO_FREE)) {
1173 1.37 chs uvm_lock_pageq();
1174 1.37 chs }
1175 1.37 chs for (i = 0; i < npages; i++) {
1176 1.37 chs tpg = pgs[i];
1177 1.37 chs KASSERT(tpg->uobject == uobj);
1178 1.37 chs if (flags & PGO_DEACTIVATE &&
1179 1.37 chs (tpg->pqflags & PQ_INACTIVE) == 0 &&
1180 1.37 chs tpg->wire_count == 0) {
1181 1.37 chs (void) pmap_clear_reference(tpg);
1182 1.37 chs uvm_pagedeactivate(tpg);
1183 1.37 chs } else if (flags & PGO_FREE) {
1184 1.37 chs pmap_page_protect(tpg, VM_PROT_NONE);
1185 1.37 chs if (tpg->flags & PG_BUSY) {
1186 1.37 chs tpg->flags |= freeflag;
1187 1.37 chs if (freeflag == PG_PAGEOUT) {
1188 1.37 chs uvmexp.paging++;
1189 1.37 chs uvm_pagedequeue(tpg);
1190 1.37 chs }
1191 1.37 chs } else {
1192 1.37 chs nextpg = TAILQ_NEXT(tpg, listq);
1193 1.37 chs uvm_pagefree(tpg);
1194 1.37 chs }
1195 1.37 chs }
1196 1.37 chs }
1197 1.37 chs if (flags & (PGO_DEACTIVATE|PGO_FREE)) {
1198 1.37 chs uvm_unlock_pageq();
1199 1.37 chs }
1200 1.37 chs if (needs_clean) {
1201 1.37 chs
1202 1.37 chs /*
1203 1.37 chs * start the i/o. if we're traversing by list,
1204 1.37 chs * keep our place in the list with a marker page.
1205 1.37 chs */
1206 1.37 chs
1207 1.37 chs if (by_list) {
1208 1.37 chs TAILQ_INSERT_AFTER(&uobj->memq, pg, &curmp,
1209 1.37 chs listq);
1210 1.37 chs }
1211 1.37 chs simple_unlock(&uobj->vmobjlock);
1212 1.37 chs error = GOP_WRITE(vp, pgs, npages, flags);
1213 1.37 chs simple_lock(&uobj->vmobjlock);
1214 1.37 chs if (by_list) {
1215 1.37 chs pg = TAILQ_NEXT(&curmp, listq);
1216 1.37 chs TAILQ_REMOVE(&uobj->memq, &curmp, listq);
1217 1.37 chs }
1218 1.37 chs if (error == ENOMEM) {
1219 1.37 chs for (i = 0; i < npages; i++) {
1220 1.37 chs tpg = pgs[i];
1221 1.37 chs if (tpg->flags & PG_PAGEOUT) {
1222 1.37 chs tpg->flags &= ~PG_PAGEOUT;
1223 1.37 chs uvmexp.paging--;
1224 1.37 chs }
1225 1.37 chs tpg->flags &= ~PG_CLEAN;
1226 1.37 chs uvm_pageactivate(tpg);
1227 1.37 chs }
1228 1.37 chs uvm_page_unbusy(pgs, npages);
1229 1.37 chs }
1230 1.37 chs if (error) {
1231 1.37 chs break;
1232 1.37 chs }
1233 1.37 chs if (by_list) {
1234 1.37 chs continue;
1235 1.37 chs }
1236 1.37 chs }
1237 1.37 chs
1238 1.37 chs /*
1239 1.37 chs * find the next page and continue if there was no error.
1240 1.37 chs */
1241 1.37 chs
1242 1.37 chs if (by_list) {
1243 1.37 chs if (nextpg) {
1244 1.37 chs pg = nextpg;
1245 1.37 chs nextpg = NULL;
1246 1.37 chs } else {
1247 1.37 chs pg = TAILQ_NEXT(pg, listq);
1248 1.37 chs }
1249 1.37 chs } else {
1250 1.37 chs off += PAGE_SIZE;
1251 1.37 chs if (off < endoff) {
1252 1.37 chs pg = uvm_pagelookup(uobj, off);
1253 1.37 chs }
1254 1.37 chs }
1255 1.37 chs }
1256 1.37 chs if (by_list) {
1257 1.37 chs TAILQ_REMOVE(&uobj->memq, &endmp, listq);
1258 1.37 chs PRELE(curproc);
1259 1.37 chs }
1260 1.37 chs
1261 1.37 chs /*
1262 1.37 chs * if we're cleaning and there was nothing to clean,
1263 1.37 chs * take us off the syncer list. if we started any i/o
1264 1.37 chs * and we're doing sync i/o, wait for all writes to finish.
1265 1.37 chs */
1266 1.37 chs
1267 1.37 chs if ((flags & PGO_CLEANIT) && wasclean &&
1268 1.37 chs startoff == 0 && endoff == trunc_page(LLONG_MAX) &&
1269 1.37 chs LIST_FIRST(&vp->v_dirtyblkhd) == NULL &&
1270 1.37 chs (vp->v_flag & VONWORKLST)) {
1271 1.37 chs vp->v_flag &= ~VONWORKLST;
1272 1.37 chs LIST_REMOVE(vp, v_synclist);
1273 1.37 chs }
1274 1.37 chs if (!wasclean && !async) {
1275 1.37 chs s = splbio();
1276 1.37 chs while (vp->v_numoutput != 0) {
1277 1.37 chs vp->v_flag |= VBWAIT;
1278 1.37 chs UVM_UNLOCK_AND_WAIT(&vp->v_numoutput, &uobj->vmobjlock,
1279 1.37 chs FALSE, "genput2",0);
1280 1.37 chs simple_lock(&uobj->vmobjlock);
1281 1.37 chs }
1282 1.37 chs splx(s);
1283 1.37 chs }
1284 1.37 chs simple_unlock(&uobj->vmobjlock);
1285 1.37 chs return error;
1286 1.37 chs }
1287 1.37 chs
1288 1.37 chs int
1289 1.37 chs genfs_gop_write(struct vnode *vp, struct vm_page **pgs, int npages, int flags)
1290 1.37 chs {
1291 1.37 chs int s, error, run;
1292 1.37 chs int fs_bshift, dev_bshift;
1293 1.21 chs vaddr_t kva;
1294 1.21 chs off_t eof, offset, startoffset;
1295 1.21 chs size_t bytes, iobytes, skipbytes;
1296 1.21 chs daddr_t lbn, blkno;
1297 1.21 chs struct vm_page *pg;
1298 1.21 chs struct buf *mbp, *bp;
1299 1.36 chs struct vnode *devvp;
1300 1.37 chs boolean_t async = (flags & PGO_SYNCIO) == 0;
1301 1.37 chs UVMHIST_FUNC("genfs_do_putpages"); UVMHIST_CALLED(ubchist);
1302 1.21 chs
1303 1.37 chs UVMHIST_LOG(ubchist, "vp %p pgs %p npages %d flags 0x%x",
1304 1.37 chs vp, pgs, npages, flags);
1305 1.21 chs
1306 1.37 chs GOP_SIZE(vp, vp->v_size, &eof);
1307 1.36 chs if (vp->v_type == VREG) {
1308 1.36 chs fs_bshift = vp->v_mount->mnt_fs_bshift;
1309 1.36 chs dev_bshift = vp->v_mount->mnt_dev_bshift;
1310 1.36 chs } else {
1311 1.36 chs fs_bshift = DEV_BSHIFT;
1312 1.36 chs dev_bshift = DEV_BSHIFT;
1313 1.36 chs }
1314 1.37 chs error = 0;
1315 1.37 chs pg = pgs[0];
1316 1.21 chs startoffset = pg->offset;
1317 1.26 chs bytes = MIN(npages << PAGE_SHIFT, eof - startoffset);
1318 1.21 chs skipbytes = 0;
1319 1.21 chs KASSERT(bytes != 0);
1320 1.21 chs
1321 1.37 chs kva = uvm_pagermapin(pgs, npages, UVMPAGER_MAPIN_WRITE |
1322 1.37 chs UVMPAGER_MAPIN_WAITOK);
1323 1.21 chs
1324 1.21 chs s = splbio();
1325 1.21 chs vp->v_numoutput += 2;
1326 1.21 chs mbp = pool_get(&bufpool, PR_WAITOK);
1327 1.21 chs UVMHIST_LOG(ubchist, "vp %p mbp %p num now %d bytes 0x%x",
1328 1.21 chs vp, mbp, vp->v_numoutput, bytes);
1329 1.21 chs splx(s);
1330 1.21 chs mbp->b_bufsize = npages << PAGE_SHIFT;
1331 1.21 chs mbp->b_data = (void *)kva;
1332 1.21 chs mbp->b_resid = mbp->b_bcount = bytes;
1333 1.37 chs mbp->b_flags = B_BUSY|B_WRITE|B_AGE| (async ? B_CALL : 0);
1334 1.21 chs mbp->b_iodone = uvm_aio_biodone;
1335 1.21 chs mbp->b_vp = vp;
1336 1.21 chs LIST_INIT(&mbp->b_dep);
1337 1.21 chs
1338 1.21 chs bp = NULL;
1339 1.21 chs for (offset = startoffset;
1340 1.21 chs bytes > 0;
1341 1.21 chs offset += iobytes, bytes -= iobytes) {
1342 1.21 chs lbn = offset >> fs_bshift;
1343 1.36 chs error = VOP_BMAP(vp, lbn, &devvp, &blkno, &run);
1344 1.21 chs if (error) {
1345 1.21 chs UVMHIST_LOG(ubchist, "VOP_BMAP() -> %d", error,0,0,0);
1346 1.21 chs skipbytes += bytes;
1347 1.21 chs bytes = 0;
1348 1.21 chs break;
1349 1.21 chs }
1350 1.21 chs
1351 1.26 chs iobytes = MIN((((off_t)lbn + 1 + run) << fs_bshift) - offset,
1352 1.26 chs bytes);
1353 1.21 chs if (blkno == (daddr_t)-1) {
1354 1.21 chs skipbytes += iobytes;
1355 1.21 chs continue;
1356 1.21 chs }
1357 1.21 chs
1358 1.21 chs /* if it's really one i/o, don't make a second buf */
1359 1.21 chs if (offset == startoffset && iobytes == bytes) {
1360 1.21 chs bp = mbp;
1361 1.21 chs } else {
1362 1.21 chs s = splbio();
1363 1.21 chs vp->v_numoutput++;
1364 1.21 chs bp = pool_get(&bufpool, PR_WAITOK);
1365 1.21 chs UVMHIST_LOG(ubchist, "vp %p bp %p num now %d",
1366 1.21 chs vp, bp, vp->v_numoutput, 0);
1367 1.21 chs splx(s);
1368 1.21 chs bp->b_data = (char *)kva +
1369 1.21 chs (vaddr_t)(offset - pg->offset);
1370 1.21 chs bp->b_resid = bp->b_bcount = iobytes;
1371 1.37 chs bp->b_flags = B_BUSY|B_WRITE|B_CALL;
1372 1.21 chs bp->b_iodone = uvm_aio_biodone1;
1373 1.21 chs bp->b_vp = vp;
1374 1.21 chs LIST_INIT(&bp->b_dep);
1375 1.21 chs }
1376 1.21 chs bp->b_lblkno = 0;
1377 1.21 chs bp->b_private = mbp;
1378 1.37 chs if (devvp->v_type == VBLK) {
1379 1.37 chs bp->b_dev = devvp->v_rdev;
1380 1.37 chs }
1381 1.21 chs
1382 1.21 chs /* adjust physical blkno for partial blocks */
1383 1.25 fvdl bp->b_blkno = blkno + ((offset - ((off_t)lbn << fs_bshift)) >>
1384 1.21 chs dev_bshift);
1385 1.21 chs UVMHIST_LOG(ubchist, "vp %p offset 0x%x bcount 0x%x blkno 0x%x",
1386 1.21 chs vp, offset, bp->b_bcount, bp->b_blkno);
1387 1.21 chs VOP_STRATEGY(bp);
1388 1.21 chs }
1389 1.21 chs if (skipbytes) {
1390 1.29 chs UVMHIST_LOG(ubchist, "skipbytes %d", skipbytes, 0,0,0);
1391 1.21 chs s = splbio();
1392 1.29 chs if (error) {
1393 1.29 chs mbp->b_flags |= B_ERROR;
1394 1.29 chs mbp->b_error = error;
1395 1.29 chs }
1396 1.37 chs mbp->b_resid -= skipbytes;
1397 1.21 chs if (mbp->b_resid == 0) {
1398 1.21 chs biodone(mbp);
1399 1.21 chs }
1400 1.21 chs splx(s);
1401 1.21 chs }
1402 1.21 chs if (async) {
1403 1.32 chs UVMHIST_LOG(ubchist, "returning 0 (async)", 0,0,0,0);
1404 1.32 chs return 0;
1405 1.21 chs }
1406 1.37 chs UVMHIST_LOG(ubchist, "waiting for mbp %p", mbp,0,0,0);
1407 1.37 chs error = biowait(mbp);
1408 1.37 chs uvm_aio_aiodone(mbp);
1409 1.21 chs UVMHIST_LOG(ubchist, "returning, error %d", error,0,0,0);
1410 1.29 chs return error;
1411 1.21 chs }
1412 1.21 chs
1413 1.37 chs void
1414 1.37 chs genfs_node_init(struct vnode *vp, struct genfs_ops *ops)
1415 1.37 chs {
1416 1.37 chs struct genfs_node *gp = VTOG(vp);
1417 1.37 chs
1418 1.37 chs lockinit(&gp->g_glock, PINOD, "glock", 0, 0);
1419 1.37 chs gp->g_op = ops;
1420 1.37 chs }
1421 1.37 chs
1422 1.37 chs void
1423 1.37 chs genfs_size(struct vnode *vp, off_t size, off_t *eobp)
1424 1.21 chs {
1425 1.21 chs int bsize;
1426 1.21 chs
1427 1.37 chs bsize = 1 << vp->v_mount->mnt_fs_bshift;
1428 1.37 chs *eobp = (size + bsize - 1) & ~(bsize - 1);
1429 1.1 mycroft }
1430