Subject: panic: getblk: block size invariant failed
To: None <tech-kern@netbsd.org>
From: Tad Hunt <tad@entrisphere.com>
List: tech-kern
Date: 11/21/2001 16:08:11
I can reliably reproduce the above panic, on NetBSD-1.5-i386, when
doing disklabel(5) related stuff.

If I have a fd open to the raw partition, and from that program,
I modify the disklabel such that the raw partition changes, do an
ioctl(fd, DIOCSDINFO, &label), then lseek(2) to the disklabel
block, and write(2) the new disklabel, then I get this panic.

If I write(2) the new disklabel, *then* do the ioctl(2), everything
is happy and there is no panic.  I would expect any operation on
the fd I have open to the partition that changed to fail with
errno set to something, rather than panic.

I'm using a modified version of the "bsdlabel" program written by
mouse@Rodents.Montreal.QC.CA to write a NetBSD-mpc8260 (powerpc)
disklabel from an NetBSD-i386 box.  I've uploaded this version of
the bsdlabel program to http://www.csh-east.org/~tad/bsdlabel.c

The panic comes from inside an #ifdef DIAGNOSTIC in kern/vfs_bio.c.
It appears as though the panic results when finding the requested
block in the cache with a size smaller than the requested size.
The comment at the head of the getblk() function states:

	" ... It is up to the caller to insure that the cached
	blocks be of the correct size."

If this is true, wouldn't that imply the diagnostic check is bogus?

When the panic occurs, bp->b_count is 2048, and size is 8192, if
that makes any difference.

-Tad