Skip to content

Commit 578f7ff

Browse files
f-borWescoeur
authored andcommitted
Use serial instead of SCSI ID for USB devices (#107)
Adding SRs on multiple usb devices may fail because /usr/lib/udev/scsi_id returns the same device id for all the usb devices. This change fixes this by checking the drive type and using the device serial number if correctly read. Signed-off-by: Frederic Bor <[email protected]> Signed-off-by: Ronan Abhamon <[email protected]>
1 parent 527db10 commit 578f7ff

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

libs/sm/core/util.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,12 @@ def _isSCSIid(s):
10161016
return regex.search(s, 0)
10171017

10181018

1019+
def is_usb_device(device):
1020+
cmd = ["udevadm", "info", "-q", "path", "-n", device]
1021+
result = pread2(cmd).split('/')
1022+
return len(result) >= 5 and result[4].startswith('usb')
1023+
1024+
10191025
def test_scsiserial(session, device):
10201026
device = os.path.realpath(device)
10211027
if not scsiutil._isSCSIdev(device):
@@ -1039,6 +1045,14 @@ def test_scsiserial(session, device):
10391045
% device)
10401046
return False
10411047

1048+
# USB devices can have identical SCSI IDs - prefer matching with serial number
1049+
try:
1050+
usb_device_with_serial = serial and is_usb_device(device)
1051+
except:
1052+
usb_device_with_serial = False
1053+
SMlog("Unable to check if device is USB:")
1054+
SMlog(traceback.format_exc())
1055+
10421056
try:
10431057
SRs = session.xenapi.SR.get_all_records()
10441058
except:
@@ -1048,7 +1062,7 @@ def test_scsiserial(session, device):
10481062
conf = record["sm_config"]
10491063
if 'devserial' in conf:
10501064
for dev in conf['devserial'].split(','):
1051-
if _isSCSIid(dev):
1065+
if not usb_device_with_serial and _isSCSIid(dev):
10521066
if match_scsiID(dev, scsiID):
10531067
return True
10541068
elif len(serial) and dev == serial:

0 commit comments

Comments
 (0)