[blivet] Revive the mountExistingSystem() function and all it needs

Vratislav Podzimek vpodzime at redhat.com
Wed Mar 4 16:58:46 UTC 2015


These pieces got lost during multiple rebases from one branch to another.

Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 blivet/errors.py    |  5 +++++
 blivet/osinstall.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git a/blivet/errors.py b/blivet/errors.py
index b05c0c7..360c440 100644
--- a/blivet/errors.py
+++ b/blivet/errors.py
@@ -80,6 +80,11 @@ class FSResizeError(FSError):
         FSError.__init__(self, message)
         self.details = details
 
+class DirtyFSError(FSError):
+    def __init__(self, devices):
+        FSError.__init__(self)
+        self.devices = devices
+
 class LUKSError(DeviceFormatError):
     pass
 
diff --git a/blivet/osinstall.py b/blivet/osinstall.py
index b2fd9e1..23b1c33 100644
--- a/blivet/osinstall.py
+++ b/blivet/osinstall.py
@@ -31,7 +31,7 @@ from . import getSysroot, getTargetPhysicalRoot, errorHandler, ERROR_RAISE
 
 from .storage_log import log_exception_info
 from .devices import FileDevice, NFSDevice, NoDevice, OpticalDevice, NetworkStorageDevice, DirectoryDevice
-from .errors import FSTabTypeMismatchError, UnrecognizedFSTabEntryError, StorageError, FSResizeError, UnknownSourceDeviceError
+from .errors import FSTabTypeMismatchError, UnrecognizedFSTabEntryError, StorageError, FSResizeError, UnknownSourceDeviceError, DeviceError, DirtyFSError
 from .formats import get_device_format_class
 from .formats import getFormat
 from .flags import flags
@@ -1126,3 +1126,51 @@ def storageInitialize(storage, ksdata, protected):
                                          if d.name not in ksdata.ignoredisk.ignoredisk]
             log.debug("onlyuse is now: %s", ",".join(ksdata.ignoredisk.onlyuse))
 
+def mountExistingSystem(fsset, rootDevice,
+                        allowDirty=None, dirtyCB=None,
+                        readOnly=None):
+    """ Mount filesystems specified in rootDevice's /etc/fstab file. """
+
+    rootPath = getSysroot()
+    if dirtyCB is None:
+        dirtyCB = lambda l: False
+
+    if readOnly:
+        readOnly = "ro"
+    else:
+        readOnly = ""
+
+    if rootDevice.protected and os.path.ismount("/mnt/install/isodir"):
+        util.mount("/mnt/install/isodir",
+                   rootPath,
+                   fstype=rootDevice.format.type,
+                   options="bind")
+    else:
+        rootDevice.setup()
+        rootDevice.format.mount(chroot=rootPath,
+                                mountpoint="/",
+                                options=readOnly)
+
+    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 or dirtyCB(dirtyDevs)):
+        raise DirtyFSError(dirtyDevs)
+
+    fsset.mountFilesystems(rootPath=getSysroot(), readOnly=readOnly, skipRoot=True)
-- 
2.1.0



More information about the anaconda-patches mailing list