Commit 32c356d76d7e13dcd0675189d8e9c64ef66aa561

Authored by James Bottomley
1 parent 26e9a39777

[SCSI] fix removable device inability to detect disk changes

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 ?

The problem is essentially caused by us eating UNIT_ATTENTION
conditions in scsi_test_unit_ready().  Fix by updating the ->changed
flag when this happens if the media is removable.

[pochini@shiny.it: updates to tidy up patch]
Signed-off-by: Giuliano Pochini <pochini@shiny.it>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>

Showing 1 changed file with 10 additions and 11 deletions Side-by-side Diff

drivers/scsi/scsi_lib.c
... ... @@ -2105,22 +2105,21 @@
2105 2105 do {
2106 2106 result = scsi_execute_req(sdev, cmd, DMA_NONE, NULL, 0, sshdr,
2107 2107 timeout, retries);
2108   - } while ((driver_byte(result) & DRIVER_SENSE) &&
2109   - sshdr && sshdr->sense_key == UNIT_ATTENTION &&
2110   - --retries);
  2108 + if (sdev->removable && scsi_sense_valid(sshdr) &&
  2109 + sshdr->sense_key == UNIT_ATTENTION)
  2110 + sdev->changed = 1;
  2111 + } while (scsi_sense_valid(sshdr) &&
  2112 + sshdr->sense_key == UNIT_ATTENTION && --retries);
2111 2113  
2112 2114 if (!sshdr)
2113 2115 /* could not allocate sense buffer, so can't process it */
2114 2116 return result;
2115 2117  
2116   - if ((driver_byte(result) & DRIVER_SENSE) && sdev->removable) {
2117   -
2118   - if ((scsi_sense_valid(sshdr)) &&
2119   - ((sshdr->sense_key == UNIT_ATTENTION) ||
2120   - (sshdr->sense_key == NOT_READY))) {
2121   - sdev->changed = 1;
2122   - result = 0;
2123   - }
  2118 + if (sdev->removable && scsi_sense_valid(sshdr) &&
  2119 + (sshdr->sense_key == UNIT_ATTENTION ||
  2120 + sshdr->sense_key == NOT_READY)) {
  2121 + sdev->changed = 1;
  2122 + result = 0;
2124 2123 }
2125 2124 if (!sshdr_external)
2126 2125 kfree(sshdr);