vfs_default.c revision 74437
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 74437 2001-03-19 05:44:15Z rwatson $ 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 }, 8330743Sphk { &vop_bwrite_desc, (vop_t *) vop_stdbwrite }, 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 33631727Swollmanint 33730743Sphkvop_stdbwrite(ap) 33830743Sphk struct vop_bwrite_args *ap; 33930743Sphk{ 34030743Sphk return (bwrite(ap->a_bp)); 34130743Sphk} 34230743Sphk 34330743Sphk/* 34430743Sphk * Stubs to use when there is no locking to be done on the underlying object. 34530743Sphk * A minimal shared lock is necessary to ensure that the underlying object 34630743Sphk * is not revoked while an operation is in progress. So, an active shared 34730743Sphk * count is maintained in an auxillary vnode lock structure. 34830743Sphk */ 34930743Sphkint 35030743Sphkvop_sharedlock(ap) 35130743Sphk struct vop_lock_args /* { 35230743Sphk struct vnode *a_vp; 35330743Sphk int a_flags; 35430743Sphk struct proc *a_p; 35530743Sphk } */ *ap; 35630743Sphk{ 35730743Sphk /* 35830743Sphk * This code cannot be used until all the non-locking filesystems 35930743Sphk * (notably NFS) are converted to properly lock and release nodes. 36030743Sphk * Also, certain vnode operations change the locking state within 36130743Sphk * the operation (create, mknod, remove, link, rename, mkdir, rmdir, 36230743Sphk * and symlink). Ideally these operations should not change the 36330743Sphk * lock state, but should be changed to let the caller of the 36430743Sphk * function unlock them. Otherwise all intermediate vnode layers 36530743Sphk * (such as union, umapfs, etc) must catch these functions to do 36630743Sphk * the necessary locking at their layer. Note that the inactive 36730743Sphk * and lookup operations also change their lock state, but this 36830743Sphk * cannot be avoided, so these two operations will always need 36930743Sphk * to be handled in intermediate layers. 37030743Sphk */ 37130743Sphk struct vnode *vp = ap->a_vp; 37230743Sphk int vnflags, flags = ap->a_flags; 37330743Sphk 37430743Sphk switch (flags & LK_TYPE_MASK) { 37530743Sphk case LK_DRAIN: 37630743Sphk vnflags = LK_DRAIN; 37730743Sphk break; 37830743Sphk case LK_EXCLUSIVE: 37930743Sphk#ifdef DEBUG_VFS_LOCKS 38030743Sphk /* 38130743Sphk * Normally, we use shared locks here, but that confuses 38230743Sphk * the locking assertions. 38330743Sphk */ 38430743Sphk vnflags = LK_EXCLUSIVE; 38530743Sphk break; 38630743Sphk#endif 38730743Sphk case LK_SHARED: 38830743Sphk vnflags = LK_SHARED; 38930743Sphk break; 39030743Sphk case LK_UPGRADE: 39130743Sphk case LK_EXCLUPGRADE: 39230743Sphk case LK_DOWNGRADE: 39330743Sphk return (0); 39430743Sphk case LK_RELEASE: 39530743Sphk default: 39630743Sphk panic("vop_sharedlock: bad operation %d", flags & LK_TYPE_MASK); 39730743Sphk } 39830743Sphk if (flags & LK_INTERLOCK) 39930743Sphk vnflags |= LK_INTERLOCK; 40042900Seivind#ifndef DEBUG_LOCKS 40166355Sbp return (lockmgr(&vp->v_lock, vnflags, &vp->v_interlock, ap->a_p)); 40242900Seivind#else 40366355Sbp return (debuglockmgr(&vp->v_lock, vnflags, &vp->v_interlock, ap->a_p, 40442900Seivind "vop_sharedlock", vp->filename, vp->line)); 40542900Seivind#endif 40630743Sphk} 40730743Sphk 40830743Sphk/* 40930743Sphk * Stubs to use when there is no locking to be done on the underlying object. 41030743Sphk * A minimal shared lock is necessary to ensure that the underlying object 41130743Sphk * is not revoked while an operation is in progress. So, an active shared 41230743Sphk * count is maintained in an auxillary vnode lock structure. 41330743Sphk */ 41430743Sphkint 41530743Sphkvop_nolock(ap) 41630743Sphk struct vop_lock_args /* { 41730743Sphk struct vnode *a_vp; 41830743Sphk int a_flags; 41930743Sphk struct proc *a_p; 42030743Sphk } */ *ap; 42130743Sphk{ 42230743Sphk#ifdef notyet 42330743Sphk /* 42430743Sphk * This code cannot be used until all the non-locking filesystems 42530743Sphk * (notably NFS) are converted to properly lock and release nodes. 42630743Sphk * Also, certain vnode operations change the locking state within 42730743Sphk * the operation (create, mknod, remove, link, rename, mkdir, rmdir, 42830743Sphk * and symlink). Ideally these operations should not change the 42930743Sphk * lock state, but should be changed to let the caller of the 43030743Sphk * function unlock them. Otherwise all intermediate vnode layers 43130743Sphk * (such as union, umapfs, etc) must catch these functions to do 43230743Sphk * the necessary locking at their layer. Note that the inactive 43330743Sphk * and lookup operations also change their lock state, but this 43430743Sphk * cannot be avoided, so these two operations will always need 43530743Sphk * to be handled in intermediate layers. 43630743Sphk */ 43730743Sphk struct vnode *vp = ap->a_vp; 43830743Sphk int vnflags, flags = ap->a_flags; 43930743Sphk 44030743Sphk switch (flags & LK_TYPE_MASK) { 44130743Sphk case LK_DRAIN: 44230743Sphk vnflags = LK_DRAIN; 44330743Sphk break; 44430743Sphk case LK_EXCLUSIVE: 44530743Sphk case LK_SHARED: 44630743Sphk vnflags = LK_SHARED; 44730743Sphk break; 44830743Sphk case LK_UPGRADE: 44930743Sphk case LK_EXCLUPGRADE: 45030743Sphk case LK_DOWNGRADE: 45130743Sphk return (0); 45230743Sphk case LK_RELEASE: 45330743Sphk default: 45430743Sphk panic("vop_nolock: bad operation %d", flags & LK_TYPE_MASK); 45530743Sphk } 45630743Sphk if (flags & LK_INTERLOCK) 45730743Sphk vnflags |= LK_INTERLOCK; 45866355Sbp return(lockmgr(&vp->v_lock, vnflags, &vp->v_interlock, ap->a_p)); 45930743Sphk#else /* for now */ 46030743Sphk /* 46130743Sphk * Since we are not using the lock manager, we must clear 46230743Sphk * the interlock here. 46330743Sphk */ 46431263Sbde if (ap->a_flags & LK_INTERLOCK) 46572200Sbmilekic mtx_unlock(&ap->a_vp->v_interlock); 46630743Sphk return (0); 46730743Sphk#endif 46830743Sphk} 46930743Sphk 47030743Sphk/* 47130743Sphk * Do the inverse of vop_nolock, handling the interlock in a compatible way. 47230743Sphk */ 47330743Sphkint 47430743Sphkvop_nounlock(ap) 47530743Sphk struct vop_unlock_args /* { 47630743Sphk struct vnode *a_vp; 47730743Sphk int a_flags; 47830743Sphk struct proc *a_p; 47930743Sphk } */ *ap; 48030743Sphk{ 48130743Sphk 48266355Sbp /* 48366355Sbp * Since we are not using the lock manager, we must clear 48466355Sbp * the interlock here. 48566355Sbp */ 48666355Sbp if (ap->a_flags & LK_INTERLOCK) 48772200Sbmilekic mtx_unlock(&ap->a_vp->v_interlock); 48866355Sbp return (0); 48930743Sphk} 49030743Sphk 49130743Sphk/* 49230743Sphk * Return whether or not the node is in use. 49330743Sphk */ 49430743Sphkint 49530743Sphkvop_noislocked(ap) 49630743Sphk struct vop_islocked_args /* { 49730743Sphk struct vnode *a_vp; 49854444Seivind struct proc *a_p; 49930743Sphk } */ *ap; 50030743Sphk{ 50130743Sphk 50266355Sbp return (0); 50330743Sphk} 50430743Sphk 50562976Smckusick/* 50662976Smckusick * Return our mount point, as we will take charge of the writes. 50762976Smckusick */ 50862976Smckusickint 50962976Smckusickvop_stdgetwritemount(ap) 51062976Smckusick struct vop_getwritemount_args /* { 51162976Smckusick struct vnode *a_vp; 51262976Smckusick struct mount **a_mpp; 51362976Smckusick } */ *ap; 51462976Smckusick{ 51562976Smckusick 51662976Smckusick *(ap->a_mpp) = ap->a_vp->v_mount; 51762976Smckusick return (0); 51862976Smckusick} 51962976Smckusick 52065770Sbpint 52165770Sbpvop_stdcreatevobject(ap) 52265770Sbp struct vop_createvobject_args /* { 52365770Sbp struct vnode *vp; 52465770Sbp struct ucred *cred; 52565770Sbp struct proc *p; 52665770Sbp } */ *ap; 52765770Sbp{ 52865770Sbp struct vnode *vp = ap->a_vp; 52965770Sbp struct ucred *cred = ap->a_cred; 53065770Sbp struct proc *p = ap->a_p; 53165770Sbp struct vattr vat; 53265770Sbp vm_object_t object; 53365770Sbp int error = 0; 53465770Sbp 53565770Sbp if (!vn_isdisk(vp, NULL) && vn_canvmio(vp) == FALSE) 53665770Sbp return (0); 53765770Sbp 53865770Sbpretry: 53965770Sbp if ((object = vp->v_object) == NULL) { 54065770Sbp if (vp->v_type == VREG || vp->v_type == VDIR) { 54165770Sbp if ((error = VOP_GETATTR(vp, &vat, cred, p)) != 0) 54265770Sbp goto retn; 54365770Sbp object = vnode_pager_alloc(vp, vat.va_size, 0, 0); 54465770Sbp } else if (devsw(vp->v_rdev) != NULL) { 54565770Sbp /* 54665770Sbp * This simply allocates the biggest object possible 54765770Sbp * for a disk vnode. This should be fixed, but doesn't 54865770Sbp * cause any problems (yet). 54965770Sbp */ 55065770Sbp object = vnode_pager_alloc(vp, IDX_TO_OFF(INT_MAX), 0, 0); 55165770Sbp } else { 55265770Sbp goto retn; 55365770Sbp } 55465770Sbp /* 55565770Sbp * Dereference the reference we just created. This assumes 55665770Sbp * that the object is associated with the vp. 55765770Sbp */ 55865770Sbp object->ref_count--; 55965770Sbp vp->v_usecount--; 56065770Sbp } else { 56165770Sbp if (object->flags & OBJ_DEAD) { 56265770Sbp VOP_UNLOCK(vp, 0, p); 56365770Sbp tsleep(object, PVM, "vodead", 0); 56465770Sbp vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); 56565770Sbp goto retry; 56665770Sbp } 56765770Sbp } 56865770Sbp 56965770Sbp KASSERT(vp->v_object != NULL, ("vfs_object_create: NULL object")); 57065770Sbp vp->v_flag |= VOBJBUF; 57165770Sbp 57265770Sbpretn: 57365770Sbp return (error); 57465770Sbp} 57565770Sbp 57665770Sbpint 57765770Sbpvop_stddestroyvobject(ap) 57865770Sbp struct vop_destroyvobject_args /* { 57965770Sbp struct vnode *vp; 58065770Sbp } */ *ap; 58165770Sbp{ 58265770Sbp struct vnode *vp = ap->a_vp; 58365770Sbp vm_object_t obj = vp->v_object; 58465770Sbp 58565770Sbp if (vp->v_object == NULL) 58665770Sbp return (0); 58765770Sbp 58865770Sbp if (obj->ref_count == 0) { 58965770Sbp /* 59065770Sbp * vclean() may be called twice. The first time 59165770Sbp * removes the primary reference to the object, 59265770Sbp * the second time goes one further and is a 59365770Sbp * special-case to terminate the object. 59465770Sbp */ 59565770Sbp vm_object_terminate(obj); 59665770Sbp } else { 59765770Sbp /* 59865770Sbp * Woe to the process that tries to page now :-). 59965770Sbp */ 60065770Sbp vm_pager_deallocate(obj); 60165770Sbp } 60265770Sbp return (0); 60365770Sbp} 60465770Sbp 60565770Sbpint 60665770Sbpvop_stdgetvobject(ap) 60765770Sbp struct vop_getvobject_args /* { 60865770Sbp struct vnode *vp; 60965770Sbp struct vm_object **objpp; 61065770Sbp } */ *ap; 61165770Sbp{ 61265770Sbp struct vnode *vp = ap->a_vp; 61365770Sbp struct vm_object **objpp = ap->a_objpp; 61465770Sbp 61565770Sbp if (objpp) 61665770Sbp *objpp = vp->v_object; 61765770Sbp return (vp->v_object ? 0 : EINVAL); 61865770Sbp} 61965770Sbp 62051068Salfred/* 62151068Salfred * vfs default ops 62251068Salfred * used to fill the vfs fucntion table to get reasonable default return values. 62351068Salfred */ 62451068Salfredint 62551068Salfredvfs_stdmount (mp, path, data, ndp, p) 62651068Salfred struct mount *mp; 62751068Salfred char *path; 62851068Salfred caddr_t data; 62951068Salfred struct nameidata *ndp; 63051068Salfred struct proc *p; 63151068Salfred{ 63251068Salfred return (0); 63351068Salfred} 63451068Salfred 63551068Salfredint 63651068Salfredvfs_stdunmount (mp, mntflags, p) 63751068Salfred struct mount *mp; 63851068Salfred int mntflags; 63951068Salfred struct proc *p; 64051068Salfred{ 64151068Salfred return (0); 64251068Salfred} 64351068Salfred 64451068Salfredint 64551068Salfredvfs_stdroot (mp, vpp) 64651068Salfred struct mount *mp; 64751068Salfred struct vnode **vpp; 64851068Salfred{ 64951068Salfred return (EOPNOTSUPP); 65051068Salfred} 65151068Salfred 65251068Salfredint 65351068Salfredvfs_stdstatfs (mp, sbp, p) 65451068Salfred struct mount *mp; 65551068Salfred struct statfs *sbp; 65651068Salfred struct proc *p; 65751068Salfred{ 65851068Salfred return (EOPNOTSUPP); 65951068Salfred} 66051068Salfred 66151068Salfredint 66251068Salfredvfs_stdvptofh (vp, fhp) 66351068Salfred struct vnode *vp; 66451068Salfred struct fid *fhp; 66551068Salfred{ 66651068Salfred return (EOPNOTSUPP); 66751068Salfred} 66851068Salfred 66951068Salfredint 67051068Salfredvfs_stdstart (mp, flags, p) 67151068Salfred struct mount *mp; 67251068Salfred int flags; 67351068Salfred struct proc *p; 67451068Salfred{ 67551068Salfred return (0); 67651068Salfred} 67751068Salfred 67851068Salfredint 67951068Salfredvfs_stdquotactl (mp, cmds, uid, arg, p) 68051068Salfred struct mount *mp; 68151068Salfred int cmds; 68251068Salfred uid_t uid; 68351068Salfred caddr_t arg; 68451068Salfred struct proc *p; 68551068Salfred{ 68651068Salfred return (EOPNOTSUPP); 68751068Salfred} 68851068Salfred 68951068Salfredint 69051068Salfredvfs_stdsync (mp, waitfor, cred, p) 69151068Salfred struct mount *mp; 69251068Salfred int waitfor; 69351068Salfred struct ucred *cred; 69451068Salfred struct proc *p; 69551068Salfred{ 69651068Salfred return (0); 69751068Salfred} 69851068Salfred 69951068Salfredint 70051068Salfredvfs_stdvget (mp, ino, vpp) 70151068Salfred struct mount *mp; 70251068Salfred ino_t ino; 70351068Salfred struct vnode **vpp; 70451068Salfred{ 70551068Salfred return (EOPNOTSUPP); 70651068Salfred} 70751068Salfred 70851068Salfredint 70951138Salfredvfs_stdfhtovp (mp, fhp, vpp) 71051068Salfred struct mount *mp; 71151068Salfred struct fid *fhp; 71251138Salfred struct vnode **vpp; 71351138Salfred{ 71451138Salfred return (EOPNOTSUPP); 71551138Salfred} 71651138Salfred 71751138Salfredint 71851138Salfredvfs_stdcheckexp (mp, nam, extflagsp, credanonp) 71951138Salfred struct mount *mp; 72051068Salfred struct sockaddr *nam; 72151138Salfred int *extflagsp; 72251068Salfred struct ucred **credanonp; 72351068Salfred{ 72451068Salfred return (EOPNOTSUPP); 72551068Salfred} 72651068Salfred 72751068Salfredint 72851068Salfredvfs_stdinit (vfsp) 72951068Salfred struct vfsconf *vfsp; 73051068Salfred{ 73151068Salfred return (0); 73251068Salfred} 73351068Salfred 73451068Salfredint 73551068Salfredvfs_stduninit (vfsp) 73651068Salfred struct vfsconf *vfsp; 73751068Salfred{ 73851068Salfred return(0); 73951068Salfred} 74051068Salfred 74154803Srwatsonint 74274437Srwatsonvfs_stdextattrctl(mp, cmd, filename_vp, attrnamespace, attrname, p) 74354803Srwatson struct mount *mp; 74454803Srwatson int cmd; 74574273Srwatson struct vnode *filename_vp; 74674437Srwatson int attrnamespace; 74756272Srwatson const char *attrname; 74854803Srwatson struct proc *p; 74954803Srwatson{ 75054803Srwatson return(EOPNOTSUPP); 75154803Srwatson} 75254803Srwatson 75351068Salfred/* end of vfs default ops */ 754