From d1797ef53663a956455000409fa3a3476ce4c464 Mon Sep 17 00:00:00 2001 From: David Lehman Date: Fri, 6 Mar 2015 12:49:42 -0600 Subject: [PATCH 11/19] Minor refactoring of deviceChangedCB. --- blivet/handler.py | 61 ++++++++++++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/blivet/handler.py b/blivet/handler.py index 97146aa..90babca 100644 --- a/blivet/handler.py +++ b/blivet/handler.py @@ -467,15 +467,13 @@ class EventHandler(object): if not device: # We're not concerned with updating devices that have been removed # from the tree. - log.warning("device not found: %s", udev.device_get_name(info)) + log.info("device not found: %s", udev.device_get_name(info)) return if not device.exists: - # - # A policy must be decided upon for external events that conflict - # with scheduled actions. - # - log.warning("ignoring change uevent on non-existent device") + if not expected: + log.error("ignoring change uevent on non-existent device %s", + device.name) return if not os.path.exists(device.path): @@ -509,7 +507,9 @@ class EventHandler(object): # A policy must be decided upon for external events that conflict # with scheduled actions. # - log.warning("ignoring change uevent on device with non-existent format") + if not expected: + log.warning("ignoring change uevent on device with " + "non-existent format") return log.debug("changed: %s", pprint.pformat(dict(info))) @@ -536,26 +536,27 @@ class EventHandler(object): uuid_changed = (device.format.uuid and device.format.uuid != uuid) reformatted = uuid_changed or type_changed - if not type_changed and (expected or not uuid_changed): - log.info("%s was not reformatted, or was reformatted by blivet", - device.name) - ## - ## Not reformatted or reformatted as expected by blivet. - ## + if not type_changed: + if hasattr(device.format, "label"): + device.format.label = label - ## update UUID and label - device.format.uuid = uuid + if expected: + device.format.uuid = uuid - # FIXME: grab the info about uuid attrs from the container instance? - if expected and hasattr(device.format, "containerUUID"): - if device.format.type == "lvmpv": - self.devicetree.dropLVMCache() - device.format.containerUUID = self._getContainerUUID(info, - device) + if hasattr(device.format, "containerUUID"): + if device.format.type == "lvmpv": + self.devicetree.dropLVMCache() + device.format.containerUUID = self._getContainerUUID(info, + device) + try: + container = self.devicetree.getChildren(device)[0] + except IndexError: + pass - if hasattr(device.format, "label"): - device.format.label = label - elif reformatted and not expected: + if expected: + return + + if reformatted: log.info("%s was reformatted from outside of blivet", device.name) self.devicetree.cancelDiskActions(device.disks) # eg: wipefs on lvm pv w/ configured vg and lvs @@ -564,15 +565,7 @@ class EventHandler(object): device.format = None self.devicetree.handleUdevDeviceFormat(info, device) - - if expected: - return - - ## - ## Now handle devices whose formatting determines other devices' - ## existence. - ## - if partitioned: + elif partitioned: self._diskLabelChangeHandler(info, device) elif hasattr(device.format, "containerUUID"): if device.format.type == "lvmpv": @@ -608,5 +601,3 @@ class EventHandler(object): if hasattr(fmt, "_mountpoint"): fmt._mountpoint = None fmt._mounted_read_only = False - - -- 1.9.3