union_vfsops.c revision 1.9 1 1.9 agc /* $NetBSD: union_vfsops.c,v 1.9 2003/08/07 16:31:40 agc Exp $ */
2 1.1 jdolecek
3 1.1 jdolecek /*
4 1.1 jdolecek * Copyright (c) 1994 The Regents of the University of California.
5 1.9 agc * All rights reserved.
6 1.9 agc *
7 1.9 agc * This code is derived from software donated to Berkeley by
8 1.9 agc * Jan-Simon Pendry.
9 1.9 agc *
10 1.9 agc * Redistribution and use in source and binary forms, with or without
11 1.9 agc * modification, are permitted provided that the following conditions
12 1.9 agc * are met:
13 1.9 agc * 1. Redistributions of source code must retain the above copyright
14 1.9 agc * notice, this list of conditions and the following disclaimer.
15 1.9 agc * 2. Redistributions in binary form must reproduce the above copyright
16 1.9 agc * notice, this list of conditions and the following disclaimer in the
17 1.9 agc * documentation and/or other materials provided with the distribution.
18 1.9 agc * 3. Neither the name of the University nor the names of its contributors
19 1.9 agc * may be used to endorse or promote products derived from this software
20 1.9 agc * without specific prior written permission.
21 1.9 agc *
22 1.9 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.9 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.9 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.9 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.9 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.9 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.9 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.9 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.9 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.9 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.9 agc * SUCH DAMAGE.
33 1.9 agc *
34 1.9 agc * @(#)union_vfsops.c 8.20 (Berkeley) 5/20/95
35 1.9 agc */
36 1.9 agc
37 1.9 agc /*
38 1.1 jdolecek * Copyright (c) 1994 Jan-Simon Pendry.
39 1.1 jdolecek * All rights reserved.
40 1.1 jdolecek *
41 1.1 jdolecek * This code is derived from software donated to Berkeley by
42 1.1 jdolecek * Jan-Simon Pendry.
43 1.1 jdolecek *
44 1.1 jdolecek * Redistribution and use in source and binary forms, with or without
45 1.1 jdolecek * modification, are permitted provided that the following conditions
46 1.1 jdolecek * are met:
47 1.1 jdolecek * 1. Redistributions of source code must retain the above copyright
48 1.1 jdolecek * notice, this list of conditions and the following disclaimer.
49 1.1 jdolecek * 2. Redistributions in binary form must reproduce the above copyright
50 1.1 jdolecek * notice, this list of conditions and the following disclaimer in the
51 1.1 jdolecek * documentation and/or other materials provided with the distribution.
52 1.1 jdolecek * 3. All advertising materials mentioning features or use of this software
53 1.1 jdolecek * must display the following acknowledgement:
54 1.1 jdolecek * This product includes software developed by the University of
55 1.1 jdolecek * California, Berkeley and its contributors.
56 1.1 jdolecek * 4. Neither the name of the University nor the names of its contributors
57 1.1 jdolecek * may be used to endorse or promote products derived from this software
58 1.1 jdolecek * without specific prior written permission.
59 1.1 jdolecek *
60 1.1 jdolecek * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
61 1.1 jdolecek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62 1.1 jdolecek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
63 1.1 jdolecek * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
64 1.1 jdolecek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
65 1.1 jdolecek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
66 1.1 jdolecek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67 1.1 jdolecek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68 1.1 jdolecek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69 1.1 jdolecek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70 1.1 jdolecek * SUCH DAMAGE.
71 1.1 jdolecek *
72 1.1 jdolecek * @(#)union_vfsops.c 8.20 (Berkeley) 5/20/95
73 1.1 jdolecek */
74 1.1 jdolecek
75 1.1 jdolecek /*
76 1.1 jdolecek * Union Layer
77 1.1 jdolecek */
78 1.1 jdolecek
79 1.1 jdolecek #include <sys/cdefs.h>
80 1.9 agc __KERNEL_RCSID(0, "$NetBSD: union_vfsops.c,v 1.9 2003/08/07 16:31:40 agc Exp $");
81 1.1 jdolecek
82 1.1 jdolecek #include <sys/param.h>
83 1.1 jdolecek #include <sys/systm.h>
84 1.1 jdolecek #include <sys/time.h>
85 1.1 jdolecek #include <sys/proc.h>
86 1.1 jdolecek #include <sys/vnode.h>
87 1.1 jdolecek #include <sys/mount.h>
88 1.1 jdolecek #include <sys/namei.h>
89 1.1 jdolecek #include <sys/malloc.h>
90 1.1 jdolecek #include <sys/filedesc.h>
91 1.1 jdolecek #include <sys/queue.h>
92 1.1 jdolecek #include <sys/stat.h>
93 1.1 jdolecek
94 1.1 jdolecek #include <fs/union/union.h>
95 1.1 jdolecek
96 1.1 jdolecek int union_mount __P((struct mount *, const char *, void *, struct nameidata *,
97 1.8 fvdl struct proc *));
98 1.8 fvdl int union_start __P((struct mount *, int, struct proc *));
99 1.8 fvdl int union_unmount __P((struct mount *, int, struct proc *));
100 1.7 thorpej int union_root __P((struct mount *, struct vnode **));
101 1.8 fvdl int union_quotactl __P((struct mount *, int, uid_t, caddr_t, struct proc *));
102 1.8 fvdl int union_statfs __P((struct mount *, struct statfs *, struct proc *));
103 1.8 fvdl int union_sync __P((struct mount *, int, struct ucred *, struct proc *));
104 1.7 thorpej int union_vget __P((struct mount *, ino_t, struct vnode **));
105 1.7 thorpej int union_fhtovp __P((struct mount *, struct fid *, struct vnode **));
106 1.1 jdolecek int union_checkexp __P((struct mount *, struct mbuf *, int *,
107 1.1 jdolecek struct ucred **));
108 1.1 jdolecek int union_vptofh __P((struct vnode *, struct fid *));
109 1.1 jdolecek int union_sysctl __P((int *, u_int, void *, size_t *, void *, size_t,
110 1.8 fvdl struct proc *));
111 1.1 jdolecek
112 1.1 jdolecek /*
113 1.1 jdolecek * Mount union filesystem
114 1.1 jdolecek */
115 1.1 jdolecek int
116 1.8 fvdl union_mount(mp, path, data, ndp, p)
117 1.1 jdolecek struct mount *mp;
118 1.1 jdolecek const char *path;
119 1.1 jdolecek void *data;
120 1.1 jdolecek struct nameidata *ndp;
121 1.8 fvdl struct proc *p;
122 1.1 jdolecek {
123 1.1 jdolecek int error = 0;
124 1.1 jdolecek struct union_args args;
125 1.1 jdolecek struct vnode *lowerrootvp = NULLVP;
126 1.1 jdolecek struct vnode *upperrootvp = NULLVP;
127 1.1 jdolecek struct union_mount *um = 0;
128 1.1 jdolecek struct ucred *cred = 0;
129 1.1 jdolecek char *cp;
130 1.1 jdolecek int len;
131 1.1 jdolecek size_t size;
132 1.1 jdolecek
133 1.1 jdolecek #ifdef UNION_DIAGNOSTIC
134 1.1 jdolecek printf("union_mount(mp = %p)\n", mp);
135 1.1 jdolecek #endif
136 1.1 jdolecek
137 1.1 jdolecek if (mp->mnt_flag & MNT_GETARGS) {
138 1.1 jdolecek um = MOUNTTOUNIONMOUNT(mp);
139 1.1 jdolecek if (um == NULL)
140 1.1 jdolecek return EIO;
141 1.1 jdolecek args.target = NULL;
142 1.1 jdolecek args.mntflags = um->um_op;
143 1.1 jdolecek return copyout(&args, data, sizeof(args));
144 1.1 jdolecek }
145 1.1 jdolecek /*
146 1.1 jdolecek * Update is a no-op
147 1.1 jdolecek */
148 1.1 jdolecek if (mp->mnt_flag & MNT_UPDATE) {
149 1.1 jdolecek /*
150 1.1 jdolecek * Need to provide.
151 1.1 jdolecek * 1. a way to convert between rdonly and rdwr mounts.
152 1.1 jdolecek * 2. support for nfs exports.
153 1.1 jdolecek */
154 1.1 jdolecek error = EOPNOTSUPP;
155 1.1 jdolecek goto bad;
156 1.1 jdolecek }
157 1.1 jdolecek
158 1.1 jdolecek /*
159 1.1 jdolecek * Get argument
160 1.1 jdolecek */
161 1.1 jdolecek error = copyin(data, (caddr_t)&args, sizeof(struct union_args));
162 1.1 jdolecek if (error)
163 1.1 jdolecek goto bad;
164 1.1 jdolecek
165 1.1 jdolecek lowerrootvp = mp->mnt_vnodecovered;
166 1.1 jdolecek VREF(lowerrootvp);
167 1.1 jdolecek
168 1.1 jdolecek /*
169 1.1 jdolecek * Find upper node.
170 1.1 jdolecek */
171 1.1 jdolecek NDINIT(ndp, LOOKUP, FOLLOW,
172 1.8 fvdl UIO_USERSPACE, args.target, p);
173 1.1 jdolecek
174 1.1 jdolecek if ((error = namei(ndp)) != 0)
175 1.1 jdolecek goto bad;
176 1.1 jdolecek
177 1.1 jdolecek upperrootvp = ndp->ni_vp;
178 1.1 jdolecek
179 1.1 jdolecek if (upperrootvp->v_type != VDIR) {
180 1.1 jdolecek error = EINVAL;
181 1.1 jdolecek goto bad;
182 1.1 jdolecek }
183 1.1 jdolecek
184 1.1 jdolecek um = (struct union_mount *) malloc(sizeof(struct union_mount),
185 1.1 jdolecek M_UFSMNT, M_WAITOK); /* XXX */
186 1.1 jdolecek
187 1.1 jdolecek /*
188 1.1 jdolecek * Keep a held reference to the target vnodes.
189 1.1 jdolecek * They are vrele'd in union_unmount.
190 1.1 jdolecek *
191 1.1 jdolecek * Depending on the _BELOW flag, the filesystems are
192 1.1 jdolecek * viewed in a different order. In effect, this is the
193 1.1 jdolecek * same as providing a mount under option to the mount syscall.
194 1.1 jdolecek */
195 1.1 jdolecek
196 1.1 jdolecek um->um_op = args.mntflags & UNMNT_OPMASK;
197 1.1 jdolecek switch (um->um_op) {
198 1.1 jdolecek case UNMNT_ABOVE:
199 1.1 jdolecek um->um_lowervp = lowerrootvp;
200 1.1 jdolecek um->um_uppervp = upperrootvp;
201 1.1 jdolecek break;
202 1.1 jdolecek
203 1.1 jdolecek case UNMNT_BELOW:
204 1.1 jdolecek um->um_lowervp = upperrootvp;
205 1.1 jdolecek um->um_uppervp = lowerrootvp;
206 1.1 jdolecek break;
207 1.1 jdolecek
208 1.1 jdolecek case UNMNT_REPLACE:
209 1.1 jdolecek vrele(lowerrootvp);
210 1.1 jdolecek lowerrootvp = NULLVP;
211 1.1 jdolecek um->um_uppervp = upperrootvp;
212 1.1 jdolecek um->um_lowervp = lowerrootvp;
213 1.1 jdolecek break;
214 1.1 jdolecek
215 1.1 jdolecek default:
216 1.1 jdolecek error = EINVAL;
217 1.1 jdolecek goto bad;
218 1.1 jdolecek }
219 1.1 jdolecek
220 1.1 jdolecek /*
221 1.1 jdolecek * Unless the mount is readonly, ensure that the top layer
222 1.1 jdolecek * supports whiteout operations
223 1.1 jdolecek */
224 1.1 jdolecek if ((mp->mnt_flag & MNT_RDONLY) == 0) {
225 1.1 jdolecek error = VOP_WHITEOUT(um->um_uppervp, (struct componentname *) 0, LOOKUP);
226 1.1 jdolecek if (error)
227 1.1 jdolecek goto bad;
228 1.1 jdolecek }
229 1.1 jdolecek
230 1.1 jdolecek um->um_cred = p->p_ucred;
231 1.1 jdolecek crhold(um->um_cred);
232 1.1 jdolecek um->um_cmode = UN_DIRMODE &~ p->p_cwdi->cwdi_cmask;
233 1.1 jdolecek
234 1.1 jdolecek /*
235 1.1 jdolecek * Depending on what you think the MNT_LOCAL flag might mean,
236 1.1 jdolecek * you may want the && to be || on the conditional below.
237 1.1 jdolecek * At the moment it has been defined that the filesystem is
238 1.1 jdolecek * only local if it is all local, ie the MNT_LOCAL flag implies
239 1.1 jdolecek * that the entire namespace is local. If you think the MNT_LOCAL
240 1.1 jdolecek * flag implies that some of the files might be stored locally
241 1.1 jdolecek * then you will want to change the conditional.
242 1.1 jdolecek */
243 1.1 jdolecek if (um->um_op == UNMNT_ABOVE) {
244 1.1 jdolecek if (((um->um_lowervp == NULLVP) ||
245 1.1 jdolecek (um->um_lowervp->v_mount->mnt_flag & MNT_LOCAL)) &&
246 1.1 jdolecek (um->um_uppervp->v_mount->mnt_flag & MNT_LOCAL))
247 1.1 jdolecek mp->mnt_flag |= MNT_LOCAL;
248 1.1 jdolecek }
249 1.1 jdolecek
250 1.1 jdolecek /*
251 1.1 jdolecek * Copy in the upper layer's RDONLY flag. This is for the benefit
252 1.1 jdolecek * of lookup() which explicitly checks the flag, rather than asking
253 1.1 jdolecek * the filesystem for it's own opinion. This means, that an update
254 1.1 jdolecek * mount of the underlying filesystem to go from rdonly to rdwr
255 1.1 jdolecek * will leave the unioned view as read-only.
256 1.1 jdolecek */
257 1.1 jdolecek mp->mnt_flag |= (um->um_uppervp->v_mount->mnt_flag & MNT_RDONLY);
258 1.1 jdolecek
259 1.1 jdolecek mp->mnt_data = um;
260 1.1 jdolecek vfs_getnewfsid(mp);
261 1.1 jdolecek
262 1.4 christos error = set_statfs_info( path, UIO_USERSPACE, NULL, UIO_USERSPACE,
263 1.8 fvdl mp, p);
264 1.4 christos if (error)
265 1.4 christos goto bad;
266 1.1 jdolecek
267 1.1 jdolecek switch (um->um_op) {
268 1.1 jdolecek case UNMNT_ABOVE:
269 1.1 jdolecek cp = "<above>:";
270 1.1 jdolecek break;
271 1.1 jdolecek case UNMNT_BELOW:
272 1.1 jdolecek cp = "<below>:";
273 1.1 jdolecek break;
274 1.1 jdolecek case UNMNT_REPLACE:
275 1.1 jdolecek cp = "";
276 1.1 jdolecek break;
277 1.1 jdolecek default:
278 1.1 jdolecek cp = "<invalid>:";
279 1.1 jdolecek #ifdef DIAGNOSTIC
280 1.1 jdolecek panic("union_mount: bad um_op");
281 1.1 jdolecek #endif
282 1.1 jdolecek break;
283 1.1 jdolecek }
284 1.1 jdolecek len = strlen(cp);
285 1.1 jdolecek memcpy(mp->mnt_stat.f_mntfromname, cp, len);
286 1.1 jdolecek
287 1.1 jdolecek cp = mp->mnt_stat.f_mntfromname + len;
288 1.1 jdolecek len = MNAMELEN - len;
289 1.1 jdolecek
290 1.1 jdolecek (void) copyinstr(args.target, cp, len - 1, &size);
291 1.1 jdolecek memset(cp + size, 0, len - size);
292 1.1 jdolecek
293 1.1 jdolecek #ifdef UNION_DIAGNOSTIC
294 1.1 jdolecek printf("union_mount: from %s, on %s\n",
295 1.1 jdolecek mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname);
296 1.1 jdolecek #endif
297 1.2 jdolecek
298 1.2 jdolecek /* Setup the readdir hook if it's not set already */
299 1.2 jdolecek if (!vn_union_readdir_hook)
300 1.2 jdolecek vn_union_readdir_hook = union_readdirhook;
301 1.2 jdolecek
302 1.1 jdolecek return (0);
303 1.1 jdolecek
304 1.1 jdolecek bad:
305 1.1 jdolecek if (um)
306 1.1 jdolecek free(um, M_UFSMNT);
307 1.1 jdolecek if (cred)
308 1.1 jdolecek crfree(cred);
309 1.1 jdolecek if (upperrootvp)
310 1.1 jdolecek vrele(upperrootvp);
311 1.1 jdolecek if (lowerrootvp)
312 1.1 jdolecek vrele(lowerrootvp);
313 1.1 jdolecek return (error);
314 1.1 jdolecek }
315 1.1 jdolecek
316 1.1 jdolecek /*
317 1.1 jdolecek * VFS start. Nothing needed here - the start routine
318 1.1 jdolecek * on the underlying filesystem(s) will have been called
319 1.1 jdolecek * when that filesystem was mounted.
320 1.1 jdolecek */
321 1.1 jdolecek /*ARGSUSED*/
322 1.1 jdolecek int
323 1.8 fvdl union_start(mp, flags, p)
324 1.1 jdolecek struct mount *mp;
325 1.1 jdolecek int flags;
326 1.8 fvdl struct proc *p;
327 1.1 jdolecek {
328 1.1 jdolecek
329 1.1 jdolecek return (0);
330 1.1 jdolecek }
331 1.1 jdolecek
332 1.1 jdolecek /*
333 1.1 jdolecek * Free reference to union layer
334 1.1 jdolecek */
335 1.1 jdolecek int
336 1.8 fvdl union_unmount(mp, mntflags, p)
337 1.1 jdolecek struct mount *mp;
338 1.1 jdolecek int mntflags;
339 1.8 fvdl struct proc *p;
340 1.1 jdolecek {
341 1.1 jdolecek struct union_mount *um = MOUNTTOUNIONMOUNT(mp);
342 1.1 jdolecek struct vnode *um_rootvp;
343 1.1 jdolecek int error;
344 1.1 jdolecek int freeing;
345 1.1 jdolecek
346 1.1 jdolecek #ifdef UNION_DIAGNOSTIC
347 1.1 jdolecek printf("union_unmount(mp = %p)\n", mp);
348 1.1 jdolecek #endif
349 1.1 jdolecek
350 1.7 thorpej if ((error = union_root(mp, &um_rootvp)) != 0)
351 1.1 jdolecek return (error);
352 1.1 jdolecek
353 1.1 jdolecek /*
354 1.1 jdolecek * Keep flushing vnodes from the mount list.
355 1.1 jdolecek * This is needed because of the un_pvp held
356 1.1 jdolecek * reference to the parent vnode.
357 1.1 jdolecek * If more vnodes have been freed on a given pass,
358 1.1 jdolecek * the try again. The loop will iterate at most
359 1.1 jdolecek * (d) times, where (d) is the maximum tree depth
360 1.1 jdolecek * in the filesystem.
361 1.1 jdolecek */
362 1.1 jdolecek for (freeing = 0; vflush(mp, um_rootvp, 0) != 0;) {
363 1.1 jdolecek struct vnode *vp;
364 1.1 jdolecek int n;
365 1.1 jdolecek
366 1.1 jdolecek /* count #vnodes held on mount list */
367 1.1 jdolecek for (n = 0, vp = mp->mnt_vnodelist.lh_first;
368 1.1 jdolecek vp != NULLVP;
369 1.1 jdolecek vp = vp->v_mntvnodes.le_next)
370 1.1 jdolecek n++;
371 1.1 jdolecek
372 1.1 jdolecek /* if this is unchanged then stop */
373 1.1 jdolecek if (n == freeing)
374 1.1 jdolecek break;
375 1.1 jdolecek
376 1.1 jdolecek /* otherwise try once more time */
377 1.1 jdolecek freeing = n;
378 1.1 jdolecek }
379 1.1 jdolecek
380 1.1 jdolecek /*
381 1.1 jdolecek * Ok, now that we've tried doing it gently, get out the hammer.
382 1.1 jdolecek */
383 1.1 jdolecek
384 1.1 jdolecek if (mntflags & MNT_FORCE)
385 1.1 jdolecek vflush(mp, um_rootvp, FORCECLOSE);
386 1.1 jdolecek
387 1.1 jdolecek
388 1.1 jdolecek /* At this point the root vnode should have a single reference */
389 1.1 jdolecek if (um_rootvp->v_usecount > 1) {
390 1.1 jdolecek vput(um_rootvp);
391 1.1 jdolecek return (EBUSY);
392 1.1 jdolecek }
393 1.1 jdolecek
394 1.1 jdolecek #ifdef UNION_DIAGNOSTIC
395 1.1 jdolecek vprint("union root", um_rootvp);
396 1.1 jdolecek #endif
397 1.1 jdolecek /*
398 1.1 jdolecek * Discard references to upper and lower target vnodes.
399 1.1 jdolecek */
400 1.1 jdolecek if (um->um_lowervp)
401 1.1 jdolecek vrele(um->um_lowervp);
402 1.1 jdolecek vrele(um->um_uppervp);
403 1.1 jdolecek crfree(um->um_cred);
404 1.1 jdolecek /*
405 1.1 jdolecek * Release reference on underlying root vnode
406 1.1 jdolecek */
407 1.1 jdolecek vput(um_rootvp);
408 1.1 jdolecek /*
409 1.1 jdolecek * And blow it away for future re-use
410 1.1 jdolecek */
411 1.1 jdolecek vgone(um_rootvp);
412 1.1 jdolecek /*
413 1.1 jdolecek * Finally, throw away the union_mount structure
414 1.1 jdolecek */
415 1.1 jdolecek free(mp->mnt_data, M_UFSMNT); /* XXX */
416 1.1 jdolecek mp->mnt_data = 0;
417 1.1 jdolecek return (0);
418 1.1 jdolecek }
419 1.1 jdolecek
420 1.1 jdolecek int
421 1.7 thorpej union_root(mp, vpp)
422 1.1 jdolecek struct mount *mp;
423 1.1 jdolecek struct vnode **vpp;
424 1.1 jdolecek {
425 1.1 jdolecek struct union_mount *um = MOUNTTOUNIONMOUNT(mp);
426 1.1 jdolecek int error;
427 1.1 jdolecek int loselock;
428 1.1 jdolecek
429 1.1 jdolecek /*
430 1.1 jdolecek * Return locked reference to root.
431 1.1 jdolecek */
432 1.1 jdolecek VREF(um->um_uppervp);
433 1.1 jdolecek if ((um->um_op == UNMNT_BELOW) &&
434 1.1 jdolecek VOP_ISLOCKED(um->um_uppervp)) {
435 1.1 jdolecek loselock = 1;
436 1.1 jdolecek } else {
437 1.1 jdolecek vn_lock(um->um_uppervp, LK_EXCLUSIVE | LK_RETRY);
438 1.1 jdolecek loselock = 0;
439 1.1 jdolecek }
440 1.1 jdolecek if (um->um_lowervp)
441 1.1 jdolecek VREF(um->um_lowervp);
442 1.1 jdolecek error = union_allocvp(vpp, mp,
443 1.1 jdolecek (struct vnode *) 0,
444 1.1 jdolecek (struct vnode *) 0,
445 1.1 jdolecek (struct componentname *) 0,
446 1.1 jdolecek um->um_uppervp,
447 1.1 jdolecek um->um_lowervp,
448 1.7 thorpej 1);
449 1.1 jdolecek
450 1.1 jdolecek if (error) {
451 1.1 jdolecek if (!loselock)
452 1.1 jdolecek VOP_UNLOCK(um->um_uppervp, 0);
453 1.1 jdolecek vrele(um->um_uppervp);
454 1.1 jdolecek if (um->um_lowervp)
455 1.1 jdolecek vrele(um->um_lowervp);
456 1.1 jdolecek } else {
457 1.1 jdolecek if (loselock)
458 1.1 jdolecek VTOUNION(*vpp)->un_flags &= ~UN_ULOCK;
459 1.1 jdolecek }
460 1.1 jdolecek
461 1.1 jdolecek return (error);
462 1.1 jdolecek }
463 1.1 jdolecek
464 1.1 jdolecek /*ARGSUSED*/
465 1.1 jdolecek int
466 1.8 fvdl union_quotactl(mp, cmd, uid, arg, p)
467 1.1 jdolecek struct mount *mp;
468 1.1 jdolecek int cmd;
469 1.1 jdolecek uid_t uid;
470 1.1 jdolecek caddr_t arg;
471 1.8 fvdl struct proc *p;
472 1.1 jdolecek {
473 1.1 jdolecek
474 1.1 jdolecek return (EOPNOTSUPP);
475 1.1 jdolecek }
476 1.1 jdolecek
477 1.1 jdolecek int
478 1.8 fvdl union_statfs(mp, sbp, p)
479 1.1 jdolecek struct mount *mp;
480 1.1 jdolecek struct statfs *sbp;
481 1.8 fvdl struct proc *p;
482 1.1 jdolecek {
483 1.1 jdolecek int error;
484 1.1 jdolecek struct union_mount *um = MOUNTTOUNIONMOUNT(mp);
485 1.1 jdolecek struct statfs mstat;
486 1.1 jdolecek int lbsize;
487 1.1 jdolecek
488 1.1 jdolecek #ifdef UNION_DIAGNOSTIC
489 1.1 jdolecek printf("union_statfs(mp = %p, lvp = %p, uvp = %p)\n", mp,
490 1.1 jdolecek um->um_lowervp, um->um_uppervp);
491 1.1 jdolecek #endif
492 1.1 jdolecek
493 1.1 jdolecek memset(&mstat, 0, sizeof(mstat));
494 1.1 jdolecek
495 1.1 jdolecek if (um->um_lowervp) {
496 1.8 fvdl error = VFS_STATFS(um->um_lowervp->v_mount, &mstat, p);
497 1.1 jdolecek if (error)
498 1.1 jdolecek return (error);
499 1.1 jdolecek }
500 1.1 jdolecek
501 1.1 jdolecek /* now copy across the "interesting" information and fake the rest */
502 1.1 jdolecek lbsize = mstat.f_bsize;
503 1.1 jdolecek sbp->f_blocks = mstat.f_blocks - mstat.f_bfree;
504 1.1 jdolecek sbp->f_files = mstat.f_files - mstat.f_ffree;
505 1.1 jdolecek
506 1.8 fvdl error = VFS_STATFS(um->um_uppervp->v_mount, &mstat, p);
507 1.1 jdolecek if (error)
508 1.1 jdolecek return (error);
509 1.1 jdolecek
510 1.1 jdolecek sbp->f_type = 0;
511 1.1 jdolecek sbp->f_flags = mstat.f_flags;
512 1.1 jdolecek sbp->f_bsize = mstat.f_bsize;
513 1.1 jdolecek sbp->f_iosize = mstat.f_iosize;
514 1.1 jdolecek
515 1.1 jdolecek /*
516 1.1 jdolecek * The "total" fields count total resources in all layers,
517 1.1 jdolecek * the "free" fields count only those resources which are
518 1.1 jdolecek * free in the upper layer (since only the upper layer
519 1.1 jdolecek * is writable).
520 1.1 jdolecek */
521 1.1 jdolecek
522 1.1 jdolecek if (mstat.f_bsize != lbsize)
523 1.1 jdolecek sbp->f_blocks = sbp->f_blocks * lbsize / mstat.f_bsize;
524 1.1 jdolecek sbp->f_blocks += mstat.f_blocks;
525 1.1 jdolecek sbp->f_bfree = mstat.f_bfree;
526 1.1 jdolecek sbp->f_bavail = mstat.f_bavail;
527 1.1 jdolecek sbp->f_files += mstat.f_files;
528 1.1 jdolecek sbp->f_ffree = mstat.f_ffree;
529 1.1 jdolecek
530 1.4 christos copy_statfs_info(sbp, mp);
531 1.1 jdolecek return (0);
532 1.1 jdolecek }
533 1.1 jdolecek
534 1.1 jdolecek /*ARGSUSED*/
535 1.1 jdolecek int
536 1.8 fvdl union_sync(mp, waitfor, cred, p)
537 1.1 jdolecek struct mount *mp;
538 1.1 jdolecek int waitfor;
539 1.1 jdolecek struct ucred *cred;
540 1.8 fvdl struct proc *p;
541 1.1 jdolecek {
542 1.1 jdolecek
543 1.1 jdolecek /*
544 1.1 jdolecek * XXX - Assumes no data cached at union layer.
545 1.1 jdolecek */
546 1.1 jdolecek return (0);
547 1.1 jdolecek }
548 1.1 jdolecek
549 1.1 jdolecek /*ARGSUSED*/
550 1.1 jdolecek int
551 1.7 thorpej union_vget(mp, ino, vpp)
552 1.1 jdolecek struct mount *mp;
553 1.1 jdolecek ino_t ino;
554 1.1 jdolecek struct vnode **vpp;
555 1.1 jdolecek {
556 1.1 jdolecek
557 1.1 jdolecek return (EOPNOTSUPP);
558 1.1 jdolecek }
559 1.1 jdolecek
560 1.1 jdolecek /*ARGSUSED*/
561 1.1 jdolecek int
562 1.7 thorpej union_fhtovp(mp, fidp, vpp)
563 1.1 jdolecek struct mount *mp;
564 1.1 jdolecek struct fid *fidp;
565 1.1 jdolecek struct vnode **vpp;
566 1.1 jdolecek {
567 1.1 jdolecek
568 1.1 jdolecek return (EOPNOTSUPP);
569 1.1 jdolecek }
570 1.1 jdolecek
571 1.1 jdolecek /*ARGSUSED*/
572 1.1 jdolecek int
573 1.1 jdolecek union_checkexp(mp, nam, exflagsp, credanonp)
574 1.1 jdolecek struct mount *mp;
575 1.1 jdolecek struct mbuf *nam;
576 1.1 jdolecek int *exflagsp;
577 1.1 jdolecek struct ucred **credanonp;
578 1.1 jdolecek {
579 1.1 jdolecek
580 1.1 jdolecek return (EOPNOTSUPP);
581 1.1 jdolecek }
582 1.1 jdolecek
583 1.1 jdolecek /*ARGSUSED*/
584 1.1 jdolecek int
585 1.1 jdolecek union_vptofh(vp, fhp)
586 1.1 jdolecek struct vnode *vp;
587 1.1 jdolecek struct fid *fhp;
588 1.1 jdolecek {
589 1.1 jdolecek
590 1.1 jdolecek return (EOPNOTSUPP);
591 1.1 jdolecek }
592 1.1 jdolecek
593 1.1 jdolecek int
594 1.8 fvdl union_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
595 1.1 jdolecek int *name;
596 1.1 jdolecek u_int namelen;
597 1.1 jdolecek void *oldp;
598 1.1 jdolecek size_t *oldlenp;
599 1.1 jdolecek void *newp;
600 1.1 jdolecek size_t newlen;
601 1.8 fvdl struct proc *p;
602 1.1 jdolecek {
603 1.1 jdolecek return (EOPNOTSUPP);
604 1.1 jdolecek }
605 1.1 jdolecek
606 1.1 jdolecek extern const struct vnodeopv_desc union_vnodeop_opv_desc;
607 1.1 jdolecek
608 1.1 jdolecek const struct vnodeopv_desc * const union_vnodeopv_descs[] = {
609 1.1 jdolecek &union_vnodeop_opv_desc,
610 1.1 jdolecek NULL,
611 1.1 jdolecek };
612 1.1 jdolecek
613 1.1 jdolecek struct vfsops union_vfsops = {
614 1.1 jdolecek MOUNT_UNION,
615 1.1 jdolecek union_mount,
616 1.1 jdolecek union_start,
617 1.1 jdolecek union_unmount,
618 1.1 jdolecek union_root,
619 1.1 jdolecek union_quotactl,
620 1.1 jdolecek union_statfs,
621 1.1 jdolecek union_sync,
622 1.1 jdolecek union_vget,
623 1.1 jdolecek union_fhtovp,
624 1.1 jdolecek union_vptofh,
625 1.1 jdolecek union_init,
626 1.3 jdolecek NULL, /* vfs_reinit */
627 1.1 jdolecek union_done,
628 1.1 jdolecek union_sysctl,
629 1.1 jdolecek NULL, /* vfs_mountroot */
630 1.1 jdolecek union_checkexp,
631 1.1 jdolecek union_vnodeopv_descs,
632 1.1 jdolecek };
633