summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGui Chen <gui.chen@intel.com>2013-03-25 11:19:21 +0800
committerGui Chen <gui.chen@intel.com>2013-03-27 11:01:48 +0800
commit70f363725b922b5f6268f3a84424434107a819d4 (patch)
tree7a18b52c3b89c48adec168dd0ccc229377e0a84c
parent410c37df6260642aebb4fd1b53f7f275d7a27b83 (diff)
downloadmic-70f363725b922b5f6268f3a84424434107a819d4.tar.gz
mic-70f363725b922b5f6268f3a84424434107a819d4.tar.bz2
mic-70f363725b922b5f6268f3a84424434107a819d4.zip
mount tmpdir as tmpfs to accelerate performance
use --tmpfs to enable this experimental feature Change-Id: I5fb8e60a24236f7e6cab624a137c3ddb3d03f7d9 Signed-off-by: Gui Chen <gui.chen@intel.com>
-rw-r--r--mic/creator.py6
-rw-r--r--mic/imager/baseimager.py25
2 files changed, 30 insertions, 1 deletions
diff --git a/mic/creator.py b/mic/creator.py
index afe1654..af5fb82 100644
--- a/mic/creator.py
+++ b/mic/creator.py
@@ -112,6 +112,9 @@ class Creator(cmdln.Cmdln):
dest='install_pkgs', default=None,
help='Specify what type of packages to be installed,'
' valid: source, debuginfo, debugsource')
+ optparser.add_option('', '--tmpfs', action='store_true', dest='enabletmpfs',
+ help='Setup tmpdir as tmpfs to accelerate, experimental'
+ ' feature, use it if you have more than 4G memory')
optparser.add_option('', '--repourl', action='append',
dest='repourl', default=[],
help=SUPPRESS_HELP)
@@ -241,6 +244,9 @@ class Creator(cmdln.Cmdln):
configmgr.create['install_pkgs'].append(pkgtype)
+ if self.options.enabletmpfs:
+ configmgr.create['enabletmpfs'] = self.options.enabletmpfs
+
if self.options.repourl:
for item in self.options.repourl:
try:
diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py
index 96f653e..4a501dd 100644
--- a/mic/imager/baseimager.py
+++ b/mic/imager/baseimager.py
@@ -71,6 +71,7 @@ class BaseImageCreator(object):
self.name = "target"
self.tmpdir = "/var/tmp/mic"
self.cachedir = "/var/tmp/mic/cache"
+ self.workdir = "/var/tmp/mic/build"
self.destdir = "."
self.target_arch = "noarch"
self._local_pkgs_path = None
@@ -79,6 +80,8 @@ class BaseImageCreator(object):
# If the kernel is save to the destdir when copy_kernel cmd is called.
self._need_copy_kernel = False
+ # setup tmpfs tmpdir when enabletmpfs is True
+ self.enabletmpfs = False
if createopts:
# Mapping table for variables that have different names.
@@ -585,7 +588,10 @@ class BaseImageCreator(object):
return
try:
- self.__builddir = tempfile.mkdtemp(dir = self.tmpdir,
+ self.workdir = os.path.join(self.tmpdir, "build")
+ if not os.path.exists(self.workdir):
+ os.makedirs(self.workdir)
+ self.__builddir = tempfile.mkdtemp(dir = self.workdir,
prefix = "imgcreate-")
except OSError, (err, msg):
raise CreatorError("Failed create build directory in %s: %s" %
@@ -647,6 +653,18 @@ class BaseImageCreator(object):
os.umask(origumask)
+ def __setup_tmpdir(self):
+ if not self.enabletmpfs:
+ return
+
+ runner.show('mount -t tmpfs -o size=4G tmpfs %s' % self.workdir)
+
+ def __clean_tmpdir(self):
+ if not self.enabletmpfs:
+ return
+
+ runner.show('umount -l %s' % self.workdir)
+
def mount(self, base_on = None, cachedir = None):
"""Setup the target filesystem in preparation for an install.
@@ -665,6 +683,7 @@ class BaseImageCreator(object):
multiple installs.
"""
+ self.__setup_tmpdir()
self.__ensure_builddir()
# prevent popup dialog in Ubuntu(s)
@@ -688,6 +707,7 @@ class BaseImageCreator(object):
self.qemu_emulator = misc.setup_qemu_emulator(self._instroot,
self.target_arch)
+
self.get_cachedir(cachedir)
# bind mount system directories into _instroot
@@ -748,6 +768,7 @@ class BaseImageCreator(object):
# reset settings of popup dialog in Ubuntu(s)
misc.unhide_loopdev_presentation()
+
def cleanup(self):
"""Unmounts the target filesystem and deletes temporary files.
@@ -773,6 +794,8 @@ class BaseImageCreator(object):
shutil.rmtree(self.__builddir, ignore_errors = True)
self.__builddir = None
+ self.__clean_tmpdir()
+
def __is_excluded_pkg(self, pkg):
if pkg in self._excluded_pkgs:
self._excluded_pkgs.remove(pkg)