null_vfsops.c revision 1.1.1.1 1 1.1 mycroft /*
2 1.1 mycroft * Copyright (c) 1992, 1993
3 1.1 mycroft * The Regents of the University of California. All rights reserved.
4 1.1 mycroft *
5 1.1 mycroft * This code is derived from software donated to Berkeley by
6 1.1 mycroft * Jan-Simon Pendry.
7 1.1 mycroft *
8 1.1 mycroft * Redistribution and use in source and binary forms, with or without
9 1.1 mycroft * modification, are permitted provided that the following conditions
10 1.1 mycroft * are met:
11 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
12 1.1 mycroft * notice, this list of conditions and the following disclaimer.
13 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
15 1.1 mycroft * documentation and/or other materials provided with the distribution.
16 1.1 mycroft * 3. All advertising materials mentioning features or use of this software
17 1.1 mycroft * must display the following acknowledgement:
18 1.1 mycroft * This product includes software developed by the University of
19 1.1 mycroft * California, Berkeley and its contributors.
20 1.1 mycroft * 4. Neither the name of the University nor the names of its contributors
21 1.1 mycroft * may be used to endorse or promote products derived from this software
22 1.1 mycroft * without specific prior written permission.
23 1.1 mycroft *
24 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.1 mycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.1 mycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.1 mycroft * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.1 mycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.1 mycroft * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.1 mycroft * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.1 mycroft * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.1 mycroft * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.1 mycroft * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.1 mycroft * SUCH DAMAGE.
35 1.1 mycroft *
36 1.1.1.1 fvdl * @(#)null_vfsops.c 8.2 (Berkeley) 1/21/94
37 1.1.1.1 fvdl *
38 1.1.1.1 fvdl * @(#)lofs_vfsops.c 1.2 (Berkeley) 6/18/92
39 1.1.1.1 fvdl * $Id: null_vfsops.c,v 1.1.1.1 1998/03/01 02:09:59 fvdl Exp $
40 1.1 mycroft */
41 1.1 mycroft
42 1.1 mycroft /*
43 1.1 mycroft * Null Layer
44 1.1 mycroft * (See null_vnops.c for a description of what this does.)
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.1 mycroft #include <sys/time.h>
50 1.1 mycroft #include <sys/types.h>
51 1.1 mycroft #include <sys/vnode.h>
52 1.1 mycroft #include <sys/mount.h>
53 1.1 mycroft #include <sys/namei.h>
54 1.1 mycroft #include <sys/malloc.h>
55 1.1 mycroft #include <miscfs/nullfs/null.h>
56 1.1 mycroft
57 1.1 mycroft /*
58 1.1 mycroft * Mount null layer
59 1.1 mycroft */
60 1.1 mycroft int
61 1.1 mycroft nullfs_mount(mp, path, data, ndp, p)
62 1.1 mycroft struct mount *mp;
63 1.1 mycroft char *path;
64 1.1 mycroft caddr_t data;
65 1.1 mycroft struct nameidata *ndp;
66 1.1 mycroft struct proc *p;
67 1.1 mycroft {
68 1.1 mycroft int error = 0;
69 1.1 mycroft struct null_args args;
70 1.1 mycroft struct vnode *lowerrootvp, *vp;
71 1.1 mycroft struct vnode *nullm_rootvp;
72 1.1 mycroft struct null_mount *xmp;
73 1.1 mycroft u_int size;
74 1.1 mycroft
75 1.1 mycroft #ifdef NULLFS_DIAGNOSTIC
76 1.1 mycroft printf("nullfs_mount(mp = %x)\n", mp);
77 1.1 mycroft #endif
78 1.1 mycroft
79 1.1 mycroft /*
80 1.1 mycroft * Update is a no-op
81 1.1 mycroft */
82 1.1 mycroft if (mp->mnt_flag & MNT_UPDATE) {
83 1.1 mycroft return (EOPNOTSUPP);
84 1.1 mycroft /* return VFS_MOUNT(MOUNTTONULLMOUNT(mp)->nullm_vfs, path, data, ndp, p);*/
85 1.1 mycroft }
86 1.1 mycroft
87 1.1 mycroft /*
88 1.1 mycroft * Get argument
89 1.1 mycroft */
90 1.1 mycroft if (error = copyin(data, (caddr_t)&args, sizeof(struct null_args)))
91 1.1 mycroft return (error);
92 1.1 mycroft
93 1.1 mycroft /*
94 1.1 mycroft * Find lower node
95 1.1 mycroft */
96 1.1 mycroft NDINIT(ndp, LOOKUP, FOLLOW|WANTPARENT|LOCKLEAF,
97 1.1 mycroft UIO_USERSPACE, args.target, p);
98 1.1 mycroft if (error = namei(ndp))
99 1.1 mycroft return (error);
100 1.1 mycroft
101 1.1 mycroft /*
102 1.1 mycroft * Sanity check on lower vnode
103 1.1 mycroft */
104 1.1 mycroft lowerrootvp = ndp->ni_vp;
105 1.1 mycroft
106 1.1 mycroft vrele(ndp->ni_dvp);
107 1.1 mycroft ndp->ni_dvp = NULL;
108 1.1 mycroft
109 1.1 mycroft xmp = (struct null_mount *) malloc(sizeof(struct null_mount),
110 1.1 mycroft M_UFSMNT, M_WAITOK); /* XXX */
111 1.1 mycroft
112 1.1 mycroft /*
113 1.1 mycroft * Save reference to underlying FS
114 1.1 mycroft */
115 1.1 mycroft xmp->nullm_vfs = lowerrootvp->v_mount;
116 1.1 mycroft
117 1.1 mycroft /*
118 1.1 mycroft * Save reference. Each mount also holds
119 1.1 mycroft * a reference on the root vnode.
120 1.1 mycroft */
121 1.1 mycroft error = null_node_create(mp, lowerrootvp, &vp);
122 1.1 mycroft /*
123 1.1 mycroft * Unlock the node (either the lower or the alias)
124 1.1 mycroft */
125 1.1 mycroft VOP_UNLOCK(vp);
126 1.1 mycroft /*
127 1.1 mycroft * Make sure the node alias worked
128 1.1 mycroft */
129 1.1 mycroft if (error) {
130 1.1 mycroft vrele(lowerrootvp);
131 1.1 mycroft free(xmp, M_UFSMNT); /* XXX */
132 1.1 mycroft return (error);
133 1.1 mycroft }
134 1.1 mycroft
135 1.1 mycroft /*
136 1.1 mycroft * Keep a held reference to the root vnode.
137 1.1 mycroft * It is vrele'd in nullfs_unmount.
138 1.1 mycroft */
139 1.1 mycroft nullm_rootvp = vp;
140 1.1 mycroft nullm_rootvp->v_flag |= VROOT;
141 1.1 mycroft xmp->nullm_rootvp = nullm_rootvp;
142 1.1 mycroft if (NULLVPTOLOWERVP(nullm_rootvp)->v_mount->mnt_flag & MNT_LOCAL)
143 1.1 mycroft mp->mnt_flag |= MNT_LOCAL;
144 1.1 mycroft mp->mnt_data = (qaddr_t) xmp;
145 1.1.1.1 fvdl getnewfsid(mp, MOUNT_LOFS);
146 1.1 mycroft
147 1.1 mycroft (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
148 1.1 mycroft bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
149 1.1 mycroft (void) copyinstr(args.target, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
150 1.1 mycroft &size);
151 1.1 mycroft bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
152 1.1 mycroft #ifdef NULLFS_DIAGNOSTIC
153 1.1 mycroft printf("nullfs_mount: lower %s, alias at %s\n",
154 1.1 mycroft mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname);
155 1.1 mycroft #endif
156 1.1 mycroft return (0);
157 1.1 mycroft }
158 1.1 mycroft
159 1.1 mycroft /*
160 1.1 mycroft * VFS start. Nothing needed here - the start routine
161 1.1 mycroft * on the underlying filesystem will have been called
162 1.1 mycroft * when that filesystem was mounted.
163 1.1 mycroft */
164 1.1 mycroft int
165 1.1 mycroft nullfs_start(mp, flags, p)
166 1.1 mycroft struct mount *mp;
167 1.1 mycroft int flags;
168 1.1 mycroft struct proc *p;
169 1.1 mycroft {
170 1.1 mycroft return (0);
171 1.1 mycroft /* return VFS_START(MOUNTTONULLMOUNT(mp)->nullm_vfs, flags, p); */
172 1.1 mycroft }
173 1.1 mycroft
174 1.1 mycroft /*
175 1.1 mycroft * Free reference to null layer
176 1.1 mycroft */
177 1.1 mycroft int
178 1.1 mycroft nullfs_unmount(mp, mntflags, p)
179 1.1 mycroft struct mount *mp;
180 1.1 mycroft int mntflags;
181 1.1 mycroft struct proc *p;
182 1.1 mycroft {
183 1.1 mycroft struct vnode *nullm_rootvp = MOUNTTONULLMOUNT(mp)->nullm_rootvp;
184 1.1 mycroft int error;
185 1.1 mycroft int flags = 0;
186 1.1 mycroft extern int doforce;
187 1.1 mycroft
188 1.1 mycroft #ifdef NULLFS_DIAGNOSTIC
189 1.1 mycroft printf("nullfs_unmount(mp = %x)\n", mp);
190 1.1 mycroft #endif
191 1.1 mycroft
192 1.1 mycroft if (mntflags & MNT_FORCE) {
193 1.1 mycroft /* lofs can never be rootfs so don't check for it */
194 1.1 mycroft if (!doforce)
195 1.1 mycroft return (EINVAL);
196 1.1 mycroft flags |= FORCECLOSE;
197 1.1 mycroft }
198 1.1 mycroft
199 1.1 mycroft /*
200 1.1 mycroft * Clear out buffer cache. I don't think we
201 1.1 mycroft * ever get anything cached at this level at the
202 1.1 mycroft * moment, but who knows...
203 1.1 mycroft */
204 1.1 mycroft #if 0
205 1.1 mycroft mntflushbuf(mp, 0);
206 1.1 mycroft if (mntinvalbuf(mp, 1))
207 1.1 mycroft return (EBUSY);
208 1.1 mycroft #endif
209 1.1 mycroft if (nullm_rootvp->v_usecount > 1)
210 1.1 mycroft return (EBUSY);
211 1.1 mycroft if (error = vflush(mp, nullm_rootvp, flags))
212 1.1 mycroft return (error);
213 1.1 mycroft
214 1.1 mycroft #ifdef NULLFS_DIAGNOSTIC
215 1.1 mycroft vprint("alias root of lower", nullm_rootvp);
216 1.1 mycroft #endif
217 1.1 mycroft /*
218 1.1 mycroft * Release reference on underlying root vnode
219 1.1 mycroft */
220 1.1 mycroft vrele(nullm_rootvp);
221 1.1 mycroft /*
222 1.1 mycroft * And blow it away for future re-use
223 1.1 mycroft */
224 1.1 mycroft vgone(nullm_rootvp);
225 1.1 mycroft /*
226 1.1 mycroft * Finally, throw away the null_mount structure
227 1.1 mycroft */
228 1.1 mycroft free(mp->mnt_data, M_UFSMNT); /* XXX */
229 1.1 mycroft mp->mnt_data = 0;
230 1.1 mycroft return 0;
231 1.1 mycroft }
232 1.1 mycroft
233 1.1 mycroft int
234 1.1 mycroft nullfs_root(mp, vpp)
235 1.1 mycroft struct mount *mp;
236 1.1 mycroft struct vnode **vpp;
237 1.1 mycroft {
238 1.1 mycroft struct vnode *vp;
239 1.1 mycroft
240 1.1 mycroft #ifdef NULLFS_DIAGNOSTIC
241 1.1 mycroft printf("nullfs_root(mp = %x, vp = %x->%x)\n", mp,
242 1.1 mycroft MOUNTTONULLMOUNT(mp)->nullm_rootvp,
243 1.1 mycroft NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp)->nullm_rootvp)
244 1.1 mycroft );
245 1.1 mycroft #endif
246 1.1 mycroft
247 1.1 mycroft /*
248 1.1 mycroft * Return locked reference to root.
249 1.1 mycroft */
250 1.1 mycroft vp = MOUNTTONULLMOUNT(mp)->nullm_rootvp;
251 1.1 mycroft VREF(vp);
252 1.1 mycroft VOP_LOCK(vp);
253 1.1 mycroft *vpp = vp;
254 1.1 mycroft return 0;
255 1.1 mycroft }
256 1.1 mycroft
257 1.1 mycroft int
258 1.1 mycroft nullfs_quotactl(mp, cmd, uid, arg, p)
259 1.1 mycroft struct mount *mp;
260 1.1 mycroft int cmd;
261 1.1 mycroft uid_t uid;
262 1.1 mycroft caddr_t arg;
263 1.1 mycroft struct proc *p;
264 1.1 mycroft {
265 1.1 mycroft return VFS_QUOTACTL(MOUNTTONULLMOUNT(mp)->nullm_vfs, cmd, uid, arg, p);
266 1.1 mycroft }
267 1.1 mycroft
268 1.1 mycroft int
269 1.1 mycroft nullfs_statfs(mp, sbp, p)
270 1.1 mycroft struct mount *mp;
271 1.1 mycroft struct statfs *sbp;
272 1.1 mycroft struct proc *p;
273 1.1 mycroft {
274 1.1 mycroft int error;
275 1.1 mycroft struct statfs mstat;
276 1.1 mycroft
277 1.1 mycroft #ifdef NULLFS_DIAGNOSTIC
278 1.1 mycroft printf("nullfs_statfs(mp = %x, vp = %x->%x)\n", mp,
279 1.1 mycroft MOUNTTONULLMOUNT(mp)->nullm_rootvp,
280 1.1 mycroft NULLVPTOLOWERVP(MOUNTTONULLMOUNT(mp)->nullm_rootvp)
281 1.1 mycroft );
282 1.1 mycroft #endif
283 1.1 mycroft
284 1.1 mycroft bzero(&mstat, sizeof(mstat));
285 1.1 mycroft
286 1.1 mycroft error = VFS_STATFS(MOUNTTONULLMOUNT(mp)->nullm_vfs, &mstat, p);
287 1.1 mycroft if (error)
288 1.1 mycroft return (error);
289 1.1 mycroft
290 1.1 mycroft /* now copy across the "interesting" information and fake the rest */
291 1.1 mycroft sbp->f_type = mstat.f_type;
292 1.1 mycroft sbp->f_flags = mstat.f_flags;
293 1.1 mycroft sbp->f_bsize = mstat.f_bsize;
294 1.1 mycroft sbp->f_iosize = mstat.f_iosize;
295 1.1 mycroft sbp->f_blocks = mstat.f_blocks;
296 1.1 mycroft sbp->f_bfree = mstat.f_bfree;
297 1.1 mycroft sbp->f_bavail = mstat.f_bavail;
298 1.1 mycroft sbp->f_files = mstat.f_files;
299 1.1 mycroft sbp->f_ffree = mstat.f_ffree;
300 1.1 mycroft if (sbp != &mp->mnt_stat) {
301 1.1 mycroft bcopy(&mp->mnt_stat.f_fsid, &sbp->f_fsid, sizeof(sbp->f_fsid));
302 1.1 mycroft bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
303 1.1 mycroft bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
304 1.1 mycroft }
305 1.1 mycroft return (0);
306 1.1 mycroft }
307 1.1 mycroft
308 1.1 mycroft int
309 1.1 mycroft nullfs_sync(mp, waitfor, cred, p)
310 1.1 mycroft struct mount *mp;
311 1.1 mycroft int waitfor;
312 1.1 mycroft struct ucred *cred;
313 1.1 mycroft struct proc *p;
314 1.1 mycroft {
315 1.1 mycroft /*
316 1.1 mycroft * XXX - Assumes no data cached at null layer.
317 1.1 mycroft */
318 1.1 mycroft return (0);
319 1.1 mycroft }
320 1.1 mycroft
321 1.1 mycroft int
322 1.1 mycroft nullfs_vget(mp, ino, vpp)
323 1.1 mycroft struct mount *mp;
324 1.1 mycroft ino_t ino;
325 1.1 mycroft struct vnode **vpp;
326 1.1 mycroft {
327 1.1 mycroft
328 1.1 mycroft return VFS_VGET(MOUNTTONULLMOUNT(mp)->nullm_vfs, ino, vpp);
329 1.1 mycroft }
330 1.1 mycroft
331 1.1 mycroft int
332 1.1 mycroft nullfs_fhtovp(mp, fidp, nam, vpp, exflagsp, credanonp)
333 1.1 mycroft struct mount *mp;
334 1.1 mycroft struct fid *fidp;
335 1.1 mycroft struct mbuf *nam;
336 1.1 mycroft struct vnode **vpp;
337 1.1 mycroft int *exflagsp;
338 1.1 mycroft struct ucred**credanonp;
339 1.1 mycroft {
340 1.1 mycroft
341 1.1 mycroft return VFS_FHTOVP(MOUNTTONULLMOUNT(mp)->nullm_vfs, fidp, nam, vpp, exflagsp,credanonp);
342 1.1 mycroft }
343 1.1 mycroft
344 1.1 mycroft int
345 1.1 mycroft nullfs_vptofh(vp, fhp)
346 1.1 mycroft struct vnode *vp;
347 1.1 mycroft struct fid *fhp;
348 1.1 mycroft {
349 1.1 mycroft return VFS_VPTOFH(NULLVPTOLOWERVP(vp), fhp);
350 1.1 mycroft }
351 1.1 mycroft
352 1.1 mycroft int nullfs_init __P((void));
353 1.1 mycroft
354 1.1 mycroft struct vfsops null_vfsops = {
355 1.1 mycroft nullfs_mount,
356 1.1 mycroft nullfs_start,
357 1.1 mycroft nullfs_unmount,
358 1.1 mycroft nullfs_root,
359 1.1 mycroft nullfs_quotactl,
360 1.1 mycroft nullfs_statfs,
361 1.1 mycroft nullfs_sync,
362 1.1 mycroft nullfs_vget,
363 1.1 mycroft nullfs_fhtovp,
364 1.1 mycroft nullfs_vptofh,
365 1.1 mycroft nullfs_init,
366 1.1 mycroft };
367