Home | History | Annotate | Line # | Download | only in genfs
layer_vfsops.c revision 1.14
      1 /*	$NetBSD: layer_vfsops.c,v 1.14 2004/04/21 01:05:41 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1999 National Aeronautics & Space Administration
      5  * All rights reserved.
      6  *
      7  * This software was written by William Studenmund of the
      8  * Numerical Aerospace Simulation Facility, NASA Ames Research Center.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. Neither the name of the National Aeronautics & Space Administration
     19  *    nor the names of its contributors may be used to endorse or promote
     20  *    products derived from this software without specific prior written
     21  *    permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE NATIONAL AERONAUTICS & SPACE ADMINISTRATION
     24  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     25  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     26  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ADMINISTRATION OR CONTRIB-
     27  * UTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
     28  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     33  * POSSIBILITY OF SUCH DAMAGE.
     34  */
     35 /*
     36  * Copyright (c) 1992, 1993, 1995
     37  *	The Regents of the University of California.  All rights reserved.
     38  *
     39  * This code is derived from software donated to Berkeley by
     40  * Jan-Simon Pendry.
     41  *
     42  * Redistribution and use in source and binary forms, with or without
     43  * modification, are permitted provided that the following conditions
     44  * are met:
     45  * 1. Redistributions of source code must retain the above copyright
     46  *    notice, this list of conditions and the following disclaimer.
     47  * 2. Redistributions in binary form must reproduce the above copyright
     48  *    notice, this list of conditions and the following disclaimer in the
     49  *    documentation and/or other materials provided with the distribution.
     50  * 3. Neither the name of the University nor the names of its contributors
     51  *    may be used to endorse or promote products derived from this software
     52  *    without specific prior written permission.
     53  *
     54  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     55  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     56  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     57  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     58  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     59  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     60  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     61  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     62  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     63  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     64  * SUCH DAMAGE.
     65  *
     66  *	from: Id: lofs_vfsops.c,v 1.9 1992/05/30 10:26:24 jsp Exp
     67  *	from: @(#)lofs_vfsops.c	1.2 (Berkeley) 6/18/92
     68  *	@(#)null_vfsops.c	8.7 (Berkeley) 5/14/95
     69  */
     70 
     71 /*
     72  * generic layer vfs ops.
     73  */
     74 
     75 #include <sys/cdefs.h>
     76 __KERNEL_RCSID(0, "$NetBSD: layer_vfsops.c,v 1.14 2004/04/21 01:05:41 christos Exp $");
     77 
     78 #include <sys/param.h>
     79 #include <sys/sysctl.h>
     80 #include <sys/systm.h>
     81 #include <sys/time.h>
     82 #include <sys/proc.h>
     83 #include <sys/vnode.h>
     84 #include <sys/mount.h>
     85 #include <sys/namei.h>
     86 #include <sys/malloc.h>
     87 #include <miscfs/genfs/layer.h>
     88 #include <miscfs/genfs/layer_extern.h>
     89 
     90 /*
     91  * VFS start.  Nothing needed here - the start routine
     92  * on the underlying filesystem will have been called
     93  * when that filesystem was mounted.
     94  */
     95 int
     96 layerfs_start(mp, flags, p)
     97 	struct mount *mp;
     98 	int flags;
     99 	struct proc *p;
    100 {
    101 
    102 	return (0);
    103 	/* return VFS_START(MOUNTTOLAYERMOUNT(mp)->layerm_vfs, flags, p); */
    104 }
    105 
    106 int
    107 layerfs_root(mp, vpp)
    108 	struct mount *mp;
    109 	struct vnode **vpp;
    110 {
    111 	struct vnode *vp;
    112 
    113 #ifdef LAYERFS_DIAGNOSTIC
    114 	printf("layerfs_root(mp = %p, vp = %p->%p)\n", mp,
    115 	    MOUNTTOLAYERMOUNT(mp)->layerm_rootvp,
    116 	    LAYERVPTOLOWERVP(MOUNTTOLAYERMOUNT(mp)->layerm_rootvp));
    117 #endif
    118 
    119 	/*
    120 	 * Return locked reference to root.
    121 	 */
    122 	vp = MOUNTTOLAYERMOUNT(mp)->layerm_rootvp;
    123 	if (vp == NULL) {
    124 		*vpp = NULL;
    125 		return (EINVAL);
    126 	}
    127 	VREF(vp);
    128 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    129 	*vpp = vp;
    130 	return 0;
    131 }
    132 
    133 int
    134 layerfs_quotactl(mp, cmd, uid, arg, p)
    135 	struct mount *mp;
    136 	int cmd;
    137 	uid_t uid;
    138 	caddr_t arg;
    139 	struct proc *p;
    140 {
    141 
    142 	return VFS_QUOTACTL(MOUNTTOLAYERMOUNT(mp)->layerm_vfs,
    143 				cmd, uid, arg, p);
    144 }
    145 
    146 int
    147 layerfs_statvfs(mp, sbp, p)
    148 	struct mount *mp;
    149 	struct statvfs *sbp;
    150 	struct proc *p;
    151 {
    152 	int error;
    153 	struct statvfs mstat;
    154 
    155 #ifdef LAYERFS_DIAGNOSTIC
    156 	printf("layerfs_statvfs(mp = %p, vp = %p->%p)\n", mp,
    157 	    MOUNTTOLAYERMOUNT(mp)->layerm_rootvp,
    158 	    LAYERVPTOLOWERVP(MOUNTTOLAYERMOUNT(mp)->layerm_rootvp));
    159 #endif
    160 
    161 	memset(&mstat, 0, sizeof(mstat));
    162 
    163 	error = VFS_STATVFS(MOUNTTOLAYERMOUNT(mp)->layerm_vfs, &mstat, p);
    164 	if (error)
    165 		return (error);
    166 
    167 	/* now copy across the "interesting" information and fake the rest */
    168 	sbp->f_flag = mstat.f_flag;
    169 	sbp->f_bsize = mstat.f_bsize;
    170 	sbp->f_frsize = mstat.f_frsize;
    171 	sbp->f_iosize = mstat.f_iosize;
    172 	sbp->f_blocks = mstat.f_blocks;
    173 	sbp->f_bfree = mstat.f_bfree;
    174 	sbp->f_bavail = mstat.f_bavail;
    175 	sbp->f_bresvd = mstat.f_bresvd;
    176 	sbp->f_files = mstat.f_files;
    177 	sbp->f_ffree = mstat.f_ffree;
    178 	sbp->f_favail = mstat.f_favail;
    179 	sbp->f_fresvd = mstat.f_fresvd;
    180 	sbp->f_namemax = mstat.f_namemax;
    181 	copy_statvfs_info(sbp, mp);
    182 	return (0);
    183 }
    184 
    185 int
    186 layerfs_sync(mp, waitfor, cred, p)
    187 	struct mount *mp;
    188 	int waitfor;
    189 	struct ucred *cred;
    190 	struct proc *p;
    191 {
    192 
    193 	/*
    194 	 * XXX - Assumes no data cached at layer.
    195 	 */
    196 	return (0);
    197 }
    198 
    199 int
    200 layerfs_vget(mp, ino, vpp)
    201 	struct mount *mp;
    202 	ino_t ino;
    203 	struct vnode **vpp;
    204 {
    205 	int error;
    206 	struct vnode *vp;
    207 
    208 	if ((error = VFS_VGET(MOUNTTOLAYERMOUNT(mp)->layerm_vfs, ino, &vp))) {
    209 		*vpp = NULL;
    210 		return (error);
    211 	}
    212 	if ((error = layer_node_create(mp, vp, vpp))) {
    213 		vput(vp);
    214 		*vpp = NULL;
    215 		return (error);
    216 	}
    217 
    218 	return (0);
    219 }
    220 
    221 int
    222 layerfs_fhtovp(mp, fidp, vpp)
    223 	struct mount *mp;
    224 	struct fid *fidp;
    225 	struct vnode **vpp;
    226 {
    227 	int error;
    228 	struct vnode *vp;
    229 
    230 	if ((error = VFS_FHTOVP(MOUNTTOLAYERMOUNT(mp)->layerm_vfs, fidp, &vp)))
    231 		return (error);
    232 
    233 	if ((error = layer_node_create(mp, vp, vpp))) {
    234 		vput(vp);
    235 		*vpp = NULL;
    236 		return (error);
    237 	}
    238 
    239 	return (0);
    240 }
    241 
    242 int
    243 layerfs_checkexp(mp, nam, exflagsp, credanonp)
    244 	struct mount *mp;
    245 	struct mbuf *nam;
    246 	int *exflagsp;
    247 	struct ucred**credanonp;
    248 {
    249 	struct	netcred *np;
    250 	struct	layer_mount *lmp = MOUNTTOLAYERMOUNT(mp);
    251 
    252 	/*
    253 	 * get the export permission structure for this <mp, client> tuple.
    254 	 */
    255 	if ((np = vfs_export_lookup(mp, &lmp->layerm_export, nam)) == NULL)
    256 		return (EACCES);
    257 
    258 	*exflagsp = np->netc_exflags;
    259 	*credanonp = &np->netc_anon;
    260 	return (0);
    261 }
    262 
    263 int
    264 layerfs_vptofh(vp, fhp)
    265 	struct vnode *vp;
    266 	struct fid *fhp;
    267 {
    268 
    269 	return (VFS_VPTOFH(LAYERVPTOLOWERVP(vp), fhp));
    270 }
    271 
    272 SYSCTL_SETUP(sysctl_vfs_layerfs_setup, "sysctl vfs.layerfs subtree setup")
    273 {
    274 
    275 	sysctl_createv(clog, 0, NULL, NULL,
    276 		       CTLFLAG_PERMANENT,
    277 		       CTLTYPE_NODE, "vfs", NULL,
    278 		       NULL, 0, NULL, 0,
    279 		       CTL_VFS, CTL_EOL);
    280 	sysctl_createv(clog, 0, NULL, NULL,
    281 		       CTLFLAG_PERMANENT,
    282 		       CTLTYPE_NODE, "layerfs", NULL,
    283 		       NULL, 0, NULL, 0,
    284 		       CTL_VFS, CTL_CREATE);
    285 	/*
    286 	 * other subtrees should really be aliases to this, but since
    287 	 * they can't tell if layerfs has been instantiated yet, they
    288 	 * can't do that...not easily.  not yet.  :-)
    289 	 */
    290 }
    291