4 # Copyright (c) 1992, 1993
5 # The Regents of the University of California. All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 # 4. 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
17 # without specific prior written permission.
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
21 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
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
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
32 # @(#)vnode_if.sh 8.1 (Berkeley) 6/10/93
35 # Script to produce VFS front-end sugar.
37 # usage: vnode_if.awk <srcfile> [-c | -h | -p | -q]
38 # (where <srcfile> is currently /sys/kern/vnode_if.src)
39 # The source file must have a .src extension
44 print "usage: vnode_if.awk <srcfile> [-c|-h|-p|-q]";
48 function die
(msg
, what
)
50 printf srcfile
"(" fnr "): " > "/dev/stderr";
51 printf msg
"\n", what
> "/dev/stderr";
57 # Append a space if the type is not a pointer
58 return (type ~
/\
*$
/) ? type
: type
" ";
61 # These are just for convenience ...
62 function printc
(s
) {print s
> cfile
;}
63 function printh
(s
) {print s
> hfile
;}
64 function printp
(s
) {print s
> pfile
;}
65 function printq
(s
) {print s
> qfile
;}
67 function add_debug_code
(name
, arg
, pos
, ind
)
73 if (lockdata
[name
, arg
, pos
] && (lockdata
[name
, arg
, pos
] != "-")) {
74 printc
(ind
"ASSERT_VI_UNLOCKED("star
"a->a_"arg
", \""uname
"\");");
75 # Add assertions for locking
76 if (lockdata
[name
, arg
, pos
] ==
"L")
77 printc
(ind
"ASSERT_VOP_LOCKED(" star
"a->a_"arg
", \""uname
"\");");
78 else if (lockdata
[name
, arg
, pos
] ==
"U")
79 printc
(ind
"ASSERT_VOP_UNLOCKED(" star
"a->a_"arg
", \""uname
"\");");
80 else if (lockdata
[name
, arg
, pos
] ==
"E")
81 printc
(ind
"ASSERT_VOP_ELOCKED(" star
"a->a_"arg
", \""uname
"\");");
88 function add_pre
(name
)
90 if (lockdata
[name
, "pre"]) {
91 printc
("\t"lockdata
[name
, "pre"]"(a);");
95 function add_post
(name
)
97 if (lockdata
[name
, "post"]) {
98 printc
("\t"lockdata
[name
, "post"]"(a, rc);");
102 function find_arg_with_type
(type
)
104 for (jj =
0; jj
< numargs
; jj
++) {
105 if (types
[jj
] == type
) {
106 return "VOPARG_OFFSETOF(struct " \
107 name
"_args,a_" args
[jj
] ")";
111 return "VDESC_NO_OFFSET";
116 # Process the command line
117 for (i =
1; i
< ARGC; i
++) {
119 if (arg !~
/^
-[chpq
]+$
/ && arg !~
/\.src$
/)
122 cfile =
"vnode_if.c";
124 hfile =
"vnode_if.h";
126 pfile =
"vnode_if_newproto.h";
128 qfile =
"vnode_if_typedef.h";
134 if (!cfile
&& !hfile
&& !pfile
&& !qfile
)
142 " * This file is produced automatically.\n" \
143 " * Do not modify anything in here by hand.\n" \
145 " * Created from $FreeBSD$\n" \
151 printp
("struct vop_vector {")
152 printp
("\tstruct vop_vector\t*vop_default;")
153 printp
("\tvop_bypass_t\t*vop_bypass;")
161 printh
(common_head
"extern struct vnodeop_desc vop_default_desc;");
162 printh
("#include \"vnode_if_typedef.h\"")
163 printh
("#include \"vnode_if_newproto.h\"")
168 "#include <sys/param.h>\n" \
169 "#include <sys/event.h>\n" \
170 "#include <sys/kernel.h>\n" \
171 "#include <sys/mount.h>\n" \
172 "#include <sys/sdt.h>\n" \
173 "#include <sys/signalvar.h>\n" \
174 "#include <sys/systm.h>\n" \
175 "#include <sys/vnode.h>\n" \
177 "SDT_PROVIDER_DECLARE(vfs);\n" \
179 "struct vnodeop_desc vop_default_desc = {\n" \
182 " (vop_bypass_t *)vop_panic,\n" \
184 " VDESC_NO_OFFSET,\n" \
185 " VDESC_NO_OFFSET,\n" \
186 " VDESC_NO_OFFSET,\n" \
187 " VDESC_NO_OFFSET,\n" \
191 while ((getline < srcfile
) > 0) {
197 $
2 !~
/^
[a
-z_
]+$
/ || $
3 !~
/^
[a
-z
]+$
/ ||
198 $
4 !~
/^.$
/ || $
5 !~
/^.$
/ || $
6 !~
/^.$
/) {
199 die
("Invalid %s construction", "%%");
202 lockdata
["vop_" $
2, $
3, "Entry"] = $
4;
203 lockdata
["vop_" $
2, $
3, "OK"] = $
5;
204 lockdata
["vop_" $
2, $
3, "Error"] = $
6;
210 ($
3 != "pre" && $
3 != "post")) {
211 die
("Invalid %s construction", "%!");
214 lockdata
["vop_" $
2, $
3] = $
4;
220 # Get the function name.
222 uname =
toupper(name
);
224 # Get the function arguments.
225 for (numargs =
0; ; ++numargs
) {
226 if ((getline < srcfile
) <=
0) {
227 die
("Unable to read through the arguments for \"%s\"",
234 # Delete comments, if any.
235 gsub (/\
/\
*.
*\
*\
//, "");
237 # Condense whitespace and delete leading/trailing space.
238 gsub(/[[:space
:]]+/, " ");
242 # Pick off direction.
243 if ($
1 != "INOUT" && $
1 != "IN" && $
1 != "OUT")
244 die
("No IN/OUT direction for \"%s\".", $
0);
248 if ((reles
[numargs
] = $
1) ==
"WILLRELE")
251 reles
[numargs
] =
"WONTRELE";
254 if (sub(/;$
/, "") < 1)
255 die
("Missing end-of-line ; in \"%s\".", $
0);
257 # pick off variable name
258 if ((argp =
match($
0, /[A
-Za
-z0
-9_
]+$
/)) < 1)
259 die
("Missing var name \"a_foo\" in \"%s\".", $
0);
260 args
[numargs
] =
substr($
0, argp
);
261 $
0 =
substr($
0, 1, argp
- 1);
263 # what is left must be type
264 # remove trailing space (if any)
272 ctrstr = ctrargs
"(KTR_VOP, \"VOP\", \"" uname
"\", (uintptr_t)a,\n\t ";
273 ctrstr = ctrstr
"\"" args
[0] ":0x%jX\", (uintptr_t)a->a_" args
[0];
274 for (i =
1; i
< ctrargs
; ++i
)
275 ctrstr = ctrstr
", \"" args
[i
] ":0x%jX\", a->a_" args
[i
];
276 ctrstr = ctrstr
");";
279 printp
("\t"name
"_t\t*"name
";")
282 printq
("struct "name
"_args;")
283 printq
("typedef int "name
"_t(struct "name
"_args *);\n")
287 # Print out the vop_F_args structure.
288 printh
("struct "name
"_args {\n\tstruct vop_generic_args a_gen;");
289 for (i =
0; i
< numargs
; ++i
)
290 printh
("\t" t_spc
(types
[i
]) "a_" args
[i
] ";");
294 # Print out extern declaration.
295 printh
("extern struct vnodeop_desc " name
"_desc;");
298 # Print out function prototypes.
299 printh
("int " uname
"_AP(struct " name
"_args *);");
300 printh
("int " uname
"_APV(struct vop_vector *vop, struct " name
"_args *);");
302 printh
("static __inline int " uname
"(");
303 for (i =
0; i
< numargs
; ++i
) {
304 printh
("\t" t_spc
(types
[i
]) args
[i
] \
305 (i
< numargs
- 1 ?
"," : ")"));
308 printh
("\tstruct " name
"_args a;");
310 printh
("\ta.a_gen.a_desc = &" name
"_desc;");
311 for (i =
0; i
< numargs
; ++i
)
312 printh
("\ta.a_" args
[i
] " = " args
[i
] ";");
313 printh
("\treturn (" uname
"_APV("args
[0]"->v_op, &a));");
320 # Print out the vop_F_vp_offsets structure. This all depends
321 # on naming conventions and nothing else.
322 printc
("static int " name
"_vp_offsets[] = {");
323 # as a side effect, figure out the releflags
326 for (i =
0; i
< numargs
; i
++) {
327 if (types
[i
] ==
"struct vnode *") {
328 printc
("\tVOPARG_OFFSETOF(struct " name \
329 "_args,a_" args
[i
] "),");
330 if (reles
[i
] ==
"WILLRELE") {
331 releflags = releflags \
332 "|VDESC_VP" vpnum
"_WILLRELE";
338 sub(/^\
|/, "", releflags
);
339 printc
("\tVDESC_NO_OFFSET");
343 printc
("SDT_PROBE_DEFINE2(vfs, vop, " name
", entry, \"struct vnode *\", \"struct " name
"_args *\");\n");
344 printc
("SDT_PROBE_DEFINE3(vfs, vop, " name
", return, \"struct vnode *\", \"struct " name
"_args *\", \"int\");\n");
346 # Print out function.
347 printc
("\nint\n" uname
"_AP(struct " name
"_args *a)");
350 printc
("\treturn(" uname
"_APV(a->a_" args
[0] "->v_op, a));");
352 printc
("\nint\n" uname
"_APV(struct vop_vector *vop, struct " name
"_args *a)");
356 printc
("\tVNASSERT(a->a_gen.a_desc == &" name
"_desc, a->a_" args
[0]",");
357 printc
("\t (\"Wrong a_desc in " name
"(%p, %p)\", a->a_" args
[0]", a));");
358 printc
("\twhile(vop != NULL && \\");
359 printc
("\t vop->"name
" == NULL && vop->vop_bypass == NULL)")
360 printc
("\t\tvop = vop->vop_default;")
361 printc
("\tVNASSERT(vop != NULL, a->a_" args
[0]", (\"No "name
"(%p, %p)\", a->a_" args
[0]", a));")
362 printc
("\tSDT_PROBE2(vfs, vop, " name
", entry, a->a_" args
[0] ", a);\n");
363 for (i =
0; i
< numargs
; ++i
)
364 add_debug_code
(name
, args
[i
], "Entry", "\t");
365 printc
("\tKTR_START" ctrstr
);
367 printc
("\tVFS_PROLOGUE(a->a_" args
[0]"->v_mount);")
368 printc
("\tif (vop->"name
" != NULL)")
369 printc
("\t\trc = vop->"name
"(a);")
371 printc
("\t\trc = vop->vop_bypass(&a->a_gen);")
372 printc
("\tVFS_EPILOGUE(a->a_" args
[0]"->v_mount);")
373 printc
("\tSDT_PROBE3(vfs, vop, " name
", return, a->a_" args
[0] ", a, rc);\n");
374 printc
("\tif (rc == 0) {");
375 for (i =
0; i
< numargs
; ++i
)
376 add_debug_code
(name
, args
[i
], "OK", "\t\t");
377 printc
("\t} else {");
378 for (i =
0; i
< numargs
; ++i
)
379 add_debug_code
(name
, args
[i
], "Error", "\t\t");
382 printc
("\tKTR_STOP" ctrstr
);
383 printc
("\treturn (rc);");
386 # Print out the vnodeop_desc structure.
387 printc
("struct vnodeop_desc " name
"_desc = {");
389 printc
("\t\"" name
"\",");
392 for (i =
0; i
< numargs
; i
++) {
393 if (types
[i
] ==
"struct vnode **" && \
394 reles
[i
] ==
"WILLRELE") {
395 vppwillrele =
"|VDESC_VPP_WILLRELE";
401 printc
("\t" releflags vppwillrele
",");
404 printc
("\t(vop_bypass_t *)" uname
"_AP,");
406 printc
("\t" name
"_vp_offsets,");
408 printc
("\t" find_arg_with_type
("struct vnode **") ",");
410 printc
("\t" find_arg_with_type
("struct ucred *") ",");
412 printc
("\t" find_arg_with_type
("struct thread *") ",");
414 printc
("\t" find_arg_with_type
("struct componentname *") ",");
415 # transport layer information