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/kernel.h>
44 #include <sys/limits.h>
46 #include <sys/malloc.h>
47 #include <sys/mount.h>
48 #include <sys/mutex.h>
49 #include <sys/unistd.h>
50 #include <sys/vnode.h>
54 #include <vm/vm_object.h>
55 #include <vm/vm_extern.h>
57 #include <vm/vm_map.h>
58 #include <vm/vm_page.h>
59 #include <vm/vm_pager.h>
60 #include <vm/vnode_pager.h>
62 static int vop_nolookup(struct vop_lookup_args *);
63 static int vop_nostrategy(struct vop_strategy_args *);
66 * This vnode table stores what we want to do if the filesystem doesn't
67 * implement a particular VOP.
69 * If there is no specific entry here, we will return EOPNOTSUPP.
73 struct vop_vector default_vnodeops = {
75 .vop_bypass = VOP_EOPNOTSUPP,
77 .vop_advlock = VOP_EINVAL,
78 .vop_bmap = vop_stdbmap,
79 .vop_close = VOP_NULL,
80 .vop_fsync = VOP_NULL,
81 .vop_getpages = vop_stdgetpages,
82 .vop_getwritemount = vop_stdgetwritemount,
83 .vop_inactive = VOP_NULL,
84 .vop_ioctl = VOP_ENOTTY,
85 .vop_islocked = vop_stdislocked,
86 .vop_lease = VOP_NULL,
87 .vop_lock = vop_stdlock,
88 .vop_lookup = vop_nolookup,
90 .vop_pathconf = VOP_EINVAL,
91 .vop_poll = vop_nopoll,
92 .vop_putpages = vop_stdputpages,
93 .vop_readlink = VOP_EINVAL,
94 .vop_revoke = VOP_PANIC,
95 .vop_strategy = vop_nostrategy,
96 .vop_unlock = vop_stdunlock,
100 * Series of placeholder functions for various error returns for
105 vop_eopnotsupp(struct vop_generic_args *ap)
108 printf("vop_notsupp[%s]\n", ap->a_desc->vdesc_name);
115 vop_ebadf(struct vop_generic_args *ap)
122 vop_enotty(struct vop_generic_args *ap)
129 vop_einval(struct vop_generic_args *ap)
136 vop_null(struct vop_generic_args *ap)
143 * Helper function to panic on some bad VOPs in some filesystems.
146 vop_panic(struct vop_generic_args *ap)
149 panic("filesystem goof: vop_panic[%s]", ap->a_desc->vdesc_name);
153 * vop_std<something> and vop_no<something> are default functions for use by
154 * filesystems that need the "default reasonable" implementation for a
155 * particular operation.
157 * The documentation for the operations they implement exists (if it exists)
158 * in the VOP_<SOMETHING>(9) manpage (all uppercase).
162 * Default vop for filesystems that do not support name lookup
166 struct vop_lookup_args /* {
168 struct vnode **a_vpp;
169 struct componentname *a_cnp;
180 * Strategy routine for VFS devices that have none.
182 * BIO_ERROR and B_INVAL must be cleared prior to calling any strategy
183 * routine. Typically this is done for a BIO_READ strategy call.
184 * Typically B_INVAL is assumed to already be clear prior to a write
185 * and should not be cleared manually unless you just made the buffer
186 * invalid. BIO_ERROR should be cleared either way.
190 vop_nostrategy (struct vop_strategy_args *ap)
192 printf("No strategy for buffer at %p\n", ap->a_bp);
193 vprint("vnode", ap->a_vp);
194 ap->a_bp->b_ioflags |= BIO_ERROR;
195 ap->a_bp->b_error = EOPNOTSUPP;
203 * Standard implementation of POSIX pathconf, to get information about limits
205 * Override per filesystem for the case where the filesystem has smaller
210 struct vop_pathconf_args /* {
217 switch (ap->a_name) {
219 *ap->a_retval = LINK_MAX;
222 *ap->a_retval = MAX_CANON;
225 *ap->a_retval = MAX_INPUT;
228 *ap->a_retval = PIPE_BUF;
230 case _PC_CHOWN_RESTRICTED:
234 *ap->a_retval = _POSIX_VDISABLE;
243 * Standard lock, unlock and islocked functions.
247 struct vop_lock_args /* {
253 struct vnode *vp = ap->a_vp;
256 return (lockmgr(vp->v_vnlock, ap->a_flags, VI_MTX(vp), ap->a_td));
258 return (debuglockmgr(vp->v_vnlock, ap->a_flags, VI_MTX(vp),
259 ap->a_td, "vop_stdlock", vp->filename, vp->line));
266 struct vop_unlock_args /* {
272 struct vnode *vp = ap->a_vp;
274 return (lockmgr(vp->v_vnlock, ap->a_flags | LK_RELEASE, VI_MTX(vp),
281 struct vop_islocked_args /* {
287 return (lockstatus(ap->a_vp->v_vnlock, ap->a_td));
291 * Return true for select/poll.
295 struct vop_poll_args /* {
298 struct ucred *a_cred;
303 * Return true for read/write. If the user asked for something
304 * special, return POLLNVAL, so that clients have a way of
305 * determining reliably whether or not the extended
306 * functionality is present without hard-coding knowledge
307 * of specific filesystem implementations.
308 * Stay in sync with kern_conf.c::no_poll().
310 if (ap->a_events & ~POLLSTANDARD)
313 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
317 * Implement poll for local filesystems that support it.
321 struct vop_poll_args /* {
324 struct ucred *a_cred;
328 if (ap->a_events & ~POLLSTANDARD)
329 return (vn_pollrecord(ap->a_vp, ap->a_td, ap->a_events));
330 return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
334 * Return our mount point, as we will take charge of the writes.
337 vop_stdgetwritemount(ap)
338 struct vop_getwritemount_args /* {
340 struct mount **a_mpp;
344 *(ap->a_mpp) = ap->a_vp->v_mount;
348 /* XXX Needs good comment and VOP_BMAP(9) manpage */
351 struct vop_bmap_args /* {
354 struct bufobj **a_bop;
361 if (ap->a_bop != NULL)
362 *ap->a_bop = &ap->a_vp->v_bufobj;
363 if (ap->a_bnp != NULL)
364 *ap->a_bnp = ap->a_bn * btodb(ap->a_vp->v_mount->mnt_stat.f_iosize);
365 if (ap->a_runp != NULL)
367 if (ap->a_runb != NULL)
374 struct vop_fsync_args /* {
376 struct ucred *a_cred;
381 struct vnode *vp = ap->a_vp;
386 int maxretry = 1000; /* large, arbitrarily chosen */
391 * MARK/SCAN initialization to avoid infinite loops.
393 TAILQ_FOREACH(bp, &vp->v_bufobj.bo_dirty.bv_hd, b_bobufs) {
394 bp->b_vflags &= ~BV_SCANNED;
399 * Flush all dirty buffers associated with a vnode.
402 TAILQ_FOREACH_SAFE(bp, &vp->v_bufobj.bo_dirty.bv_hd, b_bobufs, nbp) {
403 if ((bp->b_vflags & BV_SCANNED) != 0)
405 bp->b_vflags |= BV_SCANNED;
406 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT, NULL))
409 if ((bp->b_flags & B_DELWRI) == 0)
410 panic("fsync: not dirty");
411 if ((vp->v_object != NULL) && (bp->b_flags & B_CLUSTEROK)) {
422 * If synchronous the caller expects us to completely resolve all
423 * dirty buffers in the system. Wait for in-progress I/O to
424 * complete (which could include background bitmap writes), then
425 * retry if dirty blocks still exist.
427 if (ap->a_waitfor == MNT_WAIT) {
429 bufobj_wwait(bo, 0, 0);
430 if (bo->bo_dirty.bv_cnt > 0) {
432 * If we are unable to write any of these buffers
433 * then we fail now rather than trying endlessly
436 TAILQ_FOREACH(bp, &bo->bo_dirty.bv_hd, b_bobufs)
437 if ((error = bp->b_error) == 0)
439 if (error == 0 && --maxretry >= 0)
446 vprint("fsync: giving up on dirty", vp);
451 /* XXX Needs good comment and more info in the manpage (VOP_GETPAGES(9)). */
454 struct vop_getpages_args /* {
459 vm_ooffset_t a_offset;
463 return vnode_pager_generic_getpages(ap->a_vp, ap->a_m,
464 ap->a_count, ap->a_reqpage);
467 /* XXX Needs good comment and more info in the manpage (VOP_PUTPAGES(9)). */
470 struct vop_putpages_args /* {
476 vm_ooffset_t a_offset;
480 return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
481 ap->a_sync, ap->a_rtvals);
486 * used to fill the vfs function table to get reasonable default return values.
489 vfs_stdroot (mp, flags, vpp, td)
500 vfs_stdstatfs (mp, sbp, td)
510 vfs_stdvptofh (vp, fhp)
519 vfs_stdquotactl (mp, cmds, uid, arg, td)
531 vfs_stdsync(mp, waitfor, td)
536 struct vnode *vp, *nvp;
537 int error, lockreq, allerror = 0;
539 lockreq = LK_EXCLUSIVE | LK_INTERLOCK;
540 if (waitfor != MNT_WAIT)
541 lockreq |= LK_NOWAIT;
543 * Force stale buffer cache information to be flushed.
547 MNT_VNODE_FOREACH(vp, mp, nvp) {
550 if (vp->v_bufobj.bo_dirty.bv_cnt == 0) {
556 if ((error = vget(vp, lockreq, td)) != 0) {
562 error = VOP_FSYNC(vp, waitfor, td);
566 VOP_UNLOCK(vp, 0, td);
575 vfs_stdnosync (mp, waitfor, td)
585 vfs_stdvget (mp, ino, flags, vpp)
596 vfs_stdfhtovp (mp, fhp, vpp)
607 struct vfsconf *vfsp;
615 struct vfsconf *vfsp;
622 vfs_stdextattrctl(mp, cmd, filename_vp, attrnamespace, attrname, td)
625 struct vnode *filename_vp;
627 const char *attrname;
631 if (filename_vp != NULL)
632 VOP_UNLOCK(filename_vp, 0, td);
637 vfs_stdsysctl(mp, op, req)
640 struct sysctl_req *req;
646 /* end of vfs default ops */