From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 3F695138350 for ; Wed, 22 Apr 2020 05:52:43 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 746AFE0A8E; Wed, 22 Apr 2020 05:52:42 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 4C9A8E0A8E for ; Wed, 22 Apr 2020 05:52:42 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 3DB6134F0FE for ; Wed, 22 Apr 2020 05:52:41 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id F3F821ED for ; Wed, 22 Apr 2020 05:52:39 +0000 (UTC) From: "Matt Turner" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Matt Turner" Message-ID: <1587514944.773270f3647a0d08d6468eccb141496f26e0a601.mattst88@gentoo> Subject: [gentoo-commits] proj/catalyst:master commit in: catalyst/, catalyst/base/ X-VCS-Repository: proj/catalyst X-VCS-Files: catalyst/base/stagebase.py catalyst/defaults.py X-VCS-Directories: catalyst/base/ catalyst/ X-VCS-Committer: mattst88 X-VCS-Committer-Name: Matt Turner X-VCS-Revision: 773270f3647a0d08d6468eccb141496f26e0a601 X-VCS-Branch: master Date: Wed, 22 Apr 2020 05:52:39 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: b8d97790-da35-4259-b65a-a5933b4c5a4d X-Archives-Hash: e62935c4ba758356adf19833f5807356 commit: 773270f3647a0d08d6468eccb141496f26e0a601 Author: Matt Turner gentoo org> AuthorDate: Sat Apr 18 20:15:18 2020 +0000 Commit: Matt Turner gentoo org> CommitDate: Wed Apr 22 00:22:24 2020 +0000 URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=773270f3 catalyst: Consolidate mount code into an OrderedDict Keeping source and target together in a single data structure makes things tidier than having self.mountmap (map of mount name to source mount) self.targets_map (map of mount name to target mount) self.mounts (list of mounts in the order they're mounted) This also has another nice benefit: the the order that the mounts take place is stored in one location and isn't affected by the order in which the code chooses to enable or disable them (dependent on configuration options). Signed-off-by: Matt Turner gentoo.org> catalyst/base/stagebase.py | 94 ++++++++++++++++++++------------------------ catalyst/defaults.py | 97 +++++++++++++++++++++++++++++++++------------- 2 files changed, 112 insertions(+), 79 deletions(-) diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py index f8c1611e..cc997688 100644 --- a/catalyst/base/stagebase.py +++ b/catalyst/base/stagebase.py @@ -11,8 +11,7 @@ from snakeoil.osutils import pjoin from DeComp.compress import CompressMap from catalyst import log -from catalyst.defaults import (SOURCE_MOUNT_DEFAULTS, TARGET_MOUNT_DEFAULTS, - PORT_LOGDIR_CLEAN) +from catalyst.defaults import (MOUNT_DEFAULTS, PORT_LOGDIR_CLEAN) from catalyst.support import (CatalystError, file_locate, normpath, cmd, read_makeconf, ismount, file_check) from catalyst.base.targetbase import TargetBase @@ -188,46 +187,39 @@ class StageBase(TargetBase, ClearBase, GenBase): file_locate(self.settings, ["portage_confdir"], expand=0) # Setup our mount points. - # initialize our target mounts. - self.target_mounts = TARGET_MOUNT_DEFAULTS.copy() - - self.mounts = ["proc", "dev", "portdir", "distdir", "port_tmpdir"] - # initialize our source mounts - self.mountmap = SOURCE_MOUNT_DEFAULTS.copy() - # update these from settings - self.mountmap["portdir"] = self.settings["portdir"] - self.mountmap["distdir"] = self.settings["distdir"] - self.target_mounts["portdir"] = normpath(self.settings["repo_basedir"] + - "/" + self.settings["repo_name"]) - self.target_mounts["distdir"] = self.settings["target_distdir"] - self.target_mounts["packagedir"] = self.settings["target_pkgdir"] + self.mount = MOUNT_DEFAULTS.copy() + + self.mount['portdir']['source'] = self.settings['portdir'] + self.mount['portdir']['target'] = normpath(self.settings["repo_basedir"] + + "/" + + self.settings["repo_name"]) + self.mount['distdir']['source'] = self.settings['distdir'] + self.mount["distdir"]['target'] = self.settings["target_distdir"] + if "snapcache" not in self.settings["options"]: - self.mounts.remove("portdir") - self.mountmap["portdir"] = None + self.mount['portdir']['enable'] = False else: - self.mountmap["portdir"] = normpath("/".join([ - self.settings["snapshot_cache_path"], - self.settings["repo_name"], + self.mount['portdir']['source'] = normpath("/".join([ + self.settings['snapshot_cache_path'], + self.settings['repo_name'] ])) - self.mounts.append("devpts") - self.mounts.append("shm") - self.mounts.append("run") # Configure any user specified options (either in catalyst.conf or on # the command line). if "pkgcache" in self.settings["options"]: self.set_pkgcache_path() + self.mount['pkgdir']['enable'] = True + self.mount['pkgdir']['source'] = self.settings['pkgcache_path'] + self.mount['pkgdir']['target'] = self.settings["target_pkgdir"] log.info('Location of the package cache is %s', self.settings['pkgcache_path']) - self.mounts.append("packagedir") - self.mountmap["packagedir"] = self.settings["pkgcache_path"] if "kerncache" in self.settings["options"]: self.set_kerncache_path() + self.mount['kerncache']['enable'] = True + self.mount['kerncache']['source'] = self.settings["kerncache_path"] log.info('Location of the kerncache is %s', self.settings['kerncache_path']) - self.mounts.append("kerncache") - self.mountmap["kerncache"] = self.settings["kerncache_path"] if "ccache" in self.settings["options"]: if "CCACHE_DIR" in os.environ: @@ -238,20 +230,19 @@ class StageBase(TargetBase, ClearBase, GenBase): if not os.path.isdir(ccdir): raise CatalystError( "Compiler cache support can't be enabled (can't find " + ccdir+")") - self.mounts.append("ccache") - self.mountmap["ccache"] = ccdir - # for the chroot: - self.env["CCACHE_DIR"] = self.target_mounts["ccache"] + self.mount['ccache']['enable'] = True + self.mount['ccache']['source'] = ccdir + self.env["CCACHE_DIR"] = self.mount['ccache']['target'] if "icecream" in self.settings["options"]: - self.mounts.append("icecream") - self.mountmap["icecream"] = self.settings["icecream"] - self.env["PATH"] = self.target_mounts["icecream"] + \ + self.mount['icecream']['enable'] = True + self.mount['icecream']['source'] = self.settings['icecream'] + self.env["PATH"] = self.mount['icecream']['target'] + \ ":" + self.env["PATH"] if "port_logdir" in self.settings: - self.mounts.append("port_logdir") - self.mountmap["port_logdir"] = self.settings["port_logdir"] + self.mount['port_logdir']['enable'] = True + self.mount['port_logdir']['source'] = self.settings['port_logdir'] self.env["PORT_LOGDIR"] = self.settings["port_logdir"] self.env["PORT_LOGDIR_CLEAN"] = PORT_LOGDIR_CLEAN @@ -697,10 +688,10 @@ class StageBase(TargetBase, ClearBase, GenBase): if not os.path.exists(self.settings["chroot_path"]): return - log.debug('self.mounts = %s', self.mounts) - for x in self.mounts: - target = normpath( - self.settings["chroot_path"] + self.target_mounts[x]) + log.debug('self.mount = %s', self.mount) + for x in [x for x in self.mount if self.mount[x]['enable']]: + target = normpath(self.settings['chroot_path'] + + self.mount[x]['target']) log.debug('mount_safety_check() x = %s %s', x, target) if not os.path.exists(target): continue @@ -971,17 +962,17 @@ class StageBase(TargetBase, ClearBase, GenBase): env=self.env) def bind(self): - for x in self.mounts: + for x in [x for x in self.mount if self.mount[x]['enable']]: log.debug('bind(); x = %s', x) - target = normpath( - self.settings["chroot_path"] + self.target_mounts[x]) + target = normpath(self.settings['chroot_path'] + + self.mount[x]['target']) ensure_dirs(target, mode=0o755) - if not os.path.exists(self.mountmap[x]): - if self.mountmap[x] not in ("maybe_tmpfs", "tmpfs", "shmfs"): - ensure_dirs(self.mountmap[x], mode=0o755) + if not os.path.exists(self.mount[x]['source']): + if self.mount[x]['source'] not in ("maybe_tmpfs", "tmpfs", "shmfs"): + ensure_dirs(self.mount[x]['source'], mode=0o755) - src = self.mountmap[x] + src = self.mount[x]['source'] log.debug('bind(); src = %s', src) if "snapcache" in self.settings["options"] and x == "portdir": self.snapcache_lock.read_lock() @@ -1008,11 +999,10 @@ class StageBase(TargetBase, ClearBase, GenBase): def unbind(self): ouch = 0 mypath = self.settings["chroot_path"] - myrevmounts = self.mounts[:] - myrevmounts.reverse() - # Unmount in reverse order for nested bind-mounts - for x in myrevmounts: - target = normpath(mypath + self.target_mounts[x]) + + # Unmount in reverse order + for x in [x for x in reversed(self.mount) if self.mount[x]['enable']]: + target = normpath(mypath + self.mount[x]['target']) if not os.path.exists(target): log.notice('%s does not exist. Skipping', target) continue diff --git a/catalyst/defaults.py b/catalyst/defaults.py index f292c211..e09d08e8 100644 --- a/catalyst/defaults.py +++ b/catalyst/defaults.py @@ -1,4 +1,6 @@ +from collections import OrderedDict + from DeComp.definitions import DECOMPRESSOR_SEARCH_ORDER from DeComp.definitions import COMPRESSOR_PROGRAM_OPTIONS, XATTRS_OPTIONS from DeComp.definitions import DECOMPRESSOR_PROGRAM_OPTIONS, LIST_XATTRS_OPTIONS @@ -68,7 +70,7 @@ confdefaults = { "port_conf": "/etc/portage", "make_conf": "%(port_conf)s/make.conf", "options": set(), - "packagedir": PKGDIR[:], + "pkgdir": PKGDIR[:], "portdir": PORTDIR[:], "port_tmpdir": "/var/tmp/portage", "PythonDir": "./catalyst", @@ -89,32 +91,73 @@ DEFAULT_CONFIG_FILE = '/etc/catalyst/catalyst.conf' PORT_LOGDIR_CLEAN = \ 'find "${PORT_LOGDIR}" -type f ! -name "summary.log*" -mtime +30 -delete' -TARGET_MOUNT_DEFAULTS = { - "ccache": "/var/tmp/ccache", - "dev": "/dev", - "devpts": "/dev/pts", - "distdir": DISTDIR[:], - "icecream": "/usr/lib/icecc/bin", - "kerncache": "/tmp/kerncache", - "packagedir": PKGDIR[:], - "portdir": PORTDIR[:], - "port_tmpdir": "/var/tmp/portage", - "port_logdir": "/var/log/portage", - "proc": "/proc", - "shm": "/dev/shm", - "run": "/run", -} - -SOURCE_MOUNT_DEFAULTS = { - "dev": "/dev", - "devpts": "/dev/pts", - "distdir": DISTDIR[:], - "portdir": PORTDIR[:], - "port_tmpdir": "maybe_tmpfs", - "proc": "/proc", - "shm": "shmfs", - "run": "tmpfs", -} +MOUNT_DEFAULTS = OrderedDict([ + ('proc', { + 'enable': True, + 'source': '/proc', + 'target': '/proc', + }), + ('dev', { + 'enable': True, + 'source': '/dev', + 'target': '/dev', + }), + ('devpts', { + 'enable': True, + 'source': '/dev/pts', + 'target': '/dev/pts', + }), + ('shm', { + 'enable': True, + 'source': 'shmfs', + 'target': '/dev/shm', + }), + ('run', { + 'enable': True, + 'source': 'tmpfs', + 'target': '/run', + }), + ('portdir', { + 'enable': True, + 'source': 'config', + 'target': 'config', + }), + ('distdir', { + 'enable': True, + 'source': 'config', + 'target': 'config', + }), + ('pkgdir', { + 'enable': False, + 'source': 'config', + 'target': 'config', + }), + ('port_tmpdir', { + 'enable': True, + 'source': 'maybe_tmpfs', + 'target': '/var/tmp/portage', + }), + ('kerncache', { + 'enable': False, + 'source': 'config', + 'target': '/tmp/kerncache', + }), + ('port_logdir', { + 'enable': False, + 'source': 'config', + 'target': '/var/log/portage', + }), + ('ccache', { + 'enable': False, + 'source': 'config', + 'target': '/var/tmp/ccache', + }), + ('icecream', { + 'enable': False, + 'source': ..., + 'target': '/usr/lib/icecc/bin', + }), +]) option_messages = { "autoresume": "Autoresuming support enabled.",