Tue Sep 29 11:51:02 2009 UTC ()
Add a switch on whether to create VNODE_LOCKDEBUG checks or not.
Since VNODE_LOCKDEBUG has never been generally useful, default to
off.  However, the checks can still be generated by flipping the
switch for the isolated cases where this form of dynamic analysis
is useful and the person using it knows what she is doing.


(pooka)
diff -r1.51 -r1.52 src/sys/kern/vnode_if.sh

cvs diff -r1.51 -r1.52 src/sys/kern/vnode_if.sh (expand / switch to unified diff)

--- src/sys/kern/vnode_if.sh 2008/11/19 14:10:49 1.51
+++ src/sys/kern/vnode_if.sh 2009/09/29 11:51:02 1.52
@@ -19,49 +19,52 @@ copyright="\ @@ -19,49 +19,52 @@ copyright="\
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS \`\`AS IS'' AND 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 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 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 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 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 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31" 31"
32SCRIPT_ID='$NetBSD: vnode_if.sh,v 1.51 2008/11/19 14:10:49 pooka Exp $' 32SCRIPT_ID='$NetBSD: vnode_if.sh,v 1.52 2009/09/29 11:51:02 pooka Exp $'
33 33
34# Script to produce VFS front-end sugar. 34# Script to produce VFS front-end sugar.
35# 35#
36# usage: vnode_if.sh srcfile 36# usage: vnode_if.sh srcfile
37# (where srcfile is currently /sys/kern/vnode_if.src) 37# (where srcfile is currently /sys/kern/vnode_if.src)
38# 38#
39 39
40if [ $# -ne 1 ] ; then 40if [ $# -ne 1 ] ; then
41 echo 'usage: vnode_if.sh srcfile' 41 echo 'usage: vnode_if.sh srcfile'
42 exit 1 42 exit 1
43fi 43fi
44 44
45# Name and revision of the source file. 45# Name and revision of the source file.
46src=$1 46src=$1
47SRC_ID=`head -1 $src | sed -e 's/.*\$\(.*\)\$.*/\1/'` 47SRC_ID=`head -1 $src | sed -e 's/.*\$\(.*\)\$.*/\1/'`
48 48
49# Names of the created files. 49# Names of the created files.
50out_c=vnode_if.c 50out_c=vnode_if.c
51out_rumpc=../rump/librump/rumpvfs/rumpvnode_if.c 51out_rumpc=../rump/librump/rumpvfs/rumpvnode_if.c
52out_h=../sys/vnode_if.h 52out_h=../sys/vnode_if.h
53out_rumph=../rump/include/rump/rumpvnode_if.h 53out_rumph=../rump/include/rump/rumpvnode_if.h
54 54
 55# generate VNODE_LOCKDEBUG checks (not fully functional)
 56lockdebug=0
 57
55# Awk program (must support nawk extensions) 58# Awk program (must support nawk extensions)
56# Use "awk" at Berkeley, "nawk" or "gawk" elsewhere. 59# Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
57awk=${AWK:-awk} 60awk=${AWK:-awk}
58 61
59# Does this awk have a "toupper" function? (i.e. is it GNU awk) 62# Does this awk have a "toupper" function? (i.e. is it GNU awk)
60isgawk=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null` 63isgawk=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
61 64
62# If this awk does not define "toupper" then define our own. 65# If this awk does not define "toupper" then define our own.
63if [ "$isgawk" = TRUE ] ; then 66if [ "$isgawk" = TRUE ] ; then
64 # GNU awk provides it. 67 # GNU awk provides it.
65 toupper= 68 toupper=
66else 69else
67 # Provide our own toupper() 70 # Provide our own toupper()
@@ -186,30 +189,32 @@ rump=$2 @@ -186,30 +189,32 @@ rump=$2
186 189
187# Begin stuff 190# Begin stuff
188if [ -z "${rump}" ]; then 191if [ -z "${rump}" ]; then
189 SYS='SYS_' 192 SYS='SYS_'
190else 193else
191 SYS='RUMP_RUMP' 194 SYS='RUMP_RUMP'
192fi 195fi
193echo -n "$warning" | sed -e 's/\$//g;s/@/\$/g;s/ $//' 196echo -n "$warning" | sed -e 's/\$//g;s/@/\$/g;s/ $//'
194echo "" 197echo ""
195echo -n "$copyright" 198echo -n "$copyright"
196echo '' 199echo ''
197echo "#ifndef _${SYS}VNODE_IF_H_" 200echo "#ifndef _${SYS}VNODE_IF_H_"
198echo "#define _${SYS}VNODE_IF_H_" 201echo "#define _${SYS}VNODE_IF_H_"
199echo '' 202if [ ${lockdebug} -ne 0 ] ; then
200echo '#ifdef _KERNEL_OPT' 203 echo ''
201echo '#include "opt_vnode_lockdebug.h"' 204 echo '#ifdef _KERNEL_OPT'
202echo '#endif /* _KERNEL_OPT */' 205 echo '#include "opt_vnode_lockdebug.h"'
 206 echo '#endif /* _KERNEL_OPT */'
 207fi
