Ver código fonte

[scsi] Retry TEST UNIT READY command

The TEST UNIT READY command is issued automatically when the device is
opened, and is not the result of a command being issued by the caller.
This is required in order that a permanent TEST UNIT READY failure can
be used to identify unusable paths in a multipath SAN device.

Since the TEST UNIT READY command is not part of the caller's command
issuing process, it is not covered by any external retry loops (such
as the main retry loop in sandev_command()).

We must therefore be prepared to retry the TEST UNIT READY command
within the SCSI layer itself.  We retry only the TEST UNIT READY
command so as not to multiply the number of potential retries for
normal commands (which are already retried by sandev_command()).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 7 anos atrás
pai
commit
a66ac07165
1 arquivos alterados com 35 adições e 10 exclusões
  1. 35
    10
      src/drivers/block/scsi.c

+ 35
- 10
src/drivers/block/scsi.c Ver arquivo

40
  *
40
  *
41
  */
41
  */
42
 
42
 
43
+/** Maximum number of TEST UNIT READY retries */
44
+#define SCSI_READY_MAX_RETRIES 10
45
+
43
 /* Error numbers generated by SCSI sense data */
46
 /* Error numbers generated by SCSI sense data */
44
 #define EIO_NO_SENSE __einfo_error ( EINFO_EIO_NO_SENSE )
47
 #define EIO_NO_SENSE __einfo_error ( EINFO_EIO_NO_SENSE )
45
 #define EINFO_EIO_NO_SENSE \
48
 #define EINFO_EIO_NO_SENSE \
240
 	struct interface ready;
243
 	struct interface ready;
241
 	/** TEST UNIT READY process */
244
 	/** TEST UNIT READY process */
242
 	struct process process;
245
 	struct process process;
246
+	/** TEST UNIT READY retry count */
247
+	unsigned int retries;
243
 
248
 
244
 	/** List of commands */
249
 	/** List of commands */
245
 	struct list_head cmds;
250
 	struct list_head cmds;
875
 static void scsidev_ready ( struct scsi_device *scsidev, int rc ) {
880
 static void scsidev_ready ( struct scsi_device *scsidev, int rc ) {
876
 
881
 
877
 	/* Shut down interface */
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
 		return;
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
 /** SCSI device TEST UNIT READY interface operations */
919
 /** SCSI device TEST UNIT READY interface operations */

Carregando…
Cancelar
Salvar