Home | History | Annotate | Line # | Download | only in nullfs
null_vfsops.c revision 1.29.2.4
      1  1.29.2.4   nathanw /*	$NetBSD: null_vfsops.c,v 1.29.2.4 2001/11/14 19:17:10 nathanw Exp $	*/
      2       1.2       cgd 
      3       1.1   mycroft /*
      4      1.24  wrstuden  * Copyright (c) 1999 National Aeronautics & Space Administration
      5      1.24  wrstuden  * All rights reserved.
      6      1.24  wrstuden  *
      7      1.24  wrstuden  * This software was written by William Studenmund of the
      8  1.29.2.1   nathanw  * Numerical Aerospace Simulation Facility, NASA Ames Research Center.
      9      1.24  wrstuden  *
     10      1.24  wrstuden  * Redistribution and use in source and binary forms, with or without
     11      1.24  wrstuden  * modification, are permitted provided that the following conditions
     12      1.24  wrstuden  * are met:
     13      1.24  wrstuden  * 1. Redistributions of source code must retain the above copyright
     14      1.24  wrstuden  *    notice, this list of conditions and the following disclaimer.
     15      1.24  wrstuden  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.24  wrstuden  *    notice, this list of conditions and the following disclaimer in the
     17      1.24  wrstuden  *    documentation and/or other materials provided with the distribution.
     18      1.25     soren  * 3. Neither the name of the National Aeronautics & Space Administration
     19      1.24  wrstuden  *    nor the names of its contributors may be used to endorse or promote
     20      1.24  wrstuden  *    products derived from this software without specific prior written
     21      1.24  wrstuden  *    permission.
     22      1.24  wrstuden  *
     23      1.24  wrstuden  * THIS SOFTWARE IS PROVIDED BY THE NATIONAL AERONAUTICS & SPACE ADMINISTRATION
     24      1.24  wrstuden  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     25      1.24  wrstuden  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     26      1.24  wrstuden  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ADMINISTRATION OR CONTRIB-
     27      1.24  wrstuden  * UTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
     28      1.24  wrstuden  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     29      1.24  wrstuden  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30      1.24  wrstuden  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     31      1.24  wrstuden  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     32      1.24  wrstuden  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     33      1.24  wrstuden  * POSSIBILITY OF SUCH DAMAGE.
     34      1.24  wrstuden  */
     35      1.24  wrstuden /*
     36      1.19      fvdl  * Copyright (c) 1992, 1993, 1995
     37       1.1   mycroft  *	The Regents of the University of California.  All rights reserved.
     38       1.1   mycroft  *
     39       1.1   mycroft  * This code is derived from software donated to Berkeley by
     40       1.1   mycroft  * Jan-Simon Pendry.
     41       1.1   mycroft  *
     42       1.1   mycroft  * Redistribution and use in source and binary forms, with or without
     43       1.1   mycroft  * modification, are permitted provided that the following conditions
     44       1.1   mycroft  * are met:
     45       1.1   mycroft  * 1. Redistributions of source code must retain the above copyright
     46       1.1   mycroft  *    notice, this list of conditions and the following disclaimer.
     47       1.1   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     48       1.1   mycroft  *    notice, this list of conditions and the following disclaimer in the
     49       1.1   mycroft  *    documentation and/or other materials provided with the distribution.
     50       1.1   mycroft  * 3. All advertising materials mentioning features or use of this software
     51       1.1   mycroft  *    must display the following acknowledgement:
     52       1.1   mycroft  *	This product includes software developed by the University of
     53       1.1   mycroft  *	California, Berkeley and its contributors.
     54       1.1   mycroft  * 4. Neither the name of the University nor the names of its contributors
     55       1.1   mycroft  *    may be used to endorse or promote products derived from this software
     56       1.1   mycroft  *    without specific prior written permission.
     57       1.1   mycroft  *
     58       1.1   mycroft  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     59       1.1   mycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     60       1.1   mycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     61       1.1   mycroft  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     62       1.1   mycroft  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     63       1.1   mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     64       1.1   mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     65       1.1   mycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     66       1.1   mycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     67       1.1   mycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     68       1.1   mycroft  * SUCH DAMAGE.
     69       1.1   mycroft  *
     70       1.1   mycroft  *	from: Id: lofs_vfsops.c,v 1.9 1992/05/30 10:26:24 jsp Exp
     71       1.1   mycroft  *	from: @(#)lofs_vfsops.c	1.2 (Berkeley) 6/18/92
     72      1.19      fvdl  *	@(#)null_vfsops.c	8.7 (Berkeley) 5/14/95
     73       1.1   mycroft  */
     74       1.1   mycroft 
     75       1.1   mycroft /*
     76       1.1   mycroft  * Null Layer
     77       1.1   mycroft  * (See null_vnops.c for a description of what this does.)
     78       1.1   mycroft  */
     79       1.1   mycroft 
     80  1.29.2.4   nathanw #include <sys/cdefs.h>
     81  1.29.2.4   nathanw __KERNEL_RCSID(0, "$NetBSD: null_vfsops.c,v 1.29.2.4 2001/11/14 19:17:10 nathanw Exp $");
     82  1.29.2.4   nathanw 
     83       1.1   mycroft #include <sys/param.h>
     84       1.1   mycroft #include <sys/systm.h>
     85       1.1   mycroft #include <sys/time.h>
     86      1.19      fvdl #include <sys/proc.h>
     87       1.1   mycroft #include <sys/vnode.h>
     88       1.1   mycroft #include <sys/mount.h>
     89       1.1   mycroft #include <sys/namei.h>
     90       1.1   mycroft #include <sys/malloc.h>
     91  1.29.2.4   nathanw 
     92       1.1   mycroft #include <miscfs/nullfs/null.h>
     93      1.24  wrstuden #include <miscfs/genfs/layer_extern.h>
     94       1.1   mycroft 
     95      1.14       cgd int	nullfs_mount __P((struct mount *, const char *, void *,
     96  1.29.2.4   nathanw 	    struct nameidata *, struct proc *));
     97      1.10  christos int	nullfs_unmount __P((struct mount *, int, struct proc *));
     98      1.24  wrstuden 
     99       1.1   mycroft /*
    100       1.1   mycroft  * Mount null layer
    101       1.1   mycroft  */
    102       1.1   mycroft int
    103       1.1   mycroft nullfs_mount(mp, path, data, ndp, p)
    104       1.1   mycroft 	struct mount *mp;
    105      1.14       cgd 	const char *path;
    106      1.14       cgd 	void *data;
    107       1.1   mycroft 	struct nameidata *ndp;
    108       1.1   mycroft 	struct proc *p;
    109       1.1   mycroft {
    110       1.1   mycroft 	struct null_args args;
    111       1.1   mycroft 	struct vnode *lowerrootvp, *vp;
    112      1.24  wrstuden 	struct null_mount *nmp;
    113      1.24  wrstuden 	struct layer_mount *lmp;
    114       1.8   mycroft 	size_t size;
    115  1.29.2.4   nathanw 	int error = 0;
    116       1.1   mycroft 
    117       1.1   mycroft #ifdef NULLFS_DIAGNOSTIC
    118      1.16  christos 	printf("nullfs_mount(mp = %p)\n", mp);
    119       1.1   mycroft #endif
    120       1.1   mycroft 
    121       1.1   mycroft 	/*
    122       1.1   mycroft 	 * Get argument
    123       1.1   mycroft 	 */
    124      1.10  christos 	error = copyin(data, (caddr_t)&args, sizeof(struct null_args));
    125      1.10  christos 	if (error)
    126       1.1   mycroft 		return (error);
    127       1.1   mycroft 
    128       1.1   mycroft 	/*
    129      1.24  wrstuden 	 * Update only does export updating.
    130      1.24  wrstuden 	 */
    131      1.24  wrstuden 	if (mp->mnt_flag & MNT_UPDATE) {
    132      1.24  wrstuden 		lmp = MOUNTTOLAYERMOUNT(mp);
    133  1.29.2.4   nathanw 		if (args.nulla_target == NULL)
    134      1.24  wrstuden 			return (vfs_export(mp, &lmp->layerm_export,
    135  1.29.2.4   nathanw 			    &args.la.export));
    136      1.24  wrstuden 		else
    137      1.24  wrstuden 			return (EOPNOTSUPP);
    138      1.24  wrstuden 	}
    139      1.24  wrstuden 
    140      1.24  wrstuden 	/*
    141       1.1   mycroft 	 * Find lower node
    142       1.1   mycroft 	 */
    143  1.29.2.2   nathanw 	NDINIT(ndp, LOOKUP, FOLLOW|LOCKLEAF,
    144      1.24  wrstuden 		UIO_USERSPACE, args.la.target, p);
    145      1.10  christos 	if ((error = namei(ndp)) != 0)
    146       1.1   mycroft 		return (error);
    147       1.1   mycroft 
    148       1.1   mycroft 	/*
    149       1.1   mycroft 	 * Sanity check on lower vnode
    150       1.1   mycroft 	 */
    151       1.1   mycroft 	lowerrootvp = ndp->ni_vp;
    152       1.1   mycroft 
    153      1.24  wrstuden 	/*
    154      1.24  wrstuden 	 * First cut at fixing up upper mount point
    155      1.24  wrstuden 	 */
    156      1.24  wrstuden 	nmp = (struct null_mount *) malloc(sizeof(struct null_mount),
    157  1.29.2.4   nathanw 	    M_UFSMNT, M_WAITOK);		/* XXX */
    158      1.24  wrstuden 	memset((caddr_t)nmp, 0, sizeof(struct null_mount));
    159      1.24  wrstuden 
    160      1.24  wrstuden 	mp->mnt_data = (qaddr_t) nmp;
    161      1.24  wrstuden 	nmp->nullm_vfs = lowerrootvp->v_mount;
    162      1.24  wrstuden 	if (nmp->nullm_vfs->mnt_flag & MNT_LOCAL)
    163      1.24  wrstuden 		mp->mnt_flag |= MNT_LOCAL;
    164       1.1   mycroft 
    165       1.1   mycroft 	/*
    166      1.24  wrstuden 	 * Make sure that the mount point is sufficiently initialized
    167      1.24  wrstuden 	 * that the node create call will work.
    168       1.1   mycroft 	 */
    169      1.27     assar 	vfs_getnewfsid(mp);
    170      1.24  wrstuden 
    171  1.29.2.4   nathanw 	nmp->nullm_size = sizeof(struct null_node);
    172      1.24  wrstuden 	nmp->nullm_tag = VT_NULL;
    173      1.24  wrstuden 	nmp->nullm_bypass = layer_bypass;
    174      1.24  wrstuden 	nmp->nullm_alloc = layer_node_alloc;	/* the default alloc is fine */
    175      1.24  wrstuden 	nmp->nullm_vnodeop_p = null_vnodeop_p;
    176      1.24  wrstuden 	simple_lock_init(&nmp->nullm_hashlock);
    177  1.29.2.4   nathanw 	nmp->nullm_node_hashtbl = hashinit(desiredvnodes, HASH_LIST, M_CACHE,
    178      1.28        ad 	    M_WAITOK, &nmp->nullm_node_hash);
    179       1.1   mycroft 
    180       1.1   mycroft 	/*
    181      1.24  wrstuden 	 * Fix up null node for root vnode
    182       1.1   mycroft 	 */
    183      1.24  wrstuden 	error = layer_node_create(mp, lowerrootvp, &vp);
    184       1.1   mycroft 	/*
    185      1.24  wrstuden 	 * Make sure the fixup worked
    186       1.1   mycroft 	 */
    187       1.1   mycroft 	if (error) {
    188      1.24  wrstuden 		vput(lowerrootvp);
    189  1.29.2.4   nathanw 		hashdone(nmp->nullm_node_hashtbl, M_CACHE);
    190      1.24  wrstuden 		free(nmp, M_UFSMNT);	/* XXX */
    191       1.1   mycroft 		return (error);
    192       1.1   mycroft 	}
    193      1.21  wrstuden 	/*
    194      1.24  wrstuden 	 * Unlock the node
    195      1.21  wrstuden 	 */
    196      1.21  wrstuden 	VOP_UNLOCK(vp, 0);
    197       1.1   mycroft 
    198       1.1   mycroft 	/*
    199       1.1   mycroft 	 * Keep a held reference to the root vnode.
    200       1.1   mycroft 	 * It is vrele'd in nullfs_unmount.
    201       1.1   mycroft 	 */
    202      1.24  wrstuden 	vp->v_flag |= VROOT;
    203      1.24  wrstuden 	nmp->nullm_rootvp = vp;
    204       1.1   mycroft 
    205       1.1   mycroft 	(void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
    206      1.20     perry 	memset(mp->mnt_stat.f_mntonname + size, 0, MNAMELEN - size);
    207  1.29.2.4   nathanw 	(void) copyinstr(args.la.target, mp->mnt_stat.f_mntfromname,
    208  1.29.2.4   nathanw 	    MNAMELEN - 1, &size);
    209      1.20     perry 	memset(mp->mnt_stat.f_mntfromname + size, 0, MNAMELEN - size);
    210       1.1   mycroft #ifdef NULLFS_DIAGNOSTIC
    211      1.13  christos 	printf("nullfs_mount: lower %s, alias at %s\n",
    212      1.12  christos 	    mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname);
    213       1.1   mycroft #endif
    214       1.1   mycroft 	return (0);
    215       1.1   mycroft }
    216       1.1   mycroft 
    217       1.1   mycroft /*
    218       1.1   mycroft  * Free reference to null layer
    219       1.1   mycroft  */
    220       1.1   mycroft int
    221       1.1   mycroft nullfs_unmount(mp, mntflags, p)
    222       1.1   mycroft 	struct mount *mp;
    223       1.1   mycroft 	int mntflags;
    224       1.1   mycroft 	struct proc *p;
    225       1.1   mycroft {
    226  1.29.2.4   nathanw 	struct null_mount *nmp = MOUNTTONULLMOUNT(mp);
    227  1.29.2.4   nathanw 	struct vnode *null_rootvp = nmp->nullm_rootvp;
    228       1.1   mycroft 	int error;
    229       1.1   mycroft 	int flags = 0;
    230       1.1   mycroft 
    231       1.1   mycroft #ifdef NULLFS_DIAGNOSTIC
    232      1.16  christos 	printf("nullfs_unmount(mp = %p)\n", mp);
    233       1.1   mycroft #endif
    234       1.1   mycroft 
    235      1.19      fvdl 	if (mntflags & MNT_FORCE)
    236       1.1   mycroft 		flags |= FORCECLOSE;
    237       1.1   mycroft 
    238       1.1   mycroft 	/*
    239       1.1   mycroft 	 * Clear out buffer cache.  I don't think we
    240       1.1   mycroft 	 * ever get anything cached at this level at the
    241       1.1   mycroft 	 * moment, but who knows...
    242       1.1   mycroft 	 */
    243       1.1   mycroft #if 0
    244  1.29.2.4   nathanw 	mntflushbuf(mp, 0);
    245       1.1   mycroft 	if (mntinvalbuf(mp, 1))
    246       1.1   mycroft 		return (EBUSY);
    247       1.1   mycroft #endif
    248      1.24  wrstuden 	if (null_rootvp->v_usecount > 1)
    249       1.1   mycroft 		return (EBUSY);
    250      1.24  wrstuden 	if ((error = vflush(mp, null_rootvp, flags)) != 0)
    251       1.1   mycroft 		return (error);
    252       1.1   mycroft 
    253       1.1   mycroft #ifdef NULLFS_DIAGNOSTIC
    254      1.24  wrstuden 	vprint("alias root of lower", null_rootvp);
    255  1.29.2.4   nathanw #endif
    256       1.1   mycroft 	/*
    257       1.1   mycroft 	 * Release reference on underlying root vnode
    258       1.1   mycroft 	 */
    259      1.24  wrstuden 	vrele(null_rootvp);
    260  1.29.2.4   nathanw 
    261       1.1   mycroft 	/*
    262       1.1   mycroft 	 * And blow it away for future re-use
    263       1.1   mycroft 	 */
    264      1.24  wrstuden 	vgone(null_rootvp);
    265  1.29.2.4   nathanw 
    266       1.1   mycroft 	/*
    267       1.1   mycroft 	 * Finally, throw away the null_mount structure
    268       1.1   mycroft 	 */
    269  1.29.2.4   nathanw 	hashdone(nmp->nullm_node_hashtbl, M_CACHE);
    270       1.1   mycroft 	free(mp->mnt_data, M_UFSMNT);	/* XXX */
    271  1.29.2.4   nathanw 	mp->mnt_data = NULL;
    272  1.29.2.4   nathanw 	return (0);
    273       1.1   mycroft }
    274       1.1   mycroft 
    275      1.29  jdolecek extern const struct vnodeopv_desc null_vnodeop_opv_desc;
    276      1.18   thorpej 
    277      1.29  jdolecek const struct vnodeopv_desc * const nullfs_vnodeopv_descs[] = {
    278      1.19      fvdl 	&null_vnodeop_opv_desc,
    279      1.18   thorpej 	NULL,
    280      1.18   thorpej };
    281      1.18   thorpej 
    282      1.17   thorpej struct vfsops nullfs_vfsops = {
    283       1.1   mycroft 	MOUNT_NULL,
    284       1.1   mycroft 	nullfs_mount,
    285      1.24  wrstuden 	layerfs_start,
    286       1.1   mycroft 	nullfs_unmount,
    287      1.24  wrstuden 	layerfs_root,
    288      1.24  wrstuden 	layerfs_quotactl,
    289      1.24  wrstuden 	layerfs_statfs,
    290      1.24  wrstuden 	layerfs_sync,
    291      1.24  wrstuden 	layerfs_vget,
    292      1.24  wrstuden 	layerfs_fhtovp,
    293      1.24  wrstuden 	layerfs_vptofh,
    294      1.24  wrstuden 	layerfs_init,
    295  1.29.2.3   nathanw 	NULL,
    296      1.26  jdolecek 	layerfs_done,
    297      1.24  wrstuden 	layerfs_sysctl,
    298      1.18   thorpej 	NULL,				/* vfs_mountroot */
    299      1.24  wrstuden 	layerfs_checkexp,
    300      1.18   thorpej 	nullfs_vnodeopv_descs,
    301       1.1   mycroft };
    302