Skip to content

Commit 4b8ef49

Browse files
rmetrichvojtechtrefny
authored andcommitted
iSCSI: don't crash when LUN ID >= 256
When LUN ID >= 256, systemd udev function format_lun_number() generates an address of the form "lun-0x...". Due to this, using int(lun) fails with a backtrace. Signed-off-by: Renaud Métrich <[email protected]>
1 parent a6f2156 commit 4b8ef49

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

blivet/devices/disk.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from gi.repository import GLib
2929

3030
import os
31+
import re
3132
from collections import namedtuple
3233

3334
from .. import errors
@@ -354,8 +355,17 @@ def __init__(self, device, **kwargs):
354355
self.offload = kwargs.pop("offload")
355356
name = kwargs.pop("name")
356357
self.target = kwargs.pop("target")
358+
lun = kwargs.pop("lun")
357359
try:
358-
self.lun = int(kwargs.pop("lun"))
360+
self.lun = int(lun)
361+
except ValueError:
362+
# See systemd udev function format_lun_number()
363+
m = re.fullmatch('0x([0-9a-fA-F]{4})([0-9a-fA-F]{4})00000000', lun)
364+
if m is None:
365+
log.warning("Failed to extract hex from lun '%s'", lun)
366+
self.lun = None
367+
else:
368+
self.lun = int(m.group(1), 16) + (1 << 16) * int(m.group(2), 16)
359369
except TypeError as e:
360370
log.warning("Failed to set lun attribute of iscsi disk: %s", e)
361371
self.lun = None

0 commit comments

Comments
 (0)