Remove MFS from the kernel.
This commit is contained in:
parent
49b07961a9
commit
870b4959b7
@ -1,51 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1991, 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* 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.
|
||||
*
|
||||
* @(#)mfs_extern.h 8.4 (Berkeley) 3/30/95
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _UFS_MFS_MFS_EXTERN_H_
|
||||
#define _UFS_MFS_MFS_EXTERN_H_
|
||||
|
||||
struct buf;
|
||||
struct mfsnode;
|
||||
struct mount;
|
||||
struct proc;
|
||||
struct vnode;
|
||||
|
||||
void mfs_doio __P((struct buf *bp, struct mfsnode *mfsnode));
|
||||
u_char *mfs_getimage __P((void));
|
||||
int mfs_mountfs __P((struct vnode *, struct mount *, struct proc *));
|
||||
int mfs_mountroot __P((void));
|
||||
|
||||
#endif /* !_UFS_MFS_MFS_EXTERN_H_ */
|
@ -1,413 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1989, 1990, 1993, 1994
|
||||
* 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* 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.
|
||||
*
|
||||
* @(#)mfs_vfsops.c 8.11 (Berkeley) 6/19/95
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
|
||||
#include "opt_mfs.h"
|
||||
#include "opt_ufs.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/bio.h>
|
||||
#include <sys/buf.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/signalvar.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/linker.h>
|
||||
|
||||
#include <ufs/ufs/extattr.h>
|
||||
#include <ufs/ufs/quota.h>
|
||||
#include <ufs/ufs/inode.h>
|
||||
#include <ufs/ufs/ufsmount.h>
|
||||
#include <ufs/ufs/ufs_extern.h>
|
||||
|
||||
#include <ufs/ffs/fs.h>
|
||||
#include <ufs/ffs/ffs_extern.h>
|
||||
|
||||
#include <ufs/mfs/mfsnode.h>
|
||||
#include <ufs/mfs/mfs_extern.h>
|
||||
|
||||
MALLOC_DEFINE(M_MFSNODE, "MFS node", "MFS vnode private part");
|
||||
|
||||
|
||||
static int mfs_minor; /* used for building internal dev_t */
|
||||
|
||||
extern vop_t **mfs_vnodeop_p;
|
||||
|
||||
static int mfs_mount __P((struct mount *mp,
|
||||
char *path, caddr_t data, struct nameidata *ndp,
|
||||
struct proc *p));
|
||||
static int mfs_start __P((struct mount *mp, int flags, struct proc *p));
|
||||
static int mfs_statfs __P((struct mount *mp, struct statfs *sbp,
|
||||
struct proc *p));
|
||||
static int mfs_init __P((struct vfsconf *));
|
||||
|
||||
static struct cdevsw mfs_cdevsw = {
|
||||
/* open */ noopen,
|
||||
/* close */ noclose,
|
||||
/* read */ physread,
|
||||
/* write */ physwrite,
|
||||
/* ioctl */ noioctl,
|
||||
/* poll */ nopoll,
|
||||
/* mmap */ nommap,
|
||||
/* strategy */ nostrategy,
|
||||
/* name */ "MFS",
|
||||
/* maj */ 253,
|
||||
/* dump */ nodump,
|
||||
/* psize */ nopsize,
|
||||
/* flags */ D_DISK,
|
||||
};
|
||||
|
||||
/*
|
||||
* mfs vfs operations.
|
||||
*/
|
||||
static struct vfsops mfs_vfsops = {
|
||||
mfs_mount,
|
||||
mfs_start,
|
||||
ffs_unmount,
|
||||
ufs_root,
|
||||
ufs_quotactl,
|
||||
mfs_statfs,
|
||||
ffs_sync,
|
||||
ffs_vget,
|
||||
ffs_fhtovp,
|
||||
vfs_stdcheckexp,
|
||||
ffs_vptofh,
|
||||
mfs_init,
|
||||
vfs_stduninit,
|
||||
#ifdef UFS_EXTATTR
|
||||
ufs_extattrctl,
|
||||
#else
|
||||
vfs_stdextattrctl,
|
||||
#endif
|
||||
};
|
||||
|
||||
VFS_SET(mfs_vfsops, mfs, 0);
|
||||
|
||||
|
||||
/*
|
||||
* mfs_mount
|
||||
*
|
||||
* Called when mounting local physical media
|
||||
*
|
||||
* PARAMETERS:
|
||||
* mountroot
|
||||
* mp mount point structure
|
||||
* path NULL (flag for root mount!!!)
|
||||
* data <unused>
|
||||
* ndp <unused>
|
||||
* p process (user credentials check [statfs])
|
||||
*
|
||||
* mount
|
||||
* mp mount point structure
|
||||
* path path to mount point
|
||||
* data pointer to argument struct in user space
|
||||
* ndp mount point namei() return (used for
|
||||
* credentials on reload), reused to look
|
||||
* up block device.
|
||||
* p process (user credentials check)
|
||||
*
|
||||
* RETURNS: 0 Success
|
||||
* !0 error number (errno.h)
|
||||
*
|
||||
* LOCK STATE:
|
||||
*
|
||||
* ENTRY
|
||||
* mount point is locked
|
||||
* EXIT
|
||||
* mount point is locked
|
||||
*
|
||||
* NOTES:
|
||||
* A NULL path can be used for a flag since the mount
|
||||
* system call will fail with EFAULT in copyinstr in
|
||||
* namei() if it is a genuine NULL from the user.
|
||||
*/
|
||||
/* ARGSUSED */
|
||||
static int
|
||||
mfs_mount(mp, path, data, ndp, p)
|
||||
register struct mount *mp;
|
||||
char *path;
|
||||
caddr_t data;
|
||||
struct nameidata *ndp;
|
||||
struct proc *p;
|
||||
{
|
||||
struct vnode *devvp;
|
||||
struct mfs_args args;
|
||||
struct ufsmount *ump;
|
||||
struct fs *fs;
|
||||
struct mfsnode *mfsp;
|
||||
size_t size;
|
||||
int flags, err;
|
||||
dev_t dev;
|
||||
|
||||
/*
|
||||
* Use NULL path to flag a root mount
|
||||
*/
|
||||
if( path == NULL) {
|
||||
/*
|
||||
***
|
||||
* Mounting root file system
|
||||
***
|
||||
*/
|
||||
|
||||
/* you loose */
|
||||
panic("mfs_mount: mount MFS as root: not configured!");
|
||||
}
|
||||
|
||||
/*
|
||||
***
|
||||
* Mounting non-root file system or updating a file system
|
||||
***
|
||||
*/
|
||||
|
||||
/* copy in user arguments*/
|
||||
if ((err = copyin(data, (caddr_t)&args, sizeof (struct mfs_args))) != 0)
|
||||
goto error_1;
|
||||
|
||||
/*
|
||||
* If updating, check whether changing from read-only to
|
||||
* read/write; if there is no device name, that's all we do.
|
||||
*/
|
||||
if (mp->mnt_flag & MNT_UPDATE) {
|
||||
/*
|
||||
********************
|
||||
* UPDATE
|
||||
********************
|
||||
*/
|
||||
ump = VFSTOUFS(mp);
|
||||
fs = ump->um_fs;
|
||||
if (fs->fs_ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) {
|
||||
flags = WRITECLOSE;
|
||||
if (mp->mnt_flag & MNT_FORCE)
|
||||
flags |= FORCECLOSE;
|
||||
err = ffs_flushfiles(mp, flags, p);
|
||||
if (err)
|
||||
goto error_1;
|
||||
}
|
||||
if (fs->fs_ronly && (mp->mnt_kern_flag & MNTK_WANTRDWR))
|
||||
fs->fs_ronly = 0;
|
||||
/* if not updating name...*/
|
||||
if (args.fspec == 0) {
|
||||
/*
|
||||
* Process export requests. Jumping to "success"
|
||||
* will return the vfs_export() error code.
|
||||
*/
|
||||
err = vfs_export(mp, &args.export);
|
||||
goto success;
|
||||
}
|
||||
|
||||
/* XXX MFS does not support name updating*/
|
||||
goto success;
|
||||
}
|
||||
/*
|
||||
* Do the MALLOC before the getnewvnode since doing so afterward
|
||||
* might cause a bogus v_data pointer to get dereferenced
|
||||
* elsewhere if MALLOC should block.
|
||||
*/
|
||||
MALLOC(mfsp, struct mfsnode *, sizeof *mfsp, M_MFSNODE, M_WAITOK);
|
||||
|
||||
err = getnewvnode(VT_MFS, (struct mount *)0, mfs_vnodeop_p, &devvp);
|
||||
if (err) {
|
||||
FREE(mfsp, M_MFSNODE);
|
||||
goto error_1;
|
||||
}
|
||||
devvp->v_type = VCHR;
|
||||
dev = makedev(mfs_cdevsw.d_maj, mfs_minor);
|
||||
dev->si_devsw = &mfs_cdevsw;
|
||||
/* It is not clear that these will get initialized otherwise */
|
||||
dev->si_bsize_phys = DEV_BSIZE;
|
||||
dev->si_iosize_max = DFLTPHYS;
|
||||
devvp = addaliasu(devvp, makeudev(253, mfs_minor++));
|
||||
devvp->v_data = mfsp;
|
||||
mfsp->mfs_baseoff = args.base;
|
||||
mfsp->mfs_size = args.size;
|
||||
mfsp->mfs_vnode = devvp;
|
||||
mfsp->mfs_pid = p->p_pid;
|
||||
mfsp->mfs_active = 1;
|
||||
bufq_init(&mfsp->buf_queue);
|
||||
|
||||
/*
|
||||
* Since this is a new mount, we want the names for
|
||||
* the device and the mount point copied in. If an
|
||||
* error occurs, the mountpoint is discarded by the
|
||||
* upper level code.
|
||||
*/
|
||||
/* Save "last mounted on" info for mount point (NULL pad)*/
|
||||
copyinstr( path, /* mount point*/
|
||||
mp->mnt_stat.f_mntonname, /* save area*/
|
||||
MNAMELEN - 1, /* max size*/
|
||||
&size); /* real size*/
|
||||
bzero( mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
|
||||
|
||||
/* Save "mounted from" info for mount point (NULL pad)*/
|
||||
copyinstr( args.fspec, /* device name*/
|
||||
mp->mnt_stat.f_mntfromname, /* save area*/
|
||||
MNAMELEN - 1, /* max size*/
|
||||
&size); /* real size*/
|
||||
bzero( mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
|
||||
|
||||
if ((err = ffs_mountfs(devvp, mp, p, M_MFSNODE)) != 0) {
|
||||
mfsp->mfs_active = 0;
|
||||
goto error_2;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize FS stat information in mount struct; uses both
|
||||
* mp->mnt_stat.f_mntonname and mp->mnt_stat.f_mntfromname
|
||||
*
|
||||
* This code is common to root and non-root mounts
|
||||
*/
|
||||
(void) VFS_STATFS(mp, &mp->mnt_stat, p);
|
||||
|
||||
goto success;
|
||||
|
||||
error_2: /* error with devvp held*/
|
||||
|
||||
/* release devvp before failing*/
|
||||
vrele(devvp);
|
||||
|
||||
error_1: /* no state to back out*/
|
||||
|
||||
success:
|
||||
return( err);
|
||||
}
|
||||
|
||||
|
||||
static int mfs_pri = PWAIT | PCATCH; /* XXX prob. temp */
|
||||
|
||||
/*
|
||||
* Used to grab the process and keep it in the kernel to service
|
||||
* memory filesystem I/O requests.
|
||||
*
|
||||
* Loop servicing I/O requests.
|
||||
* Copy the requested data into or out of the memory filesystem
|
||||
* address space.
|
||||
*/
|
||||
/* ARGSUSED */
|
||||
static int
|
||||
mfs_start(mp, flags, p)
|
||||
struct mount *mp;
|
||||
int flags;
|
||||
struct proc *p;
|
||||
{
|
||||
register struct vnode *vp = VFSTOUFS(mp)->um_devvp;
|
||||
register struct mfsnode *mfsp = VTOMFS(vp);
|
||||
register struct buf *bp;
|
||||
register int gotsig = 0, sig;
|
||||
|
||||
/*
|
||||
* We must prevent the system from trying to swap
|
||||
* out or kill ( when swap space is low, see vm/pageout.c ) the
|
||||
* process. A deadlock can occur if the process is swapped out,
|
||||
* and the system can loop trying to kill the unkillable ( while
|
||||
* references exist ) MFS process when swap space is low.
|
||||
*/
|
||||
PHOLD(curproc);
|
||||
|
||||
while (mfsp->mfs_active) {
|
||||
int s;
|
||||
|
||||
s = splbio();
|
||||
|
||||
while ((bp = bufq_first(&mfsp->buf_queue)) != NULL) {
|
||||
bufq_remove(&mfsp->buf_queue, bp);
|
||||
splx(s);
|
||||
mfs_doio(bp, mfsp);
|
||||
wakeup((caddr_t)bp);
|
||||
s = splbio();
|
||||
}
|
||||
|
||||
splx(s);
|
||||
|
||||
/*
|
||||
* If a non-ignored signal is received, try to unmount.
|
||||
* If that fails, clear the signal (it has been "processed"),
|
||||
* otherwise we will loop here, as tsleep will always return
|
||||
* EINTR/ERESTART.
|
||||
*/
|
||||
/*
|
||||
* Note that dounmount() may fail if work was queued after
|
||||
* we slept. We have to jump hoops here to make sure that we
|
||||
* process any buffers after the sleep, before we dounmount()
|
||||
*/
|
||||
if (gotsig) {
|
||||
gotsig = 0;
|
||||
if (dounmount(mp, 0, p) != 0) {
|
||||
sig = CURSIG(p);
|
||||
if (sig) {
|
||||
PROC_LOCK(p);
|
||||
SIGDELSET(p->p_siglist, sig);
|
||||
PROC_UNLOCK(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (tsleep((caddr_t)vp, mfs_pri, "mfsidl", 0))
|
||||
gotsig++; /* try to unmount in next pass */
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get file system statistics.
|
||||
*/
|
||||
static int
|
||||
mfs_statfs(mp, sbp, p)
|
||||
struct mount *mp;
|
||||
struct statfs *sbp;
|
||||
struct proc *p;
|
||||
{
|
||||
int error;
|
||||
|
||||
error = ffs_statfs(mp, sbp, p);
|
||||
sbp->f_type = mp->mnt_vfc->vfc_typenum;
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* Memory based filesystem initialization.
|
||||
*/
|
||||
static int
|
||||
mfs_init(vfsp)
|
||||
struct vfsconf *vfsp;
|
||||
{
|
||||
|
||||
cdevsw_add(&mfs_cdevsw);
|
||||
return (0);
|
||||
}
|
||||
|
@ -1,416 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* 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.
|
||||
*
|
||||
* @(#)mfs_vnops.c 8.11 (Berkeley) 5/22/95
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include "opt_ufs.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/bio.h>
|
||||
#include <sys/buf.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/sysproto.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <ufs/ufs/extattr.h>
|
||||
|
||||
#include <ufs/mfs/mfsnode.h>
|
||||
#include <ufs/mfs/mfs_extern.h>
|
||||
|
||||
static int mfs_badop __P((struct vop_generic_args *));
|
||||
static int mfs_close __P((struct vop_close_args *));
|
||||
static int mfs_fsync __P((struct vop_fsync_args *));
|
||||
static int mfs_freeblks __P((struct vop_freeblks_args *));
|
||||
static int mfs_inactive __P((struct vop_inactive_args *)); /* XXX */
|
||||
static int mfs_open __P((struct vop_open_args *));
|
||||
static int mfs_reclaim __P((struct vop_reclaim_args *)); /* XXX */
|
||||
static int mfs_print __P((struct vop_print_args *)); /* XXX */
|
||||
static int mfs_strategy __P((struct vop_strategy_args *)); /* XXX */
|
||||
static int mfs_getpages __P((struct vop_getpages_args *)); /* XXX */
|
||||
/*
|
||||
* mfs vnode operations.
|
||||
*/
|
||||
vop_t **mfs_vnodeop_p;
|
||||
static struct vnodeopv_entry_desc mfs_vnodeop_entries[] = {
|
||||
{ &vop_default_desc, (vop_t *) mfs_badop },
|
||||
{ &vop_bmap_desc, (vop_t *) vop_stdbmap },
|
||||
{ &vop_close_desc, (vop_t *) mfs_close },
|
||||
{ &vop_createvobject_desc, (vop_t *) vop_stdcreatevobject },
|
||||
{ &vop_destroyvobject_desc, (vop_t *) vop_stddestroyvobject },
|
||||
{ &vop_freeblks_desc, (vop_t *) mfs_freeblks },
|
||||
{ &vop_fsync_desc, (vop_t *) mfs_fsync },
|
||||
#ifdef UFS_EXTATTR
|
||||
{ &vop_getextattr_desc, (vop_t *) ufs_vop_getextattr },
|
||||
#endif
|
||||
{ &vop_getpages_desc, (vop_t *) mfs_getpages },
|
||||
{ &vop_getvobject_desc, (vop_t *) vop_stdgetvobject },
|
||||
{ &vop_inactive_desc, (vop_t *) mfs_inactive },
|
||||
{ &vop_ioctl_desc, (vop_t *) vop_enotty },
|
||||
{ &vop_islocked_desc, (vop_t *) vop_defaultop },
|
||||
{ &vop_lock_desc, (vop_t *) vop_defaultop },
|
||||
{ &vop_open_desc, (vop_t *) mfs_open },
|
||||
{ &vop_print_desc, (vop_t *) mfs_print },
|
||||
{ &vop_reclaim_desc, (vop_t *) mfs_reclaim },
|
||||
#ifdef UFS_EXTATTR
|
||||
{ &vop_setextattr_desc, (vop_t *) ufs_vop_setextattr },
|
||||
#endif
|
||||
{ &vop_strategy_desc, (vop_t *) mfs_strategy },
|
||||
{ &vop_unlock_desc, (vop_t *) vop_defaultop },
|
||||
{ &vop_getwritemount_desc, (vop_t *) vop_stdgetwritemount },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
static struct vnodeopv_desc mfs_vnodeop_opv_desc =
|
||||
{ &mfs_vnodeop_p, mfs_vnodeop_entries };
|
||||
|
||||
VNODEOP_SET(mfs_vnodeop_opv_desc);
|
||||
|
||||
/*
|
||||
* 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 */
|
||||
static int
|
||||
mfs_open(ap)
|
||||
struct vop_open_args /* {
|
||||
struct vnode *a_vp;
|
||||
int a_mode;
|
||||
struct ucred *a_cred;
|
||||
struct proc *a_p;
|
||||
} */ *ap;
|
||||
{
|
||||
|
||||
if (ap->a_vp->v_type != VCHR)
|
||||
panic("mfs_open not VCHR");
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
mfs_fsync(ap)
|
||||
struct vop_fsync_args *ap;
|
||||
{
|
||||
|
||||
return (VOCALL(spec_vnodeop_p, VOFFSET(vop_fsync), ap));
|
||||
}
|
||||
|
||||
/*
|
||||
* mfs_freeblks() - hook to allow us to free physical memory.
|
||||
*
|
||||
* We implement the BIO_DELETE strategy. We can't just madvise()
|
||||
* here because we have to do it in the correct order vs other bio
|
||||
* requests, so we queue it.
|
||||
*
|
||||
* Note: geteblk() sets B_INVAL. We leave it set to guarentee buffer
|
||||
* throw-away on brelse()? XXX
|
||||
*/
|
||||
|
||||
static int
|
||||
mfs_freeblks(ap)
|
||||
struct vop_freeblks_args /* {
|
||||
struct vnode *a_vp;
|
||||
daddr_t a_addr;
|
||||
daddr_t a_length;
|
||||
} */ *ap;
|
||||
{
|
||||
struct buf *bp;
|
||||
struct vnode *vp;
|
||||
|
||||
if (!vfinddev(ap->a_vp->v_rdev, VCHR, &vp) || vp->v_usecount == 0)
|
||||
panic("mfs_freeblks: bad dev");
|
||||
|
||||
bp = geteblk(ap->a_length);
|
||||
bp->b_flags |= B_ASYNC;
|
||||
bp->b_iocmd = BIO_DELETE;
|
||||
bp->b_dev = ap->a_vp->v_rdev;
|
||||
bp->b_blkno = ap->a_addr;
|
||||
bp->b_offset = dbtob(ap->a_addr);
|
||||
bp->b_bcount = ap->a_length;
|
||||
BUF_KERNPROC(bp);
|
||||
VOP_STRATEGY(vp, bp);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Pass I/O requests to the memory filesystem process.
|
||||
*/
|
||||
static int
|
||||
mfs_strategy(ap)
|
||||
struct vop_strategy_args /* {
|
||||
struct vnode *a_vp;
|
||||
struct bio *a_bp;
|
||||
} */ *ap;
|
||||
{
|
||||
register struct buf *bp = (struct buf *)ap->a_bp;
|
||||
register struct mfsnode *mfsp;
|
||||
struct vnode *vp;
|
||||
struct proc *p = curproc; /* XXX */
|
||||
int s;
|
||||
|
||||
if (!vfinddev(bp->b_dev, VCHR, &vp) || vp->v_usecount == 0)
|
||||
panic("mfs_strategy: bad dev");
|
||||
mfsp = VTOMFS(vp);
|
||||
|
||||
/*
|
||||
* splbio required for queueing/dequeueing, in case of forwarded
|
||||
* BPs from bio interrupts (?). It may not be necessary.
|
||||
*/
|
||||
|
||||
s = splbio();
|
||||
|
||||
if (mfsp->mfs_pid == 0) {
|
||||
/*
|
||||
* mini-root. Note: BIO_DELETE not supported at the moment,
|
||||
* I'm not sure what kind of dataspace b_data is in.
|
||||
*/
|
||||
caddr_t base;
|
||||
|
||||
base = mfsp->mfs_baseoff + (bp->b_blkno << DEV_BSHIFT);
|
||||
if (bp->b_iocmd == BIO_DELETE)
|
||||
;
|
||||
if (bp->b_iocmd == BIO_READ)
|
||||
bcopy(base, bp->b_data, bp->b_bcount);
|
||||
else
|
||||
bcopy(bp->b_data, base, bp->b_bcount);
|
||||
bufdone(bp);
|
||||
} else if (mfsp->mfs_pid == p->p_pid) {
|
||||
/*
|
||||
* VOP to self
|
||||
*/
|
||||
splx(s);
|
||||
mfs_doio(bp, mfsp);
|
||||
s = splbio();
|
||||
} else {
|
||||
/*
|
||||
* VOP from some other process, queue to MFS process and
|
||||
* wake it up.
|
||||
*/
|
||||
bufq_insert_tail(&mfsp->buf_queue, bp);
|
||||
wakeup((caddr_t)vp);
|
||||
}
|
||||
splx(s);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Memory file system I/O.
|
||||
*
|
||||
* Trivial on the HP since buffer has already been mapping into KVA space.
|
||||
*
|
||||
* Read and Write are handled with a simple copyin and copyout.
|
||||
*
|
||||
* We also partially support VOP_FREEBLKS() via BIO_DELETE. We can't implement
|
||||
* completely -- for example, on fragments or inode metadata, but we can
|
||||
* implement it for page-aligned requests.
|
||||
*/
|
||||
void
|
||||
mfs_doio(bp, mfsp)
|
||||
register struct buf *bp;
|
||||
struct mfsnode *mfsp;
|
||||
{
|
||||
caddr_t base = mfsp->mfs_baseoff + (bp->b_blkno << DEV_BSHIFT);
|
||||
|
||||
if (bp->b_iocmd == BIO_DELETE) {
|
||||
/*
|
||||
* Implement BIO_DELETE, which allows the filesystem to tell
|
||||
* a block device when blocks are no longer needed (like when
|
||||
* a file is deleted). We use the hook to MADV_FREE the VM.
|
||||
* This makes an MFS filesystem work as well or better then
|
||||
* a sun-style swap-mounted filesystem.
|
||||
*/
|
||||
int bytes = bp->b_bcount;
|
||||
|
||||
if ((vm_offset_t)base & PAGE_MASK) {
|
||||
int n = PAGE_SIZE - ((vm_offset_t)base & PAGE_MASK);
|
||||
bytes -= n;
|
||||
base += n;
|
||||
}
|
||||
if (bytes > 0) {
|
||||
struct madvise_args uap;
|
||||
|
||||
bytes &= ~PAGE_MASK;
|
||||
if (bytes != 0) {
|
||||
bzero(&uap, sizeof(uap));
|
||||
uap.addr = base;
|
||||
uap.len = bytes;
|
||||
uap.behav = MADV_FREE;
|
||||
madvise(curproc, &uap);
|
||||
}
|
||||
}
|
||||
bp->b_error = 0;
|
||||
} else if (bp->b_iocmd == BIO_READ) {
|
||||
/*
|
||||
* Read data from our 'memory' disk
|
||||
*/
|
||||
bp->b_error = copyin(base, bp->b_data, bp->b_bcount);
|
||||
} else {
|
||||
/*
|
||||
* Write data to our 'memory' disk
|
||||
*/
|
||||
bp->b_error = copyout(bp->b_data, base, bp->b_bcount);
|
||||
}
|
||||
if (bp->b_error)
|
||||
bp->b_ioflags |= BIO_ERROR;
|
||||
bufdone(bp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Memory filesystem close routine
|
||||
*/
|
||||
/* ARGSUSED */
|
||||
static int
|
||||
mfs_close(ap)
|
||||
struct vop_close_args /* {
|
||||
struct vnode *a_vp;
|
||||
int a_fflag;
|
||||
struct ucred *a_cred;
|
||||
struct proc *a_p;
|
||||
} */ *ap;
|
||||
{
|
||||
register struct vnode *vp = ap->a_vp;
|
||||
register struct mfsnode *mfsp = VTOMFS(vp);
|
||||
register struct buf *bp;
|
||||
int error;
|
||||
|
||||
/*
|
||||
* Finish any pending I/O requests.
|
||||
*/
|
||||
while ((bp = bufq_first(&mfsp->buf_queue)) != NULL) {
|
||||
bufq_remove(&mfsp->buf_queue, bp);
|
||||
mfs_doio(bp, mfsp);
|
||||
wakeup((caddr_t)bp);
|
||||
}
|
||||
/*
|
||||
* On last close of a memory filesystem
|
||||
* we must invalidate any in core blocks, so that
|
||||
* we can, free up its vnode.
|
||||
*/
|
||||
if ((error = vinvalbuf(vp, 1, ap->a_cred, ap->a_p, 0, 0)) != 0)
|
||||
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)
|
||||
printf("mfs_close: ref count %d > 1\n", vp->v_usecount);
|
||||
if (vp->v_usecount > 1 || (bufq_first(&mfsp->buf_queue) != NULL))
|
||||
panic("mfs_close");
|
||||
/*
|
||||
* Send a request to the filesystem server to exit.
|
||||
*/
|
||||
mfsp->mfs_active = 0;
|
||||
wakeup((caddr_t)vp);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Memory filesystem inactive routine
|
||||
*/
|
||||
/* ARGSUSED */
|
||||
static int
|
||||
mfs_inactive(ap)
|
||||
struct vop_inactive_args /* {
|
||||
struct vnode *a_vp;
|
||||
struct proc *a_p;
|
||||
} */ *ap;
|
||||
{
|
||||
struct vnode *vp = ap->a_vp;
|
||||
struct mfsnode *mfsp = VTOMFS(vp);
|
||||
|
||||
if (bufq_first(&mfsp->buf_queue) != NULL)
|
||||
panic("mfs_inactive: not inactive (next buffer %p)",
|
||||
bufq_first(&mfsp->buf_queue));
|
||||
VOP_UNLOCK(vp, 0, ap->a_p);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Reclaim a memory filesystem devvp so that it can be reused.
|
||||
*/
|
||||
static int
|
||||
mfs_reclaim(ap)
|
||||
struct vop_reclaim_args /* {
|
||||
struct vnode *a_vp;
|
||||
} */ *ap;
|
||||
{
|
||||
register struct vnode *vp = ap->a_vp;
|
||||
|
||||
FREE(vp->v_data, M_MFSNODE);
|
||||
vp->v_data = NULL;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print out the contents of an mfsnode.
|
||||
*/
|
||||
static int
|
||||
mfs_print(ap)
|
||||
struct vop_print_args /* {
|
||||
struct vnode *a_vp;
|
||||
} */ *ap;
|
||||
{
|
||||
register struct mfsnode *mfsp = VTOMFS(ap->a_vp);
|
||||
|
||||
printf("tag VT_MFS, pid %ld, base %p, size %ld\n",
|
||||
(long)mfsp->mfs_pid, (void *)mfsp->mfs_baseoff, mfsp->mfs_size);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Block device bad operation
|
||||
*/
|
||||
static int
|
||||
mfs_badop(struct vop_generic_args *ap)
|
||||
{
|
||||
int i;
|
||||
|
||||
printf("mfs_badop[%s]\n", ap->a_desc->vdesc_name);
|
||||
i = vop_defaultop(ap);
|
||||
printf("mfs_badop[%s] = %d\n", ap->a_desc->vdesc_name,i);
|
||||
return (i);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
mfs_getpages(ap)
|
||||
struct vop_getpages_args *ap;
|
||||
{
|
||||
|
||||
return (VOCALL(spec_vnodeop_p, VOFFSET(vop_getpages), ap));
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* 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.
|
||||
*
|
||||
* @(#)mfsnode.h 8.3 (Berkeley) 5/19/95
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _UFS_MFS_MFSNODE_H_
|
||||
#define _UFS_MFS_MFSNODE_H_
|
||||
|
||||
/*
|
||||
* This structure defines the control data for the memory based file system.
|
||||
*/
|
||||
|
||||
struct mfsnode {
|
||||
struct vnode *mfs_vnode; /* vnode associated with this mfsnode */
|
||||
caddr_t mfs_baseoff; /* base of file system in memory */
|
||||
long mfs_size; /* size of memory file system */
|
||||
pid_t mfs_pid; /* supporting process pid */
|
||||
struct buf_queue_head buf_queue; /* list of I/O requests */
|
||||
int mfs_active;
|
||||
long mfs_spare[1];
|
||||
};
|
||||
|
||||
/*
|
||||
* Convert between mfsnode pointers and vnode pointers
|
||||
*/
|
||||
#define VTOMFS(vp) ((struct mfsnode *)(vp)->v_data)
|
||||
#define MFSTOV(mfsp) ((mfsp)->mfs_vnode)
|
||||
|
||||
#ifdef MALLOC_DECLARE
|
||||
MALLOC_DECLARE(M_MFSNODE);
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user