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_lock1 = 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,
99 .vop_vptofh = vop_stdvptofh,
103 * Series of placeholder functions for various error returns for
108 vop_eopnotsupp(struct vop_generic_args *ap)
111 printf("vop_notsupp[%s]\n", ap->a_desc->vdesc_name);
118 vop_ebadf(struct vop_generic_args *ap)
125 vop_enotty(struct vop_generic_args *ap)
132 vop_einval(struct vop_generic_args *ap)
139 vop_null(struct vop_generic_args *ap)
146 * Helper function to panic on some bad VOPs in some filesystems.
149 vop_panic(struct vop_generic_args *ap)
152 panic("filesystem goof: vop_panic[%s]", ap->a_desc->vdesc_name);
156 * vop_std<something> and vop_no<something> are default functions for use by
157 * filesystems that need the "default reasonable" implementation for a
158 * particular operation.
160 * The documentation for the operations they implement exists (if it exists)
161 * in the VOP_<SOMETHING>(9) manpage (all uppercase).
165 * Default vop for filesystems that do not support name lookup
169 struct vop_lookup_args /* {
171 struct vnode **a_vpp;
172 struct componentname *a_cnp;
183 * Strategy routine for VFS devices that have none.
185 * BIO_ERROR and B_INVAL must be cleared prior to calling any strategy
186 * routine. Typically this is done for a BIO_READ strategy call.
187 * Typically B_INVAL is assumed to already be clear prior to a write
188 * and should not be cleared manually unless you just made the buffer
189 * invalid. BIO_ERROR should be cleared either way.
193 vop_nostrategy (struct vop_strategy_args *ap)
195 printf("No strategy for buffer at %p\n", ap->a_bp);
196 vprint("vnode", ap->a_vp);
197 ap->a_bp->b_ioflags |= BIO_ERROR;
198 ap->a_bp->b_error = EOPNOTSUPP;
206 * Standard implementation of POSIX pathconf, to get information about limits
208 * Override per filesystem for the case where the filesystem has smaller
213 struct vop_pathconf_args /* {
220 switch (ap->a_name) {
222 *ap->a_retval = NAME_MAX;
225 *ap->a_retval = PATH_MAX;
228 *ap->a_retval = LINK_MAX;
231 *ap->a_retval = MAX_CANON;
234 *ap->a_retval = MAX_INPUT;
237 *ap->a_retval = PIPE_BUF;
239 case _PC_CHOWN_RESTRICTED:
243 *ap->a_retval = _POSIX_VDISABLE;
252 * Standard lock, unlock and islocked functions.
256 struct vop_lock1_args /* {
264 struct vnode *vp = ap->a_vp;
266 return (_lockmgr(vp->v_vnlock, ap->a_flags, VI_MTX(vp), ap->a_td, ap->a_file, ap->a_line));
272 struct vop_unlock_args /* {
278 struct vnode *vp = ap->a_vp;
280 return (lockmgr(vp->v_vnlock, ap->a_flags | LK_RELEASE, VI_MTX(vp),
287 struct vop_islocked_args /* {
293 return (lockstatus(ap->a_vp->v_vnlock, ap->a_td));
297 * Return true for select/poll.
301 struct vop_poll_args /* {
304 struct ucred *a_cred;
309 * Return true for read/write. If the user asked for something
310 * special, return POLLNVAL, so that clients have a way of
311 * determining reliably whether or not the extended
312 * functionality is present without hard-coding knowledge
313 * of specific filesystem implementations.
314 * Stay in sync with kern_conf.c::no_poll().
316 if (ap->a_events & ~POLLSTANDARD)
319 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
323 * Implement poll for local filesystems that support it.
327 struct vop_poll_args /* {
330 struct ucred *a_cred;
334 if (ap->a_events & ~POLLSTANDARD)
335 return (vn_pollrecord(ap->a_vp, ap->a_td, ap->a_events));
336 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
340 * Return our mount point, as we will take charge of the writes.
343 vop_stdgetwritemount(ap)
344 struct vop_getwritemount_args /* {
346 struct mount **a_mpp;
352 * XXX Since this is called unlocked we may be recycled while
353 * attempting to ref the mount. If this is the case or mountpoint
354 * will be set to NULL. We only have to prevent this call from
355 * returning with a ref to an incorrect mountpoint. It is not
356 * harmful to return with a ref to our previous mountpoint.
358 mp = ap->a_vp->v_mount;
361 if (mp != ap->a_vp->v_mount) {
370 /* XXX Needs good comment and VOP_BMAP(9) manpage */
373 struct vop_bmap_args /* {
376 struct bufobj **a_bop;
383 if (ap->a_bop != NULL)
384 *ap->a_bop = &ap->a_vp->v_bufobj;
385 if (ap->a_bnp != NULL)
386 *ap->a_bnp = ap->a_bn * btodb(ap->a_vp->v_mount->mnt_stat.f_iosize);
387 if (ap->a_runp != NULL)
389 if (ap->a_runb != NULL)
396 struct vop_fsync_args /* {
398 struct ucred *a_cred;
403 struct vnode *vp = ap->a_vp;
408 int maxretry = 1000; /* large, arbitrarily chosen */
413 * MARK/SCAN initialization to avoid infinite loops.
415 TAILQ_FOREACH(bp, &vp->v_bufobj.bo_dirty.bv_hd, b_bobufs) {
416 bp->b_vflags &= ~BV_SCANNED;
421 * Flush all dirty buffers associated with a vnode.
424 TAILQ_FOREACH_SAFE(bp, &vp->v_bufobj.bo_dirty.bv_hd, b_bobufs, nbp) {
425 if ((bp->b_vflags & BV_SCANNED) != 0)
427 bp->b_vflags |= BV_SCANNED;
428 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT, NULL))
431 KASSERT(bp->b_bufobj == &vp->v_bufobj,
432 ("bp %p wrong b_bufobj %p should be %p",
433 bp, bp->b_bufobj, &vp->v_bufobj));
434 if ((bp->b_flags & B_DELWRI) == 0)
435 panic("fsync: not dirty");
436 if ((vp->v_object != NULL) && (bp->b_flags & B_CLUSTEROK)) {
447 * If synchronous the caller expects us to completely resolve all
448 * dirty buffers in the system. Wait for in-progress I/O to
449 * complete (which could include background bitmap writes), then
450 * retry if dirty blocks still exist.
452 if (ap->a_waitfor == MNT_WAIT) {
454 bufobj_wwait(bo, 0, 0);
455 if (bo->bo_dirty.bv_cnt > 0) {
457 * If we are unable to write any of these buffers
458 * then we fail now rather than trying endlessly
461 TAILQ_FOREACH(bp, &bo->bo_dirty.bv_hd, b_bobufs)
462 if ((error = bp->b_error) == 0)
464 if (error == 0 && --maxretry >= 0)
471 vprint("fsync: giving up on dirty", vp);
476 /* XXX Needs good comment and more info in the manpage (VOP_GETPAGES(9)). */
479 struct vop_getpages_args /* {
484 vm_ooffset_t a_offset;
488 return vnode_pager_generic_getpages(ap->a_vp, ap->a_m,
489 ap->a_count, ap->a_reqpage);
493 vop_stdkqfilter(struct vop_kqfilter_args *ap)
495 return vfs_kqfilter(ap);
498 /* XXX Needs good comment and more info in the manpage (VOP_PUTPAGES(9)). */
501 struct vop_putpages_args /* {
507 vm_ooffset_t a_offset;
511 return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
512 ap->a_sync, ap->a_rtvals);
516 vop_stdvptofh(struct vop_vptofh_args *ap)
523 * used to fill the vfs function table to get reasonable default return values.
526 vfs_stdroot (mp, flags, vpp, td)
537 vfs_stdstatfs (mp, sbp, td)
547 vfs_stdquotactl (mp, cmds, uid, arg, td)
559 vfs_stdsync(mp, waitfor, td)
564 struct vnode *vp, *mvp;
565 int error, lockreq, allerror = 0;
567 lockreq = LK_EXCLUSIVE | LK_INTERLOCK;
568 if (waitfor != MNT_WAIT)
569 lockreq |= LK_NOWAIT;
571 * Force stale buffer cache information to be flushed.
575 MNT_VNODE_FOREACH(vp, mp, mvp) {
578 if (vp->v_bufobj.bo_dirty.bv_cnt == 0) {
584 if ((error = vget(vp, lockreq, td)) != 0) {
586 if (error == ENOENT) {
587 MNT_VNODE_FOREACH_ABORT_ILOCKED(mp, mvp);
592 error = VOP_FSYNC(vp, waitfor, td);
596 /* Do not turn this into vput. td is not always curthread. */
597 VOP_UNLOCK(vp, 0, td);
606 vfs_stdnosync (mp, waitfor, td)
616 vfs_stdvget (mp, ino, flags, vpp)
627 vfs_stdfhtovp (mp, fhp, vpp)
638 struct vfsconf *vfsp;
646 struct vfsconf *vfsp;
653 vfs_stdextattrctl(mp, cmd, filename_vp, attrnamespace, attrname, td)
656 struct vnode *filename_vp;
658 const char *attrname;
662 if (filename_vp != NULL)
663 VOP_UNLOCK(filename_vp, 0, td);
668 vfs_stdsysctl(mp, op, req)
671 struct sysctl_req *req;
677 /* end of vfs default ops */