possible bug in ll_rw_blk.c in 2.0.x and 2.1.x

Chris Dent (cdent@kiva.net)
Sat, 15 Nov 1997 19:37:24 -0500 (EST)


I think I may have found a possible bug (or a misfeature caused by
some bad planning) in driver/block/ll_rw_blk.c in add_request. It is
also possible that I'm misunderstanding the code. I'm doing most of my
poking in 2.0.30pre(9|10) but the code looks the same in 2.1.64.

In there a switch is done to determine the disk_index to provide to
drive_stat_acct. If a system has both and hda and sda (but not both
hdb and sdb) the disk_index numbers will collide:

switch (MAJOR(req->rq_dev)) {
case SCSI_DISK_MAJOR:
disk_index = (MINOR(req->rq_dev) & 0x0070) >> 4;
if (disk_index < 4)
drive_stat_acct(req->cmd, req->nr_sectors, disk_index);
break;
case IDE0_MAJOR: /* same as HD_MAJOR */
case XT_DISK_MAJOR:
disk_index = (MINOR(req->rq_dev) & 0x0040) >> 6;
drive_stat_acct(req->cmd, req->nr_sectors, disk_index);
break;
case IDE1_MAJOR:
disk_index = ((MINOR(req->rq_dev) & 0x0040) >> 6) + 2;
drive_stat_acct(req->cmd, req->nr_sectors, disk_index);
default:
break;
}

[kiva@telegraph /dev]$ ls -l hda sda hdb sdb
brw-rw---- 1 root disk 3, 0 Sep 7 1994 hda
brw-rw---- 1 root disk 3, 64 Sep 7 1994 hdb
brw-rw---- 1 root disk 8, 0 Sep 12 1994 sda
brw-rw---- 1 root disk 8, 16 Sep 12 1994 sdb

In the case of minor number 0 for both SCSI and IDE0 disk_index
comes out 0, correct? It looks like there may be other collisions
as well. I'm afraid I can't offer up any code for a solution, there
doesn't appear to be a simple one and my math skills won't carry me
to the hard ones. I'm happy to test out any suggestions though.

In general the disk_index scheme doesn't seem quite right: it doesn't
make it easy to know which disk is being talked about when looking at
/proc/stat (or an iostat that reads /proc/stat).

I discovered this in my pursuit of good iostat output.

If someone does patch something into the kernel for this I would also
suggest including something along the line of what Terje Malmedal
supported in a message with subject: disk reporting in /proc/stat on
Oct 7, 1997. It allows greater than 4 disks to be reported.

Thanks for listening.