2010-03-02 20:20:02 +03:00
|
|
|
/* $NetBSD: mfs_vfsops.c,v 1.102 2010/03/02 17:20:02 pooka 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>
|
2010-03-02 20:20:02 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: mfs_vfsops.c,v 1.102 2010/03/02 17:20:02 pooka 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>
|
2004-10-28 11:07:35 +04:00
|
|
|
#include <sys/bufq.h>
|
1994-06-08 15:41:58 +04:00
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/vnode.h>
|
2008-03-26 17:19:43 +03:00
|
|
|
#include <sys/kmem.h>
|
2008-05-10 06:26:09 +04:00
|
|
|
#include <sys/module.h>
|
1994-06-08 15:41:58 +04:00
|
|
|
|
2008-01-28 17:31:15 +03:00
|
|
|
#include <miscfs/genfs/genfs.h>
|
2008-01-25 13:30:20 +03:00
|
|
|
#include <miscfs/specfs/specdev.h>
|
2001-04-17 02:41:09 +04:00
|
|
|
|
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>
|
|
|
|
|
2008-11-13 14:10:41 +03:00
|
|
|
MODULE(MODULE_CLASS_VFS, mfs, "ffs");
|
2008-05-10 06:26:09 +04:00
|
|
|
|
2008-03-26 17:19:43 +03:00
|
|
|
kmutex_t mfs_lock; /* global lock */
|
1994-06-08 15:41:58 +04:00
|
|
|
|
2010-03-02 20:20:02 +03:00
|
|
|
/* used for building internal dev_t, minor == 0 reserved for miniroot */
|
|
|
|
static int mfs_minor = 1;
|
2008-03-26 17:19:43 +03:00
|
|
|
static int mfs_initcnt;
|
1994-06-08 15:41:58 +04:00
|
|
|
|
2005-08-31 02:01:12 +04:00
|
|
|
extern int (**mfs_vnodeop_p)(void *);
|
1994-06-08 15:41:58 +04:00
|
|
|
|
2008-06-28 05:34:05 +04:00
|
|
|
static struct sysctllog *mfs_sysctl_log;
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* mfs vfs operations.
|
|
|
|
*/
|
1998-02-18 10:05:47 +03:00
|
|
|
|
2005-02-27 01:31:44 +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,
|
2007-07-12 23:35:32 +04:00
|
|
|
sizeof (struct mfs_args),
|
1994-06-08 15:41:58 +04:00
|
|
|
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,
|
2004-05-25 18:54:55 +04:00
|
|
|
(int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
|
2005-01-02 19:08:28 +03:00
|
|
|
vfs_stdextattrctl,
|
2007-07-27 02:57:36 +04:00
|
|
|
(void *)eopnotsupp, /* vfs_suspendctl */
|
2008-01-28 17:31:15 +03:00
|
|
|
genfs_renamelock_enter,
|
|
|
|
genfs_renamelock_exit,
|
2008-04-29 22:18:08 +04:00
|
|
|
(void *)eopnotsupp,
|
1998-02-18 10:05:47 +03:00
|
|
|
mfs_vnodeopv_descs,
|
2006-09-02 11:04:01 +04:00
|
|
|
0,
|
|
|
|
{ NULL, NULL },
|
1994-06-08 15:41:58 +04:00
|
|
|
};
|
2008-05-10 06:26:09 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
mfs_modcmd(modcmd_t cmd, void *arg)
|
|
|
|
{
|
2008-06-28 05:34:05 +04:00
|
|
|
int error;
|
2008-05-10 06:26:09 +04:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case MODULE_CMD_INIT:
|
2008-06-28 05:34:05 +04:00
|
|
|
error = vfs_attach(&mfs_vfsops);
|
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
sysctl_createv(&mfs_sysctl_log, 0, NULL, NULL,
|
|
|
|
CTLFLAG_PERMANENT,
|
|
|
|
CTLTYPE_NODE, "vfs", NULL,
|
|
|
|
NULL, 0, NULL, 0,
|
|
|
|
CTL_VFS, CTL_EOL);
|
|
|
|
sysctl_createv(&mfs_sysctl_log, 0, NULL, NULL,
|
|
|
|
CTLFLAG_PERMANENT|CTLFLAG_ALIAS,
|
|
|
|
CTLTYPE_NODE, "mfs",
|
|
|
|
SYSCTL_DESCR("Memory based file system"),
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
break;
|
2008-05-10 06:26:09 +04:00
|
|
|
case MODULE_CMD_FINI:
|
2008-06-28 05:34:05 +04:00
|
|
|
error = vfs_detach(&mfs_vfsops);
|
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
sysctl_teardown(&mfs_sysctl_log);
|
|
|
|
break;
|
2008-05-10 06:26:09 +04:00
|
|
|
default:
|
2008-06-28 05:34:05 +04:00
|
|
|
error = ENOTTY;
|
|
|
|
break;
|
2008-05-10 06:26:09 +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
|
|
|
|
2008-06-28 05:34:05 +04:00
|
|
|
return (error);
|
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
|
|
|
}
|
|
|
|
|
2005-02-27 01:31:44 +03:00
|
|
|
/*
|
1998-03-01 05:20:01 +03:00
|
|
|
* Memory based filesystem initialization.
|
2005-02-27 01:31:44 +03:00
|
|
|
*/
|
1998-03-01 05:20:01 +03:00
|
|
|
void
|
2005-08-31 02:01:12 +04:00
|
|
|
mfs_init(void)
|
1998-03-01 05:20:01 +03:00
|
|
|
{
|
2007-06-30 13:37:53 +04:00
|
|
|
|
2008-03-26 17:19:43 +03:00
|
|
|
if (mfs_initcnt++ == 0) {
|
|
|
|
mutex_init(&mfs_lock, MUTEX_DEFAULT, IPL_NONE);
|
|
|
|
ffs_init();
|
|
|
|
}
|
1998-03-01 05:20:01 +03:00
|
|
|
}
|
|
|
|
|
2001-09-15 20:12:54 +04:00
|
|
|
void
|
2005-08-31 02:01:12 +04:00
|
|
|
mfs_reinit(void)
|
2001-09-15 20:12:54 +04:00
|
|
|
{
|
2008-03-26 17:19:43 +03:00
|
|
|
|
2001-09-15 20:12:54 +04:00
|
|
|
ffs_reinit();
|
|
|
|
}
|
|
|
|
|
2000-03-16 21:20:06 +03:00
|
|
|
void
|
2005-08-31 02:01:12 +04:00
|
|
|
mfs_done(void)
|
2000-03-16 21:20:06 +03:00
|
|
|
{
|
2008-03-26 17:19:43 +03:00
|
|
|
|
|
|
|
if (--mfs_initcnt == 0) {
|
|
|
|
ffs_done();
|
|
|
|
mutex_destroy(&mfs_lock);
|
|
|
|
}
|
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
|
2005-08-31 02:01:12 +04:00
|
|
|
mfs_mountroot(void)
|
1994-06-08 15:41:58 +04:00
|
|
|
{
|
1998-03-01 05:20:01 +03:00
|
|
|
struct fs *fs;
|
|
|
|
struct mount *mp;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *l = curlwp; /* 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
|
|
|
|
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
|
|
|
|
2008-03-26 17:19:43 +03:00
|
|
|
mfsp = kmem_alloc(sizeof(*mfsp), KM_SLEEP);
|
1994-06-08 15:41:58 +04:00
|
|
|
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;
|
2008-03-26 17:19:43 +03:00
|
|
|
cv_init(&mfsp->mfs_cv, "mfs");
|
|
|
|
mfsp->mfs_refcnt = 1;
|
2005-10-15 21:29:10 +04:00
|
|
|
bufq_alloc(&mfsp->mfs_buflist, "fcfs", 0);
|
2005-12-11 15:16:03 +03:00
|
|
|
if ((error = ffs_mountfs(rootvp, mp, l)) != 0) {
|
2008-04-30 16:49:16 +04:00
|
|
|
vfs_unbusy(mp, false, NULL);
|
2005-10-15 21:29:10 +04:00
|
|
|
bufq_free(mfsp->mfs_buflist);
|
PR kern/38141 lookup/vfs_busy acquire rwlock recursively
Simplify the mount locking. Remove all the crud to deal with recursion on
the mount lock, and crud to deal with unmount as another weirdo lock.
Hopefully this will once and for all fix the deadlocks with this. With this
commit there are two locks on each mount:
- krwlock_t mnt_unmounting. This is used to prevent unmount across critical
sections like getnewvnode(). It's only ever read locked with rw_tryenter(),
and is only ever write locked in dounmount(). A write hold can't be taken
on this lock if the current LWP could hold a vnode lock.
- kmutex_t mnt_updating. This is taken by threads updating the mount, for
example when going r/o -> r/w, and is only present to serialize updates.
In order to take this lock, a read hold must first be taken on
mnt_unmounting, and the two need to be held across the operation.
One effect of this change: previously if an unmount failed, we would make a
half hearted attempt to back out of it gracefully, but that was unlikely to
work in a lot of cases. Now while an unmount that will be aborted is in
progress, new file operations within the mount will fail instead of being
delayed. That is unlikely to be a problem though, because if the admin
requests unmount of a file system then s(he) has made a decision to deny
access to the resource.
2008-05-06 22:43:44 +04:00
|
|
|
vfs_destroy(mp);
|
2008-03-26 17:19:43 +03:00
|
|
|
kmem_free(mfsp, sizeof(*mfsp));
|
1994-06-08 15:41:58 +04:00
|
|
|
return (error);
|
2005-02-27 01:31:44 +03:00
|
|
|
}
|
2007-10-11 00:42:20 +04:00
|
|
|
mutex_enter(&mountlist_lock);
|
1995-01-18 09:19:49 +03:00
|
|
|
CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
|
2007-10-11 00:42:20 +04:00
|
|
|
mutex_exit(&mountlist_lock);
|
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);
|
2007-11-26 22:01:26 +03:00
|
|
|
(void)ffs_statvfs(mp, &mp->mnt_stat);
|
2008-04-30 16:49:16 +04:00
|
|
|
vfs_unbusy(mp, false, NULL);
|
1994-06-08 15:41:58 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* VFS Operations.
|
|
|
|
*
|
|
|
|
* mount system call
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2007-11-26 22:01:26 +03:00
|
|
|
mfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
|
1994-06-08 15:41:58 +04:00
|
|
|
{
|
2007-11-26 22:01:26 +03:00
|
|
|
struct lwp *l = curlwp;
|
1994-06-08 15:41:58 +04:00
|
|
|
struct vnode *devvp;
|
2007-07-12 23:35:32 +04:00
|
|
|
struct mfs_args *args = data;
|
1994-06-08 15:41:58 +04:00
|
|
|
struct ufsmount *ump;
|
2000-03-30 16:41:09 +04:00
|
|
|
struct fs *fs;
|
|
|
|
struct mfsnode *mfsp;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct proc *p;
|
2007-07-12 23:35:32 +04:00
|
|
|
int flags, error = 0;
|
|
|
|
|
|
|
|
if (*data_len < sizeof *args)
|
|
|
|
return EINVAL;
|
1994-06-08 15:41:58 +04:00
|
|
|
|
2005-12-11 15:16:03 +03:00
|
|
|
p = l->l_proc;
|
2002-09-21 22:10:34 +04:00
|
|
|
if (mp->mnt_flag & MNT_GETARGS) {
|
|
|
|
struct vnode *vp;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2007-07-12 23:35:32 +04:00
|
|
|
args->fspec = NULL;
|
|
|
|
args->base = mfsp->mfs_baseoff;
|
|
|
|
args->size = mfsp->mfs_size;
|
|
|
|
*data_len = sizeof *args;
|
|
|
|
return 0;
|
2002-09-21 22:10:34 +04:00
|
|
|
}
|
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
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* 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;
|
2005-12-11 15:16:03 +03:00
|
|
|
error = ffs_flushfiles(mp, flags, l);
|
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;
|
2007-07-12 23:35:32 +04:00
|
|
|
if (args->fspec == NULL)
|
Apply the NFS exports list rototill patch:
- Remove all NFS related stuff from file system specific code.
- Drop the vfs_checkexp hook and generalize it in the new nfs_check_export
function, thus removing redundancy from all file systems.
- Move all NFS export-related stuff from kern/vfs_subr.c to the new
file sys/nfs/nfs_export.c. The former was becoming large and its code
is always compiled, regardless of the build options. Using the latter,
the code is only compiled in when NFSSERVER is enabled. While doing this,
also make some functions in nfs_subs.c conditional to NFSSERVER.
- Add a new command in nfssvc(2), called NFSSVC_SETEXPORTSLIST, that takes a
path and a set of export entries. At the moment it can only clear the
exports list or append entries, one by one, but it is done in a way that
allows setting the whole set of entries atomically in the future (see the
comment in mountd_set_exports_list or in doc/TODO).
- Change mountd(8) to use the nfssvc(2) system call instead of mount(2) so
that it becomes file system agnostic. In fact, all this whole thing was
done to remove a 'XXX' block from this utility!
- Change the mount*, newfs and fsck* userland utilities to not deal with NFS
exports initialization; done internally by the kernel when initializing
the NFS support for each file system.
- Implement an interface for VFS (called VFS hooks) so that several kernel
subsystems can run arbitrary code upon receipt of specific VFS events.
At the moment, this only provides support for unmount and is used to
destroy NFS exports lists from the file systems being unmounted, though it
has room for extension.
Thanks go to yamt@, chs@, thorpej@, wrstuden@ and others for their comments
and advice in the development of this patch.
2005-09-23 16:10:31 +04:00
|
|
|
return EINVAL;
|
1994-06-08 15:41:58 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
error = getnewvnode(VT_MFS, (struct mount *)0, mfs_vnodeop_p, &devvp);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
2008-02-21 17:10:57 +03:00
|
|
|
devvp->v_vflag |= VV_MPSAFE;
|
1994-06-08 15:41:58 +04:00
|
|
|
devvp->v_type = VBLK;
|
2008-01-25 13:30:20 +03:00
|
|
|
spec_node_init(devvp, makedev(255, mfs_minor));
|
2001-02-24 03:05:22 +03:00
|
|
|
mfs_minor++;
|
2008-03-26 17:19:43 +03:00
|
|
|
mfsp = kmem_alloc(sizeof(*mfsp), KM_SLEEP);
|
1994-06-08 15:41:58 +04:00
|
|
|
devvp->v_data = mfsp;
|
2007-07-12 23:35:32 +04:00
|
|
|
mfsp->mfs_baseoff = args->base;
|
|
|
|
mfsp->mfs_size = args->size;
|
1994-06-08 15:41:58 +04:00
|
|
|
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;
|
2008-02-21 17:10:57 +03:00
|
|
|
cv_init(&mfsp->mfs_cv, "mfsidl");
|
2008-03-26 17:19:43 +03:00
|
|
|
mfsp->mfs_refcnt = 1;
|
2005-10-15 21:29:10 +04:00
|
|
|
bufq_alloc(&mfsp->mfs_buflist, "fcfs", 0);
|
2005-12-11 15:16:03 +03:00
|
|
|
if ((error = ffs_mountfs(devvp, mp, l)) != 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;
|
2007-07-12 23:35:32 +04:00
|
|
|
error = set_statvfs_info(path, UIO_USERSPACE, args->fspec,
|
2007-07-17 15:19:31 +04:00
|
|
|
UIO_USERSPACE, mp->mnt_op->vfs_name, mp, l);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2007-11-26 22:01:26 +03:00
|
|
|
mfs_start(struct mount *mp, int flags)
|
1994-06-08 15:41:58 +04:00
|
|
|
{
|
2008-03-26 17:19:43 +03:00
|
|
|
struct vnode *vp;
|
|
|
|
struct mfsnode *mfsp;
|
2007-02-10 00:55:00 +03:00
|
|
|
struct proc *p;
|
2000-05-20 00:42:20 +04:00
|
|
|
struct buf *bp;
|
2007-03-04 08:59:00 +03:00
|
|
|
void *base;
|
2008-03-26 17:19:43 +03:00
|
|
|
int sleepreturn = 0, refcnt, error;
|
2007-02-10 00:55:00 +03:00
|
|
|
ksiginfoq_t kq;
|
1994-06-08 15:41:58 +04:00
|
|
|
|
2008-03-26 17:19:43 +03:00
|
|
|
/*
|
|
|
|
* Ensure that file system is still mounted when getting mfsnode.
|
|
|
|
* Add a reference to the mfsnode to prevent it disappearing in
|
|
|
|
* this routine.
|
|
|
|
*/
|
PR kern/38141 lookup/vfs_busy acquire rwlock recursively
Simplify the mount locking. Remove all the crud to deal with recursion on
the mount lock, and crud to deal with unmount as another weirdo lock.
Hopefully this will once and for all fix the deadlocks with this. With this
commit there are two locks on each mount:
- krwlock_t mnt_unmounting. This is used to prevent unmount across critical
sections like getnewvnode(). It's only ever read locked with rw_tryenter(),
and is only ever write locked in dounmount(). A write hold can't be taken
on this lock if the current LWP could hold a vnode lock.
- kmutex_t mnt_updating. This is taken by threads updating the mount, for
example when going r/o -> r/w, and is only present to serialize updates.
In order to take this lock, a read hold must first be taken on
mnt_unmounting, and the two need to be held across the operation.
One effect of this change: previously if an unmount failed, we would make a
half hearted attempt to back out of it gracefully, but that was unlikely to
work in a lot of cases. Now while an unmount that will be aborted is in
progress, new file operations within the mount will fail instead of being
delayed. That is unlikely to be a problem though, because if the admin
requests unmount of a file system then s(he) has made a decision to deny
access to the resource.
2008-05-06 22:43:44 +04:00
|
|
|
if ((error = vfs_busy(mp, NULL)) != 0)
|
2008-03-26 17:19:43 +03:00
|
|
|
return error;
|
|
|
|
vp = VFSTOUFS(mp)->um_devvp;
|
|
|
|
mfsp = VTOMFS(vp);
|
|
|
|
mutex_enter(&mfs_lock);
|
|
|
|
mfsp->mfs_refcnt++;
|
|
|
|
mutex_exit(&mfs_lock);
|
2008-04-30 16:49:16 +04:00
|
|
|
vfs_unbusy(mp, false, NULL);
|
2008-03-26 17:19:43 +03:00
|
|
|
|
2000-05-20 00:42:20 +04:00
|
|
|
base = mfsp->mfs_baseoff;
|
2008-03-26 17:19:43 +03:00
|
|
|
mutex_enter(&mfs_lock);
|
2002-07-19 20:26:01 +04:00
|
|
|
while (mfsp->mfs_shutdown != 1) {
|
2009-01-13 16:33:58 +03:00
|
|
|
while ((bp = bufq_get(mfsp->mfs_buflist)) != NULL) {
|
2008-03-26 17:19:43 +03:00
|
|
|
mutex_exit(&mfs_lock);
|
2000-10-13 21:59:11 +04:00
|
|
|
mfs_doio(bp, base);
|
2008-03-26 17:19:43 +03:00
|
|
|
mutex_enter(&mfs_lock);
|
2000-10-13 21:59:11 +04:00
|
|
|
}
|
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) {
|
2008-03-26 17:19:43 +03:00
|
|
|
mutex_exit(&mfs_lock);
|
PR kern/38141 lookup/vfs_busy acquire rwlock recursively
Simplify the mount locking. Remove all the crud to deal with recursion on
the mount lock, and crud to deal with unmount as another weirdo lock.
Hopefully this will once and for all fix the deadlocks with this. With this
commit there are two locks on each mount:
- krwlock_t mnt_unmounting. This is used to prevent unmount across critical
sections like getnewvnode(). It's only ever read locked with rw_tryenter(),
and is only ever write locked in dounmount(). A write hold can't be taken
on this lock if the current LWP could hold a vnode lock.
- kmutex_t mnt_updating. This is taken by threads updating the mount, for
example when going r/o -> r/w, and is only present to serialize updates.
In order to take this lock, a read hold must first be taken on
mnt_unmounting, and the two need to be held across the operation.
One effect of this change: previously if an unmount failed, we would make a
half hearted attempt to back out of it gracefully, but that was unlikely to
work in a lot of cases. Now while an unmount that will be aborted is in
progress, new file operations within the mount will fail instead of being
delayed. That is unlikely to be a problem though, because if the admin
requests unmount of a file system then s(he) has made a decision to deny
access to the resource.
2008-05-06 22:43:44 +04:00
|
|
|
if (dounmount(mp, 0, curlwp) != 0) {
|
2008-03-26 17:19:43 +03:00
|
|
|
p = curproc;
|
2007-02-10 00:55:00 +03:00
|
|
|
ksiginfo_queue_init(&kq);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_enter(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
sigclearall(p, NULL, &kq);
|
2008-04-24 22:39:20 +04:00
|
|
|
mutex_exit(p->p_lock);
|
2007-02-10 00:55:00 +03:00
|
|
|
ksiginfo_queue_drain(&kq);
|
|
|
|
}
|
1998-03-01 05:20:01 +03:00
|
|
|
sleepreturn = 0;
|
2008-03-26 17:19:43 +03:00
|
|
|
mutex_enter(&mfs_lock);
|
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
|
|
|
|
2008-03-26 17:19:43 +03:00
|
|
|
sleepreturn = cv_wait_sig(&mfsp->mfs_cv, &mfs_lock);
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
2009-01-13 16:33:58 +03:00
|
|
|
KASSERT(bufq_peek(mfsp->mfs_buflist) == NULL);
|
2008-03-26 17:19:43 +03:00
|
|
|
refcnt = --mfsp->mfs_refcnt;
|
|
|
|
mutex_exit(&mfs_lock);
|
|
|
|
if (refcnt == 0) {
|
|
|
|
bufq_free(mfsp->mfs_buflist);
|
|
|
|
cv_destroy(&mfsp->mfs_cv);
|
|
|
|
kmem_free(mfsp, sizeof(*mfsp));
|
|
|
|
}
|
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
|
2007-11-26 22:01:26 +03:00
|
|
|
mfs_statvfs(struct mount *mp, struct statvfs *sbp)
|
1994-06-08 15:41:58 +04:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2007-11-26 22:01:26 +03:00
|
|
|
error = ffs_statvfs(mp, sbp);
|
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
|
|
|
}
|