Skip to content

Commit e464d66

Browse files
committed
Use serial instead of SCSI ID for USB devices
Signed-off-by: f-bor <[email protected]>
1 parent de309bc commit e464d66

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

drivers/util.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,12 @@ def _isSCSIid(s):
10381038
return regex.search(s, 0)
10391039

10401040

1041+
def is_usb_device(device):
1042+
cmd = ["udevadm", "info", "-q", "path", "-n", device]
1043+
result = pread2(cmd).split('/')
1044+
return len(result) >= 5 and result[4].startswith('usb')
1045+
1046+
10411047
def test_scsiserial(session, device):
10421048
device = os.path.realpath(device)
10431049
if not scsiutil._isSCSIdev(device):
@@ -1061,6 +1067,12 @@ def test_scsiserial(session, device):
10611067
% device)
10621068
return False
10631069

1070+
# USB devices can have identical SCSI IDs - prefer matching with serial number
1071+
try:
1072+
usb_device_with_serial = serial and is_usb_device(device)
1073+
except CommandException:
1074+
usb_device_with_serial = False
1075+
10641076
try:
10651077
SRs = session.xenapi.SR.get_all_records()
10661078
except:
@@ -1070,7 +1082,7 @@ def test_scsiserial(session, device):
10701082
conf = record["sm_config"]
10711083
if 'devserial' in conf:
10721084
for dev in conf['devserial'].split(','):
1073-
if _isSCSIid(dev):
1085+
if not usb_device_with_serial and _isSCSIid(dev):
10741086
if match_scsiID(dev, scsiID):
10751087
return True
10761088
elif len(serial) and dev == serial:

0 commit comments

Comments
 (0)