From ce6361cdffff7327a4621d4307369ea75c83f287 Mon Sep 17 00:00:00 2001 From: f-bor Date: Sat, 1 Nov 2025 19:11:37 +0100 Subject: [PATCH] Use serial instead of SCSI ID for USB devices Signed-off-by: Frederic Bor --- drivers/util.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/util.py b/drivers/util.py index 825bd306f..8107e4f73 100755 --- a/drivers/util.py +++ b/drivers/util.py @@ -1038,6 +1038,12 @@ def _isSCSIid(s): return regex.search(s, 0) +def is_usb_device(device): + cmd = ["udevadm", "info", "-q", "path", "-n", device] + result = pread2(cmd).split('/') + return len(result) >= 5 and result[4].startswith('usb') + + def test_scsiserial(session, device): device = os.path.realpath(device) if not scsiutil._isSCSIdev(device): @@ -1061,6 +1067,14 @@ def test_scsiserial(session, device): % device) return False + # USB devices can have identical SCSI IDs - prefer matching with serial number + try: + usb_device_with_serial = serial and is_usb_device(device) + except: + usb_device_with_serial = False + SMlog("Unable to check if device is USB:") + SMlog(traceback.format_exc()) + try: SRs = session.xenapi.SR.get_all_records() except: @@ -1070,7 +1084,7 @@ def test_scsiserial(session, device): conf = record["sm_config"] if 'devserial' in conf: for dev in conf['devserial'].split(','): - if _isSCSIid(dev): + if not usb_device_with_serial and _isSCSIid(dev): if match_scsiID(dev, scsiID): return True elif len(serial) and dev == serial: