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 * $FreeBSD: src/sys/miscfs/umapfs/umap_vfsops.c,v 1.31.2.2 2001/09/11 09:49:53 kris Exp $
39 * $DragonFly: src/sys/vfs/umapfs/Attic/umap_vfsops.c,v 1.15 2004/12/17 00:18:46 dillon Exp $
44 * (See mount_umap(8) for a description of this layer.)
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/kernel.h>
51 #include <sys/vnode.h>
52 #include <sys/mount.h>
53 #include <sys/nlookup.h>
54 #include <sys/malloc.h>
56 #include <vm/vm_zone.h>
58 extern struct vnodeopv_entry_desc umap_vnodeop_entries[];
60 static MALLOC_DEFINE(M_UMAPFSMNT, "UMAP mount", "UMAP mount structure");
62 static int umapfs_fhtovp (struct mount *mp, struct fid *fidp,
64 static int umapfs_checkexp (struct mount *mp, struct sockaddr *nam,
65 int *extflagsp, struct ucred **credanonp);
66 static int umapfs_mount (struct mount *mp, char *path, caddr_t data,
68 static int umapfs_quotactl (struct mount *mp, int cmd, uid_t uid,
69 caddr_t arg, struct thread *td);
70 static int umapfs_root (struct mount *mp, struct vnode **vpp);
71 static int umapfs_start (struct mount *mp, int flags, struct thread *td);
72 static int umapfs_statfs (struct mount *mp, struct statfs *sbp,
74 static int umapfs_sync (struct mount *mp, int waitfor,
76 static int umapfs_unmount (struct mount *mp, int mntflags,
78 static int umapfs_vget (struct mount *mp, ino_t ino,
80 static int umapfs_vptofh (struct vnode *vp, struct fid *fhp);
81 static int umapfs_extattrctl (struct mount *mp, int cmd,
82 const char *attrname, caddr_t arg,
89 umapfs_mount(struct mount *mp, char *path, caddr_t data, struct thread *td)
91 struct umap_args args;
92 struct vnode *lowerrootvp, *vp;
93 struct vnode *umapm_rootvp;
94 struct umap_mount *amp;
95 struct nlookupdata nd;
105 if ((error = suser(td)) != 0)
109 printf("umapfs_mount(mp = %p)\n", (void *)mp);
115 if (mp->mnt_flag & MNT_UPDATE) {
122 error = copyin(data, (caddr_t)&args, sizeof(struct umap_args));
130 error = nlookup_init(&nd, args.target, UIO_USERSPACE, NLC_FOLLOW);
132 error = nlookup(&nd);
134 error = cache_vget(nd.nl_ncp, nd.nl_cred, LK_EXCLUSIVE,
142 * Sanity check on lower vnode
145 printf("vp = %p, check for VDIR...\n", (void *)lowerrootvp);
147 if (lowerrootvp->v_type != VDIR) {
153 printf("mp = %p\n", (void *)mp);
156 amp = (struct umap_mount *) malloc(sizeof(struct umap_mount),
157 M_UMAPFSMNT, M_WAITOK); /* XXX */
160 * Save reference to underlying FS
162 amp->umapm_vfs = lowerrootvp->v_mount;
165 * Now copy in the number of entries and maps for umap mapping.
167 if (args.nentries > MAPFILEENTRIES || args.gnentries >
173 amp->info_nentries = args.nentries;
174 amp->info_gnentries = args.gnentries;
175 error = copyin(args.mapdata, (caddr_t)amp->info_mapdata,
176 2*sizeof(u_long)*args.nentries);
181 printf("umap_mount:nentries %d\n",args.nentries);
182 for (i = 0; i < args.nentries; i++)
183 printf(" %lu maps to %lu\n", amp->info_mapdata[i][0],
184 amp->info_mapdata[i][1]);
187 error = copyin(args.gmapdata, (caddr_t)amp->info_gmapdata,
188 2*sizeof(u_long)*args.gnentries);
193 printf("umap_mount:gnentries %d\n",args.gnentries);
194 for (i = 0; i < args.gnentries; i++)
195 printf(" group %lu maps to %lu\n",
196 amp->info_gmapdata[i][0],
197 amp->info_gmapdata[i][1]);
200 vfs_add_vnodeops(mp, &mp->mnt_vn_norm_ops, umap_vnodeop_entries);
203 * Save reference. Each mount also holds
204 * a reference on the root vnode.
206 error = umap_node_create(mp, lowerrootvp, &vp);
208 * Unlock the node (either the lower or the alias)
210 VOP_UNLOCK(vp, 0, td);
212 * Make sure the node alias worked
216 free(amp, M_UMAPFSMNT); /* XXX */
221 * Keep a held reference to the root vnode.
222 * It is vrele'd in umapfs_unmount.
225 umapm_rootvp->v_flag |= VROOT;
226 amp->umapm_rootvp = umapm_rootvp;
227 if (UMAPVPTOLOWERVP(umapm_rootvp)->v_mount->mnt_flag & MNT_LOCAL)
228 mp->mnt_flag |= MNT_LOCAL;
229 mp->mnt_data = (qaddr_t) amp;
232 (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
233 bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
234 (void) copyinstr(args.target, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
236 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
237 (void)umapfs_statfs(mp, &mp->mnt_stat, td);
239 printf("umapfs_mount: lower %s, alias at %s\n",
240 mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname);
246 * VFS start. Nothing needed here - the start routine
247 * on the underlying filesystem will have been called
248 * when that filesystem was mounted.
251 umapfs_start(struct mount *mp, int flags, struct thread *td)
254 /* return (VFS_START(MOUNTTOUMAPMOUNT(mp)->umapm_vfs, flags, p)); */
258 * Free reference to umap layer
261 umapfs_unmount(struct mount *mp, int mntflags, struct thread *td)
267 printf("umapfs_unmount(mp = %p)\n", (void *)mp);
270 if (mntflags & MNT_FORCE)
274 * Clear out buffer cache. I don't think we
275 * ever get anything cached at this level at the
276 * moment, but who knows...
280 if (mntinvalbuf(mp, 1))
283 /* There is 1 extra root vnode reference (umapm_rootvp). */
284 error = vflush(mp, 1, flags);
289 * Finally, throw away the umap_mount structure
291 free(mp->mnt_data, M_UMAPFSMNT); /* XXX */
297 umapfs_root(struct mount *mp, struct vnode **vpp)
299 struct thread *td = curthread; /* XXX */
303 printf("umapfs_root(mp = %p, vp = %p->%p)\n",
304 (void *)mp, (void *)MOUNTTOUMAPMOUNT(mp)->umapm_rootvp,
305 (void *)UMAPVPTOLOWERVP(MOUNTTOUMAPMOUNT(mp)->umapm_rootvp));
309 * Return locked reference to root.
311 vp = MOUNTTOUMAPMOUNT(mp)->umapm_rootvp;
313 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
319 umapfs_quotactl(struct mount *mp, int cmd, uid_t uid,
320 caddr_t arg, struct thread *td)
322 return (VFS_QUOTACTL(MOUNTTOUMAPMOUNT(mp)->umapm_vfs, cmd, uid, arg, td));
326 umapfs_statfs(struct mount *mp, struct statfs *sbp, struct thread *td)
332 printf("umapfs_statfs(mp = %p, vp = %p->%p)\n",
333 (void *)mp, (void *)MOUNTTOUMAPMOUNT(mp)->umapm_rootvp,
334 (void *)UMAPVPTOLOWERVP(MOUNTTOUMAPMOUNT(mp)->umapm_rootvp));
337 bzero(&mstat, sizeof(mstat));
339 error = VFS_STATFS(MOUNTTOUMAPMOUNT(mp)->umapm_vfs, &mstat, td);
343 /* now copy across the "interesting" information and fake the rest */
344 sbp->f_type = mstat.f_type;
345 sbp->f_flags = mstat.f_flags;
346 sbp->f_bsize = mstat.f_bsize;
347 sbp->f_iosize = mstat.f_iosize;
348 sbp->f_blocks = mstat.f_blocks;
349 sbp->f_bfree = mstat.f_bfree;
350 sbp->f_bavail = mstat.f_bavail;
351 sbp->f_files = mstat.f_files;
352 sbp->f_ffree = mstat.f_ffree;
353 if (sbp != &mp->mnt_stat) {
354 bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
355 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
356 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
362 umapfs_sync(struct mount *mp, int waitfor, struct thread *td)
365 * XXX - Assumes no data cached at umap layer.
371 umapfs_vget(struct mount *mp, ino_t ino, struct vnode **vpp)
374 return (VFS_VGET(MOUNTTOUMAPMOUNT(mp)->umapm_vfs, ino, vpp));
378 umapfs_fhtovp(struct mount *mp, struct fid *fidp, struct vnode **vpp)
381 return (VFS_FHTOVP(MOUNTTOUMAPMOUNT(mp)->umapm_vfs, fidp, vpp));
385 umapfs_checkexp(struct mount *mp, struct sockaddr *nam, int *exflagsp,
386 struct ucred **credanonp)
389 return (VFS_CHECKEXP(MOUNTTOUMAPMOUNT(mp)->umapm_vfs, nam,
390 exflagsp, credanonp));
394 umapfs_vptofh(struct vnode *vp, struct fid *fhp)
396 return (VFS_VPTOFH(UMAPVPTOLOWERVP(vp), fhp));
400 umapfs_extattrctl(struct mount *mp, int cmd, const char *attrname,
401 caddr_t arg, struct thread *td)
403 return (VFS_EXTATTRCTL(MOUNTTOUMAPMOUNT(mp)->umapm_vfs, cmd, attrname,
408 static struct vfsops umap_vfsops = {
425 VFS_SET(umap_vfsops, umap, VFCF_LOOPBACK);