Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion drivers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand All @@ -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:
Expand Down