[blivet:master 4/6] Factor out calculation of dirtyDevices and be less eager in calculating.

mulhern amulhern at redhat.com
Wed Dec 17 14:33:46 UTC 2014


The list of dirty devices is only needed if allowDirty is False,
so only calculate it in that case.

There is a tricky bit in the middle of the method where device.setup() is
called. I believe that this can be dropped from the main path of
mountExistingSystem() because setup() is called again in
FSSet.mountFilesystems().

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/__init__.py | 46 +++++++++++++++++++++++++++-------------------
 1 file changed, 27 insertions(+), 19 deletions(-)

diff --git a/blivet/__init__.py b/blivet/__init__.py
index 63d6f9c..2a137aa 100644
--- a/blivet/__init__.py
+++ b/blivet/__init__.py
@@ -2050,6 +2050,29 @@ class Blivet(object):
 
         self.fsset.setFstabSwaps(devices)
 
+def dirtyDevices(fsset):
+    """ Discover dirty devices.
+
+        :returns: a list of dirty devices
+        :rtype: list
+    """
+    dirtyDevs = []
+    for device in fsset.mountpoints.values():
+        if not hasattr(device.format, "needsFSCheck"):
+            continue
+
+        try:
+            device.setup()
+        except DeviceError:
+            continue
+
+        if device.format.needsFSCheck:
+            log.info("%s contains a dirty %s filesystem", device.path,
+                                                          device.format.type)
+            dirtyDevs.append(device.path)
+
+        return dirtyDevs
+
 def mountExistingSystem(fsset, rootDevice, allowDirty=False, readOnly=None):
     """ Mount filesystems specified in rootDevice's /etc/fstab file. """
     rootPath = _sysroot
@@ -2072,25 +2095,10 @@ def mountExistingSystem(fsset, rootDevice, allowDirty=False, readOnly=None):
 
     fsset.parseFSTab()
 
-    # check for dirty filesystems
-    dirtyDevs = []
-    for device in fsset.mountpoints.values():
-        if not hasattr(device.format, "needsFSCheck"):
-            continue
-
-        try:
-            device.setup()
-        except DeviceError:
-            # we'll catch this in the main loop
-            continue
-
-        if device.format.needsFSCheck:
-            log.info("%s contains a dirty %s filesystem", device.path,
-                                                          device.format.type)
-            dirtyDevs.append(device.path)
-
-    if dirtyDevs and not allowDirty:
-        raise DirtyFSError(dirtyDevs)
+    if not allowDirty:
+        dirtyDevs = dirtyDevices(fsset)
+        if dirtyDevs:
+            raise DirtyFSError(dirtyDevs)
 
     fsset.mountFilesystems(rootPath=_sysroot, readOnly=readOnly, skipRoot=True)
 
-- 
1.9.3



More information about the anaconda-patches mailing list