Mon Mar 6 10:10:07 2017 UTC ()
Add field "mnt_lower" to "struct mount" to track the file system
a layered file system is mounted on.

Welcome to 7.99.65


(hannken)
diff -r1.76 -r1.77 src/sys/fs/union/union_vfsops.c
diff -r1.91 -r1.92 src/sys/miscfs/nullfs/null_vfsops.c
diff -r1.64 -r1.65 src/sys/miscfs/overlay/overlay_vfsops.c
diff -r1.96 -r1.97 src/sys/miscfs/umapfs/umap_vfsops.c
diff -r1.220 -r1.221 src/sys/sys/mount.h
diff -r1.531 -r1.532 src/sys/sys/param.h

cvs diff -r1.76 -r1.77 src/sys/fs/union/union_vfsops.c (switch to unified diff)

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

cvs diff -r1.91 -r1.92 src/sys/miscfs/nullfs/null_vfsops.c (switch to unified diff)

--- src/sys/miscfs/nullfs/null_vfsops.c 2017/02/17 08:31:25 1.91
+++ src/sys/miscfs/nullfs/null_vfsops.c 2017/03/06 10:10:07 1.92
@@ -1,271 +1,272 @@ @@ -1,271 +1,272 @@
1/* $NetBSD: null_vfsops.c,v 1.91 2017/02/17 08:31:25 hannken Exp $ */ 1/* $NetBSD: null_vfsops.c,v 1.92 2017/03/06 10:10:07 hannken Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1999 National Aeronautics & Space Administration 4 * Copyright (c) 1999 National Aeronautics & Space Administration
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This software was written by William Studenmund of the 7 * This software was written by William Studenmund of the
8 * Numerical Aerospace Simulation Facility, NASA Ames Research Center. 8 * Numerical Aerospace Simulation Facility, NASA Ames Research Center.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the National Aeronautics & Space Administration 18 * 3. Neither the name of the National Aeronautics & Space Administration
19 * nor the names of its contributors may be used to endorse or promote 19 * nor the names of its contributors may be used to endorse or promote
20 * products derived from this software without specific prior written 20 * products derived from this software without specific prior written
21 * permission. 21 * permission.
22 * 22 *
23 * THIS SOFTWARE IS PROVIDED BY THE NATIONAL AERONAUTICS & SPACE ADMINISTRATION 23 * THIS SOFTWARE IS PROVIDED BY THE NATIONAL AERONAUTICS & SPACE ADMINISTRATION
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ADMINISTRATION OR CONTRIB- 26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ADMINISTRATION OR CONTRIB-
27 * UTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 27 * UTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE. 33 * POSSIBILITY OF SUCH DAMAGE.
34 */ 34 */
35 35
36/* 36/*
37 * Copyright (c) 1992, 1993, 1995 37 * Copyright (c) 1992, 1993, 1995
38 * The Regents of the University of California. All rights reserved. 38 * The Regents of the University of California. All rights reserved.
39 * 39 *
40 * This code is derived from software donated to Berkeley by 40 * This code is derived from software donated to Berkeley by
41 * Jan-Simon Pendry. 41 * Jan-Simon Pendry.
42 * 42 *
43 * Redistribution and use in source and binary forms, with or without 43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions 44 * modification, are permitted provided that the following conditions
45 * are met: 45 * are met:
46 * 1. Redistributions of source code must retain the above copyright 46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer. 47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright 48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the 49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution. 50 * documentation and/or other materials provided with the distribution.
51 * 3. Neither the name of the University nor the names of its contributors 51 * 3. Neither the name of the University nor the names of its contributors
52 * may be used to endorse or promote products derived from this software 52 * may be used to endorse or promote products derived from this software
53 * without specific prior written permission. 53 * without specific prior written permission.
54 * 54 *
55 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 55 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 56 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 58 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 59 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 60 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 61 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 63 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 64 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
65 * SUCH DAMAGE. 65 * SUCH DAMAGE.
66 * 66 *
67 * from: Id: lofs_vfsops.c,v 1.9 1992/05/30 10:26:24 jsp Exp 67 * from: Id: lofs_vfsops.c,v 1.9 1992/05/30 10:26:24 jsp Exp
68 * from: @(#)lofs_vfsops.c 1.2 (Berkeley) 6/18/92 68 * from: @(#)lofs_vfsops.c 1.2 (Berkeley) 6/18/92
69 * @(#)null_vfsops.c 8.7 (Berkeley) 5/14/95 69 * @(#)null_vfsops.c 8.7 (Berkeley) 5/14/95
70 */ 70 */
71 71
72/* 72/*
73 * Null file-system: VFS operations. 73 * Null file-system: VFS operations.
74 * 74 *
75 * See null_vnops.c for a description. 75 * See null_vnops.c for a description.
76 */ 76 */
77 77
78#include <sys/cdefs.h> 78#include <sys/cdefs.h>
79__KERNEL_RCSID(0, "$NetBSD: null_vfsops.c,v 1.91 2017/02/17 08:31:25 hannken Exp $"); 79__KERNEL_RCSID(0, "$NetBSD: null_vfsops.c,v 1.92 2017/03/06 10:10:07 hannken Exp $");
80 80
81#include <sys/param.h> 81#include <sys/param.h>
82#include <sys/systm.h> 82#include <sys/systm.h>
83#include <sys/sysctl.h> 83#include <sys/sysctl.h>
84#include <sys/vnode.h> 84#include <sys/vnode.h>
85#include <sys/mount.h> 85#include <sys/mount.h>
86#include <sys/namei.h> 86#include <sys/namei.h>
87#include <sys/module.h> 87#include <sys/module.h>
88 88
89#include <miscfs/nullfs/null.h> 89#include <miscfs/nullfs/null.h>
90#include <miscfs/genfs/layer_extern.h> 90#include <miscfs/genfs/layer_extern.h>
91 91
92MODULE(MODULE_CLASS_VFS, null, "layerfs"); 92MODULE(MODULE_CLASS_VFS, null, "layerfs");
93 93
94VFS_PROTOS(nullfs); 94VFS_PROTOS(nullfs);
95 95
96static struct sysctllog *nullfs_sysctl_log; 96static struct sysctllog *nullfs_sysctl_log;
97 97
98int 98int
99nullfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len) 99nullfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
100{ 100{
101 struct vnode *lowerrootvp, *vp; 101 struct vnode *lowerrootvp, *vp;
102 struct null_args *args = data; 102 struct null_args *args = data;
103 struct null_mount *nmp; 103 struct null_mount *nmp;
104 struct layer_mount *lmp; 104 struct layer_mount *lmp;
105 struct pathbuf *pb; 105 struct pathbuf *pb;
106 struct nameidata nd; 106 struct nameidata nd;
107 int error; 107 int error;
108 108
109 if (args == NULL) 109 if (args == NULL)
110 return EINVAL; 110 return EINVAL;
111 if (*data_len < sizeof(*args)) 111 if (*data_len < sizeof(*args))
112 return EINVAL; 112 return EINVAL;
113 113
114 if (mp->mnt_flag & MNT_GETARGS) { 114 if (mp->mnt_flag & MNT_GETARGS) {
115 lmp = MOUNTTOLAYERMOUNT(mp); 115 lmp = MOUNTTOLAYERMOUNT(mp);
116 if (lmp == NULL) 116 if (lmp == NULL)
117 return EIO; 117 return EIO;
118 args->la.target = NULL; 118 args->la.target = NULL;
119 *data_len = sizeof(*args); 119 *data_len = sizeof(*args);
120 return 0; 120 return 0;
121 } 121 }
122 122
123 /* Update is not supported. */ 123 /* Update is not supported. */
124 if (mp->mnt_flag & MNT_UPDATE) 124 if (mp->mnt_flag & MNT_UPDATE)
125 return EOPNOTSUPP; 125 return EOPNOTSUPP;
126 126
127 /* Find the lower vnode and lock it. */ 127 /* Find the lower vnode and lock it. */
128 error = pathbuf_copyin(args->la.target, &pb); 128 error = pathbuf_copyin(args->la.target, &pb);
129 if (error) { 129 if (error) {
130 return error; 130 return error;
131 } 131 }
132 NDINIT(&nd, LOOKUP, FOLLOW|LOCKLEAF, pb); 132 NDINIT(&nd, LOOKUP, FOLLOW|LOCKLEAF, pb);
133 if ((error = namei(&nd)) != 0) { 133 if ((error = namei(&nd)) != 0) {
134 pathbuf_destroy(pb); 134 pathbuf_destroy(pb);
135 return error; 135 return error;
136 } 136 }
137 lowerrootvp = nd.ni_vp; 137 lowerrootvp = nd.ni_vp;
138 pathbuf_destroy(pb); 138 pathbuf_destroy(pb);
139 139
140 /* Create the mount point. */ 140 /* Create the mount point. */
141 nmp = kmem_zalloc(sizeof(struct null_mount), KM_SLEEP); 141 nmp = kmem_zalloc(sizeof(struct null_mount), KM_SLEEP);
142 mp->mnt_data = nmp; 142 mp->mnt_data = nmp;
143 nmp->nullm_vfs = lowerrootvp->v_mount; 143 nmp->nullm_vfs = lowerrootvp->v_mount;
144 if (nmp->nullm_vfs->mnt_flag & MNT_LOCAL) 144 if (nmp->nullm_vfs->mnt_flag & MNT_LOCAL)
145 mp->mnt_flag |= MNT_LOCAL; 145 mp->mnt_flag |= MNT_LOCAL;
146 146
147 /* 147 /*
148 * Make sure that the mount point is sufficiently initialized 148 * Make sure that the mount point is sufficiently initialized
149 * that the node create call will work. 149 * that the node create call will work.
150 */ 150 */
151 vfs_getnewfsid(mp); 151 vfs_getnewfsid(mp);
152 152
153 nmp->nullm_size = sizeof(struct null_node); 153 nmp->nullm_size = sizeof(struct null_node);
154 nmp->nullm_tag = VT_NULL; 154 nmp->nullm_tag = VT_NULL;
155 nmp->nullm_bypass = layer_bypass; 155 nmp->nullm_bypass = layer_bypass;
156 nmp->nullm_vnodeop_p = null_vnodeop_p; 156 nmp->nullm_vnodeop_p = null_vnodeop_p;
157 157
158 /* Setup a null node for root vnode. */ 158 /* Setup a null node for root vnode. */
159 VOP_UNLOCK(lowerrootvp); 159 VOP_UNLOCK(lowerrootvp);
160 error = layer_node_create(mp, lowerrootvp, &vp); 160 error = layer_node_create(mp, lowerrootvp, &vp);
161 if (error) { 161 if (error) {
162 vrele(lowerrootvp); 162 vrele(lowerrootvp);
163 kmem_free(nmp, sizeof(struct null_mount)); 163 kmem_free(nmp, sizeof(struct null_mount));
164 return error; 164 return error;
165 } 165 }
166 /* 166 /*
167 * Keep a held reference to the root vnode. It will be released on 167 * Keep a held reference to the root vnode. It will be released on
168 * umount. Note: nullfs is MP-safe. 168 * umount. Note: nullfs is MP-safe.
169 */ 169 */
170 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); 170 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
171 vp->v_vflag |= VV_ROOT; 171 vp->v_vflag |= VV_ROOT;
172 nmp->nullm_rootvp = vp; 172 nmp->nullm_rootvp = vp;
 173 mp->mnt_lower = nmp->nullm_vfs;
173 mp->mnt_iflag |= IMNT_MPSAFE; 174 mp->mnt_iflag |= IMNT_MPSAFE;
174 VOP_UNLOCK(vp); 175 VOP_UNLOCK(vp);
175 176
176 error = set_statvfs_info(path, UIO_USERSPACE, args->la.target, 177 error = set_statvfs_info(path, UIO_USERSPACE, args->la.target,
177 UIO_USERSPACE, mp->mnt_op->vfs_name, mp, curlwp); 178 UIO_USERSPACE, mp->mnt_op->vfs_name, mp, curlwp);
178 return error; 179 return error;
179} 180}
180 181
181int 182int
182nullfs_unmount(struct mount *mp, int mntflags) 183nullfs_unmount(struct mount *mp, int mntflags)
183{ 184{
184 struct null_mount *nmp = MOUNTTONULLMOUNT(mp); 185 struct null_mount *nmp = MOUNTTONULLMOUNT(mp);
185 struct vnode *null_rootvp = nmp->nullm_rootvp; 186 struct vnode *null_rootvp = nmp->nullm_rootvp;
186 int error, flags = 0; 187 int error, flags = 0;
187 188
188 if (mntflags & MNT_FORCE) 189 if (mntflags & MNT_FORCE)
189 flags |= FORCECLOSE; 190 flags |= FORCECLOSE;
190 191
191 if (null_rootvp->v_usecount > 1 && (mntflags & MNT_FORCE) == 0) 192 if (null_rootvp->v_usecount > 1 && (mntflags & MNT_FORCE) == 0)
192 return EBUSY; 193 return EBUSY;
193 194
194 if ((error = vflush(mp, null_rootvp, flags)) != 0) 195 if ((error = vflush(mp, null_rootvp, flags)) != 0)
195 return error; 196 return error;
196 197
197 /* Eliminate all activity and release the vnode. */ 198 /* Eliminate all activity and release the vnode. */
198 vgone(null_rootvp); 199 vgone(null_rootvp);
199 200
200 /* Finally, destroy the mount point structures. */ 201 /* Finally, destroy the mount point structures. */
201 kmem_free(mp->mnt_data, sizeof(struct null_mount)); 202 kmem_free(mp->mnt_data, sizeof(struct null_mount));
202 mp->mnt_data = NULL; 203 mp->mnt_data = NULL;
203 return 0; 204 return 0;
204} 205}
205 206
206extern const struct vnodeopv_desc null_vnodeop_opv_desc; 207extern const struct vnodeopv_desc null_vnodeop_opv_desc;
207 208
208const struct vnodeopv_desc * const nullfs_vnodeopv_descs[] = { 209const struct vnodeopv_desc * const nullfs_vnodeopv_descs[] = {
209 &null_vnodeop_opv_desc, 210 &null_vnodeop_opv_desc,
210 NULL, 211 NULL,
211}; 212};
212 213
213struct vfsops nullfs_vfsops = { 214struct vfsops nullfs_vfsops = {
214 .vfs_name = MOUNT_NULL, 215 .vfs_name = MOUNT_NULL,
215 .vfs_min_mount_data = sizeof (struct null_args), 216 .vfs_min_mount_data = sizeof (struct null_args),
216 .vfs_mount = nullfs_mount, 217 .vfs_mount = nullfs_mount,
217 .vfs_start = layerfs_start, 218 .vfs_start = layerfs_start,
218 .vfs_unmount = nullfs_unmount, 219 .vfs_unmount = nullfs_unmount,
219 .vfs_root = layerfs_root, 220 .vfs_root = layerfs_root,
220 .vfs_quotactl = layerfs_quotactl, 221 .vfs_quotactl = layerfs_quotactl,
221 .vfs_statvfs = layerfs_statvfs, 222 .vfs_statvfs = layerfs_statvfs,
222 .vfs_sync = layerfs_sync, 223 .vfs_sync = layerfs_sync,
223 .vfs_loadvnode = layerfs_loadvnode, 224 .vfs_loadvnode = layerfs_loadvnode,
224 .vfs_vget = layerfs_vget, 225 .vfs_vget = layerfs_vget,
225 .vfs_fhtovp = layerfs_fhtovp, 226 .vfs_fhtovp = layerfs_fhtovp,
226 .vfs_vptofh = layerfs_vptofh, 227 .vfs_vptofh = layerfs_vptofh,
227 .vfs_init = layerfs_init, 228 .vfs_init = layerfs_init,
228 .vfs_done = layerfs_done, 229 .vfs_done = layerfs_done,
229 .vfs_snapshot = layerfs_snapshot, 230 .vfs_snapshot = layerfs_snapshot,
230 .vfs_extattrctl = vfs_stdextattrctl, 231 .vfs_extattrctl = vfs_stdextattrctl,
231 .vfs_suspendctl = layerfs_suspendctl, 232 .vfs_suspendctl = layerfs_suspendctl,
232 .vfs_renamelock_enter = layerfs_renamelock_enter, 233 .vfs_renamelock_enter = layerfs_renamelock_enter,
233 .vfs_renamelock_exit = layerfs_renamelock_exit, 234 .vfs_renamelock_exit = layerfs_renamelock_exit,
234 .vfs_fsync = (void *)eopnotsupp, 235 .vfs_fsync = (void *)eopnotsupp,
235 .vfs_opv_descs = nullfs_vnodeopv_descs 236 .vfs_opv_descs = nullfs_vnodeopv_descs
236}; 237};
237 238
238static int 239static int
239null_modcmd(modcmd_t cmd, void *arg) 240null_modcmd(modcmd_t cmd, void *arg)
240{ 241{
241 int error; 242 int error;
242 243
243 switch (cmd) { 244 switch (cmd) {
244 case MODULE_CMD_INIT: 245 case MODULE_CMD_INIT:
245 error = vfs_attach(&nullfs_vfsops); 246 error = vfs_attach(&nullfs_vfsops);
246 if (error != 0) 247 if (error != 0)
247 break; 248 break;
248 sysctl_createv(&nullfs_sysctl_log, 0, NULL, NULL, 249 sysctl_createv(&nullfs_sysctl_log, 0, NULL, NULL,
249 CTLFLAG_PERMANENT, 250 CTLFLAG_PERMANENT,
250 CTLTYPE_NODE, "null", 251 CTLTYPE_NODE, "null",
251 SYSCTL_DESCR("Loopback file system"), 252 SYSCTL_DESCR("Loopback file system"),
252 NULL, 0, NULL, 0, 253 NULL, 0, NULL, 0,
253 CTL_VFS, 9, CTL_EOL); 254 CTL_VFS, 9, CTL_EOL);
254 /* 255 /*
255 * XXX the "9" above could be dynamic, thereby eliminating 256 * XXX the "9" above could be dynamic, thereby eliminating
256 * one more instance of the "number to vfs" mapping problem, 257 * one more instance of the "number to vfs" mapping problem,
257 * but "9" is the order as taken from sys/mount.h 258 * but "9" is the order as taken from sys/mount.h
258 */ 259 */
259 break; 260 break;
260 case MODULE_CMD_FINI: 261 case MODULE_CMD_FINI:
261 error = vfs_detach(&nullfs_vfsops); 262 error = vfs_detach(&nullfs_vfsops);
262 if (error != 0) 263 if (error != 0)
263 break; 264 break;
264 sysctl_teardown(&nullfs_sysctl_log); 265 sysctl_teardown(&nullfs_sysctl_log);
265 break; 266 break;
266 default: 267 default:
267 error = ENOTTY; 268 error = ENOTTY;
268 break; 269 break;
269 } 270 }
270 return error; 271 return error;
271} 272}

