2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed
6 * to Berkeley by John Heidemann of the UCLA Ficus project.
8 * Source: * @(#)i405_init.c 2.10 92/04/27 UCLA Ficus project
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <sys/param.h>
39 #include <sys/systm.h>
43 #include <sys/event.h>
44 #include <sys/kernel.h>
45 #include <sys/limits.h>
47 #include <sys/lockf.h>
48 #include <sys/malloc.h>
49 #include <sys/mount.h>
50 #include <sys/mutex.h>
51 #include <sys/unistd.h>
52 #include <sys/vnode.h>
56 #include <vm/vm_object.h>
57 #include <vm/vm_extern.h>
59 #include <vm/vm_map.h>
60 #include <vm/vm_page.h>
61 #include <vm/vm_pager.h>
62 #include <vm/vnode_pager.h>
64 static int vop_nolookup(struct vop_lookup_args *);
65 static int vop_nostrategy(struct vop_strategy_args *);
68 * This vnode table stores what we want to do if the filesystem doesn't
69 * implement a particular VOP.
71 * If there is no specific entry here, we will return EOPNOTSUPP.
75 struct vop_vector default_vnodeops = {
77 .vop_bypass = VOP_EOPNOTSUPP,
79 .vop_advlock = vop_stdadvlock,
80 .vop_advlockasync = vop_stdadvlockasync,
81 .vop_bmap = vop_stdbmap,
82 .vop_close = VOP_NULL,
83 .vop_fsync = VOP_NULL,
84 .vop_getpages = vop_stdgetpages,
85 .vop_getwritemount = vop_stdgetwritemount,
86 .vop_inactive = VOP_NULL,
87 .vop_ioctl = VOP_ENOTTY,
88 .vop_kqfilter = vop_stdkqfilter,
89 .vop_islocked = vop_stdislocked,
90 .vop_lease = VOP_NULL,
91 .vop_lock1 = vop_stdlock,
92 .vop_lookup = vop_nolookup,
94 .vop_pathconf = VOP_EINVAL,
95 .vop_poll = vop_nopoll,
96 .vop_putpages = vop_stdputpages,
97 .vop_readlink = VOP_EINVAL,
98 .vop_revoke = VOP_PANIC,
99 .vop_strategy = vop_nostrategy,
100 .vop_unlock = vop_stdunlock,
101 .vop_vptofh = vop_stdvptofh,
105 * Series of placeholder functions for various error returns for
110 vop_eopnotsupp(struct vop_generic_args *ap)
113 printf("vop_notsupp[%s]\n", ap->a_desc->vdesc_name);
120 vop_ebadf(struct vop_generic_args *ap)
127 vop_enotty(struct vop_generic_args *ap)
134 vop_einval(struct vop_generic_args *ap)
141 vop_null(struct vop_generic_args *ap)
148 * Helper function to panic on some bad VOPs in some filesystems.
151 vop_panic(struct vop_generic_args *ap)
154 panic("filesystem goof: vop_panic[%s]", ap->a_desc->vdesc_name);
158 * vop_std<something> and vop_no<something> are default functions for use by
159 * filesystems that need the "default reasonable" implementation for a
160 * particular operation.
162 * The documentation for the operations they implement exists (if it exists)
163 * in the VOP_<SOMETHING>(9) manpage (all uppercase).
167 * Default vop for filesystems that do not support name lookup
171 struct vop_lookup_args /* {
173 struct vnode **a_vpp;
174 struct componentname *a_cnp;
185 * Strategy routine for VFS devices that have none.
187 * BIO_ERROR and B_INVAL must be cleared prior to calling any strategy
188 * routine. Typically this is done for a BIO_READ strategy call.
189 * Typically B_INVAL is assumed to already be clear prior to a write
190 * and should not be cleared manually unless you just made the buffer
191 * invalid. BIO_ERROR should be cleared either way.
195 vop_nostrategy (struct vop_strategy_args *ap)
197 printf("No strategy for buffer at %p\n", ap->a_bp);
198 vprint("vnode", ap->a_vp);
199 ap->a_bp->b_ioflags |= BIO_ERROR;
200 ap->a_bp->b_error = EOPNOTSUPP;
206 * Advisory record locking support
209 vop_stdadvlock(struct vop_advlock_args *ap)
211 struct vnode *vp = ap->a_vp;
212 struct thread *td = curthread;
216 vn_lock(vp, LK_SHARED | LK_RETRY, td);
217 error = VOP_GETATTR(vp, &vattr, td->td_ucred, td);
218 VOP_UNLOCK(vp, 0, td);
222 return (lf_advlock(ap, &(vp->v_lockf), vattr.va_size));
226 vop_stdadvlockasync(struct vop_advlockasync_args *ap)
228 struct vnode *vp = ap->a_vp;
229 struct thread *td = curthread;
233 vn_lock(vp, LK_SHARED | LK_RETRY, td);
234 error = VOP_GETATTR(vp, &vattr, td->td_ucred, td);
235 VOP_UNLOCK(vp, 0, td);
239 return (lf_advlockasync(ap, &(vp->v_lockf), vattr.va_size));
245 * Standard implementation of POSIX pathconf, to get information about limits
247 * Override per filesystem for the case where the filesystem has smaller
252 struct vop_pathconf_args /* {
259 switch (ap->a_name) {
261 *ap->a_retval = NAME_MAX;
264 *ap->a_retval = PATH_MAX;
267 *ap->a_retval = LINK_MAX;
270 *ap->a_retval = MAX_CANON;
273 *ap->a_retval = MAX_INPUT;
276 *ap->a_retval = PIPE_BUF;
278 case _PC_CHOWN_RESTRICTED:
282 *ap->a_retval = _POSIX_VDISABLE;
291 * Standard lock, unlock and islocked functions.
295 struct vop_lock1_args /* {
303 struct vnode *vp = ap->a_vp;
305 return (_lockmgr(vp->v_vnlock, ap->a_flags, VI_MTX(vp), ap->a_td, ap->a_file, ap->a_line));
311 struct vop_unlock_args /* {
317 struct vnode *vp = ap->a_vp;
319 return (lockmgr(vp->v_vnlock, ap->a_flags | LK_RELEASE, VI_MTX(vp),
326 struct vop_islocked_args /* {
332 return (lockstatus(ap->a_vp->v_vnlock, ap->a_td));
336 * Return true for select/poll.
340 struct vop_poll_args /* {
343 struct ucred *a_cred;
348 return (poll_no_poll(ap->a_events));
352 * Implement poll for local filesystems that support it.
356 struct vop_poll_args /* {
359 struct ucred *a_cred;
363 if (ap->a_events & ~POLLSTANDARD)
364 return (vn_pollrecord(ap->a_vp, ap->a_td, ap->a_events));
365 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
369 * Return our mount point, as we will take charge of the writes.
372 vop_stdgetwritemount(ap)
373 struct vop_getwritemount_args /* {
375 struct mount **a_mpp;
381 * XXX Since this is called unlocked we may be recycled while
382 * attempting to ref the mount. If this is the case or mountpoint
383 * will be set to NULL. We only have to prevent this call from
384 * returning with a ref to an incorrect mountpoint. It is not
385 * harmful to return with a ref to our previous mountpoint.
387 mp = ap->a_vp->v_mount;
390 if (mp != ap->a_vp->v_mount) {
399 /* XXX Needs good comment and VOP_BMAP(9) manpage */
402 struct vop_bmap_args /* {
405 struct bufobj **a_bop;
412 if (ap->a_bop != NULL)
413 *ap->a_bop = &ap->a_vp->v_bufobj;
414 if (ap->a_bnp != NULL)
415 *ap->a_bnp = ap->a_bn * btodb(ap->a_vp->v_mount->mnt_stat.f_iosize);
416 if (ap->a_runp != NULL)
418 if (ap->a_runb != NULL)
425 struct vop_fsync_args /* {
427 struct ucred *a_cred;
432 struct vnode *vp = ap->a_vp;
437 int maxretry = 1000; /* large, arbitrarily chosen */
442 * MARK/SCAN initialization to avoid infinite loops.
444 TAILQ_FOREACH(bp, &vp->v_bufobj.bo_dirty.bv_hd, b_bobufs) {
445 bp->b_vflags &= ~BV_SCANNED;
450 * Flush all dirty buffers associated with a vnode.
453 TAILQ_FOREACH_SAFE(bp, &vp->v_bufobj.bo_dirty.bv_hd, b_bobufs, nbp) {
454 if ((bp->b_vflags & BV_SCANNED) != 0)
456 bp->b_vflags |= BV_SCANNED;
457 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT, NULL))
460 KASSERT(bp->b_bufobj == &vp->v_bufobj,
461 ("bp %p wrong b_bufobj %p should be %p",
462 bp, bp->b_bufobj, &vp->v_bufobj));
463 if ((bp->b_flags & B_DELWRI) == 0)
464 panic("fsync: not dirty");
465 if ((vp->v_object != NULL) && (bp->b_flags & B_CLUSTEROK)) {
476 * If synchronous the caller expects us to completely resolve all
477 * dirty buffers in the system. Wait for in-progress I/O to
478 * complete (which could include background bitmap writes), then
479 * retry if dirty blocks still exist.
481 if (ap->a_waitfor == MNT_WAIT) {
483 bufobj_wwait(bo, 0, 0);
484 if (bo->bo_dirty.bv_cnt > 0) {
486 * If we are unable to write any of these buffers
487 * then we fail now rather than trying endlessly
490 TAILQ_FOREACH(bp, &bo->bo_dirty.bv_hd, b_bobufs)
491 if ((error = bp->b_error) == 0)
493 if (error == 0 && --maxretry >= 0)
500 vprint("fsync: giving up on dirty", vp);
505 /* XXX Needs good comment and more info in the manpage (VOP_GETPAGES(9)). */
508 struct vop_getpages_args /* {
513 vm_ooffset_t a_offset;
517 return vnode_pager_generic_getpages(ap->a_vp, ap->a_m,
518 ap->a_count, ap->a_reqpage);
522 vop_stdkqfilter(struct vop_kqfilter_args *ap)
524 return vfs_kqfilter(ap);
527 /* XXX Needs good comment and more info in the manpage (VOP_PUTPAGES(9)). */
530 struct vop_putpages_args /* {
536 vm_ooffset_t a_offset;
540 return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
541 ap->a_sync, ap->a_rtvals);
545 vop_stdvptofh(struct vop_vptofh_args *ap)
552 * used to fill the vfs function table to get reasonable default return values.
555 vfs_stdroot (mp, flags, vpp, td)
566 vfs_stdstatfs (mp, sbp, td)
576 vfs_stdquotactl (mp, cmds, uid, arg, td)
588 vfs_stdsync(mp, waitfor, td)
593 struct vnode *vp, *mvp;
594 int error, lockreq, allerror = 0;
596 lockreq = LK_EXCLUSIVE | LK_INTERLOCK;
597 if (waitfor != MNT_WAIT)
598 lockreq |= LK_NOWAIT;
600 * Force stale buffer cache information to be flushed.
604 MNT_VNODE_FOREACH(vp, mp, mvp) {
607 if (vp->v_bufobj.bo_dirty.bv_cnt == 0) {
613 if ((error = vget(vp, lockreq, td)) != 0) {
615 if (error == ENOENT) {
616 MNT_VNODE_FOREACH_ABORT_ILOCKED(mp, mvp);
621 error = VOP_FSYNC(vp, waitfor, td);
625 /* Do not turn this into vput. td is not always curthread. */
626 VOP_UNLOCK(vp, 0, td);
635 vfs_stdnosync (mp, waitfor, td)
645 vfs_stdvget (mp, ino, flags, vpp)
656 vfs_stdfhtovp (mp, fhp, vpp)
667 struct vfsconf *vfsp;
675 struct vfsconf *vfsp;
682 vfs_stdextattrctl(mp, cmd, filename_vp, attrnamespace, attrname, td)
685 struct vnode *filename_vp;
687 const char *attrname;
691 if (filename_vp != NULL)
692 VOP_UNLOCK(filename_vp, 0, td);
697 vfs_stdsysctl(mp, op, req)
700 struct sysctl_req *req;
706 /* end of vfs default ops */