Strange code in revalidate_scsidisk
Hi, Guys:
Here's a short summary to provide the context for my question. Fujitsu report a lockup (on RHEL3, but the code is the same as 2.6). They hook up a USB connected MO drive with three partitions and do:
while : ; do fsck -t ext2 -p -y /dev/sdb1 & fsck -t ext2 -p -y \
/dev/sdb2 & fsck -t ext2 -p -y /dev/sdb3 ; done
If the drive is unplugged, the system hangs. They were able to capture netdump logs and cores and came up with a patch which replaced rdisk->busy flag with a semaphore.
My theory is that the following loop is to blame:
static int sd_open(struct inode *inode, struct file *filp)
{
/*
* Make sure that only one process can do a check_change_disk at one time.
* This is also used to lock out further access when the partition table
* is being re-read.
*/
while (rscsi_disks[target].device->busy) {
barrier();
cpu_relax();
}........
First process sets the busy flag and sleeps. Remaining processes take a CPU each, lock the usb-storage thread out, and no progress can be made thereafter.
Now, the question is: is there a specific reason to avoid waiting in the following fragment:
#define DEVICE_BUSY rscsi_disks[target].device->busy int revalidate_scsidisk(kdev_t dev, int maxusage)
{
target = DEVICE_NR(dev);
if (DEVICE_BUSY || (ALLOW_REVALIDATE == 0 && USAGE > maxusage)) {
printk("Device busy for revalidation (usage=%d)\n", USAGE);
return -EBUSY;
}
DEVICE_BUSY = 1;
........ lotsa code ..........
DEVICE_BUSY = 0;
}What happens if we just take the necessary semaphore here? In other words:
revalidate_scsidisk()
{
if ((ALLOW_REVALIDATE == 0 && USAGE > maxusage)) {
printk("Device busy for revalidation (usage=%d)\n", USAGE);
return -EBUSY;
}
down(&rscsi_disks[target].device->busy_sem);
........ lotsa code ..........
up(&rscsi_disks[target].device->busy_sem);
}Thanks,
-- Pete
Quoted 4 lines · Pete Zaitcev
Hi, Guys:
Here's a short summary to provide the context for my question. Fujitsu report a lockup (on RHEL3, but the code is the same as 2.6). They hook up a USB
Actually the code looks completely different in 2.6. And yes, the 2.4 code looks extremly fishy.
Quoted 7 lines · On Tue, 14 Sep 2004 23:37:43 +0100 Christoph Hellwig <[email protected]> wrote:
Quoted 2 lines · Pete Zaitcev
Here's a short summary to provide the context for my question. Fujitsu report a lockup (on RHEL3, but the code is the same as 2.6). They hook up a USB
Actually the code looks completely different in 2.6. And yes, the 2.4 code looks extremly fishy.
I must've changed to a wrong directory by accident. Sorry for the confusion.
-- Pete