cvs diff -r1.64 -r1.65 src/sys/miscfs/overlay/overlay_vfsops.c (switch to unified diff)

--- src/sys/miscfs/overlay/overlay_vfsops.c 2017/02/17 08:31:25 1.64
+++ src/sys/miscfs/overlay/overlay_vfsops.c 2017/03/06 10:10:07 1.65
@@ -1,298 +1,299 @@ @@ -1,298 +1,299 @@
1/* $NetBSD: overlay_vfsops.c,v 1.64 2017/02/17 08:31:25 hannken Exp $ */ 1/* $NetBSD: overlay_vfsops.c,v 1.65 2017/03/06 10:10:07 hannken Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1999, 2000 National Aeronautics & Space Administration 4 * Copyright (c) 1999, 2000 National Aeronautics & Space Administration
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This software was written by William Studenmund of the 7 * This software was written by William Studenmund of the
8 * Numerical Aerospace Simulation Facility, NASA Ames Research Center. 8 * Numerical Aerospace Simulation Facility, NASA Ames Research Center.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the National Aeronautics & Space Administration 18 * 3. Neither the name of the National Aeronautics & Space Administration
19 * nor the names of its contributors may be used to endorse or promote 19 * nor the names of its contributors may be used to endorse or promote
20 * products derived from this software without specific prior written 20 * products derived from this software without specific prior written
21 * permission. 21 * permission.
22 * 22 *
23 * THIS SOFTWARE IS PROVIDED BY THE NATIONAL AERONAUTICS & SPACE ADMINISTRATION 23 * THIS SOFTWARE IS PROVIDED BY THE NATIONAL AERONAUTICS & SPACE ADMINISTRATION
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ADMINISTRATION OR CONTRIB- 26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ADMINISTRATION OR CONTRIB-
27 * UTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 27 * UTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE. 33 * POSSIBILITY OF SUCH DAMAGE.
34 */ 34 */
35/* 35/*
36 * Copyright (c) 1992, 1993, 1995 36 * Copyright (c) 1992, 1993, 1995
37 * The Regents of the University of California. All rights reserved. 37 * The Regents of the University of California. All rights reserved.
38 * 38 *
39 * This code is derived from software donated to Berkeley by 39 * This code is derived from software donated to Berkeley by
40 * Jan-Simon Pendry. 40 * Jan-Simon Pendry.
41 * 41 *
42 * Redistribution and use in source and binary forms, with or without 42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions 43 * modification, are permitted provided that the following conditions
44 * are met: 44 * are met:
45 * 1. Redistributions of source code must retain the above copyright 45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer. 46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright 47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the 48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution. 49 * documentation and/or other materials provided with the distribution.
50 * 3. Neither the name of the University nor the names of its contributors 50 * 3. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software 51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission. 52 * without specific prior written permission.
53 * 53 *
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE. 64 * SUCH DAMAGE.
65 * 65 *
66 * from: Id: lofs_vfsops.c,v 1.9 1992/05/30 10:26:24 jsp Exp 66 * from: Id: lofs_vfsops.c,v 1.9 1992/05/30 10:26:24 jsp Exp
67 * from: @(#)lofs_vfsops.c 1.2 (Berkeley) 6/18/92 67 * from: @(#)lofs_vfsops.c 1.2 (Berkeley) 6/18/92
68 * @(#)null_vfsops.c 8.7 (Berkeley) 5/14/95 68 * @(#)null_vfsops.c 8.7 (Berkeley) 5/14/95
69 */ 69 */
70 70
71/* 71/*
72 * Overlay Layer 72 * Overlay Layer
73 * (See overlay_vnops.c for a description of what this does.) 73 * (See overlay_vnops.c for a description of what this does.)
74 */ 74 */
75 75
76#include <sys/cdefs.h> 76#include <sys/cdefs.h>
77__KERNEL_RCSID(0, "$NetBSD: overlay_vfsops.c,v 1.64 2017/02/17 08:31:25 hannken Exp $"); 77__KERNEL_RCSID(0, "$NetBSD: overlay_vfsops.c,v 1.65 2017/03/06 10:10:07 hannken Exp $");
78 78
79#include <sys/param.h> 79#include <sys/param.h>
80#include <sys/systm.h> 80#include <sys/systm.h>
81#include <sys/sysctl.h> 81#include <sys/sysctl.h>
82#include <sys/time.h> 82#include <sys/time.h>
83#include <sys/proc.h> 83#include <sys/proc.h>
84#include <sys/vnode.h> 84#include <sys/vnode.h>
85#include <sys/mount.h> 85#include <sys/mount.h>
86#include <sys/namei.h> 86#include <sys/namei.h>
87#include <sys/module.h> 87#include <sys/module.h>
88#include <miscfs/overlay/overlay.h> 88#include <miscfs/overlay/overlay.h>
89#include <miscfs/genfs/layer_extern.h> 89#include <miscfs/genfs/layer_extern.h>
90 90
91MODULE(MODULE_CLASS_VFS, overlay, "layerfs"); 91MODULE(MODULE_CLASS_VFS, overlay, "layerfs");
92 92
93VFS_PROTOS(ov); 93VFS_PROTOS(ov);
94 94
95static struct sysctllog *overlay_sysctl_log; 95static struct sysctllog *overlay_sysctl_log;
96 96
97#define NOVERLAYNODECACHE 16 97#define NOVERLAYNODECACHE 16
98 98
99/* 99/*
100 * Mount overlay layer 100 * Mount overlay layer
101 */ 101 */
102int 102int
103ov_mount(struct mount *mp, const char *path, void *data, size_t *data_len) 103ov_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
104{ 104{
105 struct lwp *l = curlwp; 105 struct lwp *l = curlwp;
106 int error = 0; 106 int error = 0;
107 struct overlay_args *args = data; 107 struct overlay_args *args = data;
108 struct vnode *lowerrootvp, *vp; 108 struct vnode *lowerrootvp, *vp;
109 struct overlay_mount *nmp; 109 struct overlay_mount *nmp;
110 struct layer_mount *lmp; 110 struct layer_mount *lmp;
111 111
112#ifdef OVERLAYFS_DIAGNOSTIC 112#ifdef OVERLAYFS_DIAGNOSTIC
113 printf("ov_mount(mp = %p)\n", mp); 113 printf("ov_mount(mp = %p)\n", mp);
114#endif 114#endif
115 115
116 if (args == NULL) 116 if (args == NULL)
117 return EINVAL; 117 return EINVAL;
118 if (*data_len < sizeof *args) 118 if (*data_len < sizeof *args)
119 return EINVAL; 119 return EINVAL;
120 120
121 if (mp->mnt_flag & MNT_GETARGS) { 121 if (mp->mnt_flag & MNT_GETARGS) {
122 lmp = MOUNTTOLAYERMOUNT(mp); 122 lmp = MOUNTTOLAYERMOUNT(mp);
123 if (lmp == NULL) 123 if (lmp == NULL)
124 return EIO; 124 return EIO;
125 args->la.target = NULL; 125 args->la.target = NULL;
126 *data_len = sizeof *args; 126 *data_len = sizeof *args;
127 return 0; 127 return 0;
128 } 128 }
129 129
130 /* 130 /*
131 * Update is not supported 131 * Update is not supported
132 */ 132 */
133 if (mp->mnt_flag & MNT_UPDATE) 133 if (mp->mnt_flag & MNT_UPDATE)
134 return EOPNOTSUPP; 134 return EOPNOTSUPP;
135 135
136 /* 136 /*
137 * Find lower node 137 * Find lower node
138 */ 138 */
139 lowerrootvp = mp->mnt_vnodecovered; 139 lowerrootvp = mp->mnt_vnodecovered;
140 vref(lowerrootvp); 140 vref(lowerrootvp);
141 if ((error = vn_lock(lowerrootvp, LK_EXCLUSIVE | LK_RETRY))) { 141 if ((error = vn_lock(lowerrootvp, LK_EXCLUSIVE | LK_RETRY))) {
142 vrele(lowerrootvp); 142 vrele(lowerrootvp);
143 return (error); 143 return (error);
144 } 144 }
145 145
146 /* 146 /*
147 * First cut at fixing up upper mount point 147 * First cut at fixing up upper mount point
148 */ 148 */
149 nmp = kmem_zalloc(sizeof(struct overlay_mount), KM_SLEEP); 149 nmp = kmem_zalloc(sizeof(struct overlay_mount), KM_SLEEP);
150 150
151 mp->mnt_data = nmp; 151 mp->mnt_data = nmp;
152 nmp->ovm_vfs = lowerrootvp->v_mount; 152 nmp->ovm_vfs = lowerrootvp->v_mount;
153 if (nmp->ovm_vfs->mnt_flag & MNT_LOCAL) 153 if (nmp->ovm_vfs->mnt_flag & MNT_LOCAL)
154 mp->mnt_flag |= MNT_LOCAL; 154 mp->mnt_flag |= MNT_LOCAL;
155 155
156 /* 156 /*
157 * Make sure that the mount point is sufficiently initialized 157 * Make sure that the mount point is sufficiently initialized
158 * that the node create call will work. 158 * that the node create call will work.
159 */ 159 */
160 vfs_getnewfsid(mp); 160 vfs_getnewfsid(mp);
161 161
162 nmp->ovm_size = sizeof (struct overlay_node); 162 nmp->ovm_size = sizeof (struct overlay_node);
163 nmp->ovm_tag = VT_OVERLAY; 163 nmp->ovm_tag = VT_OVERLAY;
164 nmp->ovm_bypass = layer_bypass; 164 nmp->ovm_bypass = layer_bypass;
165 nmp->ovm_vnodeop_p = overlay_vnodeop_p; 165 nmp->ovm_vnodeop_p = overlay_vnodeop_p;
166 166
167 /* 167 /*
168 * Fix up overlay node for root vnode 168 * Fix up overlay node for root vnode
169 */ 169 */
170 VOP_UNLOCK(lowerrootvp); 170 VOP_UNLOCK(lowerrootvp);
171 error = layer_node_create(mp, lowerrootvp, &vp); 171 error = layer_node_create(mp, lowerrootvp, &vp);
172 /* 172 /*
173 * Make sure the fixup worked 173 * Make sure the fixup worked
174 */ 174 */
175 if (error) { 175 if (error) {
176 vrele(lowerrootvp); 176 vrele(lowerrootvp);
177 kmem_free(nmp, sizeof(struct overlay_mount)); 177 kmem_free(nmp, sizeof(struct overlay_mount));
178 return error; 178 return error;
179 } 179 }
180 180
181 /* 181 /*
182 * Keep a held reference to the root vnode. 182 * Keep a held reference to the root vnode.
183 * It is vrele'd in ov_unmount. 183 * It is vrele'd in ov_unmount.
184 */ 184 */
185 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); 185 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
186 vp->v_vflag |= VV_ROOT; 186 vp->v_vflag |= VV_ROOT;
187 nmp->ovm_rootvp = vp; 187 nmp->ovm_rootvp = vp;
 188 mp->mnt_lower = nmp->ovm_vfs;
188 VOP_UNLOCK(vp); 189 VOP_UNLOCK(vp);
189 190
190 error = set_statvfs_info(path, UIO_USERSPACE, args->la.target, 191 error = set_statvfs_info(path, UIO_USERSPACE, args->la.target,
191 UIO_USERSPACE, mp->mnt_op->vfs_name, mp, l); 192 UIO_USERSPACE, mp->mnt_op->vfs_name, mp, l);
192#ifdef OVERLAYFS_DIAGNOSTIC 193#ifdef OVERLAYFS_DIAGNOSTIC
193 printf("ov_mount: lower %s, alias at %s\n", 194 printf("ov_mount: lower %s, alias at %s\n",
194 mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname); 195 mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname);
195#endif 196#endif
196 return error; 197 return error;
197} 198}
198 199
199/* 200/*
200 * Free reference to overlay layer 201 * Free reference to overlay layer
201 */ 202 */
202int 203int
203ov_unmount(struct mount *mp, int mntflags) 204ov_unmount(struct mount *mp, int mntflags)
204{ 205{
205 struct vnode *overlay_rootvp = MOUNTTOOVERLAYMOUNT(mp)->ovm_rootvp; 206 struct vnode *overlay_rootvp = MOUNTTOOVERLAYMOUNT(mp)->ovm_rootvp;
206 struct overlay_mount *omp; 207 struct overlay_mount *omp;
207 int error; 208 int error;
208 int flags = 0; 209 int flags = 0;
209 210
210#ifdef OVERLAYFS_DIAGNOSTIC 211#ifdef OVERLAYFS_DIAGNOSTIC
211 printf("ov_unmount(mp = %p)\n", mp); 212 printf("ov_unmount(mp = %p)\n", mp);
212#endif 213#endif
213 214
214 if (mntflags & MNT_FORCE) 215 if (mntflags & MNT_FORCE)
215 flags |= FORCECLOSE; 216 flags |= FORCECLOSE;
216 217
217 if (overlay_rootvp->v_usecount > 1 && (mntflags & MNT_FORCE) == 0) 218 if (overlay_rootvp->v_usecount > 1 && (mntflags & MNT_FORCE) == 0)
218 return (EBUSY); 219 return (EBUSY);
219 if ((error = vflush(mp, overlay_rootvp, flags)) != 0) 220 if ((error = vflush(mp, overlay_rootvp, flags)) != 0)
220 return (error); 221 return (error);
221 222
222#ifdef OVERLAYFS_DIAGNOSTIC 223#ifdef OVERLAYFS_DIAGNOSTIC
223 vprint("alias root of lower", overlay_rootvp); 224 vprint("alias root of lower", overlay_rootvp);
224#endif 225#endif
225 /* 226 /*
226 * Blow it away for future re-use 227 * Blow it away for future re-use
227 */ 228 */
228 vgone(overlay_rootvp); 229 vgone(overlay_rootvp);
229 /* 230 /*
230 * Finally, throw away the overlay_mount structure 231 * Finally, throw away the overlay_mount structure
231 */ 232 */
232 omp = mp->mnt_data; 233 omp = mp->mnt_data;
233 kmem_free(omp, sizeof(struct overlay_mount)); 234 kmem_free(omp, sizeof(struct overlay_mount));
234 mp->mnt_data = NULL; 235 mp->mnt_data = NULL;
235 return 0; 236 return 0;
236} 237}
237 238
238extern const struct vnodeopv_desc overlay_vnodeop_opv_desc; 239extern const struct vnodeopv_desc overlay_vnodeop_opv_desc;
239 240
240const struct vnodeopv_desc * const ov_vnodeopv_descs[] = { 241const struct vnodeopv_desc * const ov_vnodeopv_descs[] = {
241 &overlay_vnodeop_opv_desc, 242 &overlay_vnodeop_opv_desc,
242 NULL, 243 NULL,
243}; 244};
244 245
245struct vfsops overlay_vfsops = { 246struct vfsops overlay_vfsops = {
246 .vfs_name = MOUNT_OVERLAY, 247 .vfs_name = MOUNT_OVERLAY,
247 .vfs_min_mount_data = sizeof (struct overlay_args), 248 .vfs_min_mount_data = sizeof (struct overlay_args),
248 .vfs_mount = ov_mount, 249 .vfs_mount = ov_mount,
249 .vfs_start = layerfs_start, 250 .vfs_start = layerfs_start,
250 .vfs_unmount = ov_unmount, 251 .vfs_unmount = ov_unmount,
251 .vfs_root = layerfs_root, 252 .vfs_root = layerfs_root,
252 .vfs_quotactl = layerfs_quotactl, 253 .vfs_quotactl = layerfs_quotactl,
253 .vfs_statvfs = layerfs_statvfs, 254 .vfs_statvfs = layerfs_statvfs,
254 .vfs_sync = layerfs_sync, 255 .vfs_sync = layerfs_sync,
255 .vfs_loadvnode = layerfs_loadvnode, 256 .vfs_loadvnode = layerfs_loadvnode,
256 .vfs_vget = layerfs_vget, 257 .vfs_vget = layerfs_vget,
257 .vfs_fhtovp = layerfs_fhtovp, 258 .vfs_fhtovp = layerfs_fhtovp,
258 .vfs_vptofh = layerfs_vptofh, 259 .vfs_vptofh = layerfs_vptofh,
259 .vfs_init = layerfs_init, 260 .vfs_init = layerfs_init,
260 .vfs_done = layerfs_done, 261 .vfs_done = layerfs_done,
261 .vfs_snapshot = layerfs_snapshot, 262 .vfs_snapshot = layerfs_snapshot,
262 .vfs_extattrctl = vfs_stdextattrctl, 263 .vfs_extattrctl = vfs_stdextattrctl,
263 .vfs_suspendctl = layerfs_suspendctl, 264 .vfs_suspendctl = layerfs_suspendctl,
264 .vfs_renamelock_enter = layerfs_renamelock_enter, 265 .vfs_renamelock_enter = layerfs_renamelock_enter,
265 .vfs_renamelock_exit = layerfs_renamelock_exit, 266 .vfs_renamelock_exit = layerfs_renamelock_exit,
266 .vfs_fsync = (void *)eopnotsupp, 267 .vfs_fsync = (void *)eopnotsupp,
267 .vfs_opv_descs = ov_vnodeopv_descs 268 .vfs_opv_descs = ov_vnodeopv_descs
268}; 269};
269 270
270static int 271static int
271overlay_modcmd(modcmd_t cmd, void *arg) 272overlay_modcmd(modcmd_t cmd, void *arg)
272{ 273{
273 int error; 274 int error;
274 275
275 switch (cmd) { 276 switch (cmd) {
276 case MODULE_CMD_INIT: 277 case MODULE_CMD_INIT:
277 error = vfs_attach(&overlay_vfsops); 278 error = vfs_attach(&overlay_vfsops);
278 if (error != 0) 279 if (error != 0)
279 break; 280 break;
280 sysctl_createv(&overlay_sysctl_log, 0, NULL, NULL, 281 sysctl_createv(&overlay_sysctl_log, 0, NULL, NULL,
281 CTLFLAG_PERMANENT, CTLTYPE_NODE, "overlay", 282 CTLFLAG_PERMANENT, CTLTYPE_NODE, "overlay",
282 SYSCTL_DESCR("Overlay file system"), 283 SYSCTL_DESCR("Overlay file system"),
283 NULL, 0, NULL, 0, 284 NULL, 0, NULL, 0,
284 CTL_VFS, CTL_CREATE, CTL_EOL); 285 CTL_VFS, CTL_CREATE, CTL_EOL);
285 break; 286 break;
286 case MODULE_CMD_FINI: 287 case MODULE_CMD_FINI:
287 error = vfs_detach(&overlay_vfsops); 288 error = vfs_detach(&overlay_vfsops);
288 if (error != 0) 289 if (error != 0)
289 break; 290 break;
290 sysctl_teardown(&overlay_sysctl_log); 291 sysctl_teardown(&overlay_sysctl_log);
291 break; 292 break;
292 default: 293 default:
293 error = ENOTTY; 294 error = ENOTTY;
294 break; 295 break;
295 } 296 }
296 297
297 return (error); 298 return (error);
298} 299}

