vfs_default.c revision 76131
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 76131 2001-04-29 11:48:41Z phk $ 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> 4831561Sbde#include <sys/lock.h> 4930743Sphk#include <sys/malloc.h> 5051068Salfred#include <sys/mount.h> 5167365Sjhb#include <sys/mutex.h> 5230492Sphk#include <sys/unistd.h> 5330489Sphk#include <sys/vnode.h> 5430743Sphk#include <sys/poll.h> 5530489Sphk 5665770Sbp#include <machine/limits.h> 5765770Sbp 5865770Sbp#include <vm/vm.h> 5965770Sbp#include <vm/vm_object.h> 6065770Sbp#include <vm/vm_extern.h> 6165770Sbp#include <vm/pmap.h> 6265770Sbp#include <vm/vm_map.h> 6365770Sbp#include <vm/vm_page.h> 6465770Sbp#include <vm/vm_pager.h> 6565770Sbp#include <vm/vnode_pager.h> 6665770Sbp#include <vm/vm_zone.h> 6765770Sbp 6872594Sbdestatic int vop_nolookup __P((struct vop_lookup_args *)); 6972594Sbdestatic int vop_nostrategy __P((struct vop_strategy_args *)); 7030489Sphk 7130489Sphk/* 7230489Sphk * This vnode table stores what we want to do if the filesystem doesn't 7330489Sphk * implement a particular VOP. 7430489Sphk * 7530489Sphk * If there is no specific entry here, we will return EOPNOTSUPP. 7630489Sphk * 7730489Sphk */ 7830489Sphk 7930489Sphkvop_t **default_vnodeop_p; 8030489Sphkstatic struct vnodeopv_entry_desc default_vnodeop_entries[] = { 8130492Sphk { &vop_default_desc, (vop_t *) vop_eopnotsupp }, 8230492Sphk { &vop_advlock_desc, (vop_t *) vop_einval }, 8376131Sphk { &vop_bmap_desc, (vop_t *) vop_stdbmap }, 8430492Sphk { &vop_close_desc, (vop_t *) vop_null }, 8565770Sbp { &vop_createvobject_desc, (vop_t *) vop_stdcreatevobject }, 8665770Sbp { &vop_destroyvobject_desc, (vop_t *) vop_stddestroyvobject }, 8730492Sphk { &vop_fsync_desc, (vop_t *) vop_null }, 8865770Sbp { &vop_getvobject_desc, (vop_t *) vop_stdgetvobject }, 8964819Sphk { &vop_inactive_desc, (vop_t *) vop_stdinactive }, 9030492Sphk { &vop_ioctl_desc, (vop_t *) vop_enotty }, 9130496Sphk { &vop_islocked_desc, (vop_t *) vop_noislocked }, 9230739Sphk { &vop_lease_desc, (vop_t *) vop_null }, 9330496Sphk { &vop_lock_desc, (vop_t *) vop_nolock }, 9472594Sbde { &vop_lookup_desc, (vop_t *) vop_nolookup }, 9530492Sphk { &vop_open_desc, (vop_t *) vop_null }, 9630492Sphk { &vop_pathconf_desc, (vop_t *) vop_einval }, 9730489Sphk { &vop_poll_desc, (vop_t *) vop_nopoll }, 9830492Sphk { &vop_readlink_desc, (vop_t *) vop_einval }, 9930489Sphk { &vop_revoke_desc, (vop_t *) vop_revoke }, 10030489Sphk { &vop_strategy_desc, (vop_t *) vop_nostrategy }, 10130496Sphk { &vop_unlock_desc, (vop_t *) vop_nounlock }, 10230489Sphk { NULL, NULL } 10330489Sphk}; 10430489Sphk 10530489Sphkstatic struct vnodeopv_desc default_vnodeop_opv_desc = 10630489Sphk { &default_vnodeop_p, default_vnodeop_entries }; 10730489Sphk 10830489SphkVNODEOP_SET(default_vnodeop_opv_desc); 10930489Sphk 11030489Sphkint 11130492Sphkvop_eopnotsupp(struct vop_generic_args *ap) 11230489Sphk{ 11330489Sphk /* 11430492Sphk printf("vop_notsupp[%s]\n", ap->a_desc->vdesc_name); 11530489Sphk */ 11630489Sphk 11730489Sphk return (EOPNOTSUPP); 11830489Sphk} 11930489Sphk 12030489Sphkint 12130492Sphkvop_ebadf(struct vop_generic_args *ap) 12230489Sphk{ 12330489Sphk 12430492Sphk return (EBADF); 12530492Sphk} 12630492Sphk 12730492Sphkint 12830492Sphkvop_enotty(struct vop_generic_args *ap) 12930492Sphk{ 13030492Sphk 13130492Sphk return (ENOTTY); 13230492Sphk} 13330492Sphk 13430492Sphkint 13530492Sphkvop_einval(struct vop_generic_args *ap) 13630492Sphk{ 13730492Sphk 13830492Sphk return (EINVAL); 13930492Sphk} 14030492Sphk 14130492Sphkint 14230492Sphkvop_null(struct vop_generic_args *ap) 14330492Sphk{ 14430492Sphk 14530492Sphk return (0); 14630492Sphk} 14730492Sphk 14830492Sphkint 14930492Sphkvop_defaultop(struct vop_generic_args *ap) 15030492Sphk{ 15130492Sphk 15230489Sphk return (VOCALL(default_vnodeop_p, ap->a_desc->vdesc_offset, ap)); 15330489Sphk} 15430489Sphk 15541056Speterint 15641056Spetervop_panic(struct vop_generic_args *ap) 15741056Speter{ 15841056Speter 15972594Sbde panic("filesystem goof: vop_panic[%s]", ap->a_desc->vdesc_name); 16041056Speter} 16141056Speter 16272594Sbdestatic int 16372594Sbdevop_nolookup(ap) 16472594Sbde struct vop_lookup_args /* { 16572594Sbde struct vnode *a_dvp; 16672594Sbde struct vnode **a_vpp; 16772594Sbde struct componentname *a_cnp; 16872594Sbde } */ *ap; 16972594Sbde{ 17072594Sbde 17172594Sbde *ap->a_vpp = NULL; 17272594Sbde return (ENOTDIR); 17372594Sbde} 17472594Sbde 17546349Salc/* 17646349Salc * vop_nostrategy: 17746349Salc * 17846349Salc * Strategy routine for VFS devices that have none. 17946349Salc * 18058934Sphk * BIO_ERROR and B_INVAL must be cleared prior to calling any strategy 18158345Sphk * routine. Typically this is done for a BIO_READ strategy call. 18258345Sphk * Typically B_INVAL is assumed to already be clear prior to a write 18358345Sphk * and should not be cleared manually unless you just made the buffer 18458934Sphk * invalid. BIO_ERROR should be cleared either way. 18546349Salc */ 18646349Salc 18730489Sphkstatic int 18830489Sphkvop_nostrategy (struct vop_strategy_args *ap) 18930489Sphk{ 19030489Sphk printf("No strategy for buffer at %p\n", ap->a_bp); 19137384Sjulian vprint("", ap->a_vp); 19230489Sphk vprint("", ap->a_bp->b_vp); 19358934Sphk ap->a_bp->b_ioflags |= BIO_ERROR; 19430489Sphk ap->a_bp->b_error = EOPNOTSUPP; 19559249Sphk bufdone(ap->a_bp); 19630489Sphk return (EOPNOTSUPP); 19730489Sphk} 19830492Sphk 19930492Sphkint 20030492Sphkvop_stdpathconf(ap) 20130492Sphk struct vop_pathconf_args /* { 20230492Sphk struct vnode *a_vp; 20330492Sphk int a_name; 20430492Sphk int *a_retval; 20530492Sphk } */ *ap; 20630492Sphk{ 20730492Sphk 20830492Sphk switch (ap->a_name) { 20930492Sphk case _PC_LINK_MAX: 21030492Sphk *ap->a_retval = LINK_MAX; 21130492Sphk return (0); 21230492Sphk case _PC_MAX_CANON: 21330492Sphk *ap->a_retval = MAX_CANON; 21430492Sphk return (0); 21530492Sphk case _PC_MAX_INPUT: 21630492Sphk *ap->a_retval = MAX_INPUT; 21730492Sphk return (0); 21830492Sphk case _PC_PIPE_BUF: 21930492Sphk *ap->a_retval = PIPE_BUF; 22030492Sphk return (0); 22130492Sphk case _PC_CHOWN_RESTRICTED: 22230492Sphk *ap->a_retval = 1; 22330492Sphk return (0); 22430492Sphk case _PC_VDISABLE: 22530492Sphk *ap->a_retval = _POSIX_VDISABLE; 22630492Sphk return (0); 22730492Sphk default: 22830492Sphk return (EINVAL); 22930492Sphk } 23030492Sphk /* NOTREACHED */ 23130492Sphk} 23230513Sphk 23330513Sphk/* 23430513Sphk * Standard lock, unlock and islocked functions. 23530513Sphk * 23630513Sphk * These depend on the lock structure being the first element in the 23730513Sphk * inode, ie: vp->v_data points to the the lock! 23830513Sphk */ 23930513Sphkint 24030513Sphkvop_stdlock(ap) 24130513Sphk struct vop_lock_args /* { 24230513Sphk struct vnode *a_vp; 24330513Sphk int a_flags; 24430513Sphk struct proc *a_p; 24530513Sphk } */ *ap; 24630513Sphk{ 24766355Sbp struct vnode *vp = ap->a_vp; 24830513Sphk 24942900Seivind#ifndef DEBUG_LOCKS 25066355Sbp return (lockmgr(&vp->v_lock, ap->a_flags, &vp->v_interlock, ap->a_p)); 25142900Seivind#else 25266355Sbp return (debuglockmgr(&vp->v_lock, ap->a_flags, &vp->v_interlock, 25366355Sbp ap->a_p, "vop_stdlock", vp->filename, vp->line)); 25442900Seivind#endif 25530513Sphk} 25630513Sphk 25730513Sphkint 25830513Sphkvop_stdunlock(ap) 25930513Sphk struct vop_unlock_args /* { 26030513Sphk struct vnode *a_vp; 26130513Sphk int a_flags; 26230513Sphk struct proc *a_p; 26330513Sphk } */ *ap; 26430513Sphk{ 26566355Sbp struct vnode *vp = ap->a_vp; 26630513Sphk 26766355Sbp return (lockmgr(&vp->v_lock, ap->a_flags | LK_RELEASE, &vp->v_interlock, 26830513Sphk ap->a_p)); 26930513Sphk} 27030513Sphk 27130513Sphkint 27230513Sphkvop_stdislocked(ap) 27330513Sphk struct vop_islocked_args /* { 27430513Sphk struct vnode *a_vp; 27554444Seivind struct proc *a_p; 27630513Sphk } */ *ap; 27730513Sphk{ 27830513Sphk 27966355Sbp return (lockstatus(&ap->a_vp->v_lock, ap->a_p)); 28030513Sphk} 28130513Sphk 28264819Sphkint 28364819Sphkvop_stdinactive(ap) 28464819Sphk struct vop_inactive_args /* { 28564819Sphk struct vnode *a_vp; 28664819Sphk struct proc *a_p; 28764819Sphk } */ *ap; 28864819Sphk{ 28964819Sphk 29064819Sphk VOP_UNLOCK(ap->a_vp, 0, ap->a_p); 29164819Sphk return (0); 29264819Sphk} 29364819Sphk 29430743Sphk/* 29530743Sphk * Return true for select/poll. 29630743Sphk */ 29730743Sphkint 29830743Sphkvop_nopoll(ap) 29930743Sphk struct vop_poll_args /* { 30030743Sphk struct vnode *a_vp; 30130743Sphk int a_events; 30230743Sphk struct ucred *a_cred; 30330743Sphk struct proc *a_p; 30430743Sphk } */ *ap; 30530743Sphk{ 30630743Sphk /* 30731727Swollman * Return true for read/write. If the user asked for something 30831727Swollman * special, return POLLNVAL, so that clients have a way of 30931727Swollman * determining reliably whether or not the extended 31031727Swollman * functionality is present without hard-coding knowledge 31131727Swollman * of specific filesystem implementations. 31230743Sphk */ 31331727Swollman if (ap->a_events & ~POLLSTANDARD) 31431727Swollman return (POLLNVAL); 31531727Swollman 31630743Sphk return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)); 31730743Sphk} 31830743Sphk 31931727Swollman/* 32031727Swollman * Implement poll for local filesystems that support it. 32131727Swollman */ 32230743Sphkint 32331727Swollmanvop_stdpoll(ap) 32431727Swollman struct vop_poll_args /* { 32531727Swollman struct vnode *a_vp; 32631727Swollman int a_events; 32731727Swollman struct ucred *a_cred; 32831727Swollman struct proc *a_p; 32931727Swollman } */ *ap; 33031727Swollman{ 33131811Swollman if ((ap->a_events & ~POLLSTANDARD) == 0) 33231811Swollman return (ap->a_events & (POLLRDNORM|POLLWRNORM)); 33331727Swollman return (vn_pollrecord(ap->a_vp, ap->a_p, ap->a_events)); 33431727Swollman} 33531727Swollman 33630743Sphk/* 33730743Sphk * Stubs to use when there is no locking to be done on the underlying object. 33830743Sphk * A minimal shared lock is necessary to ensure that the underlying object 33930743Sphk * is not revoked while an operation is in progress. So, an active shared 34030743Sphk * count is maintained in an auxillary vnode lock structure. 34130743Sphk */ 34230743Sphkint 34330743Sphkvop_sharedlock(ap) 34430743Sphk struct vop_lock_args /* { 34530743Sphk struct vnode *a_vp; 34630743Sphk int a_flags; 34730743Sphk struct proc *a_p; 34830743Sphk } */ *ap; 34930743Sphk{ 35030743Sphk /* 35130743Sphk * This code cannot be used until all the non-locking filesystems 35230743Sphk * (notably NFS) are converted to properly lock and release nodes. 35330743Sphk * Also, certain vnode operations change the locking state within 35430743Sphk * the operation (create, mknod, remove, link, rename, mkdir, rmdir, 35530743Sphk * and symlink). Ideally these operations should not change the 35630743Sphk * lock state, but should be changed to let the caller of the 35730743Sphk * function unlock them. Otherwise all intermediate vnode layers 35830743Sphk * (such as union, umapfs, etc) must catch these functions to do 35930743Sphk * the necessary locking at their layer. Note that the inactive 36030743Sphk * and lookup operations also change their lock state, but this 36130743Sphk * cannot be avoided, so these two operations will always need 36230743Sphk * to be handled in intermediate layers. 36330743Sphk */ 36430743Sphk struct vnode *vp = ap->a_vp; 36530743Sphk int vnflags, flags = ap->a_flags; 36630743Sphk 36730743Sphk switch (flags & LK_TYPE_MASK) { 36830743Sphk case LK_DRAIN: 36930743Sphk vnflags = LK_DRAIN; 37030743Sphk break; 37130743Sphk case LK_EXCLUSIVE: 37230743Sphk#ifdef DEBUG_VFS_LOCKS 37330743Sphk /* 37430743Sphk * Normally, we use shared locks here, but that confuses 37530743Sphk * the locking assertions. 37630743Sphk */ 37730743Sphk vnflags = LK_EXCLUSIVE; 37830743Sphk break; 37930743Sphk#endif 38030743Sphk case LK_SHARED: 38130743Sphk vnflags = LK_SHARED; 38230743Sphk break; 38330743Sphk case LK_UPGRADE: 38430743Sphk case LK_EXCLUPGRADE: 38530743Sphk case LK_DOWNGRADE: 38630743Sphk return (0); 38730743Sphk case LK_RELEASE: 38830743Sphk default: 38930743Sphk panic("vop_sharedlock: bad operation %d", flags & LK_TYPE_MASK); 39030743Sphk } 39130743Sphk if (flags & LK_INTERLOCK) 39230743Sphk vnflags |= LK_INTERLOCK; 39342900Seivind#ifndef DEBUG_LOCKS 39466355Sbp return (lockmgr(&vp->v_lock, vnflags, &vp->v_interlock, ap->a_p)); 39542900Seivind#else 39666355Sbp return (debuglockmgr(&vp->v_lock, vnflags, &vp->v_interlock, ap->a_p, 39742900Seivind "vop_sharedlock", vp->filename, vp->line)); 39842900Seivind#endif 39930743Sphk} 40030743Sphk 40130743Sphk/* 40230743Sphk * Stubs to use when there is no locking to be done on the underlying object. 40330743Sphk * A minimal shared lock is necessary to ensure that the underlying object 40430743Sphk * is not revoked while an operation is in progress. So, an active shared 40530743Sphk * count is maintained in an auxillary vnode lock structure. 40630743Sphk */ 40730743Sphkint 40830743Sphkvop_nolock(ap) 40930743Sphk struct vop_lock_args /* { 41030743Sphk struct vnode *a_vp; 41130743Sphk int a_flags; 41230743Sphk struct proc *a_p; 41330743Sphk } */ *ap; 41430743Sphk{ 41530743Sphk#ifdef notyet 41630743Sphk /* 41730743Sphk * This code cannot be used until all the non-locking filesystems 41830743Sphk * (notably NFS) are converted to properly lock and release nodes. 41930743Sphk * Also, certain vnode operations change the locking state within 42030743Sphk * the operation (create, mknod, remove, link, rename, mkdir, rmdir, 42130743Sphk * and symlink). Ideally these operations should not change the 42230743Sphk * lock state, but should be changed to let the caller of the 42330743Sphk * function unlock them. Otherwise all intermediate vnode layers 42430743Sphk * (such as union, umapfs, etc) must catch these functions to do 42530743Sphk * the necessary locking at their layer. Note that the inactive 42630743Sphk * and lookup operations also change their lock state, but this 42730743Sphk * cannot be avoided, so these two operations will always need 42830743Sphk * to be handled in intermediate layers. 42930743Sphk */ 43030743Sphk struct vnode *vp = ap->a_vp; 43130743Sphk int vnflags, flags = ap->a_flags; 43230743Sphk 43330743Sphk switch (flags & LK_TYPE_MASK) { 43430743Sphk case LK_DRAIN: 43530743Sphk vnflags = LK_DRAIN; 43630743Sphk break; 43730743Sphk case LK_EXCLUSIVE: 43830743Sphk case LK_SHARED: 43930743Sphk vnflags = LK_SHARED; 44030743Sphk break; 44130743Sphk case LK_UPGRADE: 44230743Sphk case LK_EXCLUPGRADE: 44330743Sphk case LK_DOWNGRADE: 44430743Sphk return (0); 44530743Sphk case LK_RELEASE: 44630743Sphk default: 44730743Sphk panic("vop_nolock: bad operation %d", flags & LK_TYPE_MASK); 44830743Sphk } 44930743Sphk if (flags & LK_INTERLOCK) 45030743Sphk vnflags |= LK_INTERLOCK; 45166355Sbp return(lockmgr(&vp->v_lock, vnflags, &vp->v_interlock, ap->a_p)); 45230743Sphk#else /* for now */ 45330743Sphk /* 45430743Sphk * Since we are not using the lock manager, we must clear 45530743Sphk * the interlock here. 45630743Sphk */ 45731263Sbde if (ap->a_flags & LK_INTERLOCK) 45872200Sbmilekic mtx_unlock(&ap->a_vp->v_interlock); 45930743Sphk return (0); 46030743Sphk#endif 46130743Sphk} 46230743Sphk 46330743Sphk/* 46430743Sphk * Do the inverse of vop_nolock, handling the interlock in a compatible way. 46530743Sphk */ 46630743Sphkint 46730743Sphkvop_nounlock(ap) 46830743Sphk struct vop_unlock_args /* { 46930743Sphk struct vnode *a_vp; 47030743Sphk int a_flags; 47130743Sphk struct proc *a_p; 47230743Sphk } */ *ap; 47330743Sphk{ 47430743Sphk 47566355Sbp /* 47666355Sbp * Since we are not using the lock manager, we must clear 47766355Sbp * the interlock here. 47866355Sbp */ 47966355Sbp if (ap->a_flags & LK_INTERLOCK) 48072200Sbmilekic mtx_unlock(&ap->a_vp->v_interlock); 48166355Sbp return (0); 48230743Sphk} 48330743Sphk 48430743Sphk/* 48530743Sphk * Return whether or not the node is in use. 48630743Sphk */ 48730743Sphkint 48830743Sphkvop_noislocked(ap) 48930743Sphk struct vop_islocked_args /* { 49030743Sphk struct vnode *a_vp; 49154444Seivind struct proc *a_p; 49230743Sphk } */ *ap; 49330743Sphk{ 49430743Sphk 49566355Sbp return (0); 49630743Sphk} 49730743Sphk 49862976Smckusick/* 49962976Smckusick * Return our mount point, as we will take charge of the writes. 50062976Smckusick */ 50162976Smckusickint 50262976Smckusickvop_stdgetwritemount(ap) 50362976Smckusick struct vop_getwritemount_args /* { 50462976Smckusick struct vnode *a_vp; 50562976Smckusick struct mount **a_mpp; 50662976Smckusick } */ *ap; 50762976Smckusick{ 50862976Smckusick 50962976Smckusick *(ap->a_mpp) = ap->a_vp->v_mount; 51062976Smckusick return (0); 51162976Smckusick} 51262976Smckusick 51365770Sbpint 51465770Sbpvop_stdcreatevobject(ap) 51565770Sbp struct vop_createvobject_args /* { 51665770Sbp struct vnode *vp; 51765770Sbp struct ucred *cred; 51865770Sbp struct proc *p; 51965770Sbp } */ *ap; 52065770Sbp{ 52165770Sbp struct vnode *vp = ap->a_vp; 52265770Sbp struct ucred *cred = ap->a_cred; 52365770Sbp struct proc *p = ap->a_p; 52465770Sbp struct vattr vat; 52565770Sbp vm_object_t object; 52665770Sbp int error = 0; 52765770Sbp 52865770Sbp if (!vn_isdisk(vp, NULL) && vn_canvmio(vp) == FALSE) 52965770Sbp return (0); 53065770Sbp 53165770Sbpretry: 53265770Sbp if ((object = vp->v_object) == NULL) { 53365770Sbp if (vp->v_type == VREG || vp->v_type == VDIR) { 53465770Sbp if ((error = VOP_GETATTR(vp, &vat, cred, p)) != 0) 53565770Sbp goto retn; 53665770Sbp object = vnode_pager_alloc(vp, vat.va_size, 0, 0); 53765770Sbp } else if (devsw(vp->v_rdev) != NULL) { 53865770Sbp /* 53965770Sbp * This simply allocates the biggest object possible 54065770Sbp * for a disk vnode. This should be fixed, but doesn't 54165770Sbp * cause any problems (yet). 54265770Sbp */ 54365770Sbp object = vnode_pager_alloc(vp, IDX_TO_OFF(INT_MAX), 0, 0); 54465770Sbp } else { 54565770Sbp goto retn; 54665770Sbp } 54765770Sbp /* 54865770Sbp * Dereference the reference we just created. This assumes 54965770Sbp * that the object is associated with the vp. 55065770Sbp */ 55165770Sbp object->ref_count--; 55265770Sbp vp->v_usecount--; 55365770Sbp } else { 55465770Sbp if (object->flags & OBJ_DEAD) { 55565770Sbp VOP_UNLOCK(vp, 0, p); 55665770Sbp tsleep(object, PVM, "vodead", 0); 55765770Sbp vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); 55865770Sbp goto retry; 55965770Sbp } 56065770Sbp } 56165770Sbp 56265770Sbp KASSERT(vp->v_object != NULL, ("vfs_object_create: NULL object")); 56365770Sbp vp->v_flag |= VOBJBUF; 56465770Sbp 56565770Sbpretn: 56665770Sbp return (error); 56765770Sbp} 56865770Sbp 56965770Sbpint 57065770Sbpvop_stddestroyvobject(ap) 57165770Sbp struct vop_destroyvobject_args /* { 57265770Sbp struct vnode *vp; 57365770Sbp } */ *ap; 57465770Sbp{ 57565770Sbp struct vnode *vp = ap->a_vp; 57665770Sbp vm_object_t obj = vp->v_object; 57765770Sbp 57865770Sbp if (vp->v_object == NULL) 57965770Sbp return (0); 58065770Sbp 58165770Sbp if (obj->ref_count == 0) { 58265770Sbp /* 58365770Sbp * vclean() may be called twice. The first time 58465770Sbp * removes the primary reference to the object, 58565770Sbp * the second time goes one further and is a 58665770Sbp * special-case to terminate the object. 58765770Sbp */ 58865770Sbp vm_object_terminate(obj); 58965770Sbp } else { 59065770Sbp /* 59165770Sbp * Woe to the process that tries to page now :-). 59265770Sbp */ 59365770Sbp vm_pager_deallocate(obj); 59465770Sbp } 59565770Sbp return (0); 59665770Sbp} 59765770Sbp 59865770Sbpint 59965770Sbpvop_stdgetvobject(ap) 60065770Sbp struct vop_getvobject_args /* { 60165770Sbp struct vnode *vp; 60265770Sbp struct vm_object **objpp; 60365770Sbp } */ *ap; 60465770Sbp{ 60565770Sbp struct vnode *vp = ap->a_vp; 60665770Sbp struct vm_object **objpp = ap->a_objpp; 60765770Sbp 60865770Sbp if (objpp) 60965770Sbp *objpp = vp->v_object; 61065770Sbp return (vp->v_object ? 0 : EINVAL); 61165770Sbp} 61265770Sbp 61376131Sphkint 61476131Sphkvop_stdbmap(ap) 61576131Sphk struct vop_bmap_args /* { 61676131Sphk struct vnode *a_vp; 61776131Sphk daddr_t a_bn; 61876131Sphk struct vnode **a_vpp; 61976131Sphk daddr_t *a_bnp; 62076131Sphk int *a_runp; 62176131Sphk int *a_runb; 62276131Sphk } */ *ap; 62376131Sphk{ 62476131Sphk 62576131Sphk if (ap->a_vpp != NULL) 62676131Sphk *ap->a_vpp = ap->a_vp; 62776131Sphk if (ap->a_bnp != NULL) 62876131Sphk *ap->a_bnp = ap->a_bn * btodb(ap->a_vp->v_mount->mnt_stat.f_iosize); 62976131Sphk if (ap->a_runp != NULL) 63076131Sphk *ap->a_runp = 0; 63176131Sphk if (ap->a_runb != NULL) 63276131Sphk *ap->a_runb = 0; 63376131Sphk return (0); 63476131Sphk} 63576131Sphk 63676131Sphk 63751068Salfred/* 63851068Salfred * vfs default ops 63951068Salfred * used to fill the vfs fucntion table to get reasonable default return values. 64051068Salfred */ 64151068Salfredint 64251068Salfredvfs_stdmount (mp, path, data, ndp, p) 64351068Salfred struct mount *mp; 64451068Salfred char *path; 64551068Salfred caddr_t data; 64651068Salfred struct nameidata *ndp; 64751068Salfred struct proc *p; 64851068Salfred{ 64951068Salfred return (0); 65051068Salfred} 65151068Salfred 65251068Salfredint 65351068Salfredvfs_stdunmount (mp, mntflags, p) 65451068Salfred struct mount *mp; 65551068Salfred int mntflags; 65651068Salfred struct proc *p; 65751068Salfred{ 65851068Salfred return (0); 65951068Salfred} 66051068Salfred 66151068Salfredint 66251068Salfredvfs_stdroot (mp, vpp) 66351068Salfred struct mount *mp; 66451068Salfred struct vnode **vpp; 66551068Salfred{ 66651068Salfred return (EOPNOTSUPP); 66751068Salfred} 66851068Salfred 66951068Salfredint 67051068Salfredvfs_stdstatfs (mp, sbp, p) 67151068Salfred struct mount *mp; 67251068Salfred struct statfs *sbp; 67351068Salfred struct proc *p; 67451068Salfred{ 67551068Salfred return (EOPNOTSUPP); 67651068Salfred} 67751068Salfred 67851068Salfredint 67951068Salfredvfs_stdvptofh (vp, fhp) 68051068Salfred struct vnode *vp; 68151068Salfred struct fid *fhp; 68251068Salfred{ 68351068Salfred return (EOPNOTSUPP); 68451068Salfred} 68551068Salfred 68651068Salfredint 68751068Salfredvfs_stdstart (mp, flags, p) 68851068Salfred struct mount *mp; 68951068Salfred int flags; 69051068Salfred struct proc *p; 69151068Salfred{ 69251068Salfred return (0); 69351068Salfred} 69451068Salfred 69551068Salfredint 69651068Salfredvfs_stdquotactl (mp, cmds, uid, arg, p) 69751068Salfred struct mount *mp; 69851068Salfred int cmds; 69951068Salfred uid_t uid; 70051068Salfred caddr_t arg; 70151068Salfred struct proc *p; 70251068Salfred{ 70351068Salfred return (EOPNOTSUPP); 70451068Salfred} 70551068Salfred 70651068Salfredint 70751068Salfredvfs_stdsync (mp, waitfor, cred, p) 70851068Salfred struct mount *mp; 70951068Salfred int waitfor; 71051068Salfred struct ucred *cred; 71151068Salfred struct proc *p; 71251068Salfred{ 71351068Salfred return (0); 71451068Salfred} 71551068Salfred 71651068Salfredint 71751068Salfredvfs_stdvget (mp, ino, vpp) 71851068Salfred struct mount *mp; 71951068Salfred ino_t ino; 72051068Salfred struct vnode **vpp; 72151068Salfred{ 72251068Salfred return (EOPNOTSUPP); 72351068Salfred} 72451068Salfred 72551068Salfredint 72651138Salfredvfs_stdfhtovp (mp, fhp, vpp) 72751068Salfred struct mount *mp; 72851068Salfred struct fid *fhp; 72951138Salfred struct vnode **vpp; 73051138Salfred{ 73151138Salfred return (EOPNOTSUPP); 73251138Salfred} 73351138Salfred 73451068Salfredint 73551068Salfredvfs_stdinit (vfsp) 73651068Salfred struct vfsconf *vfsp; 73751068Salfred{ 73851068Salfred return (0); 73951068Salfred} 74051068Salfred 74151068Salfredint 74251068Salfredvfs_stduninit (vfsp) 74351068Salfred struct vfsconf *vfsp; 74451068Salfred{ 74551068Salfred return(0); 74651068Salfred} 74751068Salfred 74854803Srwatsonint 74974437Srwatsonvfs_stdextattrctl(mp, cmd, filename_vp, attrnamespace, attrname, p) 75054803Srwatson struct mount *mp; 75154803Srwatson int cmd; 75274273Srwatson struct vnode *filename_vp; 75374437Srwatson int attrnamespace; 75456272Srwatson const char *attrname; 75554803Srwatson struct proc *p; 75654803Srwatson{ 75754803Srwatson return(EOPNOTSUPP); 75854803Srwatson} 75954803Srwatson 76051068Salfred/* end of vfs default ops */ 761