Blame SOURCES/0006-Fix-resolving-devices-with-names-that-look-like-BIOS.patch

20511f
From 344e624f91010b6041c22ee8a24c9305b82af969 Mon Sep 17 00:00:00 2001
20511f
From: Vojtech Trefny <vtrefny@redhat.com>
20511f
Date: Tue, 18 May 2021 12:54:02 +0200
20511f
Subject: [PATCH] Fix resolving devices with names that look like BIOS drive
20511f
 number
20511f
20511f
A RAID array named "10" will not be resolved because we try to
20511f
resolve it using EDD data and after this lookup fails, we don't
20511f
try the name.
20511f
20511f
Resolves: rhbz#1960798
20511f
---
20511f
 blivet/devicetree.py     | 18 +++++++++---------
20511f
 tests/devicetree_test.py |  4 ++++
20511f
 2 files changed, 13 insertions(+), 9 deletions(-)
20511f
20511f
diff --git a/blivet/devicetree.py b/blivet/devicetree.py
20511f
index 88e9f0e5..f4ae1968 100644
20511f
--- a/blivet/devicetree.py
20511f
+++ b/blivet/devicetree.py
20511f
@@ -634,20 +634,20 @@ class DeviceTreeBase(object):
20511f
                     (label.startswith("'") and label.endswith("'"))):
20511f
                 label = label[1:-1]
20511f
             device = self.labels.get(label)
20511f
-        elif re.match(r'(0x)?[A-Fa-f0-9]{2}(p\d+)?$', devspec):
20511f
-            # BIOS drive number
20511f
-            (drive, _p, partnum) = devspec.partition("p")
20511f
-            spec = int(drive, 16)
20511f
-            for (edd_name, edd_number) in self.edd_dict.items():
20511f
-                if edd_number == spec:
20511f
-                    device = self.get_device_by_name(edd_name + partnum)
20511f
-                    break
20511f
         elif options and "nodev" in options.split(","):
20511f
             device = self.get_device_by_name(devspec)
20511f
             if not device:
20511f
                 device = self.get_device_by_path(devspec)
20511f
         else:
20511f
-            if not devspec.startswith("/dev/"):
20511f
+            if re.match(r'(0x)?[A-Fa-f0-9]{2}(p\d+)?$', devspec):
20511f
+                # BIOS drive number
20511f
+                (drive, _p, partnum) = devspec.partition("p")
20511f
+                spec = int(drive, 16)
20511f
+                for (edd_name, edd_number) in self.edd_dict.items():
20511f
+                    if edd_number == spec:
20511f
+                        device = self.get_device_by_name(edd_name + partnum)
20511f
+                        break
20511f
+            if not device and not devspec.startswith("/dev/"):
20511f
                 device = self.get_device_by_name(devspec)
20511f
                 if not device:
20511f
                     devspec = "/dev/" + devspec
20511f
diff --git a/tests/devicetree_test.py b/tests/devicetree_test.py
20511f
index 11f8469d..b033343d 100644
20511f
--- a/tests/devicetree_test.py
20511f
+++ b/tests/devicetree_test.py
20511f
@@ -49,6 +49,9 @@ class DeviceTreeTestCase(unittest.TestCase):
20511f
         dev3 = StorageDevice("sdp2", exists=True)
20511f
         dt._add_device(dev3)
20511f
 
20511f
+        dev4 = StorageDevice("10", exists=True)
20511f
+        dt._add_device(dev4)
20511f
+
20511f
         dt.edd_dict.update({"dev1": 0x81,
20511f
                             "dev2": 0x82})
20511f
 
20511f
@@ -62,6 +65,7 @@ class DeviceTreeTestCase(unittest.TestCase):
20511f
         self.assertEqual(dt.resolve_device("0x82"), dev2)
20511f
 
20511f
         self.assertEqual(dt.resolve_device(dev3.name), dev3)
20511f
+        self.assertEqual(dt.resolve_device(dev4.name), dev4)
20511f
 
20511f
     def test_device_name(self):
20511f
         # check that devicetree.names property contains all device's names
20511f
-- 
20511f
2.31.1
20511f