Home | History | Annotate | Line # | Download | only in mfs
mfs_vfsops.c revision 1.83.8.2
      1  1.83.8.2  pooka /*	$NetBSD: mfs_vfsops.c,v 1.83.8.2 2007/07/31 21:14:21 pooka Exp $	*/
      2  1.83.8.2  pooka 
      3  1.83.8.2  pooka /*
      4  1.83.8.2  pooka  * Copyright (c) 1989, 1990, 1993, 1994
      5  1.83.8.2  pooka  *	The Regents of the University of California.  All rights reserved.
      6  1.83.8.2  pooka  *
      7  1.83.8.2  pooka  * Redistribution and use in source and binary forms, with or without
      8  1.83.8.2  pooka  * modification, are permitted provided that the following conditions
      9  1.83.8.2  pooka  * are met:
     10  1.83.8.2  pooka  * 1. Redistributions of source code must retain the above copyright
     11  1.83.8.2  pooka  *    notice, this list of conditions and the following disclaimer.
     12  1.83.8.2  pooka  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.83.8.2  pooka  *    notice, this list of conditions and the following disclaimer in the
     14  1.83.8.2  pooka  *    documentation and/or other materials provided with the distribution.
     15  1.83.8.2  pooka  * 3. Neither the name of the University nor the names of its contributors
     16  1.83.8.2  pooka  *    may be used to endorse or promote products derived from this software
     17  1.83.8.2  pooka  *    without specific prior written permission.
     18  1.83.8.2  pooka  *
     19  1.83.8.2  pooka  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20  1.83.8.2  pooka  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  1.83.8.2  pooka  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  1.83.8.2  pooka  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23  1.83.8.2  pooka  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  1.83.8.2  pooka  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  1.83.8.2  pooka  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  1.83.8.2  pooka  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  1.83.8.2  pooka  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  1.83.8.2  pooka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  1.83.8.2  pooka  * SUCH DAMAGE.
     30  1.83.8.2  pooka  *
     31  1.83.8.2  pooka  *	@(#)mfs_vfsops.c	8.11 (Berkeley) 6/19/95
     32  1.83.8.2  pooka  */
     33  1.83.8.2  pooka 
     34  1.83.8.2  pooka #include <sys/cdefs.h>
     35  1.83.8.2  pooka __KERNEL_RCSID(0, "$NetBSD: mfs_vfsops.c,v 1.83.8.2 2007/07/31 21:14:21 pooka Exp $");
     36  1.83.8.2  pooka 
     37  1.83.8.2  pooka #if defined(_KERNEL_OPT)
     38  1.83.8.2  pooka #include "opt_compat_netbsd.h"
     39  1.83.8.2  pooka #endif
     40  1.83.8.2  pooka 
     41  1.83.8.2  pooka #include <sys/param.h>
     42  1.83.8.2  pooka #include <sys/systm.h>
     43  1.83.8.2  pooka #include <sys/sysctl.h>
     44  1.83.8.2  pooka #include <sys/time.h>
     45  1.83.8.2  pooka #include <sys/kernel.h>
     46  1.83.8.2  pooka #include <sys/proc.h>
     47  1.83.8.2  pooka #include <sys/buf.h>
     48  1.83.8.2  pooka #include <sys/bufq.h>
     49  1.83.8.2  pooka #include <sys/mount.h>
     50  1.83.8.2  pooka #include <sys/signalvar.h>
     51  1.83.8.2  pooka #include <sys/vnode.h>
     52  1.83.8.2  pooka #include <sys/malloc.h>
     53  1.83.8.2  pooka 
     54  1.83.8.2  pooka #include <miscfs/syncfs/syncfs.h>
     55  1.83.8.2  pooka 
     56  1.83.8.2  pooka #include <ufs/ufs/quota.h>
     57  1.83.8.2  pooka #include <ufs/ufs/inode.h>
     58  1.83.8.2  pooka #include <ufs/ufs/ufsmount.h>
     59  1.83.8.2  pooka #include <ufs/ufs/ufs_extern.h>
     60  1.83.8.2  pooka 
     61  1.83.8.2  pooka #include <ufs/ffs/fs.h>
     62  1.83.8.2  pooka #include <ufs/ffs/ffs_extern.h>
     63  1.83.8.2  pooka 
     64  1.83.8.2  pooka #include <ufs/mfs/mfsnode.h>
     65  1.83.8.2  pooka #include <ufs/mfs/mfs_extern.h>
     66  1.83.8.2  pooka 
     67  1.83.8.2  pooka void *	mfs_rootbase;	/* address of mini-root in kernel virtual memory */
     68  1.83.8.2  pooka u_long	mfs_rootsize;	/* size of mini-root in bytes */
     69  1.83.8.2  pooka 
     70  1.83.8.2  pooka static	int mfs_minor;	/* used for building internal dev_t */
     71  1.83.8.2  pooka 
     72  1.83.8.2  pooka extern int (**mfs_vnodeop_p)(void *);
     73  1.83.8.2  pooka 
     74  1.83.8.2  pooka MALLOC_JUSTDEFINE(M_MFSNODE, "MFS node", "MFS vnode private part");
     75  1.83.8.2  pooka 
     76  1.83.8.2  pooka /*
     77  1.83.8.2  pooka  * mfs vfs operations.
     78  1.83.8.2  pooka  */
     79  1.83.8.2  pooka 
     80  1.83.8.2  pooka extern const struct vnodeopv_desc mfs_vnodeop_opv_desc;
     81  1.83.8.2  pooka 
     82  1.83.8.2  pooka const struct vnodeopv_desc * const mfs_vnodeopv_descs[] = {
     83  1.83.8.2  pooka 	&mfs_vnodeop_opv_desc,
     84  1.83.8.2  pooka 	NULL,
     85  1.83.8.2  pooka };
     86  1.83.8.2  pooka 
     87  1.83.8.2  pooka struct vfsops mfs_vfsops = {
     88  1.83.8.2  pooka 	MOUNT_MFS,
     89  1.83.8.2  pooka 	sizeof (struct mfs_args),
     90  1.83.8.2  pooka 	mfs_mount,
     91  1.83.8.2  pooka 	mfs_start,
     92  1.83.8.2  pooka 	ffs_unmount,
     93  1.83.8.2  pooka 	ufs_root,
     94  1.83.8.2  pooka 	ufs_quotactl,
     95  1.83.8.2  pooka 	mfs_statvfs,
     96  1.83.8.2  pooka 	ffs_sync,
     97  1.83.8.2  pooka 	ffs_vget,
     98  1.83.8.2  pooka 	ffs_fhtovp,
     99  1.83.8.2  pooka 	ffs_vptofh,
    100  1.83.8.2  pooka 	mfs_init,
    101  1.83.8.2  pooka 	mfs_reinit,
    102  1.83.8.2  pooka 	mfs_done,
    103  1.83.8.2  pooka 	NULL,
    104  1.83.8.2  pooka 	(int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
    105  1.83.8.2  pooka 	vfs_stdextattrctl,
    106  1.83.8.2  pooka 	(void *)eopnotsupp,	/* vfs_suspendctl */
    107  1.83.8.2  pooka 	mfs_vnodeopv_descs,
    108  1.83.8.2  pooka 	0,
    109  1.83.8.2  pooka 	{ NULL, NULL },
    110  1.83.8.2  pooka };
    111  1.83.8.2  pooka VFS_ATTACH(mfs_vfsops);
    112  1.83.8.2  pooka 
    113  1.83.8.2  pooka SYSCTL_SETUP(sysctl_vfs_mfs_setup, "sysctl vfs.mfs subtree setup")
    114  1.83.8.2  pooka {
    115  1.83.8.2  pooka 
    116  1.83.8.2  pooka 	sysctl_createv(clog, 0, NULL, NULL,
    117  1.83.8.2  pooka 		       CTLFLAG_PERMANENT,
    118  1.83.8.2  pooka 		       CTLTYPE_NODE, "vfs", NULL,
    119  1.83.8.2  pooka 		       NULL, 0, NULL, 0,
    120  1.83.8.2  pooka 		       CTL_VFS, CTL_EOL);
    121  1.83.8.2  pooka 	sysctl_createv(clog, 0, NULL, NULL,
    122  1.83.8.2  pooka 		       CTLFLAG_PERMANENT|CTLFLAG_ALIAS,
    123  1.83.8.2  pooka 		       CTLTYPE_NODE, "mfs",
    124  1.83.8.2  pooka 		       SYSCTL_DESCR("Memory based file system"),
    125  1.83.8.2  pooka 		       NULL, 1, NULL, 0,
    126  1.83.8.2  pooka 		       CTL_VFS, 3, CTL_EOL);
    127  1.83.8.2  pooka 	/*
    128  1.83.8.2  pooka 	 * XXX the "1" and the "3" above could be dynamic, thereby
    129  1.83.8.2  pooka 	 * eliminating one more instance of the "number to vfs"
    130  1.83.8.2  pooka 	 * mapping problem, but they are in order as taken from
    131  1.83.8.2  pooka 	 * sys/mount.h
    132  1.83.8.2  pooka 	 */
    133  1.83.8.2  pooka }
    134  1.83.8.2  pooka 
    135  1.83.8.2  pooka /*
    136  1.83.8.2  pooka  * Memory based filesystem initialization.
    137  1.83.8.2  pooka  */
    138  1.83.8.2  pooka void
    139  1.83.8.2  pooka mfs_init(void)
    140  1.83.8.2  pooka {
    141  1.83.8.2  pooka 
    142  1.83.8.2  pooka 	malloc_type_attach(M_MFSNODE);
    143  1.83.8.2  pooka 	/*
    144  1.83.8.2  pooka 	 * ffs_init() ensures to initialize necessary resources
    145  1.83.8.2  pooka 	 * only once.
    146  1.83.8.2  pooka 	 */
    147  1.83.8.2  pooka 	ffs_init();
    148  1.83.8.2  pooka }
    149  1.83.8.2  pooka 
    150  1.83.8.2  pooka void
    151  1.83.8.2  pooka mfs_reinit(void)
    152  1.83.8.2  pooka {
    153  1.83.8.2  pooka 	ffs_reinit();
    154  1.83.8.2  pooka }
    155  1.83.8.2  pooka 
    156  1.83.8.2  pooka void
    157  1.83.8.2  pooka mfs_done(void)
    158  1.83.8.2  pooka {
    159  1.83.8.2  pooka 	/*
    160  1.83.8.2  pooka 	 * ffs_done() ensures to free necessary resources
    161  1.83.8.2  pooka 	 * only once, when it's no more needed.
    162  1.83.8.2  pooka 	 */
    163  1.83.8.2  pooka 	ffs_done();
    164  1.83.8.2  pooka 	malloc_type_detach(M_MFSNODE);
    165  1.83.8.2  pooka }
    166  1.83.8.2  pooka 
    167  1.83.8.2  pooka /*
    168  1.83.8.2  pooka  * Called by main() when mfs is going to be mounted as root.
    169  1.83.8.2  pooka  */
    170  1.83.8.2  pooka 
    171  1.83.8.2  pooka int
    172  1.83.8.2  pooka mfs_mountroot(void)
    173  1.83.8.2  pooka {
    174  1.83.8.2  pooka 	struct fs *fs;
    175  1.83.8.2  pooka 	struct mount *mp;
    176  1.83.8.2  pooka 	struct lwp *l = curlwp;		/* XXX */
    177  1.83.8.2  pooka 	struct ufsmount *ump;
    178  1.83.8.2  pooka 	struct mfsnode *mfsp;
    179  1.83.8.2  pooka 	int error = 0;
    180  1.83.8.2  pooka 
    181  1.83.8.2  pooka 	if ((error = vfs_rootmountalloc(MOUNT_MFS, "mfs_root", &mp))) {
    182  1.83.8.2  pooka 		vrele(rootvp);
    183  1.83.8.2  pooka 		return (error);
    184  1.83.8.2  pooka 	}
    185  1.83.8.2  pooka 
    186  1.83.8.2  pooka 	mfsp = malloc(sizeof *mfsp, M_MFSNODE, M_WAITOK);
    187  1.83.8.2  pooka 	rootvp->v_data = mfsp;
    188  1.83.8.2  pooka 	rootvp->v_op = mfs_vnodeop_p;
    189  1.83.8.2  pooka 	rootvp->v_tag = VT_MFS;
    190  1.83.8.2  pooka 	mfsp->mfs_baseoff = mfs_rootbase;
    191  1.83.8.2  pooka 	mfsp->mfs_size = mfs_rootsize;
    192  1.83.8.2  pooka 	mfsp->mfs_vnode = rootvp;
    193  1.83.8.2  pooka 	mfsp->mfs_proc = NULL;		/* indicate kernel space */
    194  1.83.8.2  pooka 	mfsp->mfs_shutdown = 0;
    195  1.83.8.2  pooka 	bufq_alloc(&mfsp->mfs_buflist, "fcfs", 0);
    196  1.83.8.2  pooka 	if ((error = ffs_mountfs(rootvp, mp, l)) != 0) {
    197  1.83.8.2  pooka 		mp->mnt_op->vfs_refcount--;
    198  1.83.8.2  pooka 		vfs_unbusy(mp);
    199  1.83.8.2  pooka 		bufq_free(mfsp->mfs_buflist);
    200  1.83.8.2  pooka 		free(mp, M_MOUNT);
    201  1.83.8.2  pooka 		free(mfsp, M_MFSNODE);
    202  1.83.8.2  pooka 		return (error);
    203  1.83.8.2  pooka 	}
    204  1.83.8.2  pooka 	simple_lock(&mountlist_slock);
    205  1.83.8.2  pooka 	CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
    206  1.83.8.2  pooka 	simple_unlock(&mountlist_slock);
    207  1.83.8.2  pooka 	mp->mnt_vnodecovered = NULLVP;
    208  1.83.8.2  pooka 	ump = VFSTOUFS(mp);
    209  1.83.8.2  pooka 	fs = ump->um_fs;
    210  1.83.8.2  pooka 	(void) copystr(mp->mnt_stat.f_mntonname, fs->fs_fsmnt, MNAMELEN - 1, 0);
    211  1.83.8.2  pooka 	(void)ffs_statvfs(mp, &mp->mnt_stat, l);
    212  1.83.8.2  pooka 	vfs_unbusy(mp);
    213  1.83.8.2  pooka 	return (0);
    214  1.83.8.2  pooka }
    215  1.83.8.2  pooka 
    216  1.83.8.2  pooka /*
    217  1.83.8.2  pooka  * This is called early in boot to set the base address and size
    218  1.83.8.2  pooka  * of the mini-root.
    219  1.83.8.2  pooka  */
    220  1.83.8.2  pooka int
    221  1.83.8.2  pooka mfs_initminiroot(void *base)
    222  1.83.8.2  pooka {
    223  1.83.8.2  pooka 	struct fs *fs = (struct fs *)((char *)base + SBLOCK_UFS1);
    224  1.83.8.2  pooka 
    225  1.83.8.2  pooka 	/* check for valid super block */
    226  1.83.8.2  pooka 	if (fs->fs_magic != FS_UFS1_MAGIC || fs->fs_bsize > MAXBSIZE ||
    227  1.83.8.2  pooka 	    fs->fs_bsize < sizeof(struct fs))
    228  1.83.8.2  pooka 		return (0);
    229  1.83.8.2  pooka 	mountroot = mfs_mountroot;
    230  1.83.8.2  pooka 	mfs_rootbase = base;
    231  1.83.8.2  pooka 	mfs_rootsize = fs->fs_fsize * fs->fs_size;
    232  1.83.8.2  pooka 	rootdev = makedev(255, mfs_minor);
    233  1.83.8.2  pooka 	mfs_minor++;
    234  1.83.8.2  pooka 	return (mfs_rootsize);
    235  1.83.8.2  pooka }
    236  1.83.8.2  pooka 
    237  1.83.8.2  pooka /*
    238  1.83.8.2  pooka  * VFS Operations.
    239  1.83.8.2  pooka  *
    240  1.83.8.2  pooka  * mount system call
    241  1.83.8.2  pooka  */
    242  1.83.8.2  pooka /* ARGSUSED */
    243  1.83.8.2  pooka int
    244  1.83.8.2  pooka mfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len,
    245  1.83.8.2  pooka     struct lwp *l)
    246  1.83.8.2  pooka {
    247  1.83.8.2  pooka 	struct vnode *devvp;
    248  1.83.8.2  pooka 	struct mfs_args *args = data;
    249  1.83.8.2  pooka 	struct ufsmount *ump;
    250  1.83.8.2  pooka 	struct fs *fs;
    251  1.83.8.2  pooka 	struct mfsnode *mfsp;
    252  1.83.8.2  pooka 	struct proc *p;
    253  1.83.8.2  pooka 	int flags, error = 0;
    254  1.83.8.2  pooka 
    255  1.83.8.2  pooka 	if (*data_len < sizeof *args)
    256  1.83.8.2  pooka 		return EINVAL;
    257  1.83.8.2  pooka 
    258  1.83.8.2  pooka 	p = l->l_proc;
    259  1.83.8.2  pooka 	if (mp->mnt_flag & MNT_GETARGS) {
    260  1.83.8.2  pooka 		struct vnode *vp;
    261  1.83.8.2  pooka 
    262  1.83.8.2  pooka 		ump = VFSTOUFS(mp);
    263  1.83.8.2  pooka 		if (ump == NULL)
    264  1.83.8.2  pooka 			return EIO;
    265  1.83.8.2  pooka 
    266  1.83.8.2  pooka 		vp = ump->um_devvp;
    267  1.83.8.2  pooka 		if (vp == NULL)
    268  1.83.8.2  pooka 			return EIO;
    269  1.83.8.2  pooka 
    270  1.83.8.2  pooka 		mfsp = VTOMFS(vp);
    271  1.83.8.2  pooka 		if (mfsp == NULL)
    272  1.83.8.2  pooka 			return EIO;
    273  1.83.8.2  pooka 
    274  1.83.8.2  pooka 		args->fspec = NULL;
    275  1.83.8.2  pooka 		args->base = mfsp->mfs_baseoff;
    276  1.83.8.2  pooka 		args->size = mfsp->mfs_size;
    277  1.83.8.2  pooka 		*data_len = sizeof *args;
    278  1.83.8.2  pooka 		return 0;
    279  1.83.8.2  pooka 	}
    280  1.83.8.2  pooka 	/*
    281  1.83.8.2  pooka 	 * XXX turn off async to avoid hangs when writing lots of data.
    282  1.83.8.2  pooka 	 * the problem is that MFS needs to allocate pages to clean pages,
    283  1.83.8.2  pooka 	 * so if we wait until the last minute to clean pages then there
    284  1.83.8.2  pooka 	 * may not be any pages available to do the cleaning.
    285  1.83.8.2  pooka 	 * ... and since the default partially-synchronous mode turns out
    286  1.83.8.2  pooka 	 * to not be sufficient under heavy load, make it full synchronous.
    287  1.83.8.2  pooka 	 */
    288  1.83.8.2  pooka 	mp->mnt_flag &= ~MNT_ASYNC;
    289  1.83.8.2  pooka 	mp->mnt_flag |= MNT_SYNCHRONOUS;
    290  1.83.8.2  pooka 
    291  1.83.8.2  pooka 	/*
    292  1.83.8.2  pooka 	 * If updating, check whether changing from read-only to
    293  1.83.8.2  pooka 	 * read/write; if there is no device name, that's all we do.
    294  1.83.8.2  pooka 	 */
    295  1.83.8.2  pooka 	if (mp->mnt_flag & MNT_UPDATE) {
    296  1.83.8.2  pooka 		ump = VFSTOUFS(mp);
    297  1.83.8.2  pooka 		fs = ump->um_fs;
    298  1.83.8.2  pooka 		if (fs->fs_ronly == 0 && (mp->mnt_flag & MNT_RDONLY)) {
    299  1.83.8.2  pooka 			flags = WRITECLOSE;
    300  1.83.8.2  pooka 			if (mp->mnt_flag & MNT_FORCE)
    301  1.83.8.2  pooka 				flags |= FORCECLOSE;
    302  1.83.8.2  pooka 			error = ffs_flushfiles(mp, flags, l);
    303  1.83.8.2  pooka 			if (error)
    304  1.83.8.2  pooka 				return (error);
    305  1.83.8.2  pooka 		}
    306  1.83.8.2  pooka 		if (fs->fs_ronly && (mp->mnt_iflag & IMNT_WANTRDWR))
    307  1.83.8.2  pooka 			fs->fs_ronly = 0;
    308  1.83.8.2  pooka 		if (args->fspec == NULL)
    309  1.83.8.2  pooka 			return EINVAL;
    310  1.83.8.2  pooka 		return (0);
    311  1.83.8.2  pooka 	}
    312  1.83.8.2  pooka 	error = getnewvnode(VT_MFS, (struct mount *)0, mfs_vnodeop_p, &devvp);
    313  1.83.8.2  pooka 	if (error)
    314  1.83.8.2  pooka 		return (error);
    315  1.83.8.2  pooka 	devvp->v_type = VBLK;
    316  1.83.8.2  pooka 	if (checkalias(devvp, makedev(255, mfs_minor), (struct mount *)0))
    317  1.83.8.2  pooka 		panic("mfs_mount: dup dev");
    318  1.83.8.2  pooka 	mfs_minor++;
    319  1.83.8.2  pooka 	mfsp = (struct mfsnode *)malloc(sizeof *mfsp, M_MFSNODE, M_WAITOK);
    320  1.83.8.2  pooka 	devvp->v_data = mfsp;
    321  1.83.8.2  pooka 	mfsp->mfs_baseoff = args->base;
    322  1.83.8.2  pooka 	mfsp->mfs_size = args->size;
    323  1.83.8.2  pooka 	mfsp->mfs_vnode = devvp;
    324  1.83.8.2  pooka 	mfsp->mfs_proc = p;
    325  1.83.8.2  pooka 	mfsp->mfs_shutdown = 0;
    326  1.83.8.2  pooka 	bufq_alloc(&mfsp->mfs_buflist, "fcfs", 0);
    327  1.83.8.2  pooka 	if ((error = ffs_mountfs(devvp, mp, l)) != 0) {
    328  1.83.8.2  pooka 		mfsp->mfs_shutdown = 1;
    329  1.83.8.2  pooka 		vrele(devvp);
    330  1.83.8.2  pooka 		return (error);
    331  1.83.8.2  pooka 	}
    332  1.83.8.2  pooka 	ump = VFSTOUFS(mp);
    333  1.83.8.2  pooka 	fs = ump->um_fs;
    334  1.83.8.2  pooka 	error = set_statvfs_info(path, UIO_USERSPACE, args->fspec,
    335  1.83.8.2  pooka 	    UIO_USERSPACE, mp->mnt_op->vfs_name, mp, l);
    336  1.83.8.2  pooka 	if (error)
    337  1.83.8.2  pooka 		return error;
    338  1.83.8.2  pooka 	(void)strncpy(fs->fs_fsmnt, mp->mnt_stat.f_mntonname,
    339  1.83.8.2  pooka 		sizeof(fs->fs_fsmnt));
    340  1.83.8.2  pooka 	fs->fs_fsmnt[sizeof(fs->fs_fsmnt) - 1] = '\0';
    341  1.83.8.2  pooka 	/* XXX: cleanup on error */
    342  1.83.8.2  pooka 	return 0;
    343  1.83.8.2  pooka }
    344  1.83.8.2  pooka 
    345  1.83.8.2  pooka int	mfs_pri = PWAIT | PCATCH;		/* XXX prob. temp */
    346  1.83.8.2  pooka 
    347  1.83.8.2  pooka /*
    348  1.83.8.2  pooka  * Used to grab the process and keep it in the kernel to service
    349  1.83.8.2  pooka  * memory filesystem I/O requests.
    350  1.83.8.2  pooka  *
    351  1.83.8.2  pooka  * Loop servicing I/O requests.
    352  1.83.8.2  pooka  * Copy the requested data into or out of the memory filesystem
    353  1.83.8.2  pooka  * address space.
    354  1.83.8.2  pooka  */
    355  1.83.8.2  pooka /* ARGSUSED */
    356  1.83.8.2  pooka int
    357  1.83.8.2  pooka mfs_start(struct mount *mp, int flags, struct lwp *l)
    358  1.83.8.2  pooka {
    359  1.83.8.2  pooka 	struct vnode *vp = VFSTOUFS(mp)->um_devvp;
    360  1.83.8.2  pooka 	struct mfsnode *mfsp = VTOMFS(vp);
    361  1.83.8.2  pooka 	struct proc *p;
    362  1.83.8.2  pooka 	struct buf *bp;
    363  1.83.8.2  pooka 	void *base;
    364  1.83.8.2  pooka 	int sleepreturn = 0;
    365  1.83.8.2  pooka 	ksiginfoq_t kq;
    366  1.83.8.2  pooka 
    367  1.83.8.2  pooka 	base = mfsp->mfs_baseoff;
    368  1.83.8.2  pooka 	while (mfsp->mfs_shutdown != 1) {
    369  1.83.8.2  pooka 		while ((bp = BUFQ_GET(mfsp->mfs_buflist)) != NULL) {
    370  1.83.8.2  pooka 			mfs_doio(bp, base);
    371  1.83.8.2  pooka 			wakeup((void *)bp);
    372  1.83.8.2  pooka 		}
    373  1.83.8.2  pooka 		/*
    374  1.83.8.2  pooka 		 * If a non-ignored signal is received, try to unmount.
    375  1.83.8.2  pooka 		 * If that fails, or the filesystem is already in the
    376  1.83.8.2  pooka 		 * process of being unmounted, clear the signal (it has been
    377  1.83.8.2  pooka 		 * "processed"), otherwise we will loop here, as tsleep
    378  1.83.8.2  pooka 		 * will always return EINTR/ERESTART.
    379  1.83.8.2  pooka 		 */
    380  1.83.8.2  pooka 		if (sleepreturn != 0) {
    381  1.83.8.2  pooka 			/*
    382  1.83.8.2  pooka 			 * XXX Freeze syncer.  Must do this before locking
    383  1.83.8.2  pooka 			 * the mount point.  See dounmount() for details.
    384  1.83.8.2  pooka 			 */
    385  1.83.8.2  pooka 			mutex_enter(&syncer_mutex);
    386  1.83.8.2  pooka 			if (vfs_busy(mp, LK_NOWAIT, 0) != 0)
    387  1.83.8.2  pooka 				mutex_exit(&syncer_mutex);
    388  1.83.8.2  pooka 			else if (dounmount(mp, 0, l) != 0) {
    389  1.83.8.2  pooka 				p = l->l_proc;
    390  1.83.8.2  pooka 				ksiginfo_queue_init(&kq);
    391  1.83.8.2  pooka 				mutex_enter(&p->p_smutex);
    392  1.83.8.2  pooka 				sigclearall(p, NULL, &kq);
    393  1.83.8.2  pooka 				mutex_exit(&p->p_smutex);
    394  1.83.8.2  pooka 				ksiginfo_queue_drain(&kq);
    395  1.83.8.2  pooka 			}
    396  1.83.8.2  pooka 			sleepreturn = 0;
    397  1.83.8.2  pooka 			continue;
    398  1.83.8.2  pooka 		}
    399  1.83.8.2  pooka 
    400  1.83.8.2  pooka 		sleepreturn = tsleep(vp, mfs_pri, "mfsidl", 0);
    401  1.83.8.2  pooka 	}
    402  1.83.8.2  pooka 	KASSERT(BUFQ_PEEK(mfsp->mfs_buflist) == NULL);
    403  1.83.8.2  pooka 	bufq_free(mfsp->mfs_buflist);
    404  1.83.8.2  pooka 	return (sleepreturn);
    405  1.83.8.2  pooka }
    406  1.83.8.2  pooka 
    407  1.83.8.2  pooka /*
    408  1.83.8.2  pooka  * Get file system statistics.
    409  1.83.8.2  pooka  */
    410  1.83.8.2  pooka int
    411  1.83.8.2  pooka mfs_statvfs(struct mount *mp, struct statvfs *sbp, struct lwp *l)
    412  1.83.8.2  pooka {
    413  1.83.8.2  pooka 	int error;
    414  1.83.8.2  pooka 
    415  1.83.8.2  pooka 	error = ffs_statvfs(mp, sbp, l);
    416  1.83.8.2  pooka 	if (error)
    417  1.83.8.2  pooka 		return error;
    418  1.83.8.2  pooka 	(void)strncpy(sbp->f_fstypename, mp->mnt_op->vfs_name,
    419  1.83.8.2  pooka 	    sizeof(sbp->f_fstypename));
    420  1.83.8.2  pooka 	sbp->f_fstypename[sizeof(sbp->f_fstypename) - 1] = '\0';
    421  1.83.8.2  pooka 	return 0;
    422  1.83.8.2  pooka }
    423