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