[SCSI] libsas: reuse the original port when hotplugging phys in wide ports
There's a hotplug problem in the way libsas allocates ports: it loops over the available ports first trying to add to an existing for a wide port and otherwise allocating the next free port. This scheme only works if the port array is packed from zero, which fails if a port gets hot unplugged and the array becomes sparse. In that case, a new port is formed even if there's a wide port it should be part of. Fix this by creating two loops over all the ports: the first to see if the phy should be part of a wide port and the second to form a new port in an empty port slot. Signed-off-by: Tom Peng <tom_peng@usish.com> Signed-off-by: Jack Wang <jack_wang@usish.com> Signed-off-by: Lindar Liu <lindar_liu@usish.com> Cc: Stable Tree <stable@kernel.org> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
This commit is contained in:
parent
35b5c55fee
commit
5381837f12
|
@ -56,7 +56,7 @@ static void sas_form_port(struct asd_sas_phy *phy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* find a port */
|
/* see if the phy should be part of a wide port */
|
||||||
spin_lock_irqsave(&sas_ha->phy_port_lock, flags);
|
spin_lock_irqsave(&sas_ha->phy_port_lock, flags);
|
||||||
for (i = 0; i < sas_ha->num_phys; i++) {
|
for (i = 0; i < sas_ha->num_phys; i++) {
|
||||||
port = sas_ha->sas_port[i];
|
port = sas_ha->sas_port[i];
|
||||||
|
@ -69,12 +69,23 @@ static void sas_form_port(struct asd_sas_phy *phy)
|
||||||
SAS_DPRINTK("phy%d matched wide port%d\n", phy->id,
|
SAS_DPRINTK("phy%d matched wide port%d\n", phy->id,
|
||||||
port->id);
|
port->id);
|
||||||
break;
|
break;
|
||||||
} else if (*(u64 *) port->sas_addr == 0 && port->num_phys==0) {
|
|
||||||
memcpy(port->sas_addr, phy->sas_addr, SAS_ADDR_SIZE);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
spin_unlock(&port->phy_list_lock);
|
spin_unlock(&port->phy_list_lock);
|
||||||
}
|
}
|
||||||
|
/* The phy does not match any existing port, create a new one */
|
||||||
|
if (i == sas_ha->num_phys) {
|
||||||
|
for (i = 0; i < sas_ha->num_phys; i++) {
|
||||||
|
port = sas_ha->sas_port[i];
|
||||||
|
spin_lock(&port->phy_list_lock);
|
||||||
|
if (*(u64 *)port->sas_addr == 0
|
||||||
|
&& port->num_phys == 0) {
|
||||||
|
memcpy(port->sas_addr, phy->sas_addr,
|
||||||
|
SAS_ADDR_SIZE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
spin_unlock(&port->phy_list_lock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (i >= sas_ha->num_phys) {
|
if (i >= sas_ha->num_phys) {
|
||||||
printk(KERN_NOTICE "%s: couldn't find a free port, bug?\n",
|
printk(KERN_NOTICE "%s: couldn't find a free port, bug?\n",
|
||||||
|
|
Loading…
Reference in New Issue