vfs_default.c revision 91690
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 91690 2002-03-05 15:38:49Z eivind $ 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 }, 8876167Sphk { &vop_getpages_desc, (vop_t *) vop_stdgetpages }, 8965770Sbp { &vop_getvobject_desc, (vop_t *) vop_stdgetvobject }, 9064819Sphk { &vop_inactive_desc, (vop_t *) vop_stdinactive }, 9130492Sphk { &vop_ioctl_desc, (vop_t *) vop_enotty }, 9230496Sphk { &vop_islocked_desc, (vop_t *) vop_noislocked }, 9330739Sphk { &vop_lease_desc, (vop_t *) vop_null }, 9430496Sphk { &vop_lock_desc, (vop_t *) vop_nolock }, 9572594Sbde { &vop_lookup_desc, (vop_t *) vop_nolookup }, 9630492Sphk { &vop_open_desc, (vop_t *) vop_null }, 9730492Sphk { &vop_pathconf_desc, (vop_t *) vop_einval }, 9876167Sphk { &vop_putpages_desc, (vop_t *) vop_stdputpages }, 9930489Sphk { &vop_poll_desc, (vop_t *) vop_nopoll }, 10030492Sphk { &vop_readlink_desc, (vop_t *) vop_einval }, 10130489Sphk { &vop_revoke_desc, (vop_t *) vop_revoke }, 10230489Sphk { &vop_strategy_desc, (vop_t *) vop_nostrategy }, 10330496Sphk { &vop_unlock_desc, (vop_t *) vop_nounlock }, 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. 20758345Sphk * 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); 21637384Sjulian vprint("", ap->a_vp); 21730489Sphk vprint("", 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/* 22591690Seivind * vop_stdpathconf: 22691690Seivind * 22791690Seivind * Standard implementation of POSIX pathconf, to get information about limits 22891690Seivind * for a filesystem. 22991690Seivind * Override per filesystem for the case where the filesystem has smaller 23091690Seivind * limits. 23191690Seivind */ 23230492Sphkint 23330492Sphkvop_stdpathconf(ap) 23430492Sphk struct vop_pathconf_args /* { 23530492Sphk struct vnode *a_vp; 23630492Sphk int a_name; 23730492Sphk int *a_retval; 23830492Sphk } */ *ap; 23930492Sphk{ 24030492Sphk 24130492Sphk switch (ap->a_name) { 24230492Sphk case _PC_LINK_MAX: 24330492Sphk *ap->a_retval = LINK_MAX; 24430492Sphk return (0); 24530492Sphk case _PC_MAX_CANON: 24630492Sphk *ap->a_retval = MAX_CANON; 24730492Sphk return (0); 24830492Sphk case _PC_MAX_INPUT: 24930492Sphk *ap->a_retval = MAX_INPUT; 25030492Sphk return (0); 25130492Sphk case _PC_PIPE_BUF: 25230492Sphk *ap->a_retval = PIPE_BUF; 25330492Sphk return (0); 25430492Sphk case _PC_CHOWN_RESTRICTED: 25530492Sphk *ap->a_retval = 1; 25630492Sphk return (0); 25730492Sphk case _PC_VDISABLE: 25830492Sphk *ap->a_retval = _POSIX_VDISABLE; 25930492Sphk return (0); 26030492Sphk default: 26130492Sphk return (EINVAL); 26230492Sphk } 26330492Sphk /* NOTREACHED */ 26430492Sphk} 26530513Sphk 26630513Sphk/* 26730513Sphk * Standard lock, unlock and islocked functions. 26830513Sphk * 26930513Sphk * These depend on the lock structure being the first element in the 27030513Sphk * inode, ie: vp->v_data points to the the lock! 27130513Sphk */ 27230513Sphkint 27330513Sphkvop_stdlock(ap) 27430513Sphk struct vop_lock_args /* { 27530513Sphk struct vnode *a_vp; 27630513Sphk int a_flags; 27783366Sjulian struct thread *a_td; 27830513Sphk } */ *ap; 27930513Sphk{ 28066355Sbp struct vnode *vp = ap->a_vp; 28130513Sphk 28242900Seivind#ifndef DEBUG_LOCKS 28383366Sjulian return (lockmgr(&vp->v_lock, ap->a_flags, &vp->v_interlock, ap->a_td)); 28442900Seivind#else 28566355Sbp return (debuglockmgr(&vp->v_lock, ap->a_flags, &vp->v_interlock, 28683366Sjulian ap->a_td, "vop_stdlock", vp->filename, vp->line)); 28742900Seivind#endif 28830513Sphk} 28930513Sphk 29091690Seivind/* See above. */ 29130513Sphkint 29230513Sphkvop_stdunlock(ap) 29330513Sphk struct vop_unlock_args /* { 29430513Sphk struct vnode *a_vp; 29530513Sphk int a_flags; 29683366Sjulian struct thread *a_td; 29730513Sphk } */ *ap; 29830513Sphk{ 29966355Sbp struct vnode *vp = ap->a_vp; 30030513Sphk 30166355Sbp return (lockmgr(&vp->v_lock, ap->a_flags | LK_RELEASE, &vp->v_interlock, 30283366Sjulian ap->a_td)); 30330513Sphk} 30430513Sphk 30591690Seivind/* See above. */ 30630513Sphkint 30730513Sphkvop_stdislocked(ap) 30830513Sphk struct vop_islocked_args /* { 30930513Sphk struct vnode *a_vp; 31083366Sjulian struct thread *a_td; 31130513Sphk } */ *ap; 31230513Sphk{ 31330513Sphk 31483366Sjulian return (lockstatus(&ap->a_vp->v_lock, ap->a_td)); 31530513Sphk} 31630513Sphk 31791690Seivind/* Mark the vnode inactive */ 31864819Sphkint 31964819Sphkvop_stdinactive(ap) 32064819Sphk struct vop_inactive_args /* { 32164819Sphk struct vnode *a_vp; 32283366Sjulian struct thread *a_td; 32364819Sphk } */ *ap; 32464819Sphk{ 32564819Sphk 32683366Sjulian VOP_UNLOCK(ap->a_vp, 0, ap->a_td); 32764819Sphk return (0); 32864819Sphk} 32964819Sphk 33030743Sphk/* 33130743Sphk * Return true for select/poll. 33230743Sphk */ 33330743Sphkint 33430743Sphkvop_nopoll(ap) 33530743Sphk struct vop_poll_args /* { 33630743Sphk struct vnode *a_vp; 33730743Sphk int a_events; 33830743Sphk struct ucred *a_cred; 33983366Sjulian struct thread *a_td; 34030743Sphk } */ *ap; 34130743Sphk{ 34230743Sphk /* 34331727Swollman * Return true for read/write. If the user asked for something 34431727Swollman * special, return POLLNVAL, so that clients have a way of 34531727Swollman * determining reliably whether or not the extended 34631727Swollman * functionality is present without hard-coding knowledge 34731727Swollman * of specific filesystem implementations. 34830743Sphk */ 34931727Swollman if (ap->a_events & ~POLLSTANDARD) 35031727Swollman return (POLLNVAL); 35131727Swollman 35230743Sphk return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)); 35330743Sphk} 35430743Sphk 35531727Swollman/* 35631727Swollman * Implement poll for local filesystems that support it. 35731727Swollman */ 35830743Sphkint 35931727Swollmanvop_stdpoll(ap) 36031727Swollman struct vop_poll_args /* { 36131727Swollman struct vnode *a_vp; 36231727Swollman int a_events; 36331727Swollman struct ucred *a_cred; 36483366Sjulian struct thread *a_td; 36531727Swollman } */ *ap; 36631727Swollman{ 36776578Sjlemon if (ap->a_events & ~POLLSTANDARD) 36883366Sjulian return (vn_pollrecord(ap->a_vp, ap->a_td, ap->a_events)); 36976578Sjlemon return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)); 37031727Swollman} 37131727Swollman 37230743Sphk/* 37330743Sphk * Stubs to use when there is no locking to be done on the underlying object. 37430743Sphk * A minimal shared lock is necessary to ensure that the underlying object 37530743Sphk * is not revoked while an operation is in progress. So, an active shared 37630743Sphk * count is maintained in an auxillary vnode lock structure. 37730743Sphk */ 37830743Sphkint 37930743Sphkvop_sharedlock(ap) 38030743Sphk struct vop_lock_args /* { 38130743Sphk struct vnode *a_vp; 38230743Sphk int a_flags; 38383366Sjulian struct thread *a_td; 38430743Sphk } */ *ap; 38530743Sphk{ 38630743Sphk /* 38730743Sphk * This code cannot be used until all the non-locking filesystems 38830743Sphk * (notably NFS) are converted to properly lock and release nodes. 38930743Sphk * Also, certain vnode operations change the locking state within 39030743Sphk * the operation (create, mknod, remove, link, rename, mkdir, rmdir, 39130743Sphk * and symlink). Ideally these operations should not change the 39230743Sphk * lock state, but should be changed to let the caller of the 39330743Sphk * function unlock them. Otherwise all intermediate vnode layers 39430743Sphk * (such as union, umapfs, etc) must catch these functions to do 39530743Sphk * the necessary locking at their layer. Note that the inactive 39630743Sphk * and lookup operations also change their lock state, but this 39730743Sphk * cannot be avoided, so these two operations will always need 39830743Sphk * to be handled in intermediate layers. 39930743Sphk */ 40030743Sphk struct vnode *vp = ap->a_vp; 40130743Sphk int vnflags, flags = ap->a_flags; 40230743Sphk 40330743Sphk switch (flags & LK_TYPE_MASK) { 40430743Sphk case LK_DRAIN: 40530743Sphk vnflags = LK_DRAIN; 40630743Sphk break; 40730743Sphk case LK_EXCLUSIVE: 40830743Sphk#ifdef DEBUG_VFS_LOCKS 40930743Sphk /* 41030743Sphk * Normally, we use shared locks here, but that confuses 41130743Sphk * the locking assertions. 41230743Sphk */ 41330743Sphk vnflags = LK_EXCLUSIVE; 41430743Sphk break; 41530743Sphk#endif 41630743Sphk case LK_SHARED: 41730743Sphk vnflags = LK_SHARED; 41830743Sphk break; 41930743Sphk case LK_UPGRADE: 42030743Sphk case LK_EXCLUPGRADE: 42130743Sphk case LK_DOWNGRADE: 42230743Sphk return (0); 42330743Sphk case LK_RELEASE: 42430743Sphk default: 42530743Sphk panic("vop_sharedlock: bad operation %d", flags & LK_TYPE_MASK); 42630743Sphk } 42730743Sphk if (flags & LK_INTERLOCK) 42830743Sphk vnflags |= LK_INTERLOCK; 42942900Seivind#ifndef DEBUG_LOCKS 43083366Sjulian return (lockmgr(&vp->v_lock, vnflags, &vp->v_interlock, ap->a_td)); 43142900Seivind#else 43283366Sjulian return (debuglockmgr(&vp->v_lock, vnflags, &vp->v_interlock, ap->a_td, 43342900Seivind "vop_sharedlock", vp->filename, vp->line)); 43442900Seivind#endif 43530743Sphk} 43630743Sphk 43730743Sphk/* 43830743Sphk * Stubs to use when there is no locking to be done on the underlying object. 43930743Sphk * A minimal shared lock is necessary to ensure that the underlying object 44030743Sphk * is not revoked while an operation is in progress. So, an active shared 44130743Sphk * count is maintained in an auxillary vnode lock structure. 44230743Sphk */ 44330743Sphkint 44430743Sphkvop_nolock(ap) 44530743Sphk struct vop_lock_args /* { 44630743Sphk struct vnode *a_vp; 44730743Sphk int a_flags; 44883366Sjulian struct thread *a_td; 44930743Sphk } */ *ap; 45030743Sphk{ 45130743Sphk#ifdef notyet 45230743Sphk /* 45330743Sphk * This code cannot be used until all the non-locking filesystems 45430743Sphk * (notably NFS) are converted to properly lock and release nodes. 45530743Sphk * Also, certain vnode operations change the locking state within 45630743Sphk * the operation (create, mknod, remove, link, rename, mkdir, rmdir, 45730743Sphk * and symlink). Ideally these operations should not change the 45830743Sphk * lock state, but should be changed to let the caller of the 45930743Sphk * function unlock them. Otherwise all intermediate vnode layers 46030743Sphk * (such as union, umapfs, etc) must catch these functions to do 46130743Sphk * the necessary locking at their layer. Note that the inactive 46230743Sphk * and lookup operations also change their lock state, but this 46330743Sphk * cannot be avoided, so these two operations will always need 46430743Sphk * to be handled in intermediate layers. 46530743Sphk */ 46630743Sphk struct vnode *vp = ap->a_vp; 46730743Sphk int vnflags, flags = ap->a_flags; 46830743Sphk 46930743Sphk switch (flags & LK_TYPE_MASK) { 47030743Sphk case LK_DRAIN: 47130743Sphk vnflags = LK_DRAIN; 47230743Sphk break; 47330743Sphk case LK_EXCLUSIVE: 47430743Sphk case LK_SHARED: 47530743Sphk vnflags = LK_SHARED; 47630743Sphk break; 47730743Sphk case LK_UPGRADE: 47830743Sphk case LK_EXCLUPGRADE: 47930743Sphk case LK_DOWNGRADE: 48030743Sphk return (0); 48130743Sphk case LK_RELEASE: 48230743Sphk default: 48330743Sphk panic("vop_nolock: bad operation %d", flags & LK_TYPE_MASK); 48430743Sphk } 48530743Sphk if (flags & LK_INTERLOCK) 48630743Sphk vnflags |= LK_INTERLOCK; 48783366Sjulian return(lockmgr(&vp->v_lock, vnflags, &vp->v_interlock, ap->a_td)); 48830743Sphk#else /* for now */ 48930743Sphk /* 49030743Sphk * Since we are not using the lock manager, we must clear 49130743Sphk * the interlock here. 49230743Sphk */ 49331263Sbde if (ap->a_flags & LK_INTERLOCK) 49472200Sbmilekic mtx_unlock(&ap->a_vp->v_interlock); 49530743Sphk return (0); 49630743Sphk#endif 49730743Sphk} 49830743Sphk 49930743Sphk/* 50030743Sphk * Do the inverse of vop_nolock, handling the interlock in a compatible way. 50130743Sphk */ 50230743Sphkint 50330743Sphkvop_nounlock(ap) 50430743Sphk struct vop_unlock_args /* { 50530743Sphk struct vnode *a_vp; 50630743Sphk int a_flags; 50783366Sjulian struct thread *a_td; 50830743Sphk } */ *ap; 50930743Sphk{ 51030743Sphk 51166355Sbp /* 51266355Sbp * Since we are not using the lock manager, we must clear 51366355Sbp * the interlock here. 51466355Sbp */ 51566355Sbp if (ap->a_flags & LK_INTERLOCK) 51672200Sbmilekic mtx_unlock(&ap->a_vp->v_interlock); 51766355Sbp return (0); 51830743Sphk} 51930743Sphk 52030743Sphk/* 52130743Sphk * Return whether or not the node is in use. 52230743Sphk */ 52330743Sphkint 52430743Sphkvop_noislocked(ap) 52530743Sphk struct vop_islocked_args /* { 52630743Sphk struct vnode *a_vp; 52783366Sjulian struct thread *a_td; 52830743Sphk } */ *ap; 52930743Sphk{ 53030743Sphk 53166355Sbp return (0); 53230743Sphk} 53330743Sphk 53462976Smckusick/* 53562976Smckusick * Return our mount point, as we will take charge of the writes. 53662976Smckusick */ 53762976Smckusickint 53862976Smckusickvop_stdgetwritemount(ap) 53962976Smckusick struct vop_getwritemount_args /* { 54062976Smckusick struct vnode *a_vp; 54162976Smckusick struct mount **a_mpp; 54262976Smckusick } */ *ap; 54362976Smckusick{ 54462976Smckusick 54562976Smckusick *(ap->a_mpp) = ap->a_vp->v_mount; 54662976Smckusick return (0); 54762976Smckusick} 54862976Smckusick 54991690Seivind/* Create the VM system backing object for this vnode */ 55065770Sbpint 55165770Sbpvop_stdcreatevobject(ap) 55265770Sbp struct vop_createvobject_args /* { 55365770Sbp struct vnode *vp; 55465770Sbp struct ucred *cred; 55583366Sjulian struct thread *td; 55665770Sbp } */ *ap; 55765770Sbp{ 55865770Sbp struct vnode *vp = ap->a_vp; 55965770Sbp struct ucred *cred = ap->a_cred; 56083366Sjulian struct thread *td = ap->a_td; 56165770Sbp struct vattr vat; 56265770Sbp vm_object_t object; 56365770Sbp int error = 0; 56465770Sbp 56579224Sdillon GIANT_REQUIRED; 56679224Sdillon 56765770Sbp if (!vn_isdisk(vp, NULL) && vn_canvmio(vp) == FALSE) 56865770Sbp return (0); 56965770Sbp 57065770Sbpretry: 57165770Sbp if ((object = vp->v_object) == NULL) { 57265770Sbp if (vp->v_type == VREG || vp->v_type == VDIR) { 57383366Sjulian if ((error = VOP_GETATTR(vp, &vat, cred, td)) != 0) 57465770Sbp goto retn; 57565770Sbp object = vnode_pager_alloc(vp, vat.va_size, 0, 0); 57665770Sbp } else if (devsw(vp->v_rdev) != NULL) { 57765770Sbp /* 57865770Sbp * This simply allocates the biggest object possible 57965770Sbp * for a disk vnode. This should be fixed, but doesn't 58065770Sbp * cause any problems (yet). 58165770Sbp */ 58265770Sbp object = vnode_pager_alloc(vp, IDX_TO_OFF(INT_MAX), 0, 0); 58365770Sbp } else { 58465770Sbp goto retn; 58565770Sbp } 58665770Sbp /* 58765770Sbp * Dereference the reference we just created. This assumes 58865770Sbp * that the object is associated with the vp. 58965770Sbp */ 59065770Sbp object->ref_count--; 59165770Sbp vp->v_usecount--; 59265770Sbp } else { 59365770Sbp if (object->flags & OBJ_DEAD) { 59483366Sjulian VOP_UNLOCK(vp, 0, td); 59579224Sdillon tsleep(object, PVM, "vodead", 0); 59683366Sjulian vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); 59765770Sbp goto retry; 59865770Sbp } 59965770Sbp } 60065770Sbp 60165770Sbp KASSERT(vp->v_object != NULL, ("vfs_object_create: NULL object")); 60265770Sbp vp->v_flag |= VOBJBUF; 60365770Sbp 60465770Sbpretn: 60565770Sbp return (error); 60665770Sbp} 60765770Sbp 60891690Seivind/* Destroy the VM system object associated with this vnode */ 60965770Sbpint 61065770Sbpvop_stddestroyvobject(ap) 61165770Sbp struct vop_destroyvobject_args /* { 61265770Sbp struct vnode *vp; 61365770Sbp } */ *ap; 61465770Sbp{ 61565770Sbp struct vnode *vp = ap->a_vp; 61665770Sbp vm_object_t obj = vp->v_object; 61765770Sbp 61879224Sdillon GIANT_REQUIRED; 61979224Sdillon 62065770Sbp if (vp->v_object == NULL) 62165770Sbp return (0); 62265770Sbp 62365770Sbp if (obj->ref_count == 0) { 62465770Sbp /* 62565770Sbp * vclean() may be called twice. The first time 62665770Sbp * removes the primary reference to the object, 62765770Sbp * the second time goes one further and is a 62865770Sbp * special-case to terminate the object. 62985340Sdillon * 63085340Sdillon * don't double-terminate the object 63165770Sbp */ 63285340Sdillon if ((obj->flags & OBJ_DEAD) == 0) 63385340Sdillon vm_object_terminate(obj); 63465770Sbp } else { 63565770Sbp /* 63665770Sbp * Woe to the process that tries to page now :-). 63765770Sbp */ 63865770Sbp vm_pager_deallocate(obj); 63965770Sbp } 64065770Sbp return (0); 64165770Sbp} 64265770Sbp 64385340Sdillon/* 64485340Sdillon * Return the underlying VM object. This routine may be called with or 64585340Sdillon * without the vnode interlock held. If called without, the returned 64685340Sdillon * object is not guarenteed to be valid. The syncer typically gets the 64785340Sdillon * object without holding the interlock in order to quickly test whether 64885340Sdillon * it might be dirty before going heavy-weight. vm_object's use zalloc 64985340Sdillon * and thus stable-storage, so this is safe. 65085340Sdillon */ 65165770Sbpint 65265770Sbpvop_stdgetvobject(ap) 65365770Sbp struct vop_getvobject_args /* { 65465770Sbp struct vnode *vp; 65565770Sbp struct vm_object **objpp; 65665770Sbp } */ *ap; 65765770Sbp{ 65865770Sbp struct vnode *vp = ap->a_vp; 65965770Sbp struct vm_object **objpp = ap->a_objpp; 66065770Sbp 66165770Sbp if (objpp) 66265770Sbp *objpp = vp->v_object; 66365770Sbp return (vp->v_object ? 0 : EINVAL); 66465770Sbp} 66565770Sbp 66691690Seivind/* XXX Needs good comment and VOP_BMAP(9) manpage */ 66776131Sphkint 66876131Sphkvop_stdbmap(ap) 66976131Sphk struct vop_bmap_args /* { 67076131Sphk struct vnode *a_vp; 67176131Sphk daddr_t a_bn; 67276131Sphk struct vnode **a_vpp; 67376131Sphk daddr_t *a_bnp; 67476131Sphk int *a_runp; 67576131Sphk int *a_runb; 67676131Sphk } */ *ap; 67776131Sphk{ 67876131Sphk 67976131Sphk if (ap->a_vpp != NULL) 68076131Sphk *ap->a_vpp = ap->a_vp; 68176131Sphk if (ap->a_bnp != NULL) 68276131Sphk *ap->a_bnp = ap->a_bn * btodb(ap->a_vp->v_mount->mnt_stat.f_iosize); 68376131Sphk if (ap->a_runp != NULL) 68476131Sphk *ap->a_runp = 0; 68576131Sphk if (ap->a_runb != NULL) 68676131Sphk *ap->a_runb = 0; 68776131Sphk return (0); 68876131Sphk} 68976131Sphk 69091690Seivind/* XXX Needs good comment and more info in the manpage (VOP_GETPAGES(9)). */ 69176167Sphkint 69276167Sphkvop_stdgetpages(ap) 69376167Sphk struct vop_getpages_args /* { 69476167Sphk struct vnode *a_vp; 69576167Sphk vm_page_t *a_m; 69676167Sphk int a_count; 69776167Sphk int a_reqpage; 69876167Sphk vm_ooffset_t a_offset; 69976167Sphk } */ *ap; 70076167Sphk{ 70176131Sphk 70276167Sphk return vnode_pager_generic_getpages(ap->a_vp, ap->a_m, 70376167Sphk ap->a_count, ap->a_reqpage); 70476167Sphk} 70576167Sphk 70691690Seivind/* XXX Needs good comment and more info in the manpage (VOP_PUTPAGES(9)). */ 70776319Sphkint 70876167Sphkvop_stdputpages(ap) 70976167Sphk struct vop_putpages_args /* { 71076167Sphk struct vnode *a_vp; 71176167Sphk vm_page_t *a_m; 71276167Sphk int a_count; 71376167Sphk int a_sync; 71476167Sphk int *a_rtvals; 71576167Sphk vm_ooffset_t a_offset; 71676167Sphk } */ *ap; 71776167Sphk{ 71876167Sphk 71976319Sphk return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count, 72076167Sphk ap->a_sync, ap->a_rtvals); 72176167Sphk} 72276167Sphk 72376167Sphk 72476167Sphk 72551068Salfred/* 72651068Salfred * vfs default ops 72791690Seivind * used to fill the vfs function table to get reasonable default return values. 72851068Salfred */ 72951068Salfredint 73083366Sjulianvfs_stdmount (mp, path, data, ndp, td) 73151068Salfred struct mount *mp; 73251068Salfred char *path; 73351068Salfred caddr_t data; 73451068Salfred struct nameidata *ndp; 73583366Sjulian struct thread *td; 73651068Salfred{ 73751068Salfred return (0); 73851068Salfred} 73951068Salfred 74091690Seivindint 74183366Sjulianvfs_stdunmount (mp, mntflags, td) 74251068Salfred struct mount *mp; 74351068Salfred int mntflags; 74483366Sjulian struct thread *td; 74551068Salfred{ 74651068Salfred return (0); 74751068Salfred} 74851068Salfred 74991690Seivindint 75051068Salfredvfs_stdroot (mp, vpp) 75151068Salfred struct mount *mp; 75251068Salfred struct vnode **vpp; 75351068Salfred{ 75451068Salfred return (EOPNOTSUPP); 75551068Salfred} 75651068Salfred 75791690Seivindint 75883366Sjulianvfs_stdstatfs (mp, sbp, td) 75951068Salfred struct mount *mp; 76051068Salfred struct statfs *sbp; 76183366Sjulian struct thread *td; 76251068Salfred{ 76351068Salfred return (EOPNOTSUPP); 76451068Salfred} 76551068Salfred 76651068Salfredint 76751068Salfredvfs_stdvptofh (vp, fhp) 76851068Salfred struct vnode *vp; 76951068Salfred struct fid *fhp; 77051068Salfred{ 77151068Salfred return (EOPNOTSUPP); 77251068Salfred} 77351068Salfred 77491690Seivindint 77583366Sjulianvfs_stdstart (mp, flags, td) 77651068Salfred struct mount *mp; 77751068Salfred int flags; 77883366Sjulian struct thread *td; 77951068Salfred{ 78051068Salfred return (0); 78151068Salfred} 78251068Salfred 78351068Salfredint 78483366Sjulianvfs_stdquotactl (mp, cmds, uid, arg, td) 78551068Salfred struct mount *mp; 78651068Salfred int cmds; 78751068Salfred uid_t uid; 78851068Salfred caddr_t arg; 78983366Sjulian struct thread *td; 79051068Salfred{ 79151068Salfred return (EOPNOTSUPP); 79251068Salfred} 79351068Salfred 79451068Salfredint 79583366Sjulianvfs_stdsync (mp, waitfor, cred, td) 79651068Salfred struct mount *mp; 79751068Salfred int waitfor; 79851068Salfred struct ucred *cred; 79983366Sjulian struct thread *td; 80051068Salfred{ 80151068Salfred return (0); 80251068Salfred} 80351068Salfred 80451068Salfredint 80551068Salfredvfs_stdvget (mp, ino, vpp) 80651068Salfred struct mount *mp; 80751068Salfred ino_t ino; 80851068Salfred struct vnode **vpp; 80951068Salfred{ 81051068Salfred return (EOPNOTSUPP); 81151068Salfred} 81251068Salfred 81351068Salfredint 81451138Salfredvfs_stdfhtovp (mp, fhp, vpp) 81551068Salfred struct mount *mp; 81651068Salfred struct fid *fhp; 81751138Salfred struct vnode **vpp; 81851138Salfred{ 81951138Salfred return (EOPNOTSUPP); 82051138Salfred} 82151138Salfred 82251068Salfredint 82351068Salfredvfs_stdinit (vfsp) 82451068Salfred struct vfsconf *vfsp; 82551068Salfred{ 82651068Salfred return (0); 82751068Salfred} 82851068Salfred 82951068Salfredint 83051068Salfredvfs_stduninit (vfsp) 83151068Salfred struct vfsconf *vfsp; 83251068Salfred{ 83351068Salfred return(0); 83451068Salfred} 83551068Salfred 83654803Srwatsonint 83783366Sjulianvfs_stdextattrctl(mp, cmd, filename_vp, attrnamespace, attrname, td) 83854803Srwatson struct mount *mp; 83954803Srwatson int cmd; 84074273Srwatson struct vnode *filename_vp; 84174437Srwatson int attrnamespace; 84256272Srwatson const char *attrname; 84383366Sjulian struct thread *td; 84454803Srwatson{ 84554803Srwatson return(EOPNOTSUPP); 84654803Srwatson} 84754803Srwatson 84851068Salfred/* end of vfs default ops */ 849