2004-07-05 11:28:45 +04:00
|
|
|
/* $NetBSD: mfs_vfsops.c,v 1.61 2004/07/05 07:28:46 pk Exp $ */
|
1994-06-29 10:39:25 +04:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* 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.
|
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_vfsops.c 8.11 (Berkeley) 6/19/95
|
1994-06-08 15:41:58 +04:00
|
|
|
*/
|
|
|
|
|
2001-11-08 05:39:06 +03:00
|
|
|
#include <sys/cdefs.h>
|
2004-07-05 11:28:45 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: mfs_vfsops.c,v 1.61 2004/07/05 07:28:46 pk Exp $");
|
2001-11-08 05:39:06 +03:00
|
|
|
|
2001-05-30 15:57:16 +04:00
|
|
|
#if defined(_KERNEL_OPT)
|
1998-07-05 12:49:30 +04:00
|
|
|
#include "opt_compat_netbsd.h"
|
|
|
|
#endif
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
Dynamic sysctl.
Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.
Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.
All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.
PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
2003-12-04 22:38:21 +03:00
|
|
|
#include <sys/sysctl.h>
|
1994-06-08 15:41:58 +04:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
|
2001-04-17 02:41:09 +04:00
|
|
|
#include <miscfs/syncfs/syncfs.h>
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
#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>
|
|
|
|
|
|
|
|
caddr_t mfs_rootbase; /* address of mini-root in kernel virtual memory */
|
|
|
|
u_long mfs_rootsize; /* size of mini-root in bytes */
|
|
|
|
|
|
|
|
static int mfs_minor; /* used for building internal dev_t */
|
|
|
|
|
1996-02-10 01:31:27 +03:00
|
|
|
extern int (**mfs_vnodeop_p) __P((void *));
|
1994-06-08 15:41:58 +04:00
|
|
|
|
2003-02-01 09:23:35 +03:00
|
|
|
MALLOC_DEFINE(M_MFSNODE, "MFS node", "MFS vnode private part");
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* mfs vfs operations.
|
|
|
|
*/
|
1998-02-18 10:05:47 +03:00
|
|
|
|
2001-01-22 15:17:35 +03:00
|
|
|
extern const struct vnodeopv_desc mfs_vnodeop_opv_desc;
|
1998-02-18 10:05:47 +03:00
|
|
|
|
2001-01-22 15:17:35 +03:00
|
|
|
const struct vnodeopv_desc * const mfs_vnodeopv_descs[] = {
|
1998-02-18 10:05:47 +03:00
|
|
|
&mfs_vnodeop_opv_desc,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
struct vfsops mfs_vfsops = {
|
|
|
|
MOUNT_MFS,
|
|
|
|
mfs_mount,
|
|
|
|
mfs_start,
|
|
|
|
ffs_unmount,
|
|
|
|
ufs_root,
|
|
|
|
ufs_quotactl,
|
2004-04-21 05:05:31 +04:00
|
|
|
mfs_statvfs,
|
1994-06-08 15:41:58 +04:00
|
|
|
ffs_sync,
|
|
|
|
ffs_vget,
|
|
|
|
ffs_fhtovp,
|
|
|
|
ffs_vptofh,
|
|
|
|
mfs_init,
|
2001-09-15 20:12:54 +04:00
|
|
|
mfs_reinit,
|
2000-03-16 21:20:06 +03:00
|
|
|
mfs_done,
|
Dynamic sysctl.
Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.
Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.
All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.
PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
2003-12-04 22:38:21 +03:00
|
|
|
NULL,
|
1998-03-02 01:16:01 +03:00
|
|
|
NULL,
|
1999-02-27 02:44:43 +03:00
|
|
|
ufs_check_export,
|
2004-05-25 18:54:55 +04:00
|
|
|
(int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
|
1998-02-18 10:05:47 +03:00
|
|
|
mfs_vnodeopv_descs,
|
1994-06-08 15:41:58 +04:00
|
|
|
};
|
|
|
|
|
Dynamic sysctl.
Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.
Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.
All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.
PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
2003-12-04 22:38:21 +03:00
|
|
|
SYSCTL_SETUP(sysctl_vfs_mfs_setup, "sysctl vfs.mfs subtree setup")
|
|
|
|
{
|
|
|
|
|
2004-03-24 18:34:46 +03:00
|
|
|
sysctl_createv(clog, 0, NULL, NULL,
|
|
|
|
CTLFLAG_PERMANENT,
|
Dynamic sysctl.
Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.
Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.
All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.
PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
2003-12-04 22:38:21 +03:00
|
|
|
CTLTYPE_NODE, "vfs", NULL,
|
|
|
|
NULL, 0, NULL, 0,
|
|
|
|
CTL_VFS, CTL_EOL);
|
2004-03-24 18:34:46 +03:00
|
|
|
sysctl_createv(clog, 0, NULL, NULL,
|
|
|
|
CTLFLAG_PERMANENT|CTLFLAG_ALIAS,
|
2004-05-25 08:44:43 +04:00
|
|
|
CTLTYPE_NODE, "mfs",
|
|
|
|
SYSCTL_DESCR("Memory based file system"),
|
Dynamic sysctl.
Gone are the old kern_sysctl(), cpu_sysctl(), hw_sysctl(),
vfs_sysctl(), etc, routines, along with sysctl_int() et al. Now all
nodes are registered with the tree, and nodes can be added (or
removed) easily, and I/O to and from the tree is handled generically.
Since the nodes are registered with the tree, the mapping from name to
number (and back again) can now be discovered, instead of having to be
hard coded. Adding new nodes to the tree is likewise much simpler --
the new infrastructure handles almost all the work for simple types,
and just about anything else can be done with a small helper function.
All existing nodes are where they were before (numerically speaking),
so all existing consumers of sysctl information should notice no
difference.
PS - I'm sorry, but there's a distinct lack of documentation at the
moment. I'm working on sysctl(3/8/9) right now, and I promise to
watch out for buses.
2003-12-04 22:38:21 +03:00
|
|
|
NULL, 1, NULL, 0,
|
|
|
|
CTL_VFS, 3, CTL_EOL);
|
|
|
|
/*
|
|
|
|
* XXX the "1" and the "3" above could be dynamic, thereby
|
|
|
|
* eliminating one more instance of the "number to vfs"
|
|
|
|
* mapping problem, but they are in order as taken from
|
|
|
|
* sys/mount.h
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
1998-03-01 05:20:01 +03:00
|
|
|
/*
|
|
|
|
* Memory based filesystem initialization.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
mfs_init()
|
|
|
|
{
|
2003-04-22 21:14:12 +04:00
|
|
|
#ifdef _LKM
|
|
|
|
malloc_type_attach(M_MFSNODE);
|
|
|
|
#endif
|
2000-03-16 21:20:06 +03:00
|
|
|
/*
|
|
|
|
* ffs_init() ensures to initialize necessary resources
|
|
|
|
* only once.
|
|
|
|
*/
|
|
|
|
ffs_init();
|
1998-03-01 05:20:01 +03:00
|
|
|
}
|
|
|
|
|
2001-09-15 20:12:54 +04:00
|
|
|
void
|
|
|
|
mfs_reinit()
|
|
|
|
{
|
|
|
|
ffs_reinit();
|
|
|
|
}
|
|
|
|
|
2000-03-16 21:20:06 +03:00
|
|
|
void
|
|
|
|
mfs_done()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* ffs_done() ensures to free necessary resources
|
|
|
|
* only once, when it's no more needed.
|
|
|
|
*/
|
|
|
|
ffs_done();
|
2003-04-22 21:14:12 +04:00
|
|
|
#ifdef _LKM
|
|
|
|
malloc_type_detach(M_MFSNODE);
|
|
|
|
#endif
|
2000-03-16 21:20:06 +03:00
|
|
|
}
|
1998-03-01 05:20:01 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* Called by main() when mfs is going to be mounted as root.
|
|
|
|
*/
|
|
|
|
|
1996-02-10 01:31:27 +03:00
|
|
|
int
|
1994-06-08 15:41:58 +04:00
|
|
|
mfs_mountroot()
|
|
|
|
{
|
1998-03-01 05:20:01 +03:00
|
|
|
struct fs *fs;
|
|
|
|
struct mount *mp;
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p = curproc; /* XXX */
|
1994-06-08 15:41:58 +04:00
|
|
|
struct ufsmount *ump;
|
|
|
|
struct mfsnode *mfsp;
|
1998-03-01 05:20:01 +03:00
|
|
|
int error = 0;
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
/*
|
1997-06-12 21:12:17 +04:00
|
|
|
* Get vnodes for rootdev.
|
1994-06-08 15:41:58 +04:00
|
|
|
*/
|
1998-03-01 05:20:01 +03:00
|
|
|
if (bdevvp(rootdev, &rootvp)) {
|
|
|
|
printf("mfs_mountroot: can't setup bdevvp's");
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1999-07-17 05:08:28 +04:00
|
|
|
if ((error = vfs_rootmountalloc(MOUNT_MFS, "mfs_root", &mp))) {
|
|
|
|
vrele(rootvp);
|
1998-03-01 05:20:01 +03:00
|
|
|
return (error);
|
1999-07-17 05:08:28 +04:00
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
mfsp = malloc(sizeof *mfsp, M_MFSNODE, M_WAITOK);
|
|
|
|
rootvp->v_data = mfsp;
|
|
|
|
rootvp->v_op = mfs_vnodeop_p;
|
|
|
|
rootvp->v_tag = VT_MFS;
|
|
|
|
mfsp->mfs_baseoff = mfs_rootbase;
|
|
|
|
mfsp->mfs_size = mfs_rootsize;
|
|
|
|
mfsp->mfs_vnode = rootvp;
|
2000-05-16 04:24:08 +04:00
|
|
|
mfsp->mfs_proc = NULL; /* indicate kernel space */
|
2002-07-19 20:26:01 +04:00
|
|
|
mfsp->mfs_shutdown = 0;
|
2002-07-21 19:32:17 +04:00
|
|
|
bufq_alloc(&mfsp->mfs_buflist, BUFQ_FCFS);
|
2003-06-30 02:28:00 +04:00
|
|
|
if ((error = ffs_mountfs(rootvp, mp, p)) != 0) {
|
1998-03-01 05:20:01 +03:00
|
|
|
mp->mnt_op->vfs_refcount--;
|
|
|
|
vfs_unbusy(mp);
|
2002-07-21 19:32:17 +04:00
|
|
|
bufq_free(&mfsp->mfs_buflist);
|
1994-06-08 15:41:58 +04:00
|
|
|
free(mp, M_MOUNT);
|
|
|
|
free(mfsp, M_MFSNODE);
|
1999-07-17 05:08:28 +04:00
|
|
|
vrele(rootvp);
|
1994-06-08 15:41:58 +04:00
|
|
|
return (error);
|
1998-03-01 05:20:01 +03:00
|
|
|
}
|
|
|
|
simple_lock(&mountlist_slock);
|
1995-01-18 09:19:49 +03:00
|
|
|
CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
|
1998-03-01 05:20:01 +03:00
|
|
|
simple_unlock(&mountlist_slock);
|
1994-06-08 15:41:58 +04:00
|
|
|
mp->mnt_vnodecovered = NULLVP;
|
|
|
|
ump = VFSTOUFS(mp);
|
|
|
|
fs = ump->um_fs;
|
1998-03-01 05:20:01 +03:00
|
|
|
(void) copystr(mp->mnt_stat.f_mntonname, fs->fs_fsmnt, MNAMELEN - 1, 0);
|
2004-04-21 05:05:31 +04:00
|
|
|
(void)ffs_statvfs(mp, &mp->mnt_stat, p);
|
1998-03-01 05:20:01 +03:00
|
|
|
vfs_unbusy(mp);
|
1994-06-08 15:41:58 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called early in boot to set the base address and size
|
|
|
|
* of the mini-root.
|
|
|
|
*/
|
1996-02-10 01:31:27 +03:00
|
|
|
int
|
1994-06-08 15:41:58 +04:00
|
|
|
mfs_initminiroot(base)
|
|
|
|
caddr_t base;
|
|
|
|
{
|
2003-04-02 14:39:19 +04:00
|
|
|
struct fs *fs = (struct fs *)(base + SBLOCK_UFS1);
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
/* check for valid super block */
|
2003-04-02 14:39:19 +04:00
|
|
|
if (fs->fs_magic != FS_UFS1_MAGIC || fs->fs_bsize > MAXBSIZE ||
|
1994-06-08 15:41:58 +04:00
|
|
|
fs->fs_bsize < sizeof(struct fs))
|
|
|
|
return (0);
|
|
|
|
mountroot = mfs_mountroot;
|
|
|
|
mfs_rootbase = base;
|
|
|
|
mfs_rootsize = fs->fs_fsize * fs->fs_size;
|
2001-02-24 03:05:22 +03:00
|
|
|
rootdev = makedev(255, mfs_minor);
|
|
|
|
mfs_minor++;
|
1994-06-08 15:41:58 +04:00
|
|
|
return (mfs_rootsize);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* VFS Operations.
|
|
|
|
*
|
|
|
|
* mount system call
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2003-06-30 02:28:00 +04:00
|
|
|
mfs_mount(mp, path, data, ndp, p)
|
2000-03-30 16:41:09 +04:00
|
|
|
struct mount *mp;
|
1996-12-22 13:10:12 +03:00
|
|
|
const char *path;
|
|
|
|
void *data;
|
1994-06-08 15:41:58 +04:00
|
|
|
struct nameidata *ndp;
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p;
|
1994-06-08 15:41:58 +04:00
|
|
|
{
|
|
|
|
struct vnode *devvp;
|
|
|
|
struct mfs_args args;
|
|
|
|
struct ufsmount *ump;
|
2000-03-30 16:41:09 +04:00
|
|
|
struct fs *fs;
|
|
|
|
struct mfsnode *mfsp;
|
1994-06-08 15:41:58 +04:00
|
|
|
int flags, error;
|
|
|
|
|
2002-09-21 22:10:34 +04:00
|
|
|
if (mp->mnt_flag & MNT_GETARGS) {
|
|
|
|
struct vnode *vp;
|
|
|
|
struct mfsnode *mfsp;
|
|
|
|
|
|
|
|
ump = VFSTOUFS(mp);
|
|
|
|
if (ump == NULL)
|
|
|
|
return EIO;
|
|
|
|
|
|
|
|
vp = ump->um_devvp;
|
|
|
|
if (vp == NULL)
|
|
|
|
return EIO;
|
|
|
|
|
|
|
|
mfsp = VTOMFS(vp);
|
|
|
|
if (mfsp == NULL)
|
|
|
|
return EIO;
|
|
|
|
|
|
|
|
args.fspec = NULL;
|
|
|
|
vfs_showexport(mp, &args.export, &ump->um_export);
|
|
|
|
args.base = mfsp->mfs_baseoff;
|
|
|
|
args.size = mfsp->mfs_size;
|
|
|
|
return copyout(&args, data, sizeof(args));
|
|
|
|
}
|
2002-02-03 06:51:57 +03:00
|
|
|
/*
|
|
|
|
* XXX turn off async to avoid hangs when writing lots of data.
|
|
|
|
* the problem is that MFS needs to allocate pages to clean pages,
|
|
|
|
* so if we wait until the last minute to clean pages then there
|
|
|
|
* may not be any pages available to do the cleaning.
|
2002-10-24 20:41:00 +04:00
|
|
|
* ... and since the default partially-synchronous mode turns out
|
|
|
|
* to not be sufficient under heavy load, make it full synchronous.
|
2002-02-03 06:51:57 +03:00
|
|
|
*/
|
|
|
|
mp->mnt_flag &= ~MNT_ASYNC;
|
2002-10-24 20:41:00 +04:00
|
|
|
mp->mnt_flag |= MNT_SYNCHRONOUS;
|
2002-02-03 06:51:57 +03:00
|
|
|
|
1996-02-10 01:31:27 +03:00
|
|
|
error = copyin(data, (caddr_t)&args, sizeof (struct mfs_args));
|
|
|
|
if (error)
|
1994-06-08 15:41:58 +04:00
|
|
|
return (error);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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) {
|
|
|
|
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;
|
2003-06-30 02:28:00 +04:00
|
|
|
error = ffs_flushfiles(mp, flags, p);
|
1994-06-08 15:41:58 +04:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
}
|
2003-10-14 18:02:56 +04:00
|
|
|
if (fs->fs_ronly && (mp->mnt_iflag & IMNT_WANTRDWR))
|
1994-06-08 15:41:58 +04:00
|
|
|
fs->fs_ronly = 0;
|
|
|
|
if (args.fspec == 0)
|
|
|
|
return (vfs_export(mp, &ump->um_export, &args.export));
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
error = getnewvnode(VT_MFS, (struct mount *)0, mfs_vnodeop_p, &devvp);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
devvp->v_type = VBLK;
|
2001-02-24 03:05:22 +03:00
|
|
|
if (checkalias(devvp, makedev(255, mfs_minor), (struct mount *)0))
|
1994-06-08 15:41:58 +04:00
|
|
|
panic("mfs_mount: dup dev");
|
2001-02-24 03:05:22 +03:00
|
|
|
mfs_minor++;
|
1994-06-08 15:41:58 +04:00
|
|
|
mfsp = (struct mfsnode *)malloc(sizeof *mfsp, M_MFSNODE, M_WAITOK);
|
|
|
|
devvp->v_data = mfsp;
|
|
|
|
mfsp->mfs_baseoff = args.base;
|
|
|
|
mfsp->mfs_size = args.size;
|
|
|
|
mfsp->mfs_vnode = devvp;
|
2000-05-16 04:24:08 +04:00
|
|
|
mfsp->mfs_proc = p;
|
2002-07-19 20:26:01 +04:00
|
|
|
mfsp->mfs_shutdown = 0;
|
2002-07-21 19:32:17 +04:00
|
|
|
bufq_alloc(&mfsp->mfs_buflist, BUFQ_FCFS);
|
2003-06-30 02:28:00 +04:00
|
|
|
if ((error = ffs_mountfs(devvp, mp, p)) != 0) {
|
2002-07-19 20:26:01 +04:00
|
|
|
mfsp->mfs_shutdown = 1;
|
1994-06-08 15:41:58 +04:00
|
|
|
vrele(devvp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
ump = VFSTOUFS(mp);
|
|
|
|
fs = ump->um_fs;
|
2004-04-21 05:05:31 +04:00
|
|
|
error = set_statvfs_info(path, UIO_USERSPACE, args.fspec,
|
2003-06-30 02:28:00 +04:00
|
|
|
UIO_USERSPACE, mp, p);
|
2004-04-21 16:00:36 +04:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
(void)strncpy(fs->fs_fsmnt, mp->mnt_stat.f_mntonname,
|
|
|
|
sizeof(fs->fs_fsmnt));
|
|
|
|
fs->fs_fsmnt[sizeof(fs->fs_fsmnt) - 1] = '\0';
|
2004-04-21 11:58:02 +04:00
|
|
|
/* XXX: cleanup on error */
|
2004-04-21 16:00:36 +04:00
|
|
|
return 0;
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
*
|
2000-05-20 00:42:20 +04:00
|
|
|
* Loop servicing I/O requests.
|
|
|
|
* Copy the requested data into or out of the memory filesystem
|
|
|
|
* address space.
|
1994-06-08 15:41:58 +04:00
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2003-06-30 02:28:00 +04:00
|
|
|
mfs_start(mp, flags, p)
|
1994-06-08 15:41:58 +04:00
|
|
|
struct mount *mp;
|
|
|
|
int flags;
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p;
|
1994-06-08 15:41:58 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct vnode *vp = VFSTOUFS(mp)->um_devvp;
|
|
|
|
struct mfsnode *mfsp = VTOMFS(vp);
|
2000-05-20 00:42:20 +04:00
|
|
|
struct buf *bp;
|
|
|
|
caddr_t base;
|
1998-03-01 05:20:01 +03:00
|
|
|
int sleepreturn = 0;
|
2003-06-30 02:28:00 +04:00
|
|
|
struct lwp *l; /* XXX NJWLWP */
|
1994-06-08 15:41:58 +04:00
|
|
|
|
2003-06-30 02:28:00 +04:00
|
|
|
/* XXX NJWLWP the vnode interface again gives us a proc in a
|
|
|
|
* place where we want a execution context. Cheat.
|
|
|
|
*/
|
|
|
|
KASSERT(curproc == p);
|
|
|
|
l = curlwp;
|
2000-05-20 00:42:20 +04:00
|
|
|
base = mfsp->mfs_baseoff;
|
2002-07-19 20:26:01 +04:00
|
|
|
while (mfsp->mfs_shutdown != 1) {
|
|
|
|
while ((bp = BUFQ_GET(&mfsp->mfs_buflist)) != NULL) {
|
2000-10-13 21:59:11 +04:00
|
|
|
mfs_doio(bp, base);
|
|
|
|
wakeup((caddr_t)bp);
|
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* If a non-ignored signal is received, try to unmount.
|
1998-03-01 05:20:01 +03:00
|
|
|
* If that fails, or the filesystem is already in the
|
|
|
|
* process of being unmounted, clear the signal (it has been
|
|
|
|
* "processed"), otherwise we will loop here, as tsleep
|
|
|
|
* will always return EINTR/ERESTART.
|
1994-06-08 15:41:58 +04:00
|
|
|
*/
|
1998-03-01 05:20:01 +03:00
|
|
|
if (sleepreturn != 0) {
|
2001-04-17 02:41:09 +04:00
|
|
|
/*
|
|
|
|
* XXX Freeze syncer. Must do this before locking
|
|
|
|
* the mount point. See dounmount() for details.
|
|
|
|
*/
|
|
|
|
lockmgr(&syncer_lock, LK_EXCLUSIVE, NULL);
|
|
|
|
if (vfs_busy(mp, LK_NOWAIT, 0) != 0)
|
|
|
|
lockmgr(&syncer_lock, LK_RELEASE, NULL);
|
2003-06-30 02:28:00 +04:00
|
|
|
else if (dounmount(mp, 0, p) != 0)
|
|
|
|
CLRSIG(p, CURSIG(l));
|
1998-03-01 05:20:01 +03:00
|
|
|
sleepreturn = 0;
|
1997-02-22 06:25:05 +03:00
|
|
|
continue;
|
1995-09-01 23:39:18 +04:00
|
|
|
}
|
2000-05-20 00:42:20 +04:00
|
|
|
|
|
|
|
sleepreturn = tsleep(vp, mfs_pri, "mfsidl", 0);
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
2002-07-19 20:26:01 +04:00
|
|
|
KASSERT(BUFQ_PEEK(&mfsp->mfs_buflist) == NULL);
|
2002-07-21 19:32:17 +04:00
|
|
|
bufq_free(&mfsp->mfs_buflist);
|
1998-03-01 05:20:01 +03:00
|
|
|
return (sleepreturn);
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get file system statistics.
|
|
|
|
*/
|
1996-02-10 01:31:27 +03:00
|
|
|
int
|
2004-04-21 05:05:31 +04:00
|
|
|
mfs_statvfs(mp, sbp, p)
|
1994-06-08 15:41:58 +04:00
|
|
|
struct mount *mp;
|
2004-04-21 05:05:31 +04:00
|
|
|
struct statvfs *sbp;
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p;
|
1994-06-08 15:41:58 +04:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2004-04-21 05:05:31 +04:00
|
|
|
error = ffs_statvfs(mp, sbp, p);
|
2004-04-21 16:00:36 +04:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
(void)strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name,
|
|
|
|
sizeof(sbp->f_fstypename));
|
|
|
|
sbp->f_fstypename[sizeof(sbp->f_fstypename) - 1] = '\0';
|
|
|
|
return 0;
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|