[PATCH 1/3] block layer: early detection of medium not present

From: Alan Stern
Date: Tue Jun 06 2006 - 11:26:01 EST


When the block layer checks for new media in a drive, it uses a two-step
procedure: First it checks for media change and then it revalidates the
disk. When no medium is present the second step fails.

However some drivers (such as the SCSI disk driver) are capable of
detecting medium-not-present as part of the media-changed check. Doing so
will reduce by a factor of 2 or more the amount of work done by tasks
which, like hald, constantly poll empty drives.

This patch (as694) changes the block layer core to make it recognize a
-ENOMEDIUM error return from the media_changed method. A follow-on patch
makes the sd driver return this code when no medium is present.



Signed-off-by: Alan Stern <stern@xxxxxxxxxxxxxxxxxxx>

---

In fact, each sd poll by hald ends up sending 8 (!) SCSI commands: 4 pairs
of TEST UNIT READY plus REQUEST SENSE. These patches will reduce it to
two commands.

As far as I can see, drivers don't return anything other than 0 or 1 for
media_changed, so recognizing this error code shouldn't cause any new
problems.

Index: usb-2.6/fs/block_dev.c
===================================================================
--- usb-2.6.orig/fs/block_dev.c
+++ usb-2.6/fs/block_dev.c
@@ -818,14 +818,18 @@ int check_disk_change(struct block_devic
{
struct gendisk *disk = bdev->bd_disk;
struct block_device_operations * bdops = disk->fops;
+ int rc;

if (!bdops->media_changed)
return 0;
- if (!bdops->media_changed(bdev->bd_disk))
+ rc = bdops->media_changed(bdev->bd_disk);
+ if (!rc)
return 0;

if (__invalidate_device(bdev))
printk("VFS: busy inodes on changed media.\n");
+ if (rc == -ENOMEDIUM)
+ return 1;

if (bdops->revalidate_disk)
bdops->revalidate_disk(bdev->bd_disk);

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/