|
@@ -40,6 +40,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
40
|
40
|
*
|
41
|
41
|
*/
|
42
|
42
|
|
|
43
|
+/** Maximum number of TEST UNIT READY retries */
|
|
44
|
+#define SCSI_READY_MAX_RETRIES 10
|
|
45
|
+
|
43
|
46
|
/* Error numbers generated by SCSI sense data */
|
44
|
47
|
#define EIO_NO_SENSE __einfo_error ( EINFO_EIO_NO_SENSE )
|
45
|
48
|
#define EINFO_EIO_NO_SENSE \
|
|
@@ -240,6 +243,8 @@ struct scsi_device {
|
240
|
243
|
struct interface ready;
|
241
|
244
|
/** TEST UNIT READY process */
|
242
|
245
|
struct process process;
|
|
246
|
+ /** TEST UNIT READY retry count */
|
|
247
|
+ unsigned int retries;
|
243
|
248
|
|
244
|
249
|
/** List of commands */
|
245
|
250
|
struct list_head cmds;
|
|
@@ -875,20 +880,40 @@ static struct interface_descriptor scsidev_block_desc =
|
875
|
880
|
static void scsidev_ready ( struct scsi_device *scsidev, int rc ) {
|
876
|
881
|
|
877
|
882
|
/* Shut down interface */
|
878
|
|
- intf_shutdown ( &scsidev->ready, rc );
|
|
883
|
+ intf_restart ( &scsidev->ready, rc );
|
879
|
884
|
|
880
|
|
- /* Close device on failure */
|
881
|
|
- if ( rc != 0 ) {
|
882
|
|
- DBGC ( scsidev, "SCSI %p not ready: %s\n",
|
883
|
|
- scsidev, strerror ( rc ) );
|
884
|
|
- scsidev_close ( scsidev, rc );
|
|
885
|
+ /* Mark device as ready, if applicable */
|
|
886
|
+ if ( rc == 0 ) {
|
|
887
|
+ DBGC ( scsidev, "SCSI %p unit is ready\n", scsidev );
|
|
888
|
+ scsidev->flags |= SCSIDEV_UNIT_READY;
|
|
889
|
+ xfer_window_changed ( &scsidev->block );
|
|
890
|
+ return;
|
|
891
|
+ }
|
|
892
|
+ DBGC ( scsidev, "SCSI %p not ready: %s\n", scsidev, strerror ( rc ) );
|
|
893
|
+
|
|
894
|
+ /* SCSI targets have an annoying habit of returning occasional
|
|
895
|
+ * pointless "error" messages such as "power-on occurred", so
|
|
896
|
+ * we have to be prepared to retry commands.
|
|
897
|
+ *
|
|
898
|
+ * For most commands, we rely on the caller (e.g. the generic
|
|
899
|
+ * SAN device layer) to retry commands as needed. However, a
|
|
900
|
+ * TEST UNIT READY failure is used as an indication that the
|
|
901
|
+ * whole SCSI device is unavailable and should be closed. We
|
|
902
|
+ * must therefore perform this retry loop within the SCSI
|
|
903
|
+ * layer.
|
|
904
|
+ */
|
|
905
|
+ if ( scsidev->retries++ < SCSI_READY_MAX_RETRIES ) {
|
|
906
|
+ DBGC ( scsidev, "SCSI %p retrying (retry %d)\n",
|
|
907
|
+ scsidev, scsidev->retries );
|
|
908
|
+ scsidev->flags &= ~SCSIDEV_UNIT_TESTED;
|
|
909
|
+ process_add ( &scsidev->process );
|
885
|
910
|
return;
|
886
|
911
|
}
|
887
|
912
|
|
888
|
|
- /* Mark device as ready */
|
889
|
|
- scsidev->flags |= SCSIDEV_UNIT_READY;
|
890
|
|
- xfer_window_changed ( &scsidev->block );
|
891
|
|
- DBGC ( scsidev, "SCSI %p unit is ready\n", scsidev );
|
|
913
|
+ /* Close device */
|
|
914
|
+ DBGC ( scsidev, "SCSI %p never became ready: %s\n",
|
|
915
|
+ scsidev, strerror ( rc ) );
|
|
916
|
+ scsidev_close ( scsidev, rc );
|
892
|
917
|
}
|
893
|
918
|
|
894
|
919
|
/** SCSI device TEST UNIT READY interface operations */
|