Home | History | Annotate | Line # | Download | only in mfs
mfs_vfsops.c revision 1.99
      1  1.99        ad /*	$NetBSD: mfs_vfsops.c,v 1.99 2008/11/13 11:10:41 ad Exp $	*/
      2   1.2       cgd 
      3   1.1   mycroft /*
      4   1.1   mycroft  * Copyright (c) 1989, 1990, 1993, 1994
      5   1.1   mycroft  *	The Regents of the University of California.  All rights reserved.
      6   1.1   mycroft  *
      7   1.1   mycroft  * Redistribution and use in source and binary forms, with or without
      8   1.1   mycroft  * modification, are permitted provided that the following conditions
      9   1.1   mycroft  * are met:
     10   1.1   mycroft  * 1. Redistributions of source code must retain the above copyright
     11   1.1   mycroft  *    notice, this list of conditions and the following disclaimer.
     12   1.1   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1   mycroft  *    notice, this list of conditions and the following disclaimer in the
     14   1.1   mycroft  *    documentation and/or other materials provided with the distribution.
     15  1.52       agc  * 3. Neither the name of the University nor the names of its contributors
     16   1.1   mycroft  *    may be used to endorse or promote products derived from this software
     17   1.1   mycroft  *    without specific prior written permission.
     18   1.1   mycroft  *
     19   1.1   mycroft  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20   1.1   mycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21   1.1   mycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22   1.1   mycroft  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23   1.1   mycroft  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24   1.1   mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25   1.1   mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26   1.1   mycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27   1.1   mycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28   1.1   mycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29   1.1   mycroft  * SUCH DAMAGE.
     30   1.1   mycroft  *
     31  1.15      fvdl  *	@(#)mfs_vfsops.c	8.11 (Berkeley) 6/19/95
     32   1.1   mycroft  */
     33  1.36     lukem 
     34  1.36     lukem #include <sys/cdefs.h>
     35  1.99        ad __KERNEL_RCSID(0, "$NetBSD: mfs_vfsops.c,v 1.99 2008/11/13 11:10:41 ad Exp $");
     36  1.17  jonathan 
     37  1.34       mrg #if defined(_KERNEL_OPT)
     38  1.17  jonathan #include "opt_compat_netbsd.h"
     39  1.17  jonathan #endif
     40   1.1   mycroft 
     41   1.1   mycroft #include <sys/param.h>
     42   1.1   mycroft #include <sys/systm.h>
     43  1.54    atatat #include <sys/sysctl.h>
     44   1.1   mycroft #include <sys/time.h>
     45   1.1   mycroft #include <sys/kernel.h>
     46   1.1   mycroft #include <sys/proc.h>
     47   1.1   mycroft #include <sys/buf.h>
     48  1.62      yamt #include <sys/bufq.h>
     49   1.1   mycroft #include <sys/mount.h>
     50   1.1   mycroft #include <sys/signalvar.h>
     51   1.1   mycroft #include <sys/vnode.h>
     52  1.91        ad #include <sys/kmem.h>
     53  1.97    rumble #include <sys/module.h>
     54   1.1   mycroft 
     55  1.88  dholland #include <miscfs/genfs/genfs.h>
     56  1.87     pooka #include <miscfs/specfs/specdev.h>
     57  1.33   thorpej 
     58   1.1   mycroft #include <ufs/ufs/quota.h>
     59   1.1   mycroft #include <ufs/ufs/inode.h>
     60   1.1   mycroft #include <ufs/ufs/ufsmount.h>
     61   1.1   mycroft #include <ufs/ufs/ufs_extern.h>
     62   1.1   mycroft 
     63   1.1   mycroft #include <ufs/ffs/fs.h>
     64   1.1   mycroft #include <ufs/ffs/ffs_extern.h>
     65   1.1   mycroft 
     66   1.1   mycroft #include <ufs/mfs/mfsnode.h>
     67   1.1   mycroft #include <ufs/mfs/mfs_extern.h>
     68   1.1   mycroft 
     69  1.99        ad MODULE(MODULE_CLASS_VFS, mfs, "ffs");
     70  1.97    rumble 
     71  1.78  christos void *	mfs_rootbase;	/* address of mini-root in kernel virtual memory */
     72   1.1   mycroft u_long	mfs_rootsize;	/* size of mini-root in bytes */
     73  1.91        ad kmutex_t mfs_lock;	/* global lock */
     74   1.1   mycroft 
     75  1.91        ad static int mfs_minor;	/* used for building internal dev_t */
     76  1.91        ad static int mfs_initcnt;
     77   1.1   mycroft 
     78  1.68   xtraeme extern int (**mfs_vnodeop_p)(void *);
     79  1.44   thorpej 
     80  1.98    rumble static struct sysctllog *mfs_sysctl_log;
     81  1.98    rumble 
     82   1.1   mycroft /*
     83   1.1   mycroft  * mfs vfs operations.
     84   1.1   mycroft  */
     85  1.14   thorpej 
     86  1.65     perry extern const struct vnodeopv_desc mfs_vnodeop_opv_desc;
     87  1.14   thorpej 
     88  1.31  jdolecek const struct vnodeopv_desc * const mfs_vnodeopv_descs[] = {
     89  1.14   thorpej 	&mfs_vnodeop_opv_desc,
     90  1.14   thorpej 	NULL,
     91  1.14   thorpej };
     92  1.14   thorpej 
     93   1.1   mycroft struct vfsops mfs_vfsops = {
     94   1.1   mycroft 	MOUNT_MFS,
     95  1.80       dsl 	sizeof (struct mfs_args),
     96   1.1   mycroft 	mfs_mount,
     97   1.1   mycroft 	mfs_start,
     98   1.1   mycroft 	ffs_unmount,
     99   1.1   mycroft 	ufs_root,
    100   1.1   mycroft 	ufs_quotactl,
    101  1.56  christos 	mfs_statvfs,
    102   1.1   mycroft 	ffs_sync,
    103   1.1   mycroft 	ffs_vget,
    104   1.1   mycroft 	ffs_fhtovp,
    105   1.1   mycroft 	ffs_vptofh,
    106   1.1   mycroft 	mfs_init,
    107  1.35       chs 	mfs_reinit,
    108  1.23  jdolecek 	mfs_done,
    109  1.54    atatat 	NULL,
    110  1.60   hannken 	(int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
    111  1.63   thorpej 	vfs_stdextattrctl,
    112  1.82     pooka 	(void *)eopnotsupp,	/* vfs_suspendctl */
    113  1.88  dholland 	genfs_renamelock_enter,
    114  1.88  dholland 	genfs_renamelock_exit,
    115  1.93        ad 	(void *)eopnotsupp,
    116  1.14   thorpej 	mfs_vnodeopv_descs,
    117  1.73  christos 	0,
    118  1.73  christos 	{ NULL, NULL },
    119   1.1   mycroft };
    120  1.97    rumble 
    121  1.97    rumble static int
    122  1.97    rumble mfs_modcmd(modcmd_t cmd, void *arg)
    123  1.97    rumble {
    124  1.98    rumble 	int error;
    125  1.97    rumble 
    126  1.97    rumble 	switch (cmd) {
    127  1.97    rumble 	case MODULE_CMD_INIT:
    128  1.98    rumble 		error = vfs_attach(&mfs_vfsops);
    129  1.98    rumble 		if (error != 0)
    130  1.98    rumble 			break;
    131  1.98    rumble 		sysctl_createv(&mfs_sysctl_log, 0, NULL, NULL,
    132  1.98    rumble 			       CTLFLAG_PERMANENT,
    133  1.98    rumble 			       CTLTYPE_NODE, "vfs", NULL,
    134  1.98    rumble 			       NULL, 0, NULL, 0,
    135  1.98    rumble 			       CTL_VFS, CTL_EOL);
    136  1.98    rumble 		sysctl_createv(&mfs_sysctl_log, 0, NULL, NULL,
    137  1.98    rumble 			       CTLFLAG_PERMANENT|CTLFLAG_ALIAS,
    138  1.98    rumble 			       CTLTYPE_NODE, "mfs",
    139  1.98    rumble 			       SYSCTL_DESCR("Memory based file system"),
    140  1.98    rumble 			       NULL, 1, NULL, 0,
    141  1.98    rumble 			       CTL_VFS, 3, CTL_EOL);
    142  1.98    rumble 		/*
    143  1.98    rumble 		 * XXX the "1" and the "3" above could be dynamic, thereby
    144  1.98    rumble 		 * eliminating one more instance of the "number to vfs"
    145  1.98    rumble 		 * mapping problem, but they are in order as taken from
    146  1.98    rumble 		 * sys/mount.h
    147  1.98    rumble 		 */
    148  1.98    rumble 		break;
    149  1.97    rumble 	case MODULE_CMD_FINI:
    150  1.98    rumble 		error = vfs_detach(&mfs_vfsops);
    151  1.98    rumble 		if (error != 0)
    152  1.98    rumble 			break;
    153  1.98    rumble 		sysctl_teardown(&mfs_sysctl_log);
    154  1.98    rumble 		break;
    155  1.97    rumble 	default:
    156  1.98    rumble 		error = ENOTTY;
    157  1.98    rumble 		break;
    158  1.97    rumble 	}
    159  1.54    atatat 
    160  1.98    rumble 	return (error);
    161  1.54    atatat }
    162   1.1   mycroft 
    163  1.65     perry /*
    164  1.15      fvdl  * Memory based filesystem initialization.
    165  1.65     perry  */
    166  1.15      fvdl void
    167  1.68   xtraeme mfs_init(void)
    168  1.15      fvdl {
    169  1.79     pooka 
    170  1.91        ad 	if (mfs_initcnt++ == 0) {
    171  1.91        ad 		mutex_init(&mfs_lock, MUTEX_DEFAULT, IPL_NONE);
    172  1.91        ad 		ffs_init();
    173  1.91        ad 	}
    174  1.35       chs }
    175  1.35       chs 
    176  1.35       chs void
    177  1.68   xtraeme mfs_reinit(void)
    178  1.35       chs {
    179  1.91        ad 
    180  1.35       chs 	ffs_reinit();
    181  1.15      fvdl }
    182  1.15      fvdl 
    183  1.23  jdolecek void
    184  1.68   xtraeme mfs_done(void)
    185  1.23  jdolecek {
    186  1.91        ad 
    187  1.91        ad 	if (--mfs_initcnt == 0) {
    188  1.91        ad 		ffs_done();
    189  1.91        ad 		mutex_destroy(&mfs_lock);
    190  1.91        ad 	}
    191  1.23  jdolecek }
    192  1.15      fvdl 
    193   1.1   mycroft /*
    194   1.1   mycroft  * Called by main() when mfs is going to be mounted as root.
    195   1.1   mycroft  */
    196   1.1   mycroft 
    197  1.10  christos int
    198  1.68   xtraeme mfs_mountroot(void)
    199   1.1   mycroft {
    200  1.15      fvdl 	struct fs *fs;
    201  1.15      fvdl 	struct mount *mp;
    202  1.71  christos 	struct lwp *l = curlwp;		/* XXX */
    203   1.1   mycroft 	struct ufsmount *ump;
    204   1.1   mycroft 	struct mfsnode *mfsp;
    205  1.15      fvdl 	int error = 0;
    206   1.1   mycroft 
    207  1.21  wrstuden 	if ((error = vfs_rootmountalloc(MOUNT_MFS, "mfs_root", &mp))) {
    208  1.21  wrstuden 		vrele(rootvp);
    209  1.15      fvdl 		return (error);
    210  1.21  wrstuden 	}
    211   1.1   mycroft 
    212  1.91        ad 	mfsp = kmem_alloc(sizeof(*mfsp), KM_SLEEP);
    213   1.1   mycroft 	rootvp->v_data = mfsp;
    214   1.1   mycroft 	rootvp->v_op = mfs_vnodeop_p;
    215   1.1   mycroft 	rootvp->v_tag = VT_MFS;
    216   1.1   mycroft 	mfsp->mfs_baseoff = mfs_rootbase;
    217   1.1   mycroft 	mfsp->mfs_size = mfs_rootsize;
    218   1.1   mycroft 	mfsp->mfs_vnode = rootvp;
    219  1.26   thorpej 	mfsp->mfs_proc = NULL;		/* indicate kernel space */
    220  1.39   hannken 	mfsp->mfs_shutdown = 0;
    221  1.91        ad 	cv_init(&mfsp->mfs_cv, "mfs");
    222  1.91        ad 	mfsp->mfs_refcnt = 1;
    223  1.70      yamt 	bufq_alloc(&mfsp->mfs_buflist, "fcfs", 0);
    224  1.71  christos 	if ((error = ffs_mountfs(rootvp, mp, l)) != 0) {
    225  1.95        ad 		vfs_unbusy(mp, false, NULL);
    226  1.70      yamt 		bufq_free(mfsp->mfs_buflist);
    227  1.96        ad 		vfs_destroy(mp);
    228  1.91        ad 		kmem_free(mfsp, sizeof(*mfsp));
    229   1.1   mycroft 		return (error);
    230  1.65     perry 	}
    231  1.84        ad 	mutex_enter(&mountlist_lock);
    232   1.4   mycroft 	CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
    233  1.84        ad 	mutex_exit(&mountlist_lock);
    234   1.1   mycroft 	mp->mnt_vnodecovered = NULLVP;
    235   1.1   mycroft 	ump = VFSTOUFS(mp);
    236   1.1   mycroft 	fs = ump->um_fs;
    237  1.15      fvdl 	(void) copystr(mp->mnt_stat.f_mntonname, fs->fs_fsmnt, MNAMELEN - 1, 0);
    238  1.85     pooka 	(void)ffs_statvfs(mp, &mp->mnt_stat);
    239  1.95        ad 	vfs_unbusy(mp, false, NULL);
    240   1.1   mycroft 	return (0);
    241   1.1   mycroft }
    242   1.1   mycroft 
    243   1.1   mycroft /*
    244   1.1   mycroft  * This is called early in boot to set the base address and size
    245   1.1   mycroft  * of the mini-root.
    246   1.1   mycroft  */
    247  1.10  christos int
    248  1.78  christos mfs_initminiroot(void *base)
    249   1.1   mycroft {
    250  1.78  christos 	struct fs *fs = (struct fs *)((char *)base + SBLOCK_UFS1);
    251   1.1   mycroft 
    252   1.1   mycroft 	/* check for valid super block */
    253  1.45      fvdl 	if (fs->fs_magic != FS_UFS1_MAGIC || fs->fs_bsize > MAXBSIZE ||
    254   1.1   mycroft 	    fs->fs_bsize < sizeof(struct fs))
    255   1.1   mycroft 		return (0);
    256   1.1   mycroft 	mountroot = mfs_mountroot;
    257   1.1   mycroft 	mfs_rootbase = base;
    258   1.1   mycroft 	mfs_rootsize = fs->fs_fsize * fs->fs_size;
    259  1.32       cgd 	rootdev = makedev(255, mfs_minor);
    260  1.32       cgd 	mfs_minor++;
    261   1.1   mycroft 	return (mfs_rootsize);
    262   1.1   mycroft }
    263   1.1   mycroft 
    264   1.1   mycroft /*
    265   1.1   mycroft  * VFS Operations.
    266   1.1   mycroft  *
    267   1.1   mycroft  * mount system call
    268   1.1   mycroft  */
    269   1.1   mycroft /* ARGSUSED */
    270   1.1   mycroft int
    271  1.85     pooka mfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
    272   1.1   mycroft {
    273  1.85     pooka 	struct lwp *l = curlwp;
    274   1.1   mycroft 	struct vnode *devvp;
    275  1.80       dsl 	struct mfs_args *args = data;
    276   1.1   mycroft 	struct ufsmount *ump;
    277  1.25  augustss 	struct fs *fs;
    278  1.25  augustss 	struct mfsnode *mfsp;
    279  1.71  christos 	struct proc *p;
    280  1.80       dsl 	int flags, error = 0;
    281  1.80       dsl 
    282  1.80       dsl 	if (*data_len < sizeof *args)
    283  1.80       dsl 		return EINVAL;
    284  1.37       chs 
    285  1.71  christos 	p = l->l_proc;
    286  1.41  christos 	if (mp->mnt_flag & MNT_GETARGS) {
    287  1.41  christos 		struct vnode *vp;
    288  1.41  christos 
    289  1.41  christos 		ump = VFSTOUFS(mp);
    290  1.41  christos 		if (ump == NULL)
    291  1.41  christos 			return EIO;
    292  1.41  christos 
    293  1.41  christos 		vp = ump->um_devvp;
    294  1.41  christos 		if (vp == NULL)
    295  1.41  christos 			return EIO;
    296  1.41  christos 
    297  1.41  christos 		mfsp = VTOMFS(vp);
    298  1.41  christos 		if (mfsp == NULL)
    299  1.41  christos 			return EIO;
    300  1.41  christos 
    301  1.80       dsl 		args->fspec = NULL;
    302  1.80       dsl 		args->base = mfsp->mfs_baseoff;
    303  1.80       dsl 		args->size = mfsp->mfs_size;
    304  1.80       dsl 		*data_len = sizeof *args;
    305  1.80       dsl 		return 0;
    306  1.41  christos 	}
    307  1.37       chs 	/*
    308  1.37       chs 	 * XXX turn off async to avoid hangs when writing lots of data.
    309  1.37       chs 	 * the problem is that MFS needs to allocate pages to clean pages,
    310  1.37       chs 	 * so if we wait until the last minute to clean pages then there
    311  1.37       chs 	 * may not be any pages available to do the cleaning.
    312  1.42       chs 	 * ... and since the default partially-synchronous mode turns out
    313  1.42       chs 	 * to not be sufficient under heavy load, make it full synchronous.
    314  1.37       chs 	 */
    315  1.37       chs 	mp->mnt_flag &= ~MNT_ASYNC;
    316  1.42       chs 	mp->mnt_flag |= MNT_SYNCHRONOUS;
    317   1.1   mycroft 
    318   1.1   mycroft 	/*
    319   1.1   mycroft 	 * If updating, check whether changing from read-only to
    320   1.1   mycroft 	 * read/write; if there is no device name, that's all we do.
    321   1.1   mycroft 	 */
    322   1.1   mycroft 	if (mp->mnt_flag & MNT_UPDATE) {
    323   1.1   mycroft 		ump = VFSTOUFS(mp);
    324   1.1   mycroft 		fs = ump->um_fs;
    325   1.1   mycroft 		if (fs->fs_ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) {
    326   1.1   mycroft 			flags = WRITECLOSE;
    327   1.1   mycroft 			if (mp->mnt_flag & MNT_FORCE)
    328   1.1   mycroft 				flags |= FORCECLOSE;
    329  1.71  christos 			error = ffs_flushfiles(mp, flags, l);
    330   1.1   mycroft 			if (error)
    331   1.1   mycroft 				return (error);
    332   1.1   mycroft 		}
    333  1.53       dbj 		if (fs->fs_ronly && (mp->mnt_iflag & IMNT_WANTRDWR))
    334   1.1   mycroft 			fs->fs_ronly = 0;
    335  1.80       dsl 		if (args->fspec == NULL)
    336  1.69      jmmv 			return EINVAL;
    337   1.1   mycroft 		return (0);
    338   1.1   mycroft 	}
    339   1.1   mycroft 	error = getnewvnode(VT_MFS, (struct mount *)0, mfs_vnodeop_p, &devvp);
    340   1.1   mycroft 	if (error)
    341   1.1   mycroft 		return (error);
    342  1.90        ad 	devvp->v_vflag |= VV_MPSAFE;
    343   1.1   mycroft 	devvp->v_type = VBLK;
    344  1.87     pooka 	spec_node_init(devvp, makedev(255, mfs_minor));
    345  1.32       cgd 	mfs_minor++;
    346  1.91        ad 	mfsp = kmem_alloc(sizeof(*mfsp), KM_SLEEP);
    347   1.1   mycroft 	devvp->v_data = mfsp;
    348  1.80       dsl 	mfsp->mfs_baseoff = args->base;
    349  1.80       dsl 	mfsp->mfs_size = args->size;
    350   1.1   mycroft 	mfsp->mfs_vnode = devvp;
    351  1.26   thorpej 	mfsp->mfs_proc = p;
    352  1.39   hannken 	mfsp->mfs_shutdown = 0;
    353  1.90        ad 	cv_init(&mfsp->mfs_cv, "mfsidl");
    354  1.91        ad 	mfsp->mfs_refcnt = 1;
    355  1.70      yamt 	bufq_alloc(&mfsp->mfs_buflist, "fcfs", 0);
    356  1.71  christos 	if ((error = ffs_mountfs(devvp, mp, l)) != 0) {
    357  1.39   hannken 		mfsp->mfs_shutdown = 1;
    358   1.1   mycroft 		vrele(devvp);
    359   1.1   mycroft 		return (error);
    360   1.1   mycroft 	}
    361   1.1   mycroft 	ump = VFSTOUFS(mp);
    362   1.1   mycroft 	fs = ump->um_fs;
    363  1.80       dsl 	error = set_statvfs_info(path, UIO_USERSPACE, args->fspec,
    364  1.81     pooka 	    UIO_USERSPACE, mp->mnt_op->vfs_name, mp, l);
    365  1.58  christos 	if (error)
    366  1.58  christos 		return error;
    367  1.58  christos 	(void)strncpy(fs->fs_fsmnt, mp->mnt_stat.f_mntonname,
    368  1.58  christos 		sizeof(fs->fs_fsmnt));
    369  1.58  christos 	fs->fs_fsmnt[sizeof(fs->fs_fsmnt) - 1] = '\0';
    370  1.57     enami 	/* XXX: cleanup on error */
    371  1.58  christos 	return 0;
    372   1.1   mycroft }
    373   1.1   mycroft 
    374   1.1   mycroft /*
    375   1.1   mycroft  * Used to grab the process and keep it in the kernel to service
    376   1.1   mycroft  * memory filesystem I/O requests.
    377   1.1   mycroft  *
    378  1.28   thorpej  * Loop servicing I/O requests.
    379  1.28   thorpej  * Copy the requested data into or out of the memory filesystem
    380  1.28   thorpej  * address space.
    381   1.1   mycroft  */
    382   1.1   mycroft /* ARGSUSED */
    383   1.1   mycroft int
    384  1.85     pooka mfs_start(struct mount *mp, int flags)
    385   1.1   mycroft {
    386  1.91        ad 	struct vnode *vp;
    387  1.91        ad 	struct mfsnode *mfsp;
    388  1.77        ad 	struct proc *p;
    389  1.28   thorpej 	struct buf *bp;
    390  1.78  christos 	void *base;
    391  1.91        ad 	int sleepreturn = 0, refcnt, error;
    392  1.77        ad 	ksiginfoq_t kq;
    393   1.1   mycroft 
    394  1.91        ad 	/*
    395  1.91        ad 	 * Ensure that file system is still mounted when getting mfsnode.
    396  1.91        ad 	 * Add a reference to the mfsnode to prevent it disappearing in
    397  1.91        ad 	 * this routine.
    398  1.91        ad 	 */
    399  1.96        ad 	if ((error = vfs_busy(mp, NULL)) != 0)
    400  1.91        ad 		return error;
    401  1.91        ad 	vp = VFSTOUFS(mp)->um_devvp;
    402  1.91        ad 	mfsp = VTOMFS(vp);
    403  1.91        ad 	mutex_enter(&mfs_lock);
    404  1.91        ad 	mfsp->mfs_refcnt++;
    405  1.91        ad 	mutex_exit(&mfs_lock);
    406  1.95        ad 	vfs_unbusy(mp, false, NULL);
    407  1.91        ad 
    408  1.28   thorpej 	base = mfsp->mfs_baseoff;
    409  1.91        ad 	mutex_enter(&mfs_lock);
    410  1.39   hannken 	while (mfsp->mfs_shutdown != 1) {
    411  1.70      yamt 		while ((bp = BUFQ_GET(mfsp->mfs_buflist)) != NULL) {
    412  1.91        ad 			mutex_exit(&mfs_lock);
    413  1.30    simonb 			mfs_doio(bp, base);
    414  1.91        ad 			mutex_enter(&mfs_lock);
    415  1.30    simonb 		}
    416   1.1   mycroft 		/*
    417   1.1   mycroft 		 * If a non-ignored signal is received, try to unmount.
    418  1.15      fvdl 		 * If that fails, or the filesystem is already in the
    419  1.15      fvdl 		 * process of being unmounted, clear the signal (it has been
    420  1.15      fvdl 		 * "processed"), otherwise we will loop here, as tsleep
    421  1.15      fvdl 		 * will always return EINTR/ERESTART.
    422   1.1   mycroft 		 */
    423  1.15      fvdl 		if (sleepreturn != 0) {
    424  1.91        ad 			mutex_exit(&mfs_lock);
    425  1.96        ad 			if (dounmount(mp, 0, curlwp) != 0) {
    426  1.91        ad 				p = curproc;
    427  1.77        ad 				ksiginfo_queue_init(&kq);
    428  1.92        ad 				mutex_enter(p->p_lock);
    429  1.77        ad 				sigclearall(p, NULL, &kq);
    430  1.92        ad 				mutex_exit(p->p_lock);
    431  1.77        ad 				ksiginfo_queue_drain(&kq);
    432  1.77        ad 			}
    433  1.15      fvdl 			sleepreturn = 0;
    434  1.91        ad 			mutex_enter(&mfs_lock);
    435  1.12      fvdl 			continue;
    436   1.9   mycroft 		}
    437  1.28   thorpej 
    438  1.91        ad 		sleepreturn = cv_wait_sig(&mfsp->mfs_cv, &mfs_lock);
    439   1.1   mycroft 	}
    440  1.70      yamt 	KASSERT(BUFQ_PEEK(mfsp->mfs_buflist) == NULL);
    441  1.91        ad 	refcnt = --mfsp->mfs_refcnt;
    442  1.91        ad 	mutex_exit(&mfs_lock);
    443  1.91        ad 	if (refcnt == 0) {
    444  1.91        ad 		bufq_free(mfsp->mfs_buflist);
    445  1.91        ad 		cv_destroy(&mfsp->mfs_cv);
    446  1.91        ad 		kmem_free(mfsp, sizeof(*mfsp));
    447  1.91        ad 	}
    448  1.15      fvdl 	return (sleepreturn);
    449   1.1   mycroft }
    450   1.1   mycroft 
    451   1.1   mycroft /*
    452   1.1   mycroft  * Get file system statistics.
    453   1.1   mycroft  */
    454  1.10  christos int
    455  1.85     pooka mfs_statvfs(struct mount *mp, struct statvfs *sbp)
    456   1.1   mycroft {
    457   1.1   mycroft 	int error;
    458   1.1   mycroft 
    459  1.85     pooka 	error = ffs_statvfs(mp, sbp);
    460  1.58  christos 	if (error)
    461  1.58  christos 		return error;
    462  1.58  christos 	(void)strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name,
    463  1.58  christos 	    sizeof(sbp->f_fstypename));
    464  1.58  christos 	sbp->f_fstypename[sizeof(sbp->f_fstypename) - 1] = '\0';
    465  1.58  christos 	return 0;
    466   1.1   mycroft }
    467