From 2d8f93d64130f83f9f0ac4e8e7af1ed8a3dd661b Mon Sep 17 00:00:00 2001 From: Xiaoning Zhu Date: Wed, 15 Jan 2014 13:39:30 +0800 Subject: [PATCH] Fix chroot failure caused by out-of-disk-space error. 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 --- mic/chroot.py | 14 ++++++++++---- mic/utils/fs_related.py | 8 +++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/mic/chroot.py b/mic/chroot.py index 8a74137..a2bafdf 100644 --- a/mic/chroot.py +++ b/mic/chroot.py @@ -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) diff --git a/mic/utils/fs_related.py b/mic/utils/fs_related.py index 4c38a27..514fd41 100644 --- a/mic/utils/fs_related.py +++ b/mic/utils/fs_related.py @@ -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] -- 2.7.4