aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/libsas
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/libsas
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/libsas')
-rw-r--r--drivers/scsi/libsas/sas_discover.c45
-rw-r--r--drivers/scsi/libsas/sas_expander.c8
2 files changed, 20 insertions, 33 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