cvs diff -r1.96 -r1.97 src/sys/miscfs/umapfs/umap_vfsops.c (switch to unified diff)

--- src/sys/miscfs/umapfs/umap_vfsops.c 2017/02/17 08:31:25 1.96
+++ src/sys/miscfs/umapfs/umap_vfsops.c 2017/03/06 10:10:07 1.97
@@ -1,338 +1,339 @@ @@ -1,338 +1,339 @@
1/* $NetBSD: umap_vfsops.c,v 1.96 2017/02/17 08:31:25 hannken Exp $ */ 1/* $NetBSD: umap_vfsops.c,v 1.97 2017/03/06 10:10:07 hannken Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software donated to Berkeley by 7 * This code is derived from software donated to Berkeley by
8 * the UCLA Ficus project. 8 * the UCLA Ficus project.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors 18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software 19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission. 20 * without specific prior written permission.
21 * 21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 * 33 *
34 * from: @(#)null_vfsops.c 1.5 (Berkeley) 7/10/92 34 * from: @(#)null_vfsops.c 1.5 (Berkeley) 7/10/92
35 * @(#)umap_vfsops.c 8.8 (Berkeley) 5/14/95 35 * @(#)umap_vfsops.c 8.8 (Berkeley) 5/14/95
36 */ 36 */
37 37
38/* 38/*
39 * Umap Layer 39 * Umap Layer
40 * (See mount_umap(8) for a description of this layer.) 40 * (See mount_umap(8) for a description of this layer.)
41 */ 41 */
42 42
43#include <sys/cdefs.h> 43#include <sys/cdefs.h>
44__KERNEL_RCSID(0, "$NetBSD: umap_vfsops.c,v 1.96 2017/02/17 08:31:25 hannken Exp $"); 44__KERNEL_RCSID(0, "$NetBSD: umap_vfsops.c,v 1.97 2017/03/06 10:10:07 hannken Exp $");
45 45
46#include <sys/param.h> 46#include <sys/param.h>
47#include <sys/systm.h> 47#include <sys/systm.h>
48#include <sys/sysctl.h> 48#include <sys/sysctl.h>
49#include <sys/proc.h> 49#include <sys/proc.h>
50#include <sys/time.h> 50#include <sys/time.h>
51#include <sys/vnode.h> 51#include <sys/vnode.h>
52#include <sys/mount.h> 52#include <sys/mount.h>
53#include <sys/namei.h> 53#include <sys/namei.h>
54#include <sys/kauth.h> 54#include <sys/kauth.h>
55#include <sys/module.h> 55#include <sys/module.h>
56 56
57#include <miscfs/umapfs/umap.h> 57#include <miscfs/umapfs/umap.h>
58#include <miscfs/genfs/layer_extern.h> 58#include <miscfs/genfs/layer_extern.h>
59 59
60MODULE(MODULE_CLASS_VFS, umap, "layerfs"); 60MODULE(MODULE_CLASS_VFS, umap, "layerfs");
61 61
62VFS_PROTOS(umapfs); 62VFS_PROTOS(umapfs);
63 63
64static struct sysctllog *umapfs_sysctl_log; 64static struct sysctllog *umapfs_sysctl_log;
65 65
66/* 66/*
67 * Mount umap layer 67 * Mount umap layer
68 */ 68 */
69int 69int
70umapfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len) 70umapfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
71{ 71{
72 struct lwp *l = curlwp; 72 struct lwp *l = curlwp;
73 struct pathbuf *pb; 73 struct pathbuf *pb;
74 struct nameidata nd; 74 struct nameidata nd;
75 struct umap_args *args = data; 75 struct umap_args *args = data;
76 struct vnode *lowerrootvp, *vp; 76 struct vnode *lowerrootvp, *vp;
77 struct umap_mount *amp; 77 struct umap_mount *amp;
78 int error; 78 int error;
79#ifdef UMAPFS_DIAGNOSTIC 79#ifdef UMAPFS_DIAGNOSTIC
80 int i; 80 int i;
81#endif 81#endif
82 82
83 if (args == NULL) 83 if (args == NULL)
84 return EINVAL; 84 return EINVAL;
85 if (*data_len < sizeof *args) 85 if (*data_len < sizeof *args)
86 return EINVAL; 86 return EINVAL;
87 87
88 if (mp->mnt_flag & MNT_GETARGS) { 88 if (mp->mnt_flag & MNT_GETARGS) {
89 amp = MOUNTTOUMAPMOUNT(mp); 89 amp = MOUNTTOUMAPMOUNT(mp);
90 if (amp == NULL) 90 if (amp == NULL)
91 return EIO; 91 return EIO;
92 args->la.target = NULL; 92 args->la.target = NULL;
93 args->nentries = amp->info_nentries; 93 args->nentries = amp->info_nentries;
94 args->gnentries = amp->info_gnentries; 94 args->gnentries = amp->info_gnentries;
95 *data_len = sizeof *args; 95 *data_len = sizeof *args;
96 return 0; 96 return 0;
97 } 97 }
98 98
99 /* only for root */ 99 /* only for root */
100 error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_MOUNT, 100 error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_MOUNT,
101 KAUTH_REQ_SYSTEM_MOUNT_UMAP, NULL, NULL, NULL); 101 KAUTH_REQ_SYSTEM_MOUNT_UMAP, NULL, NULL, NULL);
102 if (error) 102 if (error)
103 return error; 103 return error;
104 104
105#ifdef UMAPFS_DIAGNOSTIC 105#ifdef UMAPFS_DIAGNOSTIC
106 printf("umapfs_mount(mp = %p)\n", mp); 106 printf("umapfs_mount(mp = %p)\n", mp);
107#endif 107#endif
108 108
109 /* 109 /*
110 * Update is not supported 110 * Update is not supported
111 */ 111 */
112 if (mp->mnt_flag & MNT_UPDATE) 112 if (mp->mnt_flag & MNT_UPDATE)
113 return EOPNOTSUPP; 113 return EOPNOTSUPP;
114 114
115 /* 115 /*
116 * Find lower node 116 * Find lower node
117 */ 117 */
118 error = pathbuf_copyin(args->umap_target, &pb); 118 error = pathbuf_copyin(args->umap_target, &pb);
119 if (error) { 119 if (error) {
120 return error; 120 return error;
121 } 121 }
122 NDINIT(&nd, LOOKUP, FOLLOW|LOCKLEAF, pb); 122 NDINIT(&nd, LOOKUP, FOLLOW|LOCKLEAF, pb);
123 if ((error = namei(&nd)) != 0) { 123 if ((error = namei(&nd)) != 0) {
124 pathbuf_destroy(pb); 124 pathbuf_destroy(pb);
125 return error; 125 return error;
126 } 126 }
127 127
128 /* 128 /*
129 * Sanity check on lower vnode 129 * Sanity check on lower vnode
130 */ 130 */
131 lowerrootvp = nd.ni_vp; 131 lowerrootvp = nd.ni_vp;
132 pathbuf_destroy(pb); 132 pathbuf_destroy(pb);
133#ifdef UMAPFS_DIAGNOSTIC 133#ifdef UMAPFS_DIAGNOSTIC
134 printf("vp = %p, check for VDIR...\n", lowerrootvp); 134 printf("vp = %p, check for VDIR...\n", lowerrootvp);
135#endif 135#endif
136 136
137 if (lowerrootvp->v_type != VDIR) { 137 if (lowerrootvp->v_type != VDIR) {
138 vput(lowerrootvp); 138 vput(lowerrootvp);
139 return (EINVAL); 139 return (EINVAL);
140 } 140 }
141 141
142#ifdef UMAPFS_DIAGNOSTIC 142#ifdef UMAPFS_DIAGNOSTIC
143 printf("mp = %p\n", mp); 143 printf("mp = %p\n", mp);
144#endif 144#endif
145 145
146 amp = kmem_zalloc(sizeof(struct umap_mount), KM_SLEEP); 146 amp = kmem_zalloc(sizeof(struct umap_mount), KM_SLEEP);
147 mp->mnt_data = amp; 147 mp->mnt_data = amp;
148 amp->umapm_vfs = lowerrootvp->v_mount; 148 amp->umapm_vfs = lowerrootvp->v_mount;
149 if (amp->umapm_vfs->mnt_flag & MNT_LOCAL) 149 if (amp->umapm_vfs->mnt_flag & MNT_LOCAL)
150 mp->mnt_flag |= MNT_LOCAL; 150 mp->mnt_flag |= MNT_LOCAL;
151 151
152 /* 152 /*
153 * Now copy in the number of entries and maps for umap mapping. 153 * Now copy in the number of entries and maps for umap mapping.
154 */ 154 */
155 if (args->nentries < 0 || args->nentries > MAPFILEENTRIES || 155 if (args->nentries < 0 || args->nentries > MAPFILEENTRIES ||
156 args->gnentries < 0 || args->gnentries > GMAPFILEENTRIES) { 156 args->gnentries < 0 || args->gnentries > GMAPFILEENTRIES) {
157 vput(lowerrootvp); 157 vput(lowerrootvp);
158 return (EINVAL); 158 return (EINVAL);
159 } 159 }
160 160
161 amp->info_nentries = args->nentries; 161 amp->info_nentries = args->nentries;
162 amp->info_gnentries = args->gnentries; 162 amp->info_gnentries = args->gnentries;
163 error = copyin(args->mapdata, amp->info_mapdata, 163 error = copyin(args->mapdata, amp->info_mapdata,
164 2*sizeof(u_long)*args->nentries); 164 2*sizeof(u_long)*args->nentries);
165 if (error) { 165 if (error) {
166 vput(lowerrootvp); 166 vput(lowerrootvp);
167 return (error); 167 return (error);
168 } 168 }
169 169
170#ifdef UMAPFS_DIAGNOSTIC 170#ifdef UMAPFS_DIAGNOSTIC
171 printf("umap_mount:nentries %d\n",args->nentries); 171 printf("umap_mount:nentries %d\n",args->nentries);
172 for (i = 0; i < args->nentries; i++) 172 for (i = 0; i < args->nentries; i++)
173 printf(" %ld maps to %ld\n", amp->info_mapdata[i][0], 173 printf(" %ld maps to %ld\n", amp->info_mapdata[i][0],
174 amp->info_mapdata[i][1]); 174 amp->info_mapdata[i][1]);
175#endif 175#endif
176 176
177 error = copyin(args->gmapdata, amp->info_gmapdata, 177 error = copyin(args->gmapdata, amp->info_gmapdata,
178 2*sizeof(u_long)*args->gnentries); 178 2*sizeof(u_long)*args->gnentries);
179 if (error) { 179 if (error) {
180 vput(lowerrootvp); 180 vput(lowerrootvp);
181 return (error); 181 return (error);
182 } 182 }
183 183
184#ifdef UMAPFS_DIAGNOSTIC 184#ifdef UMAPFS_DIAGNOSTIC
185 printf("umap_mount:gnentries %d\n",args->gnentries); 185 printf("umap_mount:gnentries %d\n",args->gnentries);
186 for (i = 0; i < args->gnentries; i++) 186 for (i = 0; i < args->gnentries; i++)
187 printf("\tgroup %ld maps to %ld\n", 187 printf("\tgroup %ld maps to %ld\n",
188 amp->info_gmapdata[i][0], 188 amp->info_gmapdata[i][0],
189 amp->info_gmapdata[i][1]); 189 amp->info_gmapdata[i][1]);
190#endif 190#endif
191 191
192 /* 192 /*
193 * Make sure the mount point's sufficiently initialized 193 * Make sure the mount point's sufficiently initialized
194 * that the node create call will work. 194 * that the node create call will work.
195 */ 195 */
196 vfs_getnewfsid(mp); 196 vfs_getnewfsid(mp);
197 amp->umapm_size = sizeof(struct umap_node); 197 amp->umapm_size = sizeof(struct umap_node);
198 amp->umapm_tag = VT_UMAP; 198 amp->umapm_tag = VT_UMAP;
199 amp->umapm_bypass = umap_bypass; 199 amp->umapm_bypass = umap_bypass;
200 amp->umapm_vnodeop_p = umap_vnodeop_p; 200 amp->umapm_vnodeop_p = umap_vnodeop_p;
201 201
202 /* 202 /*
203 * fix up umap node for root vnode. 203 * fix up umap node for root vnode.
204 */ 204 */
205 VOP_UNLOCK(lowerrootvp); 205 VOP_UNLOCK(lowerrootvp);
206 error = layer_node_create(mp, lowerrootvp, &vp); 206 error = layer_node_create(mp, lowerrootvp, &vp);
207 /* 207 /*
208 * Make sure the node alias worked 208 * Make sure the node alias worked
209 */ 209 */
210 if (error) { 210 if (error) {
211 vrele(lowerrootvp); 211 vrele(lowerrootvp);
212 kmem_free(amp, sizeof(struct umap_mount)); 212 kmem_free(amp, sizeof(struct umap_mount));
213 return error; 213 return error;
214 } 214 }
215 215
216 /* 216 /*
217 * Keep a held reference to the root vnode. 217 * Keep a held reference to the root vnode.
218 * It is vrele'd in umapfs_unmount. 218 * It is vrele'd in umapfs_unmount.
219 */ 219 */
220 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); 220 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
221 vp->v_vflag |= VV_ROOT; 221 vp->v_vflag |= VV_ROOT;
222 amp->umapm_rootvp = vp; 222 amp->umapm_rootvp = vp;
 223 mp->mnt_lower = amp->umapm_vfs;
223 VOP_UNLOCK(vp); 224 VOP_UNLOCK(vp);
224 225
225 error = set_statvfs_info(path, UIO_USERSPACE, args->umap_target, 226 error = set_statvfs_info(path, UIO_USERSPACE, args->umap_target,
226 UIO_USERSPACE, mp->mnt_op->vfs_name, mp, l); 227 UIO_USERSPACE, mp->mnt_op->vfs_name, mp, l);
227#ifdef UMAPFS_DIAGNOSTIC 228#ifdef UMAPFS_DIAGNOSTIC
228 printf("umapfs_mount: lower %s, alias at %s\n", 229 printf("umapfs_mount: lower %s, alias at %s\n",
229 mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname); 230 mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname);
230#endif 231#endif
231 return error; 232 return error;
232} 233}
233 234
234/* 235/*
235 * Free reference to umap layer 236 * Free reference to umap layer
236 */ 237 */
237int 238int
238umapfs_unmount(struct mount *mp, int mntflags) 239umapfs_unmount(struct mount *mp, int mntflags)
239{ 240{
240 struct umap_mount *amp = MOUNTTOUMAPMOUNT(mp); 241 struct umap_mount *amp = MOUNTTOUMAPMOUNT(mp);
241 struct vnode *rtvp = amp->umapm_rootvp; 242 struct vnode *rtvp = amp->umapm_rootvp;
242 int error; 243 int error;
243 int flags = 0; 244 int flags = 0;
244 245
245#ifdef UMAPFS_DIAGNOSTIC 246#ifdef UMAPFS_DIAGNOSTIC
246 printf("umapfs_unmount(mp = %p)\n", mp); 247 printf("umapfs_unmount(mp = %p)\n", mp);
247#endif 248#endif
248 249
249 if (mntflags & MNT_FORCE) 250 if (mntflags & MNT_FORCE)
250 flags |= FORCECLOSE; 251 flags |= FORCECLOSE;
251 252
252 if (rtvp->v_usecount > 1 && (mntflags & MNT_FORCE) == 0) 253 if (rtvp->v_usecount > 1 && (mntflags & MNT_FORCE) == 0)
253 return (EBUSY); 254 return (EBUSY);
254 if ((error = vflush(mp, rtvp, flags)) != 0) 255 if ((error = vflush(mp, rtvp, flags)) != 0)
255 return (error); 256 return (error);
256 257
257#ifdef UMAPFS_DIAGNOSTIC 258#ifdef UMAPFS_DIAGNOSTIC
258 vprint("alias root of lower", rtvp); 259 vprint("alias root of lower", rtvp);
259#endif 260#endif
260 /* 261 /*
261 * Blow it away for future re-use 262 * Blow it away for future re-use
262 */ 263 */
263 vgone(rtvp); 264 vgone(rtvp);
264 /* 265 /*
265 * Finally, throw away the umap_mount structure 266 * Finally, throw away the umap_mount structure
266 */ 267 */
267 kmem_free(amp, sizeof(struct umap_mount)); 268 kmem_free(amp, sizeof(struct umap_mount));
268 mp->mnt_data = NULL; 269 mp->mnt_data = NULL;
269 return 0; 270 return 0;
270} 271}
271 272
272extern const struct vnodeopv_desc umapfs_vnodeop_opv_desc; 273extern const struct vnodeopv_desc umapfs_vnodeop_opv_desc;
273 274
274const struct vnodeopv_desc * const umapfs_vnodeopv_descs[] = { 275const struct vnodeopv_desc * const umapfs_vnodeopv_descs[] = {
275 &umapfs_vnodeop_opv_desc, 276 &umapfs_vnodeop_opv_desc,
276 NULL, 277 NULL,
277}; 278};
278 279
279struct vfsops umapfs_vfsops = { 280struct vfsops umapfs_vfsops = {
280 .vfs_name = MOUNT_UMAP, 281 .vfs_name = MOUNT_UMAP,
281 .vfs_min_mount_data = sizeof (struct umap_args), 282 .vfs_min_mount_data = sizeof (struct umap_args),
282 .vfs_mount = umapfs_mount, 283 .vfs_mount = umapfs_mount,
283 .vfs_start = layerfs_start, 284 .vfs_start = layerfs_start,
284 .vfs_unmount = umapfs_unmount, 285 .vfs_unmount = umapfs_unmount,
285 .vfs_root = layerfs_root, 286 .vfs_root = layerfs_root,
286 .vfs_quotactl = layerfs_quotactl, 287 .vfs_quotactl = layerfs_quotactl,
287 .vfs_statvfs = layerfs_statvfs, 288 .vfs_statvfs = layerfs_statvfs,
288 .vfs_sync = layerfs_sync, 289 .vfs_sync = layerfs_sync,
289 .vfs_loadvnode = layerfs_loadvnode, 290 .vfs_loadvnode = layerfs_loadvnode,
290 .vfs_vget = layerfs_vget, 291 .vfs_vget = layerfs_vget,
291 .vfs_fhtovp = layerfs_fhtovp, 292 .vfs_fhtovp = layerfs_fhtovp,
292 .vfs_vptofh = layerfs_vptofh, 293 .vfs_vptofh = layerfs_vptofh,
293 .vfs_init = layerfs_init, 294 .vfs_init = layerfs_init,
294 .vfs_done = layerfs_done, 295 .vfs_done = layerfs_done,
295 .vfs_snapshot = layerfs_snapshot, 296 .vfs_snapshot = layerfs_snapshot,
296 .vfs_extattrctl = vfs_stdextattrctl, 297 .vfs_extattrctl = vfs_stdextattrctl,
297 .vfs_suspendctl = layerfs_suspendctl, 298 .vfs_suspendctl = layerfs_suspendctl,
298 .vfs_renamelock_enter = layerfs_renamelock_enter, 299 .vfs_renamelock_enter = layerfs_renamelock_enter,
299 .vfs_renamelock_exit = layerfs_renamelock_exit, 300 .vfs_renamelock_exit = layerfs_renamelock_exit,
300 .vfs_fsync = (void *)eopnotsupp, 301 .vfs_fsync = (void *)eopnotsupp,
301 .vfs_opv_descs = umapfs_vnodeopv_descs 302 .vfs_opv_descs = umapfs_vnodeopv_descs
302}; 303};
303 304
304static int 305static int
305umap_modcmd(modcmd_t cmd, void *arg) 306umap_modcmd(modcmd_t cmd, void *arg)
306{ 307{
307 int error; 308 int error;
308 309
309 switch (cmd) { 310 switch (cmd) {
310 case MODULE_CMD_INIT: 311 case MODULE_CMD_INIT:
311 error = vfs_attach(&umapfs_vfsops); 312 error = vfs_attach(&umapfs_vfsops);
312 if (error != 0) 313 if (error != 0)
313 break; 314 break;
314 sysctl_createv(&umapfs_sysctl_log, 0, NULL, NULL, 315 sysctl_createv(&umapfs_sysctl_log, 0, NULL, NULL,
315 CTLFLAG_PERMANENT, 316 CTLFLAG_PERMANENT,
316 CTLTYPE_NODE, "umap", 317 CTLTYPE_NODE, "umap",
317 SYSCTL_DESCR("UID/GID remapping file system"), 318 SYSCTL_DESCR("UID/GID remapping file system"),
318 NULL, 0, NULL, 0, 319 NULL, 0, NULL, 0,
319 CTL_VFS, 10, CTL_EOL); 320 CTL_VFS, 10, CTL_EOL);
320 /* 321 /*
321 * XXX the "10" above could be dynamic, thereby eliminating 322 * XXX the "10" above could be dynamic, thereby eliminating
322 * one more instance of the "number to vfs" mapping problem, 323 * one more instance of the "number to vfs" mapping problem,
323 * but "10" is the order as taken from sys/mount.h 324 * but "10" is the order as taken from sys/mount.h
324 */ 325 */
325 break; 326 break;
326 case MODULE_CMD_FINI: 327 case MODULE_CMD_FINI:
327 error = vfs_detach(&umapfs_vfsops); 328 error = vfs_detach(&umapfs_vfsops);
328 if (error != 0) 329 if (error != 0)
329 break; 330 break;
330 sysctl_teardown(&umapfs_sysctl_log); 331 sysctl_teardown(&umapfs_sysctl_log);
331 break; 332 break;
332 default: 333 default:
333 error = ENOTTY; 334 error = ENOTTY;
334 break; 335 break;
335 } 336 }
336 337
337 return (error); 338 return (error);
338} 339}

