linux-scsi.vger.kernel.org archive mirror
 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; 4+ 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] 4+ messages in thread

* Re: [PATCH 1/3] block layer: early detection of medium not present
  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
  0 siblings, 1 reply; 4+ messages in thread
From: James Bottomley @ 2006-06-09  1:07 UTC (permalink / raw)
  To: Alan Stern
  Cc: Andrew Morton, Jens Axboe, Kernel development list,
	SCSI development list

On Tue, 2006-06-06 at 11:26 -0400, Alan Stern wrote:
> 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.

I'm not sure there's enough buy in to make this change yet ... our media
change handling is incredibly (and quite possibly far too) complex.

As documented in Documentation/cdrom/cdrom-standard.tex, the return
codes for media change are either 0 or 1.

Personally, I can't see a problem with overloading the true return to
have more information that the error codes provide, but before we do
this we need the buy in of the cdrom layer, since that's where this
handling came from, and we need to update the documents to reflect the
new behaviour ... someone also needs to consider what changes should be
made in the cdrom layer for this (and whether this is actually the
correct way to do this from the point of view of CDs).

James

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

* Re: [PATCH 1/3] block layer: early detection of medium not present
  2006-06-09  1:07 ` James Bottomley
@ 2006-06-09 14:17   ` Alan Stern
  2006-06-09 14:19     ` Jens Axboe
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Stern @ 2006-06-09 14:17 UTC (permalink / raw)
  To: James Bottomley
  Cc: Andrew Morton, Jens Axboe, Kernel development list,
	SCSI development list

On Thu, 8 Jun 2006, James Bottomley wrote:

> On Tue, 2006-06-06 at 11:26 -0400, Alan Stern wrote:
> > 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.
> 
> I'm not sure there's enough buy in to make this change yet ... our media
> change handling is incredibly (and quite possibly far too) complex.
> 
> As documented in Documentation/cdrom/cdrom-standard.tex, the return
> codes for media change are either 0 or 1.

I can change the documentation, if necessary.  On the other hand, I don't 
want to embark on a global alteration of the media-change handling 
throughout the entire kernel!  :-)

> Personally, I can't see a problem with overloading the true return to
> have more information that the error codes provide, but before we do
> this we need the buy in of the cdrom layer, since that's where this
> handling came from, and we need to update the documents to reflect the
> new behaviour ... someone also needs to consider what changes should be
> made in the cdrom layer for this (and whether this is actually the
> correct way to do this from the point of view of CDs).

Agreed.  That's why I cc'ed Jens.  Is there anyone else I should also ask
about this change?

Alan Stern


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

* Re: [PATCH 1/3] block layer: early detection of medium not present
  2006-06-09 14:17   ` Alan Stern
@ 2006-06-09 14:19     ` Jens Axboe
  0 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2006-06-09 14:19 UTC (permalink / raw)
  To: Alan Stern
  Cc: James Bottomley, Andrew Morton, Kernel development list,
	SCSI development list

On Fri, Jun 09 2006, Alan Stern wrote:
> On Thu, 8 Jun 2006, James Bottomley wrote:
> 
> > On Tue, 2006-06-06 at 11:26 -0400, Alan Stern wrote:
> > > 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.
> > 
> > I'm not sure there's enough buy in to make this change yet ... our media
> > change handling is incredibly (and quite possibly far too) complex.
> > 
> > As documented in Documentation/cdrom/cdrom-standard.tex, the return
> > codes for media change are either 0 or 1.
> 
> I can change the documentation, if necessary.  On the other hand, I don't 
> want to embark on a global alteration of the media-change handling 
> throughout the entire kernel!  :-)
> 
> > Personally, I can't see a problem with overloading the true return to
> > have more information that the error codes provide, but before we do
> > this we need the buy in of the cdrom layer, since that's where this
> > handling came from, and we need to update the documents to reflect the
> > new behaviour ... someone also needs to consider what changes should be
> > made in the cdrom layer for this (and whether this is actually the
> > correct way to do this from the point of view of CDs).
> 
> Agreed.  That's why I cc'ed Jens.  Is there anyone else I should also ask
> about this change?

I'll be gone over the weekend, I can take a look next week.

-- 
Jens Axboe


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

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

Thread overview: 4+ 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).