Fix chroot failure caused by out-of-disk-space error.
authorXiaoning Zhu <xiaoning.zhu@intel.com>
Wed, 15 Jan 2014 05:39:30 +0000 (13:39 +0800)
committerGui Chen <gui.chen@intel.com>
Thu, 16 Jan 2014 06:43:27 +0000 (08:43 +0200)
If there is no space left on loop device, creation of mount points
will fail. In this case, mic will catch and ignore this failure.
Mic make its best effort to chroot.

Fix: #701

Change-Id: Ifb7666ec27f8bdb560983a9966ef171cb2a8a14b
Signed-off-by: Xiaoning Zhu <xiaoning.zhu@intel.com>
mic/chroot.py
mic/utils/fs_related.py

index 8a74137..a2bafdf 100644 (file)
@@ -145,10 +145,13 @@ def setup_resolv(chrootdir):
 
 def setup_mtab(chrootdir):
     """ adjust mount table """
-    mtab = "/etc/mtab"
-    dstmtab = chrootdir + mtab
-    if not os.path.islink(dstmtab):
-        shutil.copyfile(mtab, dstmtab)
+    try:
+        mtab = "/etc/mtab"
+        dstmtab = chrootdir + mtab
+        if not os.path.islink(dstmtab):
+            shutil.copyfile(mtab, dstmtab)
+    except (OSError, IOError):
+        pass
 
 def setup_chrootenv(chrootdir, bindmounts = None):
     """ setup chroot environment """
@@ -307,9 +310,12 @@ def chroot(chrootdir, bindmounts = None, execute = "/bin/bash"):
 
     savefs_before_chroot(chrootdir, None)
 
+    globalmounts = None
+
     try:
         msger.info("Launching shell. Exit to continue.\n"
                    "----------------------------------")
+
         globalmounts = setup_chrootenv(chrootdir, bindmounts)
         subprocess.call(execute, preexec_fn = mychroot, shell=True)
 
index 4c38a27..514fd41 100644 (file)
@@ -121,7 +121,13 @@ class BindChrootMount:
         if self.mounted or self.ismounted():
             return
 
-        makedirs(self.dest)
+        try:
+            makedirs(self.dest)
+        except OSError, err:
+            if err.errno == errno.ENOSPC:
+                msger.warning("No space left on device '%s'" % err.filename)
+                return
+
         if self.mount_option:
             cmdline = [self.mountcmd, "--bind", "-o", "%s" % \
                        self.mount_option, self.src, self.dest]