iSCSI: don't crash when LUN ID >= 256#1431
Merged
vojtechtrefny merged 4 commits intostoraged-project:rhel10-branchfrom Nov 10, 2025
Merged
iSCSI: don't crash when LUN ID >= 256#1431vojtechtrefny merged 4 commits intostoraged-project:rhel10-branchfrom
vojtechtrefny merged 4 commits intostoraged-project:rhel10-branchfrom
Conversation
Reviewer's GuideThis backport enhances LUN parsing in the iScsiDiskDevice constructor to handle 64-bit hex-encoded LUN strings (preventing crashes when LUN ID ≥ 256) and adds unit tests to verify both decimal and hex LUN inputs. Class diagram for updated iScsiDiskDevice LUN parsingclassDiagram
class iScsiDiskDevice {
+offload
+name
+target
+lun
__init__(device, **kwargs)
}
note for iScsiDiskDevice "LUN parsing in __init__ now supports both decimal and 64-bit hex-encoded string formats."
Flow diagram for LUN parsing logic in iScsiDiskDeviceflowchart TD
A["Input LUN value (lun)"] --> B["Try: int(lun)"]
B -- success --> C["Set self.lun = int(lun)"]
B -- ValueError --> D["Match hex pattern: 0x([0-9a-fA-F]{4})([0-9a-fA-F]{4})00000000"]
D -- match --> E["self.lun = int(m.group(1), 16) + (1 << 16) * int(m.group(2), 16)"]
D -- no match --> F["Log warning, set self.lun = None"]
B -- TypeError --> F
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `tests/unit_tests/devices_test/disk_test.py:53-62` </location>
<code_context>
+
+
+class iScsiDiskDeviceTestCase(unittest.TestCase):
+ def test_iscsi_lun(self):
+ kwargs = {"node": "", "ibft": "", "nic": "", "initiator": "",
+ "offload": False, "name": "", "target": "",
+ "address": "", "port": "", "iface": "", "id_path": ""}
+
+ disk1 = iScsiDiskDevice("test1", lun="1", **kwargs)
+ self.assertEqual(disk1.lun, 1)
+
+ disk2 = iScsiDiskDevice("test1", lun="0x0101000000000000", **kwargs)
+ self.assertEqual(disk2.lun, 257)
</code_context>
<issue_to_address>
**suggestion (testing):** Missing tests for invalid LUN formats and error conditions.
Please add tests for malformed hex strings, non-numeric values, None, and cases where the regex does not match, to verify that `disk.lun` is set to None as expected.
</issue_to_address>
### Comment 2
<location> `blivet/devices/disk.py:368` </location>
<code_context>
def __init__(self, device, **kwargs):
"""
:param name: the device name (generally a device node's basename)
:type name: str
:keyword exists: does this device exist?
:type exists: bool
:keyword size: the device's size
:type size: :class:`~.size.Size`
:keyword parents: a list of parent devices
:type parents: list of :class:`StorageDevice`
:keyword format: this device's formatting
:type format: :class:`~.formats.DeviceFormat` or a subclass of it
:keyword str wwn: the disk's WWN
:keyword target: the name of the iscsi target
:type target: str
:keyword lun: lun of the target
:type node: str
:keyword iface: name of network interface to use for operation
:type iface: str
:keyword initiator: initiator name
:type initiator: str
:keyword offload: a partial offload device (qla4xxx)
:type: bool
:keyword address: ip address of the target
:type: str
:keyword port: port of the target
:type: str
"""
# Backward compatibility attributes - to be removed
self.node = kwargs.pop("node")
self.ibft = kwargs.pop("ibft")
self.nic = kwargs.pop("nic")
self.initiator = kwargs.pop("initiator")
self.offload = kwargs.pop("offload")
name = kwargs.pop("name")
self.target = kwargs.pop("target")
lun = kwargs.pop("lun")
try:
self.lun = int(lun)
except ValueError:
# See systemd udev function format_lun_number()
m = re.fullmatch('0x([0-9a-fA-F]{4})([0-9a-fA-F]{4})00000000', lun)
if m is None:
log.warning("Failed to extract hex from lun '%s'", lun)
self.lun = None
else:
self.lun = int(m.group(1), 16) + (1 << 16) * int(m.group(2), 16)
except TypeError as e:
log.warning("Failed to set lun attribute of iscsi disk: %s", e)
self.lun = None
self.address = kwargs.pop("address")
self.port = kwargs.pop("port")
self.iface = kwargs.pop("iface")
self.id_path = kwargs.pop("id_path")
DiskDevice.__init__(self, device, **kwargs)
NetworkStorageDevice.__init__(self, host_address=self.address, nic=self.iface)
log.debug("created new iscsi disk %s from target: %s lun: %s portal: %s:%s interface: %s partial offload: %s)",
name, self.target, self.lun, self.address, self.port, self.iface, self.offload)
self._clear_local_tags()
</code_context>
<issue_to_address>
**suggestion (code-quality):** Replace m.group(x) with m[x] for re.Match objects [×2] ([`use-getitem-for-re-match-groups`](https://docs.sourcery.ai/Reference/Default-Rules/suggestions/use-getitem-for-re-match-groups/))
```suggestion
self.lun = int(m[1], 16) + (1 << 16) * int(m[2], 16)
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| log.warning("Failed to extract hex from lun '%s'", lun) | ||
| self.lun = None | ||
| else: | ||
| self.lun = int(m.group(1), 16) + (1 << 16) * int(m.group(2), 16) |
There was a problem hiding this comment.
suggestion (code-quality): Replace m.group(x) with m[x] for re.Match objects [×2] (use-getitem-for-re-match-groups)
Suggested change
| self.lun = int(m.group(1), 16) + (1 << 16) * int(m.group(2), 16) | |
| self.lun = int(m[1], 16) + (1 << 16) * int(m[2], 16) |
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 <rmetrich@redhat.com> Resolves: RHEL-122305
Related: RHEL-122305
92389b5 to
0a5a1bb
Compare
This is now enabled by default and was removed from pylintrc.
3844029 to
101aeeb
Compare
This is for our CI only.
101aeeb to
f25c7e6
Compare
c982a4a
into
storaged-project:rhel10-branch
4 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #1427
Summary by Sourcery
Support hex-encoded iSCSI LUN values and add tests to handle large LUN IDs without crashing
Bug Fixes:
Enhancements:
Tests: