vnode_if.sh revision 1.72 1 1.1 mycroft #!/bin/sh -
2 1.9 cgd copyright="\
3 1.2 gwr /*
4 1.16 fvdl * Copyright (c) 1992, 1993, 1994, 1995
5 1.2 gwr * The Regents of the University of California. All rights reserved.
6 1.2 gwr *
7 1.2 gwr * Redistribution and use in source and binary forms, with or without
8 1.2 gwr * modification, are permitted provided that the following conditions
9 1.2 gwr * are met:
10 1.2 gwr * 1. Redistributions of source code must retain the above copyright
11 1.2 gwr * notice, this list of conditions and the following disclaimer.
12 1.2 gwr * 2. Redistributions in binary form must reproduce the above copyright
13 1.2 gwr * notice, this list of conditions and the following disclaimer in the
14 1.2 gwr * documentation and/or other materials provided with the distribution.
15 1.33 agc * 3. Neither the name of the University nor the names of its contributors
16 1.2 gwr * may be used to endorse or promote products derived from this software
17 1.2 gwr * without specific prior written permission.
18 1.2 gwr *
19 1.18 christos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS \`\`AS IS'' AND
20 1.2 gwr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.2 gwr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.2 gwr * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.2 gwr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.2 gwr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.2 gwr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.2 gwr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.2 gwr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.2 gwr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.2 gwr * SUCH DAMAGE.
30 1.2 gwr */
31 1.9 cgd "
32 1.72 thorpej SCRIPT_ID='$NetBSD: vnode_if.sh,v 1.72 2021/10/20 03:08:18 thorpej Exp $'
33 1.1 mycroft
34 1.1 mycroft # Script to produce VFS front-end sugar.
35 1.1 mycroft #
36 1.1 mycroft # usage: vnode_if.sh srcfile
37 1.1 mycroft # (where srcfile is currently /sys/kern/vnode_if.src)
38 1.1 mycroft #
39 1.1 mycroft
40 1.1 mycroft if [ $# -ne 1 ] ; then
41 1.1 mycroft echo 'usage: vnode_if.sh srcfile'
42 1.1 mycroft exit 1
43 1.1 mycroft fi
44 1.2 gwr
45 1.9 cgd # Name and revision of the source file.
46 1.2 gwr src=$1
47 1.9 cgd SRC_ID=`head -1 $src | sed -e 's/.*\$\(.*\)\$.*/\1/'`
48 1.1 mycroft
49 1.1 mycroft # Names of the created files.
50 1.2 gwr out_c=vnode_if.c
51 1.51 pooka out_rumpc=../rump/librump/rumpvfs/rumpvnode_if.c
52 1.9 cgd out_h=../sys/vnode_if.h
53 1.50 pooka out_rumph=../rump/include/rump/rumpvnode_if.h
54 1.2 gwr
55 1.52 pooka # generate VNODE_LOCKDEBUG checks (not fully functional)
56 1.52 pooka lockdebug=0
57 1.52 pooka
58 1.2 gwr # Awk program (must support nawk extensions)
59 1.2 gwr # Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
60 1.2 gwr awk=${AWK:-awk}
61 1.2 gwr
62 1.2 gwr # Does this awk have a "toupper" function? (i.e. is it GNU awk)
63 1.2 gwr isgawk=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
64 1.2 gwr
65 1.2 gwr # If this awk does not define "toupper" then define our own.
66 1.2 gwr if [ "$isgawk" = TRUE ] ; then
67 1.2 gwr # GNU awk provides it.
68 1.2 gwr toupper=
69 1.2 gwr else
70 1.2 gwr # Provide our own toupper()
71 1.2 gwr toupper='
72 1.2 gwr function toupper(str) {
73 1.2 gwr _toupper_cmd = "echo "str" |tr a-z A-Z"
74 1.2 gwr _toupper_cmd | getline _toupper_str;
75 1.2 gwr close(_toupper_cmd);
76 1.2 gwr return _toupper_str;
77 1.2 gwr }'
78 1.2 gwr fi
79 1.1 mycroft
80 1.2 gwr #
81 1.2 gwr # This is the common part of all awk programs that read $src
82 1.2 gwr # This parses the input for one function into the arrays:
83 1.2 gwr # argdir, argtype, argname, willrele
84 1.2 gwr # and calls "doit()" to generate output for the function.
85 1.2 gwr #
86 1.2 gwr # Input to this parser is pre-processed slightly by sed
87 1.2 gwr # so this awk parser doesn't have to work so hard. The
88 1.2 gwr # changes done by the sed pre-processing step are:
89 1.71 andvar # insert a space between * and pointer name
90 1.2 gwr # replace semicolons with spaces
91 1.2 gwr #
92 1.2 gwr sed_prep='s:\*\([^\*/]\):\* \1:g
93 1.2 gwr s/;/ /'
94 1.2 gwr awk_parser='
95 1.2 gwr # Comment line
96 1.2 gwr /^#/ { next; }
97 1.2 gwr # First line of description
98 1.2 gwr /^vop_/ {
99 1.56 pooka name=$1;
100 1.60 hannken args_name=$1;
101 1.2 gwr argc=0;
102 1.72 thorpej have_context=0;
103 1.72 thorpej is_context=0;
104 1.72 thorpej ncontext=0;
105 1.44 pooka willmake=-1;
106 1.65 hannken fstrans="";
107 1.72 thorpej do_pre="";
108 1.72 thorpej do_post="";
109 1.2 gwr next;
110 1.2 gwr }
111 1.2 gwr # Last line of description
112 1.2 gwr /^}/ {
113 1.2 gwr doit();
114 1.2 gwr next;
115 1.2 gwr }
116 1.2 gwr # Middle lines of description
117 1.2 gwr {
118 1.60 hannken if ($1 == "VERSION") {
119 1.60 hannken args_name=args_name "_v" $2;
120 1.60 hannken next;
121 1.65 hannken } else if ($1 ~ "^FSTRANS=") {
122 1.65 hannken fstrans = $1;
123 1.65 hannken sub("FSTRANS=", "", fstrans);
124 1.62 hannken next;
125 1.72 thorpej } else if ($1 ~ "^PRE=") {
126 1.72 thorpej do_pre = $1;
127 1.72 thorpej sub("PRE=", "", do_pre);
128 1.72 thorpej next;
129 1.72 thorpej } else if ($1 ~ "^POST=") {
130 1.72 thorpej do_post = $1;
131 1.72 thorpej sub("POST=", "", do_post);
132 1.72 thorpej next;
133 1.60 hannken }
134 1.60 hannken
135 1.72 thorpej if ($1 == "CONTEXT") {
136 1.72 thorpej # CONTEXT require PRE and POST handlers.
137 1.72 thorpej if (do_pre == "" || do_post == "")
138 1.72 thorpej next;
139 1.72 thorpej is_context=1;
140 1.72 thorpej have_context=1;
141 1.72 thorpej } else {
142 1.72 thorpej if (have_context) {
143 1.72 thorpej # CONTEXT members must come at the end of
144 1.72 thorpej # the args structure, so everything else
145 1.72 thorpej # is ignored.
146 1.72 thorpej next;
147 1.72 thorpej }
148 1.72 thorpej argdir[argc] = $1;
149 1.72 thorpej }
150 1.72 thorpej i=2;
151 1.35 thorpej
152 1.72 thorpej if (is_context == 0) {
153 1.72 thorpej if ($2 == "LOCKED=YES") {
154 1.72 thorpej lockstate[argc] = 1;
155 1.72 thorpej i++;
156 1.72 thorpej } else if ($2 == "LOCKED=NO") {
157 1.72 thorpej lockstate[argc] = 0;
158 1.72 thorpej i++;
159 1.72 thorpej } else
160 1.72 thorpej lockstate[argc] = -1;
161 1.72 thorpej
162 1.72 thorpej if ($2 == "WILLRELE" ||
163 1.72 thorpej $3 == "WILLRELE") {
164 1.72 thorpej willrele[argc] = 1;
165 1.72 thorpej i++;
166 1.72 thorpej } else if ($2 == "WILLPUT" ||
167 1.72 thorpej $3 == "WILLPUT") {
168 1.72 thorpej willrele[argc] = 3;
169 1.72 thorpej i++;
170 1.72 thorpej } else
171 1.72 thorpej willrele[argc] = 0;
172 1.72 thorpej
173 1.72 thorpej if ($2 == "WILLMAKE") {
174 1.72 thorpej willmake=argc;
175 1.72 thorpej i++;
176 1.72 thorpej }
177 1.72 thorpej if (argc == 0 && fstrans == "") {
178 1.72 thorpej if (lockstate[0] == 1)
179 1.72 thorpej fstrans = "NO";
180 1.72 thorpej else
181 1.72 thorpej fstrans = "YES";
182 1.72 thorpej }
183 1.65 hannken }
184 1.44 pooka
185 1.50 pooka # XXX: replace non-portable types for rump. We should really
186 1.50 pooka # nuke the types from the kernel, but that is a battle for
187 1.50 pooka # another day.
188 1.50 pooka at = $i;
189 1.56 pooka if (rump) {
190 1.50 pooka if (at == "vm_prot_t")
191 1.50 pooka at = "int";
192 1.50 pooka if (at == "voff_t")
193 1.50 pooka at = "off_t";
194 1.56 pooka if (at == "kauth_cred_t")
195 1.56 pooka at = "struct kauth_cred *"
196 1.59 pooka if (at == "daddr_t")
197 1.59 pooka at = "int64_t"
198 1.50 pooka }
199 1.72 thorpej argtype[argc + ncontext] = at;
200 1.50 pooka i++;
201 1.2 gwr while (i < NF) {
202 1.72 thorpej argtype[argc + ncontext] = argtype[argc + ncontext]" "$i;
203 1.2 gwr i++;
204 1.2 gwr }
205 1.72 thorpej argname[argc + ncontext] = $i;
206 1.72 thorpej if (is_context)
207 1.72 thorpej ncontext++;
208 1.72 thorpej else
209 1.72 thorpej argc++;
210 1.2 gwr next;
211 1.2 gwr }
212 1.2 gwr '
213 1.1 mycroft
214 1.15 thorpej # This is put before the copyright on each generated file.
215 1.9 cgd warning="\
216 1.15 thorpej /* @NetBSD@ */
217 1.15 thorpej
218 1.1 mycroft /*
219 1.37 perry * Warning: DO NOT EDIT! This file is automatically generated!
220 1.2 gwr * (Modifications made here may easily be lost!)
221 1.1 mycroft *
222 1.9 cgd * Created from the file:
223 1.9 cgd * ${SRC_ID}
224 1.9 cgd * by the script:
225 1.2 gwr * ${SCRIPT_ID}
226 1.1 mycroft */
227 1.36 perry "
228 1.2 gwr
229 1.7 cgd # This is to satisfy McKusick (get rid of evil spaces 8^)
230 1.7 cgd anal_retentive='s:\([^/]\*\) :\1:g'
231 1.2 gwr
232 1.50 pooka do_hfile () {
233 1.2 gwr #
234 1.2 gwr # Redirect stdout to the H file.
235 1.2 gwr #
236 1.50 pooka echo "$0: Creating $1" 1>&2
237 1.50 pooka exec > $1
238 1.50 pooka rump=$2
239 1.1 mycroft
240 1.2 gwr # Begin stuff
241 1.50 pooka if [ -z "${rump}" ]; then
242 1.50 pooka SYS='SYS_'
243 1.50 pooka else
244 1.50 pooka SYS='RUMP_RUMP'
245 1.50 pooka fi
246 1.38 perry echo -n "$warning" | sed -e 's/\$//g;s/@/\$/g;s/ $//'
247 1.9 cgd echo ""
248 1.9 cgd echo -n "$copyright"
249 1.10 mikel echo ''
250 1.50 pooka echo "#ifndef _${SYS}VNODE_IF_H_"
251 1.50 pooka echo "#define _${SYS}VNODE_IF_H_"
252 1.52 pooka if [ ${lockdebug} -ne 0 ] ; then
253 1.52 pooka echo ''
254 1.52 pooka echo '#ifdef _KERNEL_OPT'
255 1.52 pooka echo '#include "opt_vnode_lockdebug.h"'
256 1.52 pooka echo '#endif /* _KERNEL_OPT */'
257 1.52 pooka fi
258 1.56 pooka [ -z "${rump}" ] && echo "
259 1.56 pooka extern const struct vnodeop_desc ${rump}vop_default_desc;"
260 1.56 pooka echo
261 1.1 mycroft
262 1.2 gwr # Body stuff
263 1.2 gwr # This awk program needs toupper() so define it if necessary.
264 1.50 pooka sed -e "$sed_prep" $src | $awk -v rump=${rump} "$toupper"'
265 1.2 gwr function doit() {
266 1.56 pooka name = rump name
267 1.2 gwr # Declare arg struct, descriptor.
268 1.56 pooka if (!rump) {
269 1.56 pooka printf("\n#define %s_DESCOFFSET %d\n",
270 1.56 pooka toupper(name), vop_offset++);
271 1.60 hannken printf("struct %s_args {\n", args_name);
272 1.56 pooka printf("\tconst struct vnodeop_desc * a_desc;\n");
273 1.56 pooka for (i=0; i<argc; i++) {
274 1.56 pooka printf("\t%s a_%s;\n", argtype[i], argname[i]);
275 1.56 pooka }
276 1.72 thorpej for (i=0; i<ncontext; i++) {
277 1.72 thorpej printf("\t%s ctx_%s;\n", argtype[argc+i], \
278 1.72 thorpej argname[argc+i]);
279 1.72 thorpej }
280 1.56 pooka printf("};\n");
281 1.56 pooka printf("extern const struct vnodeop_desc %s_desc;\n", name);
282 1.1 mycroft }
283 1.8 chopps # Prototype it.
284 1.20 thorpej protoarg = sprintf("int %s(", toupper(name));
285 1.8 chopps protolen = length(protoarg);
286 1.8 chopps printf("%s", protoarg);
287 1.8 chopps for (i=0; i<argc; i++) {
288 1.8 chopps protoarg = sprintf("%s", argtype[i]);
289 1.8 chopps if (i < (argc-1)) protoarg = (protoarg ", ");
290 1.8 chopps arglen = length(protoarg);
291 1.8 chopps if ((protolen + arglen) > 77) {
292 1.8 chopps protoarg = ("\n " protoarg);
293 1.8 chopps arglen += 4;
294 1.8 chopps protolen = 0;
295 1.8 chopps }
296 1.8 chopps printf("%s", protoarg);
297 1.8 chopps protolen += arglen;
298 1.8 chopps }
299 1.39 thorpej printf(");\n");
300 1.2 gwr }
301 1.2 gwr BEGIN {
302 1.43 pooka vop_offset = 1; # start at 1, to count the 'default' op
303 1.43 pooka
304 1.56 pooka printf("struct buf;\n");
305 1.56 pooka if (rump) {
306 1.56 pooka printf("struct flock;\n");
307 1.56 pooka printf("struct knote;\n");
308 1.56 pooka printf("struct vm_page;\n");
309 1.70 christos printf("struct acl;\n");
310 1.70 christos printf("\n#include <sys/acl.h>\n");
311 1.56 pooka }
312 1.56 pooka printf("\n#ifndef _KERNEL\n#include <stdbool.h>\n#endif\n");
313 1.56 pooka if (rump)
314 1.56 pooka printf("\n");
315 1.43 pooka }
316 1.43 pooka END {
317 1.56 pooka if (!rump) {
318 1.56 pooka printf("\n#define VNODE_OPS_COUNT\t%d\n", vop_offset);
319 1.56 pooka }
320 1.2 gwr }
321 1.7 cgd '"$awk_parser" | sed -e "$anal_retentive"
322 1.1 mycroft
323 1.2 gwr # End stuff
324 1.10 mikel echo ''
325 1.50 pooka echo "#endif /* !_${SYS}VNODE_IF_H_ */"
326 1.50 pooka }
327 1.50 pooka do_hfile $out_h ''
328 1.50 pooka do_hfile $out_rumph 'rump_'
329 1.1 mycroft
330 1.50 pooka do_cfile () {
331 1.2 gwr #
332 1.2 gwr # Redirect stdout to the C file.
333 1.2 gwr #
334 1.50 pooka echo "$0: Creating $1" 1>&2
335 1.50 pooka exec > $1
336 1.50 pooka rump=$2
337 1.1 mycroft
338 1.2 gwr # Begin stuff
339 1.38 perry echo -n "$warning" | sed -e 's/\$//g;s/@/\$/g;s/ $//'
340 1.9 cgd echo ""
341 1.9 cgd echo -n "$copyright"
342 1.30 lukem echo "
343 1.30 lukem #include <sys/cdefs.h>
344 1.52 pooka __KERNEL_RCSID(0, \"\$NetBSD\$\");"
345 1.52 pooka
346 1.52 pooka [ ${lockdebug} -ne 0 ] && echo && echo '#include "opt_vnode_lockdebug.h"'
347 1.30 lukem
348 1.21 thorpej echo '
349 1.1 mycroft #include <sys/param.h>
350 1.1 mycroft #include <sys/mount.h>
351 1.20 thorpej #include <sys/buf.h>
352 1.72 thorpej #include <sys/fcntl.h>
353 1.1 mycroft #include <sys/vnode.h>
354 1.50 pooka #include <sys/lock.h>'
355 1.62 hannken [ -z "${rump}" ] && echo '#include <sys/fstrans.h>'
356 1.53 pooka [ ! -z "${rump}" ] && echo '#include <rump/rumpvnode_if.h>' \
357 1.61 pooka && echo '#include <rump-sys/kern.h>'
358 1.1 mycroft
359 1.56 pooka if [ -z "${rump}" ] ; then
360 1.56 pooka echo "
361 1.67 hannken enum fst_op { FST_NO, FST_YES, FST_LAZY, FST_TRY };
362 1.65 hannken
363 1.65 hannken static inline int
364 1.65 hannken vop_pre(vnode_t *vp, struct mount **mp, bool *mpsafe, enum fst_op op)
365 1.65 hannken {
366 1.65 hannken int error;
367 1.65 hannken
368 1.65 hannken *mpsafe = (vp->v_vflag & VV_MPSAFE);
369 1.65 hannken
370 1.65 hannken if (!*mpsafe) {
371 1.65 hannken KERNEL_LOCK(1, curlwp);
372 1.65 hannken }
373 1.65 hannken
374 1.67 hannken if (op == FST_YES || op == FST_LAZY || op == FST_TRY) {
375 1.65 hannken for (;;) {
376 1.65 hannken *mp = vp->v_mount;
377 1.65 hannken if (op == FST_TRY) {
378 1.66 hannken error = fstrans_start_nowait(*mp);
379 1.65 hannken if (error) {
380 1.65 hannken if (!*mpsafe) {
381 1.65 hannken KERNEL_UNLOCK_ONE(curlwp);
382 1.65 hannken }
383 1.65 hannken return error;
384 1.65 hannken }
385 1.67 hannken } else if (op == FST_LAZY) {
386 1.67 hannken fstrans_start_lazy(*mp);
387 1.65 hannken } else {
388 1.66 hannken fstrans_start(*mp);
389 1.65 hannken }
390 1.65 hannken if (__predict_true(*mp == vp->v_mount))
391 1.65 hannken break;
392 1.65 hannken fstrans_done(*mp);
393 1.65 hannken }
394 1.65 hannken } else {
395 1.65 hannken *mp = vp->v_mount;
396 1.65 hannken }
397 1.65 hannken
398 1.65 hannken return 0;
399 1.65 hannken }
400 1.65 hannken
401 1.72 thorpej static inline u_quad_t
402 1.72 thorpej vop_pre_get_size(struct vnode *vp)
403 1.72 thorpej {
404 1.72 thorpej mutex_enter(vp->v_interlock);
405 1.72 thorpej KASSERT(vp->v_size != VSIZENOTSET);
406 1.72 thorpej u_quad_t rv = (u_quad_t)vp->v_size;
407 1.72 thorpej mutex_exit(vp->v_interlock);
408 1.72 thorpej
409 1.72 thorpej return rv;
410 1.72 thorpej }
411 1.72 thorpej
412 1.72 thorpej /*
413 1.72 thorpej * VOP_RMDIR(), VOP_REMOVE(), and VOP_RENAME() need special handling
414 1.72 thorpej * because they each drop the caller's references on one or more of
415 1.72 thorpej * their arguments. While there must be an open file descriptor in
416 1.72 thorpej * associated with a vnode in order for knotes to be attached to it,
417 1.72 thorpej * that status could change during the course of the operation. So,
418 1.72 thorpej * for the vnode arguments that are WILLRELE or WILLPUT, we check
419 1.72 thorpej * pre-op if there are registered knotes, take a hold count if so,
420 1.72 thorpej * and post-op release the hold after activating any knotes still
421 1.72 thorpej * associated with the vnode.
422 1.72 thorpej */
423 1.72 thorpej
424 1.72 thorpej #define VOP_POST_KNOTE(thisvp, e, n) \\
425 1.72 thorpej do { \\
426 1.72 thorpej if (__predict_true((e) == 0)) { \\
427 1.72 thorpej /* \\
428 1.72 thorpej * VN_KNOTE() does the VN_KEVENT_INTEREST() \\
429 1.72 thorpej * check for us. \\
430 1.72 thorpej */ \\
431 1.72 thorpej VN_KNOTE((thisvp), (n)); \\
432 1.72 thorpej } \\
433 1.72 thorpej } while (/*CONSTCOND*/0)
434 1.72 thorpej
435 1.72 thorpej #define VOP_POST_KNOTE_HELD(thisvp, e, n) \\
436 1.72 thorpej do { \\
437 1.72 thorpej /* \\
438 1.72 thorpej * We don't perform a VN_KEVENT_INTEREST() check here; it \\
439 1.72 thorpej * was already performed when we did the pre-op work that \\
440 1.72 thorpej * caused the vnode to be held in the first place. \\
441 1.72 thorpej */ \\
442 1.72 thorpej mutex_enter((thisvp)->v_interlock); \\
443 1.72 thorpej if (__predict_true((e) == 0)) { \\
444 1.72 thorpej knote(&(thisvp)->v_klist, (n)); \\
445 1.72 thorpej } \\
446 1.72 thorpej holdrelel((thisvp)); \\
447 1.72 thorpej mutex_exit((thisvp)->v_interlock); \\
448 1.72 thorpej /* \\
449 1.72 thorpej * thisvp might be gone now! Don't touch! \\
450 1.72 thorpej */ \\
451 1.72 thorpej } while (/*CONSTCOND*/0)
452 1.72 thorpej
453 1.72 thorpej #define vop_create_post(ap, e) \\
454 1.72 thorpej VOP_POST_KNOTE((ap)->a_dvp, (e), NOTE_WRITE)
455 1.72 thorpej
456 1.72 thorpej #define vop_mknod_post(ap, e) \\
457 1.72 thorpej VOP_POST_KNOTE((ap)->a_dvp, (e), NOTE_WRITE)
458 1.72 thorpej
459 1.72 thorpej #define vop_setattr_pre(ap) \\
460 1.72 thorpej u_quad_t osize = 0; \\
461 1.72 thorpej long vp_events = \\
462 1.72 thorpej VN_KEVENT_INTEREST((ap)->a_vp, NOTE_ATTRIB | NOTE_EXTEND) \\
463 1.72 thorpej ? NOTE_ATTRIB : 0; \\
464 1.72 thorpej bool check_extend = false; \\
465 1.72 thorpej if (__predict_false(vp_events != 0 && \\
466 1.72 thorpej (ap)->a_vap->va_size != VNOVALSIZE)) { \\
467 1.72 thorpej check_extend = true; \\
468 1.72 thorpej osize = vop_pre_get_size((ap)->a_vp); \\
469 1.72 thorpej }
470 1.72 thorpej
471 1.72 thorpej #define vop_setattr_post(ap, e) \\
472 1.72 thorpej do { \\
473 1.72 thorpej if (__predict_false(vp_events != 0)) { \\
474 1.72 thorpej if (__predict_false(check_extend && \\
475 1.72 thorpej (ap)->a_vap->va_size > osize)) { \\
476 1.72 thorpej vp_events |= NOTE_EXTEND; \\
477 1.72 thorpej } \\
478 1.72 thorpej VOP_POST_KNOTE((ap)->a_vp, (e), vp_events); \\
479 1.72 thorpej } \\
480 1.72 thorpej } while (/*CONSTCOND*/0)
481 1.72 thorpej
482 1.72 thorpej #define vop_setacl_post(ap, e) \\
483 1.72 thorpej VOP_POST_KNOTE((ap)->a_vp, (e), NOTE_ATTRIB)
484 1.72 thorpej
485 1.72 thorpej #define vop_link_post(ap, e) \\
486 1.72 thorpej do { \\
487 1.72 thorpej VOP_POST_KNOTE((ap)->a_dvp, (e), NOTE_WRITE); \\
488 1.72 thorpej VOP_POST_KNOTE((ap)->a_vp, (e), NOTE_LINK); \\
489 1.72 thorpej } while (/*CONSTCOND*/0)
490 1.72 thorpej
491 1.72 thorpej #define vop_mkdir_post(ap, e) \\
492 1.72 thorpej VOP_POST_KNOTE((ap)->a_dvp, (e), NOTE_WRITE | NOTE_LINK)
493 1.72 thorpej
494 1.72 thorpej #define vop_remove_pre_common(ap) \\
495 1.72 thorpej bool post_event_vp = \\
496 1.72 thorpej VN_KEVENT_INTEREST((ap)->a_vp, NOTE_DELETE | NOTE_LINK); \\
497 1.72 thorpej if (__predict_false(post_event_vp)) { \\
498 1.72 thorpej vhold((ap)->a_vp); \\
499 1.72 thorpej }
500 1.72 thorpej
501 1.72 thorpej #define vop_remove_post_common(ap, e, dn, lc) \\
502 1.72 thorpej do { \\
503 1.72 thorpej VOP_POST_KNOTE((ap)->a_dvp, (e), (dn)); \\
504 1.72 thorpej if (__predict_false(post_event_vp)) { \\
505 1.72 thorpej VOP_POST_KNOTE_HELD((ap)->a_vp, (e), \\
506 1.72 thorpej (lc) ? NOTE_LINK : NOTE_DELETE); \\
507 1.72 thorpej } \\
508 1.72 thorpej } while (/*CONSTCOND*/0)
509 1.72 thorpej
510 1.72 thorpej /*
511 1.72 thorpej * One could make the argument that VOP_REMOVE() should send NOTE_LINK
512 1.72 thorpej * on vp if the resulting link count is not zero, but that's not what
513 1.72 thorpej * the documentation says.
514 1.72 thorpej *
515 1.72 thorpej * We could change this easily by passing ap->ctx_vp_new_nlink to
516 1.72 thorpej * vop_remove_post_common().
517 1.72 thorpej */
518 1.72 thorpej #define vop_remove_pre(ap) \\
519 1.72 thorpej vop_remove_pre_common((ap)); \\
520 1.72 thorpej /* \\
521 1.72 thorpej * We will assume that the file being removed is deleted unless \\
522 1.72 thorpej * the file system tells us otherwise by updating vp_new_nlink. \\
523 1.72 thorpej */ \\
524 1.72 thorpej (ap)->ctx_vp_new_nlink = 0;
525 1.72 thorpej
526 1.72 thorpej #define vop_remove_post(ap, e) \\
527 1.72 thorpej vop_remove_post_common((ap), (e), NOTE_WRITE, 0)
528 1.72 thorpej
529 1.72 thorpej #define vop_rmdir_pre(ap) \\
530 1.72 thorpej vop_remove_pre_common(ap)
531 1.72 thorpej
532 1.72 thorpej #define vop_rmdir_post(ap, e) \\
533 1.72 thorpej vop_remove_post_common((ap), (e), NOTE_WRITE | NOTE_LINK, 0)
534 1.72 thorpej
535 1.72 thorpej #define vop_symlink_post(ap, e) \\
536 1.72 thorpej VOP_POST_KNOTE((ap)->a_dvp, (e), NOTE_WRITE)
537 1.72 thorpej
538 1.72 thorpej #define vop_open_post(ap, e) \\
539 1.72 thorpej VOP_POST_KNOTE((ap)->a_vp, (e), NOTE_OPEN)
540 1.72 thorpej
541 1.72 thorpej #define vop_close_post(ap, e) \\
542 1.72 thorpej do { \\
543 1.72 thorpej extern int (**dead_vnodeop_p)(void *); \\
544 1.72 thorpej \\
545 1.72 thorpej /* See the definition of VN_KNOTE() in <sys/vnode.h>. */ \\
546 1.72 thorpej if (__predict_false(VN_KEVENT_INTEREST((ap)->a_vp, \\
547 1.72 thorpej NOTE_CLOSE_WRITE | NOTE_CLOSE) && (e) == 0)) { \\
548 1.72 thorpej struct vnode *thisvp = (ap)->a_vp; \\
549 1.72 thorpej mutex_enter(thisvp->v_interlock); \\
550 1.72 thorpej /* \\
551 1.72 thorpej * Don't send NOTE_CLOSE when closing a vnode that's \\
552 1.72 thorpej * been reclaimed or otherwise revoked; a NOTE_REVOKE \\
553 1.72 thorpej * has already been sent, and this close is effectively \\
554 1.72 thorpej * meaningless from the watcher's perspective. \\
555 1.72 thorpej */ \\
556 1.72 thorpej if (__predict_true(thisvp->v_op != dead_vnodeop_p)) { \\
557 1.72 thorpej knote(&thisvp->v_klist, \\
558 1.72 thorpej ((ap)->a_fflag & FWRITE) \\
559 1.72 thorpej ? NOTE_CLOSE_WRITE : NOTE_CLOSE); \\
560 1.72 thorpej } \\
561 1.72 thorpej mutex_exit(thisvp->v_interlock); \\
562 1.72 thorpej } \\
563 1.72 thorpej } while (/*CONSTCOND*/0)
564 1.72 thorpej
565 1.72 thorpej #define vop_read_post(ap, e) \\
566 1.72 thorpej VOP_POST_KNOTE((ap)->a_vp, (e), NOTE_READ)
567 1.72 thorpej
568 1.72 thorpej #define vop_write_pre(ap) \\
569 1.72 thorpej off_t ooffset = 0, noffset = 0; \\
570 1.72 thorpej u_quad_t osize = 0; \\
571 1.72 thorpej long vp_events = \\
572 1.72 thorpej VN_KEVENT_INTEREST((ap)->a_vp, NOTE_WRITE | NOTE_EXTEND) \\
573 1.72 thorpej ? NOTE_WRITE : 0; \\
574 1.72 thorpej if (__predict_false(vp_events != 0)) { \\
575 1.72 thorpej ooffset = (ap)->a_uio->uio_offset; \\
576 1.72 thorpej osize = vop_pre_get_size((ap)->a_vp); \\
577 1.72 thorpej }
578 1.72 thorpej
579 1.72 thorpej #define vop_write_post(ap, e) \\
580 1.72 thorpej do { \\
581 1.72 thorpej /* \\
582 1.72 thorpej * If any data was written, we'll post an event, even if \\
583 1.72 thorpej * there was an error. \\
584 1.72 thorpej */ \\
585 1.72 thorpej noffset = (ap)->a_uio->uio_offset; \\
586 1.72 thorpej if (__predict_false(vp_events != 0 && noffset > ooffset)) { \\
587 1.72 thorpej if (noffset > osize) { \\
588 1.72 thorpej vp_events |= NOTE_EXTEND; \\
589 1.72 thorpej } \\
590 1.72 thorpej VN_KNOTE((ap)->a_vp, vp_events); \\
591 1.72 thorpej } \\
592 1.72 thorpej } while (/*CONSTCOND*/0)
593 1.72 thorpej
594 1.65 hannken static inline void
595 1.65 hannken vop_post(vnode_t *vp, struct mount *mp, bool mpsafe, enum fst_op op)
596 1.65 hannken {
597 1.65 hannken
598 1.67 hannken if (op == FST_YES || op == FST_LAZY) {
599 1.65 hannken fstrans_done(mp);
600 1.65 hannken }
601 1.65 hannken
602 1.65 hannken if (!mpsafe) {
603 1.65 hannken KERNEL_UNLOCK_ONE(curlwp);
604 1.65 hannken }
605 1.65 hannken }
606 1.65 hannken
607 1.56 pooka const struct vnodeop_desc vop_default_desc = {"
608 1.50 pooka echo ' 0,
609 1.1 mycroft "default",
610 1.1 mycroft 0,
611 1.1 mycroft NULL,
612 1.1 mycroft VDESC_NO_OFFSET,
613 1.1 mycroft VDESC_NO_OFFSET,
614 1.1 mycroft VDESC_NO_OFFSET,
615 1.1 mycroft };
616 1.2 gwr '
617 1.56 pooka fi
618 1.1 mycroft
619 1.2 gwr # Body stuff
620 1.52 pooka sed -e "$sed_prep" $src | $awk -v rump=${rump} -v lockdebug=${lockdebug} '
621 1.2 gwr function do_offset(typematch) {
622 1.2 gwr for (i=0; i<argc; i++) {
623 1.2 gwr if (argtype[i] == typematch) {
624 1.2 gwr printf("\tVOPARG_OFFSETOF(struct %s_args, a_%s),\n",
625 1.60 hannken args_name, argname[i]);
626 1.2 gwr return i;
627 1.2 gwr };
628 1.2 gwr };
629 1.2 gwr print "\tVDESC_NO_OFFSET,";
630 1.2 gwr return -1;
631 1.2 gwr }
632 1.1 mycroft
633 1.56 pooka function offsets() {
634 1.2 gwr # Define offsets array
635 1.56 pooka printf("const int %s_vp_offsets[] = {\n", name);
636 1.2 gwr for (i=0; i<argc; i++) {
637 1.2 gwr if (argtype[i] == "struct vnode *") {
638 1.2 gwr printf ("\tVOPARG_OFFSETOF(struct %s_args,a_%s),\n",
639 1.60 hannken args_name, argname[i]);
640 1.2 gwr }
641 1.1 mycroft }
642 1.2 gwr print "\tVDESC_NO_OFFSET";
643 1.2 gwr print "};";
644 1.2 gwr # Define F_desc
645 1.28 jdolecek printf("const struct vnodeop_desc %s_desc = {\n", name);
646 1.2 gwr # offset
647 1.43 pooka printf ("\t%s_DESCOFFSET,\n", toupper(name));
648 1.2 gwr # printable name
649 1.2 gwr printf ("\t\"%s\",\n", name);
650 1.2 gwr # flags
651 1.2 gwr printf("\t0");
652 1.2 gwr vpnum = 0;
653 1.2 gwr for (i=0; i<argc; i++) {
654 1.2 gwr if (willrele[i]) {
655 1.63 riastrad if (willrele[i] == 3) {
656 1.19 wrstuden word = "PUT";
657 1.19 wrstuden } else {
658 1.19 wrstuden word = "RELE";
659 1.19 wrstuden }
660 1.57 rmind printf(" | VDESC_VP%s_WILL%s", vpnum, word);
661 1.64 riastrad }
662 1.64 riastrad if (argtype[i] == "struct vnode *")
663 1.2 gwr vpnum++;
664 1.1 mycroft }
665 1.2 gwr print ",";
666 1.2 gwr # vp offsets
667 1.2 gwr printf ("\t%s_vp_offsets,\n", name);
668 1.2 gwr # vpp (if any)
669 1.2 gwr do_offset("struct vnode **");
670 1.2 gwr # cred (if any)
671 1.42 elad do_offset("kauth_cred_t");
672 1.2 gwr # componentname
673 1.2 gwr do_offset("struct componentname *");
674 1.54 pooka printf ("};\n");
675 1.56 pooka }
676 1.20 thorpej
677 1.56 pooka function bodyrump() {
678 1.56 pooka printf("{\n\tint error;\n\n");
679 1.56 pooka printf("\trump_schedule();\n");
680 1.56 pooka printf("\terror = %s(", toupper(name));
681 1.20 thorpej for (i=0; i<argc; i++) {
682 1.56 pooka printf("%s", argname[i]);
683 1.56 pooka if (i < (argc-1)) printf(", ");
684 1.20 thorpej }
685 1.56 pooka printf(");\n");
686 1.56 pooka printf("\trump_unschedule();\n\n");
687 1.56 pooka printf("\treturn error;\n}\n");
688 1.56 pooka }
689 1.56 pooka
690 1.56 pooka function bodynorm() {
691 1.60 hannken printf("{\n\tint error;\n\tbool mpsafe;\n\tstruct %s_args a;\n",
692 1.60 hannken args_name);
693 1.65 hannken printf("\tstruct mount *mp;\n");
694 1.52 pooka if (lockdebug) {
695 1.52 pooka printf("#ifdef VNODE_LOCKDEBUG\n");
696 1.52 pooka for (i=0; i<argc; i++) {
697 1.52 pooka if (lockstate[i] != -1)
698 1.52 pooka printf("\tint islocked_%s;\n", argname[i]);
699 1.52 pooka }
700 1.52 pooka printf("#endif\n");
701 1.35 thorpej }
702 1.20 thorpej printf("\ta.a_desc = VDESC(%s);\n", name);
703 1.20 thorpej for (i=0; i<argc; i++) {
704 1.20 thorpej printf("\ta.a_%s = %s;\n", argname[i], argname[i]);
705 1.52 pooka if (lockdebug && lockstate[i] != -1) {
706 1.35 thorpej printf("#ifdef VNODE_LOCKDEBUG\n");
707 1.45 ad printf("\tislocked_%s = (%s->v_vflag & VV_LOCKSWORK) ? (VOP_ISLOCKED(%s) == LK_EXCLUSIVE) : %d;\n",
708 1.35 thorpej argname[i], argname[i], argname[i], lockstate[i]);
709 1.35 thorpej printf("\tif (islocked_%s != %d)\n", argname[i],
710 1.35 thorpej lockstate[i]);
711 1.35 thorpej printf("\t\tpanic(\"%s: %s: locked %%d, expected %%d\", islocked_%s, %d);\n", name, argname[i], argname[i], lockstate[i]);
712 1.35 thorpej printf("#endif\n");
713 1.35 thorpej }
714 1.20 thorpej }
715 1.72 thorpej # This is done before generic vop_pre() because we want
716 1.72 thorpej # to do any setup before beginning an fstrans.
717 1.72 thorpej if (do_pre != "")
718 1.72 thorpej printf("\t%s(&a);\n", do_pre);
719 1.65 hannken if (fstrans == "LOCK")
720 1.65 hannken printf("\terror = vop_pre(%s, &mp, &mpsafe, %s);\n",
721 1.69 ad argname[0], "(!(flags & (LK_SHARED|LK_EXCLUSIVE)) ? FST_NO : (flags & LK_NOWAIT ? FST_TRY : FST_YES))");
722 1.65 hannken else if (fstrans == "UNLOCK")
723 1.65 hannken printf("\terror = vop_pre(%s, &mp, &mpsafe, FST_%s);\n",
724 1.65 hannken argname[0], "NO");
725 1.65 hannken else
726 1.65 hannken printf("\terror = vop_pre(%s, &mp, &mpsafe, FST_%s);\n",
727 1.65 hannken argname[0], fstrans);
728 1.65 hannken printf("\tif (error)\n\t\treturn error;\n");
729 1.58 hannken printf("\terror = (VCALL(%s, VOFFSET(%s), &a));\n",
730 1.58 hannken argname[0], name);
731 1.65 hannken if (fstrans == "LOCK")
732 1.65 hannken printf("\tvop_post(%s, mp, mpsafe, %s);\n",
733 1.68 ad argname[0], "(flags & (LK_UPGRADE|LK_DOWNGRADE) ? FST_NO : (error ? FST_YES : FST_NO))");
734 1.65 hannken else if (fstrans == "UNLOCK")
735 1.65 hannken printf("\tvop_post(%s, mp, mpsafe, FST_%s);\n",
736 1.65 hannken argname[0], "YES");
737 1.65 hannken else
738 1.65 hannken printf("\tvop_post(%s, mp, mpsafe, FST_%s);\n",
739 1.65 hannken argname[0], fstrans);
740 1.72 thorpej # This is done after generic vop_post() in order to minimize
741 1.72 thorpej # time spent with the KERNEL_LOCK held for file systems that
742 1.72 thorpej # still require it.
743 1.72 thorpej if (do_post != "")
744 1.72 thorpej printf("\t%s(&a, error);\n", do_post);
745 1.44 pooka if (willmake != -1) {
746 1.44 pooka printf("#ifdef DIAGNOSTIC\n");
747 1.46 ad printf("\tif (error == 0)\n" \
748 1.44 pooka "\t\tKASSERT((*%s)->v_size != VSIZENOTSET\n" \
749 1.44 pooka "\t\t && (*%s)->v_writesize != VSIZENOTSET);\n",
750 1.44 pooka argname[willmake], argname[willmake]);
751 1.44 pooka printf("#endif /* DIAGNOSTIC */\n");
752 1.44 pooka }
753 1.46 ad printf("\treturn error;\n}\n");
754 1.20 thorpej }
755 1.56 pooka
756 1.56 pooka function doit() {
757 1.56 pooka printf("\n");
758 1.56 pooka if (!rump)
759 1.56 pooka offsets();
760 1.56 pooka
761 1.56 pooka if (rump)
762 1.56 pooka extname = "RUMP_" toupper(name);
763 1.56 pooka else
764 1.56 pooka extname = toupper(name);
765 1.56 pooka
766 1.56 pooka # Define function.
767 1.56 pooka printf("int\n%s(", extname);
768 1.56 pooka for (i=0; i<argc; i++) {
769 1.56 pooka printf("%s %s", argtype[i], argname[i]);
770 1.56 pooka if (i < (argc-1)) printf(",\n ");
771 1.56 pooka }
772 1.56 pooka printf(")\n");
773 1.56 pooka
774 1.56 pooka if (rump)
775 1.56 pooka bodyrump();
776 1.56 pooka else
777 1.56 pooka bodynorm();
778 1.56 pooka }
779 1.20 thorpej BEGIN {
780 1.28 jdolecek # start from 1 (vop_default is at 0)
781 1.2 gwr argc=1;
782 1.1 mycroft }
783 1.7 cgd '"$awk_parser" | sed -e "$anal_retentive"
784 1.1 mycroft
785 1.2 gwr # End stuff
786 1.56 pooka [ -n "${rump}" ] && return
787 1.1 mycroft
788 1.2 gwr # Add the vfs_op_descs array to the C file.
789 1.2 gwr # Begin stuff
790 1.50 pooka echo "
791 1.50 pooka const struct vnodeop_desc * const ${rump}vfs_op_descs[] = {
792 1.50 pooka &${rump}vop_default_desc, /* MUST BE FIRST */
793 1.50 pooka "
794 1.2 gwr
795 1.2 gwr # Body stuff
796 1.50 pooka sed -e "$sed_prep" $src | $awk -v rump=${rump} '
797 1.2 gwr function doit() {
798 1.2 gwr printf("\t&%s_desc,\n", name);
799 1.1 mycroft }
800 1.2 gwr '"$awk_parser"
801 1.1 mycroft
802 1.2 gwr # End stuff
803 1.2 gwr echo ' NULL
804 1.55 pooka };'
805 1.50 pooka }
806 1.50 pooka do_cfile $out_c ''
807 1.50 pooka do_cfile $out_rumpc 'rump_'
808 1.1 mycroft
809 1.2 gwr exit 0
810 1.1 mycroft
811 1.2 gwr # Local Variables:
812 1.2 gwr # tab-width: 4
813 1.2 gwr # End:
814