Home | History | Annotate | Line # | Download | only in kern
vnode_if.sh revision 1.68.2.2
      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.68.2.2        ad SCRIPT_ID='$NetBSD: vnode_if.sh,v 1.68.2.2 2020/02/29 20:21:03 ad 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.2       gwr #	insert a space beween * 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.44     pooka 	willmake=-1;
    103      1.65   hannken 	fstrans="";
    104       1.2       gwr 	next;
    105       1.2       gwr }
    106       1.2       gwr # Last line of description
    107       1.2       gwr /^}/	{
    108       1.2       gwr 	doit();
    109       1.2       gwr 	next;
    110       1.2       gwr }
    111       1.2       gwr # Middle lines of description
    112       1.2       gwr {
    113      1.60   hannken 	if ($1 == "VERSION") {
    114      1.60   hannken 		args_name=args_name "_v" $2;
    115      1.60   hannken 		next;
    116      1.65   hannken 	} else if ($1 ~ "^FSTRANS=") {
    117      1.65   hannken 		fstrans = $1;
    118      1.65   hannken 		sub("FSTRANS=", "", fstrans);
    119      1.62   hannken 		next;
    120      1.60   hannken 	}
    121      1.60   hannken 
    122       1.2       gwr 	argdir[argc] = $1; i=2;
    123      1.35   thorpej 
    124      1.35   thorpej 	if ($2 == "LOCKED=YES") {
    125      1.35   thorpej 		lockstate[argc] = 1;
    126      1.35   thorpej 		i++;
    127      1.35   thorpej 	} else if ($2 == "LOCKED=NO") {
    128      1.35   thorpej 		lockstate[argc] = 0;
    129      1.35   thorpej 		i++;
    130      1.35   thorpej 	} else
    131      1.35   thorpej 		lockstate[argc] = -1;
    132      1.35   thorpej 
    133      1.35   thorpej 	if ($2 == "WILLRELE" ||
    134      1.35   thorpej 	    $3 == "WILLRELE") {
    135       1.2       gwr 		willrele[argc] = 1;
    136       1.2       gwr 		i++;
    137      1.35   thorpej 	} else if ($2 == "WILLPUT" ||
    138      1.35   thorpej 		   $3 == "WILLPUT") {
    139      1.19  wrstuden 		willrele[argc] = 3;
    140      1.19  wrstuden 		i++;
    141       1.2       gwr 	} else
    142       1.2       gwr 		willrele[argc] = 0;
    143      1.44     pooka 
    144      1.44     pooka 	if ($2 == "WILLMAKE") {
    145      1.44     pooka 		willmake=argc;
    146      1.44     pooka 		i++;
    147      1.44     pooka 	}
    148      1.65   hannken 	if (argc == 0 && fstrans == "") {
    149      1.65   hannken 		if (lockstate[0] == 1)
    150      1.65   hannken 			fstrans = "NO";
    151      1.65   hannken 		else
    152      1.65   hannken 			fstrans = "YES";
    153      1.65   hannken 	}
    154      1.44     pooka 
    155      1.50     pooka 	# XXX: replace non-portable types for rump.  We should really
    156      1.50     pooka 	# nuke the types from the kernel, but that is a battle for
    157      1.50     pooka 	# another day.
    158      1.50     pooka 	at = $i;
    159      1.56     pooka 	if (rump) {
    160      1.50     pooka 		if (at == "vm_prot_t")
    161      1.50     pooka 			at = "int";
    162      1.50     pooka 		if (at == "voff_t")
    163      1.50     pooka 			at = "off_t";
    164      1.56     pooka 		if (at == "kauth_cred_t")
    165      1.56     pooka 			at = "struct kauth_cred *"
    166      1.59     pooka 		if (at == "daddr_t")
    167      1.59     pooka 			at = "int64_t"
    168      1.50     pooka 	}
    169      1.50     pooka 	argtype[argc] = at;
    170      1.50     pooka 	i++;
    171       1.2       gwr 	while (i < NF) {
    172       1.7       cgd 		argtype[argc] = argtype[argc]" "$i;
    173       1.2       gwr 		i++;
    174       1.2       gwr 	}
    175       1.2       gwr 	argname[argc] = $i;
    176       1.2       gwr 	argc++;
    177       1.2       gwr 	next;
    178       1.2       gwr }
    179       1.2       gwr '
    180       1.1   mycroft 
    181      1.15   thorpej # This is put before the copyright on each generated file.
    182       1.9       cgd warning="\
    183      1.15   thorpej /*	@NetBSD@	*/
    184      1.15   thorpej 
    185       1.1   mycroft /*
    186      1.37     perry  * Warning: DO NOT EDIT! This file is automatically generated!
    187       1.2       gwr  * (Modifications made here may easily be lost!)
    188       1.1   mycroft  *
    189       1.9       cgd  * Created from the file:
    190       1.9       cgd  *	${SRC_ID}
    191       1.9       cgd  * by the script:
    192       1.2       gwr  *	${SCRIPT_ID}
    193       1.1   mycroft  */
    194      1.36     perry "
    195       1.2       gwr 
    196       1.7       cgd # This is to satisfy McKusick (get rid of evil spaces 8^)
    197       1.7       cgd anal_retentive='s:\([^/]\*\) :\1:g'
    198       1.2       gwr 
    199      1.50     pooka do_hfile () {
    200       1.2       gwr #
    201       1.2       gwr # Redirect stdout to the H file.
    202       1.2       gwr #
    203      1.50     pooka echo "$0: Creating $1" 1>&2
    204      1.50     pooka exec > $1
    205      1.50     pooka rump=$2
    206       1.1   mycroft 
    207       1.2       gwr # Begin stuff
    208      1.50     pooka if [ -z "${rump}" ]; then
    209      1.50     pooka 	SYS='SYS_'
    210      1.50     pooka else
    211      1.50     pooka 	SYS='RUMP_RUMP'
    212      1.50     pooka fi
    213      1.38     perry echo -n "$warning" | sed -e 's/\$//g;s/@/\$/g;s/ $//'
    214       1.9       cgd echo ""
    215       1.9       cgd echo -n "$copyright"
    216      1.10     mikel echo ''
    217      1.50     pooka echo "#ifndef _${SYS}VNODE_IF_H_"
    218      1.50     pooka echo "#define _${SYS}VNODE_IF_H_"
    219      1.52     pooka if [ ${lockdebug} -ne 0 ] ; then
    220      1.52     pooka 	echo ''
    221      1.52     pooka 	echo '#ifdef _KERNEL_OPT'
    222      1.52     pooka 	echo '#include "opt_vnode_lockdebug.h"'
    223      1.52     pooka 	echo '#endif /* _KERNEL_OPT */'
    224      1.52     pooka fi
    225      1.56     pooka [ -z "${rump}" ] && echo "
    226      1.56     pooka extern const struct vnodeop_desc ${rump}vop_default_desc;"
    227      1.56     pooka echo
    228       1.1   mycroft 
    229       1.2       gwr # Body stuff
    230       1.2       gwr # This awk program needs toupper() so define it if necessary.
    231      1.50     pooka sed -e "$sed_prep" $src | $awk -v rump=${rump} "$toupper"'
    232       1.2       gwr function doit() {
    233      1.56     pooka 	name = rump name
    234       1.2       gwr 	# Declare arg struct, descriptor.
    235      1.56     pooka 	if (!rump) {
    236      1.56     pooka 		printf("\n#define %s_DESCOFFSET %d\n",
    237      1.56     pooka 		    toupper(name), vop_offset++);
    238      1.60   hannken 		printf("struct %s_args {\n", args_name);
    239      1.56     pooka 		printf("\tconst struct vnodeop_desc * a_desc;\n");
    240      1.56     pooka 		for (i=0; i<argc; i++) {
    241      1.56     pooka 			printf("\t%s a_%s;\n", argtype[i], argname[i]);
    242      1.56     pooka 		}
    243      1.56     pooka 		printf("};\n");
    244      1.56     pooka 		printf("extern const struct vnodeop_desc %s_desc;\n", name);
    245       1.1   mycroft 	}
    246       1.8    chopps 	# Prototype it.
    247      1.20   thorpej 	protoarg = sprintf("int %s(", toupper(name));
    248       1.8    chopps 	protolen = length(protoarg);
    249       1.8    chopps 	printf("%s", protoarg);
    250       1.8    chopps 	for (i=0; i<argc; i++) {
    251       1.8    chopps 		protoarg = sprintf("%s", argtype[i]);
    252       1.8    chopps 		if (i < (argc-1)) protoarg = (protoarg ", ");
    253       1.8    chopps 		arglen = length(protoarg);
    254       1.8    chopps 		if ((protolen + arglen) > 77) {
    255       1.8    chopps 			protoarg = ("\n    " protoarg);
    256       1.8    chopps 			arglen += 4;
    257       1.8    chopps 			protolen = 0;
    258       1.8    chopps 		}
    259       1.8    chopps 		printf("%s", protoarg);
    260       1.8    chopps 		protolen += arglen;
    261       1.8    chopps 	}
    262      1.39   thorpej 	printf(");\n");
    263       1.2       gwr }
    264       1.2       gwr BEGIN	{
    265      1.43     pooka 	vop_offset = 1; # start at 1, to count the 'default' op
    266      1.43     pooka 
    267      1.56     pooka 	printf("struct buf;\n");
    268      1.56     pooka 	if (rump) {
    269      1.56     pooka 		printf("struct flock;\n");
    270      1.56     pooka 		printf("struct knote;\n");
    271      1.56     pooka 		printf("struct vm_page;\n");
    272      1.56     pooka 	}
    273      1.56     pooka 	printf("\n#ifndef _KERNEL\n#include <stdbool.h>\n#endif\n");
    274      1.56     pooka 	if (rump)
    275      1.56     pooka 		printf("\n");
    276      1.43     pooka }
    277      1.43     pooka END	{
    278      1.56     pooka 	if (!rump) {
    279      1.56     pooka 		printf("\n#define VNODE_OPS_COUNT\t%d\n", vop_offset);
    280      1.56     pooka 	}
    281       1.2       gwr }
    282       1.7       cgd '"$awk_parser" | sed -e "$anal_retentive"
    283       1.1   mycroft 
    284       1.2       gwr # End stuff
    285      1.10     mikel echo ''
    286      1.50     pooka echo "#endif /* !_${SYS}VNODE_IF_H_ */"
    287      1.50     pooka }
    288      1.50     pooka do_hfile $out_h ''
    289      1.50     pooka do_hfile $out_rumph 'rump_'
    290       1.1   mycroft 
    291      1.50     pooka do_cfile () {
    292       1.2       gwr #
    293       1.2       gwr # Redirect stdout to the C file.
    294       1.2       gwr #
    295      1.50     pooka echo "$0: Creating $1" 1>&2
    296      1.50     pooka exec > $1
    297      1.50     pooka rump=$2
    298       1.1   mycroft 
    299       1.2       gwr # Begin stuff
    300      1.38     perry echo -n "$warning" | sed -e 's/\$//g;s/@/\$/g;s/ $//'
    301       1.9       cgd echo ""
    302       1.9       cgd echo -n "$copyright"
    303      1.30     lukem echo "
    304      1.30     lukem #include <sys/cdefs.h>
    305      1.52     pooka __KERNEL_RCSID(0, \"\$NetBSD\$\");"
    306      1.52     pooka 
    307      1.52     pooka [ ${lockdebug} -ne 0 ] && echo && echo '#include "opt_vnode_lockdebug.h"'
    308      1.30     lukem 
    309      1.21   thorpej echo '
    310       1.1   mycroft #include <sys/param.h>
    311       1.1   mycroft #include <sys/mount.h>
    312      1.20   thorpej #include <sys/buf.h>
    313       1.1   mycroft #include <sys/vnode.h>
    314      1.50     pooka #include <sys/lock.h>'
    315      1.62   hannken [ -z "${rump}" ] && echo '#include <sys/fstrans.h>'
    316      1.53     pooka [ ! -z "${rump}" ] && echo '#include <rump/rumpvnode_if.h>'		\
    317      1.61     pooka 	&& echo '#include <rump-sys/kern.h>'
    318       1.1   mycroft 
    319      1.56     pooka if [ -z "${rump}" ] ; then
    320      1.56     pooka 	echo "
    321      1.67   hannken enum fst_op { FST_NO, FST_YES, FST_LAZY, FST_TRY };
    322      1.65   hannken 
    323      1.65   hannken static inline int
    324      1.65   hannken vop_pre(vnode_t *vp, struct mount **mp, bool *mpsafe, enum fst_op op)
    325      1.65   hannken {
    326      1.65   hannken 	int error;
    327      1.65   hannken 
    328      1.65   hannken 	*mpsafe = (vp->v_vflag & VV_MPSAFE);
    329      1.65   hannken 
    330      1.65   hannken 	if (!*mpsafe) {
    331      1.65   hannken 		KERNEL_LOCK(1, curlwp);
    332      1.65   hannken 	}
    333      1.65   hannken 
    334      1.67   hannken 	if (op == FST_YES || op == FST_LAZY || op == FST_TRY) {
    335      1.65   hannken 		for (;;) {
    336      1.65   hannken 			*mp = vp->v_mount;
    337      1.65   hannken 			if (op == FST_TRY) {
    338      1.66   hannken 				error = fstrans_start_nowait(*mp);
    339      1.65   hannken 				if (error) {
    340      1.65   hannken 					if (!*mpsafe) {
    341      1.65   hannken 						KERNEL_UNLOCK_ONE(curlwp);
    342      1.65   hannken 					}
    343      1.65   hannken 					return error;
    344      1.65   hannken 				}
    345      1.67   hannken 			} else if (op == FST_LAZY) {
    346      1.67   hannken 				fstrans_start_lazy(*mp);
    347      1.65   hannken 			} else {
    348      1.66   hannken 				fstrans_start(*mp);
    349      1.65   hannken 			}
    350      1.65   hannken 			if (__predict_true(*mp == vp->v_mount))
    351      1.65   hannken 				break;
    352      1.65   hannken 			fstrans_done(*mp);
    353      1.65   hannken 		}
    354      1.65   hannken 	} else {
    355      1.65   hannken 		*mp = vp->v_mount;
    356      1.65   hannken 	}
    357      1.65   hannken 
    358      1.65   hannken 	return 0;
    359      1.65   hannken }
    360      1.65   hannken 
    361      1.65   hannken static inline void
    362      1.65   hannken vop_post(vnode_t *vp, struct mount *mp, bool mpsafe, enum fst_op op)
    363      1.65   hannken {
    364      1.65   hannken 
    365      1.67   hannken 	if (op == FST_YES || op == FST_LAZY) {
    366      1.65   hannken 		fstrans_done(mp);
    367      1.65   hannken 	}
    368      1.65   hannken 
    369      1.65   hannken 	if (!mpsafe) {
    370      1.65   hannken 		KERNEL_UNLOCK_ONE(curlwp);
    371      1.65   hannken 	}
    372      1.65   hannken }
    373      1.65   hannken 
    374      1.56     pooka const struct vnodeop_desc vop_default_desc = {"
    375      1.50     pooka echo '	0,
    376       1.1   mycroft 	"default",
    377       1.1   mycroft 	0,
    378       1.1   mycroft 	NULL,
    379       1.1   mycroft 	VDESC_NO_OFFSET,
    380       1.1   mycroft 	VDESC_NO_OFFSET,
    381       1.1   mycroft 	VDESC_NO_OFFSET,
    382       1.1   mycroft };
    383       1.2       gwr '
    384      1.56     pooka fi
    385       1.1   mycroft 
    386       1.2       gwr # Body stuff
    387      1.52     pooka sed -e "$sed_prep" $src | $awk -v rump=${rump} -v lockdebug=${lockdebug} '
    388       1.2       gwr function do_offset(typematch) {
    389       1.2       gwr 	for (i=0; i<argc; i++) {
    390       1.2       gwr 		if (argtype[i] == typematch) {
    391       1.2       gwr 			printf("\tVOPARG_OFFSETOF(struct %s_args, a_%s),\n",
    392      1.60   hannken 				args_name, argname[i]);
    393       1.2       gwr 			return i;
    394       1.2       gwr 		};
    395       1.2       gwr 	};
    396       1.2       gwr 	print "\tVDESC_NO_OFFSET,";
    397       1.2       gwr 	return -1;
    398       1.2       gwr }
    399       1.1   mycroft 
    400      1.56     pooka function offsets() {
    401       1.2       gwr 	# Define offsets array
    402      1.56     pooka 	printf("const int %s_vp_offsets[] = {\n", name);
    403       1.2       gwr 	for (i=0; i<argc; i++) {
    404       1.2       gwr 		if (argtype[i] == "struct vnode *") {
    405       1.2       gwr 			printf ("\tVOPARG_OFFSETOF(struct %s_args,a_%s),\n",
    406      1.60   hannken 				args_name, argname[i]);
    407       1.2       gwr 		}
    408       1.1   mycroft 	}
    409       1.2       gwr 	print "\tVDESC_NO_OFFSET";
    410       1.2       gwr 	print "};";
    411       1.2       gwr 	# Define F_desc
    412      1.28  jdolecek 	printf("const struct vnodeop_desc %s_desc = {\n", name);
    413       1.2       gwr 	# offset
    414      1.43     pooka 	printf ("\t%s_DESCOFFSET,\n", toupper(name));
    415       1.2       gwr 	# printable name
    416       1.2       gwr 	printf ("\t\"%s\",\n", name);
    417       1.2       gwr 	# flags
    418       1.2       gwr 	printf("\t0");
    419       1.2       gwr 	vpnum = 0;
    420       1.2       gwr 	for (i=0; i<argc; i++) {
    421       1.2       gwr 		if (willrele[i]) {
    422      1.63  riastrad 			if (willrele[i] == 3) {
    423      1.19  wrstuden 				word = "PUT";
    424      1.19  wrstuden 			} else {
    425      1.19  wrstuden 				word = "RELE";
    426      1.19  wrstuden 			}
    427      1.57     rmind 			printf(" | VDESC_VP%s_WILL%s", vpnum, word);
    428      1.64  riastrad 		}
    429      1.64  riastrad 		if (argtype[i] == "struct vnode *")
    430       1.2       gwr 			vpnum++;
    431       1.1   mycroft 	}
    432       1.2       gwr 	print ",";
    433       1.2       gwr 	# vp offsets
    434       1.2       gwr 	printf ("\t%s_vp_offsets,\n", name);
    435       1.2       gwr 	# vpp (if any)
    436       1.2       gwr 	do_offset("struct vnode **");
    437       1.2       gwr 	# cred (if any)
    438      1.42      elad 	do_offset("kauth_cred_t");
    439       1.2       gwr 	# componentname
    440       1.2       gwr 	do_offset("struct componentname *");
    441      1.54     pooka 	printf ("};\n");
    442      1.56     pooka }
    443      1.20   thorpej 
    444      1.56     pooka function bodyrump() {
    445      1.56     pooka 	printf("{\n\tint error;\n\n");
    446      1.56     pooka 	printf("\trump_schedule();\n");
    447      1.56     pooka 	printf("\terror = %s(", toupper(name));
    448      1.20   thorpej 	for (i=0; i<argc; i++) {
    449      1.56     pooka 		printf("%s", argname[i]);
    450      1.56     pooka 		if (i < (argc-1)) printf(", ");
    451      1.20   thorpej 	}
    452      1.56     pooka 	printf(");\n");
    453      1.56     pooka 	printf("\trump_unschedule();\n\n");
    454      1.56     pooka 	printf("\treturn error;\n}\n");
    455      1.56     pooka }
    456      1.56     pooka 
    457      1.56     pooka function bodynorm() {
    458      1.60   hannken 	printf("{\n\tint error;\n\tbool mpsafe;\n\tstruct %s_args a;\n",
    459      1.60   hannken 		args_name);
    460      1.65   hannken 	printf("\tstruct mount *mp;\n");
    461      1.52     pooka 	if (lockdebug) {
    462      1.52     pooka 		printf("#ifdef VNODE_LOCKDEBUG\n");
    463      1.52     pooka 		for (i=0; i<argc; i++) {
    464      1.52     pooka 			if (lockstate[i] != -1)
    465      1.52     pooka 				printf("\tint islocked_%s;\n", argname[i]);
    466      1.52     pooka 		}
    467      1.52     pooka 		printf("#endif\n");
    468      1.35   thorpej 	}
    469      1.20   thorpej 	printf("\ta.a_desc = VDESC(%s);\n", name);
    470      1.20   thorpej 	for (i=0; i<argc; i++) {
    471      1.20   thorpej 		printf("\ta.a_%s = %s;\n", argname[i], argname[i]);
    472      1.52     pooka 		if (lockdebug && lockstate[i] != -1) {
    473      1.35   thorpej 			printf("#ifdef VNODE_LOCKDEBUG\n");
    474      1.45        ad 			printf("\tislocked_%s = (%s->v_vflag & VV_LOCKSWORK) ? (VOP_ISLOCKED(%s) == LK_EXCLUSIVE) : %d;\n",
    475      1.35   thorpej 			    argname[i], argname[i], argname[i], lockstate[i]);
    476      1.35   thorpej 			printf("\tif (islocked_%s != %d)\n", argname[i],
    477      1.35   thorpej 			    lockstate[i]);
    478      1.35   thorpej 			printf("\t\tpanic(\"%s: %s: locked %%d, expected %%d\", islocked_%s, %d);\n", name, argname[i], argname[i], lockstate[i]);
    479      1.35   thorpej 			printf("#endif\n");
    480      1.35   thorpej 		}
    481      1.20   thorpej 	}
    482      1.65   hannken 	if (fstrans == "LOCK")
    483      1.65   hannken 		printf("\terror = vop_pre(%s, &mp, &mpsafe, %s);\n",
    484  1.68.2.1        ad 			argname[0], "(!(flags & (LK_SHARED|LK_EXCLUSIVE)) ? FST_NO : (flags & LK_NOWAIT ? FST_TRY : FST_YES))");
    485      1.65   hannken 	else if (fstrans == "UNLOCK")
    486      1.65   hannken 		printf("\terror = vop_pre(%s, &mp, &mpsafe, FST_%s);\n",
    487      1.65   hannken 			argname[0], "NO");
    488      1.65   hannken 	else
    489      1.65   hannken 		printf("\terror = vop_pre(%s, &mp, &mpsafe, FST_%s);\n",
    490      1.65   hannken 			argname[0], fstrans);
    491      1.65   hannken 	printf("\tif (error)\n\t\treturn error;\n");
    492      1.58   hannken 	printf("\terror = (VCALL(%s, VOFFSET(%s), &a));\n",
    493      1.58   hannken 		argname[0], name);
    494      1.65   hannken 	if (fstrans == "LOCK")
    495      1.65   hannken 		printf("\tvop_post(%s, mp, mpsafe, %s);\n",
    496      1.68        ad 			argname[0], "(flags & (LK_UPGRADE|LK_DOWNGRADE) ? FST_NO : (error ? FST_YES : FST_NO))");
    497      1.65   hannken 	else if (fstrans == "UNLOCK")
    498      1.65   hannken 		printf("\tvop_post(%s, mp, mpsafe, FST_%s);\n",
    499      1.65   hannken 			argname[0], "YES");
    500      1.65   hannken 	else
    501      1.65   hannken 		printf("\tvop_post(%s, mp, mpsafe, FST_%s);\n",
    502      1.65   hannken 			argname[0], fstrans);
    503      1.44     pooka 	if (willmake != -1) {
    504      1.44     pooka 		printf("#ifdef DIAGNOSTIC\n");
    505      1.46        ad 		printf("\tif (error == 0)\n"				\
    506      1.44     pooka 		    "\t\tKASSERT((*%s)->v_size != VSIZENOTSET\n"	\
    507      1.44     pooka 		    "\t\t    && (*%s)->v_writesize != VSIZENOTSET);\n",
    508      1.44     pooka 		    argname[willmake], argname[willmake]);
    509      1.44     pooka 		printf("#endif /* DIAGNOSTIC */\n");
    510      1.44     pooka 	}
    511      1.46        ad 	printf("\treturn error;\n}\n");
    512      1.20   thorpej }
    513      1.56     pooka 
    514      1.56     pooka function doit() {
    515      1.56     pooka 	printf("\n");
    516      1.56     pooka 	if (!rump)
    517      1.56     pooka 		offsets();
    518      1.56     pooka 
    519      1.56     pooka 	if (rump)
    520      1.56     pooka 		extname = "RUMP_" toupper(name);
    521      1.56     pooka 	else
    522      1.56     pooka 		extname = toupper(name);
    523      1.56     pooka 
    524      1.56     pooka 	# Define function.
    525      1.56     pooka 	printf("int\n%s(", extname);
    526      1.56     pooka 	for (i=0; i<argc; i++) {
    527      1.56     pooka 		printf("%s %s", argtype[i], argname[i]);
    528      1.56     pooka 		if (i < (argc-1)) printf(",\n    ");
    529      1.56     pooka 	}
    530      1.56     pooka 	printf(")\n");
    531      1.56     pooka 
    532      1.56     pooka 	if (rump)
    533      1.56     pooka 		bodyrump();
    534      1.56     pooka 	else
    535      1.56     pooka 		bodynorm();
    536      1.56     pooka }
    537      1.20   thorpej BEGIN	{
    538      1.28  jdolecek 	# start from 1 (vop_default is at 0)
    539       1.2       gwr 	argc=1;
    540       1.1   mycroft }
    541       1.7       cgd '"$awk_parser" | sed -e "$anal_retentive"
    542       1.1   mycroft 
    543       1.2       gwr # End stuff
    544      1.56     pooka [ -n "${rump}" ] && return
    545       1.1   mycroft 
    546       1.2       gwr # Add the vfs_op_descs array to the C file.
    547       1.2       gwr # Begin stuff
    548      1.50     pooka echo "
    549      1.50     pooka const struct vnodeop_desc * const ${rump}vfs_op_descs[] = {
    550      1.50     pooka 	&${rump}vop_default_desc,	/* MUST BE FIRST */
    551      1.50     pooka "
    552       1.2       gwr 
    553       1.2       gwr # Body stuff
    554      1.50     pooka sed -e "$sed_prep" $src | $awk -v rump=${rump} '
    555       1.2       gwr function doit() {
    556       1.2       gwr 	printf("\t&%s_desc,\n", name);
    557       1.1   mycroft }
    558       1.2       gwr '"$awk_parser"
    559       1.1   mycroft 
    560       1.2       gwr # End stuff
    561       1.2       gwr echo '	NULL
    562      1.55     pooka };'
    563      1.50     pooka }
    564      1.50     pooka do_cfile $out_c ''
    565      1.50     pooka do_cfile $out_rumpc 'rump_'
    566       1.1   mycroft 
    567       1.2       gwr exit 0
    568       1.1   mycroft 
    569       1.2       gwr # Local Variables:
    570       1.2       gwr # tab-width: 4
    571       1.2       gwr # End:
    572