Add an assert that v_holdcnt >= v_usecount?

Edward Tomasz Napierała trasz at FreeBSD.org
Sat May 17 20:58:04 UTC 2014


Wiadomość napisana przez Konstantin Belousov w dniu 17 maj 2014, o godz. 21:22:
> On Sat, May 17, 2014 at 01:48:11PM -0400, Benjamin Kaduk wrote:
>> jhb was helping me debug a crashy openafs build in one of my VMs, and the 
>> symptoms seemed to indicate that a vnode had been partially destroyed 
>> before vgone() was called from vflush(), as if some buggy filesystem code 
>> had called vdrop() instead of vrele() or something similar.  In a quick 
>> check, it didn't look like we had any assertions that would catch such 
>> bugs, so I tried adding something like this:
>> 
>> Index: sys/kern/vfs_subr.c
>> ===================================================================
>> --- sys/kern/vfs_subr.c	(revision 266330)
>> +++ sys/kern/vfs_subr.c	(working copy)
>> @@ -2343,6 +2343,8 @@
>>  	if (vp->v_holdcnt <= 0)
>>  		panic("vdrop: holdcnt %d", vp->v_holdcnt);
>>  	vp->v_holdcnt--;
>> +	VNASSERT(vp->v_holdcnt >= vp->v_usecount, vp,
>> +	    ("hold count less than use count"));
>>  	if (vp->v_holdcnt > 0) {
>>  		VI_UNLOCK(vp);
>>  		return;
>> 
>> Does that seem like something that would be generally useful?
> 
> This is reasonable.
> 
> As a note, I never seen such corruption of the otherwise valid vnode state 
> ever.  There were a lot of leaks, but never mismatched vget/vdrop.

In a filesystem that's already in the tree, or being developed by someone
who knows how VFS works - sure.  But assertions like this are great time
saver for someone who is new to VFS.



More information about the freebsd-fs mailing list