203echo " 208echo "
204extern const struct vnodeop_desc ${rump}vop_default_desc; 209extern const struct vnodeop_desc ${rump}vop_default_desc;
205" 210"
206 211
207# Body stuff 212# Body stuff
208# This awk program needs toupper() so define it if necessary. 213# This awk program needs toupper() so define it if necessary.
209sed -e "$sed_prep" $src | $awk -v rump=${rump} "$toupper"' 214sed -e "$sed_prep" $src | $awk -v rump=${rump} "$toupper"'
210function doit() { 215function doit() {
211 # Declare arg struct, descriptor. 216 # Declare arg struct, descriptor.
212 printf("\n#define %s_DESCOFFSET %d\n", toupper(name), vop_offset++); 217 printf("\n#define %s_DESCOFFSET %d\n", toupper(name), vop_offset++);
213 printf("struct %s_args {\n", name); 218 printf("struct %s_args {\n", name);
214 printf("\tconst struct vnodeop_desc * a_desc;\n"); 219 printf("\tconst struct vnodeop_desc * a_desc;\n");
215 for (i=0; i<argc; i++) { 220 for (i=0; i<argc; i++) {
@@ -269,54 +274,53 @@ do_cfile () { @@ -269,54 +274,53 @@ do_cfile () {
269# 274#
270# Redirect stdout to the C file. 275# Redirect stdout to the C file.
271# 276#
272echo "$0: Creating $1" 1>&2 277echo "$0: Creating $1" 1>&2
273exec > $1 278exec > $1
274rump=$2 279rump=$2
275 280
276# Begin stuff 281# Begin stuff
277echo -n "$warning" | sed -e 's/\$//g;s/@/\$/g;s/ $//' 282echo -n "$warning" | sed -e 's/\$//g;s/@/\$/g;s/ $//'
278echo "" 283echo ""
279echo -n "$copyright" 284echo -n "$copyright"
280echo " 285echo "
281#include <sys/cdefs.h> 286#include <sys/cdefs.h>
282__KERNEL_RCSID(0, \"\$NetBSD\$\"); 287__KERNEL_RCSID(0, \"\$NetBSD\$\");"
283" 288
 289[ ${lockdebug} -ne 0 ] && echo && echo '#include "opt_vnode_lockdebug.h"'
284 290
285echo ' 
286#include "opt_vnode_lockdebug.h"' 
287echo ' 291echo '
288#include <sys/param.h> 292#include <sys/param.h>
289#include <sys/mount.h> 293#include <sys/mount.h>
290#include <sys/buf.h> 294#include <sys/buf.h>
291#include <sys/vnode.h> 295#include <sys/vnode.h>
292#include <sys/lock.h>' 296#include <sys/lock.h>'
293[ ! -z "${rump}" ] && echo '#include <rump/rumpvnode_if.h>' 297[ ! -z "${rump}" ] && echo '#include <rump/rumpvnode_if.h>'
294 298
295echo " 299echo "
296const struct vnodeop_desc ${rump}vop_default_desc = {" 300const struct vnodeop_desc ${rump}vop_default_desc = {"
297echo ' 0, 301echo ' 0,
298 "default", 302 "default",
299 0, 303 0,
300 NULL, 304 NULL,
301 VDESC_NO_OFFSET, 305 VDESC_NO_OFFSET,
302 VDESC_NO_OFFSET, 306 VDESC_NO_OFFSET,
303 VDESC_NO_OFFSET, 307 VDESC_NO_OFFSET,
304 NULL, 308 NULL,
305}; 309};
306' 310'
307 311
308# Body stuff 312# Body stuff
309sed -e "$sed_prep" $src | $awk -v rump=${rump} ' 313sed -e "$sed_prep" $src | $awk -v rump=${rump} -v lockdebug=${lockdebug} '
310function do_offset(typematch) { 314function do_offset(typematch) {
311 for (i=0; i<argc; i++) { 315 for (i=0; i<argc; i++) {
312 if (argtype[i] == typematch) { 316 if (argtype[i] == typematch) {
313 printf("\tVOPARG_OFFSETOF(struct %s_args, a_%s),\n", 317 printf("\tVOPARG_OFFSETOF(struct %s_args, a_%s),\n",
314 name, argname[i]); 318 name, argname[i]);
315 return i; 319 return i;
316 }; 320 };
317 }; 321 };
318 print "\tVDESC_NO_OFFSET,"; 322 print "\tVDESC_NO_OFFSET,";
319 return -1; 323 return -1;
320} 324}
321 325
322function doit() { 326function doit() {
@@ -366,36 +370,38 @@ function doit() { @@ -366,36 +370,38 @@ function doit() {
366 # componentname 370 # componentname
367 do_offset("struct componentname *"); 371 do_offset("struct componentname *");
368 # transport layer information 372 # transport layer information
369 printf ("\tNULL,\n};\n"); 373 printf ("\tNULL,\n};\n");
370 374
371 # Define function. 375 # Define function.
372 printf("int\n%s(", toupper(name)); 376 printf("int\n%s(", toupper(name));
373 for (i=0; i<argc; i++) { 377 for (i=0; i<argc; i++) {
374 printf("%s %s", argtype[i], argname[i]); 378 printf("%s %s", argtype[i], argname[i]);
375 if (i < (argc-1)) printf(",\n "); 379 if (i < (argc-1)) printf(",\n ");
376 } 380 }
377 printf(")\n"); 381 printf(")\n");
378 printf("{\n\tint error;\n\tbool mpsafe;\n\tstruct %s_args a;\n", name); 382 printf("{\n\tint error;\n\tbool mpsafe;\n\tstruct %s_args a;\n", name);
379 printf("#ifdef VNODE_LOCKDEBUG\n"); 383 if (lockdebug) {
380 for (i=0; i<argc; i++) { 384 printf("#ifdef VNODE_LOCKDEBUG\n");
381 if (lockstate[i] != -1) 385 for (i=0; i<argc; i++) {
382 printf("\tint islocked_%s;\n", argname[i]); 386 if (lockstate[i] != -1)
 387 printf("\tint islocked_%s;\n", argname[i]);
 388 }
 389 printf("#endif\n");
383 } 390 }
384 printf("#endif\n"); 
385 printf("\ta.a_desc = VDESC(%s);\n", name); 391 printf("\ta.a_desc = VDESC(%s);\n", name);
386 for (i=0; i<argc; i++) { 392 for (i=0; i<argc; i++) {
387 printf("\ta.a_%s = %s;\n", argname[i], argname[i]); 393 printf("\ta.a_%s = %s;\n", argname[i], argname[i]);
388 if (lockstate[i] != -1) { 394 if (lockdebug && lockstate[i] != -1) {
389 printf("#ifdef VNODE_LOCKDEBUG\n"); 395 printf("#ifdef VNODE_LOCKDEBUG\n");
390 printf("\tislocked_%s = (%s->v_vflag & VV_LOCKSWORK) ? (VOP_ISLOCKED(%s) == LK_EXCLUSIVE) : %d;\n", 396 printf("\tislocked_%s = (%s->v_vflag & VV_LOCKSWORK) ? (VOP_ISLOCKED(%s) == LK_EXCLUSIVE) : %d;\n",
391 argname[i], argname[i], argname[i], lockstate[i]); 397 argname[i], argname[i], argname[i], lockstate[i]);
392 printf("\tif (islocked_%s != %d)\n", argname[i], 398 printf("\tif (islocked_%s != %d)\n", argname[i],
393 lockstate[i]); 399 lockstate[i]);
394 printf("\t\tpanic(\"%s: %s: locked %%d, expected %%d\", islocked_%s, %d);\n", name, argname[i], argname[i], lockstate[i]); 400 printf("\t\tpanic(\"%s: %s: locked %%d, expected %%d\", islocked_%s, %d);\n", name, argname[i], argname[i], lockstate[i]);
395 printf("#endif\n"); 401 printf("#endif\n");
396 } 402 }
397 } 403 }
398 printf("\tmpsafe = (%s%s->v_vflag & VV_MPSAFE);\n", argname[0], arg0special); 404 printf("\tmpsafe = (%s%s->v_vflag & VV_MPSAFE);\n", argname[0], arg0special);
399 printf("\tif (!mpsafe) { KERNEL_LOCK(1, curlwp); }\n"); 405 printf("\tif (!mpsafe) { KERNEL_LOCK(1, curlwp); }\n");
400 printf("\terror = (VCALL(%s%s, VOFFSET(%s), &a));\n", 406 printf("\terror = (VCALL(%s%s, VOFFSET(%s), &a));\n",
401 argname[0], arg0special, name); 407 argname[0], arg0special, name);