cvs diff -r1.220 -r1.221 src/sys/sys/mount.h (switch to unified diff)

--- src/sys/sys/mount.h 2017/01/11 09:07:57 1.220
+++ src/sys/sys/mount.h 2017/03/06 10:10:07 1.221
@@ -1,524 +1,525 @@ @@ -1,524 +1,525 @@
1/* $NetBSD: mount.h,v 1.220 2017/01/11 09:07:57 hannken Exp $ */ 1/* $NetBSD: mount.h,v 1.221 2017/03/06 10:10:07 hannken Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1989, 1991, 1993 4 * Copyright (c) 1989, 1991, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors 15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software 16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission. 17 * without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 * 30 *
31 * @(#)mount.h 8.21 (Berkeley) 5/20/95 31 * @(#)mount.h 8.21 (Berkeley) 5/20/95
32 */ 32 */
33 33
34#ifndef _SYS_MOUNT_H_ 34#ifndef _SYS_MOUNT_H_
35#define _SYS_MOUNT_H_ 35#define _SYS_MOUNT_H_
36 36
37#ifndef _KERNEL 37#ifndef _KERNEL
38#include <sys/featuretest.h> 38#include <sys/featuretest.h>
39#if defined(_NETBSD_SOURCE) 39#if defined(_NETBSD_SOURCE)
40#include <sys/stat.h> 40#include <sys/stat.h>
41#endif /* _NETBSD_SOURCE */ 41#endif /* _NETBSD_SOURCE */
42#endif 42#endif
43 43
44#ifndef _STANDALONE 44#ifndef _STANDALONE
45#include <sys/param.h> /* precautionary upon removal from ucred.h */ 45#include <sys/param.h> /* precautionary upon removal from ucred.h */
46#include <sys/time.h> 46#include <sys/time.h>
47#include <sys/uio.h> 47#include <sys/uio.h>
48#include <sys/ucred.h> 48#include <sys/ucred.h>
49#include <sys/fstypes.h> 49#include <sys/fstypes.h>
50#include <sys/queue.h> 50#include <sys/queue.h>
51#include <sys/rwlock.h> 51#include <sys/rwlock.h>
52#include <sys/statvfs.h> 52#include <sys/statvfs.h>
53#include <sys/specificdata.h> 53#include <sys/specificdata.h>
54#include <sys/condvar.h> 54#include <sys/condvar.h>
55#endif /* !_STANDALONE */ 55#endif /* !_STANDALONE */
56 56
57/* 57/*
58 * file system statistics 58 * file system statistics
59 */ 59 */
60 60
61#define MNAMELEN 90 /* length of buffer for returned name */ 61#define MNAMELEN 90 /* length of buffer for returned name */
62 62
63/* 63/*
64 * File system types. 64 * File system types.
65 */ 65 */
66#define MOUNT_FFS "ffs" /* UNIX "Fast" Filesystem */ 66#define MOUNT_FFS "ffs" /* UNIX "Fast" Filesystem */
67#define MOUNT_UFS MOUNT_FFS /* for compatibility */ 67#define MOUNT_UFS MOUNT_FFS /* for compatibility */
68#define MOUNT_NFS "nfs" /* Network Filesystem */ 68#define MOUNT_NFS "nfs" /* Network Filesystem */
69#define MOUNT_MFS "mfs" /* Memory Filesystem */ 69#define MOUNT_MFS "mfs" /* Memory Filesystem */
70#define MOUNT_MSDOS "msdos" /* MSDOS Filesystem */ 70#define MOUNT_MSDOS "msdos" /* MSDOS Filesystem */
71#define MOUNT_LFS "lfs" /* Log-based Filesystem */ 71#define MOUNT_LFS "lfs" /* Log-based Filesystem */
72#define MOUNT_FDESC "fdesc" /* File Descriptor Filesystem */ 72#define MOUNT_FDESC "fdesc" /* File Descriptor Filesystem */
73#define MOUNT_NULL "null" /* Minimal Filesystem Layer */ 73#define MOUNT_NULL "null" /* Minimal Filesystem Layer */
74#define MOUNT_OVERLAY "overlay" /* Minimal Overlay Filesystem Layer */ 74#define MOUNT_OVERLAY "overlay" /* Minimal Overlay Filesystem Layer */
75#define MOUNT_UMAP "umap" /* User/Group Identifier Remapping Filesystem */ 75#define MOUNT_UMAP "umap" /* User/Group Identifier Remapping Filesystem */
76#define MOUNT_KERNFS "kernfs" /* Kernel Information Filesystem */ 76#define MOUNT_KERNFS "kernfs" /* Kernel Information Filesystem */
77#define MOUNT_PROCFS "procfs" /* /proc Filesystem */ 77#define MOUNT_PROCFS "procfs" /* /proc Filesystem */
78#define MOUNT_AFS "afs" /* Andrew Filesystem */ 78#define MOUNT_AFS "afs" /* Andrew Filesystem */
79#define MOUNT_CD9660 "cd9660" /* ISO9660 (aka CDROM) Filesystem */ 79#define MOUNT_CD9660 "cd9660" /* ISO9660 (aka CDROM) Filesystem */
80#define MOUNT_UNION "union" /* Union (translucent) Filesystem */ 80#define MOUNT_UNION "union" /* Union (translucent) Filesystem */
81#define MOUNT_ADOSFS "adosfs" /* AmigaDOS Filesystem */ 81#define MOUNT_ADOSFS "adosfs" /* AmigaDOS Filesystem */
82#define MOUNT_EXT2FS "ext2fs" /* Second Extended Filesystem */ 82#define MOUNT_EXT2FS "ext2fs" /* Second Extended Filesystem */
83#define MOUNT_CFS "coda" /* Coda Filesystem */ 83#define MOUNT_CFS "coda" /* Coda Filesystem */
84#define MOUNT_CODA MOUNT_CFS /* Coda Filesystem */ 84#define MOUNT_CODA MOUNT_CFS /* Coda Filesystem */
85#define MOUNT_FILECORE "filecore" /* Acorn Filecore Filesystem */ 85#define MOUNT_FILECORE "filecore" /* Acorn Filecore Filesystem */
86#define MOUNT_NTFS "ntfs" /* Windows/NT Filesystem */ 86#define MOUNT_NTFS "ntfs" /* Windows/NT Filesystem */
87#define MOUNT_SMBFS "smbfs" /* CIFS (SMB) */ 87#define MOUNT_SMBFS "smbfs" /* CIFS (SMB) */
88#define MOUNT_PTYFS "ptyfs" /* Pseudo tty filesystem */ 88#define MOUNT_PTYFS "ptyfs" /* Pseudo tty filesystem */
89#define MOUNT_TMPFS "tmpfs" /* Efficient memory file-system */ 89#define MOUNT_TMPFS "tmpfs" /* Efficient memory file-system */
90#define MOUNT_UDF "udf" /* UDF CD/DVD filesystem */ 90#define MOUNT_UDF "udf" /* UDF CD/DVD filesystem */
91#define MOUNT_SYSVBFS "sysvbfs" /* System V Boot Filesystem */ 91#define MOUNT_SYSVBFS "sysvbfs" /* System V Boot Filesystem */
92#define MOUNT_PUFFS "puffs" /* Pass-to-Userspace filesystem */ 92#define MOUNT_PUFFS "puffs" /* Pass-to-Userspace filesystem */
93#define MOUNT_HFS "hfs" /* Apple HFS+ Filesystem */ 93#define MOUNT_HFS "hfs" /* Apple HFS+ Filesystem */
94#define MOUNT_EFS "efs" /* SGI's Extent Filesystem */ 94#define MOUNT_EFS "efs" /* SGI's Extent Filesystem */
95#define MOUNT_ZFS "zfs" /* Sun ZFS */ 95#define MOUNT_ZFS "zfs" /* Sun ZFS */
96#define MOUNT_NILFS "nilfs" /* NTT's NiLFS(2) logging file system */ 96#define MOUNT_NILFS "nilfs" /* NTT's NiLFS(2) logging file system */
97#define MOUNT_RUMPFS "rumpfs" /* rump virtual file system */ 97#define MOUNT_RUMPFS "rumpfs" /* rump virtual file system */
98#define MOUNT_V7FS "v7fs" /* 7th Edition of Unix Filesystem */ 98#define MOUNT_V7FS "v7fs" /* 7th Edition of Unix Filesystem */
99 99
100#ifndef _STANDALONE 100#ifndef _STANDALONE
101 101
102struct vnode; 102struct vnode;
103struct vnode_impl; 103struct vnode_impl;
104struct vattr; 104struct vattr;
105 105
106/* 106/*
107 * Structure per mounted file system. Each mounted file system has an 107 * Structure per mounted file system. Each mounted file system has an
108 * array of operations and an instance record. The file systems are 108 * array of operations and an instance record. The file systems are
109 * put on a doubly linked list. 109 * put on a doubly linked list.
110 */ 110 */
111struct mount { 111struct mount {
112 TAILQ_ENTRY(mount) mnt_list; /* mount list */ 112 TAILQ_ENTRY(mount) mnt_list; /* mount list */
113 TAILQ_HEAD(, vnode_impl) mnt_vnodelist; /* list of vnodes this mount */ 113 TAILQ_HEAD(, vnode_impl) mnt_vnodelist; /* list of vnodes this mount */
114 struct vfsops *mnt_op; /* operations on fs */ 114 struct vfsops *mnt_op; /* operations on fs */
115 struct vnode *mnt_vnodecovered; /* vnode we mounted on */ 115 struct vnode *mnt_vnodecovered; /* vnode we mounted on */
 116 struct mount *mnt_lower; /* fs mounted on */
116 int mnt_synclist_slot; /* synclist slot index */ 117 int mnt_synclist_slot; /* synclist slot index */
117 void *mnt_transinfo; /* for FS-internal use */ 118 void *mnt_transinfo; /* for FS-internal use */
118 void *mnt_data; /* private data */ 119 void *mnt_data; /* private data */
119 kmutex_t mnt_unmounting; /* to prevent new activity */ 120 kmutex_t mnt_unmounting; /* to prevent new activity */
120 kmutex_t mnt_renamelock; /* per-fs rename lock */ 121 kmutex_t mnt_renamelock; /* per-fs rename lock */
121 int mnt_refcnt; /* ref count on this structure */ 122 int mnt_refcnt; /* ref count on this structure */
122 unsigned int mnt_busynest; /* vfs_busy nestings */ 123 unsigned int mnt_busynest; /* vfs_busy nestings */
123 int mnt_flag; /* flags */ 124 int mnt_flag; /* flags */
124 int mnt_iflag; /* internal flags */ 125 int mnt_iflag; /* internal flags */
125 int mnt_fs_bshift; /* offset shift for lblkno */ 126 int mnt_fs_bshift; /* offset shift for lblkno */
126 int mnt_dev_bshift; /* shift for device sectors */ 127 int mnt_dev_bshift; /* shift for device sectors */
127 struct statvfs mnt_stat; /* cache of filesystem stats */ 128 struct statvfs mnt_stat; /* cache of filesystem stats */
128 specificdata_reference 129 specificdata_reference
129 mnt_specdataref; /* subsystem specific data */ 130 mnt_specdataref; /* subsystem specific data */
130 kmutex_t mnt_updating; /* to serialize updates */ 131 kmutex_t mnt_updating; /* to serialize updates */
131 struct wapbl_ops 132 struct wapbl_ops
132 *mnt_wapbl_op; /* logging ops */ 133 *mnt_wapbl_op; /* logging ops */
133 struct wapbl *mnt_wapbl; /* log info */ 134 struct wapbl *mnt_wapbl; /* log info */
134 struct wapbl_replay 135 struct wapbl_replay
135 *mnt_wapbl_replay; /* replay support XXX: what? */ 136 *mnt_wapbl_replay; /* replay support XXX: what? */
136 uint64_t mnt_gen; 137 uint64_t mnt_gen;
137}; 138};
138 139
139/* 140/*
140 * Sysctl CTL_VFS definitions. 141 * Sysctl CTL_VFS definitions.
141 * 142 *
142 * Second level identifier specifies which filesystem. Second level 143 * Second level identifier specifies which filesystem. Second level
143 * identifier VFS_GENERIC returns information about all filesystems. 144 * identifier VFS_GENERIC returns information about all filesystems.
144 * 145 *
145 * Note the slightly non-flat nature of these sysctl numbers. Oh for 146 * Note the slightly non-flat nature of these sysctl numbers. Oh for
146 * a better sysctl interface. 147 * a better sysctl interface.
147 */ 148 */
148#define VFS_GENERIC 0 /* generic filesystem information */ 149#define VFS_GENERIC 0 /* generic filesystem information */
149#define VFS_MAXTYPENUM 1 /* int: highest defined fs type */ 150#define VFS_MAXTYPENUM 1 /* int: highest defined fs type */
150#define VFS_CONF 2 /* struct: vfsconf for filesystem given 151#define VFS_CONF 2 /* struct: vfsconf for filesystem given
151 as next argument */ 152 as next argument */
152#define VFS_USERMOUNT 3 /* enable/disable fs mnt by non-root */ 153#define VFS_USERMOUNT 3 /* enable/disable fs mnt by non-root */
153#define VFS_MAGICLINKS 4 /* expand 'magic' symlinks */ 154#define VFS_MAGICLINKS 4 /* expand 'magic' symlinks */
154#define VFSGEN_MAXID 5 /* number of valid vfs.generic ids */ 155#define VFSGEN_MAXID 5 /* number of valid vfs.generic ids */
155 156
156/* 157/*
157 * USE THE SAME NAMES AS MOUNT_*! 158 * USE THE SAME NAMES AS MOUNT_*!
158 * 159 *
159 * Only need to add new entry here if the filesystem actually supports 160 * Only need to add new entry here if the filesystem actually supports
160 * sysctl(2). 161 * sysctl(2).
161 */ 162 */
162#define CTL_VFS_NAMES { \ 163#define CTL_VFS_NAMES { \
163 { "generic", CTLTYPE_NODE }, \ 164 { "generic", CTLTYPE_NODE }, \
164 { MOUNT_FFS, CTLTYPE_NODE }, \ 165 { MOUNT_FFS, CTLTYPE_NODE }, \
165 { MOUNT_NFS, CTLTYPE_NODE }, \ 166 { MOUNT_NFS, CTLTYPE_NODE }, \
166 { MOUNT_MFS, CTLTYPE_NODE }, \ 167 { MOUNT_MFS, CTLTYPE_NODE }, \
167 { MOUNT_MSDOS, CTLTYPE_NODE }, \ 168 { MOUNT_MSDOS, CTLTYPE_NODE }, \
168 { MOUNT_LFS, CTLTYPE_NODE }, \ 169 { MOUNT_LFS, CTLTYPE_NODE }, \
169 { 0, 0 }, /* MOUNT_LOFS */ \ 170 { 0, 0 }, /* MOUNT_LOFS */ \
170 { MOUNT_FDESC, CTLTYPE_NODE }, \ 171 { MOUNT_FDESC, CTLTYPE_NODE }, \
171 { MOUNT_NULL, CTLTYPE_NODE }, \ 172 { MOUNT_NULL, CTLTYPE_NODE }, \
172 { MOUNT_UMAP, CTLTYPE_NODE }, \ 173 { MOUNT_UMAP, CTLTYPE_NODE }, \
173 { MOUNT_KERNFS, CTLTYPE_NODE }, \ 174 { MOUNT_KERNFS, CTLTYPE_NODE }, \
174 { MOUNT_PROCFS, CTLTYPE_NODE }, \ 175 { MOUNT_PROCFS, CTLTYPE_NODE }, \
175 { MOUNT_AFS, CTLTYPE_NODE }, \ 176 { MOUNT_AFS, CTLTYPE_NODE }, \
176 { MOUNT_CD9660, CTLTYPE_NODE }, \ 177 { MOUNT_CD9660, CTLTYPE_NODE }, \
177 { MOUNT_UNION, CTLTYPE_NODE }, \ 178 { MOUNT_UNION, CTLTYPE_NODE }, \
178 { MOUNT_ADOSFS, CTLTYPE_NODE }, \ 179 { MOUNT_ADOSFS, CTLTYPE_NODE }, \
179 { MOUNT_EXT2FS, CTLTYPE_NODE }, \ 180 { MOUNT_EXT2FS, CTLTYPE_NODE }, \
180 { MOUNT_CODA, CTLTYPE_NODE }, \ 181 { MOUNT_CODA, CTLTYPE_NODE }, \
181 { MOUNT_FILECORE, CTLTYPE_NODE }, \ 182 { MOUNT_FILECORE, CTLTYPE_NODE }, \
182 { MOUNT_NTFS, CTLTYPE_NODE }, \ 183 { MOUNT_NTFS, CTLTYPE_NODE }, \
183} 184}
184 185
185#define VFS_MAXID 20 /* number of valid vfs ids */ 186#define VFS_MAXID 20 /* number of valid vfs ids */
186 187
187#define CTL_VFSGENCTL_NAMES { \ 188#define CTL_VFSGENCTL_NAMES { \
188 { 0, 0 }, \ 189 { 0, 0 }, \
189 { "maxtypenum", CTLTYPE_INT }, \ 190 { "maxtypenum", CTLTYPE_INT }, \
190 { "conf", CTLTYPE_NODE }, /* Special */ \ 191 { "conf", CTLTYPE_NODE }, /* Special */ \
191 { "usermount", CTLTYPE_INT }, \ 192 { "usermount", CTLTYPE_INT }, \
192 { "magiclinks", CTLTYPE_INT }, \ 193 { "magiclinks", CTLTYPE_INT }, \
193} 194}
194 195
195#if defined(_KERNEL) 196#if defined(_KERNEL)
196 197
197struct quotactl_args; /* in sys/quotactl.h */ 198struct quotactl_args; /* in sys/quotactl.h */
198struct quotastat; /* in sys/quotactl.h */ 199struct quotastat; /* in sys/quotactl.h */
199struct quotaidtypestat; /* in sys/quotactl.h */ 200struct quotaidtypestat; /* in sys/quotactl.h */
200struct quotaobjtypestat; /* in sys/quotactl.h */ 201struct quotaobjtypestat; /* in sys/quotactl.h */
201struct quotakcursor; /* in sys/quotactl.h */ 202struct quotakcursor; /* in sys/quotactl.h */
202struct quotakey; /* in sys/quota.h */ 203struct quotakey; /* in sys/quota.h */
203struct quotaval; /* in sys/quota.h */ 204struct quotaval; /* in sys/quota.h */
204 205
205#if __STDC__ 206#if __STDC__
206struct nameidata; 207struct nameidata;
207#endif 208#endif
208 209
209/* 210/*
210 * Operations supported on mounted file system. 211 * Operations supported on mounted file system.
211 */ 212 */
212 213
213struct vfsops { 214struct vfsops {
214 const char *vfs_name; 215 const char *vfs_name;
215 size_t vfs_min_mount_data; 216 size_t vfs_min_mount_data;
216 int (*vfs_mount) (struct mount *, const char *, void *, 217 int (*vfs_mount) (struct mount *, const char *, void *,
217 size_t *); 218 size_t *);
218 int (*vfs_start) (struct mount *, int); 219 int (*vfs_start) (struct mount *, int);
219 int (*vfs_unmount) (struct mount *, int); 220 int (*vfs_unmount) (struct mount *, int);
220 int (*vfs_root) (struct mount *, struct vnode **); 221 int (*vfs_root) (struct mount *, struct vnode **);
221 int (*vfs_quotactl) (struct mount *, struct quotactl_args *); 222 int (*vfs_quotactl) (struct mount *, struct quotactl_args *);
222 int (*vfs_statvfs) (struct mount *, struct statvfs *); 223 int (*vfs_statvfs) (struct mount *, struct statvfs *);
223 int (*vfs_sync) (struct mount *, int, struct kauth_cred *); 224 int (*vfs_sync) (struct mount *, int, struct kauth_cred *);
224 int (*vfs_vget) (struct mount *, ino_t, struct vnode **); 225 int (*vfs_vget) (struct mount *, ino_t, struct vnode **);
225 int (*vfs_loadvnode) (struct mount *, struct vnode *, 226 int (*vfs_loadvnode) (struct mount *, struct vnode *,
226 const void *, size_t, const void **); 227 const void *, size_t, const void **);
227 int (*vfs_newvnode) (struct mount *, struct vnode *, struct vnode *, 228 int (*vfs_newvnode) (struct mount *, struct vnode *, struct vnode *,
228 struct vattr *, kauth_cred_t, 229 struct vattr *, kauth_cred_t,
229 size_t *, const void **); 230 size_t *, const void **);
230 int (*vfs_fhtovp) (struct mount *, struct fid *, 231 int (*vfs_fhtovp) (struct mount *, struct fid *,
231 struct vnode **); 232 struct vnode **);
232 int (*vfs_vptofh) (struct vnode *, struct fid *, size_t *); 233 int (*vfs_vptofh) (struct vnode *, struct fid *, size_t *);
233 void (*vfs_init) (void); 234 void (*vfs_init) (void);
234 void (*vfs_reinit) (void); 235 void (*vfs_reinit) (void);
235 void (*vfs_done) (void); 236 void (*vfs_done) (void);
236 int (*vfs_mountroot)(void); 237 int (*vfs_mountroot)(void);
237 int (*vfs_snapshot) (struct mount *, struct vnode *, 238 int (*vfs_snapshot) (struct mount *, struct vnode *,
238 struct timespec *); 239 struct timespec *);
239 int (*vfs_extattrctl) (struct mount *, int, 240 int (*vfs_extattrctl) (struct mount *, int,
240 struct vnode *, int, const char *); 241 struct vnode *, int, const char *);
241 int (*vfs_suspendctl) (struct mount *, int); 242 int (*vfs_suspendctl) (struct mount *, int);
242 int (*vfs_renamelock_enter)(struct mount *); 243 int (*vfs_renamelock_enter)(struct mount *);
243 void (*vfs_renamelock_exit)(struct mount *); 244 void (*vfs_renamelock_exit)(struct mount *);
244 int (*vfs_fsync) (struct vnode *, int); 245 int (*vfs_fsync) (struct vnode *, int);
245 const struct vnodeopv_desc * const *vfs_opv_descs; 246 const struct vnodeopv_desc * const *vfs_opv_descs;
246 int vfs_refcount; 247 int vfs_refcount;
247 LIST_ENTRY(vfsops) vfs_list; 248 LIST_ENTRY(vfsops) vfs_list;
248}; 249};
249 250
250/* XXX vget is actually file system internal. */ 251/* XXX vget is actually file system internal. */
251#define VFS_VGET(MP, INO, VPP) (*(MP)->mnt_op->vfs_vget)(MP, INO, VPP) 252#define VFS_VGET(MP, INO, VPP) (*(MP)->mnt_op->vfs_vget)(MP, INO, VPP)
252#define VFS_LOADVNODE(MP, VP, KEY, KEY_LEN, NEW_KEY) \ 253#define VFS_LOADVNODE(MP, VP, KEY, KEY_LEN, NEW_KEY) \
253 (*(MP)->mnt_op->vfs_loadvnode)(MP, VP, KEY, KEY_LEN, NEW_KEY) 254 (*(MP)->mnt_op->vfs_loadvnode)(MP, VP, KEY, KEY_LEN, NEW_KEY)
254#define VFS_NEWVNODE(MP, DVP, VP, VAP, CRED, NEW_LEN, NEW_KEY) \ 255#define VFS_NEWVNODE(MP, DVP, VP, VAP, CRED, NEW_LEN, NEW_KEY) \
255 (*(MP)->mnt_op->vfs_newvnode)(MP, DVP, VP, VAP, CRED, NEW_LEN, NEW_KEY) 256 (*(MP)->mnt_op->vfs_newvnode)(MP, DVP, VP, VAP, CRED, NEW_LEN, NEW_KEY)
256 257
257#define VFS_RENAMELOCK_ENTER(MP) (*(MP)->mnt_op->vfs_renamelock_enter)(MP) 258#define VFS_RENAMELOCK_ENTER(MP) (*(MP)->mnt_op->vfs_renamelock_enter)(MP)
258#define VFS_RENAMELOCK_EXIT(MP) (*(MP)->mnt_op->vfs_renamelock_exit)(MP) 259#define VFS_RENAMELOCK_EXIT(MP) (*(MP)->mnt_op->vfs_renamelock_exit)(MP)
259#define VFS_FSYNC(MP, VP, FLG) (*(MP)->mnt_op->vfs_fsync)(VP, FLG) 260#define VFS_FSYNC(MP, VP, FLG) (*(MP)->mnt_op->vfs_fsync)(VP, FLG)
260 261
261int VFS_MOUNT(struct mount *, const char *, void *, size_t *); 262int VFS_MOUNT(struct mount *, const char *, void *, size_t *);
262int VFS_START(struct mount *, int); 263int VFS_START(struct mount *, int);
263int VFS_UNMOUNT(struct mount *, int); 264int VFS_UNMOUNT(struct mount *, int);
264int VFS_ROOT(struct mount *, struct vnode **); 265int VFS_ROOT(struct mount *, struct vnode **);
265int VFS_QUOTACTL(struct mount *, struct quotactl_args *); 266int VFS_QUOTACTL(struct mount *, struct quotactl_args *);
266int VFS_STATVFS(struct mount *, struct statvfs *); 267int VFS_STATVFS(struct mount *, struct statvfs *);
267int VFS_SYNC(struct mount *, int, struct kauth_cred *); 268int VFS_SYNC(struct mount *, int, struct kauth_cred *);
268int VFS_FHTOVP(struct mount *, struct fid *, struct vnode **); 269int VFS_FHTOVP(struct mount *, struct fid *, struct vnode **);
269int VFS_VPTOFH(struct vnode *, struct fid *, size_t *); 270int VFS_VPTOFH(struct vnode *, struct fid *, size_t *);
270int VFS_SNAPSHOT(struct mount *, struct vnode *, struct timespec *); 271int VFS_SNAPSHOT(struct mount *, struct vnode *, struct timespec *);
271int VFS_EXTATTRCTL(struct mount *, int, struct vnode *, int, const char *); 272int VFS_EXTATTRCTL(struct mount *, int, struct vnode *, int, const char *);
272int VFS_SUSPENDCTL(struct mount *, int); 273int VFS_SUSPENDCTL(struct mount *, int);
273 274
274#endif /* _KERNEL */ 275#endif /* _KERNEL */
275 276
276#ifdef _KERNEL 277#ifdef _KERNEL
277#if __STDC__ 278#if __STDC__
278struct mbuf; 279struct mbuf;
279struct vnodeopv_desc; 280struct vnodeopv_desc;
280struct kauth_cred; 281struct kauth_cred;
281#endif 282#endif
282 283
283#define VFS_MAX_MOUNT_DATA 8192 284#define VFS_MAX_MOUNT_DATA 8192
284 285
285#define VFS_PROTOS(fsname) \ 286#define VFS_PROTOS(fsname) \
286int fsname##_mount(struct mount *, const char *, void *, \ 287int fsname##_mount(struct mount *, const char *, void *, \
287 size_t *); \ 288 size_t *); \
288int fsname##_start(struct mount *, int); \ 289int fsname##_start(struct mount *, int); \
289int fsname##_unmount(struct mount *, int); \ 290int fsname##_unmount(struct mount *, int); \
290int fsname##_root(struct mount *, struct vnode **); \ 291int fsname##_root(struct mount *, struct vnode **); \
291int fsname##_quotactl(struct mount *, struct quotactl_args *); \ 292int fsname##_quotactl(struct mount *, struct quotactl_args *); \
292int fsname##_statvfs(struct mount *, struct statvfs *); \ 293int fsname##_statvfs(struct mount *, struct statvfs *); \
293int fsname##_sync(struct mount *, int, struct kauth_cred *); \ 294int fsname##_sync(struct mount *, int, struct kauth_cred *); \
294int fsname##_vget(struct mount *, ino_t, struct vnode **); \ 295int fsname##_vget(struct mount *, ino_t, struct vnode **); \
295int fsname##_loadvnode(struct mount *, struct vnode *, \ 296int fsname##_loadvnode(struct mount *, struct vnode *, \
296 const void *, size_t, const void **); \ 297 const void *, size_t, const void **); \
297int fsname##_newvnode(struct mount *, struct vnode *, \ 298int fsname##_newvnode(struct mount *, struct vnode *, \
298 struct vnode *, struct vattr *, kauth_cred_t, \ 299 struct vnode *, struct vattr *, kauth_cred_t, \
299 size_t *, const void **); \ 300 size_t *, const void **); \
300int fsname##_fhtovp(struct mount *, struct fid *, struct vnode **); \ 301int fsname##_fhtovp(struct mount *, struct fid *, struct vnode **); \
301int fsname##_vptofh(struct vnode *, struct fid *, size_t *); \ 302int fsname##_vptofh(struct vnode *, struct fid *, size_t *); \
302void fsname##_init(void); \ 303void fsname##_init(void); \
303void fsname##_reinit(void); \ 304void fsname##_reinit(void); \
304void fsname##_done(void); \ 305void fsname##_done(void); \
305int fsname##_mountroot(void); \ 306int fsname##_mountroot(void); \
306int fsname##_snapshot(struct mount *, struct vnode *, \ 307int fsname##_snapshot(struct mount *, struct vnode *, \
307 struct timespec *); \ 308 struct timespec *); \
308int fsname##_extattrctl(struct mount *, int, struct vnode *, int, \ 309int fsname##_extattrctl(struct mount *, int, struct vnode *, int, \
309 const char *); \ 310 const char *); \
310int fsname##_suspendctl(struct mount *, int) 311int fsname##_suspendctl(struct mount *, int)
311 312
312/* 313/*
313 * This operations vector is so wapbl can be wrapped into a filesystem lkm. 314 * This operations vector is so wapbl can be wrapped into a filesystem lkm.
314 * XXX Eventually, we want to move this functionality 315 * XXX Eventually, we want to move this functionality
315 * down into the filesystems themselves so that this isn't needed. 316 * down into the filesystems themselves so that this isn't needed.
316 */ 317 */
317struct wapbl_ops { 318struct wapbl_ops {
318 void (*wo_wapbl_discard)(struct wapbl *); 319 void (*wo_wapbl_discard)(struct wapbl *);
319 int (*wo_wapbl_replay_isopen)(struct wapbl_replay *); 320 int (*wo_wapbl_replay_isopen)(struct wapbl_replay *);
320 int (*wo_wapbl_replay_can_read)(struct wapbl_replay *, daddr_t, long); 321 int (*wo_wapbl_replay_can_read)(struct wapbl_replay *, daddr_t, long);
321 int (*wo_wapbl_replay_read)(struct wapbl_replay *, void *, daddr_t, long); 322 int (*wo_wapbl_replay_read)(struct wapbl_replay *, void *, daddr_t, long);
322 void (*wo_wapbl_add_buf)(struct wapbl *, struct buf *); 323 void (*wo_wapbl_add_buf)(struct wapbl *, struct buf *);
323 void (*wo_wapbl_remove_buf)(struct wapbl *, struct buf *); 324 void (*wo_wapbl_remove_buf)(struct wapbl *, struct buf *);
324 void (*wo_wapbl_resize_buf)(struct wapbl *, struct buf *, long, long); 325 void (*wo_wapbl_resize_buf)(struct wapbl *, struct buf *, long, long);
325 int (*wo_wapbl_begin)(struct wapbl *, const char *, int); 326 int (*wo_wapbl_begin)(struct wapbl *, const char *, int);
326 void (*wo_wapbl_end)(struct wapbl *); 327 void (*wo_wapbl_end)(struct wapbl *);
327 void (*wo_wapbl_junlock_assert)(struct wapbl *); 328 void (*wo_wapbl_junlock_assert)(struct wapbl *);
328 void (*wo_wapbl_biodone)(struct buf *); 329 void (*wo_wapbl_biodone)(struct buf *);
329}; 330};
330#define WAPBL_DISCARD(MP) \ 331#define WAPBL_DISCARD(MP) \
331 (*(MP)->mnt_wapbl_op->wo_wapbl_discard)((MP)->mnt_wapbl) 332 (*(MP)->mnt_wapbl_op->wo_wapbl_discard)((MP)->mnt_wapbl)
332#define WAPBL_REPLAY_ISOPEN(MP) \ 333#define WAPBL_REPLAY_ISOPEN(MP) \
333 (*(MP)->mnt_wapbl_op->wo_wapbl_replay_isopen)((MP)->mnt_wapbl_replay) 334 (*(MP)->mnt_wapbl_op->wo_wapbl_replay_isopen)((MP)->mnt_wapbl_replay)
334#define WAPBL_REPLAY_CAN_READ(MP, BLK, LEN) \ 335#define WAPBL_REPLAY_CAN_READ(MP, BLK, LEN) \
335 (*(MP)->mnt_wapbl_op->wo_wapbl_replay_can_read)((MP)->mnt_wapbl_replay, \ 336 (*(MP)->mnt_wapbl_op->wo_wapbl_replay_can_read)((MP)->mnt_wapbl_replay, \
336 (BLK), (LEN)) 337 (BLK), (LEN))
337#define WAPBL_REPLAY_READ(MP, DATA, BLK, LEN) \ 338#define WAPBL_REPLAY_READ(MP, DATA, BLK, LEN) \
338 (*(MP)->mnt_wapbl_op->wo_wapbl_replay_read)((MP)->mnt_wapbl_replay, \ 339 (*(MP)->mnt_wapbl_op->wo_wapbl_replay_read)((MP)->mnt_wapbl_replay, \
339 (DATA), (BLK), (LEN)) 340 (DATA), (BLK), (LEN))
340#define WAPBL_ADD_BUF(MP, BP) \ 341#define WAPBL_ADD_BUF(MP, BP) \
341 (*(MP)->mnt_wapbl_op->wo_wapbl_add_buf)((MP)->mnt_wapbl, (BP)) 342 (*(MP)->mnt_wapbl_op->wo_wapbl_add_buf)((MP)->mnt_wapbl, (BP))
342#define WAPBL_REMOVE_BUF(MP, BP) \ 343#define WAPBL_REMOVE_BUF(MP, BP) \
343 (*(MP)->mnt_wapbl_op->wo_wapbl_remove_buf)((MP)->mnt_wapbl, (BP)) 344 (*(MP)->mnt_wapbl_op->wo_wapbl_remove_buf)((MP)->mnt_wapbl, (BP))
344#define WAPBL_RESIZE_BUF(MP, BP, OLDSZ, OLDCNT) \ 345#define WAPBL_RESIZE_BUF(MP, BP, OLDSZ, OLDCNT) \
345 (*(MP)->mnt_wapbl_op->wo_wapbl_resize_buf)((MP)->mnt_wapbl, (BP), \ 346 (*(MP)->mnt_wapbl_op->wo_wapbl_resize_buf)((MP)->mnt_wapbl, (BP), \
346 (OLDSZ), (OLDCNT)) 347 (OLDSZ), (OLDCNT))
347#define WAPBL_BEGIN(MP) \ 348#define WAPBL_BEGIN(MP) \
348 (*(MP)->mnt_wapbl_op->wo_wapbl_begin)((MP)->mnt_wapbl, \ 349 (*(MP)->mnt_wapbl_op->wo_wapbl_begin)((MP)->mnt_wapbl, \
349 __FILE__, __LINE__) 350 __FILE__, __LINE__)
350#define WAPBL_END(MP) \ 351#define WAPBL_END(MP) \
351 (*(MP)->mnt_wapbl_op->wo_wapbl_end)((MP)->mnt_wapbl) 352 (*(MP)->mnt_wapbl_op->wo_wapbl_end)((MP)->mnt_wapbl)
352#define WAPBL_JUNLOCK_ASSERT(MP) \ 353#define WAPBL_JUNLOCK_ASSERT(MP) \
353 (*(MP)->mnt_wapbl_op->wo_wapbl_junlock_assert)((MP)->mnt_wapbl) 354 (*(MP)->mnt_wapbl_op->wo_wapbl_junlock_assert)((MP)->mnt_wapbl)
354 355
355struct vfs_hooks { 356struct vfs_hooks {
356 LIST_ENTRY(vfs_hooks) vfs_hooks_list; 357 LIST_ENTRY(vfs_hooks) vfs_hooks_list;
357 void (*vh_unmount)(struct mount *); 358 void (*vh_unmount)(struct mount *);
358 int (*vh_reexport)(struct mount *, const char *, void *); 359 int (*vh_reexport)(struct mount *, const char *, void *);
359 void (*vh_future_expansion_1)(void); 360 void (*vh_future_expansion_1)(void);
360 void (*vh_future_expansion_2)(void); 361 void (*vh_future_expansion_2)(void);
361 void (*vh_future_expansion_3)(void); 362 void (*vh_future_expansion_3)(void);
362 void (*vh_future_expansion_4)(void); 363 void (*vh_future_expansion_4)(void);
363 void (*vh_future_expansion_5)(void); 364 void (*vh_future_expansion_5)(void);
364}; 365};
365 366
366void vfs_hooks_init(void); 367void vfs_hooks_init(void);
367int vfs_hooks_attach(struct vfs_hooks *); 368int vfs_hooks_attach(struct vfs_hooks *);
368int vfs_hooks_detach(struct vfs_hooks *); 369int vfs_hooks_detach(struct vfs_hooks *);
369void vfs_hooks_unmount(struct mount *); 370void vfs_hooks_unmount(struct mount *);
370int vfs_hooks_reexport(struct mount *, const char *, void *); 371int vfs_hooks_reexport(struct mount *, const char *, void *);
371 372
372#endif /* _KERNEL */ 373#endif /* _KERNEL */
373 374
374/* 375/*
375 * Export arguments for local filesystem mount calls. 376 * Export arguments for local filesystem mount calls.
376 * 377 *
377 * This structure is deprecated and is only provided for compatibility 378 * This structure is deprecated and is only provided for compatibility
378 * reasons with old binary utilities; several file systems expose an 379 * reasons with old binary utilities; several file systems expose an
379 * instance of this structure in their mount arguments structure, thus 380 * instance of this structure in their mount arguments structure, thus
380 * needing a padding in place of the old values. This definition cannot 381 * needing a padding in place of the old values. This definition cannot
381 * change in the future due to this reason. 382 * change in the future due to this reason.
382 * XXX: This should be moved to the compat subtree but cannot be done 383 * XXX: This should be moved to the compat subtree but cannot be done
383 * until we can move the mount args structures themselves. 384 * until we can move the mount args structures themselves.
384 * 385 *
385 * The current export_args structure can be found in nfs/nfs.h. 386 * The current export_args structure can be found in nfs/nfs.h.
386 */ 387 */
387struct export_args30 { 388struct export_args30 {
388 int ex_flags; /* export related flags */ 389 int ex_flags; /* export related flags */
389 uid_t ex_root; /* mapping for root uid */ 390 uid_t ex_root; /* mapping for root uid */
390 struct uucred ex_anon; /* mapping for anonymous user */ 391 struct uucred ex_anon; /* mapping for anonymous user */
391 struct sockaddr *ex_addr; /* net address to which exported */ 392 struct sockaddr *ex_addr; /* net address to which exported */
392 int ex_addrlen; /* and the net address length */ 393 int ex_addrlen; /* and the net address length */
393 struct sockaddr *ex_mask; /* mask of valid bits in saddr */ 394 struct sockaddr *ex_mask; /* mask of valid bits in saddr */
394 int ex_masklen; /* and the smask length */ 395 int ex_masklen; /* and the smask length */
395 char *ex_indexfile; /* index file for WebNFS URLs */ 396 char *ex_indexfile; /* index file for WebNFS URLs */
396}; 397};
397 398
398struct mnt_export_args30 { 399struct mnt_export_args30 {
399 const char *fspec; /* Always NULL */ 400 const char *fspec; /* Always NULL */
400 struct export_args30 eargs; 401 struct export_args30 eargs;
401}; 402};
402 403
403#ifdef _KERNEL 404#ifdef _KERNEL
404 405
405/* 406/*
406 * exported VFS interface (see vfssubr(9)) 407 * exported VFS interface (see vfssubr(9))
407 */ 408 */
408struct mount *vfs_getvfs(fsid_t *); /* return vfs given fsid */ 409struct mount *vfs_getvfs(fsid_t *); /* return vfs given fsid */
409int vfs_composefh(struct vnode *, fhandle_t *, size_t *); 410int vfs_composefh(struct vnode *, fhandle_t *, size_t *);
410int vfs_composefh_alloc(struct vnode *, fhandle_t **); 411int vfs_composefh_alloc(struct vnode *, fhandle_t **);
411void vfs_composefh_free(fhandle_t *); 412void vfs_composefh_free(fhandle_t *);
412int vfs_fhtovp(fhandle_t *, struct vnode **); 413int vfs_fhtovp(fhandle_t *, struct vnode **);
413int vfs_mountedon(struct vnode *);/* is a vfs mounted on vp */ 414int vfs_mountedon(struct vnode *);/* is a vfs mounted on vp */
414int vfs_mountroot(void); 415int vfs_mountroot(void);
415void vfs_shutdown(void); /* unmount and sync file systems */ 416void vfs_shutdown(void); /* unmount and sync file systems */
416void vfs_sync_all(struct lwp *); 417void vfs_sync_all(struct lwp *);
417bool vfs_unmountall(struct lwp *); /* unmount file systems */ 418bool vfs_unmountall(struct lwp *); /* unmount file systems */
418bool vfs_unmountall1(struct lwp *, bool, bool); 419bool vfs_unmountall1(struct lwp *, bool, bool);
419bool vfs_unmount_forceone(struct lwp *); 420bool vfs_unmount_forceone(struct lwp *);
420int vfs_busy(struct mount *, struct mount **); 421int vfs_busy(struct mount *, struct mount **);
421int vfs_rootmountalloc(const char *, const char *, struct mount **); 422int vfs_rootmountalloc(const char *, const char *, struct mount **);
422void vfs_unbusy(struct mount *, bool, struct mount **); 423void vfs_unbusy(struct mount *, bool, struct mount **);
423int vfs_attach(struct vfsops *); 424int vfs_attach(struct vfsops *);
424int vfs_detach(struct vfsops *); 425int vfs_detach(struct vfsops *);
425void vfs_reinit(void); 426void vfs_reinit(void);
426struct vfsops *vfs_getopsbyname(const char *); 427struct vfsops *vfs_getopsbyname(const char *);
427void vfs_delref(struct vfsops *); 428void vfs_delref(struct vfsops *);
428void vfs_destroy(struct mount *); 429void vfs_destroy(struct mount *);
429struct mount *vfs_mountalloc(struct vfsops *, struct vnode *); 430struct mount *vfs_mountalloc(struct vfsops *, struct vnode *);
430int vfs_stdextattrctl(struct mount *, int, struct vnode *, 431int vfs_stdextattrctl(struct mount *, int, struct vnode *,
431 int, const char *); 432 int, const char *);
432void vfs_insmntque(struct vnode *, struct mount *); 433void vfs_insmntque(struct vnode *, struct mount *);
433int vfs_quotactl_stat(struct mount *, struct quotastat *); 434int vfs_quotactl_stat(struct mount *, struct quotastat *);
434int vfs_quotactl_idtypestat(struct mount *, int, struct quotaidtypestat *); 435int vfs_quotactl_idtypestat(struct mount *, int, struct quotaidtypestat *);
435int vfs_quotactl_objtypestat(struct mount *,int,struct quotaobjtypestat *); 436int vfs_quotactl_objtypestat(struct mount *,int,struct quotaobjtypestat *);
436int vfs_quotactl_get(struct mount *, const struct quotakey *, 437int vfs_quotactl_get(struct mount *, const struct quotakey *,
437 struct quotaval *); 438 struct quotaval *);
438int vfs_quotactl_put(struct mount *, const struct quotakey *, 439int vfs_quotactl_put(struct mount *, const struct quotakey *,
439 const struct quotaval *); 440 const struct quotaval *);
440int vfs_quotactl_del(struct mount *, const struct quotakey *); 441int vfs_quotactl_del(struct mount *, const struct quotakey *);
441int vfs_quotactl_cursoropen(struct mount *, struct quotakcursor *); 442int vfs_quotactl_cursoropen(struct mount *, struct quotakcursor *);
442int vfs_quotactl_cursorclose(struct mount *, struct quotakcursor *); 443int vfs_quotactl_cursorclose(struct mount *, struct quotakcursor *);
443int vfs_quotactl_cursorskipidtype(struct mount *, struct quotakcursor *, 444int vfs_quotactl_cursorskipidtype(struct mount *, struct quotakcursor *,
444 int); 445 int);
445int vfs_quotactl_cursorget(struct mount *, struct quotakcursor *, 446int vfs_quotactl_cursorget(struct mount *, struct quotakcursor *,
446 struct quotakey *, struct quotaval *, unsigned, unsigned *); 447 struct quotakey *, struct quotaval *, unsigned, unsigned *);
447int vfs_quotactl_cursoratend(struct mount *, struct quotakcursor *, int *); 448int vfs_quotactl_cursoratend(struct mount *, struct quotakcursor *, int *);
448int vfs_quotactl_cursorrewind(struct mount *, struct quotakcursor *); 449int vfs_quotactl_cursorrewind(struct mount *, struct quotakcursor *);
449int vfs_quotactl_quotaon(struct mount *, int, const char *); 450int vfs_quotactl_quotaon(struct mount *, int, const char *);
450int vfs_quotactl_quotaoff(struct mount *, int); 451int vfs_quotactl_quotaoff(struct mount *, int);
451 452
452struct vnode_iterator; /* Opaque. */ 453struct vnode_iterator; /* Opaque. */
453void vfs_vnode_iterator_init(struct mount *, struct vnode_iterator **); 454void vfs_vnode_iterator_init(struct mount *, struct vnode_iterator **);
454void vfs_vnode_iterator_destroy(struct vnode_iterator *); 455void vfs_vnode_iterator_destroy(struct vnode_iterator *);
455struct vnode *vfs_vnode_iterator_next(struct vnode_iterator *, 456struct vnode *vfs_vnode_iterator_next(struct vnode_iterator *,
456 bool (*)(void *, struct vnode *), void *); 457 bool (*)(void *, struct vnode *), void *);
457 458
458/* Syncer */ 459/* Syncer */
459extern int syncer_maxdelay; 460extern int syncer_maxdelay;
460extern kmutex_t syncer_mutex; 461extern kmutex_t syncer_mutex;
461extern time_t syncdelay; 462extern time_t syncdelay;
462extern time_t filedelay; 463extern time_t filedelay;
463extern time_t dirdelay; 464extern time_t dirdelay;
464extern time_t metadelay; 465extern time_t metadelay;
465void vfs_syncer_add_to_worklist(struct mount *); 466void vfs_syncer_add_to_worklist(struct mount *);
466void vfs_syncer_remove_from_worklist(struct mount *); 467void vfs_syncer_remove_from_worklist(struct mount *);
467 468
468extern TAILQ_HEAD(mntlist, mount) mountlist; /* mounted filesystem list */ 469extern TAILQ_HEAD(mntlist, mount) mountlist; /* mounted filesystem list */
469extern struct vfsops *vfssw[]; /* filesystem type table */ 470extern struct vfsops *vfssw[]; /* filesystem type table */
470extern int nvfssw; 471extern int nvfssw;
471extern kmutex_t mountlist_lock; 472extern kmutex_t mountlist_lock;
472extern kmutex_t vfs_list_lock; 473extern kmutex_t vfs_list_lock;
473 474
474void vfs_mount_sysinit(void); 475void vfs_mount_sysinit(void);
475long makefstype(const char *); 476long makefstype(const char *);
476int mount_domount(struct lwp *, struct vnode **, struct vfsops *, 477int mount_domount(struct lwp *, struct vnode **, struct vfsops *,
477 const char *, int, void *, size_t *); 478 const char *, int, void *, size_t *);
478int dounmount(struct mount *, int, struct lwp *); 479int dounmount(struct mount *, int, struct lwp *);
479int do_sys_mount(struct lwp *, const char *, enum uio_seg, const char *, 480int do_sys_mount(struct lwp *, const char *, enum uio_seg, const char *,
480 int, void *, enum uio_seg, size_t, register_t *); 481 int, void *, enum uio_seg, size_t, register_t *);
481void vfsinit(void); 482void vfsinit(void);
482void vfs_opv_init(const struct vnodeopv_desc * const *); 483void vfs_opv_init(const struct vnodeopv_desc * const *);
483void vfs_opv_free(const struct vnodeopv_desc * const *); 484void vfs_opv_free(const struct vnodeopv_desc * const *);
484#ifdef DEBUG 485#ifdef DEBUG
485void vfs_bufstats(void); 486void vfs_bufstats(void);
486#endif 487#endif
487 488
488int mount_specific_key_create(specificdata_key_t *, specificdata_dtor_t); 489int mount_specific_key_create(specificdata_key_t *, specificdata_dtor_t);
489void mount_specific_key_delete(specificdata_key_t); 490void mount_specific_key_delete(specificdata_key_t);
490void mount_initspecific(struct mount *); 491void mount_initspecific(struct mount *);
491void mount_finispecific(struct mount *); 492void mount_finispecific(struct mount *);
492void * mount_getspecific(struct mount *, specificdata_key_t); 493void * mount_getspecific(struct mount *, specificdata_key_t);
493void mount_setspecific(struct mount *, specificdata_key_t, void *); 494void mount_setspecific(struct mount *, specificdata_key_t, void *);
494 495
495int usermount_common_policy(struct mount *, u_long); 496int usermount_common_policy(struct mount *, u_long);
496void mountlist_append(struct mount *); 497void mountlist_append(struct mount *);
497 498
498LIST_HEAD(vfs_list_head, vfsops); 499LIST_HEAD(vfs_list_head, vfsops);
499extern struct vfs_list_head vfs_list; 500extern struct vfs_list_head vfs_list;
500 501
501#else /* _KERNEL */ 502#else /* _KERNEL */
502 503
503#include <sys/cdefs.h> 504#include <sys/cdefs.h>
504 505
505__BEGIN_DECLS 506__BEGIN_DECLS
506#if !defined(__LIBC12_SOURCE__) && !defined(_STANDALONE) 507#if !defined(__LIBC12_SOURCE__) && !defined(_STANDALONE)
507int getfh(const char *, void *, size_t *) 508int getfh(const char *, void *, size_t *)
508 __RENAME(__getfh30); 509 __RENAME(__getfh30);
509#endif 510#endif
510 511
511int unmount(const char *, int); 512int unmount(const char *, int);
512#if defined(_NETBSD_SOURCE) 513#if defined(_NETBSD_SOURCE)
513#ifndef __LIBC12_SOURCE__ 514#ifndef __LIBC12_SOURCE__
514int mount(const char *, const char *, int, void *, size_t) __RENAME(__mount50); 515int mount(const char *, const char *, int, void *, size_t) __RENAME(__mount50);
515int fhopen(const void *, size_t, int) __RENAME(__fhopen40); 516int fhopen(const void *, size_t, int) __RENAME(__fhopen40);
516int fhstat(const void *, size_t, struct stat *) __RENAME(__fhstat50); 517int fhstat(const void *, size_t, struct stat *) __RENAME(__fhstat50);
517#endif 518#endif
518#endif /* _NETBSD_SOURCE */ 519#endif /* _NETBSD_SOURCE */
519__END_DECLS 520__END_DECLS
520 521
521#endif /* _KERNEL */ 522#endif /* _KERNEL */
522#endif /* !_STANDALONE */ 523#endif /* !_STANDALONE */
523 524
524#endif /* !_SYS_MOUNT_H_ */ 525#endif /* !_SYS_MOUNT_H_ */

