1fda3199fSDavid E. O'Brien#!/usr/bin/awk -f 23176a7feSEivind Eklund 360727d8bSWarner Losh#- 451369649SPedro F. Giffuni# SPDX-License-Identifier: BSD-3-Clause 551369649SPedro F. Giffuni# 6df8bae1dSRodney W. Grimes# Copyright (c) 1992, 1993 7df8bae1dSRodney W. Grimes# The Regents of the University of California. All rights reserved. 8df8bae1dSRodney W. Grimes# 9df8bae1dSRodney W. Grimes# Redistribution and use in source and binary forms, with or without 10df8bae1dSRodney W. Grimes# modification, are permitted provided that the following conditions 11df8bae1dSRodney W. Grimes# are met: 12df8bae1dSRodney W. Grimes# 1. Redistributions of source code must retain the above copyright 13df8bae1dSRodney W. Grimes# notice, this list of conditions and the following disclaimer. 14df8bae1dSRodney W. Grimes# 2. Redistributions in binary form must reproduce the above copyright 15df8bae1dSRodney W. Grimes# notice, this list of conditions and the following disclaimer in the 16df8bae1dSRodney W. Grimes# documentation and/or other materials provided with the distribution. 17fbbd9655SWarner Losh# 3. Neither the name of the University nor the names of its contributors 18df8bae1dSRodney W. Grimes# may be used to endorse or promote products derived from this software 19df8bae1dSRodney W. Grimes# without specific prior written permission. 20df8bae1dSRodney W. Grimes# 21df8bae1dSRodney W. Grimes# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22df8bae1dSRodney W. Grimes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23df8bae1dSRodney W. Grimes# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24df8bae1dSRodney W. Grimes# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25df8bae1dSRodney W. Grimes# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26df8bae1dSRodney W. Grimes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27df8bae1dSRodney W. Grimes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28df8bae1dSRodney W. Grimes# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29df8bae1dSRodney W. Grimes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30df8bae1dSRodney W. Grimes# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31df8bae1dSRodney W. Grimes# SUCH DAMAGE. 3260727d8bSWarner Losh 33df8bae1dSRodney W. Grimes# Script to produce VFS front-end sugar. 34df8bae1dSRodney W. Grimes# 353cd62520SDiomidis Spinellis# usage: vnode_if.awk <srcfile> [-c | -h | -p | -q] 36fda3199fSDavid E. O'Brien# (where <srcfile> is currently /sys/kern/vnode_if.src) 373cd62520SDiomidis Spinellis# The source file must have a .src extension 38df8bae1dSRodney W. Grimes# 39df8bae1dSRodney W. Grimes 40fda3199fSDavid E. O'Brienfunction usage() 41fda3199fSDavid E. O'Brien{ 42aec0fb7bSPoul-Henning Kamp print "usage: vnode_if.awk <srcfile> [-c|-h|-p|-q]"; 43fda3199fSDavid E. O'Brien exit 1; 446f77b2deSPeter Wemm} 45df8bae1dSRodney W. Grimes 46fda3199fSDavid E. O'Brienfunction die(msg, what) 47fda3199fSDavid E. O'Brien{ 4844d6e87bSDiomidis Spinellis printf srcfile "(" fnr "): " > "/dev/stderr"; 49fda3199fSDavid E. O'Brien printf msg "\n", what > "/dev/stderr"; 50fda3199fSDavid E. O'Brien exit 1; 516f77b2deSPeter Wemm} 52df8bae1dSRodney W. Grimes 53fda3199fSDavid E. O'Brienfunction t_spc(type) 54fda3199fSDavid E. O'Brien{ 55fda3199fSDavid E. O'Brien # Append a space if the type is not a pointer 56fda3199fSDavid E. O'Brien return (type ~ /\*$/) ? type : type " "; 576f77b2deSPeter Wemm} 58df8bae1dSRodney W. Grimes 59fda3199fSDavid E. O'Brien# These are just for convenience ... 60fda3199fSDavid E. O'Brienfunction printc(s) {print s > cfile;} 61fda3199fSDavid E. O'Brienfunction printh(s) {print s > hfile;} 62aec0fb7bSPoul-Henning Kampfunction printp(s) {print s > pfile;} 63aec0fb7bSPoul-Henning Kampfunction printq(s) {print s > qfile;} 6435b1da80SAlfred Perlstein 6563f89abfSPoul-Henning Kampfunction add_debug_code(name, arg, pos, ind) 66fda3199fSDavid E. O'Brien{ 6786ed8962SStefan Eßer if (arg == "vpp") 6863f89abfSPoul-Henning Kamp star = "*"; 6963f89abfSPoul-Henning Kamp else 7063f89abfSPoul-Henning Kamp star = ""; 717144b1d4SDon Lewis if (lockdata[name, arg, pos] && (lockdata[name, arg, pos] != "-")) { 725a4a83fdSJason A. Harmening printc(ind"ASSERT_VI_UNLOCKED("star"a->a_"arg", \""uname" "pos" ("arg")\");"); 733176a7feSEivind Eklund # Add assertions for locking 74cf409a0aSJeff Roberson if (lockdata[name, arg, pos] == "L") 755a4a83fdSJason A. Harmening printc(ind"ASSERT_VOP_LOCKED(" star "a->a_"arg", \""uname" "pos" ("arg")\");"); 76cf409a0aSJeff Roberson else if (lockdata[name, arg, pos] == "U") 775a4a83fdSJason A. Harmening printc(ind"ASSERT_VOP_UNLOCKED(" star "a->a_"arg", \""uname" "pos" ("arg")\");"); 78680a1ec6SJeff Roberson else if (lockdata[name, arg, pos] == "E") 795a4a83fdSJason A. Harmening printc(ind"ASSERT_VOP_ELOCKED(" star "a->a_"arg", \""uname" "pos" ("arg")\");"); 80fda3199fSDavid E. O'Brien else if (0) { 813176a7feSEivind Eklund # XXX More checks! 823176a7feSEivind Eklund } 833176a7feSEivind Eklund } 843176a7feSEivind Eklund} 85df8bae1dSRodney W. Grimes 86848f8effSMateusz Guzikfunction add_debugpre(name) 87848f8effSMateusz Guzik{ 88848f8effSMateusz Guzik if (lockdata[name, "debugpre"]) { 89848f8effSMateusz Guzik printc("#ifdef DEBUG_VFS_LOCKS"); 90848f8effSMateusz Guzik printc("\t"lockdata[name, "debugpre"]"(a);"); 91848f8effSMateusz Guzik printc("#endif"); 92848f8effSMateusz Guzik } 93848f8effSMateusz Guzik} 94848f8effSMateusz Guzik 95848f8effSMateusz Guzikfunction add_debugpost(name) 96848f8effSMateusz Guzik{ 97848f8effSMateusz Guzik if (lockdata[name, "debugpost"]) { 98848f8effSMateusz Guzik printc("#ifdef DEBUG_VFS_LOCKS"); 99848f8effSMateusz Guzik printc("\t"lockdata[name, "debugpost"]"(a, rc);"); 100848f8effSMateusz Guzik printc("#endif"); 101848f8effSMateusz Guzik } 102848f8effSMateusz Guzik} 103848f8effSMateusz Guzik 104679985d0SSuleiman Souhlalfunction add_pre(name) 105d1376090SJeff Roberson{ 1065c08ffedSJeff Roberson if (lockdata[name, "pre"]) { 10763f89abfSPoul-Henning Kamp printc("\t"lockdata[name, "pre"]"(a);"); 108d1376090SJeff Roberson } 109d1376090SJeff Roberson} 110d1376090SJeff Roberson 111679985d0SSuleiman Souhlalfunction add_post(name) 112d1376090SJeff Roberson{ 1135c08ffedSJeff Roberson if (lockdata[name, "post"]) { 11463f89abfSPoul-Henning Kamp printc("\t"lockdata[name, "post"]"(a, rc);"); 115d1376090SJeff Roberson } 116d1376090SJeff Roberson} 117d1376090SJeff Roberson 118848f8effSMateusz Guzikfunction can_inline(name) 119848f8effSMateusz Guzik{ 120848f8effSMateusz Guzik if (lockdata[name, "pre"]) 121848f8effSMateusz Guzik return 0; 122848f8effSMateusz Guzik if (lockdata[name, "post"]) 123848f8effSMateusz Guzik return 0; 124848f8effSMateusz Guzik return 1; 125848f8effSMateusz Guzik} 126848f8effSMateusz Guzik 127fda3199fSDavid E. O'Brienfunction find_arg_with_type (type) 128fda3199fSDavid E. O'Brien{ 129fda3199fSDavid E. O'Brien for (jj = 0; jj < numargs; jj++) { 130fda3199fSDavid E. O'Brien if (types[jj] == type) { 131fda3199fSDavid E. O'Brien return "VOPARG_OFFSETOF(struct " \ 132fda3199fSDavid E. O'Brien name "_args,a_" args[jj] ")"; 1333176a7feSEivind Eklund } 1343176a7feSEivind Eklund } 1353176a7feSEivind Eklund 1363176a7feSEivind Eklund return "VDESC_NO_OFFSET"; 1373176a7feSEivind Eklund} 138fda3199fSDavid E. O'Brien 139fda3199fSDavid E. O'BrienBEGIN{ 140fda3199fSDavid E. O'Brien 141fda3199fSDavid E. O'Brien# Process the command line 142fda3199fSDavid E. O'Brienfor (i = 1; i < ARGC; i++) { 143fda3199fSDavid E. O'Brien arg = ARGV[i]; 144aec0fb7bSPoul-Henning Kamp if (arg !~ /^-[chpq]+$/ && arg !~ /\.src$/) 145fda3199fSDavid E. O'Brien usage(); 146fda3199fSDavid E. O'Brien if (arg ~ /^-.*c/) 147fda3199fSDavid E. O'Brien cfile = "vnode_if.c"; 148fda3199fSDavid E. O'Brien if (arg ~ /^-.*h/) 149fda3199fSDavid E. O'Brien hfile = "vnode_if.h"; 150aec0fb7bSPoul-Henning Kamp if (arg ~ /^-.*p/) 151aec0fb7bSPoul-Henning Kamp pfile = "vnode_if_newproto.h"; 152aec0fb7bSPoul-Henning Kamp if (arg ~ /^-.*q/) 153aec0fb7bSPoul-Henning Kamp qfile = "vnode_if_typedef.h"; 154fda3199fSDavid E. O'Brien if (arg ~ /\.src$/) 155fda3199fSDavid E. O'Brien srcfile = arg; 156fda3199fSDavid E. O'Brien} 157fda3199fSDavid E. O'BrienARGC = 1; 158fda3199fSDavid E. O'Brien 159aec0fb7bSPoul-Henning Kampif (!cfile && !hfile && !pfile && !qfile) 160fda3199fSDavid E. O'Brien exit 0; 161fda3199fSDavid E. O'Brien 162fda3199fSDavid E. O'Brienif (!srcfile) 163fda3199fSDavid E. O'Brien usage(); 164fda3199fSDavid E. O'Brien 16552bcb118SEd Maste# Avoid a literal generated file tag here. 16652bcb118SEd Mastegenerated = "@" "generated"; 16752bcb118SEd Maste 168fda3199fSDavid E. O'Briencommon_head = \ 169fda3199fSDavid E. O'Brien "/*\n" \ 17052bcb118SEd Maste " * This file is " generated " automatically.\n" \ 171fda3199fSDavid E. O'Brien " * Do not modify anything in here by hand.\n" \ 172fda3199fSDavid E. O'Brien " */\n" \ 173fda3199fSDavid E. O'Brien "\n"; 174fda3199fSDavid E. O'Brien 175aec0fb7bSPoul-Henning Kampif (pfile) { 176aec0fb7bSPoul-Henning Kamp printp(common_head) 177aec0fb7bSPoul-Henning Kamp printp("struct vop_vector {") 178aec0fb7bSPoul-Henning Kamp printp("\tstruct vop_vector\t*vop_default;") 179aec0fb7bSPoul-Henning Kamp printp("\tvop_bypass_t\t*vop_bypass;") 180aec0fb7bSPoul-Henning Kamp} 181aec0fb7bSPoul-Henning Kamp 182aec0fb7bSPoul-Henning Kampif (qfile) { 183aec0fb7bSPoul-Henning Kamp printq(common_head) 184aec0fb7bSPoul-Henning Kamp} 185aec0fb7bSPoul-Henning Kamp 186aec0fb7bSPoul-Henning Kampif (hfile) { 187fda3199fSDavid E. O'Brien printh(common_head "extern struct vnodeop_desc vop_default_desc;"); 188aec0fb7bSPoul-Henning Kamp printh("#include \"vnode_if_typedef.h\"") 189aec0fb7bSPoul-Henning Kamp printh("#include \"vnode_if_newproto.h\"") 190aec0fb7bSPoul-Henning Kamp} 191fda3199fSDavid E. O'Brien 192fda3199fSDavid E. O'Brienif (cfile) { 193fda3199fSDavid E. O'Brien printc(common_head \ 194fda3199fSDavid E. O'Brien "#include <sys/param.h>\n" \ 195679985d0SSuleiman Souhlal "#include <sys/event.h>\n" \ 196ff8a07fdSRobert Watson "#include <sys/kernel.h>\n" \ 197679985d0SSuleiman Souhlal "#include <sys/mount.h>\n" \ 198ff8a07fdSRobert Watson "#include <sys/sdt.h>\n" \ 199593efaf9SJohn Baldwin "#include <sys/signalvar.h>\n" \ 200ef317162SJeff Roberson "#include <sys/systm.h>\n" \ 201fda3199fSDavid E. O'Brien "#include <sys/vnode.h>\n" \ 202fda3199fSDavid E. O'Brien "\n" \ 203ff8a07fdSRobert Watson "SDT_PROVIDER_DECLARE(vfs);\n" \ 204ff8a07fdSRobert Watson "\n" \ 205fda3199fSDavid E. O'Brien "struct vnodeop_desc vop_default_desc = {\n" \ 206fda3199fSDavid E. O'Brien " \"default\",\n" \ 207fda3199fSDavid E. O'Brien " 0,\n" \ 2088ff7fad1SKonstantin Belousov " 0,\n" \ 2090430a5e2SDag-Erling Smørgrav " (vop_bypass_t *)vop_panic,\n" \ 210fda3199fSDavid E. O'Brien " NULL,\n" \ 211fda3199fSDavid E. O'Brien " VDESC_NO_OFFSET,\n" \ 212fda3199fSDavid E. O'Brien " VDESC_NO_OFFSET,\n" \ 213fda3199fSDavid E. O'Brien " VDESC_NO_OFFSET,\n" \ 214fda3199fSDavid E. O'Brien " VDESC_NO_OFFSET,\n" \ 215fda3199fSDavid E. O'Brien "};\n"); 216fda3199fSDavid E. O'Brien} 217fda3199fSDavid E. O'Brien 218fda3199fSDavid E. O'Brienwhile ((getline < srcfile) > 0) { 21944d6e87bSDiomidis Spinellis fnr++; 220fda3199fSDavid E. O'Brien if (NF == 0) 221fda3199fSDavid E. O'Brien continue; 222f69ec7afSDiomidis Spinellis if ($1 ~ /^%%/) { 22344d6e87bSDiomidis Spinellis if (NF != 6 || 224f62f6c88SMikolaj Golub $2 !~ /^[a-z_]+$/ || $3 !~ /^[a-z]+$/ || 22544d6e87bSDiomidis Spinellis $4 !~ /^.$/ || $5 !~ /^.$/ || $6 !~ /^.$/) { 22644d6e87bSDiomidis Spinellis die("Invalid %s construction", "%%"); 227fda3199fSDavid E. O'Brien continue; 22844d6e87bSDiomidis Spinellis } 229fda3199fSDavid E. O'Brien lockdata["vop_" $2, $3, "Entry"] = $4; 230fda3199fSDavid E. O'Brien lockdata["vop_" $2, $3, "OK"] = $5; 231fda3199fSDavid E. O'Brien lockdata["vop_" $2, $3, "Error"] = $6; 232fda3199fSDavid E. O'Brien continue; 233fda3199fSDavid E. O'Brien } 234fda3199fSDavid E. O'Brien 235f69ec7afSDiomidis Spinellis if ($1 ~ /^%!/) { 23644d6e87bSDiomidis Spinellis if (NF != 4 || 237848f8effSMateusz Guzik ($3 != "pre" && $3 != "post" && 238848f8effSMateusz Guzik $3 != "debugpre" && $3 != "debugpost")) { 23944d6e87bSDiomidis Spinellis die("Invalid %s construction", "%!"); 240d1376090SJeff Roberson continue; 24144d6e87bSDiomidis Spinellis } 242d1376090SJeff Roberson lockdata["vop_" $2, $3] = $4; 243d1376090SJeff Roberson continue; 244d1376090SJeff Roberson } 24544d6e87bSDiomidis Spinellis if ($1 ~ /^#/) 246d1376090SJeff Roberson continue; 247d1376090SJeff Roberson 248fda3199fSDavid E. O'Brien # Get the function name. 249fda3199fSDavid E. O'Brien name = $1; 250fda3199fSDavid E. O'Brien uname = toupper(name); 25115597470SJeff Roberson 252fda3199fSDavid E. O'Brien # Get the function arguments. 253fda3199fSDavid E. O'Brien for (numargs = 0; ; ++numargs) { 254fda3199fSDavid E. O'Brien if ((getline < srcfile) <= 0) { 255fda3199fSDavid E. O'Brien die("Unable to read through the arguments for \"%s\"", 256fda3199fSDavid E. O'Brien name); 257fda3199fSDavid E. O'Brien } 25844d6e87bSDiomidis Spinellis fnr++; 259fda3199fSDavid E. O'Brien if ($1 ~ /^\};/) 260fda3199fSDavid E. O'Brien break; 261fda3199fSDavid E. O'Brien 262fda3199fSDavid E. O'Brien # Delete comments, if any. 263fda3199fSDavid E. O'Brien gsub (/\/\*.*\*\//, ""); 264fda3199fSDavid E. O'Brien 265fda3199fSDavid E. O'Brien # Condense whitespace and delete leading/trailing space. 266fda3199fSDavid E. O'Brien gsub(/[[:space:]]+/, " "); 267fda3199fSDavid E. O'Brien sub(/^ /, ""); 268fda3199fSDavid E. O'Brien sub(/ $/, ""); 269fda3199fSDavid E. O'Brien 270fda3199fSDavid E. O'Brien # Pick off direction. 271fda3199fSDavid E. O'Brien if ($1 != "INOUT" && $1 != "IN" && $1 != "OUT") 272fda3199fSDavid E. O'Brien die("No IN/OUT direction for \"%s\".", $0); 273fda3199fSDavid E. O'Brien dirs[numargs] = $1; 274fda3199fSDavid E. O'Brien sub(/^[A-Z]* /, ""); 275fda3199fSDavid E. O'Brien 276fda3199fSDavid E. O'Brien if ((reles[numargs] = $1) == "WILLRELE") 277fda3199fSDavid E. O'Brien sub(/^[A-Z]* /, ""); 278fda3199fSDavid E. O'Brien else 279fda3199fSDavid E. O'Brien reles[numargs] = "WONTRELE"; 280fda3199fSDavid E. O'Brien 281fda3199fSDavid E. O'Brien # kill trailing ; 282fda3199fSDavid E. O'Brien if (sub(/;$/, "") < 1) 283fda3199fSDavid E. O'Brien die("Missing end-of-line ; in \"%s\".", $0); 284fda3199fSDavid E. O'Brien 285fda3199fSDavid E. O'Brien # pick off variable name 286fda3199fSDavid E. O'Brien if ((argp = match($0, /[A-Za-z0-9_]+$/)) < 1) 287fda3199fSDavid E. O'Brien die("Missing var name \"a_foo\" in \"%s\".", $0); 288fda3199fSDavid E. O'Brien args[numargs] = substr($0, argp); 289fda3199fSDavid E. O'Brien $0 = substr($0, 1, argp - 1); 290fda3199fSDavid E. O'Brien 291fda3199fSDavid E. O'Brien # what is left must be type 292fda3199fSDavid E. O'Brien # remove trailing space (if any) 293fda3199fSDavid E. O'Brien sub(/ $/, ""); 294fda3199fSDavid E. O'Brien types[numargs] = $0; 295fda3199fSDavid E. O'Brien } 2964c44811cSJeff Roberson if (numargs > 4) 2974c44811cSJeff Roberson ctrargs = 4; 29815597470SJeff Roberson else 29915597470SJeff Roberson ctrargs = numargs; 3007fc3ae51SOleksandr Tymoshenko ctrstr = ctrargs "(KTR_VOP, \"VOP\", \"" uname "\", (uintptr_t)a,\n\t "; 3014c44811cSJeff Roberson ctrstr = ctrstr "\"" args[0] ":0x%jX\", (uintptr_t)a->a_" args[0]; 30263f89abfSPoul-Henning Kamp for (i = 1; i < ctrargs; ++i) 3034c44811cSJeff Roberson ctrstr = ctrstr ", \"" args[i] ":0x%jX\", a->a_" args[i]; 30415597470SJeff Roberson ctrstr = ctrstr ");"; 305fda3199fSDavid E. O'Brien 306aec0fb7bSPoul-Henning Kamp if (pfile) { 307aec0fb7bSPoul-Henning Kamp printp("\t"name"_t\t*"name";") 308aec0fb7bSPoul-Henning Kamp } 309aec0fb7bSPoul-Henning Kamp if (qfile) { 310aec0fb7bSPoul-Henning Kamp printq("struct "name"_args;") 311aec0fb7bSPoul-Henning Kamp printq("typedef int "name"_t(struct "name"_args *);\n") 312aec0fb7bSPoul-Henning Kamp } 313aec0fb7bSPoul-Henning Kamp 314fda3199fSDavid E. O'Brien if (hfile) { 315fda3199fSDavid E. O'Brien # Print out the vop_F_args structure. 31657c75b8fSWarner Losh printh("struct "name"_args {\n\tstruct vop_generic_args a_gen;"); 317fda3199fSDavid E. O'Brien for (i = 0; i < numargs; ++i) 318fda3199fSDavid E. O'Brien printh("\t" t_spc(types[i]) "a_" args[i] ";"); 319fda3199fSDavid E. O'Brien printh("};"); 32063f89abfSPoul-Henning Kamp printh(""); 321fda3199fSDavid E. O'Brien 322fda3199fSDavid E. O'Brien # Print out extern declaration. 323fda3199fSDavid E. O'Brien printh("extern struct vnodeop_desc " name "_desc;"); 32463f89abfSPoul-Henning Kamp printh(""); 325fda3199fSDavid E. O'Brien 32663f89abfSPoul-Henning Kamp # Print out function prototypes. 32763f89abfSPoul-Henning Kamp printh("int " uname "_AP(struct " name "_args *);"); 328*cd048d5dSMark Johnston printh("int " uname "_APV(const struct vop_vector *vop, struct " name "_args *);"); 32963f89abfSPoul-Henning Kamp printh(""); 330fda3199fSDavid E. O'Brien printh("static __inline int " uname "("); 331fda3199fSDavid E. O'Brien for (i = 0; i < numargs; ++i) { 332fda3199fSDavid E. O'Brien printh("\t" t_spc(types[i]) args[i] \ 333fda3199fSDavid E. O'Brien (i < numargs - 1 ? "," : ")")); 334fda3199fSDavid E. O'Brien } 33563f89abfSPoul-Henning Kamp printh("{"); 33663f89abfSPoul-Henning Kamp printh("\tstruct " name "_args a;"); 33763f89abfSPoul-Henning Kamp printh(""); 338de8a6c06SPoul-Henning Kamp printh("\ta.a_gen.a_desc = &" name "_desc;"); 339fda3199fSDavid E. O'Brien for (i = 0; i < numargs; ++i) 340fda3199fSDavid E. O'Brien printh("\ta.a_" args[i] " = " args[i] ";"); 341848f8effSMateusz Guzik if (can_inline(name)) { 342848f8effSMateusz Guzik printh("\n#if !defined(DEBUG_VFS_LOCKS) && !defined(INVARIANTS) && !defined(KTR)"); 343848f8effSMateusz Guzik printh("\tif (!SDT_PROBES_ENABLED())"); 344848f8effSMateusz Guzik printh("\t\treturn (" args[0]"->v_op->"name"(&a));"); 345848f8effSMateusz Guzik printh("\telse"); 346848f8effSMateusz Guzik printh("\t\treturn (" uname "_APV("args[0]"->v_op, &a));"); 347848f8effSMateusz Guzik printh("#else"); 348848f8effSMateusz Guzik } 349119798b3SPoul-Henning Kamp printh("\treturn (" uname "_APV("args[0]"->v_op, &a));"); 350848f8effSMateusz Guzik if (can_inline(name)) 351848f8effSMateusz Guzik printh("#endif"); 352848f8effSMateusz Guzik 353cf409a0aSJeff Roberson printh("}"); 35463f89abfSPoul-Henning Kamp 35563f89abfSPoul-Henning Kamp printh(""); 356fda3199fSDavid E. O'Brien } 357fda3199fSDavid E. O'Brien 358fda3199fSDavid E. O'Brien if (cfile) { 3596fa079fcSMateusz Guzik funcarr[name] = 1; 360fda3199fSDavid E. O'Brien # Print out the vop_F_vp_offsets structure. This all depends 361fda3199fSDavid E. O'Brien # on naming conventions and nothing else. 362fda3199fSDavid E. O'Brien printc("static int " name "_vp_offsets[] = {"); 363fda3199fSDavid E. O'Brien # as a side effect, figure out the releflags 364fda3199fSDavid E. O'Brien releflags = ""; 365fda3199fSDavid E. O'Brien vpnum = 0; 366fda3199fSDavid E. O'Brien for (i = 0; i < numargs; i++) { 367fda3199fSDavid E. O'Brien if (types[i] == "struct vnode *") { 368fda3199fSDavid E. O'Brien printc("\tVOPARG_OFFSETOF(struct " name \ 369fda3199fSDavid E. O'Brien "_args,a_" args[i] "),"); 370fda3199fSDavid E. O'Brien if (reles[i] == "WILLRELE") { 371fda3199fSDavid E. O'Brien releflags = releflags \ 372fda3199fSDavid E. O'Brien "|VDESC_VP" vpnum "_WILLRELE"; 373fda3199fSDavid E. O'Brien } 374fda3199fSDavid E. O'Brien vpnum++; 375fda3199fSDavid E. O'Brien } 376fda3199fSDavid E. O'Brien } 377fda3199fSDavid E. O'Brien 378fda3199fSDavid E. O'Brien sub(/^\|/, "", releflags); 379fda3199fSDavid E. O'Brien printc("\tVDESC_NO_OFFSET"); 380fda3199fSDavid E. O'Brien printc("};"); 381fda3199fSDavid E. O'Brien 382ff8a07fdSRobert Watson printc("\n"); 383d9fae5abSAndriy Gapon printc("SDT_PROBE_DEFINE2(vfs, vop, " name ", entry, \"struct vnode *\", \"struct " name "_args *\");\n"); 384d9fae5abSAndriy Gapon printc("SDT_PROBE_DEFINE3(vfs, vop, " name ", return, \"struct vnode *\", \"struct " name "_args *\", \"int\");\n"); 385ff8a07fdSRobert Watson 38663f89abfSPoul-Henning Kamp # Print out function. 38763f89abfSPoul-Henning Kamp printc("\nint\n" uname "_AP(struct " name "_args *a)"); 38863f89abfSPoul-Henning Kamp printc("{"); 38963f89abfSPoul-Henning Kamp printc(""); 390119798b3SPoul-Henning Kamp printc("\treturn(" uname "_APV(a->a_" args[0] "->v_op, a));"); 391119798b3SPoul-Henning Kamp printc("}"); 392*cd048d5dSMark Johnston printc("\nint\n" uname "_APV(const struct vop_vector *vop, struct " name "_args *a)"); 393119798b3SPoul-Henning Kamp printc("{"); 394119798b3SPoul-Henning Kamp printc("\tint rc;"); 395119798b3SPoul-Henning Kamp printc(""); 396119798b3SPoul-Henning Kamp printc("\tVNASSERT(a->a_gen.a_desc == &" name "_desc, a->a_" args[0]","); 397119798b3SPoul-Henning Kamp printc("\t (\"Wrong a_desc in " name "(%p, %p)\", a->a_" args[0]", a));"); 398119798b3SPoul-Henning Kamp printc("\tVNASSERT(vop != NULL, a->a_" args[0]", (\"No "name"(%p, %p)\", a->a_" args[0]", a));") 3994c44811cSJeff Roberson printc("\tKTR_START" ctrstr); 400848f8effSMateusz Guzik add_debugpre(name); 401679985d0SSuleiman Souhlal add_pre(name); 40261f67f32SMateusz Guzik for (i = 0; i < numargs; ++i) 40361f67f32SMateusz Guzik add_debug_code(name, args[i], "Entry", "\t"); 4048a6f5fd5SMateusz Guzik printc("\tif (!SDT_PROBES_ENABLED()) {"); 40563f89abfSPoul-Henning Kamp printc("\t\trc = vop->"name"(a);") 40661f67f32SMateusz Guzik printc("\t} else {") 40761f67f32SMateusz Guzik printc("\t\tSDT_PROBE2(vfs, vop, " name ", entry, a->a_" args[0] ", a);"); 4088a6f5fd5SMateusz Guzik printc("\t\trc = vop->"name"(a);") 40961f67f32SMateusz Guzik printc("\t\tSDT_PROBE3(vfs, vop, " name ", return, a->a_" args[0] ", a, rc);"); 41061f67f32SMateusz Guzik printc("\t}") 41163f89abfSPoul-Henning Kamp printc("\tif (rc == 0) {"); 41263f89abfSPoul-Henning Kamp for (i = 0; i < numargs; ++i) 41363f89abfSPoul-Henning Kamp add_debug_code(name, args[i], "OK", "\t\t"); 41463f89abfSPoul-Henning Kamp printc("\t} else {"); 41563f89abfSPoul-Henning Kamp for (i = 0; i < numargs; ++i) 41663f89abfSPoul-Henning Kamp add_debug_code(name, args[i], "Error", "\t\t"); 41763f89abfSPoul-Henning Kamp printc("\t}"); 418679985d0SSuleiman Souhlal add_post(name); 419848f8effSMateusz Guzik add_debugpost(name); 4204c44811cSJeff Roberson printc("\tKTR_STOP" ctrstr); 42163f89abfSPoul-Henning Kamp printc("\treturn (rc);"); 42263f89abfSPoul-Henning Kamp printc("}\n"); 42363f89abfSPoul-Henning Kamp 424fda3199fSDavid E. O'Brien # Print out the vnodeop_desc structure. 425fda3199fSDavid E. O'Brien printc("struct vnodeop_desc " name "_desc = {"); 426fda3199fSDavid E. O'Brien # printable name 427fda3199fSDavid E. O'Brien printc("\t\"" name "\","); 428fda3199fSDavid E. O'Brien # flags 429fda3199fSDavid E. O'Brien vppwillrele = ""; 430fda3199fSDavid E. O'Brien for (i = 0; i < numargs; i++) { 431fda3199fSDavid E. O'Brien if (types[i] == "struct vnode **" && \ 432fda3199fSDavid E. O'Brien reles[i] == "WILLRELE") { 433fda3199fSDavid E. O'Brien vppwillrele = "|VDESC_VPP_WILLRELE"; 434fda3199fSDavid E. O'Brien } 435fda3199fSDavid E. O'Brien } 436fda3199fSDavid E. O'Brien 437fda3199fSDavid E. O'Brien if (!releflags) 438fda3199fSDavid E. O'Brien releflags = "0"; 439fda3199fSDavid E. O'Brien printc("\t" releflags vppwillrele ","); 440fda3199fSDavid E. O'Brien 4418ff7fad1SKonstantin Belousov # index in struct vop_vector 4428ff7fad1SKonstantin Belousov printc("\t__offsetof(struct vop_vector, " name "),"); 44363f89abfSPoul-Henning Kamp # function to call 4440430a5e2SDag-Erling Smørgrav printc("\t(vop_bypass_t *)" uname "_AP,"); 445fda3199fSDavid E. O'Brien # vp offsets 446fda3199fSDavid E. O'Brien printc("\t" name "_vp_offsets,"); 447fda3199fSDavid E. O'Brien # vpp (if any) 448fda3199fSDavid E. O'Brien printc("\t" find_arg_with_type("struct vnode **") ","); 449fda3199fSDavid E. O'Brien # cred (if any) 450fda3199fSDavid E. O'Brien printc("\t" find_arg_with_type("struct ucred *") ","); 451fda3199fSDavid E. O'Brien # thread (if any) 452fda3199fSDavid E. O'Brien printc("\t" find_arg_with_type("struct thread *") ","); 453fda3199fSDavid E. O'Brien # componentname 454fda3199fSDavid E. O'Brien printc("\t" find_arg_with_type("struct componentname *") ","); 455fda3199fSDavid E. O'Brien # transport layer information 456e26b05cfSDag-Erling Smørgrav printc("};\n"); 457fda3199fSDavid E. O'Brien } 458fda3199fSDavid E. O'Brien} 459fda3199fSDavid E. O'Brien 4606fa079fcSMateusz Guzikif (cfile) { 4616fa079fcSMateusz Guzik printc("void"); 4626fa079fcSMateusz Guzik printc("vfs_vector_op_register(struct vop_vector *orig_vop)"); 4636fa079fcSMateusz Guzik printc("{"); 4646fa079fcSMateusz Guzik printc("\tstruct vop_vector *vop;"); 4656fa079fcSMateusz Guzik printc(""); 4666fa079fcSMateusz Guzik printc("\tif (orig_vop->registered)"); 4676fa079fcSMateusz Guzik printc("\t\tpanic(\"%s: vop_vector %p already registered\",") 4686fa079fcSMateusz Guzik printc("\t\t __func__, orig_vop);"); 4696fa079fcSMateusz Guzik printc(""); 4705f6df177SMateusz Guzik printc("\tcache_vop_vector_register(orig_vop);"); 4715f6df177SMateusz Guzik printc(""); 4726fa079fcSMateusz Guzik for (name in funcarr) { 4736fa079fcSMateusz Guzik printc("\tvop = orig_vop;"); 4746fa079fcSMateusz Guzik printc("\twhile (vop != NULL && \\"); 4756fa079fcSMateusz Guzik printc("\t vop->"name" == NULL && vop->vop_bypass == NULL)") 4766fa079fcSMateusz Guzik printc("\t\tvop = vop->vop_default;") 4776fa079fcSMateusz Guzik printc("\tif (vop != NULL)"); 4786fa079fcSMateusz Guzik printc("\t\torig_vop->"name" = vop->"name";"); 4796fa079fcSMateusz Guzik printc(""); 4806fa079fcSMateusz Guzik } 4816fa079fcSMateusz Guzik printc("\tvop = orig_vop;"); 4826fa079fcSMateusz Guzik printc("\twhile (vop != NULL && vop->vop_bypass == NULL)") 4836fa079fcSMateusz Guzik printc("\t\tvop = vop->vop_default;") 4846fa079fcSMateusz Guzik printc("\tif (vop != NULL)"); 4856fa079fcSMateusz Guzik printc("\t\torig_vop->vop_bypass = vop->vop_bypass;"); 4866fa079fcSMateusz Guzik printc(""); 4878a6f5fd5SMateusz Guzik for (name in funcarr) { 4888a6f5fd5SMateusz Guzik printc("\tif (orig_vop->"name" == NULL)"); 4898a6f5fd5SMateusz Guzik printc("\t\torig_vop->"name" = (void *)orig_vop->vop_bypass;"); 4908a6f5fd5SMateusz Guzik } 4918a6f5fd5SMateusz Guzik printc(""); 4926fa079fcSMateusz Guzik printc("\torig_vop->registered = true;"); 4936fa079fcSMateusz Guzik printc("}") 4946fa079fcSMateusz Guzik} 4956fa079fcSMateusz Guzik 4966fa079fcSMateusz Guzikif (hfile) { 4976fa079fcSMateusz Guzik printh("void vfs_vector_op_register(struct vop_vector *orig_vop);"); 4986fa079fcSMateusz Guzik} 4996fa079fcSMateusz Guzik 5006fa079fcSMateusz Guzikif (pfile) { 5016fa079fcSMateusz Guzik printp("\tbool\tregistered;") 502aec0fb7bSPoul-Henning Kamp printp("};") 5036fa079fcSMateusz Guzik} 504aec0fb7bSPoul-Henning Kamp 505fda3199fSDavid E. O'Brienif (hfile) 506fda3199fSDavid E. O'Brien close(hfile); 507fda3199fSDavid E. O'Brienif (cfile) 508fda3199fSDavid E. O'Brien close(cfile); 509aec0fb7bSPoul-Henning Kampif (pfile) 510aec0fb7bSPoul-Henning Kamp close(pfile); 511fda3199fSDavid E. O'Brienclose(srcfile); 512fda3199fSDavid E. O'Brien 513fda3199fSDavid E. O'Brienexit 0; 514fda3199fSDavid E. O'Brien 515fda3199fSDavid E. O'Brien} 516