* [gentoo-commits] proj/catalyst:wip/mattst88 commit in: catalyst/, catalyst/base/
@ 2020-05-27 6:22 Matt Turner
0 siblings, 0 replies; 4+ messages in thread
From: Matt Turner @ 2020-05-27 6:22 UTC (permalink / raw
To: gentoo-commits
commit: 4df7daf31c225910ef711aa980e9822c37018ed9
Author: Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Sat May 16 21:44:37 2020 +0000
Commit: Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Wed May 27 06:22:51 2020 +0000
URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=4df7daf3
catalyst: Add and use support API for handling mounts
Handle the mounts/unmounts in all in process rather than shelling out
(pun intended!) to an external program.
Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>
catalyst/base/stagebase.py | 28 ++++++++++++++++++----------
catalyst/mount.py | 32 ++++++++++++++++++++++++++++++++
2 files changed, 50 insertions(+), 10 deletions(-)
diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 00efd252..aa5cafd0 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -15,6 +15,7 @@ from DeComp.compress import CompressMap
from catalyst import log
from catalyst.defaults import (confdefaults, MOUNT_DEFAULTS, PORT_LOGDIR_CLEAN)
+from catalyst.mount import MS, mount, umount
from catalyst.support import (CatalystError, file_locate, normpath,
cmd, read_makeconf, ismount, file_check)
from catalyst.base.targetbase import TargetBase
@@ -847,7 +848,9 @@ class StageBase(TargetBase, ClearBase, GenBase):
source = str(self.mount[x]['source'])
target = self.settings['chroot_path'] + str(self.mount[x]['target'])
- mount = ['mount']
+ filesystem = ''
+ flags = MS.NONE
+ options = ''
log.debug('bind %s: "%s" -> "%s"', x, source, target)
@@ -855,18 +858,19 @@ class StageBase(TargetBase, ClearBase, GenBase):
if 'var_tmpfs_portage' not in self.settings:
continue
- mount += ['-t', 'tmpfs', '-o',
- f"size={self.settings['var_tmpfs_portage']}G"]
+ filesystem = 'tmpfs'
+ options = f"size={self.settings['var_tmpfs_portage']}G"
elif source == 'tmpfs':
- mount += ['-t', 'tmpfs']
+ filesystem = 'tmpfs'
elif source == 'shm':
- mount += ['-t', 'tmpfs', '-o', 'noexec,nosuid,nodev']
+ filesystem = 'tmpfs'
+ flags = MS.NOEXEC | MS.NOSUID | MS.NODEV
else:
source_path = Path(self.mount[x]['source'])
if source_path.suffix == '.sqfs':
- mount += ['-o', 'ro']
+ flags = MS.RDONLY
else:
- mount.append('--bind')
+ flags = MS.BIND
# We may need to create the source of the bind mount. E.g., in the
# case of an empty package cache we must create the directory that
@@ -875,7 +879,11 @@ class StageBase(TargetBase, ClearBase, GenBase):
Path(target).mkdir(mode=0o755, parents=True, exist_ok=True)
- cmd(mount + [source, target], env=self.env, fail_func=self.unbind)
+ try:
+ mount(source, target, filesystem, flags, options)
+ except OSError as e:
+ self.unbind()
+ raise CatalystError
def unbind(self):
ouch = 0
@@ -893,7 +901,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
continue
try:
- cmd(['umount', target], env=self.env)
+ umount(target)
except CatalystError:
log.warning('First attempt to unmount failed: %s', target)
log.warning('Killing any pids still running in the chroot')
@@ -901,7 +909,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
self.kill_chroot_pids()
try:
- cmd(['umount', target], env=self.env)
+ umount(target)
except CatalystError:
ouch = 1
log.warning("Couldn't umount bind mount: %s", target)
diff --git a/catalyst/mount.py b/catalyst/mount.py
new file mode 100644
index 00000000..21e974b1
--- /dev/null
+++ b/catalyst/mount.py
@@ -0,0 +1,32 @@
+import ctypes
+import ctypes.util
+import enum
+import os
+
+libc = ctypes.CDLL(ctypes.util.find_library('c'), use_errno=True)
+libc.mount.argtypes = (ctypes.c_char_p, ctypes.c_char_p, ctypes.c_char_p, ctypes.c_ulong, ctypes.c_char_p)
+libc.umount.argtypes = (ctypes.c_char_p,)
+
+class MS(enum.IntFlag):
+ NONE = 0x0
+ RDONLY = 0x1
+ NOSUID = 0x2
+ NODEV = 0x4
+ NOEXEC = 0x8
+ BIND = 0x1000
+
+def mount(source: str, target: str, fs: str, flags: MS = MS.NONE, options: str = '') -> None:
+ ret = libc.mount(source.encode(), target.encode(), fs.encode(), flags,
+ options.encode())
+ if ret < 0:
+ errno = ctypes.get_errno()
+ raise OSError(errno,
+ f"Error mounting {source} ({fs}) on {target} with options"
+ f" {options}': {os.strerror(errno)}")
+
+def umount(target: str) -> None:
+ ret = libc.umount(target.encode())
+ if ret < 0:
+ errno = ctypes.get_errno()
+ raise OSError(errno,
+ f"Error unmounting {target}': {os.strerror(errno)}")
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [gentoo-commits] proj/catalyst:wip/mattst88 commit in: catalyst/, catalyst/base/
@ 2020-12-19 19:56 Matt Turner
0 siblings, 0 replies; 4+ messages in thread
From: Matt Turner @ 2020-12-19 19:56 UTC (permalink / raw
To: gentoo-commits
commit: b556ff31b8d4caaef6c0e7612a70f5f0c397b02c
Author: Felix Bier <Felix.Bier <AT> rohde-schwarz <DOT> com>
AuthorDate: Tue Nov 10 00:59:01 2020 +0000
Commit: Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Sat Nov 14 16:34:57 2020 +0000
URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=b556ff31
Ensure deep copying of config defaults
This commit adds deep copying operations when initializing config
objects from a default config. This prevents the config from being
a shallow copy of the default, ensuring that modifications to the
config do not modify the default.
In particular, this fixes a check in write_make_conf, where the PORTDIR
variable is supposed to be only written to the generated make.conf when
a non-default repo_basedir is set in /etc/catalyst/catalyst.conf.
This check is never satisfied, because confvalues is a shallow copy of
confdefaults, therefore both will always hold the same value for
repo_basedir.
For self.mounts / MOUNT_DEFAULTS this problem can also be observed, the
modifications done to self.mounts are also visible in MOUNT_DEFAULTS.
I am not aware of any bugs due to this shallow copy, but I would prefer
adding a deep copy to prevent future bugs, in case a comparision
against the default mounts is ever needed.
Signed-off-by: Felix Bier <felix.bier <AT> rohde-schwarz.com>
Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>
catalyst/base/stagebase.py | 3 ++-
catalyst/main.py | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index a75dbdf9..21cf96a0 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -1,4 +1,5 @@
+import copy
import os
import platform
import shutil
@@ -187,7 +188,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
file_locate(self.settings, ["portage_confdir"], expand=0)
# Setup our mount points.
- self.mount = MOUNT_DEFAULTS.copy()
+ self.mount = copy.deepcopy(MOUNT_DEFAULTS)
self.mount['portdir']['source'] = self.snapshot
self.mount['portdir']['target'] = self.settings['repo_basedir'] + '/' + self.settings['repo_name']
diff --git a/catalyst/main.py b/catalyst/main.py
index 5536471a..48daf004 100644
--- a/catalyst/main.py
+++ b/catalyst/main.py
@@ -1,4 +1,5 @@
import argparse
+import copy
import datetime
import hashlib
import os
@@ -19,7 +20,7 @@ from catalyst.defaults import (confdefaults, option_messages,
from catalyst.support import CatalystError
from catalyst.version import get_version
-conf_values = confdefaults
+conf_values = copy.deepcopy(confdefaults)
def version():
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [gentoo-commits] proj/catalyst:wip/mattst88 commit in: catalyst/, catalyst/base/
2021-01-18 19:53 [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
@ 2020-12-19 19:56 ` Matt Turner
0 siblings, 0 replies; 4+ messages in thread
From: Matt Turner @ 2020-12-19 19:56 UTC (permalink / raw
To: gentoo-commits
commit: 37a386056f77f7cc8f1c2bdfe680b13bd806b4e6
Author: Felix Bier <Felix.Bier <AT> rohde-schwarz <DOT> com>
AuthorDate: Tue Nov 10 01:03:03 2020 +0000
Commit: Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Sat Nov 14 16:34:57 2020 +0000
URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=37a38605
Move from PORTDIR_OVERLAY to repos.conf
This commit fixes the following issues:
* The PORTDIR_OVERLAY variable has been deprecated by Gentoo.
With this commit, the variable is no longer written to the
generated make.conf. Instead, a config file
/etc/portage/repos.conf/<repo-name>.conf
is generated for each overlay. The repo name is read from the
overlay using the portage API. Internally, portage parses
metadata/layout.conf and profiles/repo_name to obtain the name.
References:
https://wiki.gentoo.org/wiki//etc/portage/make.conf
https://wiki.gentoo.org/wiki//etc/portage/repos.conf
* All overlays were copied into the same target directory. If the
same file name occurred in multiple overlays, the last overlay
would overwrite all previous files with this name. In particular,
only the metadata/layout.conf of the last overlay was retained,
so it was not possible to reference the other overlays e.g. via
the masters entry in the layout.conf or the portage-2 syntax
for specifying a parent profile from another overlay. Also,
this created problems when the overlays contained ebuilds
for the same package, but with differing versions, because
after copying, the target directory contained both versions of the
ebuild but only the manifest file of the last overlay.
With this commit, each overlay is copied into a separate
sub-directory, e.g. /var/db/repos/<repo-name>.
This directory is referenced via the location entry in the
generated /etc/portage/repos.conf/<repo-name>.conf.
Signed-off-by: Felix Bier <felix.bier <AT> rohde-schwarz.com>
Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>
catalyst/base/stagebase.py | 84 ++++++++++++++++++++++++++++++++++------------
catalyst/defaults.py | 2 +-
catalyst/support.py | 18 ++++++++++
3 files changed, 81 insertions(+), 23 deletions(-)
diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 21cf96a0..fe79b55a 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -1,4 +1,5 @@
+import configparser
import copy
import os
import platform
@@ -19,8 +20,8 @@ from catalyst import log
from catalyst.context import namespace
from catalyst.defaults import (confdefaults, MOUNT_DEFAULTS, PORT_LOGDIR_CLEAN)
from catalyst.support import (CatalystError, file_locate, normpath,
- cmd, read_makeconf, ismount, file_check,
- sanitize_name)
+ cmd, read_makeconf, get_repo_name, ismount,
+ file_check, sanitize_name)
from catalyst.base.targetbase import TargetBase
from catalyst.base.clearbase import ClearBase
from catalyst.base.genbase import GenBase
@@ -786,17 +787,55 @@ class StageBase(TargetBase, ClearBase, GenBase):
env=self.env)
self.resume.enable("setup_confdir")
+ def to_chroot(self, path):
+ """ Prepend chroot path to the given path. """
+
+ chroot = Path(self.settings['chroot_path'])
+ return chroot / path.relative_to(path.anchor)
+
+ def get_repo_conf_path(self, repo_name):
+ """ Construct repo conf path: {repos_conf}/{name}.conf """
+ return Path(self.settings['repos_conf'], repo_name + ".conf")
+
+ def get_repo_location(self, repo_name):
+ """ Construct overlay repo path: {repo_basedir}/{name} """
+ return Path(self.settings['repo_basedir'], repo_name)
+
+ def write_repo_conf(self, repo_name, config):
+ """ Write ConfigParser to {chroot}/{repos_conf}/{name}.conf """
+
+ repo_conf = self.get_repo_conf_path(repo_name)
+
+ repo_conf_chroot = self.to_chroot(repo_conf)
+ repo_conf_chroot.parent.mkdir(mode=0o755, parents=True, exist_ok=True)
+
+ log.info(f'Creating repo config {repo_conf_chroot}.')
+
+ try:
+ with open(repo_conf_chroot, 'w') as f:
+ config.write(f)
+ except OSError as e:
+ raise CatalystError(f'Could not write {repo_conf_chroot}: {e}') from e
+
def portage_overlay(self):
- """ We copy the contents of our overlays to /usr/local/portage """
+ """ We copy the contents of our repos to get_repo_location(repo_name) """
if "portage_overlay" in self.settings:
for x in self.settings["portage_overlay"]:
if os.path.exists(x):
- log.info('Copying overlay dir %s', x)
- ensure_dirs(
- self.settings['chroot_path'] + self.settings['local_overlay'])
- cmd("cp -a " + x + "/* " + self.settings["chroot_path"] +
- self.settings["local_overlay"],
- env=self.env)
+ name = get_repo_name(x)
+
+ location = self.get_repo_location(name)
+ config = configparser.ConfigParser()
+ config[name] = {'location': location}
+ self.write_repo_conf(name, config)
+
+ location_chroot = self.to_chroot(location)
+ location_chroot.mkdir(mode=0o755, parents=True, exist_ok=True)
+
+ log.info(f'Copying overlay dir {x} to {location_chroot}')
+ cmd(f'cp -a {x}/* {location_chroot}', env=self.env)
+ else:
+ log.warning(f'Skipping missing overlay {x}.')
def root_overlay(self):
""" Copy over the root_overlay """
@@ -852,8 +891,8 @@ class StageBase(TargetBase, ClearBase, GenBase):
cxt = libmount.Context(source=source, target=target,
fstype=fstype, options=options)
cxt.mount()
- except OSError as e:
- raise CatalystError(f"Couldn't mount: {source}, {e.strerror}")
+ except Exception as e:
+ raise CatalystError(f"Couldn't mount: {source}, {e}")
def chroot_setup(self):
self.makeconf = read_makeconf(normpath(self.settings["chroot_path"] +
@@ -1018,12 +1057,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
varname = x.split('_')[1].upper()
myf.write(f'{varname}="{self.settings[x]}"\n')
- if setup:
- # Setup the portage overlay
- if "portage_overlay" in self.settings:
- myf.write('PORTDIR_OVERLAY="%s"\n' %
- self.settings["local_overlay"])
-
# Set default locale for system responses. #478382
myf.write(
'\n'
@@ -1097,11 +1130,18 @@ class StageBase(TargetBase, ClearBase, GenBase):
log.warning("You've been hacking. Clearing target patches: %s", target)
clear_path(target)
- # Remove our overlay
- overlay = normpath(
- self.settings["chroot_path"] + self.settings["local_overlay"])
- if os.path.exists(overlay):
- clear_path(overlay)
+ # Remove our overlays
+ if "portage_overlay" in self.settings:
+ for repo_path in self.settings["portage_overlay"]:
+ repo_name = get_repo_name(repo_path)
+
+ repo_conf = self.get_repo_conf_path(repo_name)
+ chroot_repo_conf = self.to_chroot(repo_conf)
+ chroot_repo_conf.unlink()
+
+ location = self.get_repo_location(repo_name)
+ chroot_location = self.to_chroot(location)
+ clear_path(str(chroot_location))
if "sticky-config" not in self.settings["options"]:
# re-write the make.conf to be sure it is clean
diff --git a/catalyst/defaults.py b/catalyst/defaults.py
index 0f399b56..3f12b8d5 100644
--- a/catalyst/defaults.py
+++ b/catalyst/defaults.py
@@ -38,9 +38,9 @@ confdefaults = {
"distdir": portage.settings['DISTDIR'],
"icecream": "/var/cache/icecream",
'list_xattrs_opt': LIST_XATTRS_OPTIONS['linux'],
- "local_overlay": "/var/db/repos/local",
"port_conf": "/etc/portage",
"make_conf": "%(port_conf)s/make.conf",
+ "repos_conf": "%(port_conf)s/repos.conf",
"options": set(),
"pkgdir": "/var/cache/binpkgs",
"port_tmpdir": "/var/tmp/portage",
diff --git a/catalyst/support.py b/catalyst/support.py
index ddbd9ab9..f3a865a7 100644
--- a/catalyst/support.py
+++ b/catalyst/support.py
@@ -10,6 +10,8 @@ from subprocess import Popen
import libmount
+from portage.repository.config import RepoConfig
+
from catalyst import log
BASH_BINARY = "/bin/bash"
@@ -182,6 +184,22 @@ def read_makeconf(mymakeconffile):
return makeconf
+def get_repo_name(repo_path):
+ """ Get the name of the repo at the given repo_path.
+
+ References:
+ https://wiki.gentoo.org/wiki/Repository_format/profiles/repo_name
+ https://wiki.gentoo.org/wiki/Repository_format/metadata/layout.conf#repo-name
+ """
+
+ repo_config = RepoConfig(None, {"location": repo_path})
+
+ if repo_config.missing_repo_name:
+ raise CatalystError(f"Missing name in repository {repo_path}")
+
+ return repo_config.name
+
+
def ismount(path):
"""Like os.path.ismount, but also support bind mounts"""
path = Path(path)
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [gentoo-commits] proj/catalyst:wip/mattst88 commit in: catalyst/, catalyst/base/
@ 2021-06-10 0:48 Matt Turner
0 siblings, 0 replies; 4+ messages in thread
From: Matt Turner @ 2021-06-10 0:48 UTC (permalink / raw
To: gentoo-commits
commit: 483385348b32fab2230f596816b6e1d0b6489962
Author: Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
AuthorDate: Wed Feb 24 21:26:58 2021 +0000
Commit: Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Wed Feb 24 21:26:58 2021 +0000
URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=48338534
Add option to generate BSD-style tagged hashes (can be verified by modern coreutils)
Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>
catalyst/base/genbase.py | 6 +++++-
catalyst/defaults.py | 2 ++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/catalyst/base/genbase.py b/catalyst/base/genbase.py
index c7dd87bc..52418877 100644
--- a/catalyst/base/genbase.py
+++ b/catalyst/base/genbase.py
@@ -24,7 +24,11 @@ class GenBase():
h.update(data)
filename = os.path.split(filepath)[1]
- return f'# {name.upper()} HASH\n{h.hexdigest()} {filename}\n'
+
+ if self.settings['digest_format'] == 'bsd':
+ return f'# {name.upper()} HASH\n{name.upper()} ({filename}) = {h.hexdigest()}\n'
+ else:
+ return f'# {name.upper()} HASH\n{h.hexdigest()} {filename}\n'
def gen_contents_file(self, path):
c = self.settings['contents_map']
diff --git a/catalyst/defaults.py b/catalyst/defaults.py
index ccb0a584..2cede562 100644
--- a/catalyst/defaults.py
+++ b/catalyst/defaults.py
@@ -11,6 +11,7 @@ from DeComp.definitions import DECOMPRESSOR_PROGRAM_OPTIONS, LIST_XATTRS_OPTIONS
valid_config_file_values = frozenset([
"compression_mode",
"digests",
+ "digest_format",
"distcc_hosts",
"distdir",
"envscript",
@@ -35,6 +36,7 @@ confdefaults = {
"compressor_options": XATTRS_OPTIONS['linux'],
"decomp_opt": DECOMPRESSOR_PROGRAM_OPTIONS['linux'],
"decompressor_search_order": DECOMPRESSOR_SEARCH_ORDER,
+ "digest_format": 'linux',
"distdir": portage.settings['DISTDIR'],
"icecream": "/var/cache/icecream",
'list_xattrs_opt': LIST_XATTRS_OPTIONS['linux'],
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-06-10 0:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-27 6:22 [gentoo-commits] proj/catalyst:wip/mattst88 commit in: catalyst/, catalyst/base/ Matt Turner
-- strict thread matches above, loose matches on Subject: below --
2020-12-19 19:56 Matt Turner
2021-01-18 19:53 [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
2020-12-19 19:56 ` [gentoo-commits] proj/catalyst:wip/mattst88 " Matt Turner
2021-06-10 0:48 Matt Turner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox