2007-03-04 08:59:00 +03:00
|
|
|
/* $NetBSD: mfs_vnops.c,v 1.44 2007/03/04 06:03:46 christos Exp $ */
|
1994-06-29 10:39:25 +04:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1989, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-06-08 15:41:58 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1998-03-01 05:20:01 +03:00
|
|
|
* @(#)mfs_vnops.c 8.11 (Berkeley) 5/22/95
|
1994-06-08 15:41:58 +04:00
|
|
|
*/
|
|
|
|
|
2001-11-08 05:39:06 +03:00
|
|
|
#include <sys/cdefs.h>
|
2007-03-04 08:59:00 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: mfs_vnops.c,v 1.44 2007/03/04 06:03:46 christos Exp $");
|
2001-11-08 05:39:06 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/buf.h>
|
2004-10-28 11:07:35 +04:00
|
|
|
#include <sys/bufq.h>
|
1994-06-08 15:41:58 +04:00
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
1996-09-02 03:47:48 +04:00
|
|
|
#include <miscfs/genfs/genfs.h>
|
1994-06-08 15:41:58 +04:00
|
|
|
#include <miscfs/specfs/specdev.h>
|
|
|
|
|
2000-05-20 00:42:20 +04:00
|
|
|
#include <machine/vmparam.h>
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
#include <ufs/mfs/mfsnode.h>
|
|
|
|
#include <ufs/mfs/mfs_extern.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* mfs vnode operations.
|
|
|
|
*/
|
2005-08-31 02:01:12 +04:00
|
|
|
int (**mfs_vnodeop_p)(void *);
|
2001-01-22 15:17:35 +03:00
|
|
|
const struct vnodeopv_entry_desc mfs_vnodeop_entries[] = {
|
1994-06-08 15:41:58 +04:00
|
|
|
{ &vop_default_desc, vn_default_error },
|
|
|
|
{ &vop_lookup_desc, mfs_lookup }, /* lookup */
|
|
|
|
{ &vop_create_desc, mfs_create }, /* create */
|
|
|
|
{ &vop_mknod_desc, mfs_mknod }, /* mknod */
|
|
|
|
{ &vop_open_desc, mfs_open }, /* open */
|
|
|
|
{ &vop_close_desc, mfs_close }, /* close */
|
|
|
|
{ &vop_access_desc, mfs_access }, /* access */
|
|
|
|
{ &vop_getattr_desc, mfs_getattr }, /* getattr */
|
|
|
|
{ &vop_setattr_desc, mfs_setattr }, /* setattr */
|
|
|
|
{ &vop_read_desc, mfs_read }, /* read */
|
|
|
|
{ &vop_write_desc, mfs_write }, /* write */
|
|
|
|
{ &vop_ioctl_desc, mfs_ioctl }, /* ioctl */
|
1996-09-07 16:40:22 +04:00
|
|
|
{ &vop_poll_desc, mfs_poll }, /* poll */
|
1998-03-01 05:20:01 +03:00
|
|
|
{ &vop_revoke_desc, mfs_revoke }, /* revoke */
|
1994-06-08 15:41:58 +04:00
|
|
|
{ &vop_mmap_desc, mfs_mmap }, /* mmap */
|
|
|
|
{ &vop_fsync_desc, spec_fsync }, /* fsync */
|
|
|
|
{ &vop_seek_desc, mfs_seek }, /* seek */
|
|
|
|
{ &vop_remove_desc, mfs_remove }, /* remove */
|
|
|
|
{ &vop_link_desc, mfs_link }, /* link */
|
|
|
|
{ &vop_rename_desc, mfs_rename }, /* rename */
|
|
|
|
{ &vop_mkdir_desc, mfs_mkdir }, /* mkdir */
|
|
|
|
{ &vop_rmdir_desc, mfs_rmdir }, /* rmdir */
|
|
|
|
{ &vop_symlink_desc, mfs_symlink }, /* symlink */
|
|
|
|
{ &vop_readdir_desc, mfs_readdir }, /* readdir */
|
|
|
|
{ &vop_readlink_desc, mfs_readlink }, /* readlink */
|
|
|
|
{ &vop_abortop_desc, mfs_abortop }, /* abortop */
|
|
|
|
{ &vop_inactive_desc, mfs_inactive }, /* inactive */
|
|
|
|
{ &vop_reclaim_desc, mfs_reclaim }, /* reclaim */
|
|
|
|
{ &vop_lock_desc, mfs_lock }, /* lock */
|
|
|
|
{ &vop_unlock_desc, mfs_unlock }, /* unlock */
|
|
|
|
{ &vop_bmap_desc, mfs_bmap }, /* bmap */
|
|
|
|
{ &vop_strategy_desc, mfs_strategy }, /* strategy */
|
|
|
|
{ &vop_print_desc, mfs_print }, /* print */
|
|
|
|
{ &vop_islocked_desc, mfs_islocked }, /* islocked */
|
|
|
|
{ &vop_pathconf_desc, mfs_pathconf }, /* pathconf */
|
|
|
|
{ &vop_advlock_desc, mfs_advlock }, /* advlock */
|
|
|
|
{ &vop_bwrite_desc, mfs_bwrite }, /* bwrite */
|
2001-12-06 07:27:40 +03:00
|
|
|
{ &vop_putpages_desc, mfs_putpages }, /* putpages */
|
|
|
|
{ NULL, NULL }
|
1994-06-08 15:41:58 +04:00
|
|
|
};
|
2001-01-22 15:17:35 +03:00
|
|
|
const struct vnodeopv_desc mfs_vnodeop_opv_desc =
|
1994-06-08 15:41:58 +04:00
|
|
|
{ &mfs_vnodeop_p, mfs_vnodeop_entries };
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Vnode Operations.
|
|
|
|
*
|
|
|
|
* Open called to allow memory filesystem to initialize and
|
|
|
|
* validate before actual IO. Record our process identifier
|
|
|
|
* so we can tell when we are doing I/O to ourself.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2005-08-31 02:01:12 +04:00
|
|
|
mfs_open(void *v)
|
1996-02-10 01:31:27 +03:00
|
|
|
{
|
1994-06-08 15:41:58 +04:00
|
|
|
struct vop_open_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_mode;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t a_cred;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *a_l;
|
1996-02-10 01:31:27 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
if (ap->a_vp->v_type != VBLK) {
|
|
|
|
panic("mfs_ioctl not VBLK");
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pass I/O requests to the memory filesystem process.
|
|
|
|
*/
|
|
|
|
int
|
2005-08-31 02:01:12 +04:00
|
|
|
mfs_strategy(void *v)
|
1996-02-10 01:31:27 +03:00
|
|
|
{
|
1994-06-08 15:41:58 +04:00
|
|
|
struct vop_strategy_args /* {
|
2004-01-26 13:02:31 +03:00
|
|
|
struct vnode *a_vp;
|
1994-06-08 15:41:58 +04:00
|
|
|
struct buf *a_bp;
|
1996-02-10 01:31:27 +03:00
|
|
|
} */ *ap = v;
|
2004-01-26 13:02:31 +03:00
|
|
|
struct vnode *vp = ap->a_vp;
|
2000-03-30 16:41:09 +04:00
|
|
|
struct buf *bp = ap->a_bp;
|
|
|
|
struct mfsnode *mfsp;
|
2000-05-20 00:42:20 +04:00
|
|
|
struct proc *p = curproc; /* XXX */
|
1994-06-08 15:41:58 +04:00
|
|
|
|
2004-01-26 13:02:31 +03:00
|
|
|
if (vp->v_type != VBLK || vp->v_usecount == 0)
|
1994-06-08 15:41:58 +04:00
|
|
|
panic("mfs_strategy: bad dev");
|
|
|
|
mfsp = VTOMFS(vp);
|
2000-05-20 00:42:20 +04:00
|
|
|
/* check for mini-root access */
|
2000-05-16 21:20:23 +04:00
|
|
|
if (mfsp->mfs_proc == NULL) {
|
2007-03-04 08:59:00 +03:00
|
|
|
void *base;
|
2000-05-20 00:42:20 +04:00
|
|
|
|
2007-03-04 08:59:00 +03:00
|
|
|
base = (char *)mfsp->mfs_baseoff + (bp->b_blkno << DEV_BSHIFT);
|
1994-06-08 15:41:58 +04:00
|
|
|
if (bp->b_flags & B_READ)
|
1998-08-10 00:15:38 +04:00
|
|
|
memcpy(bp->b_data, base, bp->b_bcount);
|
1994-06-08 15:41:58 +04:00
|
|
|
else
|
1998-08-10 00:15:38 +04:00
|
|
|
memcpy(base, bp->b_data, bp->b_bcount);
|
2000-10-09 22:07:06 +04:00
|
|
|
bp->b_resid = 0;
|
2000-05-20 00:42:20 +04:00
|
|
|
biodone(bp);
|
|
|
|
} else if (mfsp->mfs_proc == p) {
|
|
|
|
mfs_doio(bp, mfsp->mfs_baseoff);
|
2000-06-11 07:09:55 +04:00
|
|
|
} else if (doing_shutdown) {
|
2005-02-27 01:31:44 +03:00
|
|
|
/*
|
2000-06-11 07:09:55 +04:00
|
|
|
* bitbucket I/O during shutdown.
|
|
|
|
* Note that reads should *not* happen here, but..
|
|
|
|
*/
|
|
|
|
if (bp->b_flags & B_READ)
|
|
|
|
printf("warning: mfs read during shutdown\n");
|
2000-10-09 22:07:06 +04:00
|
|
|
bp->b_resid = 0;
|
2000-06-11 07:09:55 +04:00
|
|
|
biodone(bp);
|
1994-06-08 15:41:58 +04:00
|
|
|
} else {
|
2005-10-15 21:29:10 +04:00
|
|
|
BUFQ_PUT(mfsp->mfs_buflist, bp);
|
2007-03-04 08:59:00 +03:00
|
|
|
wakeup((void *)vp);
|
2000-05-16 21:20:23 +04:00
|
|
|
}
|
2000-05-20 00:42:20 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Memory file system I/O.
|
|
|
|
*
|
|
|
|
* Trivial on the HP since buffer has already been mapping into KVA space.
|
|
|
|
*/
|
|
|
|
void
|
2007-03-04 08:59:00 +03:00
|
|
|
mfs_doio(struct buf *bp, void *base)
|
2000-05-20 00:42:20 +04:00
|
|
|
{
|
2007-03-04 08:59:00 +03:00
|
|
|
base = (char *)base + (bp->b_blkno << DEV_BSHIFT);
|
2000-05-20 00:42:20 +04:00
|
|
|
if (bp->b_flags & B_READ)
|
|
|
|
bp->b_error = copyin(base, bp->b_data, bp->b_bcount);
|
|
|
|
else
|
|
|
|
bp->b_error = copyout(bp->b_data, base, bp->b_bcount);
|
|
|
|
if (bp->b_error)
|
1994-06-08 15:41:58 +04:00
|
|
|
bp->b_flags |= B_ERROR;
|
1999-03-15 03:18:24 +03:00
|
|
|
else
|
|
|
|
bp->b_resid = 0;
|
1994-06-08 15:41:58 +04:00
|
|
|
biodone(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a noop, simply returning what one has been given.
|
|
|
|
*/
|
|
|
|
int
|
2005-08-31 02:01:12 +04:00
|
|
|
mfs_bmap(void *v)
|
1996-02-10 01:31:27 +03:00
|
|
|
{
|
1994-06-08 15:41:58 +04:00
|
|
|
struct vop_bmap_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
daddr_t a_bn;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
daddr_t *a_bnp;
|
|
|
|
int *a_runp;
|
1996-02-10 01:31:27 +03:00
|
|
|
} */ *ap = v;
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
if (ap->a_vpp != NULL)
|
|
|
|
*ap->a_vpp = ap->a_vp;
|
|
|
|
if (ap->a_bnp != NULL)
|
|
|
|
*ap->a_bnp = ap->a_bn;
|
1998-03-01 05:20:01 +03:00
|
|
|
if (ap->a_runp != NULL)
|
|
|
|
*ap->a_runp = 0;
|
1994-06-08 15:41:58 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Memory filesystem close routine
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2005-08-31 02:01:12 +04:00
|
|
|
mfs_close(void *v)
|
1996-02-10 01:31:27 +03:00
|
|
|
{
|
1994-06-08 15:41:58 +04:00
|
|
|
struct vop_close_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_fflag;
|
2006-05-15 01:31:52 +04:00
|
|
|
kauth_cred_t a_cred;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *a_l;
|
1996-02-10 01:31:27 +03:00
|
|
|
} */ *ap = v;
|
2000-03-30 16:41:09 +04:00
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct mfsnode *mfsp = VTOMFS(vp);
|
2000-05-20 00:42:20 +04:00
|
|
|
struct buf *bp;
|
1994-06-08 15:41:58 +04:00
|
|
|
int error;
|
|
|
|
|
2000-05-20 00:42:20 +04:00
|
|
|
/*
|
|
|
|
* Finish any pending I/O requests.
|
|
|
|
*/
|
2005-10-15 21:29:10 +04:00
|
|
|
while ((bp = BUFQ_GET(mfsp->mfs_buflist)) != NULL) {
|
2000-05-20 00:42:20 +04:00
|
|
|
mfs_doio(bp, mfsp->mfs_baseoff);
|
2007-03-04 08:59:00 +03:00
|
|
|
wakeup((void *)bp);
|
2000-05-20 00:42:20 +04:00
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* On last close of a memory filesystem
|
|
|
|
* we must invalidate any in core blocks, so that
|
|
|
|
* we can, free up its vnode.
|
|
|
|
*/
|
2005-12-11 15:16:03 +03:00
|
|
|
if ((error = vinvalbuf(vp, V_SAVE, ap->a_cred, ap->a_l, 0, 0)) != 0)
|
1994-06-08 15:41:58 +04:00
|
|
|
return (error);
|
|
|
|
/*
|
|
|
|
* There should be no way to have any more uses of this
|
|
|
|
* vnode, so if we find any other uses, it is a panic.
|
|
|
|
*/
|
|
|
|
if (vp->v_usecount > 1)
|
2000-11-27 11:39:39 +03:00
|
|
|
printf("mfs_close: ref count %d > 1\n", vp->v_usecount);
|
2005-10-15 21:29:10 +04:00
|
|
|
if (vp->v_usecount > 1 || BUFQ_PEEK(mfsp->mfs_buflist) != NULL)
|
1994-06-08 15:41:58 +04:00
|
|
|
panic("mfs_close");
|
|
|
|
/*
|
|
|
|
* Send a request to the filesystem server to exit.
|
|
|
|
*/
|
2002-07-19 20:26:01 +04:00
|
|
|
mfsp->mfs_shutdown = 1;
|
2007-03-04 08:59:00 +03:00
|
|
|
wakeup((void *)vp);
|
1994-06-08 15:41:58 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Memory filesystem inactive routine
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2005-08-31 02:01:12 +04:00
|
|
|
mfs_inactive(void *v)
|
1996-02-10 01:31:27 +03:00
|
|
|
{
|
1994-06-08 15:41:58 +04:00
|
|
|
struct vop_inactive_args /* {
|
|
|
|
struct vnode *a_vp;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *a_l;
|
1996-02-10 01:31:27 +03:00
|
|
|
} */ *ap = v;
|
1998-03-01 05:20:01 +03:00
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct mfsnode *mfsp = VTOMFS(vp);
|
1994-06-08 15:41:58 +04:00
|
|
|
|
2005-10-15 21:29:10 +04:00
|
|
|
if (BUFQ_PEEK(mfsp->mfs_buflist) != NULL)
|
1996-03-17 05:16:18 +03:00
|
|
|
panic("mfs_inactive: not inactive (mfs_buflist %p)",
|
2005-10-15 21:29:10 +04:00
|
|
|
BUFQ_PEEK(mfsp->mfs_buflist));
|
1998-03-01 05:20:01 +03:00
|
|
|
VOP_UNLOCK(vp, 0);
|
1994-06-08 15:41:58 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reclaim a memory filesystem devvp so that it can be reused.
|
|
|
|
*/
|
|
|
|
int
|
2005-08-31 02:01:12 +04:00
|
|
|
mfs_reclaim(void *v)
|
1996-02-10 01:31:27 +03:00
|
|
|
{
|
1994-06-08 15:41:58 +04:00
|
|
|
struct vop_reclaim_args /* {
|
|
|
|
struct vnode *a_vp;
|
1996-02-10 01:31:27 +03:00
|
|
|
} */ *ap = v;
|
2000-03-30 16:41:09 +04:00
|
|
|
struct vnode *vp = ap->a_vp;
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
FREE(vp->v_data, M_MFSNODE);
|
|
|
|
vp->v_data = NULL;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Print out the contents of an mfsnode.
|
|
|
|
*/
|
|
|
|
int
|
2005-08-31 02:01:12 +04:00
|
|
|
mfs_print(void *v)
|
1996-02-10 01:31:27 +03:00
|
|
|
{
|
1994-06-08 15:41:58 +04:00
|
|
|
struct vop_print_args /* {
|
|
|
|
struct vnode *a_vp;
|
1996-02-10 01:31:27 +03:00
|
|
|
} */ *ap = v;
|
2000-03-30 16:41:09 +04:00
|
|
|
struct mfsnode *mfsp = VTOMFS(ap->a_vp);
|
1994-06-08 15:41:58 +04:00
|
|
|
|
2000-05-16 04:24:08 +04:00
|
|
|
printf("tag VT_MFS, pid %d, base %p, size %ld\n",
|
|
|
|
(mfsp->mfs_proc != NULL) ? mfsp->mfs_proc->p_pid : 0,
|
1996-03-17 05:16:18 +03:00
|
|
|
mfsp->mfs_baseoff, mfsp->mfs_size);
|
1994-06-08 15:41:58 +04:00
|
|
|
return (0);
|
|
|
|
}
|