[SCSI] iscsi_transport: wait on session in error handler path
authorMike Christie <michaelc@cs.wisc.edu>
Thu, 22 Jul 2010 11:29:49 +0000 (16:59 +0530)
committerJames Bottomley <James.Bottomley@suse.de>
Wed, 28 Jul 2010 14:06:06 +0000 (09:06 -0500)
wait for session to come online in eh_device_reset_handler
and eh_target_reset_handler

Signed-off-by: Mike Christie <michaelc@cs.wisc.edu>
Signed-off-by: Vikas Chaudhary <vikas.chaudhary@qlogic.com>
Signed-off-by: Ravi Anand <ravi.anand@qlogic.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
drivers/scsi/qla4xxx/ql4_os.c
drivers/scsi/scsi_transport_iscsi.c
include/scsi/scsi_transport_iscsi.h

index 821384147a41cba12a2501f7b705001cbd1f56cb..5529b2a39741ab5a01f73df362f5cff8991e279b 100644 (file)
@@ -2020,6 +2020,11 @@ static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
        if (!ddb_entry)
                return ret;
 
+       ret = iscsi_block_scsi_eh(cmd);
+       if (ret)
+               return ret;
+       ret = FAILED;
+
        ql4_printk(KERN_INFO, ha,
                   "scsi%ld:%d:%d:%d: DEVICE RESET ISSUED.\n", ha->host_no,
                   cmd->device->channel, cmd->device->id, cmd->device->lun);
@@ -2072,11 +2077,15 @@ static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
 {
        struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
        struct ddb_entry *ddb_entry = cmd->device->hostdata;
-       int stat;
+       int stat, ret;
 
        if (!ddb_entry)
                return FAILED;
 
+       ret = iscsi_block_scsi_eh(cmd);
+       if (ret)
+               return ret;
+
        starget_printk(KERN_INFO, scsi_target(cmd->device),
                       "WARM TARGET RESET ISSUED.\n");
 
index d4b96623aa59fa5c886c61fdfcd97010dab8231f..e84026def1f4839b69032a8ea76916c07f871645 100644 (file)
@@ -30,6 +30,7 @@
 #include <scsi/scsi_transport.h>
 #include <scsi/scsi_transport_iscsi.h>
 #include <scsi/iscsi_if.h>
+#include <scsi/scsi_cmnd.h>
 
 #define ISCSI_SESSION_ATTRS 23
 #define ISCSI_CONN_ATTRS 13
@@ -534,6 +535,37 @@ static void iscsi_scan_session(struct work_struct *work)
        atomic_dec(&ihost->nr_scans);
 }
 
+/**
+ * iscsi_block_scsi_eh - block scsi eh until session state has transistioned
+ * cmd: scsi cmd passed to scsi eh handler
+ *
+ * If the session is down this function will wait for the recovery
+ * timer to fire or for the session to be logged back in. If the
+ * recovery timer fires then FAST_IO_FAIL is returned. The caller
+ * should pass this error value to the scsi eh.
+ */
+int iscsi_block_scsi_eh(struct scsi_cmnd *cmd)
+{
+       struct iscsi_cls_session *session =
+                       starget_to_session(scsi_target(cmd->device));
+       unsigned long flags;
+       int ret = 0;
+
+       spin_lock_irqsave(&session->lock, flags);
+       while (session->state != ISCSI_SESSION_LOGGED_IN) {
+               if (session->state == ISCSI_SESSION_FREE) {
+                       ret = FAST_IO_FAIL;
+                       break;
+               }
+               spin_unlock_irqrestore(&session->lock, flags);
+               msleep(1000);
+               spin_lock_irqsave(&session->lock, flags);
+       }
+       spin_unlock_irqrestore(&session->lock, flags);
+       return ret;
+}
+EXPORT_SYMBOL_GPL(iscsi_block_scsi_eh);
+
 static void session_recovery_timedout(struct work_struct *work)
 {
        struct iscsi_cls_session *session =
index 349c7f30720d8f652c79b1db0251f3a44180505a..7fff94b3b2a818c2c0645c5efc0992018282394f 100644 (file)
@@ -32,6 +32,7 @@ struct scsi_transport_template;
 struct iscsi_transport;
 struct iscsi_endpoint;
 struct Scsi_Host;
+struct scsi_cmnd;
 struct iscsi_cls_conn;
 struct iscsi_conn;
 struct iscsi_task;
@@ -255,5 +256,6 @@ extern int iscsi_scan_finished(struct Scsi_Host *shost, unsigned long time);
 extern struct iscsi_endpoint *iscsi_create_endpoint(int dd_size);
 extern void iscsi_destroy_endpoint(struct iscsi_endpoint *ep);
 extern struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle);
+extern int iscsi_block_scsi_eh(struct scsi_cmnd *cmd);
 
 #endif