aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@us.ibm.com>2007-01-26 17:08:43 -0500
committerJames Bottomley <jejb@mulgrave.il.steeleye.com>2007-01-27 11:05:15 -0500
commit6f63caae2172e97e528b58319480217b0b36542e (patch)
tree641e3d41e05a11d9edec50d56f15be11f7e9cdfb /drivers/scsi
parent3b6e9fafc40e36f50f0bd0f1ee758eecd79f1098 (diff)
[SCSI] libsas: Clean up discovery failure handler code
sas_rphy_delete does two things: it removes the sas_rphy from the transport layer and frees the sas_rphy. This can be broken down into two functions, sas_rphy_remove and sas_rphy_free; sas_rphy_remove is of interest to sas_discover_root_expander because it calls functions that require sas_rphy_add as a prerequisite and can fail (namely sas_discover_expander). In that case, sas_discover_root_expander needs to be able to undo the effects of sas_rphy_add yet leave the job of freeing the sas_rphy to the caller of sas_discover_root_expander. This patch also removes some unnecessary code from sas_discover_end_dev to eliminate an unnecessary cycle of sas_notify_lldd_gone/found for SAS devices, thus eliminating a sas_rphy_remove call (and fixing a race condition where a SCSI target scan can come in between the gone and found call). It also moves the sas_rphy_free calls into sas_discover_domain and sas_ex_discover_end_dev to complement the sas_rphy_allocation via sas_get_port_device. This patch does not change the semantics of sas_rphy_delete. Signed-off-by: Darrick J. Wong <djwong@us.ibm.com> Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Diffstat (limited to 'drivers/scsi')
-rw-r--r--drivers/scsi/libsas/sas_discover.c45
-rw-r--r--drivers/scsi/libsas/sas_expander.c8
-rw-r--r--drivers/scsi/scsi_transport_sas.c33
3 files changed, 39 insertions, 47 deletions
diff --git a/drivers/scsi/libsas/sas_discover.c b/drivers/scsi/libsas/sas_discover.c
index b6ba0e053d1a..a65598b1e536 100644
--- a/drivers/scsi/libsas/sas_discover.c
+++ b/drivers/scsi/libsas/sas_discover.c
@@ -577,8 +577,6 @@ int sas_discover_sata(struct domain_device *dev)
577out_err: 577out_err:
578 sas_notify_lldd_dev_gone(dev); 578 sas_notify_lldd_dev_gone(dev);
579out_err2: 579out_err2:
580 sas_rphy_free(dev->rphy);
581 dev->rphy = NULL;
582 return res; 580 return res;
583} 581}
584 582
@@ -600,24 +598,11 @@ int sas_discover_end_dev(struct domain_device *dev)
600 if (res) 598 if (res)
601 goto out_err; 599 goto out_err;
602 600
603 /* do this to get the end device port attributes which will have
604 * been scanned in sas_rphy_add */
605 sas_notify_lldd_dev_gone(dev);
606 res = sas_notify_lldd_dev_found(dev);
607 if (res)
608 goto out_err3;
609
610 return 0; 601 return 0;
611 602
612out_err: 603out_err:
613 sas_notify_lldd_dev_gone(dev); 604 sas_notify_lldd_dev_gone(dev);
614out_err2: 605out_err2:
615 sas_rphy_free(dev->rphy);
616 dev->rphy = NULL;
617 return res;
618out_err3:
619 sas_rphy_delete(dev->rphy);
620 dev->rphy = NULL;
621 return res; 606 return res;
622} 607}
623 608
@@ -672,6 +657,7 @@ void sas_unregister_domain_devices(struct asd_sas_port *port)
672 */ 657 */
673static void sas_discover_domain(struct work_struct *work) 658static void sas_discover_domain(struct work_struct *work)
674{ 659{
660 struct domain_device *dev;
675 int error = 0; 661 int error = 0;
676 struct sas_discovery_event *ev = 662 struct sas_discovery_event *ev =
677 container_of(work, struct sas_discovery_event, work); 663 container_of(work, struct sas_discovery_event, work);
@@ -681,39 +667,42 @@ static void sas_discover_domain(struct work_struct *work)
681 &port->disc.pending); 667 &port->disc.pending);
682 668
683 if (port->port_dev) 669 if (port->port_dev)
684 return ; 670 return;
685 else { 671
686 error = sas_get_port_device(port); 672 error = sas_get_port_device(port);
687 if (error) 673 if (error)
688 return; 674 return;
689 } 675 dev = port->port_dev;
690 676
691 SAS_DPRINTK("DOING DISCOVERY on port %d, pid:%d\n", port->id, 677 SAS_DPRINTK("DOING DISCOVERY on port %d, pid:%d\n", port->id,
692 current->pid); 678 current->pid);
693 679
694 switch (port->port_dev->dev_type) { 680 switch (dev->dev_type) {
695 case SAS_END_DEV: 681 case SAS_END_DEV:
696 error = sas_discover_end_dev(port->port_dev); 682 error = sas_discover_end_dev(dev);
697 break; 683 break;
698 case EDGE_DEV: 684 case EDGE_DEV:
699 case FANOUT_DEV: 685 case FANOUT_DEV:
700 error = sas_discover_root_expander(port->port_dev); 686 error = sas_discover_root_expander(dev);
701 break; 687 break;
702 case SATA_DEV: 688 case SATA_DEV:
703 case SATA_PM: 689 case SATA_PM:
704 error = sas_discover_sata(port->port_dev); 690 error = sas_discover_sata(dev);
705 break; 691 break;
706 default: 692 default:
707 SAS_DPRINTK("unhandled device %d\n", port->port_dev->dev_type); 693 SAS_DPRINTK("unhandled device %d\n", dev->dev_type);
708 break; 694 break;
709 } 695 }
710 696
711 if (error) { 697 if (error) {
698 sas_rphy_free(dev->rphy);
699 dev->rphy = NULL;
700
712 spin_lock(&port->dev_list_lock); 701 spin_lock(&port->dev_list_lock);
713 list_del_init(&port->port_dev->dev_list_node); 702 list_del_init(&dev->dev_list_node);
714 spin_unlock(&port->dev_list_lock); 703 spin_unlock(&port->dev_list_lock);
715 704
716 kfree(port->port_dev); /* not kobject_register-ed yet */ 705 kfree(dev); /* not kobject_register-ed yet */
717 port->port_dev = NULL; 706 port->port_dev = NULL;
718 } 707 }
719 708
diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index 0dfd97e7e96c..d9b9a008d36d 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -667,6 +667,8 @@ static struct domain_device *sas_ex_discover_end_dev(
667 return child; 667 return child;
668 668
669 out_list_del: 669 out_list_del:
670 sas_rphy_free(child->rphy);
671 child->rphy = NULL;
670 list_del(&child->dev_list_node); 672 list_del(&child->dev_list_node);
671 out_free: 673 out_free:
672 sas_port_delete(phy->port); 674 sas_port_delete(phy->port);
@@ -1444,12 +1446,8 @@ int sas_discover_root_expander(struct domain_device *dev)
1444 return res; 1446 return res;
1445 1447
1446out_err2: 1448out_err2:
1447 sas_rphy_delete(dev->rphy); 1449 sas_rphy_remove(dev->rphy);
1448 dev->rphy = NULL;
1449 return res;
1450out_err: 1450out_err:
1451 sas_rphy_free(dev->rphy);
1452 dev->rphy = NULL;
1453 return res; 1451 return res;
1454} 1452}
1455 1453
diff --git a/drivers/scsi/scsi_transport_sas.c b/drivers/scsi/scsi_transport_sas.c
index ce232803f433..010845fd2b85 100644
--- a/drivers/scsi/scsi_transport_sas.c
+++ b/drivers/scsi/scsi_transport_sas.c
@@ -1299,7 +1299,7 @@ EXPORT_SYMBOL(sas_rphy_add);
1299 * Note: 1299 * Note:
1300 * This function must only be called on a remote 1300 * This function must only be called on a remote
1301 * PHY that has not sucessfully been added using 1301 * PHY that has not sucessfully been added using
1302 * sas_rphy_add(). 1302 * sas_rphy_add() (or has been sas_rphy_remove()'d)
1303 */ 1303 */
1304void sas_rphy_free(struct sas_rphy *rphy) 1304void sas_rphy_free(struct sas_rphy *rphy)
1305{ 1305{
@@ -1318,18 +1318,30 @@ void sas_rphy_free(struct sas_rphy *rphy)
1318EXPORT_SYMBOL(sas_rphy_free); 1318EXPORT_SYMBOL(sas_rphy_free);
1319 1319
1320/** 1320/**
1321 * sas_rphy_delete -- remove SAS remote PHY 1321 * sas_rphy_delete -- remove and free SAS remote PHY
1322 * @rphy: SAS remote PHY to remove 1322 * @rphy: SAS remote PHY to remove and free
1323 * 1323 *
1324 * Removes the specified SAS remote PHY. 1324 * Removes the specified SAS remote PHY and frees it.
1325 */ 1325 */
1326void 1326void
1327sas_rphy_delete(struct sas_rphy *rphy) 1327sas_rphy_delete(struct sas_rphy *rphy)
1328{ 1328{
1329 sas_rphy_remove(rphy);
1330 sas_rphy_free(rphy);
1331}
1332EXPORT_SYMBOL(sas_rphy_delete);
1333
1334/**
1335 * sas_rphy_remove -- remove SAS remote PHY
1336 * @rphy: SAS remote phy to remove
1337 *
1338 * Removes the specified SAS remote PHY.
1339 */
1340void
1341sas_rphy_remove(struct sas_rphy *rphy)
1342{
1329 struct device *dev = &rphy->dev; 1343 struct device *dev = &rphy->dev;
1330 struct sas_port *parent = dev_to_sas_port(dev->parent); 1344 struct sas_port *parent = dev_to_sas_port(dev->parent);
1331 struct Scsi_Host *shost = dev_to_shost(parent->dev.parent);
1332 struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
1333 1345
1334 switch (rphy->identify.device_type) { 1346 switch (rphy->identify.device_type) {
1335 case SAS_END_DEVICE: 1347 case SAS_END_DEVICE:
@@ -1345,17 +1357,10 @@ sas_rphy_delete(struct sas_rphy *rphy)
1345 1357
1346 transport_remove_device(dev); 1358 transport_remove_device(dev);
1347 device_del(dev); 1359 device_del(dev);
1348 transport_destroy_device(dev);
1349
1350 mutex_lock(&sas_host->lock);
1351 list_del(&rphy->list);
1352 mutex_unlock(&sas_host->lock);
1353 1360
1354 parent->rphy = NULL; 1361 parent->rphy = NULL;
1355
1356 put_device(dev);
1357} 1362}
1358EXPORT_SYMBOL(sas_rphy_delete); 1363EXPORT_SYMBOL(sas_rphy_remove);
1359 1364
1360/** 1365/**
1361 * scsi_is_sas_rphy -- check if a struct device represents a SAS remote PHY 1366 * scsi_is_sas_rphy -- check if a struct device represents a SAS remote PHY