[SCSI] libsas: Don't issue commands to devices that have been hot-removed
authorDarrick J. Wong <djwong@us.ibm.com>
Fri, 1 Oct 2010 20:55:47 +0000 (13:55 -0700)
committerJames Bottomley <James.Bottomley@suse.de>
Fri, 8 Oct 2010 21:03:42 +0000 (16:03 -0500)
sd will get hung up issuing commands to flush write cache if a SAS
device behind the expander is unplugged without warning.  Change libsas
to reject commands to domain devices that have already gone away.

[maciej.trela@intel.com: removed setting ->gone in sas_deform_port() to
 permit sync cache commands at module removal]

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Tested-by: Haipao Fan <haipao.fan@intel.com>
Signed-off-by: Maciej Trela <maciej.trela@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
drivers/scsi/libsas/sas_ata.c
drivers/scsi/libsas/sas_expander.c
drivers/scsi/libsas/sas_scsi_host.c
include/scsi/libsas.h

index ddbade7beec937c647a2928cddfebe58bf1d7d2f..e1a395b438eeddfef4e266aedfce0aa3edbe9c5b 100644 (file)
@@ -162,6 +162,10 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc)
        unsigned int xfer = 0;
        unsigned int si;
 
+       /* If the device fell off, no sense in issuing commands */
+       if (dev->gone)
+               return AC_ERR_SYSTEM;
+
        task = sas_alloc_task(GFP_ATOMIC);
        if (!task)
                return AC_ERR_SYSTEM;
index 83dd5070a15c6ce32eabf72679956e88e58693e2..61d81f858a5aef14b0e5a9ef8eb59ac27106fd7b 100644 (file)
@@ -1724,6 +1724,7 @@ static void sas_unregister_ex_tree(struct domain_device *dev)
        struct domain_device *child, *n;
 
        list_for_each_entry_safe(child, n, &ex->children, siblings) {
+               child->gone = 1;
                if (child->dev_type == EDGE_DEV ||
                    child->dev_type == FANOUT_DEV)
                        sas_unregister_ex_tree(child);
@@ -1744,6 +1745,7 @@ static void sas_unregister_devs_sas_addr(struct domain_device *parent,
                        &ex_dev->children, siblings) {
                        if (SAS_ADDR(child->sas_addr) ==
                            SAS_ADDR(phy->attached_sas_addr)) {
+                               child->gone = 1;
                                if (child->dev_type == EDGE_DEV ||
                                    child->dev_type == FANOUT_DEV)
                                        sas_unregister_ex_tree(child);
@@ -1752,6 +1754,7 @@ static void sas_unregister_devs_sas_addr(struct domain_device *parent,
                                break;
                        }
                }
+               parent->gone = 1;
                sas_disable_routing(parent, phy->attached_sas_addr);
        }
        memset(phy->attached_sas_addr, 0, SAS_ADDR_SIZE);
index f0cfba9a1fc83656f9dfa06cc2f0d1dd48115e72..1787bd2eb4a6a7b95645e1bae06b7fc73be18c26 100644 (file)
@@ -228,6 +228,13 @@ int sas_queuecommand(struct scsi_cmnd *cmd,
                        goto out;
                }
 
+               /* If the device fell off, no sense in issuing commands */
+               if (dev->gone) {
+                       cmd->result = DID_BAD_TARGET << 16;
+                       scsi_done(cmd);
+                       goto out;
+               }
+
                res = -ENOMEM;
                task = sas_create_task(cmd, dev, GFP_ATOMIC);
                if (!task)
index d06e13be717bda345112808b0e13d50f1a06490b..3dec1949f69cd75890368d40700f68399ac68427 100644 (file)
@@ -205,6 +205,7 @@ struct domain_device {
         };
 
         void *lldd_dev;
+       int gone;
 };
 
 struct sas_discovery_event {