some case don't need to mount parent folder
authorGui Chen <gui.chen@intel.com>
Fri, 30 Nov 2012 03:21:35 +0000 (11:21 +0800)
committerGui Chen <gui.chen@intel.com>
Wed, 12 Dec 2012 11:33:44 +0000 (19:33 +0800)
bind mounting parent folder has potential issue in some case, make it optinal

some dirs like 'outdir' 'logfile' which will be created by mic is not existed
before chroot, create them to avoid left them inside chroot

Signed-off-by: Gui Chen <gui.chen@intel.com>
mic/bootstrap.py
mic/chroot.py

index 86fffc5..7f34f19 100644 (file)
@@ -245,7 +245,7 @@ class Bootstrap(object):
         gloablmounts = None
         try:
             proxy.set_proxy_environ()
-            gloablmounts = setup_chrootenv(rootdir, bindmounts)
+            gloablmounts = setup_chrootenv(rootdir, bindmounts, False)
             retcode = subprocess.call(cmd, preexec_fn=mychroot, env=env, shell=shell)
         except (OSError, IOError), err:
             raise RuntimeError(err)
index d567bb1..ed867df 100644 (file)
@@ -98,10 +98,10 @@ def cleanup_mounts(chrootdir):
 
     return 0
 
-def setup_chrootenv(chrootdir, bindmounts = None):
+def setup_chrootenv(chrootdir, bindmounts = None, mountparent = True):
     global chroot_lockfd, chroot_lock
 
-    def get_bind_mounts(chrootdir, bindmounts):
+    def get_bind_mounts(chrootdir, bindmounts, mountparent = True):
         chrootmounts = []
         if bindmounts in ("", None):
             bindmounts = ""
@@ -115,6 +115,11 @@ def setup_chrootenv(chrootdir, bindmounts = None):
             if len(srcdst) == 1:
                srcdst.append("none")
 
+            # if some bindmount is not existed, but it's created inside
+            # chroot, this is not expected
+            if not os.path.exists(srcdst[0]):
+               os.makedirs(srcdst[0])
+
             if not os.path.isdir(srcdst[0]):
                 continue
 
@@ -141,10 +146,11 @@ def setup_chrootenv(chrootdir, bindmounts = None):
                                                            chrootdir,
                                                            None))
 
-        chrootmounts.append(fs_related.BindChrootMount("/",
-                                                       chrootdir,
-                                                       "/parentroot",
-                                                       "ro"))
+        if mountparent:
+            chrootmounts.append(fs_related.BindChrootMount("/",
+                                                           chrootdir,
+                                                           "/parentroot",
+                                                           "ro"))
 
         for kernel in os.listdir("/lib/modules"):
             chrootmounts.append(fs_related.BindChrootMount(
@@ -166,7 +172,7 @@ def setup_chrootenv(chrootdir, bindmounts = None):
         except:
             pass
 
-    globalmounts = get_bind_mounts(chrootdir, bindmounts)
+    globalmounts = get_bind_mounts(chrootdir, bindmounts, mountparent)
     bind_mount(globalmounts)
 
     setup_resolv(chrootdir)