[master 1/4] Add ability to unmount specific mountpoints

bcl installerbot-noreply at redhat.com
Tue Apr 7 20:39:58 UTC 2015


From: "Brian C. Lane" <bcl at redhat.com>

The dynamic mountpoint detection patch revealed a problem with multiple
mountpoints. Sometimes things are mounted in multiple places and the
first one listed by the system isn't always the one you want to unmount.

This adds the mountpoint argument to unmount so that a specific location
can be selected. It must exist or else FSError will be raised.

The old code worked because it replaced the _mountpoint value so it
would unmount the last mounted location, but that wasn't correct because
you then lost the information about previous mountpoints.

With the current code the caller is expected to keep track of
mountpoints if more than one is used and to pass mountpoint= to unmount.
---
 blivet/formats/fs.py | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py
index 4e3d39f..e1b5bba 100644
--- a/blivet/formats/fs.py
+++ b/blivet/formats/fs.py
@@ -628,6 +628,10 @@ def mount(self, options="", chroot="/", mountpoint=None):
             :keyword chroot: prefix to apply to mountpoint
             :keyword mountpoint: mountpoint (overrides self.mountpoint)
             :raises: FSError
+
+            NOTE: When mounted multiple times the unmount method needs to be called with
+            a specific mountpoint to unmount, otherwise it will try to unmount the first
+            one listed by the system.
         """
         if not self.exists:
             raise FSError("filesystem has not been created")
@@ -678,23 +682,34 @@ def mount(self, options="", chroot="/", mountpoint=None):
             if not ret:
                 log.warning("Failed to set SELinux context for newly mounted filesystem lost+found directory at %s to %s", lost_and_found_path, lost_and_found_context)
 
-    def unmount(self):
-        """ Unmount this filesystem. """
+    def unmount(self, mountpoint=None):
+        """ Unmount this filesystem.
+
+            :param str mountpoint: Optional mountpoint to be unmounted.
+            :raises: FSError
+
+            If mountpoint isn't passed this will unmount the first mountpoint listed by the
+            system. Override this behavior by passing a specific mountpoint. FSError will
+            be raised in either case if the path doesn't exist.
+        """
         if not self.exists:
             raise FSError("filesystem has not been created")
 
-        if not self.systemMountpoint:
+        # Prefer the explicit mountpoint path, fall back to first system mountpoint
+        mountpoint = mountpoint or self.systemMountpoint
+
+        if not mountpoint:
             # not mounted
             return
 
-        if not os.path.exists(self.systemMountpoint):
+        if not os.path.exists(mountpoint):
             raise FSError("mountpoint does not exist")
 
         udev.settle()
-        rc = util.umount(self.systemMountpoint)
+        rc = util.umount(mountpoint)
         if rc:
             # try and catch whatever is causing the umount problem
-            util.run_program(["lsof", self.systemMountpoint])
+            util.run_program(["lsof", mountpoint])
             raise FSError("umount failed")
 
     def readLabel(self):


-- 
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/6ef9a096dc90d8031822e6db625a55438d208c74


More information about the anaconda-patches mailing list