public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Giuliano Pochini <pochini@shiny.it>
To: linux-scsi@vger.kernel.org
Subject: Re: removable device: can't detect disk changes
Date: Mon, 18 Aug 2008 21:52:57 +0200	[thread overview]
Message-ID: <20080818215257.e1d7700c.pochini@shiny.it> (raw)
In-Reply-To: <20080812150814.a2fd58cd.pochini@shiny.it>

On Tue, 12 Aug 2008 15:08:14 +0200
Giuliano Pochini <pochini@shiny.it> wrote:

> 
> Fujitsu magneto-optical drive, Adaptec 29160 and 
> Linux Jay 2.6.26 #7 SMP Sun Aug 10 18:34:22 CEST 2008 ppc 7455, altivec supported PowerMac3,6 GNU/Linux
> 
> When I insert a disk and I mount it, scsi_test_unit_ready() is called and
> the do-while loop gets sshdr->sense_key == UNIT_ATTENTION in the first
> cycle and 0 in the second one. So the if below misses the UNIT_ATTENTION
> and sdev->changed = 1 is not executed. At this point bad things can
> happen... I'm not sure how to fix this. Any clue ?

Ok... what about this patch ?  The while() condition also checks for
NOT_READY. For removable devices sdev->changed is set when not_ready is
detected (not only if it occurs in the last cycle).
If works fine here, but since I don't know the SCSI subsystem this patch
may be wrong.


Signed-off-by: Giuliano Pochini <pochini@shiny.it>

--- scsi_lib.c__orig	2008-08-18 21:11:45.000000000 +0200
+++ scsi_lib.c	2008-08-18 21:26:56.000000000 +0200
@@ -1961,7 +1961,7 @@ scsi_test_unit_ready(struct scsi_device 
 		TEST_UNIT_READY, 0, 0, 0, 0, 0,
 	};
 	struct scsi_sense_hdr *sshdr;
-	int result;
+	int result, not_ready;
 
 	if (!sshdr_external)
 		sshdr = kzalloc(sizeof(*sshdr), GFP_KERNEL);
@@ -1972,23 +1972,19 @@ scsi_test_unit_ready(struct scsi_device 
 	do {
 		result = scsi_execute_req(sdev, cmd, DMA_NONE, NULL, 0, sshdr,
 					  timeout, retries);
-	} while ((driver_byte(result) & DRIVER_SENSE) &&
-		 sshdr && sshdr->sense_key == UNIT_ATTENTION &&
-		 --retries);
+		not_ready = (driver_byte(result) & DRIVER_SENSE) && sshdr &&
+			    ((sshdr->sense_key == UNIT_ATTENTION) ||
+			     (sshdr->sense_key == NOT_READY));
+		if (not_ready && scsi_sense_valid(sshdr) && sdev->removable)
+			sdev->changed = 1;
+	} while (not_ready && --retries);
 
 	if (!sshdr)
 		/* could not allocate sense buffer, so can't process it */
 		return result;
 
-	if ((driver_byte(result) & DRIVER_SENSE) && sdev->removable) {
-
-		if ((scsi_sense_valid(sshdr)) &&
-		    ((sshdr->sense_key == UNIT_ATTENTION) ||
-		     (sshdr->sense_key == NOT_READY))) {
-			sdev->changed = 1;
+	if (not_ready && scsi_sense_valid(sshdr) && sdev->removable)
 			result = 0;
-		}
-	}
 	if (!sshdr_external)
 		kfree(sshdr);
 	return result;


--
Giuliano.

  reply	other threads:[~2008-08-18 19:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-12 13:08 removable device: can't detect disk changes Giuliano Pochini
2008-08-18 19:52 ` Giuliano Pochini [this message]
2008-08-18 20:58   ` James Bottomley
2008-08-19 22:58     ` Giuliano Pochini
2008-10-13 20:40       ` Giuliano Pochini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080818215257.e1d7700c.pochini@shiny.it \
    --to=pochini@shiny.it \
    --cc=linux-scsi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox