Skip to content

Commit ce6361c

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

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

drivers/util.py

Lines changed: 15 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,14 @@ 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:
1074+
usb_device_with_serial = False
1075+
SMlog("Unable to check if device is USB:")
1076+
SMlog(traceback.format_exc())
1077+
10641078
try:
10651079
SRs = session.xenapi.SR.get_all_records()
10661080
except:
@@ -1070,7 +1084,7 @@ def test_scsiserial(session, device):
10701084
conf = record["sm_config"]
10711085
if 'devserial' in conf:
10721086
for dev in conf['devserial'].split(','):
1073-
if _isSCSIid(dev):
1087+
if not usb_device_with_serial and _isSCSIid(dev):
10741088
if match_scsiID(dev, scsiID):
10751089
return True
10761090
elif len(serial) and dev == serial:

0 commit comments

Comments
 (0)