2 * Copyright (c) 1992, 1993, 1995
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software donated to Berkeley by
6 * the UCLA Ficus project.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * @(#)umap_vfsops.c 8.8 (Berkeley) 5/14/95
38 * $Id: umap_vfsops.c,v 1.24 1999/03/12 19:40:39 imp Exp $
43 * (See mount_umap(8) for a description of this layer.)
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/kernel.h>
50 #include <sys/vnode.h>
51 #include <sys/mount.h>
52 #include <sys/namei.h>
53 #include <sys/malloc.h>
54 #include <miscfs/umapfs/umap.h>
56 static MALLOC_DEFINE(M_UMAPFSMNT, "UMAP mount", "UMAP mount structure");
58 static int umapfs_fhtovp __P((struct mount *mp, struct fid *fidp,
59 struct sockaddr *nam, struct vnode **vpp,
60 int *exflagsp, struct ucred **credanonp));
61 static int umapfs_mount __P((struct mount *mp, char *path, caddr_t data,
62 struct nameidata *ndp, struct proc *p));
63 static int umapfs_quotactl __P((struct mount *mp, int cmd, uid_t uid,
64 caddr_t arg, struct proc *p));
65 static int umapfs_root __P((struct mount *mp, struct vnode **vpp));
66 static int umapfs_start __P((struct mount *mp, int flags, struct proc *p));
67 static int umapfs_statfs __P((struct mount *mp, struct statfs *sbp,
69 static int umapfs_sync __P((struct mount *mp, int waitfor,
70 struct ucred *cred, struct proc *p));
71 static int umapfs_unmount __P((struct mount *mp, int mntflags,
73 static int umapfs_vget __P((struct mount *mp, ino_t ino,
75 static int umapfs_vptofh __P((struct vnode *vp, struct fid *fhp));
81 umapfs_mount(mp, path, data, ndp, p)
85 struct nameidata *ndp;
88 struct umap_args args;
89 struct vnode *lowerrootvp, *vp;
90 struct vnode *umapm_rootvp;
91 struct umap_mount *amp;
94 #ifdef UMAP_DIAGNOSTIC
101 if ((error = suser(p)) != 0)
104 #ifdef UMAPFS_DIAGNOSTIC
105 printf("umapfs_mount(mp = %x)\n", mp);
111 if (mp->mnt_flag & MNT_UPDATE) {
113 /* return (VFS_MOUNT(MOUNTTOUMAPMOUNT(mp)->umapm_vfs, path, data, ndp, p));*/
119 error = copyin(data, (caddr_t)&args, sizeof(struct umap_args));
126 NDINIT(ndp, LOOKUP, FOLLOW|WANTPARENT|LOCKLEAF,
127 UIO_USERSPACE, args.target, p);
133 * Sanity check on lower vnode
135 lowerrootvp = ndp->ni_vp;
136 #ifdef UMAPFS_DIAGNOSTIC
137 printf("vp = %x, check for VDIR...\n", lowerrootvp);
142 if (lowerrootvp->v_type != VDIR) {
147 #ifdef UMAPFS_DIAGNOSTIC
148 printf("mp = %x\n", mp);
151 amp = (struct umap_mount *) malloc(sizeof(struct umap_mount),
152 M_UMAPFSMNT, M_WAITOK); /* XXX */
155 * Save reference to underlying FS
157 amp->umapm_vfs = lowerrootvp->v_mount;
160 * Now copy in the number of entries and maps for umap mapping.
162 amp->info_nentries = args.nentries;
163 amp->info_gnentries = args.gnentries;
164 error = copyin(args.mapdata, (caddr_t)amp->info_mapdata,
165 2*sizeof(u_long)*args.nentries);
169 #ifdef UMAP_DIAGNOSTIC
170 printf("umap_mount:nentries %d\n",args.nentries);
171 for (i = 0; i < args.nentries; i++)
172 printf(" %d maps to %d\n", amp->info_mapdata[i][0],
173 amp->info_mapdata[i][1]);
176 error = copyin(args.gmapdata, (caddr_t)amp->info_gmapdata,
177 2*sizeof(u_long)*args.gnentries);
181 #ifdef UMAP_DIAGNOSTIC
182 printf("umap_mount:gnentries %d\n",args.gnentries);
183 for (i = 0; i < args.gnentries; i++)
184 printf(" group %d maps to %d\n",
185 amp->info_gmapdata[i][0],
186 amp->info_gmapdata[i][1]);
191 * Save reference. Each mount also holds
192 * a reference on the root vnode.
194 error = umap_node_create(mp, lowerrootvp, &vp);
196 * Unlock the node (either the lower or the alias)
198 VOP_UNLOCK(vp, 0, p);
200 * Make sure the node alias worked
204 free(amp, M_UMAPFSMNT); /* XXX */
209 * Keep a held reference to the root vnode.
210 * It is vrele'd in umapfs_unmount.
213 umapm_rootvp->v_flag |= VROOT;
214 amp->umapm_rootvp = umapm_rootvp;
215 if (UMAPVPTOLOWERVP(umapm_rootvp)->v_mount->mnt_flag & MNT_LOCAL)
216 mp->mnt_flag |= MNT_LOCAL;
217 mp->mnt_data = (qaddr_t) amp;
220 (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
221 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
222 (void) copyinstr(args.target, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
224 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
225 (void)umapfs_statfs(mp, &mp->mnt_stat, p);
226 #ifdef UMAPFS_DIAGNOSTIC
227 printf("umapfs_mount: lower %s, alias at %s\n",
228 mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname);
234 * VFS start. Nothing needed here - the start routine
235 * on the underlying filesystem will have been called
236 * when that filesystem was mounted.
239 umapfs_start(mp, flags, p)
245 /* return (VFS_START(MOUNTTOUMAPMOUNT(mp)->umapm_vfs, flags, p)); */
249 * Free reference to umap layer
252 umapfs_unmount(mp, mntflags, p)
257 struct vnode *umapm_rootvp = MOUNTTOUMAPMOUNT(mp)->umapm_rootvp;
261 #ifdef UMAPFS_DIAGNOSTIC
262 printf("umapfs_unmount(mp = %x)\n", mp);
265 if (mntflags & MNT_FORCE)
269 * Clear out buffer cache. I don't think we
270 * ever get anything cached at this level at the
271 * moment, but who knows...
275 if (mntinvalbuf(mp, 1))
278 if (umapm_rootvp->v_usecount > 1)
280 error = vflush(mp, umapm_rootvp, flags);
284 #ifdef UMAPFS_DIAGNOSTIC
285 vprint("alias root of lower", umapm_rootvp);
288 * Release reference on underlying root vnode
292 * And blow it away for future re-use
296 * Finally, throw away the umap_mount structure
298 free(mp->mnt_data, M_UMAPFSMNT); /* XXX */
308 struct proc *p = curproc; /* XXX */
311 #ifdef UMAPFS_DIAGNOSTIC
312 printf("umapfs_root(mp = %x, vp = %x->%x)\n", mp,
313 MOUNTTOUMAPMOUNT(mp)->umapm_rootvp,
314 UMAPVPTOLOWERVP(MOUNTTOUMAPMOUNT(mp)->umapm_rootvp)
319 * Return locked reference to root.
321 vp = MOUNTTOUMAPMOUNT(mp)->umapm_rootvp;
323 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p);
329 umapfs_quotactl(mp, cmd, uid, arg, p)
336 return (VFS_QUOTACTL(MOUNTTOUMAPMOUNT(mp)->umapm_vfs, cmd, uid, arg, p));
340 umapfs_statfs(mp, sbp, p)
348 #ifdef UMAPFS_DIAGNOSTIC
349 printf("umapfs_statfs(mp = %x, vp = %x->%x)\n", mp,
350 MOUNTTOUMAPMOUNT(mp)->umapm_rootvp,
351 UMAPVPTOLOWERVP(MOUNTTOUMAPMOUNT(mp)->umapm_rootvp)
355 bzero(&mstat, sizeof(mstat));
357 error = VFS_STATFS(MOUNTTOUMAPMOUNT(mp)->umapm_vfs, &mstat, p);
361 /* now copy across the "interesting" information and fake the rest */
362 sbp->f_type = mstat.f_type;
363 sbp->f_flags = mstat.f_flags;
364 sbp->f_bsize = mstat.f_bsize;
365 sbp->f_iosize = mstat.f_iosize;
366 sbp->f_blocks = mstat.f_blocks;
367 sbp->f_bfree = mstat.f_bfree;
368 sbp->f_bavail = mstat.f_bavail;
369 sbp->f_files = mstat.f_files;
370 sbp->f_ffree = mstat.f_ffree;
371 if (sbp != &mp->mnt_stat) {
372 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
373 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
374 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
380 umapfs_sync(mp, waitfor, cred, p)
387 * XXX - Assumes no data cached at umap layer.
393 umapfs_vget(mp, ino, vpp)
399 return (VFS_VGET(MOUNTTOUMAPMOUNT(mp)->umapm_vfs, ino, vpp));
403 umapfs_fhtovp(mp, fidp, nam, vpp, exflagsp, credanonp)
406 struct sockaddr *nam;
409 struct ucred**credanonp;
412 return (VFS_FHTOVP(MOUNTTOUMAPMOUNT(mp)->umapm_vfs, fidp, nam, vpp, exflagsp,credanonp));
416 umapfs_vptofh(vp, fhp)
420 return (VFS_VPTOFH(UMAPVPTOLOWERVP(vp), fhp));
423 static struct vfsops umap_vfsops = {
437 VFS_SET(umap_vfsops, umap, VFCF_LOOPBACK);