vfs_default.c revision 67365
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 67365 2000-10-20 07:58:15Z jhb $ 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 6830489Sphkstatic int vop_nostrategy __P((struct vop_strategy_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 }, 8230743Sphk { &vop_bwrite_desc, (vop_t *) vop_stdbwrite }, 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 }, 8765770Sbp { &vop_getvobject_desc, (vop_t *) vop_stdgetvobject }, 8864819Sphk { &vop_inactive_desc, (vop_t *) vop_stdinactive }, 8930492Sphk { &vop_ioctl_desc, (vop_t *) vop_enotty }, 9030496Sphk { &vop_islocked_desc, (vop_t *) vop_noislocked }, 9130739Sphk { &vop_lease_desc, (vop_t *) vop_null }, 9230496Sphk { &vop_lock_desc, (vop_t *) vop_nolock }, 9330492Sphk { &vop_mmap_desc, (vop_t *) vop_einval }, 9430492Sphk { &vop_open_desc, (vop_t *) vop_null }, 9530492Sphk { &vop_pathconf_desc, (vop_t *) vop_einval }, 9630489Sphk { &vop_poll_desc, (vop_t *) vop_nopoll }, 9730492Sphk { &vop_readlink_desc, (vop_t *) vop_einval }, 9830489Sphk { &vop_revoke_desc, (vop_t *) vop_revoke }, 9930489Sphk { &vop_strategy_desc, (vop_t *) vop_nostrategy }, 10030496Sphk { &vop_unlock_desc, (vop_t *) vop_nounlock }, 10130489Sphk { NULL, NULL } 10230489Sphk}; 10330489Sphk 10430489Sphkstatic struct vnodeopv_desc default_vnodeop_opv_desc = 10530489Sphk { &default_vnodeop_p, default_vnodeop_entries }; 10630489Sphk 10730489SphkVNODEOP_SET(default_vnodeop_opv_desc); 10830489Sphk 10930489Sphkint 11030492Sphkvop_eopnotsupp(struct vop_generic_args *ap) 11130489Sphk{ 11230489Sphk /* 11330492Sphk printf("vop_notsupp[%s]\n", ap->a_desc->vdesc_name); 11430489Sphk */ 11530489Sphk 11630489Sphk return (EOPNOTSUPP); 11730489Sphk} 11830489Sphk 11930489Sphkint 12030492Sphkvop_ebadf(struct vop_generic_args *ap) 12130489Sphk{ 12230489Sphk 12330492Sphk return (EBADF); 12430492Sphk} 12530492Sphk 12630492Sphkint 12730492Sphkvop_enotty(struct vop_generic_args *ap) 12830492Sphk{ 12930492Sphk 13030492Sphk return (ENOTTY); 13130492Sphk} 13230492Sphk 13330492Sphkint 13430492Sphkvop_einval(struct vop_generic_args *ap) 13530492Sphk{ 13630492Sphk 13730492Sphk return (EINVAL); 13830492Sphk} 13930492Sphk 14030492Sphkint 14130492Sphkvop_null(struct vop_generic_args *ap) 14230492Sphk{ 14330492Sphk 14430492Sphk return (0); 14530492Sphk} 14630492Sphk 14730492Sphkint 14830492Sphkvop_defaultop(struct vop_generic_args *ap) 14930492Sphk{ 15030492Sphk 15130489Sphk return (VOCALL(default_vnodeop_p, ap->a_desc->vdesc_offset, ap)); 15230489Sphk} 15330489Sphk 15441056Speterint 15541056Spetervop_panic(struct vop_generic_args *ap) 15641056Speter{ 15741056Speter 15852970Sphk printf("vop_panic[%s]\n", ap->a_desc->vdesc_name); 15952970Sphk panic("Filesystem goof"); 16052970Sphk return (0); 16141056Speter} 16241056Speter 16346349Salc/* 16446349Salc * vop_nostrategy: 16546349Salc * 16646349Salc * Strategy routine for VFS devices that have none. 16746349Salc * 16858934Sphk * BIO_ERROR and B_INVAL must be cleared prior to calling any strategy 16958345Sphk * routine. Typically this is done for a BIO_READ strategy call. 17058345Sphk * Typically B_INVAL is assumed to already be clear prior to a write 17158345Sphk * and should not be cleared manually unless you just made the buffer 17258934Sphk * invalid. BIO_ERROR should be cleared either way. 17346349Salc */ 17446349Salc 17530489Sphkstatic int 17630489Sphkvop_nostrategy (struct vop_strategy_args *ap) 17730489Sphk{ 17830489Sphk printf("No strategy for buffer at %p\n", ap->a_bp); 17937384Sjulian vprint("", ap->a_vp); 18030489Sphk vprint("", ap->a_bp->b_vp); 18158934Sphk ap->a_bp->b_ioflags |= BIO_ERROR; 18230489Sphk ap->a_bp->b_error = EOPNOTSUPP; 18359249Sphk bufdone(ap->a_bp); 18430489Sphk return (EOPNOTSUPP); 18530489Sphk} 18630492Sphk 18730492Sphkint 18830492Sphkvop_stdpathconf(ap) 18930492Sphk struct vop_pathconf_args /* { 19030492Sphk struct vnode *a_vp; 19130492Sphk int a_name; 19230492Sphk int *a_retval; 19330492Sphk } */ *ap; 19430492Sphk{ 19530492Sphk 19630492Sphk switch (ap->a_name) { 19730492Sphk case _PC_LINK_MAX: 19830492Sphk *ap->a_retval = LINK_MAX; 19930492Sphk return (0); 20030492Sphk case _PC_MAX_CANON: 20130492Sphk *ap->a_retval = MAX_CANON; 20230492Sphk return (0); 20330492Sphk case _PC_MAX_INPUT: 20430492Sphk *ap->a_retval = MAX_INPUT; 20530492Sphk return (0); 20630492Sphk case _PC_PIPE_BUF: 20730492Sphk *ap->a_retval = PIPE_BUF; 20830492Sphk return (0); 20930492Sphk case _PC_CHOWN_RESTRICTED: 21030492Sphk *ap->a_retval = 1; 21130492Sphk return (0); 21230492Sphk case _PC_VDISABLE: 21330492Sphk *ap->a_retval = _POSIX_VDISABLE; 21430492Sphk return (0); 21530492Sphk default: 21630492Sphk return (EINVAL); 21730492Sphk } 21830492Sphk /* NOTREACHED */ 21930492Sphk} 22030513Sphk 22130513Sphk/* 22230513Sphk * Standard lock, unlock and islocked functions. 22330513Sphk * 22430513Sphk * These depend on the lock structure being the first element in the 22530513Sphk * inode, ie: vp->v_data points to the the lock! 22630513Sphk */ 22730513Sphkint 22830513Sphkvop_stdlock(ap) 22930513Sphk struct vop_lock_args /* { 23030513Sphk struct vnode *a_vp; 23130513Sphk int a_flags; 23230513Sphk struct proc *a_p; 23330513Sphk } */ *ap; 23430513Sphk{ 23566355Sbp struct vnode *vp = ap->a_vp; 23630513Sphk 23742900Seivind#ifndef DEBUG_LOCKS 23866355Sbp return (lockmgr(&vp->v_lock, ap->a_flags, &vp->v_interlock, ap->a_p)); 23942900Seivind#else 24066355Sbp return (debuglockmgr(&vp->v_lock, ap->a_flags, &vp->v_interlock, 24166355Sbp ap->a_p, "vop_stdlock", vp->filename, vp->line)); 24242900Seivind#endif 24330513Sphk} 24430513Sphk 24530513Sphkint 24630513Sphkvop_stdunlock(ap) 24730513Sphk struct vop_unlock_args /* { 24830513Sphk struct vnode *a_vp; 24930513Sphk int a_flags; 25030513Sphk struct proc *a_p; 25130513Sphk } */ *ap; 25230513Sphk{ 25366355Sbp struct vnode *vp = ap->a_vp; 25430513Sphk 25566355Sbp return (lockmgr(&vp->v_lock, ap->a_flags | LK_RELEASE, &vp->v_interlock, 25630513Sphk ap->a_p)); 25730513Sphk} 25830513Sphk 25930513Sphkint 26030513Sphkvop_stdislocked(ap) 26130513Sphk struct vop_islocked_args /* { 26230513Sphk struct vnode *a_vp; 26354444Seivind struct proc *a_p; 26430513Sphk } */ *ap; 26530513Sphk{ 26630513Sphk 26766355Sbp return (lockstatus(&ap->a_vp->v_lock, ap->a_p)); 26830513Sphk} 26930513Sphk 27064819Sphkint 27164819Sphkvop_stdinactive(ap) 27264819Sphk struct vop_inactive_args /* { 27364819Sphk struct vnode *a_vp; 27464819Sphk struct proc *a_p; 27564819Sphk } */ *ap; 27664819Sphk{ 27764819Sphk 27864819Sphk VOP_UNLOCK(ap->a_vp, 0, ap->a_p); 27964819Sphk return (0); 28064819Sphk} 28164819Sphk 28230743Sphk/* 28330743Sphk * Return true for select/poll. 28430743Sphk */ 28530743Sphkint 28630743Sphkvop_nopoll(ap) 28730743Sphk struct vop_poll_args /* { 28830743Sphk struct vnode *a_vp; 28930743Sphk int a_events; 29030743Sphk struct ucred *a_cred; 29130743Sphk struct proc *a_p; 29230743Sphk } */ *ap; 29330743Sphk{ 29430743Sphk /* 29531727Swollman * Return true for read/write. If the user asked for something 29631727Swollman * special, return POLLNVAL, so that clients have a way of 29731727Swollman * determining reliably whether or not the extended 29831727Swollman * functionality is present without hard-coding knowledge 29931727Swollman * of specific filesystem implementations. 30030743Sphk */ 30131727Swollman if (ap->a_events & ~POLLSTANDARD) 30231727Swollman return (POLLNVAL); 30331727Swollman 30430743Sphk return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)); 30530743Sphk} 30630743Sphk 30731727Swollman/* 30831727Swollman * Implement poll for local filesystems that support it. 30931727Swollman */ 31030743Sphkint 31131727Swollmanvop_stdpoll(ap) 31231727Swollman struct vop_poll_args /* { 31331727Swollman struct vnode *a_vp; 31431727Swollman int a_events; 31531727Swollman struct ucred *a_cred; 31631727Swollman struct proc *a_p; 31731727Swollman } */ *ap; 31831727Swollman{ 31931811Swollman if ((ap->a_events & ~POLLSTANDARD) == 0) 32031811Swollman return (ap->a_events & (POLLRDNORM|POLLWRNORM)); 32131727Swollman return (vn_pollrecord(ap->a_vp, ap->a_p, ap->a_events)); 32231727Swollman} 32331727Swollman 32431727Swollmanint 32530743Sphkvop_stdbwrite(ap) 32630743Sphk struct vop_bwrite_args *ap; 32730743Sphk{ 32830743Sphk return (bwrite(ap->a_bp)); 32930743Sphk} 33030743Sphk 33130743Sphk/* 33230743Sphk * Stubs to use when there is no locking to be done on the underlying object. 33330743Sphk * A minimal shared lock is necessary to ensure that the underlying object 33430743Sphk * is not revoked while an operation is in progress. So, an active shared 33530743Sphk * count is maintained in an auxillary vnode lock structure. 33630743Sphk */ 33730743Sphkint 33830743Sphkvop_sharedlock(ap) 33930743Sphk struct vop_lock_args /* { 34030743Sphk struct vnode *a_vp; 34130743Sphk int a_flags; 34230743Sphk struct proc *a_p; 34330743Sphk } */ *ap; 34430743Sphk{ 34530743Sphk /* 34630743Sphk * This code cannot be used until all the non-locking filesystems 34730743Sphk * (notably NFS) are converted to properly lock and release nodes. 34830743Sphk * Also, certain vnode operations change the locking state within 34930743Sphk * the operation (create, mknod, remove, link, rename, mkdir, rmdir, 35030743Sphk * and symlink). Ideally these operations should not change the 35130743Sphk * lock state, but should be changed to let the caller of the 35230743Sphk * function unlock them. Otherwise all intermediate vnode layers 35330743Sphk * (such as union, umapfs, etc) must catch these functions to do 35430743Sphk * the necessary locking at their layer. Note that the inactive 35530743Sphk * and lookup operations also change their lock state, but this 35630743Sphk * cannot be avoided, so these two operations will always need 35730743Sphk * to be handled in intermediate layers. 35830743Sphk */ 35930743Sphk struct vnode *vp = ap->a_vp; 36030743Sphk int vnflags, flags = ap->a_flags; 36130743Sphk 36230743Sphk switch (flags & LK_TYPE_MASK) { 36330743Sphk case LK_DRAIN: 36430743Sphk vnflags = LK_DRAIN; 36530743Sphk break; 36630743Sphk case LK_EXCLUSIVE: 36730743Sphk#ifdef DEBUG_VFS_LOCKS 36830743Sphk /* 36930743Sphk * Normally, we use shared locks here, but that confuses 37030743Sphk * the locking assertions. 37130743Sphk */ 37230743Sphk vnflags = LK_EXCLUSIVE; 37330743Sphk break; 37430743Sphk#endif 37530743Sphk case LK_SHARED: 37630743Sphk vnflags = LK_SHARED; 37730743Sphk break; 37830743Sphk case LK_UPGRADE: 37930743Sphk case LK_EXCLUPGRADE: 38030743Sphk case LK_DOWNGRADE: 38130743Sphk return (0); 38230743Sphk case LK_RELEASE: 38330743Sphk default: 38430743Sphk panic("vop_sharedlock: bad operation %d", flags & LK_TYPE_MASK); 38530743Sphk } 38630743Sphk if (flags & LK_INTERLOCK) 38730743Sphk vnflags |= LK_INTERLOCK; 38842900Seivind#ifndef DEBUG_LOCKS 38966355Sbp return (lockmgr(&vp->v_lock, vnflags, &vp->v_interlock, ap->a_p)); 39042900Seivind#else 39166355Sbp return (debuglockmgr(&vp->v_lock, vnflags, &vp->v_interlock, ap->a_p, 39242900Seivind "vop_sharedlock", vp->filename, vp->line)); 39342900Seivind#endif 39430743Sphk} 39530743Sphk 39630743Sphk/* 39730743Sphk * Stubs to use when there is no locking to be done on the underlying object. 39830743Sphk * A minimal shared lock is necessary to ensure that the underlying object 39930743Sphk * is not revoked while an operation is in progress. So, an active shared 40030743Sphk * count is maintained in an auxillary vnode lock structure. 40130743Sphk */ 40230743Sphkint 40330743Sphkvop_nolock(ap) 40430743Sphk struct vop_lock_args /* { 40530743Sphk struct vnode *a_vp; 40630743Sphk int a_flags; 40730743Sphk struct proc *a_p; 40830743Sphk } */ *ap; 40930743Sphk{ 41030743Sphk#ifdef notyet 41130743Sphk /* 41230743Sphk * This code cannot be used until all the non-locking filesystems 41330743Sphk * (notably NFS) are converted to properly lock and release nodes. 41430743Sphk * Also, certain vnode operations change the locking state within 41530743Sphk * the operation (create, mknod, remove, link, rename, mkdir, rmdir, 41630743Sphk * and symlink). Ideally these operations should not change the 41730743Sphk * lock state, but should be changed to let the caller of the 41830743Sphk * function unlock them. Otherwise all intermediate vnode layers 41930743Sphk * (such as union, umapfs, etc) must catch these functions to do 42030743Sphk * the necessary locking at their layer. Note that the inactive 42130743Sphk * and lookup operations also change their lock state, but this 42230743Sphk * cannot be avoided, so these two operations will always need 42330743Sphk * to be handled in intermediate layers. 42430743Sphk */ 42530743Sphk struct vnode *vp = ap->a_vp; 42630743Sphk int vnflags, flags = ap->a_flags; 42730743Sphk 42830743Sphk switch (flags & LK_TYPE_MASK) { 42930743Sphk case LK_DRAIN: 43030743Sphk vnflags = LK_DRAIN; 43130743Sphk break; 43230743Sphk case LK_EXCLUSIVE: 43330743Sphk case LK_SHARED: 43430743Sphk vnflags = LK_SHARED; 43530743Sphk break; 43630743Sphk case LK_UPGRADE: 43730743Sphk case LK_EXCLUPGRADE: 43830743Sphk case LK_DOWNGRADE: 43930743Sphk return (0); 44030743Sphk case LK_RELEASE: 44130743Sphk default: 44230743Sphk panic("vop_nolock: bad operation %d", flags & LK_TYPE_MASK); 44330743Sphk } 44430743Sphk if (flags & LK_INTERLOCK) 44530743Sphk vnflags |= LK_INTERLOCK; 44666355Sbp return(lockmgr(&vp->v_lock, vnflags, &vp->v_interlock, ap->a_p)); 44730743Sphk#else /* for now */ 44830743Sphk /* 44930743Sphk * Since we are not using the lock manager, we must clear 45030743Sphk * the interlock here. 45130743Sphk */ 45231263Sbde if (ap->a_flags & LK_INTERLOCK) 45366615Sjasone mtx_exit(&ap->a_vp->v_interlock, MTX_DEF); 45430743Sphk return (0); 45530743Sphk#endif 45630743Sphk} 45730743Sphk 45830743Sphk/* 45930743Sphk * Do the inverse of vop_nolock, handling the interlock in a compatible way. 46030743Sphk */ 46130743Sphkint 46230743Sphkvop_nounlock(ap) 46330743Sphk struct vop_unlock_args /* { 46430743Sphk struct vnode *a_vp; 46530743Sphk int a_flags; 46630743Sphk struct proc *a_p; 46730743Sphk } */ *ap; 46830743Sphk{ 46930743Sphk 47066355Sbp /* 47166355Sbp * Since we are not using the lock manager, we must clear 47266355Sbp * the interlock here. 47366355Sbp */ 47466355Sbp if (ap->a_flags & LK_INTERLOCK) 47566615Sjasone mtx_exit(&ap->a_vp->v_interlock, MTX_DEF); 47666355Sbp return (0); 47730743Sphk} 47830743Sphk 47930743Sphk/* 48030743Sphk * Return whether or not the node is in use. 48130743Sphk */ 48230743Sphkint 48330743Sphkvop_noislocked(ap) 48430743Sphk struct vop_islocked_args /* { 48530743Sphk struct vnode *a_vp; 48654444Seivind struct proc *a_p; 48730743Sphk } */ *ap; 48830743Sphk{ 48930743Sphk 49066355Sbp return (0); 49130743Sphk} 49230743Sphk 49362976Smckusick/* 49462976Smckusick * Return our mount point, as we will take charge of the writes. 49562976Smckusick */ 49662976Smckusickint 49762976Smckusickvop_stdgetwritemount(ap) 49862976Smckusick struct vop_getwritemount_args /* { 49962976Smckusick struct vnode *a_vp; 50062976Smckusick struct mount **a_mpp; 50162976Smckusick } */ *ap; 50262976Smckusick{ 50362976Smckusick 50462976Smckusick *(ap->a_mpp) = ap->a_vp->v_mount; 50562976Smckusick return (0); 50662976Smckusick} 50762976Smckusick 50865770Sbpint 50965770Sbpvop_stdcreatevobject(ap) 51065770Sbp struct vop_createvobject_args /* { 51165770Sbp struct vnode *vp; 51265770Sbp struct ucred *cred; 51365770Sbp struct proc *p; 51465770Sbp } */ *ap; 51565770Sbp{ 51665770Sbp struct vnode *vp = ap->a_vp; 51765770Sbp struct ucred *cred = ap->a_cred; 51865770Sbp struct proc *p = ap->a_p; 51965770Sbp struct vattr vat; 52065770Sbp vm_object_t object; 52165770Sbp int error = 0; 52265770Sbp 52365770Sbp if (!vn_isdisk(vp, NULL) && vn_canvmio(vp) == FALSE) 52465770Sbp return (0); 52565770Sbp 52665770Sbpretry: 52765770Sbp if ((object = vp->v_object) == NULL) { 52865770Sbp if (vp->v_type == VREG || vp->v_type == VDIR) { 52965770Sbp if ((error = VOP_GETATTR(vp, &vat, cred, p)) != 0) 53065770Sbp goto retn; 53165770Sbp object = vnode_pager_alloc(vp, vat.va_size, 0, 0); 53265770Sbp } else if (devsw(vp->v_rdev) != NULL) { 53365770Sbp /* 53465770Sbp * This simply allocates the biggest object possible 53565770Sbp * for a disk vnode. This should be fixed, but doesn't 53665770Sbp * cause any problems (yet). 53765770Sbp */ 53865770Sbp object = vnode_pager_alloc(vp, IDX_TO_OFF(INT_MAX), 0, 0); 53965770Sbp } else { 54065770Sbp goto retn; 54165770Sbp } 54265770Sbp /* 54365770Sbp * Dereference the reference we just created. This assumes 54465770Sbp * that the object is associated with the vp. 54565770Sbp */ 54665770Sbp object->ref_count--; 54765770Sbp vp->v_usecount--; 54865770Sbp } else { 54965770Sbp if (object->flags & OBJ_DEAD) { 55065770Sbp VOP_UNLOCK(vp, 0, p); 55165770Sbp tsleep(object, PVM, "vodead", 0); 55265770Sbp vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); 55365770Sbp goto retry; 55465770Sbp } 55565770Sbp } 55665770Sbp 55765770Sbp KASSERT(vp->v_object != NULL, ("vfs_object_create: NULL object")); 55865770Sbp vp->v_flag |= VOBJBUF; 55965770Sbp 56065770Sbpretn: 56165770Sbp return (error); 56265770Sbp} 56365770Sbp 56465770Sbpint 56565770Sbpvop_stddestroyvobject(ap) 56665770Sbp struct vop_destroyvobject_args /* { 56765770Sbp struct vnode *vp; 56865770Sbp } */ *ap; 56965770Sbp{ 57065770Sbp struct vnode *vp = ap->a_vp; 57165770Sbp vm_object_t obj = vp->v_object; 57265770Sbp 57365770Sbp if (vp->v_object == NULL) 57465770Sbp return (0); 57565770Sbp 57665770Sbp if (obj->ref_count == 0) { 57765770Sbp /* 57865770Sbp * vclean() may be called twice. The first time 57965770Sbp * removes the primary reference to the object, 58065770Sbp * the second time goes one further and is a 58165770Sbp * special-case to terminate the object. 58265770Sbp */ 58365770Sbp vm_object_terminate(obj); 58465770Sbp } else { 58565770Sbp /* 58665770Sbp * Woe to the process that tries to page now :-). 58765770Sbp */ 58865770Sbp vm_pager_deallocate(obj); 58965770Sbp } 59065770Sbp return (0); 59165770Sbp} 59265770Sbp 59365770Sbpint 59465770Sbpvop_stdgetvobject(ap) 59565770Sbp struct vop_getvobject_args /* { 59665770Sbp struct vnode *vp; 59765770Sbp struct vm_object **objpp; 59865770Sbp } */ *ap; 59965770Sbp{ 60065770Sbp struct vnode *vp = ap->a_vp; 60165770Sbp struct vm_object **objpp = ap->a_objpp; 60265770Sbp 60365770Sbp if (objpp) 60465770Sbp *objpp = vp->v_object; 60565770Sbp return (vp->v_object ? 0 : EINVAL); 60665770Sbp} 60765770Sbp 60851068Salfred/* 60951068Salfred * vfs default ops 61051068Salfred * used to fill the vfs fucntion table to get reasonable default return values. 61151068Salfred */ 61251068Salfredint 61351068Salfredvfs_stdmount (mp, path, data, ndp, p) 61451068Salfred struct mount *mp; 61551068Salfred char *path; 61651068Salfred caddr_t data; 61751068Salfred struct nameidata *ndp; 61851068Salfred struct proc *p; 61951068Salfred{ 62051068Salfred return (0); 62151068Salfred} 62251068Salfred 62351068Salfredint 62451068Salfredvfs_stdunmount (mp, mntflags, p) 62551068Salfred struct mount *mp; 62651068Salfred int mntflags; 62751068Salfred struct proc *p; 62851068Salfred{ 62951068Salfred return (0); 63051068Salfred} 63151068Salfred 63251068Salfredint 63351068Salfredvfs_stdroot (mp, vpp) 63451068Salfred struct mount *mp; 63551068Salfred struct vnode **vpp; 63651068Salfred{ 63751068Salfred return (EOPNOTSUPP); 63851068Salfred} 63951068Salfred 64051068Salfredint 64151068Salfredvfs_stdstatfs (mp, sbp, p) 64251068Salfred struct mount *mp; 64351068Salfred struct statfs *sbp; 64451068Salfred struct proc *p; 64551068Salfred{ 64651068Salfred return (EOPNOTSUPP); 64751068Salfred} 64851068Salfred 64951068Salfredint 65051068Salfredvfs_stdvptofh (vp, fhp) 65151068Salfred struct vnode *vp; 65251068Salfred struct fid *fhp; 65351068Salfred{ 65451068Salfred return (EOPNOTSUPP); 65551068Salfred} 65651068Salfred 65751068Salfredint 65851068Salfredvfs_stdstart (mp, flags, p) 65951068Salfred struct mount *mp; 66051068Salfred int flags; 66151068Salfred struct proc *p; 66251068Salfred{ 66351068Salfred return (0); 66451068Salfred} 66551068Salfred 66651068Salfredint 66751068Salfredvfs_stdquotactl (mp, cmds, uid, arg, p) 66851068Salfred struct mount *mp; 66951068Salfred int cmds; 67051068Salfred uid_t uid; 67151068Salfred caddr_t arg; 67251068Salfred struct proc *p; 67351068Salfred{ 67451068Salfred return (EOPNOTSUPP); 67551068Salfred} 67651068Salfred 67751068Salfredint 67851068Salfredvfs_stdsync (mp, waitfor, cred, p) 67951068Salfred struct mount *mp; 68051068Salfred int waitfor; 68151068Salfred struct ucred *cred; 68251068Salfred struct proc *p; 68351068Salfred{ 68451068Salfred return (0); 68551068Salfred} 68651068Salfred 68751068Salfredint 68851068Salfredvfs_stdvget (mp, ino, vpp) 68951068Salfred struct mount *mp; 69051068Salfred ino_t ino; 69151068Salfred struct vnode **vpp; 69251068Salfred{ 69351068Salfred return (EOPNOTSUPP); 69451068Salfred} 69551068Salfred 69651068Salfredint 69751138Salfredvfs_stdfhtovp (mp, fhp, vpp) 69851068Salfred struct mount *mp; 69951068Salfred struct fid *fhp; 70051138Salfred struct vnode **vpp; 70151138Salfred{ 70251138Salfred return (EOPNOTSUPP); 70351138Salfred} 70451138Salfred 70551138Salfredint 70651138Salfredvfs_stdcheckexp (mp, nam, extflagsp, credanonp) 70751138Salfred struct mount *mp; 70851068Salfred struct sockaddr *nam; 70951138Salfred int *extflagsp; 71051068Salfred struct ucred **credanonp; 71151068Salfred{ 71251068Salfred return (EOPNOTSUPP); 71351068Salfred} 71451068Salfred 71551068Salfredint 71651068Salfredvfs_stdinit (vfsp) 71751068Salfred struct vfsconf *vfsp; 71851068Salfred{ 71951068Salfred return (0); 72051068Salfred} 72151068Salfred 72251068Salfredint 72351068Salfredvfs_stduninit (vfsp) 72451068Salfred struct vfsconf *vfsp; 72551068Salfred{ 72651068Salfred return(0); 72751068Salfred} 72851068Salfred 72954803Srwatsonint 73054803Srwatsonvfs_stdextattrctl(mp, cmd, attrname, arg, p) 73154803Srwatson struct mount *mp; 73254803Srwatson int cmd; 73356272Srwatson const char *attrname; 73454803Srwatson caddr_t arg; 73554803Srwatson struct proc *p; 73654803Srwatson{ 73754803Srwatson return(EOPNOTSUPP); 73854803Srwatson} 73954803Srwatson 74051068Salfred/* end of vfs default ops */ 741