2024-03-07 14:16:13

by yangxingui

[permalink] [raw]
Subject: [PATCH v4 0/2] scsi: libsas: Fix disk not being scanned in after being removed

This patch series fixes an issue when do discovery on an empty PHY to
update PHY info after device unregister could cause newly connected device
to not be scanned.

Changes since v3:
- Revert to allocating the resp memory with alloc_smp_resp().
- Optimize goto statement.

Changes since v2:
- Based on John's suggestion, allow smp_execute_task() arguments to be on
the stack.
- Based on John's suggestion, add a helper sas_get_sas_addr_and_dev_type.
- Updated comments.

Changes since v1:
- Use sas_get_phy_discover() instead of sas_get_phy_attached_dev() in
sas_rediscover_dev() and use disc_resp to update phy info.

Xingui Yang (2):
scsi: libsas: Add a helper sas_get_sas_addr_and_dev_type()
scsi: libsas: Fix disk not being scanned in after being removed

drivers/scsi/libsas/sas_expander.c | 51 ++++++++++++++++++++----------
1 file changed, 34 insertions(+), 17 deletions(-)

--
2.17.1



2024-03-07 14:16:18

by yangxingui

[permalink] [raw]
Subject: [PATCH v4 1/2] scsi: libsas: Add a helper sas_get_sas_addr_and_dev_type()

Add a helper to get attached_sas_addr and device type from disc_resp.

Suggested-by: John Garry <[email protected]>
Signed-off-by: Xingui Yang <[email protected]>
Reviewed-by: John Garry <[email protected]>
---
drivers/scsi/libsas/sas_expander.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index 1eeb69cba8da..d6147616339f 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -1631,6 +1631,16 @@ int sas_discover_root_expander(struct domain_device *dev)

/* ---------- Domain revalidation ---------- */

+static void sas_get_sas_addr_and_dev_type(struct smp_disc_resp *disc_resp,
+ u8 *sas_addr,
+ enum sas_device_type *type)
+{
+ memcpy(sas_addr, disc_resp->disc.attached_sas_addr, SAS_ADDR_SIZE);
+ *type = to_dev_type(&disc_resp->disc);
+ if (*type == SAS_PHY_UNUSED)
+ memset(sas_addr, 0, SAS_ADDR_SIZE);
+}
+
static int sas_get_phy_discover(struct domain_device *dev,
int phy_id, struct smp_disc_resp *disc_resp)
{
@@ -1684,13 +1694,8 @@ int sas_get_phy_attached_dev(struct domain_device *dev, int phy_id,
return -ENOMEM;

res = sas_get_phy_discover(dev, phy_id, disc_resp);
- if (res == 0) {
- memcpy(sas_addr, disc_resp->disc.attached_sas_addr,
- SAS_ADDR_SIZE);
- *type = to_dev_type(&disc_resp->disc);
- if (*type == 0)
- memset(sas_addr, 0, SAS_ADDR_SIZE);
- }
+ if (res == 0)
+ sas_get_sas_addr_and_dev_type(disc_resp, sas_addr, type);
kfree(disc_resp);
return res;
}
--
2.17.1