vfs_default.c revision 101308
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 101308 2002-08-04 10:29:36Z jeff $ 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 6792723Salfredstatic int vop_nolookup(struct vop_lookup_args *); 6892723Salfredstatic int vop_nostrategy(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 }, 8276131Sphk { &vop_bmap_desc, (vop_t *) vop_stdbmap }, 8330492Sphk { &vop_close_desc, (vop_t *) vop_null }, 8465770Sbp { &vop_createvobject_desc, (vop_t *) vop_stdcreatevobject }, 8565770Sbp { &vop_destroyvobject_desc, (vop_t *) vop_stddestroyvobject }, 8630492Sphk { &vop_fsync_desc, (vop_t *) vop_null }, 8776167Sphk { &vop_getpages_desc, (vop_t *) vop_stdgetpages }, 8865770Sbp { &vop_getvobject_desc, (vop_t *) vop_stdgetvobject }, 8964819Sphk { &vop_inactive_desc, (vop_t *) vop_stdinactive }, 9030492Sphk { &vop_ioctl_desc, (vop_t *) vop_enotty }, 91100739Sjeff { &vop_islocked_desc, (vop_t *) vop_stdislocked }, 9230739Sphk { &vop_lease_desc, (vop_t *) vop_null }, 93100739Sjeff { &vop_lock_desc, (vop_t *) vop_stdlock }, 9472594Sbde { &vop_lookup_desc, (vop_t *) vop_nolookup }, 9530492Sphk { &vop_open_desc, (vop_t *) vop_null }, 9630492Sphk { &vop_pathconf_desc, (vop_t *) vop_einval }, 9776167Sphk { &vop_putpages_desc, (vop_t *) vop_stdputpages }, 9830489Sphk { &vop_poll_desc, (vop_t *) vop_nopoll }, 9930492Sphk { &vop_readlink_desc, (vop_t *) vop_einval }, 10030489Sphk { &vop_revoke_desc, (vop_t *) vop_revoke }, 10130489Sphk { &vop_strategy_desc, (vop_t *) vop_nostrategy }, 102100739Sjeff { &vop_unlock_desc, (vop_t *) vop_stdunlock }, 10330489Sphk { NULL, NULL } 10430489Sphk}; 10530489Sphk 10630489Sphkstatic struct vnodeopv_desc default_vnodeop_opv_desc = 10730489Sphk { &default_vnodeop_p, default_vnodeop_entries }; 10830489Sphk 10930489SphkVNODEOP_SET(default_vnodeop_opv_desc); 11030489Sphk 11191690Seivind/* 11291690Seivind * Series of placeholder functions for various error returns for 11391690Seivind * VOPs. 11491690Seivind */ 11591690Seivind 11630489Sphkint 11730492Sphkvop_eopnotsupp(struct vop_generic_args *ap) 11830489Sphk{ 11930489Sphk /* 12030492Sphk printf("vop_notsupp[%s]\n", ap->a_desc->vdesc_name); 12130489Sphk */ 12230489Sphk 12330489Sphk return (EOPNOTSUPP); 12430489Sphk} 12530489Sphk 12630489Sphkint 12730492Sphkvop_ebadf(struct vop_generic_args *ap) 12830489Sphk{ 12930489Sphk 13030492Sphk return (EBADF); 13130492Sphk} 13230492Sphk 13330492Sphkint 13430492Sphkvop_enotty(struct vop_generic_args *ap) 13530492Sphk{ 13630492Sphk 13730492Sphk return (ENOTTY); 13830492Sphk} 13930492Sphk 14030492Sphkint 14130492Sphkvop_einval(struct vop_generic_args *ap) 14230492Sphk{ 14330492Sphk 14430492Sphk return (EINVAL); 14530492Sphk} 14630492Sphk 14730492Sphkint 14830492Sphkvop_null(struct vop_generic_args *ap) 14930492Sphk{ 15030492Sphk 15130492Sphk return (0); 15230492Sphk} 15330492Sphk 15491690Seivind/* 15591690Seivind * Used to make a defined VOP fall back to the default VOP. 15691690Seivind */ 15730492Sphkint 15830492Sphkvop_defaultop(struct vop_generic_args *ap) 15930492Sphk{ 16030492Sphk 16130489Sphk return (VOCALL(default_vnodeop_p, ap->a_desc->vdesc_offset, ap)); 16230489Sphk} 16330489Sphk 16491690Seivind/* 16591690Seivind * Helper function to panic on some bad VOPs in some filesystems. 16691690Seivind */ 16741056Speterint 16841056Spetervop_panic(struct vop_generic_args *ap) 16941056Speter{ 17041056Speter 17172594Sbde panic("filesystem goof: vop_panic[%s]", ap->a_desc->vdesc_name); 17241056Speter} 17341056Speter 17491690Seivind/* 17591690Seivind * vop_std<something> and vop_no<something> are default functions for use by 17691690Seivind * filesystems that need the "default reasonable" implementation for a 17791690Seivind * particular operation. 17891690Seivind * 17991690Seivind * The documentation for the operations they implement exists (if it exists) 18091690Seivind * in the VOP_<SOMETHING>(9) manpage (all uppercase). 18191690Seivind */ 18291690Seivind 18391690Seivind/* 18491690Seivind * Default vop for filesystems that do not support name lookup 18591690Seivind */ 18672594Sbdestatic int 18772594Sbdevop_nolookup(ap) 18872594Sbde struct vop_lookup_args /* { 18972594Sbde struct vnode *a_dvp; 19072594Sbde struct vnode **a_vpp; 19172594Sbde struct componentname *a_cnp; 19272594Sbde } */ *ap; 19372594Sbde{ 19472594Sbde 19572594Sbde *ap->a_vpp = NULL; 19672594Sbde return (ENOTDIR); 19772594Sbde} 19872594Sbde 19946349Salc/* 20046349Salc * vop_nostrategy: 20146349Salc * 20246349Salc * Strategy routine for VFS devices that have none. 20346349Salc * 20458934Sphk * BIO_ERROR and B_INVAL must be cleared prior to calling any strategy 20558345Sphk * routine. Typically this is done for a BIO_READ strategy call. 20658345Sphk * Typically B_INVAL is assumed to already be clear prior to a write 20758345Sphk * and should not be cleared manually unless you just made the buffer 20858934Sphk * invalid. BIO_ERROR should be cleared either way. 20946349Salc */ 21046349Salc 21130489Sphkstatic int 21230489Sphkvop_nostrategy (struct vop_strategy_args *ap) 21330489Sphk{ 21430489Sphk printf("No strategy for buffer at %p\n", ap->a_bp); 21537384Sjulian vprint("", ap->a_vp); 21630489Sphk vprint("", ap->a_bp->b_vp); 21758934Sphk ap->a_bp->b_ioflags |= BIO_ERROR; 21830489Sphk ap->a_bp->b_error = EOPNOTSUPP; 21959249Sphk bufdone(ap->a_bp); 22030489Sphk return (EOPNOTSUPP); 22130489Sphk} 22230492Sphk 22391690Seivind/* 22491690Seivind * vop_stdpathconf: 22591690Seivind * 22691690Seivind * Standard implementation of POSIX pathconf, to get information about limits 22791690Seivind * for a filesystem. 22891690Seivind * Override per filesystem for the case where the filesystem has smaller 22991690Seivind * limits. 23091690Seivind */ 23130492Sphkint 23230492Sphkvop_stdpathconf(ap) 23330492Sphk struct vop_pathconf_args /* { 23430492Sphk struct vnode *a_vp; 23530492Sphk int a_name; 23630492Sphk int *a_retval; 23730492Sphk } */ *ap; 23830492Sphk{ 23930492Sphk 24030492Sphk switch (ap->a_name) { 24130492Sphk case _PC_LINK_MAX: 24230492Sphk *ap->a_retval = LINK_MAX; 24330492Sphk return (0); 24430492Sphk case _PC_MAX_CANON: 24530492Sphk *ap->a_retval = MAX_CANON; 24630492Sphk return (0); 24730492Sphk case _PC_MAX_INPUT: 24830492Sphk *ap->a_retval = MAX_INPUT; 24930492Sphk return (0); 25030492Sphk case _PC_PIPE_BUF: 25130492Sphk *ap->a_retval = PIPE_BUF; 25230492Sphk return (0); 25330492Sphk case _PC_CHOWN_RESTRICTED: 25430492Sphk *ap->a_retval = 1; 25530492Sphk return (0); 25630492Sphk case _PC_VDISABLE: 25730492Sphk *ap->a_retval = _POSIX_VDISABLE; 25830492Sphk return (0); 25930492Sphk default: 26030492Sphk return (EINVAL); 26130492Sphk } 26230492Sphk /* NOTREACHED */ 26330492Sphk} 26430513Sphk 26530513Sphk/* 26630513Sphk * Standard lock, unlock and islocked functions. 26730513Sphk */ 26830513Sphkint 26930513Sphkvop_stdlock(ap) 27030513Sphk struct vop_lock_args /* { 27130513Sphk struct vnode *a_vp; 27230513Sphk int a_flags; 27383366Sjulian struct thread *a_td; 27430513Sphk } */ *ap; 27530513Sphk{ 27666355Sbp struct vnode *vp = ap->a_vp; 27730513Sphk 27842900Seivind#ifndef DEBUG_LOCKS 27983366Sjulian return (lockmgr(&vp->v_lock, ap->a_flags, &vp->v_interlock, ap->a_td)); 28042900Seivind#else 28166355Sbp return (debuglockmgr(&vp->v_lock, ap->a_flags, &vp->v_interlock, 28283366Sjulian ap->a_td, "vop_stdlock", vp->filename, vp->line)); 28342900Seivind#endif 28430513Sphk} 28530513Sphk 28691690Seivind/* See above. */ 28730513Sphkint 28830513Sphkvop_stdunlock(ap) 28930513Sphk struct vop_unlock_args /* { 29030513Sphk struct vnode *a_vp; 29130513Sphk int a_flags; 29283366Sjulian struct thread *a_td; 29330513Sphk } */ *ap; 29430513Sphk{ 29566355Sbp struct vnode *vp = ap->a_vp; 29630513Sphk 29766355Sbp return (lockmgr(&vp->v_lock, ap->a_flags | LK_RELEASE, &vp->v_interlock, 29883366Sjulian ap->a_td)); 29930513Sphk} 30030513Sphk 30191690Seivind/* See above. */ 30230513Sphkint 30330513Sphkvop_stdislocked(ap) 30430513Sphk struct vop_islocked_args /* { 30530513Sphk struct vnode *a_vp; 30683366Sjulian struct thread *a_td; 30730513Sphk } */ *ap; 30830513Sphk{ 30930513Sphk 31083366Sjulian return (lockstatus(&ap->a_vp->v_lock, ap->a_td)); 31130513Sphk} 31230513Sphk 31391690Seivind/* Mark the vnode inactive */ 31464819Sphkint 31564819Sphkvop_stdinactive(ap) 31664819Sphk struct vop_inactive_args /* { 31764819Sphk struct vnode *a_vp; 31883366Sjulian struct thread *a_td; 31964819Sphk } */ *ap; 32064819Sphk{ 32164819Sphk 32283366Sjulian VOP_UNLOCK(ap->a_vp, 0, ap->a_td); 32364819Sphk return (0); 32464819Sphk} 32564819Sphk 32630743Sphk/* 32730743Sphk * Return true for select/poll. 32830743Sphk */ 32930743Sphkint 33030743Sphkvop_nopoll(ap) 33130743Sphk struct vop_poll_args /* { 33230743Sphk struct vnode *a_vp; 33330743Sphk int a_events; 33430743Sphk struct ucred *a_cred; 33583366Sjulian struct thread *a_td; 33630743Sphk } */ *ap; 33730743Sphk{ 33830743Sphk /* 33931727Swollman * Return true for read/write. If the user asked for something 34031727Swollman * special, return POLLNVAL, so that clients have a way of 34131727Swollman * determining reliably whether or not the extended 34231727Swollman * functionality is present without hard-coding knowledge 34331727Swollman * of specific filesystem implementations. 34430743Sphk */ 34531727Swollman if (ap->a_events & ~POLLSTANDARD) 34631727Swollman return (POLLNVAL); 34731727Swollman 34830743Sphk return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)); 34930743Sphk} 35030743Sphk 35131727Swollman/* 35231727Swollman * Implement poll for local filesystems that support it. 35331727Swollman */ 35430743Sphkint 35531727Swollmanvop_stdpoll(ap) 35631727Swollman struct vop_poll_args /* { 35731727Swollman struct vnode *a_vp; 35831727Swollman int a_events; 35931727Swollman struct ucred *a_cred; 36083366Sjulian struct thread *a_td; 36131727Swollman } */ *ap; 36231727Swollman{ 36376578Sjlemon if (ap->a_events & ~POLLSTANDARD) 36483366Sjulian return (vn_pollrecord(ap->a_vp, ap->a_td, ap->a_events)); 36576578Sjlemon return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM)); 36631727Swollman} 36731727Swollman 36830743Sphk/* 36930743Sphk * Stubs to use when there is no locking to be done on the underlying object. 37030743Sphk * A minimal shared lock is necessary to ensure that the underlying object 37130743Sphk * is not revoked while an operation is in progress. So, an active shared 37230743Sphk * count is maintained in an auxillary vnode lock structure. 37330743Sphk */ 37430743Sphkint 37530743Sphkvop_sharedlock(ap) 37630743Sphk struct vop_lock_args /* { 37730743Sphk struct vnode *a_vp; 37830743Sphk int a_flags; 37983366Sjulian struct thread *a_td; 38030743Sphk } */ *ap; 38130743Sphk{ 38230743Sphk /* 38330743Sphk * This code cannot be used until all the non-locking filesystems 38430743Sphk * (notably NFS) are converted to properly lock and release nodes. 38530743Sphk * Also, certain vnode operations change the locking state within 38630743Sphk * the operation (create, mknod, remove, link, rename, mkdir, rmdir, 38730743Sphk * and symlink). Ideally these operations should not change the 38830743Sphk * lock state, but should be changed to let the caller of the 38930743Sphk * function unlock them. Otherwise all intermediate vnode layers 39030743Sphk * (such as union, umapfs, etc) must catch these functions to do 39130743Sphk * the necessary locking at their layer. Note that the inactive 39230743Sphk * and lookup operations also change their lock state, but this 39330743Sphk * cannot be avoided, so these two operations will always need 39430743Sphk * to be handled in intermediate layers. 39530743Sphk */ 39630743Sphk struct vnode *vp = ap->a_vp; 39730743Sphk int vnflags, flags = ap->a_flags; 39830743Sphk 39930743Sphk switch (flags & LK_TYPE_MASK) { 40030743Sphk case LK_DRAIN: 40130743Sphk vnflags = LK_DRAIN; 40230743Sphk break; 40330743Sphk case LK_EXCLUSIVE: 40430743Sphk#ifdef DEBUG_VFS_LOCKS 40530743Sphk /* 40630743Sphk * Normally, we use shared locks here, but that confuses 40730743Sphk * the locking assertions. 40830743Sphk */ 40930743Sphk vnflags = LK_EXCLUSIVE; 41030743Sphk break; 41130743Sphk#endif 41230743Sphk case LK_SHARED: 41330743Sphk vnflags = LK_SHARED; 41430743Sphk break; 41530743Sphk case LK_UPGRADE: 41630743Sphk case LK_EXCLUPGRADE: 41730743Sphk case LK_DOWNGRADE: 41830743Sphk return (0); 41930743Sphk case LK_RELEASE: 42030743Sphk default: 42130743Sphk panic("vop_sharedlock: bad operation %d", flags & LK_TYPE_MASK); 42230743Sphk } 42330743Sphk if (flags & LK_INTERLOCK) 42430743Sphk vnflags |= LK_INTERLOCK; 42542900Seivind#ifndef DEBUG_LOCKS 42683366Sjulian return (lockmgr(&vp->v_lock, vnflags, &vp->v_interlock, ap->a_td)); 42742900Seivind#else 42883366Sjulian return (debuglockmgr(&vp->v_lock, vnflags, &vp->v_interlock, ap->a_td, 42942900Seivind "vop_sharedlock", vp->filename, vp->line)); 43042900Seivind#endif 43130743Sphk} 43230743Sphk 43330743Sphk/* 43430743Sphk * Stubs to use when there is no locking to be done on the underlying object. 43530743Sphk * A minimal shared lock is necessary to ensure that the underlying object 43630743Sphk * is not revoked while an operation is in progress. So, an active shared 43730743Sphk * count is maintained in an auxillary vnode lock structure. 43830743Sphk */ 43930743Sphkint 44030743Sphkvop_nolock(ap) 44130743Sphk struct vop_lock_args /* { 44230743Sphk struct vnode *a_vp; 44330743Sphk int a_flags; 44483366Sjulian struct thread *a_td; 44530743Sphk } */ *ap; 44630743Sphk{ 44730743Sphk#ifdef notyet 44830743Sphk /* 44930743Sphk * This code cannot be used until all the non-locking filesystems 45030743Sphk * (notably NFS) are converted to properly lock and release nodes. 45130743Sphk * Also, certain vnode operations change the locking state within 45230743Sphk * the operation (create, mknod, remove, link, rename, mkdir, rmdir, 45330743Sphk * and symlink). Ideally these operations should not change the 45430743Sphk * lock state, but should be changed to let the caller of the 45530743Sphk * function unlock them. Otherwise all intermediate vnode layers 45630743Sphk * (such as union, umapfs, etc) must catch these functions to do 45730743Sphk * the necessary locking at their layer. Note that the inactive 45830743Sphk * and lookup operations also change their lock state, but this 45930743Sphk * cannot be avoided, so these two operations will always need 46030743Sphk * to be handled in intermediate layers. 46130743Sphk */ 46230743Sphk struct vnode *vp = ap->a_vp; 46330743Sphk int vnflags, flags = ap->a_flags; 46430743Sphk 46530743Sphk switch (flags & LK_TYPE_MASK) { 46630743Sphk case LK_DRAIN: 46730743Sphk vnflags = LK_DRAIN; 46830743Sphk break; 46930743Sphk case LK_EXCLUSIVE: 47030743Sphk case LK_SHARED: 47130743Sphk vnflags = LK_SHARED; 47230743Sphk break; 47330743Sphk case LK_UPGRADE: 47430743Sphk case LK_EXCLUPGRADE: 47530743Sphk case LK_DOWNGRADE: 47630743Sphk return (0); 47730743Sphk case LK_RELEASE: 47830743Sphk default: 47930743Sphk panic("vop_nolock: bad operation %d", flags & LK_TYPE_MASK); 48030743Sphk } 48130743Sphk if (flags & LK_INTERLOCK) 48230743Sphk vnflags |= LK_INTERLOCK; 48383366Sjulian return(lockmgr(&vp->v_lock, vnflags, &vp->v_interlock, ap->a_td)); 48430743Sphk#else /* for now */ 48530743Sphk /* 48630743Sphk * Since we are not using the lock manager, we must clear 48730743Sphk * the interlock here. 48830743Sphk */ 48931263Sbde if (ap->a_flags & LK_INTERLOCK) 49072200Sbmilekic mtx_unlock(&ap->a_vp->v_interlock); 49130743Sphk return (0); 49230743Sphk#endif 49330743Sphk} 49430743Sphk 49530743Sphk/* 49630743Sphk * Do the inverse of vop_nolock, handling the interlock in a compatible way. 49730743Sphk */ 49830743Sphkint 49930743Sphkvop_nounlock(ap) 50030743Sphk struct vop_unlock_args /* { 50130743Sphk struct vnode *a_vp; 50230743Sphk int a_flags; 50383366Sjulian struct thread *a_td; 50430743Sphk } */ *ap; 50530743Sphk{ 50630743Sphk 50766355Sbp /* 50866355Sbp * Since we are not using the lock manager, we must clear 50966355Sbp * the interlock here. 51066355Sbp */ 51166355Sbp if (ap->a_flags & LK_INTERLOCK) 51272200Sbmilekic mtx_unlock(&ap->a_vp->v_interlock); 51366355Sbp return (0); 51430743Sphk} 51530743Sphk 51630743Sphk/* 51730743Sphk * Return whether or not the node is in use. 51830743Sphk */ 51930743Sphkint 52030743Sphkvop_noislocked(ap) 52130743Sphk struct vop_islocked_args /* { 52230743Sphk struct vnode *a_vp; 52383366Sjulian struct thread *a_td; 52430743Sphk } */ *ap; 52530743Sphk{ 52630743Sphk 52766355Sbp return (0); 52830743Sphk} 52930743Sphk 53062976Smckusick/* 53162976Smckusick * Return our mount point, as we will take charge of the writes. 53262976Smckusick */ 53362976Smckusickint 53462976Smckusickvop_stdgetwritemount(ap) 53562976Smckusick struct vop_getwritemount_args /* { 53662976Smckusick struct vnode *a_vp; 53762976Smckusick struct mount **a_mpp; 53862976Smckusick } */ *ap; 53962976Smckusick{ 54062976Smckusick 54162976Smckusick *(ap->a_mpp) = ap->a_vp->v_mount; 54262976Smckusick return (0); 54362976Smckusick} 54462976Smckusick 54591690Seivind/* Create the VM system backing object for this vnode */ 54665770Sbpint 54765770Sbpvop_stdcreatevobject(ap) 54865770Sbp struct vop_createvobject_args /* { 54965770Sbp struct vnode *vp; 55065770Sbp struct ucred *cred; 55183366Sjulian struct thread *td; 55265770Sbp } */ *ap; 55365770Sbp{ 55465770Sbp struct vnode *vp = ap->a_vp; 55565770Sbp struct ucred *cred = ap->a_cred; 55683366Sjulian struct thread *td = ap->a_td; 55765770Sbp struct vattr vat; 55865770Sbp vm_object_t object; 55965770Sbp int error = 0; 56065770Sbp 56179224Sdillon GIANT_REQUIRED; 56279224Sdillon 56365770Sbp if (!vn_isdisk(vp, NULL) && vn_canvmio(vp) == FALSE) 56465770Sbp return (0); 56565770Sbp 56665770Sbpretry: 56765770Sbp if ((object = vp->v_object) == NULL) { 56865770Sbp if (vp->v_type == VREG || vp->v_type == VDIR) { 56983366Sjulian if ((error = VOP_GETATTR(vp, &vat, cred, td)) != 0) 57065770Sbp goto retn; 57165770Sbp object = vnode_pager_alloc(vp, vat.va_size, 0, 0); 57265770Sbp } else if (devsw(vp->v_rdev) != NULL) { 57365770Sbp /* 57465770Sbp * This simply allocates the biggest object possible 57565770Sbp * for a disk vnode. This should be fixed, but doesn't 57665770Sbp * cause any problems (yet). 57765770Sbp */ 57865770Sbp object = vnode_pager_alloc(vp, IDX_TO_OFF(INT_MAX), 0, 0); 57965770Sbp } else { 58065770Sbp goto retn; 58165770Sbp } 58265770Sbp /* 58365770Sbp * Dereference the reference we just created. This assumes 58465770Sbp * that the object is associated with the vp. 58565770Sbp */ 58665770Sbp object->ref_count--; 58765770Sbp vp->v_usecount--; 58865770Sbp } else { 58965770Sbp if (object->flags & OBJ_DEAD) { 59083366Sjulian VOP_UNLOCK(vp, 0, td); 59179224Sdillon tsleep(object, PVM, "vodead", 0); 59283366Sjulian vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); 59365770Sbp goto retry; 59465770Sbp } 59565770Sbp } 59665770Sbp 59765770Sbp KASSERT(vp->v_object != NULL, ("vfs_object_create: NULL object")); 598101308Sjeff vp->v_vflag |= VV_OBJBUF; 59965770Sbp 60065770Sbpretn: 60165770Sbp return (error); 60265770Sbp} 60365770Sbp 60491690Seivind/* Destroy the VM system object associated with this vnode */ 60565770Sbpint 60665770Sbpvop_stddestroyvobject(ap) 60765770Sbp struct vop_destroyvobject_args /* { 60865770Sbp struct vnode *vp; 60965770Sbp } */ *ap; 61065770Sbp{ 61165770Sbp struct vnode *vp = ap->a_vp; 61265770Sbp vm_object_t obj = vp->v_object; 61365770Sbp 61479224Sdillon GIANT_REQUIRED; 61579224Sdillon 61665770Sbp if (vp->v_object == NULL) 61765770Sbp return (0); 61865770Sbp 61965770Sbp if (obj->ref_count == 0) { 62065770Sbp /* 62165770Sbp * vclean() may be called twice. The first time 62265770Sbp * removes the primary reference to the object, 62365770Sbp * the second time goes one further and is a 62465770Sbp * special-case to terminate the object. 62585340Sdillon * 62685340Sdillon * don't double-terminate the object 62765770Sbp */ 62885340Sdillon if ((obj->flags & OBJ_DEAD) == 0) 62985340Sdillon vm_object_terminate(obj); 63065770Sbp } else { 63165770Sbp /* 63265770Sbp * Woe to the process that tries to page now :-). 63365770Sbp */ 63465770Sbp vm_pager_deallocate(obj); 63565770Sbp } 63665770Sbp return (0); 63765770Sbp} 63865770Sbp 63985340Sdillon/* 64085340Sdillon * Return the underlying VM object. This routine may be called with or 64185340Sdillon * without the vnode interlock held. If called without, the returned 64285340Sdillon * object is not guarenteed to be valid. The syncer typically gets the 64385340Sdillon * object without holding the interlock in order to quickly test whether 64485340Sdillon * it might be dirty before going heavy-weight. vm_object's use zalloc 64585340Sdillon * and thus stable-storage, so this is safe. 64685340Sdillon */ 64765770Sbpint 64865770Sbpvop_stdgetvobject(ap) 64965770Sbp struct vop_getvobject_args /* { 65065770Sbp struct vnode *vp; 65165770Sbp struct vm_object **objpp; 65265770Sbp } */ *ap; 65365770Sbp{ 65465770Sbp struct vnode *vp = ap->a_vp; 65565770Sbp struct vm_object **objpp = ap->a_objpp; 65665770Sbp 65765770Sbp if (objpp) 65865770Sbp *objpp = vp->v_object; 65965770Sbp return (vp->v_object ? 0 : EINVAL); 66065770Sbp} 66165770Sbp 66291690Seivind/* XXX Needs good comment and VOP_BMAP(9) manpage */ 66376131Sphkint 66476131Sphkvop_stdbmap(ap) 66576131Sphk struct vop_bmap_args /* { 66676131Sphk struct vnode *a_vp; 66776131Sphk daddr_t a_bn; 66876131Sphk struct vnode **a_vpp; 66976131Sphk daddr_t *a_bnp; 67076131Sphk int *a_runp; 67176131Sphk int *a_runb; 67276131Sphk } */ *ap; 67376131Sphk{ 67476131Sphk 67576131Sphk if (ap->a_vpp != NULL) 67676131Sphk *ap->a_vpp = ap->a_vp; 67776131Sphk if (ap->a_bnp != NULL) 67876131Sphk *ap->a_bnp = ap->a_bn * btodb(ap->a_vp->v_mount->mnt_stat.f_iosize); 67976131Sphk if (ap->a_runp != NULL) 68076131Sphk *ap->a_runp = 0; 68176131Sphk if (ap->a_runb != NULL) 68276131Sphk *ap->a_runb = 0; 68376131Sphk return (0); 68476131Sphk} 68576131Sphk 68691690Seivind/* XXX Needs good comment and more info in the manpage (VOP_GETPAGES(9)). */ 68776167Sphkint 68876167Sphkvop_stdgetpages(ap) 68976167Sphk struct vop_getpages_args /* { 69076167Sphk struct vnode *a_vp; 69176167Sphk vm_page_t *a_m; 69276167Sphk int a_count; 69376167Sphk int a_reqpage; 69476167Sphk vm_ooffset_t a_offset; 69576167Sphk } */ *ap; 69676167Sphk{ 69776131Sphk 69876167Sphk return vnode_pager_generic_getpages(ap->a_vp, ap->a_m, 69976167Sphk ap->a_count, ap->a_reqpage); 70076167Sphk} 70176167Sphk 70291690Seivind/* XXX Needs good comment and more info in the manpage (VOP_PUTPAGES(9)). */ 70376319Sphkint 70476167Sphkvop_stdputpages(ap) 70576167Sphk struct vop_putpages_args /* { 70676167Sphk struct vnode *a_vp; 70776167Sphk vm_page_t *a_m; 70876167Sphk int a_count; 70976167Sphk int a_sync; 71076167Sphk int *a_rtvals; 71176167Sphk vm_ooffset_t a_offset; 71276167Sphk } */ *ap; 71376167Sphk{ 71476167Sphk 71576319Sphk return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count, 71676167Sphk ap->a_sync, ap->a_rtvals); 71776167Sphk} 71876167Sphk 71976167Sphk 72076167Sphk 72151068Salfred/* 72251068Salfred * vfs default ops 72391690Seivind * used to fill the vfs function table to get reasonable default return values. 72451068Salfred */ 72591690Seivindint 72651068Salfredvfs_stdroot (mp, vpp) 72751068Salfred struct mount *mp; 72851068Salfred struct vnode **vpp; 72951068Salfred{ 73051068Salfred return (EOPNOTSUPP); 73151068Salfred} 73251068Salfred 73391690Seivindint 73483366Sjulianvfs_stdstatfs (mp, sbp, td) 73551068Salfred struct mount *mp; 73651068Salfred struct statfs *sbp; 73783366Sjulian struct thread *td; 73851068Salfred{ 73951068Salfred return (EOPNOTSUPP); 74051068Salfred} 74151068Salfred 74251068Salfredint 74351068Salfredvfs_stdvptofh (vp, fhp) 74451068Salfred struct vnode *vp; 74551068Salfred struct fid *fhp; 74651068Salfred{ 74751068Salfred return (EOPNOTSUPP); 74851068Salfred} 74951068Salfred 75091690Seivindint 75183366Sjulianvfs_stdstart (mp, flags, td) 75251068Salfred struct mount *mp; 75351068Salfred int flags; 75483366Sjulian struct thread *td; 75551068Salfred{ 75651068Salfred return (0); 75751068Salfred} 75851068Salfred 75951068Salfredint 76083366Sjulianvfs_stdquotactl (mp, cmds, uid, arg, td) 76151068Salfred struct mount *mp; 76251068Salfred int cmds; 76351068Salfred uid_t uid; 76451068Salfred caddr_t arg; 76583366Sjulian struct thread *td; 76651068Salfred{ 76751068Salfred return (EOPNOTSUPP); 76851068Salfred} 76951068Salfred 77051068Salfredint 77183366Sjulianvfs_stdsync (mp, waitfor, cred, td) 77251068Salfred struct mount *mp; 77351068Salfred int waitfor; 77451068Salfred struct ucred *cred; 77583366Sjulian struct thread *td; 77651068Salfred{ 77751068Salfred return (0); 77851068Salfred} 77951068Salfred 78051068Salfredint 78192462Smckusickvfs_stdvget (mp, ino, flags, vpp) 78251068Salfred struct mount *mp; 78351068Salfred ino_t ino; 78492462Smckusick int flags; 78551068Salfred struct vnode **vpp; 78651068Salfred{ 78751068Salfred return (EOPNOTSUPP); 78851068Salfred} 78951068Salfred 79051068Salfredint 79151138Salfredvfs_stdfhtovp (mp, fhp, vpp) 79251068Salfred struct mount *mp; 79351068Salfred struct fid *fhp; 79451138Salfred struct vnode **vpp; 79551138Salfred{ 79651138Salfred return (EOPNOTSUPP); 79751138Salfred} 79851138Salfred 79951068Salfredint 80051068Salfredvfs_stdinit (vfsp) 80151068Salfred struct vfsconf *vfsp; 80251068Salfred{ 80351068Salfred return (0); 80451068Salfred} 80551068Salfred 80651068Salfredint 80751068Salfredvfs_stduninit (vfsp) 80851068Salfred struct vfsconf *vfsp; 80951068Salfred{ 81051068Salfred return(0); 81151068Salfred} 81251068Salfred 81354803Srwatsonint 81483366Sjulianvfs_stdextattrctl(mp, cmd, filename_vp, attrnamespace, attrname, td) 81554803Srwatson struct mount *mp; 81654803Srwatson int cmd; 81774273Srwatson struct vnode *filename_vp; 81874437Srwatson int attrnamespace; 81956272Srwatson const char *attrname; 82083366Sjulian struct thread *td; 82154803Srwatson{ 82254803Srwatson return(EOPNOTSUPP); 82354803Srwatson} 82454803Srwatson 82551068Salfred/* end of vfs default ops */ 826