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/malloc.h>
48 #include <sys/mount.h>
49 #include <sys/mutex.h>
50 #include <sys/unistd.h>
51 #include <sys/vnode.h>
55 #include <vm/vm_object.h>
56 #include <vm/vm_extern.h>
58 #include <vm/vm_map.h>
59 #include <vm/vm_page.h>
60 #include <vm/vm_pager.h>
61 #include <vm/vnode_pager.h>
63 static int vop_nolookup(struct vop_lookup_args *);
64 static int vop_nostrategy(struct vop_strategy_args *);
67 * This vnode table stores what we want to do if the filesystem doesn't
68 * implement a particular VOP.
70 * If there is no specific entry here, we will return EOPNOTSUPP.
74 struct vop_vector default_vnodeops = {
76 .vop_bypass = VOP_EOPNOTSUPP,
78 .vop_advlock = VOP_EINVAL,
79 .vop_bmap = vop_stdbmap,
80 .vop_close = VOP_NULL,
81 .vop_fsync = VOP_NULL,
82 .vop_getpages = vop_stdgetpages,
83 .vop_getwritemount = vop_stdgetwritemount,
84 .vop_inactive = VOP_NULL,
85 .vop_ioctl = VOP_ENOTTY,
86 .vop_kqfilter = vop_stdkqfilter,
87 .vop_islocked = vop_stdislocked,
88 .vop_lease = VOP_NULL,
89 .vop_lock = vop_stdlock,
90 .vop_lookup = vop_nolookup,
92 .vop_pathconf = VOP_EINVAL,
93 .vop_poll = vop_nopoll,
94 .vop_putpages = vop_stdputpages,
95 .vop_readlink = VOP_EINVAL,
96 .vop_revoke = VOP_PANIC,
97 .vop_strategy = vop_nostrategy,
98 .vop_unlock = vop_stdunlock,
102 * Series of placeholder functions for various error returns for
107 vop_eopnotsupp(struct vop_generic_args *ap)
110 printf("vop_notsupp[%s]\n", ap->a_desc->vdesc_name);
117 vop_ebadf(struct vop_generic_args *ap)
124 vop_enotty(struct vop_generic_args *ap)
131 vop_einval(struct vop_generic_args *ap)
138 vop_null(struct vop_generic_args *ap)
145 * Helper function to panic on some bad VOPs in some filesystems.
148 vop_panic(struct vop_generic_args *ap)
151 panic("filesystem goof: vop_panic[%s]", ap->a_desc->vdesc_name);
155 * vop_std<something> and vop_no<something> are default functions for use by
156 * filesystems that need the "default reasonable" implementation for a
157 * particular operation.
159 * The documentation for the operations they implement exists (if it exists)
160 * in the VOP_<SOMETHING>(9) manpage (all uppercase).
164 * Default vop for filesystems that do not support name lookup
168 struct vop_lookup_args /* {
170 struct vnode **a_vpp;
171 struct componentname *a_cnp;
182 * Strategy routine for VFS devices that have none.
184 * BIO_ERROR and B_INVAL must be cleared prior to calling any strategy
185 * routine. Typically this is done for a BIO_READ strategy call.
186 * Typically B_INVAL is assumed to already be clear prior to a write
187 * and should not be cleared manually unless you just made the buffer
188 * invalid. BIO_ERROR should be cleared either way.
192 vop_nostrategy (struct vop_strategy_args *ap)
194 printf("No strategy for buffer at %p\n", ap->a_bp);
195 vprint("vnode", ap->a_vp);
196 ap->a_bp->b_ioflags |= BIO_ERROR;
197 ap->a_bp->b_error = EOPNOTSUPP;
205 * Standard implementation of POSIX pathconf, to get information about limits
207 * Override per filesystem for the case where the filesystem has smaller
212 struct vop_pathconf_args /* {
219 switch (ap->a_name) {
221 *ap->a_retval = LINK_MAX;
224 *ap->a_retval = MAX_CANON;
227 *ap->a_retval = MAX_INPUT;
230 *ap->a_retval = PIPE_BUF;
232 case _PC_CHOWN_RESTRICTED:
236 *ap->a_retval = _POSIX_VDISABLE;
245 * Standard lock, unlock and islocked functions.
249 struct vop_lock_args /* {
255 struct vnode *vp = ap->a_vp;
258 return (lockmgr(vp->v_vnlock, ap->a_flags, VI_MTX(vp), ap->a_td));
260 return (debuglockmgr(vp->v_vnlock, ap->a_flags, VI_MTX(vp),
261 ap->a_td, "vop_stdlock", vp->filename, vp->line));
268 struct vop_unlock_args /* {
274 struct vnode *vp = ap->a_vp;
276 return (lockmgr(vp->v_vnlock, ap->a_flags | LK_RELEASE, VI_MTX(vp),
283 struct vop_islocked_args /* {
289 return (lockstatus(ap->a_vp->v_vnlock, ap->a_td));
293 * Return true for select/poll.
297 struct vop_poll_args /* {
300 struct ucred *a_cred;
305 * Return true for read/write. If the user asked for something
306 * special, return POLLNVAL, so that clients have a way of
307 * determining reliably whether or not the extended
308 * functionality is present without hard-coding knowledge
309 * of specific filesystem implementations.
310 * Stay in sync with kern_conf.c::no_poll().
312 if (ap->a_events & ~POLLSTANDARD)
315 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
319 * Implement poll for local filesystems that support it.
323 struct vop_poll_args /* {
326 struct ucred *a_cred;
330 if (ap->a_events & ~POLLSTANDARD)
331 return (vn_pollrecord(ap->a_vp, ap->a_td, ap->a_events));
332 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
336 * Return our mount point, as we will take charge of the writes.
339 vop_stdgetwritemount(ap)
340 struct vop_getwritemount_args /* {
342 struct mount **a_mpp;
346 *(ap->a_mpp) = ap->a_vp->v_mount;
350 /* XXX Needs good comment and VOP_BMAP(9) manpage */
353 struct vop_bmap_args /* {
356 struct bufobj **a_bop;
363 if (ap->a_bop != NULL)
364 *ap->a_bop = &ap->a_vp->v_bufobj;
365 if (ap->a_bnp != NULL)
366 *ap->a_bnp = ap->a_bn * btodb(ap->a_vp->v_mount->mnt_stat.f_iosize);
367 if (ap->a_runp != NULL)
369 if (ap->a_runb != NULL)
376 struct vop_fsync_args /* {
378 struct ucred *a_cred;
383 struct vnode *vp = ap->a_vp;
388 int maxretry = 1000; /* large, arbitrarily chosen */
393 * MARK/SCAN initialization to avoid infinite loops.
395 TAILQ_FOREACH(bp, &vp->v_bufobj.bo_dirty.bv_hd, b_bobufs) {
396 bp->b_vflags &= ~BV_SCANNED;
401 * Flush all dirty buffers associated with a vnode.
404 TAILQ_FOREACH_SAFE(bp, &vp->v_bufobj.bo_dirty.bv_hd, b_bobufs, nbp) {
405 if ((bp->b_vflags & BV_SCANNED) != 0)
407 bp->b_vflags |= BV_SCANNED;
408 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT, NULL))
411 KASSERT(bp->b_bufobj == &vp->v_bufobj,
412 ("bp %p wrong b_bufobj %p should be %p",
413 bp, bp->b_bufobj, &vp->v_bufobj));
414 if ((bp->b_flags & B_DELWRI) == 0)
415 panic("fsync: not dirty");
416 if ((vp->v_object != NULL) && (bp->b_flags & B_CLUSTEROK)) {
427 * If synchronous the caller expects us to completely resolve all
428 * dirty buffers in the system. Wait for in-progress I/O to
429 * complete (which could include background bitmap writes), then
430 * retry if dirty blocks still exist.
432 if (ap->a_waitfor == MNT_WAIT) {
434 bufobj_wwait(bo, 0, 0);
435 if (bo->bo_dirty.bv_cnt > 0) {
437 * If we are unable to write any of these buffers
438 * then we fail now rather than trying endlessly
441 TAILQ_FOREACH(bp, &bo->bo_dirty.bv_hd, b_bobufs)
442 if ((error = bp->b_error) == 0)
444 if (error == 0 && --maxretry >= 0)
451 vprint("fsync: giving up on dirty", vp);
456 /* XXX Needs good comment and more info in the manpage (VOP_GETPAGES(9)). */
459 struct vop_getpages_args /* {
464 vm_ooffset_t a_offset;
468 return vnode_pager_generic_getpages(ap->a_vp, ap->a_m,
469 ap->a_count, ap->a_reqpage);
473 vop_stdkqfilter(struct vop_kqfilter_args *ap)
475 return vfs_kqfilter(ap);
478 /* XXX Needs good comment and more info in the manpage (VOP_PUTPAGES(9)). */
481 struct vop_putpages_args /* {
487 vm_ooffset_t a_offset;
491 return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
492 ap->a_sync, ap->a_rtvals);
497 * used to fill the vfs function table to get reasonable default return values.
500 vfs_stdroot (mp, flags, vpp, td)
511 vfs_stdstatfs (mp, sbp, td)
521 vfs_stdvptofh (vp, fhp)
530 vfs_stdquotactl (mp, cmds, uid, arg, td)
542 vfs_stdsync(mp, waitfor, td)
547 struct vnode *vp, *nvp;
548 int error, lockreq, allerror = 0;
550 lockreq = LK_EXCLUSIVE | LK_INTERLOCK;
551 if (waitfor != MNT_WAIT)
552 lockreq |= LK_NOWAIT;
554 * Force stale buffer cache information to be flushed.
558 MNT_VNODE_FOREACH(vp, mp, nvp) {
561 if (vp->v_bufobj.bo_dirty.bv_cnt == 0) {
567 if ((error = vget(vp, lockreq, td)) != 0) {
573 error = VOP_FSYNC(vp, waitfor, td);
577 VOP_UNLOCK(vp, 0, td);
586 vfs_stdnosync (mp, waitfor, td)
596 vfs_stdvget (mp, ino, flags, vpp)
607 vfs_stdfhtovp (mp, fhp, vpp)
618 struct vfsconf *vfsp;
626 struct vfsconf *vfsp;
633 vfs_stdextattrctl(mp, cmd, filename_vp, attrnamespace, attrname, td)
636 struct vnode *filename_vp;
638 const char *attrname;
642 if (filename_vp != NULL)
643 VOP_UNLOCK(filename_vp, 0, td);
648 vfs_stdsysctl(mp, op, req)
651 struct sysctl_req *req;
657 /* end of vfs default ops */