From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Martin Wilck Date: Fri, 13 Nov 2020 22:38:21 +0100 Subject: [PATCH] libmultipath: sysfs_set_nexus_loss_tmo(): support SAS expanders With SAS expanders, SAS node names have 3 digits. libmultipath would fail to discover the sas_end_device matching a given SCSI target in this case. Fix it. Reviewed-by: Benjamin Marzinski Signed-off-by: Benjamin Marzinski --- libmultipath/discovery.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c index 6d74cc07..921025d4 100644 --- a/libmultipath/discovery.c +++ b/libmultipath/discovery.c @@ -789,14 +789,28 @@ sysfs_set_session_tmo(struct multipath *mpp, struct path *pp) static void sysfs_set_nexus_loss_tmo(struct multipath *mpp, struct path *pp) { - struct udev_device *sas_dev = NULL; - char end_dev_id[64]; + struct udev_device *parent, *sas_dev = NULL; + const char *end_dev_id = NULL; char value[11]; + static const char ed_str[] = "end_device-"; - if (mpp->dev_loss == DEV_LOSS_TMO_UNSET) + if (!pp->udev || mpp->dev_loss == DEV_LOSS_TMO_UNSET) return; - sprintf(end_dev_id, "end_device-%d:%d", - pp->sg_id.host_no, pp->sg_id.transport_id); + + for (parent = udev_device_get_parent(pp->udev); + parent; + parent = udev_device_get_parent(parent)) { + const char *ed = udev_device_get_sysname(parent); + + if (!strncmp(ed, ed_str, sizeof(ed_str) - 1)) { + end_dev_id = ed; + break; + } + } + if (!end_dev_id) { + condlog(1, "%s: No SAS end device", pp->dev); + return; + } sas_dev = udev_device_new_from_subsystem_sysname(udev, "sas_end_device", end_dev_id); if (!sas_dev) { -- 2.17.2