[blivet:master 3/3] Rearrange code related to handleUdevDeviceFormat() (#1095329)

mulhern amulhern at redhat.com
Thu May 8 19:35:45 UTC 2014


Resolves: #1095329

Move some actions from calling code into handleUdevDeviceFormat():
* Move checks for non-existant info and media not present
into handleUdevDeviceFormat().
* Move logging obtained format into handleUdevDeviceFormat()

Move check for no device found in handleUdevDevice() earlier,
make the message a bit more informative, and omit redundant
checks for existance of device that occur after the check.

Now handleUdevDeviceFormat() will exit if media not present. Previously,
there was one caller, updateDeviceFormat(), where handleUdevDeviceFormat()
would be called regardless of whether media was present and another,
handleUdevDevice() where the call would not occur if media was not present.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/devicetree.py | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/blivet/devicetree.py b/blivet/devicetree.py
index 698f7fa..68399f2 100644
--- a/blivet/devicetree.py
+++ b/blivet/devicetree.py
@@ -1170,10 +1170,14 @@ class DeviceTree(object):
             log.error("Unknown block device type for: %s", name)
             return
 
+        if not device:
+            log.debug("no device obtained for %s", name)
+            return
+
         # If this device is protected, mark it as such now. Once the tree
         # has been populated, devices' protected attribute is how we will
         # identify protected devices.
-        if device and device.name in self.protectedDevNames:
+        if device.name in self.protectedDevNames:
             device.protected = True
             # if this is the live backing device we want to mark its parents
             # as protected also
@@ -1184,23 +1188,16 @@ class DeviceTree(object):
         # If we just added a multipath or fwraid disk that is in exclusiveDisks
         # we have to make sure all of its members are in the list too.
         mdclasses = (DMRaidArrayDevice, MDRaidArrayDevice, MultipathDevice)
-        if device and device.isDisk and isinstance(device, mdclasses):
+        if device.isDisk and isinstance(device, mdclasses):
             if device.name in self.exclusiveDisks:
                 for parent in device.parents:
                     if parent.name not in self.exclusiveDisks:
                         self.exclusiveDisks.append(parent.name)
 
-        # Don't try to do format handling on drives without media or
-        # if we didn't end up with a device somehow.
-        if not device or not device.mediaPresent:
-            log.debug("no device or no media present")
-            return
+        log.info("got device: %r", device)
 
         # now handle the device's formatting
         self.handleUdevDeviceFormat(info, device)
-        log.info("got device: %r", device)
-        if device.format.type:
-            log.info("got format: %r", device.format)
         device.originalFormat = copy.copy(device.format)
         device.deviceLinks = udev.udev_device_get_symlinks(info)
 
@@ -1695,6 +1692,14 @@ class DeviceTree(object):
 
     def handleUdevDeviceFormat(self, info, device):
         log_method_call(self, name=getattr(device, "name", None))
+
+        if not info:
+            log.debug("no information for device %s", device.name)
+            return
+        if not device.mediaPresent:
+            log.debug("no media present for device %s", device.name)
+            return
+
         name = udev.udev_device_get_name(info)
         uuid = udev.udev_device_get_uuid(info)
         label = udev.udev_device_get_label(info)
@@ -1787,6 +1792,8 @@ class DeviceTree(object):
         try:
             log.info("type detected on '%s' is '%s'", name, format_type)
             device.format = formats.getFormat(*args, **kwargs)
+            if device.format.type:
+                log.info("got format: %s", device.format)
         except FSError:
             log.warning("type '%s' on '%s' invalid, assuming no format",
                       format_type, name)
@@ -1817,10 +1824,7 @@ class DeviceTree(object):
         udev.udev_settle()
         info = udev.udev_get_device(device.sysfsPath)
 
-        if info:
-            self.handleUdevDeviceFormat(info, device)
-            if device.format.type:
-                log.info("got format: %s", device.format)
+        self.handleUdevDeviceFormat(info, device)
 
     def _handleInconsistencies(self):
         for vg in [d for d in self.devices if d.type == "lvmvg"]:
-- 
1.8.3.1



More information about the anaconda-patches mailing list