From: Alan Stern 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. 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. Signed-off-by: Alan Stern Cc: James Bottomley Cc: Jens Axboe Signed-off-by: Andrew Morton --- fs/block_dev.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff -puN fs/block_dev.c~block-layer-early-detection-of-medium-not-present fs/block_dev.c --- devel/fs/block_dev.c~block-layer-early-detection-of-medium-not-present 2006-06-06 16:49:00.000000000 -0700 +++ devel-akpm/fs/block_dev.c 2006-06-06 16:49:00.000000000 -0700 @@ -837,14 +837,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); _