vfs_default.c revision 114216
130489Sphk/* 230489Sphk * Copyright (c) 1989, 1993 330489Sphk * The Regents of the University of California. All rights reserved. 430489Sphk * 530489Sphk * This code is derived from software contributed 630489Sphk * to Berkeley by John Heidemann of the UCLA Ficus project. 730489Sphk * 830489Sphk * Source: * @(#)i405_init.c 2.10 92/04/27 UCLA Ficus project 930489Sphk * 1030489Sphk * Redistribution and use in source and binary forms, with or without 1130489Sphk * modification, are permitted provided that the following conditions 1230489Sphk * are met: 1330489Sphk * 1. Redistributions of source code must retain the above copyright 1430489Sphk * notice, this list of conditions and the following disclaimer. 1530489Sphk * 2. Redistributions in binary form must reproduce the above copyright 1630489Sphk * notice, this list of conditions and the following disclaimer in the 1730489Sphk * documentation and/or other materials provided with the distribution. 1830489Sphk * 3. All advertising materials mentioning features or use of this software 1930489Sphk * must display the following acknowledgement: 2030489Sphk * This product includes software developed by the University of 2130489Sphk * California, Berkeley and its contributors. 2230489Sphk * 4. Neither the name of the University nor the names of its contributors 2330489Sphk * may be used to endorse or promote products derived from this software 2430489Sphk * without specific prior written permission. 2530489Sphk * 2630489Sphk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2730489Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2830489Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2930489Sphk * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 3030489Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3130489Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3230489Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3330489Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3430489Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3530489Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3630489Sphk * SUCH DAMAGE. 3730489Sphk * 3847989Sgpalmer * 3950477Speter * $FreeBSD: head/sys/kern/vfs_default.c 114216 2003-04-29 13:36:06Z kan $ 4030489Sphk */ 4130489Sphk 4230489Sphk#include <sys/param.h> 4330489Sphk#include <sys/systm.h> 4460041Sphk#include <sys/bio.h> 4544272Sbde#include <sys/buf.h> 4665770Sbp#include <sys/conf.h> 4730489Sphk#include <sys/kernel.h> 48114216Skan#include <sys/limits.h> 4931561Sbde#include <sys/lock.h> 5030743Sphk#include <sys/malloc.h> 5151068Salfred#include <sys/mount.h> 5267365Sjhb#include <sys/mutex.h> 5330492Sphk#include <sys/unistd.h> 5430489Sphk#include <sys/vnode.h> 5530743Sphk#include <sys/poll.h> 5630489Sphk 5765770Sbp#include <vm/vm.h> 5865770Sbp#include <vm/vm_object.h> 5965770Sbp#include <vm/vm_extern.h> 6065770Sbp#include <vm/pmap.h> 6165770Sbp#include <vm/vm_map.h> 6265770Sbp#include <vm/vm_page.h> 6365770Sbp#include <vm/vm_pager.h> 6465770Sbp#include <vm/vnode_pager.h> 6565770Sbp 6692723Salfredstatic int vop_nolookup(struct vop_lookup_args *); 6792723Salfredstatic int vop_nostrategy(struct vop_strategy_args *); 68108686Sphkstatic int vop_nospecstrategy(struct vop_specstrategy_args *); 6930489Sphk 7030489Sphk/* 7130489Sphk * This vnode table stores what we want to do if the filesystem doesn't 7230489Sphk * implement a particular VOP. 7330489Sphk * 7430489Sphk * If there is no specific entry here, we will return EOPNOTSUPP. 7530489Sphk * 7630489Sphk */ 7730489Sphk 7830489Sphkvop_t **default_vnodeop_p; 7930489Sphkstatic struct vnodeopv_entry_desc default_vnodeop_entries[] = { 8030492Sphk { &vop_default_desc, (vop_t *) vop_eopnotsupp }, 8130492Sphk { &vop_advlock_desc, (vop_t *) vop_einval }, 8276131Sphk { &vop_bmap_desc, (vop_t *) vop_stdbmap }, 8330492Sphk { &vop_close_desc, (vop_t *) vop_null }, 8465770Sbp { &vop_createvobject_desc, (vop_t *) vop_stdcreatevobject }, 8565770Sbp { &vop_destroyvobject_desc, (vop_t *) vop_stddestroyvobject }, 8630492Sphk { &vop_fsync_desc, (vop_t *) vop_null }, 8776167Sphk { &vop_getpages_desc, (vop_t *) vop_stdgetpages }, 8865770Sbp { &vop_getvobject_desc, (vop_t *) vop_stdgetvobject }, 8964819Sphk { &vop_inactive_desc, (vop_t *) vop_stdinactive }, 9030492Sphk { &vop_ioctl_desc, (vop_t *) vop_enotty }, 91100739Sjeff { &vop_islocked_desc, (vop_t *) vop_stdislocked }, 9230739Sphk { &vop_lease_desc, (vop_t *) vop_null }, 93100739Sjeff { &vop_lock_desc, (vop_t *) vop_stdlock }, 9472594Sbde { &vop_lookup_desc, (vop_t *) vop_nolookup }, 9530492Sphk { &vop_open_desc, (vop_t *) vop_null }, 9630492Sphk { &vop_pathconf_desc, (vop_t *) vop_einval }, 97108680Sphk { &vop_poll_desc, (vop_t *) vop_nopoll }, 9876167Sphk { &vop_putpages_desc, (vop_t *) vop_stdputpages }, 9930492Sphk { &vop_readlink_desc, (vop_t *) vop_einval }, 10030489Sphk { &vop_revoke_desc, (vop_t *) vop_revoke }, 101108686Sphk { &vop_specstrategy_desc, (vop_t *) vop_nospecstrategy }, 10230489Sphk { &vop_strategy_desc, (vop_t *) vop_nostrategy }, 103100739Sjeff { &vop_unlock_desc, (vop_t *) vop_stdunlock }, 10430489Sphk { NULL, NULL } 10530489Sphk}; 10630489Sphk 10730489Sphkstatic struct vnodeopv_desc default_vnodeop_opv_desc = 10830489Sphk { &default_vnodeop_p, default_vnodeop_entries }; 10930489Sphk 11030489SphkVNODEOP_SET(default_vnodeop_opv_desc); 11130489Sphk 11291690Seivind/* 11391690Seivind * Series of placeholder functions for various error returns for 11491690Seivind * VOPs. 11591690Seivind */ 11691690Seivind 11730489Sphkint 11830492Sphkvop_eopnotsupp(struct vop_generic_args *ap) 11930489Sphk{ 12030489Sphk /* 12130492Sphk printf("vop_notsupp[%s]\n", ap->a_desc->vdesc_name); 12230489Sphk */ 12330489Sphk 12430489Sphk return (EOPNOTSUPP); 12530489Sphk} 12630489Sphk 12730489Sphkint 12830492Sphkvop_ebadf(struct vop_generic_args *ap) 12930489Sphk{ 13030489Sphk 13130492Sphk return (EBADF); 13230492Sphk} 13330492Sphk 13430492Sphkint 13530492Sphkvop_enotty(struct vop_generic_args *ap) 13630492Sphk{ 13730492Sphk 13830492Sphk return (ENOTTY); 13930492Sphk} 14030492Sphk 14130492Sphkint 14230492Sphkvop_einval(struct vop_generic_args *ap) 14330492Sphk{ 14430492Sphk 14530492Sphk return (EINVAL); 14630492Sphk} 14730492Sphk 14830492Sphkint 14930492Sphkvop_null(struct vop_generic_args *ap) 15030492Sphk{ 15130492Sphk 15230492Sphk return (0); 15330492Sphk} 15430492Sphk 15591690Seivind/* 15691690Seivind * Used to make a defined VOP fall back to the default VOP. 15791690Seivind */ 15830492Sphkint 15930492Sphkvop_defaultop(struct vop_generic_args *ap) 16030492Sphk{ 16130492Sphk 16230489Sphk return (VOCALL(default_vnodeop_p, ap->a_desc->vdesc_offset, ap)); 16330489Sphk} 16430489Sphk 16591690Seivind/* 16691690Seivind * Helper function to panic on some bad VOPs in some filesystems. 16791690Seivind */ 16841056Speterint 16941056Spetervop_panic(struct vop_generic_args *ap) 17041056Speter{ 17141056Speter 17272594Sbde panic("filesystem goof: vop_panic[%s]", ap->a_desc->vdesc_name); 17341056Speter} 17441056Speter 17591690Seivind/* 17691690Seivind * vop_std<something> and vop_no<something> are default functions for use by 17791690Seivind * filesystems that need the "default reasonable" implementation for a 17891690Seivind * particular operation. 17991690Seivind * 18091690Seivind * The documentation for the operations they implement exists (if it exists) 18191690Seivind * in the VOP_<SOMETHING>(9) manpage (all uppercase). 18291690Seivind */ 18391690Seivind 18491690Seivind/* 18591690Seivind * Default vop for filesystems that do not support name lookup 18691690Seivind */ 18772594Sbdestatic int 18872594Sbdevop_nolookup(ap) 18972594Sbde struct vop_lookup_args /* { 19072594Sbde struct vnode *a_dvp; 19172594Sbde struct vnode **a_vpp; 19272594Sbde struct componentname *a_cnp; 19372594Sbde } */ *ap; 19472594Sbde{ 19572594Sbde 19672594Sbde *ap->a_vpp = NULL; 19772594Sbde return (ENOTDIR); 19872594Sbde} 19972594Sbde 20046349Salc/* 20146349Salc * vop_nostrategy: 20246349Salc * 20346349Salc * Strategy routine for VFS devices that have none. 20446349Salc * 20558934Sphk * BIO_ERROR and B_INVAL must be cleared prior to calling any strategy 20658345Sphk * routine. Typically this is done for a BIO_READ strategy call. 207112067Skan * Typically B_INVAL is assumed to already be clear prior to a write 20858345Sphk * and should not be cleared manually unless you just made the buffer 20958934Sphk * invalid. BIO_ERROR should be cleared either way. 21046349Salc */ 21146349Salc 21230489Sphkstatic int 21330489Sphkvop_nostrategy (struct vop_strategy_args *ap) 21430489Sphk{ 21530489Sphk printf("No strategy for buffer at %p\n", ap->a_bp); 216111842Snjl vprint("vnode", ap->a_vp); 217111842Snjl vprint("device vnode", ap->a_bp->b_vp); 21858934Sphk ap->a_bp->b_ioflags |= BIO_ERROR; 21930489Sphk ap->a_bp->b_error = EOPNOTSUPP; 22059249Sphk bufdone(ap->a_bp); 22130489Sphk return (EOPNOTSUPP); 22230489Sphk} 22330492Sphk 22491690Seivind/* 225108686Sphk * vop_nospecstrategy: 226108686Sphk * 227108686Sphk * This shouldn't happen. VOP_SPECSTRATEGY should always have a VCHR 228108686Sphk * argument vnode, and thos have a method for specstrategy over in 229108686Sphk * specfs, so we only ever get here if somebody botched it. 230108686Sphk * Pass the call to VOP_STRATEGY() and get on with life. 231108686Sphk * The first time we print some info useful for debugging. 232108686Sphk */ 233108686Sphk 234108686Sphkstatic int 235108686Sphkvop_nospecstrategy (struct vop_specstrategy_args *ap) 236108686Sphk{ 237108686Sphk static int once; 238108686Sphk 239108686Sphk if (!once) { 240111842Snjl vprint("VOP_SPECSTRATEGY on non-VCHR", ap->a_vp); 241108686Sphk backtrace(); 242108686Sphk once++; 243108686Sphk } 244108686Sphk return VOP_STRATEGY(ap->a_vp, ap->a_bp); 245108686Sphk} 246108686Sphk 247108686Sphk/* 24891690Seivind * vop_stdpathconf: 249112067Skan * 25091690Seivind * Standard implementation of POSIX pathconf, to get information about limits 25191690Seivind * for a filesystem. 25291690Seivind * Override per filesystem for the case where the filesystem has smaller 25391690Seivind * limits. 25491690Seivind */ 25530492Sphkint 25630492Sphkvop_stdpathconf(ap) 25730492Sphk struct vop_pathconf_args /* { 25830492Sphk struct vnode *a_vp; 25930492Sphk int a_name; 26030492Sphk int *a_retval; 26130492Sphk } */ *ap; 26230492Sphk{ 26330492Sphk 26430492Sphk switch (ap->a_name) { 26530492Sphk case _PC_LINK_MAX: 26630492Sphk *ap->a_retval = LINK_MAX; 26730492Sphk return (0); 26830492Sphk case _PC_MAX_CANON: 26930492Sphk *ap->a_retval = MAX_CANON; 27030492Sphk return (0); 27130492Sphk case _PC_MAX_INPUT: 27230492Sphk *ap->a_retval = MAX_INPUT; 27330492Sphk return (0); 27430492Sphk case _PC_PIPE_BUF: 27530492Sphk *ap->a_retval = PIPE_BUF; 27630492Sphk return (0); 27730492Sphk case _PC_CHOWN_RESTRICTED: 27830492Sphk *ap->a_retval = 1; 27930492Sphk return (0); 28030492Sphk case _PC_VDISABLE: 28130492Sphk *ap->a_retval = _POSIX_VDISABLE; 28230492Sphk return (0); 28330492Sphk default: 28430492Sphk return (EINVAL); 28530492Sphk } 28630492Sphk /* NOTREACHED */ 28730492Sphk} 28830513Sphk 28930513Sphk/* 29030513Sphk * Standard lock, unlock and islocked functions. 29130513Sphk */ 29230513Sphkint 29330513Sphkvop_stdlock(ap) 29430513Sphk struct vop_lock_args /* { 29530513Sphk struct vnode *a_vp; 29630513Sphk int a_flags; 29783366Sjulian struct thread *a_td; 29830513Sphk } */ *ap; 299112067Skan{ 30066355Sbp struct vnode *vp = ap->a_vp; 30130513Sphk 30242900Seivind#ifndef DEBUG_LOCKS 303105077Smckusick return (lockmgr(vp->v_vnlock, ap->a_flags, VI_MTX(vp), ap->a_td)); 30442900Seivind#else 305105077Smckusick return (debuglockmgr(vp->v_vnlock, ap->a_flags, VI_MTX(vp), 30683366Sjulian ap->a_td, "vop_stdlock", vp->filename, vp->line)); 30742900Seivind#endif 30830513Sphk} 30930513Sphk 31091690Seivind/* See above. */ 31130513Sphkint 31230513Sphkvop_stdunlock(ap) 31330513Sphk struct vop_unlock_args /* { 31430513Sphk struct vnode *a_vp; 31530513Sphk int a_flags; 31683366Sjulian struct thread *a_td; 31730513Sphk } */ *ap; 31830513Sphk{ 31966355Sbp struct vnode *vp = ap->a_vp; 32030513Sphk 321105077Smckusick return (lockmgr(vp->v_vnlock, ap->a_flags | LK_RELEASE, VI_MTX(vp), 32283366Sjulian ap->a_td)); 32330513Sphk} 32430513Sphk 32591690Seivind/* See above. */ 32630513Sphkint 32730513Sphkvop_stdislocked(ap) 32830513Sphk struct vop_islocked_args /* { 32930513Sphk struct vnode *a_vp; 33083366Sjulian struct thread *a_td; 33130513Sphk } */ *ap; 33230513Sphk{ 33330513Sphk 334105077Smckusick return (lockstatus(ap->a_vp->v_vnlock, ap->a_td)); 33530513Sphk} 33630513Sphk 33791690Seivind/* Mark the vnode inactive */ 33864819Sphkint 33964819Sphkvop_stdinactive(ap) 34064819Sphk struct vop_inactive_args /* { 34164819Sphk struct vnode *a_vp; 34283366Sjulian struct thread *a_td; 34364819Sphk } */ *ap; 34464819Sphk{ 34564819Sphk 34683366Sjulian VOP_UNLOCK(ap->a_vp, 0, ap->a_td); 34764819Sphk return (0); 34864819Sphk} 34964819Sphk 35030743Sphk/* 35130743Sphk * Return true for select/poll. 35230743Sphk */ 35330743Sphkint 35430743Sphkvop_nopoll(ap) 35530743Sphk struct vop_poll_args /* { 35630743Sphk struct vnode *a_vp; 35730743Sphk int a_events; 35830743Sphk struct ucred *a_cred; 35983366Sjulian struct thread *a_td; 36030743Sphk } */ *ap; 36130743Sphk{ 36230743Sphk /* 36331727Swollman * Return true for read/write. If the user asked for something 36431727Swollman * special, return POLLNVAL, so that clients have a way of 36531727Swollman * determining reliably whether or not the extended 36631727Swollman * functionality is present without hard-coding knowledge 36731727Swollman * of specific filesystem implementations. 36830743Sphk */ 36931727Swollman if (ap->a_events & ~POLLSTANDARD) 37031727Swollman return (POLLNVAL); 37131727Swollman 37230743Sphk return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)); 37330743Sphk} 37430743Sphk 37531727Swollman/* 37631727Swollman * Implement poll for local filesystems that support it. 37731727Swollman */ 37830743Sphkint 37931727Swollmanvop_stdpoll(ap) 38031727Swollman struct vop_poll_args /* { 38131727Swollman struct vnode *a_vp; 38231727Swollman int a_events; 38331727Swollman struct ucred *a_cred; 38483366Sjulian struct thread *a_td; 38531727Swollman } */ *ap; 38631727Swollman{ 38776578Sjlemon if (ap->a_events & ~POLLSTANDARD) 38883366Sjulian return (vn_pollrecord(ap->a_vp, ap->a_td, ap->a_events)); 38976578Sjlemon return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)); 39031727Swollman} 39131727Swollman 39230743Sphk/* 39330743Sphk * Stubs to use when there is no locking to be done on the underlying object. 39430743Sphk * A minimal shared lock is necessary to ensure that the underlying object 39530743Sphk * is not revoked while an operation is in progress. So, an active shared 39630743Sphk * count is maintained in an auxillary vnode lock structure. 39730743Sphk */ 39830743Sphkint 39930743Sphkvop_sharedlock(ap) 40030743Sphk struct vop_lock_args /* { 40130743Sphk struct vnode *a_vp; 40230743Sphk int a_flags; 40383366Sjulian struct thread *a_td; 40430743Sphk } */ *ap; 40530743Sphk{ 40630743Sphk /* 40730743Sphk * This code cannot be used until all the non-locking filesystems 40830743Sphk * (notably NFS) are converted to properly lock and release nodes. 40930743Sphk * Also, certain vnode operations change the locking state within 41030743Sphk * the operation (create, mknod, remove, link, rename, mkdir, rmdir, 41130743Sphk * and symlink). Ideally these operations should not change the 41230743Sphk * lock state, but should be changed to let the caller of the 41330743Sphk * function unlock them. Otherwise all intermediate vnode layers 41430743Sphk * (such as union, umapfs, etc) must catch these functions to do 41530743Sphk * the necessary locking at their layer. Note that the inactive 416112067Skan * and lookup operations also change their lock state, but this 41730743Sphk * cannot be avoided, so these two operations will always need 41830743Sphk * to be handled in intermediate layers. 41930743Sphk */ 42030743Sphk struct vnode *vp = ap->a_vp; 42130743Sphk int vnflags, flags = ap->a_flags; 42230743Sphk 42330743Sphk switch (flags & LK_TYPE_MASK) { 42430743Sphk case LK_DRAIN: 42530743Sphk vnflags = LK_DRAIN; 42630743Sphk break; 42730743Sphk case LK_EXCLUSIVE: 42830743Sphk#ifdef DEBUG_VFS_LOCKS 42930743Sphk /* 43030743Sphk * Normally, we use shared locks here, but that confuses 43130743Sphk * the locking assertions. 43230743Sphk */ 43330743Sphk vnflags = LK_EXCLUSIVE; 43430743Sphk break; 43530743Sphk#endif 43630743Sphk case LK_SHARED: 43730743Sphk vnflags = LK_SHARED; 43830743Sphk break; 43930743Sphk case LK_UPGRADE: 44030743Sphk case LK_EXCLUPGRADE: 44130743Sphk case LK_DOWNGRADE: 44230743Sphk return (0); 44330743Sphk case LK_RELEASE: 44430743Sphk default: 44530743Sphk panic("vop_sharedlock: bad operation %d", flags & LK_TYPE_MASK); 44630743Sphk } 447111965Sjhb vnflags |= flags & (LK_INTERLOCK | LK_EXTFLG_MASK); 44842900Seivind#ifndef DEBUG_LOCKS 449105077Smckusick return (lockmgr(vp->v_vnlock, vnflags, VI_MTX(vp), ap->a_td)); 45042900Seivind#else 451105077Smckusick return (debuglockmgr(vp->v_vnlock, vnflags, VI_MTX(vp), ap->a_td, 45242900Seivind "vop_sharedlock", vp->filename, vp->line)); 45342900Seivind#endif 45430743Sphk} 45530743Sphk 45630743Sphk/* 45730743Sphk * Stubs to use when there is no locking to be done on the underlying object. 45830743Sphk * A minimal shared lock is necessary to ensure that the underlying object 45930743Sphk * is not revoked while an operation is in progress. So, an active shared 46030743Sphk * count is maintained in an auxillary vnode lock structure. 46130743Sphk */ 46230743Sphkint 46330743Sphkvop_nolock(ap) 46430743Sphk struct vop_lock_args /* { 46530743Sphk struct vnode *a_vp; 46630743Sphk int a_flags; 46783366Sjulian struct thread *a_td; 46830743Sphk } */ *ap; 46930743Sphk{ 47030743Sphk#ifdef notyet 47130743Sphk /* 47230743Sphk * This code cannot be used until all the non-locking filesystems 47330743Sphk * (notably NFS) are converted to properly lock and release nodes. 47430743Sphk * Also, certain vnode operations change the locking state within 47530743Sphk * the operation (create, mknod, remove, link, rename, mkdir, rmdir, 47630743Sphk * and symlink). Ideally these operations should not change the 47730743Sphk * lock state, but should be changed to let the caller of the 47830743Sphk * function unlock them. Otherwise all intermediate vnode layers 47930743Sphk * (such as union, umapfs, etc) must catch these functions to do 48030743Sphk * the necessary locking at their layer. Note that the inactive 481112067Skan * and lookup operations also change their lock state, but this 48230743Sphk * cannot be avoided, so these two operations will always need 48330743Sphk * to be handled in intermediate layers. 48430743Sphk */ 48530743Sphk struct vnode *vp = ap->a_vp; 48630743Sphk int vnflags, flags = ap->a_flags; 48730743Sphk 48830743Sphk switch (flags & LK_TYPE_MASK) { 48930743Sphk case LK_DRAIN: 49030743Sphk vnflags = LK_DRAIN; 49130743Sphk break; 49230743Sphk case LK_EXCLUSIVE: 49330743Sphk case LK_SHARED: 49430743Sphk vnflags = LK_SHARED; 49530743Sphk break; 49630743Sphk case LK_UPGRADE: 49730743Sphk case LK_EXCLUPGRADE: 49830743Sphk case LK_DOWNGRADE: 49930743Sphk return (0); 50030743Sphk case LK_RELEASE: 50130743Sphk default: 50230743Sphk panic("vop_nolock: bad operation %d", flags & LK_TYPE_MASK); 50330743Sphk } 504111965Sjhb vnflags |= flags & (LK_INTERLOCK | LK_EXTFLG_MASK); 505105077Smckusick return(lockmgr(vp->v_vnlock, vnflags, VI_MTX(vp), ap->a_td)); 50630743Sphk#else /* for now */ 50730743Sphk /* 50830743Sphk * Since we are not using the lock manager, we must clear 50930743Sphk * the interlock here. 51030743Sphk */ 51131263Sbde if (ap->a_flags & LK_INTERLOCK) 512103927Sjeff VI_UNLOCK(ap->a_vp); 51330743Sphk return (0); 51430743Sphk#endif 51530743Sphk} 51630743Sphk 51730743Sphk/* 51830743Sphk * Do the inverse of vop_nolock, handling the interlock in a compatible way. 51930743Sphk */ 52030743Sphkint 52130743Sphkvop_nounlock(ap) 52230743Sphk struct vop_unlock_args /* { 52330743Sphk struct vnode *a_vp; 52430743Sphk int a_flags; 52583366Sjulian struct thread *a_td; 52630743Sphk } */ *ap; 52730743Sphk{ 52830743Sphk 52966355Sbp /* 53066355Sbp * Since we are not using the lock manager, we must clear 53166355Sbp * the interlock here. 53266355Sbp */ 53366355Sbp if (ap->a_flags & LK_INTERLOCK) 534103927Sjeff VI_UNLOCK(ap->a_vp); 53566355Sbp return (0); 53630743Sphk} 53730743Sphk 53830743Sphk/* 53930743Sphk * Return whether or not the node is in use. 54030743Sphk */ 54130743Sphkint 54230743Sphkvop_noislocked(ap) 54330743Sphk struct vop_islocked_args /* { 54430743Sphk struct vnode *a_vp; 54583366Sjulian struct thread *a_td; 54630743Sphk } */ *ap; 54730743Sphk{ 54830743Sphk 54966355Sbp return (0); 55030743Sphk} 55130743Sphk 55262976Smckusick/* 55362976Smckusick * Return our mount point, as we will take charge of the writes. 55462976Smckusick */ 55562976Smckusickint 55662976Smckusickvop_stdgetwritemount(ap) 55762976Smckusick struct vop_getwritemount_args /* { 55862976Smckusick struct vnode *a_vp; 55962976Smckusick struct mount **a_mpp; 56062976Smckusick } */ *ap; 56162976Smckusick{ 56262976Smckusick 56362976Smckusick *(ap->a_mpp) = ap->a_vp->v_mount; 56462976Smckusick return (0); 56562976Smckusick} 56662976Smckusick 56791690Seivind/* Create the VM system backing object for this vnode */ 56865770Sbpint 56965770Sbpvop_stdcreatevobject(ap) 57065770Sbp struct vop_createvobject_args /* { 57165770Sbp struct vnode *vp; 57265770Sbp struct ucred *cred; 57383366Sjulian struct thread *td; 57465770Sbp } */ *ap; 57565770Sbp{ 57665770Sbp struct vnode *vp = ap->a_vp; 57765770Sbp struct ucred *cred = ap->a_cred; 57883366Sjulian struct thread *td = ap->a_td; 57965770Sbp struct vattr vat; 58065770Sbp vm_object_t object; 58165770Sbp int error = 0; 58265770Sbp 58379224Sdillon GIANT_REQUIRED; 58479224Sdillon 58565770Sbp if (!vn_isdisk(vp, NULL) && vn_canvmio(vp) == FALSE) 58665770Sbp return (0); 58765770Sbp 58865770Sbpretry: 58965770Sbp if ((object = vp->v_object) == NULL) { 59065770Sbp if (vp->v_type == VREG || vp->v_type == VDIR) { 59183366Sjulian if ((error = VOP_GETATTR(vp, &vat, cred, td)) != 0) 59265770Sbp goto retn; 59365770Sbp object = vnode_pager_alloc(vp, vat.va_size, 0, 0); 59465770Sbp } else if (devsw(vp->v_rdev) != NULL) { 59565770Sbp /* 59665770Sbp * This simply allocates the biggest object possible 59765770Sbp * for a disk vnode. This should be fixed, but doesn't 59865770Sbp * cause any problems (yet). 59965770Sbp */ 60065770Sbp object = vnode_pager_alloc(vp, IDX_TO_OFF(INT_MAX), 0, 0); 60165770Sbp } else { 60265770Sbp goto retn; 60365770Sbp } 60465770Sbp /* 60565770Sbp * Dereference the reference we just created. This assumes 60665770Sbp * that the object is associated with the vp. 60765770Sbp */ 60865770Sbp object->ref_count--; 609105884Sphk vrele(vp); 61065770Sbp } else { 61165770Sbp if (object->flags & OBJ_DEAD) { 61283366Sjulian VOP_UNLOCK(vp, 0, td); 61379224Sdillon tsleep(object, PVM, "vodead", 0); 61483366Sjulian vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); 61565770Sbp goto retry; 61665770Sbp } 61765770Sbp } 61865770Sbp 61965770Sbp KASSERT(vp->v_object != NULL, ("vfs_object_create: NULL object")); 620101308Sjeff vp->v_vflag |= VV_OBJBUF; 62165770Sbp 62265770Sbpretn: 62365770Sbp return (error); 62465770Sbp} 62565770Sbp 62691690Seivind/* Destroy the VM system object associated with this vnode */ 62765770Sbpint 62865770Sbpvop_stddestroyvobject(ap) 62965770Sbp struct vop_destroyvobject_args /* { 63065770Sbp struct vnode *vp; 63165770Sbp } */ *ap; 63265770Sbp{ 63365770Sbp struct vnode *vp = ap->a_vp; 63465770Sbp vm_object_t obj = vp->v_object; 63565770Sbp 63679224Sdillon GIANT_REQUIRED; 63779224Sdillon 638114080Salc if (obj == NULL) 63965770Sbp return (0); 640114080Salc VM_OBJECT_LOCK(obj); 64165770Sbp if (obj->ref_count == 0) { 64265770Sbp /* 64365770Sbp * vclean() may be called twice. The first time 64465770Sbp * removes the primary reference to the object, 64565770Sbp * the second time goes one further and is a 64665770Sbp * special-case to terminate the object. 64785340Sdillon * 64885340Sdillon * don't double-terminate the object 64965770Sbp */ 65085340Sdillon if ((obj->flags & OBJ_DEAD) == 0) 65185340Sdillon vm_object_terminate(obj); 652114080Salc else 653114080Salc VM_OBJECT_UNLOCK(obj); 65465770Sbp } else { 655114080Salc VM_OBJECT_UNLOCK(obj); 65665770Sbp /* 65765770Sbp * Woe to the process that tries to page now :-). 65865770Sbp */ 65965770Sbp vm_pager_deallocate(obj); 66065770Sbp } 66165770Sbp return (0); 66265770Sbp} 66365770Sbp 66485340Sdillon/* 66585340Sdillon * Return the underlying VM object. This routine may be called with or 66685340Sdillon * without the vnode interlock held. If called without, the returned 66785340Sdillon * object is not guarenteed to be valid. The syncer typically gets the 66885340Sdillon * object without holding the interlock in order to quickly test whether 66985340Sdillon * it might be dirty before going heavy-weight. vm_object's use zalloc 67085340Sdillon * and thus stable-storage, so this is safe. 67185340Sdillon */ 67265770Sbpint 67365770Sbpvop_stdgetvobject(ap) 67465770Sbp struct vop_getvobject_args /* { 67565770Sbp struct vnode *vp; 67665770Sbp struct vm_object **objpp; 67765770Sbp } */ *ap; 67865770Sbp{ 67965770Sbp struct vnode *vp = ap->a_vp; 68065770Sbp struct vm_object **objpp = ap->a_objpp; 68165770Sbp 68265770Sbp if (objpp) 68365770Sbp *objpp = vp->v_object; 68465770Sbp return (vp->v_object ? 0 : EINVAL); 68565770Sbp} 68665770Sbp 68791690Seivind/* XXX Needs good comment and VOP_BMAP(9) manpage */ 68876131Sphkint 68976131Sphkvop_stdbmap(ap) 690112067Skan struct vop_bmap_args /* { 69176131Sphk struct vnode *a_vp; 69276131Sphk daddr_t a_bn; 69376131Sphk struct vnode **a_vpp; 69476131Sphk daddr_t *a_bnp; 69576131Sphk int *a_runp; 69676131Sphk int *a_runb; 69776131Sphk } */ *ap; 69876131Sphk{ 69976131Sphk 70076131Sphk if (ap->a_vpp != NULL) 70176131Sphk *ap->a_vpp = ap->a_vp; 70276131Sphk if (ap->a_bnp != NULL) 70376131Sphk *ap->a_bnp = ap->a_bn * btodb(ap->a_vp->v_mount->mnt_stat.f_iosize); 70476131Sphk if (ap->a_runp != NULL) 70576131Sphk *ap->a_runp = 0; 70676131Sphk if (ap->a_runb != NULL) 70776131Sphk *ap->a_runb = 0; 70876131Sphk return (0); 70976131Sphk} 71076131Sphk 711110584Sjeffint 712110584Sjeffvop_stdfsync(ap) 713110584Sjeff struct vop_fsync_args /* { 714110584Sjeff struct vnode *a_vp; 715110584Sjeff struct ucred *a_cred; 716110584Sjeff int a_waitfor; 717110584Sjeff struct thread *a_td; 718110584Sjeff } */ *ap; 719110584Sjeff{ 720110584Sjeff struct vnode *vp = ap->a_vp; 721110584Sjeff struct buf *bp; 722110584Sjeff struct buf *nbp; 723110584Sjeff int s, error = 0; 724110584Sjeff int maxretry = 100; /* large, arbitrarily chosen */ 725110584Sjeff 726110584Sjeff VI_LOCK(vp); 727110584Sjeffloop1: 728110584Sjeff /* 729110584Sjeff * MARK/SCAN initialization to avoid infinite loops. 730110584Sjeff */ 731110584Sjeff s = splbio(); 732110584Sjeff TAILQ_FOREACH(bp, &vp->v_dirtyblkhd, b_vnbufs) { 733110584Sjeff bp->b_vflags &= ~BV_SCANNED; 734110584Sjeff bp->b_error = 0; 735110584Sjeff } 736110584Sjeff splx(s); 737110584Sjeff 738110584Sjeff /* 739110584Sjeff * Flush all dirty buffers associated with a block device. 740110584Sjeff */ 741110584Sjeffloop2: 742110584Sjeff s = splbio(); 743110584Sjeff for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp != NULL; bp = nbp) { 744110584Sjeff nbp = TAILQ_NEXT(bp, b_vnbufs); 745110584Sjeff if ((bp->b_vflags & BV_SCANNED) != 0) 746110584Sjeff continue; 747110584Sjeff bp->b_vflags |= BV_SCANNED; 748111463Sjeff if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT, NULL)) 749110584Sjeff continue; 750110584Sjeff VI_UNLOCK(vp); 751110584Sjeff if ((bp->b_flags & B_DELWRI) == 0) 752110588Sjeff panic("fsync: not dirty"); 753110584Sjeff if ((vp->v_vflag & VV_OBJBUF) && (bp->b_flags & B_CLUSTEROK)) { 754110584Sjeff vfs_bio_awrite(bp); 755110584Sjeff splx(s); 756110584Sjeff } else { 757110584Sjeff bremfree(bp); 758110584Sjeff splx(s); 759110584Sjeff bawrite(bp); 760110584Sjeff } 761110584Sjeff VI_LOCK(vp); 762110584Sjeff goto loop2; 763110584Sjeff } 764110584Sjeff 765110584Sjeff /* 766110584Sjeff * If synchronous the caller expects us to completely resolve all 767110584Sjeff * dirty buffers in the system. Wait for in-progress I/O to 768110584Sjeff * complete (which could include background bitmap writes), then 769110584Sjeff * retry if dirty blocks still exist. 770110584Sjeff */ 771110584Sjeff if (ap->a_waitfor == MNT_WAIT) { 772110584Sjeff while (vp->v_numoutput) { 773110584Sjeff vp->v_iflag |= VI_BWAIT; 774110584Sjeff msleep((caddr_t)&vp->v_numoutput, VI_MTX(vp), 775111855Sjeff PRIBIO + 1, "fsync", 0); 776110584Sjeff } 777110584Sjeff if (!TAILQ_EMPTY(&vp->v_dirtyblkhd)) { 778110584Sjeff /* 779110584Sjeff * If we are unable to write any of these buffers 780110584Sjeff * then we fail now rather than trying endlessly 781110584Sjeff * to write them out. 782110584Sjeff */ 783110584Sjeff TAILQ_FOREACH(bp, &vp->v_dirtyblkhd, b_vnbufs) 784110584Sjeff if ((error = bp->b_error) == 0) 785110584Sjeff continue; 786110584Sjeff if (error == 0 && --maxretry >= 0) { 787110584Sjeff splx(s); 788110584Sjeff goto loop1; 789110584Sjeff } 790110584Sjeff vprint("fsync: giving up on dirty", vp); 791110584Sjeff error = EAGAIN; 792110584Sjeff } 793110584Sjeff } 794110584Sjeff VI_UNLOCK(vp); 795110584Sjeff splx(s); 796112067Skan 797110584Sjeff return (error); 798110584Sjeff} 799112067Skan 80091690Seivind/* XXX Needs good comment and more info in the manpage (VOP_GETPAGES(9)). */ 80176167Sphkint 80276167Sphkvop_stdgetpages(ap) 80376167Sphk struct vop_getpages_args /* { 80476167Sphk struct vnode *a_vp; 80576167Sphk vm_page_t *a_m; 80676167Sphk int a_count; 80776167Sphk int a_reqpage; 80876167Sphk vm_ooffset_t a_offset; 80976167Sphk } */ *ap; 81076167Sphk{ 81176131Sphk 81276167Sphk return vnode_pager_generic_getpages(ap->a_vp, ap->a_m, 81376167Sphk ap->a_count, ap->a_reqpage); 81476167Sphk} 81576167Sphk 81691690Seivind/* XXX Needs good comment and more info in the manpage (VOP_PUTPAGES(9)). */ 81776319Sphkint 81876167Sphkvop_stdputpages(ap) 81976167Sphk struct vop_putpages_args /* { 82076167Sphk struct vnode *a_vp; 82176167Sphk vm_page_t *a_m; 82276167Sphk int a_count; 82376167Sphk int a_sync; 82476167Sphk int *a_rtvals; 82576167Sphk vm_ooffset_t a_offset; 82676167Sphk } */ *ap; 82776167Sphk{ 82876167Sphk 82976319Sphk return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count, 83076167Sphk ap->a_sync, ap->a_rtvals); 83176167Sphk} 83276167Sphk 833112067Skan/* 83451068Salfred * vfs default ops 83591690Seivind * used to fill the vfs function table to get reasonable default return values. 83651068Salfred */ 83791690Seivindint 83851068Salfredvfs_stdroot (mp, vpp) 83951068Salfred struct mount *mp; 84051068Salfred struct vnode **vpp; 84151068Salfred{ 84251068Salfred return (EOPNOTSUPP); 84351068Salfred} 84451068Salfred 84591690Seivindint 84683366Sjulianvfs_stdstatfs (mp, sbp, td) 84751068Salfred struct mount *mp; 84851068Salfred struct statfs *sbp; 84983366Sjulian struct thread *td; 85051068Salfred{ 85151068Salfred return (EOPNOTSUPP); 85251068Salfred} 85351068Salfred 85451068Salfredint 85551068Salfredvfs_stdvptofh (vp, fhp) 85651068Salfred struct vnode *vp; 85751068Salfred struct fid *fhp; 85851068Salfred{ 85951068Salfred return (EOPNOTSUPP); 86051068Salfred} 86151068Salfred 86291690Seivindint 86383366Sjulianvfs_stdstart (mp, flags, td) 86451068Salfred struct mount *mp; 86551068Salfred int flags; 86683366Sjulian struct thread *td; 86751068Salfred{ 86851068Salfred return (0); 86951068Salfred} 87051068Salfred 871112067Skanint 87283366Sjulianvfs_stdquotactl (mp, cmds, uid, arg, td) 87351068Salfred struct mount *mp; 87451068Salfred int cmds; 87551068Salfred uid_t uid; 87651068Salfred caddr_t arg; 87783366Sjulian struct thread *td; 87851068Salfred{ 87951068Salfred return (EOPNOTSUPP); 88051068Salfred} 88151068Salfred 882112067Skanint 883112119Skanvfs_stdsync(mp, waitfor, cred, td) 88451068Salfred struct mount *mp; 88551068Salfred int waitfor; 886112067Skan struct ucred *cred; 88783366Sjulian struct thread *td; 88851068Salfred{ 889112119Skan struct vnode *vp, *nvp; 890112119Skan int error, lockreq, allerror = 0; 891112119Skan 892112119Skan lockreq = LK_EXCLUSIVE | LK_INTERLOCK; 893112119Skan if (waitfor != MNT_WAIT) 894112119Skan lockreq |= LK_NOWAIT; 895112119Skan /* 896112119Skan * Force stale buffer cache information to be flushed. 897112119Skan */ 898112119Skan mtx_lock(&mntvnode_mtx); 899112119Skanloop: 900112119Skan for (vp = TAILQ_FIRST(&mp->mnt_nvnodelist); vp != NULL; vp = nvp) { 901112119Skan /* 902112119Skan * If the vnode that we are about to sync is no longer 903112119Skan * associated with this mount point, start over. 904112119Skan */ 905112119Skan if (vp->v_mount != mp) 906112119Skan goto loop; 907112119Skan 908112119Skan nvp = TAILQ_NEXT(vp, v_nmntvnodes); 909112119Skan 910112119Skan VI_LOCK(vp); 911112119Skan if (TAILQ_EMPTY(&vp->v_dirtyblkhd)) { 912112119Skan VI_UNLOCK(vp); 913112119Skan continue; 914112119Skan } 915112119Skan mtx_unlock(&mntvnode_mtx); 916112119Skan 917112119Skan if ((error = vget(vp, lockreq, td)) != 0) { 918112119Skan if (error == ENOENT) 919112119Skan goto loop; 920112119Skan continue; 921112119Skan } 922112119Skan error = VOP_FSYNC(vp, cred, waitfor, td); 923112119Skan if (error) 924112119Skan allerror = error; 925112119Skan 926112119Skan mtx_lock(&mntvnode_mtx); 927112119Skan if (nvp != TAILQ_NEXT(vp, v_nmntvnodes)) { 928112119Skan vput(vp); 929112119Skan goto loop; 930112119Skan } 931112119Skan vput(vp); 932112119Skan } 933112119Skan mtx_unlock(&mntvnode_mtx); 934112119Skan return (allerror); 935112119Skan} 936112119Skan 937112119Skanint 938112119Skanvfs_stdnosync (mp, waitfor, cred, td) 939112119Skan struct mount *mp; 940112119Skan int waitfor; 941112119Skan struct ucred *cred; 942112119Skan struct thread *td; 943112119Skan{ 94451068Salfred return (0); 94551068Salfred} 94651068Salfred 947112067Skanint 94892462Smckusickvfs_stdvget (mp, ino, flags, vpp) 94951068Salfred struct mount *mp; 95051068Salfred ino_t ino; 95192462Smckusick int flags; 95251068Salfred struct vnode **vpp; 95351068Salfred{ 95451068Salfred return (EOPNOTSUPP); 95551068Salfred} 95651068Salfred 957112067Skanint 95851138Salfredvfs_stdfhtovp (mp, fhp, vpp) 95951068Salfred struct mount *mp; 96051068Salfred struct fid *fhp; 96151138Salfred struct vnode **vpp; 96251138Salfred{ 96351138Salfred return (EOPNOTSUPP); 96451138Salfred} 96551138Salfred 96651068Salfredint 967112067Skanvfs_stdinit (vfsp) 96851068Salfred struct vfsconf *vfsp; 96951068Salfred{ 97051068Salfred return (0); 97151068Salfred} 97251068Salfred 97351068Salfredint 97451068Salfredvfs_stduninit (vfsp) 97551068Salfred struct vfsconf *vfsp; 97651068Salfred{ 97751068Salfred return(0); 97851068Salfred} 97951068Salfred 98054803Srwatsonint 98183366Sjulianvfs_stdextattrctl(mp, cmd, filename_vp, attrnamespace, attrname, td) 98254803Srwatson struct mount *mp; 98354803Srwatson int cmd; 98474273Srwatson struct vnode *filename_vp; 98574437Srwatson int attrnamespace; 98656272Srwatson const char *attrname; 98783366Sjulian struct thread *td; 98854803Srwatson{ 989101786Sphk if (filename_vp != NULL) 990101786Sphk VOP_UNLOCK(filename_vp, 0, td); 99154803Srwatson return(EOPNOTSUPP); 99254803Srwatson} 99354803Srwatson 99451068Salfred/* end of vfs default ops */ 995