diff options
author | James Bottomley <James.Bottomley@suse.de> | 2010-04-01 10:30:01 -0400 |
---|---|---|
committer | James Bottomley <James.Bottomley@suse.de> | 2010-04-11 14:36:26 -0400 |
commit | 3233ac19811fe17033b537832ca7b59df8bf4aa9 (patch) | |
tree | 33c316cf6821d8c3a98624266324d318d50c47fb /drivers/scsi/sd.c | |
parent | 1469585309bb52869cbaa449c6d2cd1ce9869cca (diff) |
[SCSI] sd: retry read_capacity on UNIT_ATTENTION
Hazard testing uncovered yet another bug in sd. Under heavy reset
activity the retry counter might be exhausted and the command will be
returned with sense UNIT_ATTENTION/0x29/00 (POWER ON, RESET, OR BUS
DEVICE RESET OCCURRED). In those cases we should just increase the
retry counter again, retrying one more to clear up this Unit Attention
state.
[jejb: update to work with RC16 devices and not to loop endlessly]
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
Diffstat (limited to 'drivers/scsi/sd.c')
-rw-r--r-- | drivers/scsi/sd.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 7955bc226125..015a597a852e 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c | |||
@@ -1433,6 +1433,8 @@ static void read_capacity_error(struct scsi_disk *sdkp, struct scsi_device *sdp, | |||
1433 | #error RC16_LEN must not be more than SD_BUF_SIZE | 1433 | #error RC16_LEN must not be more than SD_BUF_SIZE |
1434 | #endif | 1434 | #endif |
1435 | 1435 | ||
1436 | #define READ_CAPACITY_RETRIES_ON_RESET 10 | ||
1437 | |||
1436 | static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp, | 1438 | static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp, |
1437 | unsigned char *buffer) | 1439 | unsigned char *buffer) |
1438 | { | 1440 | { |
@@ -1440,7 +1442,7 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp, | |||
1440 | struct scsi_sense_hdr sshdr; | 1442 | struct scsi_sense_hdr sshdr; |
1441 | int sense_valid = 0; | 1443 | int sense_valid = 0; |
1442 | int the_result; | 1444 | int the_result; |
1443 | int retries = 3; | 1445 | int retries = 3, reset_retries = READ_CAPACITY_RETRIES_ON_RESET; |
1444 | unsigned int alignment; | 1446 | unsigned int alignment; |
1445 | unsigned long long lba; | 1447 | unsigned long long lba; |
1446 | unsigned sector_size; | 1448 | unsigned sector_size; |
@@ -1469,6 +1471,13 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp, | |||
1469 | * Invalid Field in CDB, just retry | 1471 | * Invalid Field in CDB, just retry |
1470 | * silently with RC10 */ | 1472 | * silently with RC10 */ |
1471 | return -EINVAL; | 1473 | return -EINVAL; |
1474 | if (sense_valid && | ||
1475 | sshdr.sense_key == UNIT_ATTENTION && | ||
1476 | sshdr.asc == 0x29 && sshdr.ascq == 0x00) | ||
1477 | /* Device reset might occur several times, | ||
1478 | * give it one more chance */ | ||
1479 | if (--reset_retries > 0) | ||
1480 | continue; | ||
1472 | } | 1481 | } |
1473 | retries--; | 1482 | retries--; |
1474 | 1483 | ||
@@ -1527,7 +1536,7 @@ static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp, | |||
1527 | struct scsi_sense_hdr sshdr; | 1536 | struct scsi_sense_hdr sshdr; |
1528 | int sense_valid = 0; | 1537 | int sense_valid = 0; |
1529 | int the_result; | 1538 | int the_result; |
1530 | int retries = 3; | 1539 | int retries = 3, reset_retries = READ_CAPACITY_RETRIES_ON_RESET; |
1531 | sector_t lba; | 1540 | sector_t lba; |
1532 | unsigned sector_size; | 1541 | unsigned sector_size; |
1533 | 1542 | ||
@@ -1543,8 +1552,16 @@ static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp, | |||
1543 | if (media_not_present(sdkp, &sshdr)) | 1552 | if (media_not_present(sdkp, &sshdr)) |
1544 | return -ENODEV; | 1553 | return -ENODEV; |
1545 | 1554 | ||
1546 | if (the_result) | 1555 | if (the_result) { |
1547 | sense_valid = scsi_sense_valid(&sshdr); | 1556 | sense_valid = scsi_sense_valid(&sshdr); |
1557 | if (sense_valid && | ||
1558 | sshdr.sense_key == UNIT_ATTENTION && | ||
1559 | sshdr.asc == 0x29 && sshdr.ascq == 0x00) | ||
1560 | /* Device reset might occur several times, | ||
1561 | * give it one more chance */ | ||
1562 | if (--reset_retries > 0) | ||
1563 | continue; | ||
1564 | } | ||
1548 | retries--; | 1565 | retries--; |
1549 | 1566 | ||
1550 | } while (the_result && retries); | 1567 | } while (the_result && retries); |