Home | History | Annotate | Line # | Download | only in umapfs
umap_vfsops.c revision 1.23.8.1
      1  1.23.8.1  wrstuden /*	$NetBSD: umap_vfsops.c,v 1.23.8.1 1999/12/21 23:20:01 wrstuden Exp $	*/
      2       1.2       cgd 
      3       1.1   mycroft /*
      4       1.1   mycroft  * Copyright (c) 1992, 1993
      5       1.1   mycroft  *	The Regents of the University of California.  All rights reserved.
      6       1.1   mycroft  *
      7       1.1   mycroft  * This code is derived from software donated to Berkeley by
      8       1.1   mycroft  * the UCLA Ficus project.
      9       1.1   mycroft  *
     10       1.1   mycroft  * Redistribution and use in source and binary forms, with or without
     11       1.1   mycroft  * modification, are permitted provided that the following conditions
     12       1.1   mycroft  * are met:
     13       1.1   mycroft  * 1. Redistributions of source code must retain the above copyright
     14       1.1   mycroft  *    notice, this list of conditions and the following disclaimer.
     15       1.1   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1   mycroft  *    notice, this list of conditions and the following disclaimer in the
     17       1.1   mycroft  *    documentation and/or other materials provided with the distribution.
     18       1.1   mycroft  * 3. All advertising materials mentioning features or use of this software
     19       1.1   mycroft  *    must display the following acknowledgement:
     20       1.1   mycroft  *	This product includes software developed by the University of
     21       1.1   mycroft  *	California, Berkeley and its contributors.
     22       1.1   mycroft  * 4. Neither the name of the University nor the names of its contributors
     23       1.1   mycroft  *    may be used to endorse or promote products derived from this software
     24       1.1   mycroft  *    without specific prior written permission.
     25       1.1   mycroft  *
     26       1.1   mycroft  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27       1.1   mycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28       1.1   mycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29       1.1   mycroft  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30       1.1   mycroft  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31       1.1   mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32       1.1   mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33       1.1   mycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34       1.1   mycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35       1.1   mycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36       1.1   mycroft  * SUCH DAMAGE.
     37       1.1   mycroft  *
     38       1.1   mycroft  *	from: @(#)null_vfsops.c       1.5 (Berkeley) 7/10/92
     39      1.18      fvdl  *	@(#)umap_vfsops.c	8.8 (Berkeley) 5/14/95
     40       1.1   mycroft  */
     41       1.1   mycroft 
     42       1.1   mycroft /*
     43       1.1   mycroft  * Umap Layer
     44       1.1   mycroft  * (See mount_umap(8) for a description of this layer.)
     45       1.1   mycroft  */
     46       1.1   mycroft 
     47       1.1   mycroft #include <sys/param.h>
     48       1.1   mycroft #include <sys/systm.h>
     49      1.18      fvdl #include <sys/proc.h>
     50       1.1   mycroft #include <sys/time.h>
     51       1.1   mycroft #include <sys/types.h>
     52       1.1   mycroft #include <sys/vnode.h>
     53       1.1   mycroft #include <sys/mount.h>
     54       1.1   mycroft #include <sys/namei.h>
     55       1.1   mycroft #include <sys/malloc.h>
     56       1.1   mycroft #include <miscfs/umapfs/umap.h>
     57      1.23  wrstuden #include <miscfs/genfs/layer_extern.h>
     58       1.1   mycroft 
     59      1.12       cgd int	umapfs_mount __P((struct mount *, const char *, void *,
     60       1.9  christos 			  struct nameidata *, struct proc *));
     61       1.9  christos int	umapfs_unmount __P((struct mount *, int, struct proc *));
     62       1.9  christos 
     63       1.1   mycroft /*
     64       1.1   mycroft  * Mount umap layer
     65       1.1   mycroft  */
     66       1.1   mycroft int
     67       1.1   mycroft umapfs_mount(mp, path, data, ndp, p)
     68       1.1   mycroft 	struct mount *mp;
     69      1.12       cgd 	const char *path;
     70      1.12       cgd 	void *data;
     71       1.1   mycroft 	struct nameidata *ndp;
     72       1.1   mycroft 	struct proc *p;
     73       1.1   mycroft {
     74       1.1   mycroft 	struct umap_args args;
     75       1.1   mycroft 	struct vnode *lowerrootvp, *vp;
     76       1.1   mycroft 	struct umap_mount *amp;
     77       1.7   mycroft 	size_t size;
     78       1.1   mycroft 	int error;
     79      1.22  perseant #ifdef UMAPFS_DIAGNOSTIC
     80      1.22  perseant 	int i;
     81      1.22  perseant #endif
     82      1.21    bouyer 
     83      1.21    bouyer 	/* only for root */
     84      1.21    bouyer 	if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
     85      1.21    bouyer 		return error;
     86       1.1   mycroft 
     87       1.1   mycroft #ifdef UMAPFS_DIAGNOSTIC
     88      1.15  christos 	printf("umapfs_mount(mp = %p)\n", mp);
     89       1.1   mycroft #endif
     90       1.1   mycroft 
     91       1.1   mycroft 	/*
     92       1.1   mycroft 	 * Get argument
     93       1.1   mycroft 	 */
     94       1.9  christos 	error = copyin(data, (caddr_t)&args, sizeof(struct umap_args));
     95       1.9  christos 	if (error)
     96       1.1   mycroft 		return (error);
     97       1.1   mycroft 
     98       1.1   mycroft 	/*
     99      1.23  wrstuden 	 * Update only does export updating.
    100      1.23  wrstuden 	 */
    101      1.23  wrstuden 	if (mp->mnt_flag & MNT_UPDATE) {
    102      1.23  wrstuden 		amp = MOUNTTOUMAPMOUNT(mp);
    103      1.23  wrstuden 		if (args.umap_target == 0)
    104      1.23  wrstuden 			return (vfs_export(mp, &amp->umapm_export,
    105      1.23  wrstuden 					&args.umap_export));
    106      1.23  wrstuden 		else
    107      1.23  wrstuden 			return (EOPNOTSUPP);
    108      1.23  wrstuden 	}
    109      1.23  wrstuden 
    110      1.23  wrstuden 	/*
    111       1.1   mycroft 	 * Find lower node
    112       1.1   mycroft 	 */
    113       1.1   mycroft 	NDINIT(ndp, LOOKUP, FOLLOW|WANTPARENT|LOCKLEAF,
    114      1.23  wrstuden 		UIO_USERSPACE, args.umap_target, p);
    115       1.9  christos 	if ((error = namei(ndp)) != 0)
    116       1.1   mycroft 		return (error);
    117       1.1   mycroft 
    118       1.1   mycroft 	/*
    119       1.1   mycroft 	 * Sanity check on lower vnode
    120       1.1   mycroft 	 */
    121       1.1   mycroft 	lowerrootvp = ndp->ni_vp;
    122       1.1   mycroft #ifdef UMAPFS_DIAGNOSTIC
    123      1.15  christos 	printf("vp = %p, check for VDIR...\n", lowerrootvp);
    124       1.1   mycroft #endif
    125       1.1   mycroft 	vrele(ndp->ni_dvp);
    126       1.1   mycroft 	ndp->ni_dvp = 0;
    127       1.1   mycroft 
    128       1.1   mycroft 	if (lowerrootvp->v_type != VDIR) {
    129       1.1   mycroft 		vput(lowerrootvp);
    130       1.1   mycroft 		return (EINVAL);
    131       1.1   mycroft 	}
    132       1.1   mycroft 
    133       1.1   mycroft #ifdef UMAPFS_DIAGNOSTIC
    134      1.15  christos 	printf("mp = %p\n", mp);
    135       1.1   mycroft #endif
    136       1.1   mycroft 
    137       1.1   mycroft 	amp = (struct umap_mount *) malloc(sizeof(struct umap_mount),
    138       1.1   mycroft 				M_UFSMNT, M_WAITOK);	/* XXX */
    139      1.23  wrstuden 	memset((caddr_t)amp, 0, sizeof(struct umap_mount));
    140       1.1   mycroft 
    141      1.23  wrstuden 	mp->mnt_data = (qaddr_t) amp;
    142       1.1   mycroft 	amp->umapm_vfs = lowerrootvp->v_mount;
    143      1.23  wrstuden 	if (amp->umapm_vfs->mnt_flag & MNT_LOCAL)
    144      1.23  wrstuden 		mp->mnt_flag |= MNT_LOCAL;
    145  1.23.8.1  wrstuden 	mp->mnt_bshift = amp->umapm_vfs->mnt_bshift;
    146       1.1   mycroft 
    147       1.1   mycroft 	/*
    148       1.1   mycroft 	 * Now copy in the number of entries and maps for umap mapping.
    149       1.1   mycroft 	 */
    150       1.1   mycroft 	amp->info_nentries = args.nentries;
    151       1.1   mycroft 	amp->info_gnentries = args.gnentries;
    152       1.1   mycroft 	error = copyin(args.mapdata, (caddr_t)amp->info_mapdata,
    153       1.1   mycroft 	    2*sizeof(u_long)*args.nentries);
    154      1.23  wrstuden 	if (error) {
    155      1.23  wrstuden 		vput(lowerrootvp);
    156       1.1   mycroft 		return (error);
    157      1.23  wrstuden 	}
    158       1.1   mycroft 
    159      1.22  perseant #ifdef UMAPFS_DIAGNOSTIC
    160      1.11  christos 	printf("umap_mount:nentries %d\n",args.nentries);
    161       1.1   mycroft 	for (i = 0; i < args.nentries; i++)
    162      1.22  perseant 		printf("   %ld maps to %ld\n", amp->info_mapdata[i][0],
    163       1.1   mycroft 	 	    amp->info_mapdata[i][1]);
    164       1.1   mycroft #endif
    165       1.1   mycroft 
    166       1.1   mycroft 	error = copyin(args.gmapdata, (caddr_t)amp->info_gmapdata,
    167      1.13     mikel 	    2*sizeof(u_long)*args.gnentries);
    168      1.23  wrstuden 	if (error) {
    169      1.23  wrstuden 		vput(lowerrootvp);
    170       1.1   mycroft 		return (error);
    171      1.23  wrstuden 	}
    172       1.1   mycroft 
    173      1.22  perseant #ifdef UMAPFS_DIAGNOSTIC
    174      1.11  christos 	printf("umap_mount:gnentries %d\n",args.gnentries);
    175       1.1   mycroft 	for (i = 0; i < args.gnentries; i++)
    176      1.22  perseant 		printf("\tgroup %ld maps to %ld\n",
    177       1.1   mycroft 		    amp->info_gmapdata[i][0],
    178       1.1   mycroft 	 	    amp->info_gmapdata[i][1]);
    179       1.1   mycroft #endif
    180       1.1   mycroft 
    181       1.1   mycroft 	/*
    182      1.23  wrstuden 	 * Make sure the mount point's sufficiently initialized
    183      1.23  wrstuden 	 * that the node create call will work.
    184       1.1   mycroft 	 */
    185      1.23  wrstuden 	vfs_getnewfsid(mp, MOUNT_UMAP);
    186      1.23  wrstuden 	amp->umapm_size = sizeof(struct umap_node);
    187      1.23  wrstuden 	amp->umapm_tag = VT_UMAP;
    188      1.23  wrstuden 	amp->umapm_bypass = umap_bypass;
    189      1.23  wrstuden 	amp->umapm_alloc = layer_node_alloc;	/* the default alloc is fine */
    190      1.23  wrstuden 	amp->umapm_vnodeop_p = umap_vnodeop_p;
    191      1.23  wrstuden 	simple_lock_init(&amp->umapm_hashlock);
    192      1.23  wrstuden 	amp->umapm_node_hashtbl = hashinit(NUMAPNODECACHE, M_CACHE, M_WAITOK,
    193      1.23  wrstuden 			&amp->umapm_node_hash);
    194      1.23  wrstuden 
    195      1.23  wrstuden 
    196       1.1   mycroft 	/*
    197      1.23  wrstuden 	 * fix up umap node for root vnode.
    198       1.1   mycroft 	 */
    199      1.23  wrstuden 	error = layer_node_create(mp, lowerrootvp, &vp);
    200       1.1   mycroft 	/*
    201       1.1   mycroft 	 * Make sure the node alias worked
    202       1.1   mycroft 	 */
    203       1.1   mycroft 	if (error) {
    204      1.23  wrstuden 		vput(lowerrootvp);
    205       1.1   mycroft 		free(amp, M_UFSMNT);	/* XXX */
    206       1.1   mycroft 		return (error);
    207       1.1   mycroft 	}
    208      1.23  wrstuden 	/*
    209      1.23  wrstuden 	 * Unlock the node (either the lower or the alias)
    210      1.23  wrstuden 	 */
    211      1.23  wrstuden 	VOP_UNLOCK(vp, 0);
    212       1.1   mycroft 
    213       1.1   mycroft 	/*
    214       1.1   mycroft 	 * Keep a held reference to the root vnode.
    215       1.1   mycroft 	 * It is vrele'd in umapfs_unmount.
    216       1.1   mycroft 	 */
    217      1.23  wrstuden 	vp->v_flag |= VROOT;
    218      1.23  wrstuden 	amp->umapm_rootvp = vp;
    219       1.1   mycroft 
    220       1.1   mycroft 	(void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
    221      1.19     perry 	memset(mp->mnt_stat.f_mntonname + size, 0, MNAMELEN - size);
    222      1.23  wrstuden 	(void) copyinstr(args.umap_target, mp->mnt_stat.f_mntfromname,
    223      1.23  wrstuden 		MNAMELEN - 1, &size);
    224      1.19     perry 	memset(mp->mnt_stat.f_mntfromname + size, 0, MNAMELEN - size);
    225       1.1   mycroft #ifdef UMAPFS_DIAGNOSTIC
    226      1.11  christos 	printf("umapfs_mount: lower %s, alias at %s\n",
    227       1.1   mycroft 		mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname);
    228       1.1   mycroft #endif
    229       1.1   mycroft 	return (0);
    230       1.1   mycroft }
    231       1.1   mycroft 
    232       1.1   mycroft /*
    233       1.1   mycroft  * Free reference to umap layer
    234       1.1   mycroft  */
    235       1.1   mycroft int
    236       1.1   mycroft umapfs_unmount(mp, mntflags, p)
    237       1.1   mycroft 	struct mount *mp;
    238       1.1   mycroft 	int mntflags;
    239       1.1   mycroft 	struct proc *p;
    240       1.1   mycroft {
    241      1.23  wrstuden 	struct vnode *rootvp = MOUNTTOUMAPMOUNT(mp)->umapm_rootvp;
    242       1.1   mycroft 	int error;
    243       1.1   mycroft 	int flags = 0;
    244       1.1   mycroft 
    245       1.1   mycroft #ifdef UMAPFS_DIAGNOSTIC
    246      1.15  christos 	printf("umapfs_unmount(mp = %p)\n", mp);
    247       1.1   mycroft #endif
    248       1.1   mycroft 
    249      1.18      fvdl 	if (mntflags & MNT_FORCE)
    250       1.1   mycroft 		flags |= FORCECLOSE;
    251       1.1   mycroft 
    252       1.1   mycroft 	/*
    253       1.1   mycroft 	 * Clear out buffer cache.  I don't think we
    254       1.1   mycroft 	 * ever get anything cached at this level at the
    255       1.1   mycroft 	 * moment, but who knows...
    256       1.1   mycroft 	 */
    257       1.1   mycroft #ifdef notyet
    258       1.1   mycroft 	mntflushbuf(mp, 0);
    259       1.1   mycroft 	if (mntinvalbuf(mp, 1))
    260       1.1   mycroft 		return (EBUSY);
    261       1.1   mycroft #endif
    262      1.23  wrstuden 	if (rootvp->v_usecount > 1)
    263       1.1   mycroft 		return (EBUSY);
    264      1.23  wrstuden 	if ((error = vflush(mp, rootvp, flags)) != 0)
    265       1.1   mycroft 		return (error);
    266       1.1   mycroft 
    267       1.1   mycroft #ifdef UMAPFS_DIAGNOSTIC
    268      1.23  wrstuden 	vprint("alias root of lower", rootvp);
    269       1.1   mycroft #endif
    270       1.1   mycroft 	/*
    271       1.1   mycroft 	 * Release reference on underlying root vnode
    272       1.1   mycroft 	 */
    273      1.23  wrstuden 	vrele(rootvp);
    274       1.1   mycroft 	/*
    275       1.1   mycroft 	 * And blow it away for future re-use
    276       1.1   mycroft 	 */
    277      1.23  wrstuden 	vgone(rootvp);
    278       1.1   mycroft 	/*
    279       1.1   mycroft 	 * Finally, throw away the umap_mount structure
    280       1.1   mycroft 	 */
    281       1.1   mycroft 	free(mp->mnt_data, M_UFSMNT);	/* XXX */
    282       1.1   mycroft 	mp->mnt_data = 0;
    283       1.1   mycroft 	return (0);
    284       1.1   mycroft }
    285       1.1   mycroft 
    286      1.17   thorpej extern struct vnodeopv_desc umapfs_vnodeop_opv_desc;
    287      1.17   thorpej 
    288      1.17   thorpej struct vnodeopv_desc *umapfs_vnodeopv_descs[] = {
    289      1.17   thorpej 	&umapfs_vnodeop_opv_desc,
    290      1.17   thorpej 	NULL,
    291      1.17   thorpej };
    292      1.17   thorpej 
    293      1.16   thorpej struct vfsops umapfs_vfsops = {
    294       1.1   mycroft 	MOUNT_UMAP,
    295       1.1   mycroft 	umapfs_mount,
    296      1.23  wrstuden 	layerfs_start,
    297       1.1   mycroft 	umapfs_unmount,
    298      1.23  wrstuden 	layerfs_root,
    299      1.23  wrstuden 	layerfs_quotactl,
    300      1.23  wrstuden 	layerfs_statfs,
    301      1.23  wrstuden 	layerfs_sync,
    302      1.23  wrstuden 	layerfs_vget,
    303      1.23  wrstuden 	layerfs_fhtovp,
    304      1.23  wrstuden 	layerfs_vptofh,
    305      1.23  wrstuden 	layerfs_init,
    306      1.23  wrstuden 	layerfs_sysctl,
    307      1.17   thorpej 	NULL,				/* vfs_mountroot */
    308      1.23  wrstuden 	layerfs_checkexp,
    309      1.17   thorpej 	umapfs_vnodeopv_descs,
    310       1.1   mycroft };
    311