union_vfsops.c revision 1.37.2.4 1 1.37.2.4 ad /* $NetBSD: union_vfsops.c,v 1.37.2.4 2007/02/09 21:03:53 ad 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.37.2.4 ad __KERNEL_RCSID(0, "$NetBSD: union_vfsops.c,v 1.37.2.4 2007/02/09 21:03:53 ad Exp $");
81 1.1 jdolecek
82 1.1 jdolecek #include <sys/param.h>
83 1.1 jdolecek #include <sys/systm.h>
84 1.10 atatat #include <sys/sysctl.h>
85 1.1 jdolecek #include <sys/time.h>
86 1.1 jdolecek #include <sys/proc.h>
87 1.1 jdolecek #include <sys/vnode.h>
88 1.1 jdolecek #include <sys/mount.h>
89 1.1 jdolecek #include <sys/namei.h>
90 1.1 jdolecek #include <sys/malloc.h>
91 1.1 jdolecek #include <sys/filedesc.h>
92 1.1 jdolecek #include <sys/queue.h>
93 1.1 jdolecek #include <sys/stat.h>
94 1.35 elad #include <sys/kauth.h>
95 1.1 jdolecek
96 1.1 jdolecek #include <fs/union/union.h>
97 1.1 jdolecek
98 1.29 xtraeme int union_mount(struct mount *, const char *, void *, struct nameidata *,
99 1.31 christos struct lwp *);
100 1.31 christos int union_start(struct mount *, int, struct lwp *);
101 1.31 christos int union_unmount(struct mount *, int, struct lwp *);
102 1.29 xtraeme int union_root(struct mount *, struct vnode **);
103 1.31 christos int union_quotactl(struct mount *, int, uid_t, void *, struct lwp *);
104 1.31 christos int union_statvfs(struct mount *, struct statvfs *, struct lwp *);
105 1.35 elad int union_sync(struct mount *, int, kauth_cred_t, struct lwp *);
106 1.29 xtraeme int union_vget(struct mount *, ino_t, struct vnode **);
107 1.1 jdolecek
108 1.1 jdolecek /*
109 1.1 jdolecek * Mount union filesystem
110 1.1 jdolecek */
111 1.1 jdolecek int
112 1.31 christos union_mount(mp, path, data, ndp, l)
113 1.1 jdolecek struct mount *mp;
114 1.1 jdolecek const char *path;
115 1.1 jdolecek void *data;
116 1.1 jdolecek struct nameidata *ndp;
117 1.31 christos struct lwp *l;
118 1.1 jdolecek {
119 1.1 jdolecek int error = 0;
120 1.1 jdolecek struct union_args args;
121 1.1 jdolecek struct vnode *lowerrootvp = NULLVP;
122 1.1 jdolecek struct vnode *upperrootvp = NULLVP;
123 1.1 jdolecek struct union_mount *um = 0;
124 1.27 christos const char *cp;
125 1.27 christos char *xp;
126 1.1 jdolecek int len;
127 1.1 jdolecek size_t size;
128 1.1 jdolecek
129 1.1 jdolecek #ifdef UNION_DIAGNOSTIC
130 1.1 jdolecek printf("union_mount(mp = %p)\n", mp);
131 1.1 jdolecek #endif
132 1.1 jdolecek
133 1.1 jdolecek if (mp->mnt_flag & MNT_GETARGS) {
134 1.1 jdolecek um = MOUNTTOUNIONMOUNT(mp);
135 1.1 jdolecek if (um == NULL)
136 1.1 jdolecek return EIO;
137 1.1 jdolecek args.target = NULL;
138 1.1 jdolecek args.mntflags = um->um_op;
139 1.1 jdolecek return copyout(&args, data, sizeof(args));
140 1.1 jdolecek }
141 1.1 jdolecek /*
142 1.1 jdolecek * Update is a no-op
143 1.1 jdolecek */
144 1.1 jdolecek if (mp->mnt_flag & MNT_UPDATE) {
145 1.1 jdolecek /*
146 1.1 jdolecek * Need to provide.
147 1.1 jdolecek * 1. a way to convert between rdonly and rdwr mounts.
148 1.1 jdolecek * 2. support for nfs exports.
149 1.1 jdolecek */
150 1.1 jdolecek error = EOPNOTSUPP;
151 1.1 jdolecek goto bad;
152 1.1 jdolecek }
153 1.1 jdolecek
154 1.1 jdolecek /*
155 1.1 jdolecek * Get argument
156 1.1 jdolecek */
157 1.14 jrf error = copyin(data, &args, sizeof(struct union_args));
158 1.1 jdolecek if (error)
159 1.1 jdolecek goto bad;
160 1.1 jdolecek
161 1.1 jdolecek lowerrootvp = mp->mnt_vnodecovered;
162 1.1 jdolecek VREF(lowerrootvp);
163 1.1 jdolecek
164 1.1 jdolecek /*
165 1.1 jdolecek * Find upper node.
166 1.1 jdolecek */
167 1.1 jdolecek NDINIT(ndp, LOOKUP, FOLLOW,
168 1.31 christos UIO_USERSPACE, args.target, l);
169 1.1 jdolecek
170 1.1 jdolecek if ((error = namei(ndp)) != 0)
171 1.1 jdolecek goto bad;
172 1.1 jdolecek
173 1.1 jdolecek upperrootvp = ndp->ni_vp;
174 1.1 jdolecek
175 1.1 jdolecek if (upperrootvp->v_type != VDIR) {
176 1.1 jdolecek error = EINVAL;
177 1.1 jdolecek goto bad;
178 1.1 jdolecek }
179 1.25 perry
180 1.1 jdolecek um = (struct union_mount *) malloc(sizeof(struct union_mount),
181 1.1 jdolecek M_UFSMNT, M_WAITOK); /* XXX */
182 1.1 jdolecek
183 1.1 jdolecek /*
184 1.1 jdolecek * Keep a held reference to the target vnodes.
185 1.1 jdolecek * They are vrele'd in union_unmount.
186 1.1 jdolecek *
187 1.1 jdolecek * Depending on the _BELOW flag, the filesystems are
188 1.1 jdolecek * viewed in a different order. In effect, this is the
189 1.1 jdolecek * same as providing a mount under option to the mount syscall.
190 1.1 jdolecek */
191 1.1 jdolecek
192 1.1 jdolecek um->um_op = args.mntflags & UNMNT_OPMASK;
193 1.1 jdolecek switch (um->um_op) {
194 1.1 jdolecek case UNMNT_ABOVE:
195 1.1 jdolecek um->um_lowervp = lowerrootvp;
196 1.1 jdolecek um->um_uppervp = upperrootvp;
197 1.1 jdolecek break;
198 1.1 jdolecek
199 1.1 jdolecek case UNMNT_BELOW:
200 1.1 jdolecek um->um_lowervp = upperrootvp;
201 1.1 jdolecek um->um_uppervp = lowerrootvp;
202 1.1 jdolecek break;
203 1.1 jdolecek
204 1.1 jdolecek case UNMNT_REPLACE:
205 1.1 jdolecek vrele(lowerrootvp);
206 1.1 jdolecek lowerrootvp = NULLVP;
207 1.1 jdolecek um->um_uppervp = upperrootvp;
208 1.1 jdolecek um->um_lowervp = lowerrootvp;
209 1.1 jdolecek break;
210 1.1 jdolecek
211 1.1 jdolecek default:
212 1.1 jdolecek error = EINVAL;
213 1.1 jdolecek goto bad;
214 1.1 jdolecek }
215 1.1 jdolecek
216 1.1 jdolecek /*
217 1.1 jdolecek * Unless the mount is readonly, ensure that the top layer
218 1.1 jdolecek * supports whiteout operations
219 1.1 jdolecek */
220 1.1 jdolecek if ((mp->mnt_flag & MNT_RDONLY) == 0) {
221 1.1 jdolecek error = VOP_WHITEOUT(um->um_uppervp, (struct componentname *) 0, LOOKUP);
222 1.1 jdolecek if (error)
223 1.1 jdolecek goto bad;
224 1.1 jdolecek }
225 1.1 jdolecek
226 1.36 ad um->um_cred = l->l_cred;
227 1.35 elad kauth_cred_hold(um->um_cred);
228 1.31 christos um->um_cmode = UN_DIRMODE &~ l->l_proc->p_cwdi->cwdi_cmask;
229 1.1 jdolecek
230 1.1 jdolecek /*
231 1.1 jdolecek * Depending on what you think the MNT_LOCAL flag might mean,
232 1.1 jdolecek * you may want the && to be || on the conditional below.
233 1.1 jdolecek * At the moment it has been defined that the filesystem is
234 1.1 jdolecek * only local if it is all local, ie the MNT_LOCAL flag implies
235 1.1 jdolecek * that the entire namespace is local. If you think the MNT_LOCAL
236 1.1 jdolecek * flag implies that some of the files might be stored locally
237 1.1 jdolecek * then you will want to change the conditional.
238 1.1 jdolecek */
239 1.1 jdolecek if (um->um_op == UNMNT_ABOVE) {
240 1.1 jdolecek if (((um->um_lowervp == NULLVP) ||
241 1.1 jdolecek (um->um_lowervp->v_mount->mnt_flag & MNT_LOCAL)) &&
242 1.1 jdolecek (um->um_uppervp->v_mount->mnt_flag & MNT_LOCAL))
243 1.1 jdolecek mp->mnt_flag |= MNT_LOCAL;
244 1.1 jdolecek }
245 1.1 jdolecek
246 1.1 jdolecek /*
247 1.1 jdolecek * Copy in the upper layer's RDONLY flag. This is for the benefit
248 1.1 jdolecek * of lookup() which explicitly checks the flag, rather than asking
249 1.1 jdolecek * the filesystem for it's own opinion. This means, that an update
250 1.1 jdolecek * mount of the underlying filesystem to go from rdonly to rdwr
251 1.1 jdolecek * will leave the unioned view as read-only.
252 1.1 jdolecek */
253 1.1 jdolecek mp->mnt_flag |= (um->um_uppervp->v_mount->mnt_flag & MNT_RDONLY);
254 1.1 jdolecek
255 1.1 jdolecek mp->mnt_data = um;
256 1.23 hannken mp->mnt_leaf = um->um_uppervp->v_mount->mnt_leaf;
257 1.1 jdolecek vfs_getnewfsid(mp);
258 1.1 jdolecek
259 1.12 christos error = set_statvfs_info( path, UIO_USERSPACE, NULL, UIO_USERSPACE,
260 1.31 christos mp, l);
261 1.4 christos if (error)
262 1.4 christos goto bad;
263 1.1 jdolecek
264 1.1 jdolecek switch (um->um_op) {
265 1.1 jdolecek case UNMNT_ABOVE:
266 1.1 jdolecek cp = "<above>:";
267 1.1 jdolecek break;
268 1.1 jdolecek case UNMNT_BELOW:
269 1.1 jdolecek cp = "<below>:";
270 1.1 jdolecek break;
271 1.1 jdolecek case UNMNT_REPLACE:
272 1.1 jdolecek cp = "";
273 1.1 jdolecek break;
274 1.1 jdolecek default:
275 1.1 jdolecek cp = "<invalid>:";
276 1.1 jdolecek #ifdef DIAGNOSTIC
277 1.1 jdolecek panic("union_mount: bad um_op");
278 1.1 jdolecek #endif
279 1.1 jdolecek break;
280 1.1 jdolecek }
281 1.1 jdolecek len = strlen(cp);
282 1.1 jdolecek memcpy(mp->mnt_stat.f_mntfromname, cp, len);
283 1.1 jdolecek
284 1.27 christos xp = mp->mnt_stat.f_mntfromname + len;
285 1.1 jdolecek len = MNAMELEN - len;
286 1.1 jdolecek
287 1.27 christos (void) copyinstr(args.target, xp, len - 1, &size);
288 1.27 christos memset(xp + size, 0, len - size);
289 1.1 jdolecek
290 1.1 jdolecek #ifdef UNION_DIAGNOSTIC
291 1.1 jdolecek printf("union_mount: from %s, on %s\n",
292 1.1 jdolecek mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname);
293 1.1 jdolecek #endif
294 1.2 jdolecek
295 1.2 jdolecek /* Setup the readdir hook if it's not set already */
296 1.2 jdolecek if (!vn_union_readdir_hook)
297 1.2 jdolecek vn_union_readdir_hook = union_readdirhook;
298 1.2 jdolecek
299 1.1 jdolecek return (0);
300 1.1 jdolecek
301 1.1 jdolecek bad:
302 1.1 jdolecek if (um)
303 1.1 jdolecek free(um, M_UFSMNT);
304 1.1 jdolecek if (upperrootvp)
305 1.1 jdolecek vrele(upperrootvp);
306 1.1 jdolecek if (lowerrootvp)
307 1.1 jdolecek vrele(lowerrootvp);
308 1.1 jdolecek return (error);
309 1.1 jdolecek }
310 1.1 jdolecek
311 1.1 jdolecek /*
312 1.1 jdolecek * VFS start. Nothing needed here - the start routine
313 1.1 jdolecek * on the underlying filesystem(s) will have been called
314 1.1 jdolecek * when that filesystem was mounted.
315 1.1 jdolecek */
316 1.1 jdolecek /*ARGSUSED*/
317 1.1 jdolecek int
318 1.37.2.1 ad union_start(struct mount *mp, int flags,
319 1.37.2.1 ad struct lwp *l)
320 1.1 jdolecek {
321 1.1 jdolecek
322 1.1 jdolecek return (0);
323 1.1 jdolecek }
324 1.1 jdolecek
325 1.1 jdolecek /*
326 1.1 jdolecek * Free reference to union layer
327 1.1 jdolecek */
328 1.1 jdolecek int
329 1.37.2.1 ad union_unmount(struct mount *mp, int mntflags, struct lwp *l)
330 1.1 jdolecek {
331 1.1 jdolecek struct union_mount *um = MOUNTTOUNIONMOUNT(mp);
332 1.1 jdolecek int freeing;
333 1.33 christos int error;
334 1.1 jdolecek
335 1.1 jdolecek #ifdef UNION_DIAGNOSTIC
336 1.1 jdolecek printf("union_unmount(mp = %p)\n", mp);
337 1.1 jdolecek #endif
338 1.1 jdolecek
339 1.1 jdolecek /*
340 1.1 jdolecek * Keep flushing vnodes from the mount list.
341 1.1 jdolecek * This is needed because of the un_pvp held
342 1.1 jdolecek * reference to the parent vnode.
343 1.1 jdolecek * If more vnodes have been freed on a given pass,
344 1.1 jdolecek * the try again. The loop will iterate at most
345 1.1 jdolecek * (d) times, where (d) is the maximum tree depth
346 1.1 jdolecek * in the filesystem.
347 1.1 jdolecek */
348 1.33 christos for (freeing = 0; (error = vflush(mp, NULL, 0)) != 0;) {
349 1.1 jdolecek struct vnode *vp;
350 1.1 jdolecek int n;
351 1.1 jdolecek
352 1.1 jdolecek /* count #vnodes held on mount list */
353 1.37.2.1 ad n = 0;
354 1.37.2.1 ad TAILQ_FOREACH(vp, &mp->mnt_vnodelist, v_mntvnodes)
355 1.1 jdolecek n++;
356 1.1 jdolecek
357 1.1 jdolecek /* if this is unchanged then stop */
358 1.1 jdolecek if (n == freeing)
359 1.1 jdolecek break;
360 1.1 jdolecek
361 1.1 jdolecek /* otherwise try once more time */
362 1.1 jdolecek freeing = n;
363 1.1 jdolecek }
364 1.1 jdolecek
365 1.1 jdolecek /*
366 1.1 jdolecek * Ok, now that we've tried doing it gently, get out the hammer.
367 1.1 jdolecek */
368 1.1 jdolecek
369 1.1 jdolecek if (mntflags & MNT_FORCE)
370 1.33 christos error = vflush(mp, NULL, FORCECLOSE);
371 1.25 perry
372 1.33 christos if (error)
373 1.33 christos return error;
374 1.1 jdolecek
375 1.1 jdolecek /*
376 1.1 jdolecek * Discard references to upper and lower target vnodes.
377 1.1 jdolecek */
378 1.1 jdolecek if (um->um_lowervp)
379 1.1 jdolecek vrele(um->um_lowervp);
380 1.1 jdolecek vrele(um->um_uppervp);
381 1.35 elad kauth_cred_free(um->um_cred);
382 1.1 jdolecek /*
383 1.1 jdolecek * Finally, throw away the union_mount structure
384 1.1 jdolecek */
385 1.1 jdolecek free(mp->mnt_data, M_UFSMNT); /* XXX */
386 1.1 jdolecek mp->mnt_data = 0;
387 1.1 jdolecek return (0);
388 1.1 jdolecek }
389 1.1 jdolecek
390 1.1 jdolecek int
391 1.7 thorpej union_root(mp, vpp)
392 1.1 jdolecek struct mount *mp;
393 1.1 jdolecek struct vnode **vpp;
394 1.1 jdolecek {
395 1.1 jdolecek struct union_mount *um = MOUNTTOUNIONMOUNT(mp);
396 1.1 jdolecek int error;
397 1.1 jdolecek
398 1.1 jdolecek /*
399 1.1 jdolecek * Return locked reference to root.
400 1.1 jdolecek */
401 1.1 jdolecek VREF(um->um_uppervp);
402 1.37.2.4 ad vn_lock(um->um_uppervp, LK_EXCLUSIVE | LK_RETRY);
403 1.1 jdolecek if (um->um_lowervp)
404 1.1 jdolecek VREF(um->um_lowervp);
405 1.37.2.4 ad error = union_allocvp(vpp, mp, NULL, NULL, NULL,
406 1.37.2.4 ad um->um_uppervp, um->um_lowervp, 1);
407 1.1 jdolecek
408 1.1 jdolecek if (error) {
409 1.37.2.4 ad vput(um->um_uppervp);
410 1.1 jdolecek if (um->um_lowervp)
411 1.1 jdolecek vrele(um->um_lowervp);
412 1.1 jdolecek }
413 1.1 jdolecek
414 1.1 jdolecek return (error);
415 1.1 jdolecek }
416 1.1 jdolecek
417 1.1 jdolecek /*ARGSUSED*/
418 1.1 jdolecek int
419 1.37.2.1 ad union_quotactl(struct mount *mp, int cmd, uid_t uid,
420 1.37.2.1 ad void *arg, struct lwp *l)
421 1.1 jdolecek {
422 1.1 jdolecek
423 1.1 jdolecek return (EOPNOTSUPP);
424 1.1 jdolecek }
425 1.1 jdolecek
426 1.1 jdolecek int
427 1.31 christos union_statvfs(mp, sbp, l)
428 1.1 jdolecek struct mount *mp;
429 1.12 christos struct statvfs *sbp;
430 1.31 christos struct lwp *l;
431 1.1 jdolecek {
432 1.1 jdolecek int error;
433 1.1 jdolecek struct union_mount *um = MOUNTTOUNIONMOUNT(mp);
434 1.28 nakayama struct statvfs *sbuf = malloc(sizeof(*sbuf), M_TEMP, M_WAITOK | M_ZERO);
435 1.17 christos unsigned long lbsize;
436 1.1 jdolecek
437 1.1 jdolecek #ifdef UNION_DIAGNOSTIC
438 1.12 christos printf("union_statvfs(mp = %p, lvp = %p, uvp = %p)\n", mp,
439 1.1 jdolecek um->um_lowervp, um->um_uppervp);
440 1.1 jdolecek #endif
441 1.1 jdolecek
442 1.1 jdolecek if (um->um_lowervp) {
443 1.31 christos error = VFS_STATVFS(um->um_lowervp->v_mount, sbuf, l);
444 1.1 jdolecek if (error)
445 1.17 christos goto done;
446 1.1 jdolecek }
447 1.1 jdolecek
448 1.17 christos /* now copy across the "interesting" information and fake the rest */
449 1.17 christos lbsize = sbuf->f_bsize;
450 1.17 christos sbp->f_blocks = sbuf->f_blocks - sbuf->f_bfree;
451 1.17 christos sbp->f_files = sbuf->f_files - sbuf->f_ffree;
452 1.17 christos
453 1.31 christos error = VFS_STATVFS(um->um_uppervp->v_mount, sbuf, l);
454 1.1 jdolecek if (error)
455 1.17 christos goto done;
456 1.17 christos
457 1.17 christos sbp->f_flag = sbuf->f_flag;
458 1.17 christos sbp->f_bsize = sbuf->f_bsize;
459 1.17 christos sbp->f_frsize = sbuf->f_frsize;
460 1.17 christos sbp->f_iosize = sbuf->f_iosize;
461 1.17 christos
462 1.1 jdolecek /*
463 1.1 jdolecek * The "total" fields count total resources in all layers,
464 1.1 jdolecek * the "free" fields count only those resources which are
465 1.1 jdolecek * free in the upper layer (since only the upper layer
466 1.1 jdolecek * is writable).
467 1.1 jdolecek */
468 1.17 christos
469 1.17 christos if (sbuf->f_bsize != lbsize)
470 1.17 christos sbp->f_blocks = sbp->f_blocks * lbsize / sbuf->f_bsize;
471 1.17 christos sbp->f_blocks += sbuf->f_blocks;
472 1.17 christos sbp->f_bfree = sbuf->f_bfree;
473 1.17 christos sbp->f_bavail = sbuf->f_bavail;
474 1.17 christos sbp->f_bresvd = sbuf->f_bresvd;
475 1.17 christos sbp->f_files += sbuf->f_files;
476 1.17 christos sbp->f_ffree = sbuf->f_ffree;
477 1.17 christos sbp->f_favail = sbuf->f_favail;
478 1.17 christos sbp->f_fresvd = sbuf->f_fresvd;
479 1.1 jdolecek
480 1.12 christos copy_statvfs_info(sbp, mp);
481 1.17 christos done:
482 1.17 christos free(sbuf, M_TEMP);
483 1.17 christos return error;
484 1.1 jdolecek }
485 1.1 jdolecek
486 1.1 jdolecek /*ARGSUSED*/
487 1.1 jdolecek int
488 1.37.2.1 ad union_sync(struct mount *mp, int waitfor,
489 1.37.2.1 ad kauth_cred_t cred, struct lwp *l)
490 1.1 jdolecek {
491 1.1 jdolecek
492 1.1 jdolecek /*
493 1.1 jdolecek * XXX - Assumes no data cached at union layer.
494 1.1 jdolecek */
495 1.1 jdolecek return (0);
496 1.1 jdolecek }
497 1.1 jdolecek
498 1.1 jdolecek /*ARGSUSED*/
499 1.1 jdolecek int
500 1.37.2.1 ad union_vget(struct mount *mp, ino_t ino,
501 1.37.2.1 ad struct vnode **vpp)
502 1.1 jdolecek {
503 1.25 perry
504 1.1 jdolecek return (EOPNOTSUPP);
505 1.1 jdolecek }
506 1.1 jdolecek
507 1.10 atatat SYSCTL_SETUP(sysctl_vfs_union_setup, "sysctl vfs.union subtree setup")
508 1.1 jdolecek {
509 1.10 atatat
510 1.11 atatat sysctl_createv(clog, 0, NULL, NULL,
511 1.11 atatat CTLFLAG_PERMANENT,
512 1.10 atatat CTLTYPE_NODE, "vfs", NULL,
513 1.10 atatat NULL, 0, NULL, 0,
514 1.10 atatat CTL_VFS, CTL_EOL);
515 1.11 atatat sysctl_createv(clog, 0, NULL, NULL,
516 1.11 atatat CTLFLAG_PERMANENT,
517 1.18 atatat CTLTYPE_NODE, "union",
518 1.18 atatat SYSCTL_DESCR("Union file system"),
519 1.10 atatat NULL, 0, NULL, 0,
520 1.10 atatat CTL_VFS, 15, CTL_EOL);
521 1.10 atatat /*
522 1.10 atatat * XXX the "15" above could be dynamic, thereby eliminating
523 1.10 atatat * one more instance of the "number to vfs" mapping problem,
524 1.10 atatat * but "15" is the order as taken from sys/mount.h
525 1.10 atatat */
526 1.1 jdolecek }
527 1.1 jdolecek
528 1.1 jdolecek extern const struct vnodeopv_desc union_vnodeop_opv_desc;
529 1.1 jdolecek
530 1.1 jdolecek const struct vnodeopv_desc * const union_vnodeopv_descs[] = {
531 1.1 jdolecek &union_vnodeop_opv_desc,
532 1.1 jdolecek NULL,
533 1.1 jdolecek };
534 1.1 jdolecek
535 1.1 jdolecek struct vfsops union_vfsops = {
536 1.1 jdolecek MOUNT_UNION,
537 1.1 jdolecek union_mount,
538 1.1 jdolecek union_start,
539 1.1 jdolecek union_unmount,
540 1.1 jdolecek union_root,
541 1.1 jdolecek union_quotactl,
542 1.12 christos union_statvfs,
543 1.1 jdolecek union_sync,
544 1.1 jdolecek union_vget,
545 1.37.2.2 ad (void *)eopnotsupp, /* vfs_fhtovp */
546 1.37.2.2 ad (void *)eopnotsupp, /* vfs_vptofh */
547 1.1 jdolecek union_init,
548 1.3 jdolecek NULL, /* vfs_reinit */
549 1.1 jdolecek union_done,
550 1.1 jdolecek NULL, /* vfs_mountroot */
551 1.22 wrstuden (int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
552 1.24 thorpej vfs_stdextattrctl,
553 1.37.2.3 ad vfs_stdsuspendctl,
554 1.1 jdolecek union_vnodeopv_descs,
555 1.37 christos 0, /* vfs_refcount */
556 1.37 christos { NULL, NULL },
557 1.1 jdolecek };
558 1.26 thorpej VFS_ATTACH(union_vfsops);
559