clean mounts in bootstrap.cleanup
authorGui Chen <gui.chen@intel.com>
Tue, 21 Aug 2012 06:28:04 +0000 (14:28 +0800)
committerGui Chen <gui.chen@intel.com>
Tue, 21 Aug 2012 15:33:05 +0000 (23:33 +0800)
Signed-off-by: Gui Chen <gui.chen@intel.com>
mic/bootstrap.py
mic/chroot.py

index 8679be1..2916870 100644 (file)
@@ -25,7 +25,7 @@ import rpm
 from mic import msger
 from mic.utils import errors, proxy, misc
 from mic.utils.rpmmisc import readRpmHeader, RPMInstallCallback
-from mic.chroot import setup_chrootenv, cleanup_chrootenv
+from mic.chroot import cleanup_mounts, setup_chrootenv, cleanup_chrootenv
 
 RPMTRANS_FLAGS = [rpm.RPMTRANS_FLAG_ALLFILES,
                   rpm.RPMTRANS_FLAG_NOSCRIPTS,
@@ -206,6 +206,8 @@ class Bootstrap(object):
 
     def cleanup(self):
         try:
+            # clean mounts
+            cleanup_mounts(self.rootdir)
             # remove rootdir
             shutil.rmtree(self.rootdir, ignore_errors=True)
         except:
index 12ffa2f..f4f5942 100644 (file)
@@ -81,27 +81,20 @@ def check_bind_mounts(chrootdir, bindmounts):
 
 def cleanup_mounts(chrootdir):
     umountcmd = misc.find_binary_path("umount")
-    for point in BIND_MOUNTS:
-        args = [ umountcmd, "-l", chrootdir + point ]
-        runner.quiet(args)
-    point = '/parentroot'
-    args = [ umountcmd, "-l", chrootdir + point ]
-    runner.quiet(args)
-
     abs_chrootdir = os.path.abspath(chrootdir)
-    with open('/proc/mounts') as f:
-        for line in f:
-            if abs_chrootdir in line:
-                point = line.split()[1]
+    mounts = open('/proc/mounts').readlines()
+    for line in reversed(mounts):
+        if abs_chrootdir not in line:
+            continue
 
-                if abs_chrootdir == point:
-                    continue
+        point = line.split()[1]
 
-                args = [ umountcmd, "-l", point ]
-                ret = runner.quiet(args)
-                if ret != 0:
-                    msger.warning("failed to unmount %s" % point)
-                    return ret
+        # '/' to avoid common name prefix
+        if abs_chrootdir == point or point.startswith(abs_chrootdir + '/'):
+            args = [ umountcmd, "-l", point ]
+            ret = runner.quiet(args)
+            if ret != 0:
+                msger.warning("failed to unmount %s" % point)
 
     return 0