From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 0E7D7138247 for ; Wed, 18 Dec 2013 01:01:30 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 90CCAE0AAD; Wed, 18 Dec 2013 01:01:29 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 19D00E0AAD for ; Wed, 18 Dec 2013 01:01:27 +0000 (UTC) Received: from big_daddy.dol-sen.ca (S010600222de111ff.vc.shawcable.net [96.49.5.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: dolsen) by smtp.gentoo.org (Postfix) with ESMTPSA id 36D9F33F59B; Wed, 18 Dec 2013 01:01:26 +0000 (UTC) From: Brian Dolbec To: gentoo-catalyst@lists.gentoo.org Cc: Brian Dolbec Subject: [gentoo-catalyst] [PATCH] modules/generic_stage_target.py, modules/stage1_target.py: Add a target_mounts dictionary Date: Tue, 17 Dec 2013 17:01:04 -0800 Message-Id: <1387328464-25678-2-git-send-email-dolsen@gentoo.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1387328464-25678-1-git-send-email-dolsen@gentoo.org> References: <1387328464-25678-1-git-send-email-dolsen@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-catalyst@lists.gentoo.org Reply-to: gentoo-catalyst@lists.gentoo.org X-Archives-Salt: 68549c68-cf27-4d88-8688-fd4ca4905d17 X-Archives-Hash: 31f6d42f97c377063555db3547564059 Cleanup all self.mounts, self.mountmap usage. Replace multiple path additions with one instance at the beginning of the function, reuse the result multiple times. Add some extra debug prints --- modules/generic_stage_target.py | 97 +++++++++++++++++++++++++---------------- modules/stage1_target.py | 5 ++- 2 files changed, 62 insertions(+), 40 deletions(-) diff --git a/modules/generic_stage_target.py b/modules/generic_stage_target.py index d7cffa9..d9cc499 100644 --- a/modules/generic_stage_target.py +++ b/modules/generic_stage_target.py @@ -4,6 +4,21 @@ from generic_target import * from stat import * import catalyst_lock +target_mounts = { + "proc": "/proc", + "dev": "/dev", + "devpts": "/dev/pts", + "portdir": "/usr/portage", + "distdir": "/usr/portage/distfiles", + "packagedir": "/usr/portage/packages", + "port_tmpdir": "/var/tmp/portage", + "kerncache": "/tmp/kerncache", + "ccache": "/var/tmp/ccache", + "icecream": "/var/cache/icecream", + "port_logdir": "/var/log/portage", + } + + class generic_stage_target(generic_target): """ This class does all of the chroot setup, copying of files, etc. It is @@ -173,11 +188,12 @@ class generic_stage_target(generic_target): file_locate(self.settings,["portage_confdir"],expand=0) """ Setup our mount points """ + self.target_mounts = target_mounts.copy() if "SNAPCACHE" in self.settings: self.mounts=["proc", "dev", "portdir", "distdir", "port_tmpdir"] self.mountmap={"proc":"/proc", "dev":"/dev", "devpts":"/dev/pts", - "portdir":self.settings["snapshot_cache_path"]+"/portage",\ - "distdir":self.settings["distdir"],"port_tmpdir":"tmpfs"} + "portdir":normpath(self.settings["snapshot_cache_path"]+"/" + self.settings["repo_name"]), + "distdir":self.settings["distdir"],"port_tmpdir":"tmpfs"} else: self.mounts = ["proc", "dev", "distdir", "port_tmpdir"] self.mountmap = {"proc":"/proc", "dev":"/dev", "devpts":"/dev/pts", @@ -218,17 +234,17 @@ class generic_stage_target(generic_target): self.mounts.append("ccache") self.mountmap["ccache"] = ccdir """ for the chroot: """ - self.env["CCACHE_DIR"]="/var/tmp/ccache" + self.env["CCACHE_DIR"] = self.target_mounts["ccache"] if "ICECREAM" in self.settings: - self.mounts.append("/var/cache/icecream") - self.mountmap["/var/cache/icecream"]="/var/cache/icecream" + self.mounts.append("icecream") + self.mountmap["icecream"] = self.target_mounts["icecream"] self.env["PATH"]="/usr/lib/icecc/bin:"+self.env["PATH"] if "port_logdir" in self.settings: - self.mounts.append("/var/log/portage") - self.mountmap["/var/log/portage"]=self.settings["port_logdir"] - self.env["PORT_LOGDIR"]="/var/log/portage" + self.mounts.append("port_logdir") + self.mountmap["port_logdir"]=self.settings["port_logdir"] + self.env["PORT_LOGDIR"]=self.settings["port_logdir"] self.env["PORT_LOGDIR_CLEAN"]='find "${PORT_LOGDIR}" -type f ! -name "summary.log*" -mtime +30 -delete' def override_cbuild(self): @@ -602,33 +618,34 @@ class generic_stage_target(generic_target): "kill-chroot-pids script failed.",env=self.env) def mount_safety_check(self): - mypath=self.settings["chroot_path"] - """ Check and verify that none of our paths in mypath are mounted. We don't want to clean up with things still mounted, and this allows us to check. Returns 1 on ok, 0 on "something is still mounted" case. """ - if not os.path.exists(mypath): + if not os.path.exists(self.settings["chroot_path"]): return + print "self.mounts =", self.mounts for x in self.mounts: - if not os.path.exists(mypath + self.mountmap[x]): + target = normpath(self.settings["chroot_path"] + self.target_mounts[x]) + print "mount_safety_check() x =", x, target + if not os.path.exists(target): continue - if ismount(mypath + self.mountmap[x]): + if ismount(target): """ Something is still mounted "" """ try: - print self.mountmap[x] + " is still mounted; performing auto-bind-umount...", + print target + " is still mounted; performing auto-bind-umount...", """ Try to umount stuff ourselves """ self.unbind() - if ismount(mypath + self.mountmap[x]): - raise CatalystError, "Auto-unbind failed for " + self.mountmap[x] + if ismount(target): + raise CatalystError, "Auto-unbind failed for " + target else: print "Auto-unbind successful..." except CatalystError: - raise CatalystError, "Unable to auto-unbind " + self.mountmap[x] + raise CatalystError, "Unable to auto-unbind " + target def unpack(self): unpack=True @@ -896,32 +913,37 @@ class generic_stage_target(generic_target): def bind(self): for x in self.mounts: - if not os.path.exists(self.settings["chroot_path"] + self.mountmap[x]): - os.makedirs(self.settings["chroot_path"]+x,0755) + #print "bind(); x =", x + target = normpath(self.settings["chroot_path"] + self.target_mounts[x]) + if not os.path.exists(target): + os.makedirs(target, 0755) if not os.path.exists(self.mountmap[x]): if not self.mountmap[x] == "tmpfs": - os.makedirs(self.mountmap[x],0755) + os.makedirs(self.mountmap[x], 0755) src=self.mountmap[x] - if "SNAPCACHE" in self.settings and x == "/usr/portage": + #print "bind(); src =", src + if "SNAPCACHE" in self.settings and x == self.settings["portdir"]: self.snapshot_lock_object.read_lock() if os.uname()[0] == "FreeBSD": if src == "/dev": - retval = os.system("mount -t devfs none " + - self.settings["chroot_path"] + src) + cmd = "mount -t devfs none " + target + retval=os.system(cmd) else: - retval = os.system("mount_nullfs " + src + " " + - self.settings["chroot_path"] + src) + cmd = "mount_nullfs " + src + " " + target + retval=os.system(cmd) else: if src == "tmpfs": if "var_tmpfs_portage" in self.settings: - retval=os.system("mount -t tmpfs -o size="+\ - self.settings["var_tmpfs_portage"]+"G "+src+" "+\ - self.settings["chroot_path"]+x) + cmd = "mount -t tmpfs -o size=" + \ + self.settings["var_tmpfs_portage"] + "G " + \ + src + " " + target + retval=os.system(cmd) else: - retval = os.system("mount --bind " + src + " " + - self.settings["chroot_path"] + src) + cmd = "mount --bind " + src + " " + target + #print "bind(); cmd =", cmd + retval=os.system(cmd) if retval!=0: self.unbind() raise CatalystError,"Couldn't bind mount " + src @@ -933,26 +955,25 @@ class generic_stage_target(generic_target): myrevmounts.reverse() """ Unmount in reverse order for nested bind-mounts """ for x in myrevmounts: - if not os.path.exists(mypath + self.mountmap[x]): + target = normpath(mypath + self.target_mounts[x]) + if not os.path.exists(target): continue - if not ismount(mypath + self.mountmap[x]): + if not ismount(target): continue - retval=os.system("umount "+\ - os.path.join(mypath, self.mountmap[x].lstrip(os.path.sep))) + retval=os.system("umount " + target) if retval!=0: - warn("First attempt to unmount: " + mypath + - self.mountmap[x] +" failed.") + warn("First attempt to unmount: " + target + " failed.") warn("Killing any pids still running in the chroot") self.kill_chroot_pids() - retval2 = os.system("umount " + mypath + self.mountmap[x]) + retval2 = os.system("umount " + target) if retval2!=0: ouch=1 - warn("Couldn't umount bind mount: " + mypath + self.mountmap[x]) + warn("Couldn't umount bind mount: " + target) if "SNAPCACHE" in self.settings and x == "/usr/portage": try: diff --git a/modules/stage1_target.py b/modules/stage1_target.py index aa43926..1e0d874 100644 --- a/modules/stage1_target.py +++ b/modules/stage1_target.py @@ -88,8 +88,9 @@ class stage1_target(generic_stage_target): os.makedirs(self.settings["stage_path"]+"/proc") # alter the mount mappings to bind mount proc onto it - self.mounts.append("/tmp/stage1root/proc") - self.mountmap["/tmp/stage1root/proc"]="/proc" + self.mounts.append("stage1root/proc") + self.target_mounts["stage1root/proc"] = "/tmp/stage1root/proc" + self.mountmap["stage1root/proc"]="/proc" def register(foo): foo.update({"stage1":stage1_target}) -- 1.8.3.2