cvs diff -r1.531 -r1.532 src/sys/sys/param.h (switch to unified diff)

--- src/sys/sys/param.h 2017/03/01 10:44:47 1.531
+++ src/sys/sys/param.h 2017/03/06 10:10:07 1.532
@@ -1,496 +1,496 @@ @@ -1,496 +1,496 @@
1/* $NetBSD: param.h,v 1.531 2017/03/01 10:44:47 hannken Exp $ */ 1/* $NetBSD: param.h,v 1.532 2017/03/06 10:10:07 hannken Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1982, 1986, 1989, 1993 4 * Copyright (c) 1982, 1986, 1989, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc. 6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed 7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph 8 * to the University of California by American Telephone and Telegraph
9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 * the permission of UNIX System Laboratories, Inc. 10 * the permission of UNIX System Laboratories, Inc.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
15 * 1. Redistributions of source code must retain the above copyright 15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer. 16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright 17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the 18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution. 19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors 20 * 3. 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 21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission. 22 * without specific prior written permission.
23 * 23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 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 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 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 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 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 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE. 34 * SUCH DAMAGE.
35 * 35 *
36 * @(#)param.h 8.3 (Berkeley) 4/4/95 36 * @(#)param.h 8.3 (Berkeley) 4/4/95
37 */ 37 */
38 38
39#ifndef _SYS_PARAM_H_ 39#ifndef _SYS_PARAM_H_
40#define _SYS_PARAM_H_ 40#define _SYS_PARAM_H_
41 41
42#ifdef _KERNEL_OPT 42#ifdef _KERNEL_OPT
43#include "opt_param.h" 43#include "opt_param.h"
44#endif 44#endif
45 45
46/* 46/*
47 * Historic BSD #defines -- probably will remain untouched for all time. 47 * Historic BSD #defines -- probably will remain untouched for all time.
48 */ 48 */
49#define BSD 199506 /* System version (year & month). */ 49#define BSD 199506 /* System version (year & month). */
50#define BSD4_3 1 50#define BSD4_3 1
51#define BSD4_4 1 51#define BSD4_4 1
52 52
53/* 53/*
54 * #define __NetBSD_Version__ MMmmrrpp00 54 * #define __NetBSD_Version__ MMmmrrpp00
55 * 55 *
56 * M = major version 56 * M = major version
57 * m = minor version; a minor number of 99 indicates current. 57 * m = minor version; a minor number of 99 indicates current.
58 * r = 0 (*) 58 * r = 0 (*)
59 * p = patchlevel 59 * p = patchlevel
60 * 60 *
61 * When new releases are made, src/gnu/usr.bin/groff/tmac/mdoc.local 61 * When new releases are made, src/gnu/usr.bin/groff/tmac/mdoc.local
62 * needs to be updated and the changes sent back to the groff maintainers. 62 * needs to be updated and the changes sent back to the groff maintainers.
63 * 63 *
64 * (*) Up to 2.0I "release" used to be "",A-Z,Z[A-Z] but numeric 64 * (*) Up to 2.0I "release" used to be "",A-Z,Z[A-Z] but numeric
65 * e.g. NetBSD-1.2D = 102040000 ('D' == 4) 65 * e.g. NetBSD-1.2D = 102040000 ('D' == 4)
66 * NetBSD-2.0H (200080000) was changed on 20041001 to: 66 * NetBSD-2.0H (200080000) was changed on 20041001 to:
67 * 2.99.9 (299000900) 67 * 2.99.9 (299000900)
68 */ 68 */
69 69
70#define __NetBSD_Version__ 799006400 /* NetBSD 7.99.64 */ 70#define __NetBSD_Version__ 799006500 /* NetBSD 7.99.65 */
71 71
72#define __NetBSD_Prereq__(M,m,p) (((((M) * 100000000) + \ 72#define __NetBSD_Prereq__(M,m,p) (((((M) * 100000000) + \
73 (m) * 1000000) + (p) * 100) <= __NetBSD_Version__) 73 (m) * 1000000) + (p) * 100) <= __NetBSD_Version__)
74 74
75/* 75/*
76 * Historical NetBSD #define 76 * Historical NetBSD #define
77 * 77 *
78 * NetBSD 1.4 was the last release for which this value was incremented. 78 * NetBSD 1.4 was the last release for which this value was incremented.
79 * The value is now permanently fixed at 199905. It will never be 79 * The value is now permanently fixed at 199905. It will never be
80 * changed again. 80 * changed again.
81 * 81 *
82 * New code must use __NetBSD_Version__ instead, and should not even 82 * New code must use __NetBSD_Version__ instead, and should not even
83 * count on NetBSD being defined. 83 * count on NetBSD being defined.
84 * 84 *
85 */ 85 */
86 86
87#define NetBSD 199905 /* NetBSD version (year & month). */ 87#define NetBSD 199905 /* NetBSD version (year & month). */
88 88
89/* 89/*
90 * There macros determine if we are running in protected mode or not. 90 * There macros determine if we are running in protected mode or not.
91 * _HARDKERNEL: code uses kernel namespace and runs in hw priviledged mode 91 * _HARDKERNEL: code uses kernel namespace and runs in hw priviledged mode
92 * _SOFTKERNEL: code uses kernel namespace but runs without hw priviledges 92 * _SOFTKERNEL: code uses kernel namespace but runs without hw priviledges
93 */ 93 */
94#if defined(_KERNEL) && !defined(_RUMPKERNEL) 94#if defined(_KERNEL) && !defined(_RUMPKERNEL)
95#define _HARDKERNEL 95#define _HARDKERNEL
96#endif 96#endif
97#if defined(_KERNEL) && defined(_RUMPKERNEL) 97#if defined(_KERNEL) && defined(_RUMPKERNEL)
98#define _SOFTKERNEL 98#define _SOFTKERNEL
99#endif 99#endif
100 100
101#include <sys/null.h> 101#include <sys/null.h>
102 102
103#ifndef __ASSEMBLER__ 103#ifndef __ASSEMBLER__
104#include <sys/inttypes.h> 104#include <sys/inttypes.h>
105#include <sys/types.h> 105#include <sys/types.h>
106 106
107/* 107/*
108 * Machine-independent constants (some used in following include files). 108 * Machine-independent constants (some used in following include files).
109 * Redefined constants are from POSIX 1003.1 limits file. 109 * Redefined constants are from POSIX 1003.1 limits file.
110 * 110 *
111 * MAXCOMLEN should be >= sizeof(ac_comm) (see <acct.h>) 111 * MAXCOMLEN should be >= sizeof(ac_comm) (see <acct.h>)
112 * MAXHOSTNAMELEN should be >= (_POSIX_HOST_NAME_MAX + 1) (see <limits.h>) 112 * MAXHOSTNAMELEN should be >= (_POSIX_HOST_NAME_MAX + 1) (see <limits.h>)
113 * MAXLOGNAME should be >= UT_NAMESIZE (see <utmp.h>) 113 * MAXLOGNAME should be >= UT_NAMESIZE (see <utmp.h>)
114 */ 114 */
115#include <sys/syslimits.h> 115#include <sys/syslimits.h>
116 116
117#define MAXCOMLEN 16 /* max command name remembered */ 117#define MAXCOMLEN 16 /* max command name remembered */
118#define MAXINTERP PATH_MAX /* max interpreter file name length */ 118#define MAXINTERP PATH_MAX /* max interpreter file name length */
119/* DEPRECATED: use LOGIN_NAME_MAX instead. */ 119/* DEPRECATED: use LOGIN_NAME_MAX instead. */
120#define MAXLOGNAME (LOGIN_NAME_MAX - 1) /* max login name length */ 120#define MAXLOGNAME (LOGIN_NAME_MAX - 1) /* max login name length */
121#define NCARGS ARG_MAX /* max bytes for an exec function */ 121#define NCARGS ARG_MAX /* max bytes for an exec function */
122#define NGROUPS NGROUPS_MAX /* max number groups */ 122#define NGROUPS NGROUPS_MAX /* max number groups */
123#define NOGROUP 65535 /* marker for empty group set member */ 123#define NOGROUP 65535 /* marker for empty group set member */
124#define MAXHOSTNAMELEN 256 /* max hostname size */ 124#define MAXHOSTNAMELEN 256 /* max hostname size */
125 125
126#ifndef NOFILE 126#ifndef NOFILE
127#define NOFILE OPEN_MAX /* max open files per process */ 127#define NOFILE OPEN_MAX /* max open files per process */
128#endif 128#endif
129#ifndef MAXUPRC /* max simultaneous processes */ 129#ifndef MAXUPRC /* max simultaneous processes */
130#define MAXUPRC CHILD_MAX /* POSIX 1003.1-compliant default */ 130#define MAXUPRC CHILD_MAX /* POSIX 1003.1-compliant default */
131#else 131#else
132#if (MAXUPRC - 0) < CHILD_MAX 132#if (MAXUPRC - 0) < CHILD_MAX
133#error MAXUPRC less than CHILD_MAX. See options(4) for details. 133#error MAXUPRC less than CHILD_MAX. See options(4) for details.
134#endif /* (MAXUPRC - 0) < CHILD_MAX */ 134#endif /* (MAXUPRC - 0) < CHILD_MAX */
135#endif /* !defined(MAXUPRC) */ 135#endif /* !defined(MAXUPRC) */
136 136
137/* Macros for min/max. */ 137/* Macros for min/max. */
138#define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b)) 138#define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
139#define MAX(a,b) ((/*CONSTCOND*/(a)>(b))?(a):(b)) 139#define MAX(a,b) ((/*CONSTCOND*/(a)>(b))?(a):(b))
140 140
141/* More types and definitions used throughout the kernel. */ 141/* More types and definitions used throughout the kernel. */
142#ifdef _KERNEL 142#ifdef _KERNEL
143#include <sys/cdefs.h> 143#include <sys/cdefs.h>
144#include <sys/errno.h> 144#include <sys/errno.h>
145#include <sys/time.h> 145#include <sys/time.h>
146#include <sys/resource.h> 146#include <sys/resource.h>
147#include <sys/ucred.h> 147#include <sys/ucred.h>
148#include <sys/uio.h> 148#include <sys/uio.h>
149#include <uvm/uvm_param.h> 149#include <uvm/uvm_param.h>
150#ifndef NPROC 150#ifndef NPROC
151#define NPROC (20 + 16 * MAXUSERS) 151#define NPROC (20 + 16 * MAXUSERS)
152#endif 152#endif
153#ifndef NTEXT 153#ifndef NTEXT
154#define NTEXT (80 + NPROC / 8) /* actually the object cache */ 154#define NTEXT (80 + NPROC / 8) /* actually the object cache */
155#endif 155#endif
156#ifndef NVNODE 156#ifndef NVNODE
157#define NVNODE (NPROC + NTEXT + 100) 157#define NVNODE (NPROC + NTEXT + 100)
158#define NVNODE_IMPLICIT 158#define NVNODE_IMPLICIT
159#endif 159#endif
160#ifndef VNODE_KMEM_MAXPCT 160#ifndef VNODE_KMEM_MAXPCT
161#define VNODE_KMEM_MAXPCT 60 161#define VNODE_KMEM_MAXPCT 60
162#endif 162#endif
163#ifndef BUFCACHE_VA_MAXPCT 163#ifndef BUFCACHE_VA_MAXPCT
164#define BUFCACHE_VA_MAXPCT 20 164#define BUFCACHE_VA_MAXPCT 20
165#endif 165#endif
166#define VNODE_COST 2048 /* assumed space in bytes */ 166#define VNODE_COST 2048 /* assumed space in bytes */
167#endif /* _KERNEL */ 167#endif /* _KERNEL */
168 168
169/* Signals. */ 169/* Signals. */
170#include <sys/signal.h> 170#include <sys/signal.h>
171 171
172/* Machine type dependent parameters. */ 172/* Machine type dependent parameters. */
173#include <machine/param.h> 173#include <machine/param.h>
174#include <machine/limits.h> 174#include <machine/limits.h>
175 175
176/* pages ("clicks") to disk blocks */ 176/* pages ("clicks") to disk blocks */
177#define ctod(x) ((x) << (PGSHIFT - DEV_BSHIFT)) 177#define ctod(x) ((x) << (PGSHIFT - DEV_BSHIFT))
178#define dtoc(x) ((x) >> (PGSHIFT - DEV_BSHIFT)) 178#define dtoc(x) ((x) >> (PGSHIFT - DEV_BSHIFT))
179 179
180/* bytes to pages */ 180/* bytes to pages */
181#define ctob(x) ((x) << PGSHIFT) 181#define ctob(x) ((x) << PGSHIFT)
182#define btoc(x) (((x) + PGOFSET) >> PGSHIFT) 182#define btoc(x) (((x) + PGOFSET) >> PGSHIFT)
183 183
184/* bytes to disk blocks */ 184/* bytes to disk blocks */
185#define dbtob(x) ((x) << DEV_BSHIFT) 185#define dbtob(x) ((x) << DEV_BSHIFT)
186#define btodb(x) ((x) >> DEV_BSHIFT) 186#define btodb(x) ((x) >> DEV_BSHIFT)
187 187
188#ifndef COHERENCY_UNIT 188#ifndef COHERENCY_UNIT
189#define COHERENCY_UNIT 64 189#define COHERENCY_UNIT 64
190#endif 190#endif
191#ifndef CACHE_LINE_SIZE 191#ifndef CACHE_LINE_SIZE
192#define CACHE_LINE_SIZE 64 192#define CACHE_LINE_SIZE 64
193#endif 193#endif
194#ifndef MAXCPUS 194#ifndef MAXCPUS
195#define MAXCPUS 32 195#define MAXCPUS 32
196#endif 196#endif
197#ifndef MAX_LWP_PER_PROC 197#ifndef MAX_LWP_PER_PROC
198#define MAX_LWP_PER_PROC 8000 198#define MAX_LWP_PER_PROC 8000
199#endif 199#endif
200 200
201/* 201/*
202 * Stack macros. On most architectures, the stack grows down, 202 * Stack macros. On most architectures, the stack grows down,
203 * towards lower addresses; it is the rare architecture where 203 * towards lower addresses; it is the rare architecture where
204 * it grows up, towards higher addresses. 204 * it grows up, towards higher addresses.
205 * 205 *
206 * STACK_GROW and STACK_SHRINK adjust a stack pointer by some 206 * STACK_GROW and STACK_SHRINK adjust a stack pointer by some
207 * size, no questions asked. STACK_ALIGN aligns a stack pointer. 207 * size, no questions asked. STACK_ALIGN aligns a stack pointer.
208 * 208 *
209 * STACK_ALLOC returns a pointer to allocated stack space of 209 * STACK_ALLOC returns a pointer to allocated stack space of
210 * some size; given such a pointer and a size, STACK_MAX gives 210 * some size; given such a pointer and a size, STACK_MAX gives
211 * the maximum (in the "maxsaddr" sense) stack address of the 211 * the maximum (in the "maxsaddr" sense) stack address of the
212 * allocated memory. 212 * allocated memory.
213 */ 213 */
214#if defined(_KERNEL) || defined(__EXPOSE_STACK) 214#if defined(_KERNEL) || defined(__EXPOSE_STACK)
215 215
216#ifndef STACK_ALIGNBYTES 216#ifndef STACK_ALIGNBYTES
217#define STACK_ALIGNBYTES __ALIGNBYTES 217#define STACK_ALIGNBYTES __ALIGNBYTES
218#endif 218#endif
219 219
220#ifdef __MACHINE_STACK_GROWS_UP 220#ifdef __MACHINE_STACK_GROWS_UP
221#define STACK_GROW(sp, _size) (((char *)(void *)(sp)) + (_size)) 221#define STACK_GROW(sp, _size) (((char *)(void *)(sp)) + (_size))
222#define STACK_SHRINK(sp, _size) (((char *)(void *)(sp)) - (_size)) 222#define STACK_SHRINK(sp, _size) (((char *)(void *)(sp)) - (_size))
223#define STACK_ALIGN(sp, bytes) \ 223#define STACK_ALIGN(sp, bytes) \
224 ((char *)((((unsigned long)(sp)) + (bytes)) & ~(bytes))) 224 ((char *)((((unsigned long)(sp)) + (bytes)) & ~(bytes)))
225#define STACK_ALLOC(sp, _size) ((char *)(void *)(sp)) 225#define STACK_ALLOC(sp, _size) ((char *)(void *)(sp))
226#define STACK_MAX(p, _size) (((char *)(void *)(p)) + (_size)) 226#define STACK_MAX(p, _size) (((char *)(void *)(p)) + (_size))
227#else 227#else
228#define STACK_GROW(sp, _size) (((char *)(void *)(sp)) - (_size)) 228#define STACK_GROW(sp, _size) (((char *)(void *)(sp)) - (_size))
229#define STACK_SHRINK(sp, _size) (((char *)(void *)(sp)) + (_size)) 229#define STACK_SHRINK(sp, _size) (((char *)(void *)(sp)) + (_size))
230#define STACK_ALIGN(sp, bytes) \ 230#define STACK_ALIGN(sp, bytes) \
231 ((char *)(((unsigned long)(sp)) & ~(bytes))) 231 ((char *)(((unsigned long)(sp)) & ~(bytes)))
232#define STACK_ALLOC(sp, _size) (((char *)(void *)(sp)) - (_size)) 232#define STACK_ALLOC(sp, _size) (((char *)(void *)(sp)) - (_size))
233#define STACK_MAX(p, _size) ((char *)(void *)(p)) 233#define STACK_MAX(p, _size) ((char *)(void *)(p))
234#endif 234#endif
235#define STACK_LEN_ALIGN(len, bytes) (((len) + (bytes)) & ~(bytes)) 235#define STACK_LEN_ALIGN(len, bytes) (((len) + (bytes)) & ~(bytes))
236 236
237#endif /* defined(_KERNEL) || defined(__EXPOSE_STACK) */ 237#endif /* defined(_KERNEL) || defined(__EXPOSE_STACK) */
238 238
239/* 239/*
240 * Round p (pointer or byte index) up to a correctly-aligned value for all 240 * Round p (pointer or byte index) up to a correctly-aligned value for all
241 * data types (int, long, ...). The result is u_int and must be cast to 241 * data types (int, long, ...). The result is u_int and must be cast to
242 * any desired pointer type. 242 * any desired pointer type.
243 * 243 *
244 * ALIGNED_POINTER is a boolean macro that checks whether an address 244 * ALIGNED_POINTER is a boolean macro that checks whether an address
245 * is valid to fetch data elements of type t from on this architecture. 245 * is valid to fetch data elements of type t from on this architecture.
246 * This does not reflect the optimal alignment, just the possibility 246 * This does not reflect the optimal alignment, just the possibility
247 * (within reasonable limits). 247 * (within reasonable limits).
248 * 248 *
249 */ 249 */
250#define ALIGNBYTES __ALIGNBYTES 250#define ALIGNBYTES __ALIGNBYTES
251#ifndef ALIGN 251#ifndef ALIGN
252#define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) & ~ALIGNBYTES) 252#define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) & ~ALIGNBYTES)
253#endif 253#endif
254#ifndef ALIGNED_POINTER 254#ifndef ALIGNED_POINTER
255#define ALIGNED_POINTER(p,t) ((((uintptr_t)(p)) & (sizeof(t) - 1)) == 0) 255#define ALIGNED_POINTER(p,t) ((((uintptr_t)(p)) & (sizeof(t) - 1)) == 0)
256#endif 256#endif
257 257
258/* 258/*
259 * Historic priority levels. These are meaningless and remain only 259 * Historic priority levels. These are meaningless and remain only
260 * for source compatibility. Do not use in new code. 260 * for source compatibility. Do not use in new code.
261 */ 261 */
262#define PSWP 0 262#define PSWP 0
263#define PVM 4 263#define PVM 4
264#define PINOD 8 264#define PINOD 8
265#define PRIBIO 16 265#define PRIBIO 16
266#define PVFS 20 266#define PVFS 20
267#define PZERO 22 267#define PZERO 22
268#define PSOCK 24 268#define PSOCK 24
269#define PWAIT 32 269#define PWAIT 32
270#define PLOCK 36 270#define PLOCK 36
271#define PPAUSE 40 271#define PPAUSE 40
272#define PUSER 50 272#define PUSER 50
273#define MAXPRI 127 273#define MAXPRI 127
274 274
275#define PCATCH 0x100 /* OR'd with pri for tsleep to check signals */ 275#define PCATCH 0x100 /* OR'd with pri for tsleep to check signals */
276#define PNORELOCK 0x200 /* OR'd with pri for tsleep to not relock */ 276#define PNORELOCK 0x200 /* OR'd with pri for tsleep to not relock */
277 277
278/* 278/*
279 * New priority levels. 279 * New priority levels.
280 */ 280 */
281#define PRI_COUNT 224 281#define PRI_COUNT 224
282#define PRI_NONE (-1) 282#define PRI_NONE (-1)
283 283
284#define PRI_KERNEL_RT 192 284#define PRI_KERNEL_RT 192
285#define NPRI_KERNEL_RT 32 285#define NPRI_KERNEL_RT 32
286#define MAXPRI_KERNEL_RT (PRI_KERNEL_RT + NPRI_KERNEL_RT - 1) 286#define MAXPRI_KERNEL_RT (PRI_KERNEL_RT + NPRI_KERNEL_RT - 1)
287 287
288#define PRI_USER_RT 128 288#define PRI_USER_RT 128
289#define NPRI_USER_RT 64 289#define NPRI_USER_RT 64
290#define MAXPRI_USER_RT (PRI_USER_RT + NPRI_USER_RT - 1) 290#define MAXPRI_USER_RT (PRI_USER_RT + NPRI_USER_RT - 1)
291 291
292#define PRI_KTHREAD 96 292#define PRI_KTHREAD 96
293#define NPRI_KTHREAD 32 293#define NPRI_KTHREAD 32
294#define MAXPRI_KTHREAD (PRI_KTHREAD + NPRI_KTHREAD - 1) 294#define MAXPRI_KTHREAD (PRI_KTHREAD + NPRI_KTHREAD - 1)
295 295
296#define PRI_KERNEL 64 296#define PRI_KERNEL 64
297#define NPRI_KERNEL 32 297#define NPRI_KERNEL 32
298#define MAXPRI_KERNEL (PRI_KERNEL + NPRI_KERNEL - 1) 298#define MAXPRI_KERNEL (PRI_KERNEL + NPRI_KERNEL - 1)
299 299
300#define PRI_USER 0 300#define PRI_USER 0
301#define NPRI_USER 64 301#define NPRI_USER 64
302#define MAXPRI_USER (PRI_USER + NPRI_USER - 1) 302#define MAXPRI_USER (PRI_USER + NPRI_USER - 1)
303 303
304/* Priority range used by POSIX real-time features */ 304/* Priority range used by POSIX real-time features */
305#define SCHED_PRI_MIN 0 305#define SCHED_PRI_MIN 0
306#define SCHED_PRI_MAX 63 306#define SCHED_PRI_MAX 63
307 307
308/* 308/*
309 * Kernel thread priorities. 309 * Kernel thread priorities.
310 */ 310 */
311#define PRI_SOFTSERIAL MAXPRI_KERNEL_RT 311#define PRI_SOFTSERIAL MAXPRI_KERNEL_RT
312#define PRI_SOFTNET (MAXPRI_KERNEL_RT - schedppq * 1) 312#define PRI_SOFTNET (MAXPRI_KERNEL_RT - schedppq * 1)
313#define PRI_SOFTBIO (MAXPRI_KERNEL_RT - schedppq * 2) 313#define PRI_SOFTBIO (MAXPRI_KERNEL_RT - schedppq * 2)
314#define PRI_SOFTCLOCK (MAXPRI_KERNEL_RT - schedppq * 3) 314#define PRI_SOFTCLOCK (MAXPRI_KERNEL_RT - schedppq * 3)
315 315
316#define PRI_XCALL MAXPRI_KTHREAD 316#define PRI_XCALL MAXPRI_KTHREAD
317#define PRI_PGDAEMON (MAXPRI_KTHREAD - schedppq * 1) 317#define PRI_PGDAEMON (MAXPRI_KTHREAD - schedppq * 1)
318#define PRI_VM (MAXPRI_KTHREAD - schedppq * 2) 318#define PRI_VM (MAXPRI_KTHREAD - schedppq * 2)
319#define PRI_IOFLUSH (MAXPRI_KTHREAD - schedppq * 3) 319#define PRI_IOFLUSH (MAXPRI_KTHREAD - schedppq * 3)
320#define PRI_BIO (MAXPRI_KTHREAD - schedppq * 4) 320#define PRI_BIO (MAXPRI_KTHREAD - schedppq * 4)
321 321
322#define PRI_IDLE PRI_USER 322#define PRI_IDLE PRI_USER
323 323
324/* 324/*
325 * Miscellaneous. 325 * Miscellaneous.
326 */ 326 */
327#define NBPW sizeof(int) /* number of bytes per word (integer) */ 327#define NBPW sizeof(int) /* number of bytes per word (integer) */
328 328
329#define CMASK 022 /* default file mask: S_IWGRP|S_IWOTH */ 329#define CMASK 022 /* default file mask: S_IWGRP|S_IWOTH */
330#define NODEV (dev_t)(-1) /* non-existent device */ 330#define NODEV (dev_t)(-1) /* non-existent device */
331 331
332/* 332/*
333 * File system parameters and macros. 333 * File system parameters and macros.
334 * 334 *
335 * The file system is made out of blocks of at most MAXBSIZE units, with 335 * The file system is made out of blocks of at most MAXBSIZE units, with
336 * smaller units (fragments) only in the last direct block. MAXBSIZE 336 * smaller units (fragments) only in the last direct block. MAXBSIZE
337 * primarily determines the size of buffers in the buffer pool. It may be 337 * primarily determines the size of buffers in the buffer pool. It may be
338 * made larger without any effect on existing file systems; however making 338 * made larger without any effect on existing file systems; however making
339 * it smaller may make some file systems unmountable. 339 * it smaller may make some file systems unmountable.
340 */ 340 */
341#ifndef MAXBSIZE /* XXX */ 341#ifndef MAXBSIZE /* XXX */
342#define MAXBSIZE MAXPHYS 342#define MAXBSIZE MAXPHYS
343#endif 343#endif
344#define MAXFRAG 8 344#define MAXFRAG 8
345 345
346/* 346/*
347 * MAXPATHLEN defines the longest permissible path length after expanding 347 * MAXPATHLEN defines the longest permissible path length after expanding
348 * symbolic links. It is used to allocate a temporary buffer from the buffer 348 * symbolic links. It is used to allocate a temporary buffer from the buffer
349 * pool in which to do the name expansion, hence should be a power of two, 349 * pool in which to do the name expansion, hence should be a power of two,
350 * and must be less than or equal to MAXBSIZE. MAXSYMLINKS defines the 350 * and must be less than or equal to MAXBSIZE. MAXSYMLINKS defines the
351 * maximum number of symbolic links that may be expanded in a path name. 351 * maximum number of symbolic links that may be expanded in a path name.
352 * It should be set high enough to allow all legitimate uses, but halt 352 * It should be set high enough to allow all legitimate uses, but halt
353 * infinite loops reasonably quickly. 353 * infinite loops reasonably quickly.
354 * 354 *
355 * MAXSYMLINKS should be >= _POSIX_SYMLOOP_MAX (see <limits.h>) 355 * MAXSYMLINKS should be >= _POSIX_SYMLOOP_MAX (see <limits.h>)
356 */ 356 */
357#define MAXPATHLEN PATH_MAX 357#define MAXPATHLEN PATH_MAX
358#define MAXSYMLINKS 32 358#define MAXSYMLINKS 32
359 359
360/* 360/*
361 * This is the maximum individual filename component length enforced by 361 * This is the maximum individual filename component length enforced by
362 * namei. Filesystems cannot exceed this limit. The upper bound for that 362 * namei. Filesystems cannot exceed this limit. The upper bound for that
363 * limit is NAME_MAX. We don't bump it for now, for compatibility with 363 * limit is NAME_MAX. We don't bump it for now, for compatibility with
364 * old binaries during the time where MAXPATHLEN was 511 and NAME_MAX was 364 * old binaries during the time where MAXPATHLEN was 511 and NAME_MAX was
365 * 255 365 * 255
366 */ 366 */
367#define KERNEL_NAME_MAX 255 367#define KERNEL_NAME_MAX 255
368 368
369/* Bit map related macros. */ 369/* Bit map related macros. */
370#define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY)) 370#define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
371#define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY))) 371#define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
372#define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY))) 372#define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
373#define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0) 373#define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
374 374
375/* Macros for counting and rounding. */ 375/* Macros for counting and rounding. */
376#ifndef howmany 376#ifndef howmany
377#define howmany(x, y) (((x)+((y)-1))/(y)) 377#define howmany(x, y) (((x)+((y)-1))/(y))
378#endif 378#endif
379#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) 379#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
380#define rounddown(x,y) (((x)/(y))*(y)) 380#define rounddown(x,y) (((x)/(y))*(y))
381 381
382/* 382/*
383 * Rounding to powers of two. The naive definitions of roundup2 and 383 * Rounding to powers of two. The naive definitions of roundup2 and
384 * rounddown2, 384 * rounddown2,
385 * 385 *
386 * #define roundup2(x,m) (((x) + ((m) - 1)) & ~((m) - 1)) 386 * #define roundup2(x,m) (((x) + ((m) - 1)) & ~((m) - 1))
387 * #define rounddown2(x,m) ((x) & ~((m) - 1)), 387 * #define rounddown2(x,m) ((x) & ~((m) - 1)),
388 * 388 *
389 * exhibit a quirk of integer arithmetic in C because the complement 389 * exhibit a quirk of integer arithmetic in C because the complement
390 * happens in the type of m, not in the type of x. So if unsigned int 390 * happens in the type of m, not in the type of x. So if unsigned int
391 * is 32-bit, and m is an unsigned int while x is a uint64_t, then 391 * is 32-bit, and m is an unsigned int while x is a uint64_t, then
392 * roundup2 and rounddown2 would have the unintended effect of clearing 392 * roundup2 and rounddown2 would have the unintended effect of clearing
393 * the upper 32 bits of the result(!). These definitions avoid the 393 * the upper 32 bits of the result(!). These definitions avoid the
394 * pitfalls of C arithmetic depending on the types of x and m, and 394 * pitfalls of C arithmetic depending on the types of x and m, and
395 * additionally avoid multiply evaluating their arguments. 395 * additionally avoid multiply evaluating their arguments.
396 */ 396 */
397#define roundup2(x,m) ((((x) - 1) | ((m) - 1)) + 1) 397#define roundup2(x,m) ((((x) - 1) | ((m) - 1)) + 1)
398#define rounddown2(x,m) ((x) & ~((__typeof__(x))((m) - 1))) 398#define rounddown2(x,m) ((x) & ~((__typeof__(x))((m) - 1)))
399 399
400#define powerof2(x) ((((x)-1)&(x))==0) 400#define powerof2(x) ((((x)-1)&(x))==0)
401 401
402/* 402/*
403 * Constants for setting the parameters of the kernel memory allocator. 403 * Constants for setting the parameters of the kernel memory allocator.
404 * 404 *
405 * 2 ** MINBUCKET is the smallest unit of memory that will be 405 * 2 ** MINBUCKET is the smallest unit of memory that will be
406 * allocated. It must be at least large enough to hold a pointer. 406 * allocated. It must be at least large enough to hold a pointer.
407 * 407 *
408 * Units of memory less or equal to MAXALLOCSAVE will permanently 408 * Units of memory less or equal to MAXALLOCSAVE will permanently
409 * allocate physical memory; requests for these size pieces of 409 * allocate physical memory; requests for these size pieces of
410 * memory are quite fast. Allocations greater than MAXALLOCSAVE must 410 * memory are quite fast. Allocations greater than MAXALLOCSAVE must
411 * always allocate and free physical memory; requests for these 411 * always allocate and free physical memory; requests for these
412 * size allocations should be done infrequently as they will be slow. 412 * size allocations should be done infrequently as they will be slow.
413 * 413 *
414 * Constraints: NBPG <= MAXALLOCSAVE <= 2 ** (MINBUCKET + 14), and 414 * Constraints: NBPG <= MAXALLOCSAVE <= 2 ** (MINBUCKET + 14), and
415 * MAXALLOCSAVE must be a power of two. 415 * MAXALLOCSAVE must be a power of two.
416 */ 416 */
417#ifdef _LP64 417#ifdef _LP64
418#define MINBUCKET 5 /* 5 => min allocation of 32 bytes */ 418#define MINBUCKET 5 /* 5 => min allocation of 32 bytes */
419#else 419#else
420#define MINBUCKET 4 /* 4 => min allocation of 16 bytes */ 420#define MINBUCKET 4 /* 4 => min allocation of 16 bytes */
421#endif 421#endif
422#define MAXALLOCSAVE (2 * NBPG) 422#define MAXALLOCSAVE (2 * NBPG)
423 423
424/* 424/*
425 * Scale factor for scaled integers used to count %cpu time and load avgs. 425 * Scale factor for scaled integers used to count %cpu time and load avgs.
426 * 426 *
427 * The number of CPU `tick's that map to a unique `%age' can be expressed 427 * The number of CPU `tick's that map to a unique `%age' can be expressed
428 * by the formula (1 / (2 ^ (FSHIFT - 11))). The maximum load average that 428 * by the formula (1 / (2 ^ (FSHIFT - 11))). The maximum load average that
429 * can be calculated (assuming 32 bits) can be closely approximated using 429 * can be calculated (assuming 32 bits) can be closely approximated using
430 * the formula (2 ^ (2 * (16 - FSHIFT))) for (FSHIFT < 15). 430 * the formula (2 ^ (2 * (16 - FSHIFT))) for (FSHIFT < 15).
431 * 431 *
432 * For the scheduler to maintain a 1:1 mapping of CPU `tick' to `%age', 432 * For the scheduler to maintain a 1:1 mapping of CPU `tick' to `%age',
433 * FSHIFT must be at least 11; this gives us a maximum load avg of ~1024. 433 * FSHIFT must be at least 11; this gives us a maximum load avg of ~1024.
434 */ 434 */
435#define FSHIFT 11 /* bits to right of fixed binary point */ 435#define FSHIFT 11 /* bits to right of fixed binary point */
436#define FSCALE (1<<FSHIFT) 436#define FSCALE (1<<FSHIFT)
437 437
438/* 438/*
439 * The time for a process to be blocked before being very swappable. 439 * The time for a process to be blocked before being very swappable.
440 * This is a number of seconds which the system takes as being a non-trivial 440 * This is a number of seconds which the system takes as being a non-trivial
441 * amount of real time. You probably shouldn't change this; 441 * amount of real time. You probably shouldn't change this;
442 * it is used in subtle ways (fractions and multiples of it are, that is, like 442 * it is used in subtle ways (fractions and multiples of it are, that is, like
443 * half of a ``long time'', almost a long time, etc.) 443 * half of a ``long time'', almost a long time, etc.)
444 * It is related to human patience and other factors which don't really 444 * It is related to human patience and other factors which don't really
445 * change over time. 445 * change over time.
446 */ 446 */
447#define MAXSLP 20 447#define MAXSLP 20
448 448
449/* 449/*
450 * Defaults for Unified Buffer Cache parameters. 450 * Defaults for Unified Buffer Cache parameters.
451 * These may be overridden in <machine/param.h>. 451 * These may be overridden in <machine/param.h>.
452 */ 452 */
453 453
454#ifndef UBC_WINSHIFT 454#ifndef UBC_WINSHIFT
455#define UBC_WINSHIFT 13 455#define UBC_WINSHIFT 13
456#endif 456#endif
457#ifndef UBC_NWINS 457#ifndef UBC_NWINS
458#define UBC_NWINS 1024 458#define UBC_NWINS 1024
459#endif 459#endif
460 460
461#ifdef _KERNEL 461#ifdef _KERNEL
462/* 462/*
463 * macro to convert from milliseconds to hz without integer overflow 463 * macro to convert from milliseconds to hz without integer overflow
464 * Default version using only 32bits arithmetics. 464 * Default version using only 32bits arithmetics.
465 * 64bit port can define 64bit version in their <machine/param.h> 465 * 64bit port can define 64bit version in their <machine/param.h>
466 * 0x20000 is safe for hz < 20000 466 * 0x20000 is safe for hz < 20000
467 */ 467 */
468#ifndef mstohz 468#ifndef mstohz
469#define mstohz(ms) \ 469#define mstohz(ms) \
470 (__predict_false((ms) >= 0x20000) ? \ 470 (__predict_false((ms) >= 0x20000) ? \
471 ((ms +0u) / 1000u) * hz : \ 471 ((ms +0u) / 1000u) * hz : \
472 ((ms +0u) * hz) / 1000u) 472 ((ms +0u) * hz) / 1000u)
473#endif 473#endif
474#ifndef hztoms 474#ifndef hztoms
475#define hztoms(t) \ 475#define hztoms(t) \
476 (__predict_false((t) >= 0x20000) ? \ 476 (__predict_false((t) >= 0x20000) ? \
477 ((t +0u) / hz) * 1000u : \ 477 ((t +0u) / hz) * 1000u : \
478 ((t +0u) * 1000u) / hz) 478 ((t +0u) * 1000u) / hz)
479#endif 479#endif
480 480
481extern const int schedppq; 481extern const int schedppq;
482extern size_t coherency_unit; 482extern size_t coherency_unit;
483 483
484#endif /* _KERNEL */ 484#endif /* _KERNEL */
485 485
486/* 486/*
487 * Minimum alignment of "struct lwp" needed by the architecture. 487 * Minimum alignment of "struct lwp" needed by the architecture.
488 * This counts when packing a lock byte into a word alongside a 488 * This counts when packing a lock byte into a word alongside a
489 * pointer to an LWP. 489 * pointer to an LWP.
490 */ 490 */
491#ifndef MIN_LWP_ALIGNMENT 491#ifndef MIN_LWP_ALIGNMENT
492#define MIN_LWP_ALIGNMENT 32 492#define MIN_LWP_ALIGNMENT 32
493#endif 493#endif
494#endif /* !__ASSEMBLER__ */ 494#endif /* !__ASSEMBLER__ */
495 495
496#endif /* !_SYS_PARAM_H_ */ 496#endif /* !_SYS_PARAM_H_ */