public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] block layer: early detection of medium not present
@ 2006-06-06 15:26 Alan Stern
  2006-06-09  1:07 ` James Bottomley
  0 siblings, 1 reply; 5+ messages in thread
From: Alan Stern @ 2006-06-06 15:26 UTC (permalink / raw)
  To: Andrew Morton, Jens Axboe, James Bottomley
  Cc: Kernel development list, SCSI development list

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@rowland.harvard.edu>

---

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);


^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: [PATCH 1/3] block layer: early detection of medium not present
@ 2006-06-26 14:37 Alan Stern
  0 siblings, 0 replies; 5+ messages in thread
From: Alan Stern @ 2006-06-26 14:37 UTC (permalink / raw)
  To: Jens Axboe; +Cc: James Bottomley, Andrew Morton, Kernel development list

Jens:

Do you have any comments on my proposal to combine media-change detection
with no-media-present detection?

http://marc.theaimsgroup.com/?l=linux-kernel&m=114960763313366&w=2

Alan Stern


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-06-26 14:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-06 15:26 [PATCH 1/3] block layer: early detection of medium not present Alan Stern
2006-06-09  1:07 ` James Bottomley
2006-06-09 14:17   ` Alan Stern
2006-06-09 14:19     ` Jens Axboe
  -- strict thread matches above, loose matches on Subject: below --
2006-06-26 14:37 Alan Stern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox