Skip to content

Commit d7cd0b1

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 <frederic.bor@wanadoo.fr>
1 parent 993a02f commit d7cd0b1

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
@@ -1039,6 +1039,12 @@ def _isSCSIid(s):
10391039
return regex.search(s, 0)
10401040

10411041

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

1071+
# USB devices can have identical SCSI IDs - prefer matching with serial number
1072+
try:
1073+
usb_device_with_serial = serial and is_usb_device(device)
1074+
except:
1075+
usb_device_with_serial = False
1076+
SMlog("Unable to check if device is USB:")
1077+
SMlog(traceback.format_exc())
1078+
10651079
try:
10661080
SRs = session.xenapi.SR.get_all_records()
10671081
except:
@@ -1071,7 +1085,7 @@ def test_scsiserial(session, device):
10711085
conf = record["sm_config"]
10721086
if 'devserial' in conf:
10731087
for dev in conf['devserial'].split(','):
1074-
if _isSCSIid(dev):
1088+
if not usb_device_with_serial and _isSCSIid(dev):
10751089
if match_scsiID(dev, scsiID):
10761090
return True
10771091
elif len(serial) and dev == serial:

0 commit comments

Comments
 (0)