public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/catalyst:master commit in: catalyst/base/
@ 2020-10-24 22:07 Matt Turner
  2020-10-23  4:36 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
  2020-10-29 21:00 ` [gentoo-commits] proj/catalyst:wip/mattst88 " Matt Turner
  0 siblings, 2 replies; 31+ messages in thread
From: Matt Turner @ 2020-10-24 22:07 UTC (permalink / raw
  To: gentoo-commits

commit:     e13140dcbcd4d03ef3884bfb9c8af0d820fdb957
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 23 04:10:56 2020 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Fri Oct 23 04:10:56 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=e13140dc

catalyst: Drop stray vim modeline

This was the only one in catalyst. We should have an EditorConfig file
instead.

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 2 --
 1 file changed, 2 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 603e49d9..e71ce344 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -1611,5 +1611,3 @@ class StageBase(TargetBase, ClearBase, GenBase):
     @staticmethod
     def _debug_pause_():
         input("press any key to continue: ")
-
-# vim: ts=4 sw=4 sta et sts=4 ai


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:master commit in: catalyst/base/
@ 2021-01-28  2:41 Matt Turner
  2021-01-28  2:09 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
  0 siblings, 1 reply; 31+ messages in thread
From: Matt Turner @ 2021-01-28  2:41 UTC (permalink / raw
  To: gentoo-commits

commit:     2d348c2e9d063662a9fd4526d77fd28cacf233ce
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Sun Jan 24 01:54:16 2021 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Thu Jan 28 02:06:46 2021 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=2d348c2e

catalyst: Use lazy % formatting in logging functions

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 25efd4b3..28ff8fd2 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -823,7 +823,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
         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}.')
+        log.info('Creating repo config %s.', repo_conf_chroot)
 
         try:
             with open(repo_conf_chroot, 'w') as f:
@@ -846,10 +846,10 @@ class StageBase(TargetBase, ClearBase, GenBase):
                     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}')
+                    log.info('Copying overlay dir %s to %s', x, location_chroot)
                     cmd(f'cp -a {x}/* {location_chroot}', env=self.env)
                 else:
-                    log.warning(f'Skipping missing overlay {x}.')
+                    log.warning('Skipping missing overlay %s.', x)
 
     def root_overlay(self):
         """ Copy over the root_overlay """


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:master commit in: catalyst/base/
@ 2021-01-28  2:41 Matt Turner
  2021-01-28  2:09 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
  0 siblings, 1 reply; 31+ messages in thread
From: Matt Turner @ 2021-01-28  2:41 UTC (permalink / raw
  To: gentoo-commits

commit:     30c40a1572e7c95c39c0367d1ed0fbc08c7adc87
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Thu Jan 28 02:04:26 2021 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Thu Jan 28 02:06:45 2021 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=30c40a15

catalyst: Fix copy-and-paste mistake

Fixes: 87b0588a ("catalyst: Add option to enter the chroot before building")
Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 676206ff..25efd4b3 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -95,7 +95,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
             self.chroot_setup,
             self.setup_environment,
         ]
-        if 'enter-chroot' in self.settings['options']:
+        if 'enter-chroot' in myspec['options']:
             self.build_sequence.append(self.enter_chroot)
 
         self.finish_sequence = []


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/base/
@ 2021-01-28  2:09 Matt Turner
  0 siblings, 0 replies; 31+ messages in thread
From: Matt Turner @ 2021-01-28  2:09 UTC (permalink / raw
  To: gentoo-commits

commit:     d52c931a600cb0dc7193ccda37d39218c094b7d0
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Sun Jan 24 01:42:50 2021 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Thu Jan 28 02:06:45 2021 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=d52c931a

catalyst: Remove unused import

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/targetbase.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/catalyst/base/targetbase.py b/catalyst/base/targetbase.py
index 3e338bee..ce16566b 100644
--- a/catalyst/base/targetbase.py
+++ b/catalyst/base/targetbase.py
@@ -3,7 +3,7 @@ import os
 from abc import ABC, abstractmethod
 from pathlib import Path
 
-from catalyst.support import addl_arg_parse, CatalystError
+from catalyst.support import addl_arg_parse
 
 
 class TargetBase(ABC):


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/base/
@ 2021-01-28  1:54 Matt Turner
  0 siblings, 0 replies; 31+ messages in thread
From: Matt Turner @ 2021-01-28  1:54 UTC (permalink / raw
  To: gentoo-commits

commit:     126b72449f3c02197602cff558d32b1ec8929554
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Sun Jan 24 01:54:16 2021 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Sun Jan 24 01:57:37 2021 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=126b7244

catalyst: Use lazy % formatting in logging functions

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 676206ff..badcfefa 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -823,7 +823,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
         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}.')
+        log.info('Creating repo config %s.', repo_conf_chroot)
 
         try:
             with open(repo_conf_chroot, 'w') as f:
@@ -846,10 +846,10 @@ class StageBase(TargetBase, ClearBase, GenBase):
                     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}')
+                    log.info('Copying overlay dir %s to %s', x, location_chroot)
                     cmd(f'cp -a {x}/* {location_chroot}', env=self.env)
                 else:
-                    log.warning(f'Skipping missing overlay {x}.')
+                    log.warning('Skipping missing overlay %s.', x)
 
     def root_overlay(self):
         """ Copy over the root_overlay """


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/base/
@ 2021-01-28  1:54 Matt Turner
  0 siblings, 0 replies; 31+ messages in thread
From: Matt Turner @ 2021-01-28  1:54 UTC (permalink / raw
  To: gentoo-commits

commit:     2a55fecba0256c3202319f53f41036623308248e
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Sun Jan 24 01:42:50 2021 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Sun Jan 24 01:42:50 2021 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=2a55fecb

catalyst: Remove unused import

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/targetbase.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/catalyst/base/targetbase.py b/catalyst/base/targetbase.py
index 3e338bee..ce16566b 100644
--- a/catalyst/base/targetbase.py
+++ b/catalyst/base/targetbase.py
@@ -3,7 +3,7 @@ import os
 from abc import ABC, abstractmethod
 from pathlib import Path
 
-from catalyst.support import addl_arg_parse, CatalystError
+from catalyst.support import addl_arg_parse
 
 
 class TargetBase(ABC):


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/base/
@ 2021-01-18 19:53 Matt Turner
  0 siblings, 0 replies; 31+ messages in thread
From: Matt Turner @ 2021-01-18 19:53 UTC (permalink / raw
  To: gentoo-commits

commit:     a0f348e99151277cfd52ce1343777844dae5e0e8
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 19 01:58:21 2020 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Sat Dec 19 02:56:52 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=a0f348e9

catalyst: Set stage_path = chroot_path + root_path

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index fe79b55a..ba6b1a1b 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -545,7 +545,8 @@ class StageBase(TargetBase, ClearBase, GenBase):
             self.settings["catalyst_use"].append("bindist")
 
     def set_stage_path(self):
-        self.settings["stage_path"] = normpath(self.settings["chroot_path"])
+        self.settings["stage_path"] = normpath(self.settings["chroot_path"] +
+                                               self.settings["root_path"])
 
     def set_packages(self):
         pass


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/base/
@ 2020-10-29 19:05 Matt Turner
  0 siblings, 0 replies; 31+ messages in thread
From: Matt Turner @ 2020-10-29 19:05 UTC (permalink / raw
  To: gentoo-commits

commit:     570fb210e97f9f5f2213a77069c3983181820f02
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 29 13:03:33 2020 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Thu Oct 29 19:05:45 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=570fb210

catalyst: Factor out run_sequence()

This is preparation for the next patch, which will run the build
sequence in a separate mount namespace.

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 40 +++++++++++++++++++++++-----------------
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 75c84baa..06ec8727 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -1362,6 +1362,22 @@ class StageBase(TargetBase, ClearBase, GenBase):
 
         log.debug('setup_environment(); env = %r', self.env)
 
+    def run_sequence(self, sequence):
+        for func in sequence:
+            log.notice('--- Running action sequence: %s', func)
+            sys.stdout.flush()
+            try:
+                getattr(self, func)()
+            except LockInUse:
+                log.error('Unable to aquire the lock...')
+                return False
+            except Exception:
+                log.error('Exception running action sequence %s',
+                          func, exc_info=True)
+                return False
+
+        return True
+
     def run(self):
         self.chroot_lock.write_lock()
 
@@ -1386,26 +1402,16 @@ class StageBase(TargetBase, ClearBase, GenBase):
             log.info('StageBase: run() purge')
             self.purge()
 
-        failure = False
-        for x in self.prepare_sequence + self.build_sequence + self.finish_sequence:
-            log.notice('--- Running action sequence: %s', x)
-            sys.stdout.flush()
-            try:
-                getattr(self, x)()
-            except LockInUse:
-                log.error('Unable to aquire the lock...')
-                failure = True
-                break
-            except Exception:
-                log.error('Exception running action sequence %s',
-                          x, exc_info=True)
-                failure = True
-                break
+        if not self.run_sequence(self.prepare_sequence):
+            return False
 
-        if failure:
-            log.notice('Cleaning up... Running unbind()')
+        if not self.run_sequence(self.build_sequence):
             self.unbind()
             return False
+
+        if not self.run_sequence(self.finish_sequence):
+            return False
+
         return True
 
     def unmerge(self):


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/base/
@ 2020-10-29 19:05 Matt Turner
  0 siblings, 0 replies; 31+ messages in thread
From: Matt Turner @ 2020-10-29 19:05 UTC (permalink / raw
  To: gentoo-commits

commit:     eb626707556da1c86f11ad77502041f7f3ef7c52
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: Thu Oct 29 19:05:44 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=eb626707

catalyst: Use libmount for handling mounts

Handle the mounts/unmounts in all in process rather than shelling out
(pun intended!) to an external program.

While we're here, change some log.notice to log.debug since those cases
are normal and expected.

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 57 ++++++++++++++++++++++++++++------------------
 1 file changed, 35 insertions(+), 22 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index e71ce344..73eacfbe 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -6,6 +6,7 @@ import sys
 
 from pathlib import Path
 
+import libmount
 import toml
 
 from snakeoil import fileutils
@@ -853,7 +854,8 @@ class StageBase(TargetBase, ClearBase, GenBase):
 
             source = str(self.mount[x]['source'])
             target = self.settings['chroot_path'] + str(self.mount[x]['target'])
-            mount = ['mount']
+            fstype = ''
+            options = ''
 
             log.debug('bind %s: "%s" -> "%s"', x, source, target)
 
@@ -861,18 +863,20 @@ 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"]
+                fstype = 'tmpfs'
+                options = f"size={self.settings['var_tmpfs_portage']}G"
             elif source == 'tmpfs':
-                mount += ['-t', 'tmpfs']
+                fstype = 'tmpfs'
             elif source == 'shm':
-                mount += ['-t', 'tmpfs', '-o', 'noexec,nosuid,nodev']
+                fstype = 'tmpfs'
+                options = 'noexec,nosuid,nodev'
             else:
                 source_path = Path(self.mount[x]['source'])
                 if source_path.suffix == '.sqfs':
-                    mount += ['-o', 'ro']
+                    fstype = 'squashfs'
+                    options = 'ro,loop'
                 else:
-                    mount.append('--bind')
+                    options = '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
@@ -881,38 +885,47 @@ 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:
+                cxt = libmount.Context(source=source, target=target,
+                                       fstype=fstype, options=options)
+                cxt.mount()
+            except OSError as e:
+                self.unbind()
+                raise CatalystError(f"Couldn't mount: {source}, {e.strerror}")
 
     def unbind(self):
-        ouch = 0
-        mypath = self.settings["chroot_path"]
+        chroot_path = self.settings["chroot_path"]
+        umount_failed = False
 
         # 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)
+        for target in [Path(chroot_path + self.mount[x]['target'])
+                       for x in reversed(self.mount)
+                       if self.mount[x]['enable']]:
+            if not target.exists():
+                log.debug('%s does not exist. Skipping', target)
                 continue
 
             if not ismount(target):
-                log.notice('%s is not a mount point. Skipping', target)
+                log.debug('%s is not a mount point. Skipping', target)
                 continue
 
             try:
-                cmd(['umount', target], env=self.env)
-            except CatalystError:
+                cxt = libmount.Context(target=str(target))
+                cxt.umount()
+            except OSError:
                 log.warning('First attempt to unmount failed: %s', target)
                 log.warning('Killing any pids still running in the chroot')
 
                 self.kill_chroot_pids()
 
                 try:
-                    cmd(['umount', target], env=self.env)
-                except CatalystError:
-                    ouch = 1
-                    log.warning("Couldn't umount bind mount: %s", target)
+                    cxt.umount()
+                except OSError as e:
+                    umount_failed = True
+                    log.warning("Couldn't umount: %s, %s", target,
+                                e.strerror)
 
-        if ouch:
+        if umount_failed:
             # if any bind mounts really failed, then we need to raise
             # this to potentially prevent an upcoming bash stage cleanup script
             # from wiping our bind mounts.


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/base/
@ 2020-10-29 19:05 Matt Turner
  0 siblings, 0 replies; 31+ messages in thread
From: Matt Turner @ 2020-10-29 19:05 UTC (permalink / raw
  To: gentoo-commits

commit:     c5af7adf780ce42670b0beda24c2dbfd4d39f34d
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 29 14:39:35 2020 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Thu Oct 29 19:05:45 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=c5af7adf

catalyst: Remove mount_safety_check()

mount_safety_check() exists to prevent bad things from happening if a
previous catalyst invocation left bind mounts active in the chroot.
E.g., a previous catalyst invocation is interrupted without unmounting
the bind mounts. A new catalyst invocation runs and cleans the old
chroot, which inadvertently deletes files outside of the chroot via the
bind mounts.

With all the mounts now inside a namespace, it is no longer possible to
have mounts accessible outside the build sequence. In fact, I think this
code has been unnecessary since commit e5a53e42 ("catalyst: create
namespaces for building").

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 37 -------------------------------------
 1 file changed, 37 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index bd5ba8d0..b9c220d0 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -638,39 +638,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
             assert self.settings[verify] == "blake2"
             self.settings.setdefault("gk_mainargs", []).append("--b2sum")
 
-    def mount_safety_check(self):
-        """
-        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(self.settings["chroot_path"]):
-            return
-
-        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
-
-            if ismount(target):
-                # Something is still mounted
-                try:
-                    log.warning(
-                        '%s is still mounted; performing auto-bind-umount...', target)
-                    # Try to umount stuff ourselves
-                    self.unbind()
-                    if ismount(target):
-                        raise CatalystError("Auto-unbind failed for " + target)
-                    log.notice('Auto-unbind successful...')
-                except CatalystError:
-                    raise CatalystError("Unable to auto-unbind " + target)
-
     def unpack(self):
-
         clst_unpack_hash = self.resume.get("unpack")
 
         # Set up all unpack info settings
@@ -755,8 +723,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
                     % self.settings["source_path"])
 
         if _unpack:
-            self.mount_safety_check()
-
             if invalid_chroot:
                 if "autoresume" in self.settings["options"]:
                     log.notice(
@@ -1363,9 +1329,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
     def run(self):
         self.chroot_lock.write_lock()
 
-        # Check for mounts right away and abort if we cannot unmount them
-        self.mount_safety_check()
-
         if "clear-autoresume" in self.settings["options"]:
             self.clear_autoresume()
 


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/base/
@ 2020-10-29 16:34 Matt Turner
  0 siblings, 0 replies; 31+ messages in thread
From: Matt Turner @ 2020-10-29 16:34 UTC (permalink / raw
  To: gentoo-commits

commit:     cb06d0bbcf90865896f3129d7767ef0a7abb8331
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 29 14:39:35 2020 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Thu Oct 29 16:34:40 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=cb06d0bb

catalyst: Remove mount_safety_check()

mount_safety_check() exists to prevent bad things from happening if a
previous catalyst invocation left bind mounts active in the chroot.
E.g., a previous catalyst invocation is interrupted without unmounting
the bind mounts. A new catalyst invocation runs and cleans the old
chroot, which inadvertently deletes files outside of the chroot via the
bind mounts.

With all the mounts now inside a namespace, it is no longer possible to
have mounts accessible outside the build sequence. In fact, I think this
code has been unnecessary since commit e5a53e42 ("catalyst: create
namespaces for building").

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 37 -------------------------------------
 1 file changed, 37 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index bd5ba8d0..b9c220d0 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -638,39 +638,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
             assert self.settings[verify] == "blake2"
             self.settings.setdefault("gk_mainargs", []).append("--b2sum")
 
-    def mount_safety_check(self):
-        """
-        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(self.settings["chroot_path"]):
-            return
-
-        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
-
-            if ismount(target):
-                # Something is still mounted
-                try:
-                    log.warning(
-                        '%s is still mounted; performing auto-bind-umount...', target)
-                    # Try to umount stuff ourselves
-                    self.unbind()
-                    if ismount(target):
-                        raise CatalystError("Auto-unbind failed for " + target)
-                    log.notice('Auto-unbind successful...')
-                except CatalystError:
-                    raise CatalystError("Unable to auto-unbind " + target)
-
     def unpack(self):
-
         clst_unpack_hash = self.resume.get("unpack")
 
         # Set up all unpack info settings
@@ -755,8 +723,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
                     % self.settings["source_path"])
 
         if _unpack:
-            self.mount_safety_check()
-
             if invalid_chroot:
                 if "autoresume" in self.settings["options"]:
                     log.notice(
@@ -1363,9 +1329,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
     def run(self):
         self.chroot_lock.write_lock()
 
-        # Check for mounts right away and abort if we cannot unmount them
-        self.mount_safety_check()
-
         if "clear-autoresume" in self.settings["options"]:
             self.clear_autoresume()
 


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/base/
@ 2020-10-29 16:14 Matt Turner
  0 siblings, 0 replies; 31+ messages in thread
From: Matt Turner @ 2020-10-29 16:14 UTC (permalink / raw
  To: gentoo-commits

commit:     a2f06fb8468d28a42b4a68f21be340bb3a862d08
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 29 13:03:33 2020 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Thu Oct 29 16:13:47 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=a2f06fb8

catalyst: Factor out run_sequence()

This is preparation for the next patch, which will run the build
sequence in a separate mount namespace.

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 40 +++++++++++++++++++++++-----------------
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 75c84baa..06ec8727 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -1362,6 +1362,22 @@ class StageBase(TargetBase, ClearBase, GenBase):
 
         log.debug('setup_environment(); env = %r', self.env)
 
+    def run_sequence(self, sequence):
+        for func in sequence:
+            log.notice('--- Running action sequence: %s', func)
+            sys.stdout.flush()
+            try:
+                getattr(self, func)()
+            except LockInUse:
+                log.error('Unable to aquire the lock...')
+                return False
+            except Exception:
+                log.error('Exception running action sequence %s',
+                          func, exc_info=True)
+                return False
+
+        return True
+
     def run(self):
         self.chroot_lock.write_lock()
 
@@ -1386,26 +1402,16 @@ class StageBase(TargetBase, ClearBase, GenBase):
             log.info('StageBase: run() purge')
             self.purge()
 
-        failure = False
-        for x in self.prepare_sequence + self.build_sequence + self.finish_sequence:
-            log.notice('--- Running action sequence: %s', x)
-            sys.stdout.flush()
-            try:
-                getattr(self, x)()
-            except LockInUse:
-                log.error('Unable to aquire the lock...')
-                failure = True
-                break
-            except Exception:
-                log.error('Exception running action sequence %s',
-                          x, exc_info=True)
-                failure = True
-                break
+        if not self.run_sequence(self.prepare_sequence):
+            return False
 
-        if failure:
-            log.notice('Cleaning up... Running unbind()')
+        if not self.run_sequence(self.build_sequence):
             self.unbind()
             return False
+
+        if not self.run_sequence(self.finish_sequence):
+            return False
+
         return True
 
     def unmerge(self):


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/base/
@ 2020-10-29 16:14 Matt Turner
  0 siblings, 0 replies; 31+ messages in thread
From: Matt Turner @ 2020-10-29 16:14 UTC (permalink / raw
  To: gentoo-commits

commit:     c65e1c9ad098e713cd2bab7b9dce96a2e0a927fb
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 29 14:39:35 2020 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Thu Oct 29 16:13:47 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=c65e1c9a

catalyst: Remove mount_safety_check()

mount_safety_check() exists to prevent bad things from happening if a
previous catalyst invocation left bind mounts active in the chroot.
E.g., a previous catalyst invocation is interrupted without unmounting
the bind mounts. A new catalyst invocation runs and cleans the old
chroot, which inadvertently deletes files outside of the chroot via the
bind mounts.

With all the mounts now inside a namespace, it is no longer possible to
have mounts accessible outside the build sequence. In fact, I think this
code has been unnecessary since commit e5a53e42 ("catalyst: create
namespaces for building").

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 37 -------------------------------------
 1 file changed, 37 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 5fc11eae..d5454b77 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -638,39 +638,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
             assert self.settings[verify] == "blake2"
             self.settings.setdefault("gk_mainargs", []).append("--b2sum")
 
-    def mount_safety_check(self):
-        """
-        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(self.settings["chroot_path"]):
-            return
-
-        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
-
-            if ismount(target):
-                # Something is still mounted
-                try:
-                    log.warning(
-                        '%s is still mounted; performing auto-bind-umount...', target)
-                    # Try to umount stuff ourselves
-                    self.unbind()
-                    if ismount(target):
-                        raise CatalystError("Auto-unbind failed for " + target)
-                    log.notice('Auto-unbind successful...')
-                except CatalystError:
-                    raise CatalystError("Unable to auto-unbind " + target)
-
     def unpack(self):
-
         clst_unpack_hash = self.resume.get("unpack")
 
         # Set up all unpack info settings
@@ -755,8 +723,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
                     % self.settings["source_path"])
 
         if _unpack:
-            self.mount_safety_check()
-
             if invalid_chroot:
                 if "autoresume" in self.settings["options"]:
                     log.notice(
@@ -1363,9 +1329,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
     def run(self):
         self.chroot_lock.write_lock()
 
-        # Check for mounts right away and abort if we cannot unmount them
-        self.mount_safety_check()
-
         if "clear-autoresume" in self.settings["options"]:
             self.clear_autoresume()
 


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/base/
@ 2020-10-29 16:14 Matt Turner
  0 siblings, 0 replies; 31+ messages in thread
From: Matt Turner @ 2020-10-29 16:14 UTC (permalink / raw
  To: gentoo-commits

commit:     a8a92a00b53e99b66b5c2bc9f44c2a3ba22ad454
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: Thu Oct 29 16:13:47 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=a8a92a00

catalyst: Use libmount for handling mounts

Handle the mounts/unmounts in all in process rather than shelling out
(pun intended!) to an external program.

While we're here, change some log.notice to log.debug since those cases
are normal and expected.

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 57 ++++++++++++++++++++++++++++------------------
 1 file changed, 35 insertions(+), 22 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index e71ce344..73eacfbe 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -6,6 +6,7 @@ import sys
 
 from pathlib import Path
 
+import libmount
 import toml
 
 from snakeoil import fileutils
@@ -853,7 +854,8 @@ class StageBase(TargetBase, ClearBase, GenBase):
 
             source = str(self.mount[x]['source'])
             target = self.settings['chroot_path'] + str(self.mount[x]['target'])
-            mount = ['mount']
+            fstype = ''
+            options = ''
 
             log.debug('bind %s: "%s" -> "%s"', x, source, target)
 
@@ -861,18 +863,20 @@ 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"]
+                fstype = 'tmpfs'
+                options = f"size={self.settings['var_tmpfs_portage']}G"
             elif source == 'tmpfs':
-                mount += ['-t', 'tmpfs']
+                fstype = 'tmpfs'
             elif source == 'shm':
-                mount += ['-t', 'tmpfs', '-o', 'noexec,nosuid,nodev']
+                fstype = 'tmpfs'
+                options = 'noexec,nosuid,nodev'
             else:
                 source_path = Path(self.mount[x]['source'])
                 if source_path.suffix == '.sqfs':
-                    mount += ['-o', 'ro']
+                    fstype = 'squashfs'
+                    options = 'ro,loop'
                 else:
-                    mount.append('--bind')
+                    options = '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
@@ -881,38 +885,47 @@ 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:
+                cxt = libmount.Context(source=source, target=target,
+                                       fstype=fstype, options=options)
+                cxt.mount()
+            except OSError as e:
+                self.unbind()
+                raise CatalystError(f"Couldn't mount: {source}, {e.strerror}")
 
     def unbind(self):
-        ouch = 0
-        mypath = self.settings["chroot_path"]
+        chroot_path = self.settings["chroot_path"]
+        umount_failed = False
 
         # 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)
+        for target in [Path(chroot_path + self.mount[x]['target'])
+                       for x in reversed(self.mount)
+                       if self.mount[x]['enable']]:
+            if not target.exists():
+                log.debug('%s does not exist. Skipping', target)
                 continue
 
             if not ismount(target):
-                log.notice('%s is not a mount point. Skipping', target)
+                log.debug('%s is not a mount point. Skipping', target)
                 continue
 
             try:
-                cmd(['umount', target], env=self.env)
-            except CatalystError:
+                cxt = libmount.Context(target=str(target))
+                cxt.umount()
+            except OSError:
                 log.warning('First attempt to unmount failed: %s', target)
                 log.warning('Killing any pids still running in the chroot')
 
                 self.kill_chroot_pids()
 
                 try:
-                    cmd(['umount', target], env=self.env)
-                except CatalystError:
-                    ouch = 1
-                    log.warning("Couldn't umount bind mount: %s", target)
+                    cxt.umount()
+                except OSError as e:
+                    umount_failed = True
+                    log.warning("Couldn't umount: %s, %s", target,
+                                e.strerror)
 
-        if ouch:
+        if umount_failed:
             # if any bind mounts really failed, then we need to raise
             # this to potentially prevent an upcoming bash stage cleanup script
             # from wiping our bind mounts.


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/base/
@ 2020-10-29 16:04 Matt Turner
  0 siblings, 0 replies; 31+ messages in thread
From: Matt Turner @ 2020-10-29 16:04 UTC (permalink / raw
  To: gentoo-commits

commit:     6dbe9873976be48b0a226dd14925d5417db89643
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 29 13:03:33 2020 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Thu Oct 29 16:03:41 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=6dbe9873

catalyst: Factor out run_sequence()

This is preparation for the next patch, which will run the build
sequence in a separate mount namespace.

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 40 +++++++++++++++++++++++-----------------
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index e2981d58..c2abf757 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -1362,6 +1362,22 @@ class StageBase(TargetBase, ClearBase, GenBase):
 
         log.debug('setup_environment(); env = %r', self.env)
 
+    def run_sequence(self, sequence):
+        for func in sequence:
+            log.notice('--- Running action sequence: %s', func)
+            sys.stdout.flush()
+            try:
+                getattr(self, func)()
+            except LockInUse:
+                log.error('Unable to aquire the lock...')
+                return False
+            except Exception:
+                log.error('Exception running action sequence %s',
+                          func, exc_info=True)
+                return False
+
+        return True
+
     def run(self):
         self.chroot_lock.write_lock()
 
@@ -1386,26 +1402,16 @@ class StageBase(TargetBase, ClearBase, GenBase):
             log.info('StageBase: run() purge')
             self.purge()
 
-        failure = False
-        for x in self.prepare_sequence + self.build_sequence + self.finish_sequence:
-            log.notice('--- Running action sequence: %s', x)
-            sys.stdout.flush()
-            try:
-                getattr(self, x)()
-            except LockInUse:
-                log.error('Unable to aquire the lock...')
-                failure = True
-                break
-            except Exception:
-                log.error('Exception running action sequence %s',
-                          x, exc_info=True)
-                failure = True
-                break
+        if not self.run_sequence(self.prepare_sequence):
+            return False
 
-        if failure:
-            log.notice('Cleaning up... Running unbind()')
+        if not self.run_sequence(self.build_sequence):
             self.unbind()
             return False
+
+        if not self.run_sequence(self.finish_sequence):
+            return False
+
         return True
 
     def unmerge(self):


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/base/
@ 2020-10-29 16:04 Matt Turner
  0 siblings, 0 replies; 31+ messages in thread
From: Matt Turner @ 2020-10-29 16:04 UTC (permalink / raw
  To: gentoo-commits

commit:     19c3c2302fdf02cbc6bf51076e4be1724ed0ab50
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 29 14:39:35 2020 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Thu Oct 29 16:03:41 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=19c3c230

catalyst: Remove mount_safety_check()

mount_safety_check() exists to prevent bad things from happening if a
previous catalyst invocation left bind mounts active in the chroot.
E.g., a previous catalyst invocation is interrupted without unmounting
the bind mounts. A new catalyst invocation runs and cleans the old
chroot, which inadvertently deletes files outside of the chroot via the
bind mounts.

With all the mounts now inside a namespace, it is no longer possible to
have mounts accessible outside the build sequence. In fact, I think this
code has been unnecessary since commit e5a53e42 ("catalyst: create
namespaces for building").

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 37 -------------------------------------
 1 file changed, 37 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 4e959f3f..1f84965a 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -638,39 +638,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
             assert self.settings[verify] == "blake2"
             self.settings.setdefault("gk_mainargs", []).append("--b2sum")
 
-    def mount_safety_check(self):
-        """
-        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(self.settings["chroot_path"]):
-            return
-
-        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
-
-            if ismount(target):
-                # Something is still mounted
-                try:
-                    log.warning(
-                        '%s is still mounted; performing auto-bind-umount...', target)
-                    # Try to umount stuff ourselves
-                    self.unbind()
-                    if ismount(target):
-                        raise CatalystError("Auto-unbind failed for " + target)
-                    log.notice('Auto-unbind successful...')
-                except CatalystError:
-                    raise CatalystError("Unable to auto-unbind " + target)
-
     def unpack(self):
-
         clst_unpack_hash = self.resume.get("unpack")
 
         # Set up all unpack info settings
@@ -755,8 +723,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
                     % self.settings["source_path"])
 
         if _unpack:
-            self.mount_safety_check()
-
             if invalid_chroot:
                 if "autoresume" in self.settings["options"]:
                     log.notice(
@@ -1363,9 +1329,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
     def run(self):
         self.chroot_lock.write_lock()
 
-        # Check for mounts right away and abort if we cannot unmount them
-        self.mount_safety_check()
-
         if "clear-autoresume" in self.settings["options"]:
             self.clear_autoresume()
 


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/base/
@ 2020-10-29 16:04 Matt Turner
  0 siblings, 0 replies; 31+ messages in thread
From: Matt Turner @ 2020-10-29 16:04 UTC (permalink / raw
  To: gentoo-commits

commit:     14d97555884fe554f334bded9fecdc8ff4493807
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: Thu Oct 29 16:03:34 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=14d97555

catalyst: Use libmount for handling mounts

Handle the mounts/unmounts in all in process rather than shelling out
(pun intended!) to an external program.

While we're here, change some log.notice to log.debug since those cases
are normal and expected.

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 57 ++++++++++++++++++++++++++++------------------
 1 file changed, 35 insertions(+), 22 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index e71ce344..edf950e2 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -6,6 +6,7 @@ import sys
 
 from pathlib import Path
 
+import libmount
 import toml
 
 from snakeoil import fileutils
@@ -853,7 +854,8 @@ class StageBase(TargetBase, ClearBase, GenBase):
 
             source = str(self.mount[x]['source'])
             target = self.settings['chroot_path'] + str(self.mount[x]['target'])
-            mount = ['mount']
+            fstype = ''
+            options = ''
 
             log.debug('bind %s: "%s" -> "%s"', x, source, target)
 
@@ -861,18 +863,20 @@ 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"]
+                fstype = 'tmpfs'
+                options = f"size={self.settings['var_tmpfs_portage']}G"
             elif source == 'tmpfs':
-                mount += ['-t', 'tmpfs']
+                fstype = 'tmpfs'
             elif source == 'shm':
-                mount += ['-t', 'tmpfs', '-o', 'noexec,nosuid,nodev']
+                fstype = 'tmpfs'
+                options = "noexec,nosuid,nodev"
             else:
                 source_path = Path(self.mount[x]['source'])
                 if source_path.suffix == '.sqfs':
-                    mount += ['-o', 'ro']
+                    fstype = "squashfs"
+                    options = "ro,loop"
                 else:
-                    mount.append('--bind')
+                    options = "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
@@ -881,38 +885,47 @@ 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:
+                cxt = libmount.Context(source=source, target=target,
+                                       fstype=fstype, options=options)
+                cxt.mount()
+            except OSError as e:
+                self.unbind()
+                raise CatalystError(f"Couldn't mount: {source}, {e.strerror}")
 
     def unbind(self):
-        ouch = 0
-        mypath = self.settings["chroot_path"]
+        chroot_path = self.settings["chroot_path"]
+        umount_failed = False
 
         # 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)
+        for target in [Path(chroot_path + self.mount[x]['target'])
+                       for x in reversed(self.mount)
+                       if self.mount[x]['enable']]:
+            if not target.exists():
+                log.debug('%s does not exist. Skipping', target)
                 continue
 
             if not ismount(target):
-                log.notice('%s is not a mount point. Skipping', target)
+                log.debug('%s is not a mount point. Skipping', target)
                 continue
 
             try:
-                cmd(['umount', target], env=self.env)
-            except CatalystError:
+                cxt = libmount.Context(target=str(target))
+                cxt.umount()
+            except OSError:
                 log.warning('First attempt to unmount failed: %s', target)
                 log.warning('Killing any pids still running in the chroot')
 
                 self.kill_chroot_pids()
 
                 try:
-                    cmd(['umount', target], env=self.env)
-                except CatalystError:
-                    ouch = 1
-                    log.warning("Couldn't umount bind mount: %s", target)
+                    cxt.umount()
+                except OSError as e:
+                    umount_failed = True
+                    log.warning("Couldn't umount: %s, %s", target,
+                                e.strerror)
 
-        if ouch:
+        if umount_failed:
             # if any bind mounts really failed, then we need to raise
             # this to potentially prevent an upcoming bash stage cleanup script
             # from wiping our bind mounts.


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/base/
@ 2020-10-29 15:47 Matt Turner
  0 siblings, 0 replies; 31+ messages in thread
From: Matt Turner @ 2020-10-29 15:47 UTC (permalink / raw
  To: gentoo-commits

commit:     1d692ee14f3c25eb56a1b35e11f160a1dbb724ac
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 29 14:39:35 2020 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Thu Oct 29 15:46:16 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=1d692ee1

catalyst: Remove mount_safety_check()

mount_safety_check() exists to prevent bad things from happening if a
previous catalyst invocation left bind mounts active in the chroot.
E.g., a previous catalyst invocation is interrupted without unmounting
the bind mounts. A new catalyst invocation runs and cleans the old
chroot, which inadvertently deletes files outside of the chroot via the
bind mounts.

With all the mounts now inside a namespace, it is no longer possible to
have mounts accessible outside the build sequence.

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 37 -------------------------------------
 1 file changed, 37 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 605a9495..e9cf04c6 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -638,39 +638,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
             assert self.settings[verify] == "blake2"
             self.settings.setdefault("gk_mainargs", []).append("--b2sum")
 
-    def mount_safety_check(self):
-        """
-        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(self.settings["chroot_path"]):
-            return
-
-        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
-
-            if ismount(target):
-                # Something is still mounted
-                try:
-                    log.warning(
-                        '%s is still mounted; performing auto-bind-umount...', target)
-                    # Try to umount stuff ourselves
-                    self.unbind()
-                    if ismount(target):
-                        raise CatalystError("Auto-unbind failed for " + target)
-                    log.notice('Auto-unbind successful...')
-                except CatalystError:
-                    raise CatalystError("Unable to auto-unbind " + target)
-
     def unpack(self):
-
         clst_unpack_hash = self.resume.get("unpack")
 
         # Set up all unpack info settings
@@ -755,8 +723,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
                     % self.settings["source_path"])
 
         if _unpack:
-            self.mount_safety_check()
-
             if invalid_chroot:
                 if "autoresume" in self.settings["options"]:
                     log.notice(
@@ -1363,9 +1329,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
     def run(self):
         self.chroot_lock.write_lock()
 
-        # Check for mounts right away and abort if we cannot unmount them
-        self.mount_safety_check()
-
         if "clear-autoresume" in self.settings["options"]:
             self.clear_autoresume()
 


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/base/
@ 2020-10-29 15:47 Matt Turner
  0 siblings, 0 replies; 31+ messages in thread
From: Matt Turner @ 2020-10-29 15:47 UTC (permalink / raw
  To: gentoo-commits

commit:     dfea0c040f43fba778ff1ef9747be5da50090333
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 29 13:03:33 2020 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Thu Oct 29 15:24:52 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=dfea0c04

catalyst: Factor out run_sequence()

This is preparation for the next patch, which will run the build
sequence in a separate mount namespace.

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 40 +++++++++++++++++++++++-----------------
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index fd723e48..829bcc93 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -1362,6 +1362,22 @@ class StageBase(TargetBase, ClearBase, GenBase):
 
         log.debug('setup_environment(); env = %r', self.env)
 
+    def run_sequence(self, sequence):
+        for func in sequence:
+            log.notice('--- Running action sequence: %s', func)
+            sys.stdout.flush()
+            try:
+                getattr(self, func)()
+            except LockInUse:
+                log.error('Unable to aquire the lock...')
+                return False
+            except Exception:
+                log.error('Exception running action sequence %s',
+                          func, exc_info=True)
+                return False
+
+        return True
+
     def run(self):
         self.chroot_lock.write_lock()
 
@@ -1386,26 +1402,16 @@ class StageBase(TargetBase, ClearBase, GenBase):
             log.info('StageBase: run() purge')
             self.purge()
 
-        failure = False
-        for x in self.prepare_sequence + self.build_sequence + self.finish_sequence:
-            log.notice('--- Running action sequence: %s', x)
-            sys.stdout.flush()
-            try:
-                getattr(self, x)()
-            except LockInUse:
-                log.error('Unable to aquire the lock...')
-                failure = True
-                break
-            except Exception:
-                log.error('Exception running action sequence %s',
-                          x, exc_info=True)
-                failure = True
-                break
+        if not self.run_sequence(self.prepare_sequence):
+            return False
 
-        if failure:
-            log.notice('Cleaning up... Running unbind()')
+        if not self.run_sequence(self.build_sequence):
             self.unbind()
             return False
+
+        if not self.run_sequence(self.finish_sequence):
+            return False
+
         return True
 
     def unmerge(self):


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/base/
@ 2020-10-29 15:47 Matt Turner
  0 siblings, 0 replies; 31+ messages in thread
From: Matt Turner @ 2020-10-29 15:47 UTC (permalink / raw
  To: gentoo-commits

commit:     40696b7445cd4353fa542ad3dc84e120bbfa9612
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: Thu Oct 29 15:24:45 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=40696b74

catalyst: Use libmount for handling mounts

Handle the mounts/unmounts in all in process rather than shelling out
(pun intended!) to an external program.

While we're here, change some log.notice to log.debug since those cases
are normal and expected.

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 57 ++++++++++++++++++++++++++++------------------
 1 file changed, 35 insertions(+), 22 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index cdc5a8a9..fd723e48 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -6,6 +6,7 @@ import sys
 
 from pathlib import Path
 
+import libmount
 import toml
 
 from snakeoil import fileutils
@@ -860,7 +861,8 @@ class StageBase(TargetBase, ClearBase, GenBase):
 
             source = str(self.mount[x]['source'])
             target = self.settings['chroot_path'] + str(self.mount[x]['target'])
-            mount = ['mount']
+            fstype = ''
+            options = ''
 
             log.debug('bind %s: "%s" -> "%s"', x, source, target)
 
@@ -868,18 +870,20 @@ 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"]
+                fstype = 'tmpfs'
+                options = f"size={self.settings['var_tmpfs_portage']}G"
             elif source == 'tmpfs':
-                mount += ['-t', 'tmpfs']
+                fstype = 'tmpfs'
             elif source == 'shm':
-                mount += ['-t', 'tmpfs', '-o', 'noexec,nosuid,nodev']
+                fstype = 'tmpfs'
+                options = "noexec,nosuid,nodev"
             else:
                 source_path = Path(self.mount[x]['source'])
                 if source_path.suffix == '.sqfs':
-                    mount += ['-o', 'ro']
+                    fstype = "squashfs"
+                    options = "ro,loop"
                 else:
-                    mount.append('--bind')
+                    options = "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
@@ -888,38 +892,47 @@ 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:
+                cxt = libmount.Context(source=source, target=target,
+                                       fstype=fstype, options=options)
+                cxt.mount()
+            except OSError as e:
+                self.unbind()
+                raise CatalystError(f"Counldn't mount: {source}, {e.strerror}")
 
     def unbind(self):
-        ouch = 0
-        mypath = self.settings["chroot_path"]
+        chroot_path = self.settings["chroot_path"]
+        umount_failed = False
 
         # 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)
+        for target in [Path(chroot_path + self.mount[x]['target'])
+                       for x in reversed(self.mount)
+                       if self.mount[x]['enable']]:
+            if not target.exists():
+                log.debug('%s does not exist. Skipping', target)
                 continue
 
             if not ismount(target):
-                log.notice('%s is not a mount point. Skipping', target)
+                log.debug('%s is not a mount point. Skipping', target)
                 continue
 
             try:
-                cmd(['umount', target], env=self.env)
-            except CatalystError:
+                cxt = libmount.Context(target=str(target))
+                cxt.umount()
+            except OSError:
                 log.warning('First attempt to unmount failed: %s', target)
                 log.warning('Killing any pids still running in the chroot')
 
                 self.kill_chroot_pids()
 
                 try:
-                    cmd(['umount', target], env=self.env)
-                except CatalystError:
-                    ouch = 1
-                    log.warning("Couldn't umount bind mount: %s", target)
+                    cxt.umount()
+                except OSError as e:
+                    umount_failed = True
+                    log.warning("Couldn't umount: %s, %s", target,
+                                e.strerror)
 
-        if ouch:
+        if umount_failed:
             # if any bind mounts really failed, then we need to raise
             # this to potentially prevent an upcoming bash stage cleanup script
             # from wiping our bind mounts.


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/base/
@ 2020-10-29 13:08 Matt Turner
  0 siblings, 0 replies; 31+ messages in thread
From: Matt Turner @ 2020-10-29 13:08 UTC (permalink / raw
  To: gentoo-commits

commit:     2437a115e29f4b92ed90354d518ea17e1bc378ac
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 29 13:03:33 2020 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Thu Oct 29 13:08:32 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=2437a115

catalyst: Factor out run_sequence()

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 41 +++++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 18 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index cdc5a8a9..da133bf2 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -1349,6 +1349,22 @@ class StageBase(TargetBase, ClearBase, GenBase):
 
         log.debug('setup_environment(); env = %r', self.env)
 
+    def run_sequence(self, sequence):
+        for func in sequence:
+            log.notice('--- Running action sequence: %s', func)
+            sys.stdout.flush()
+            try:
+                getattr(self, func)()
+            except LockInUse:
+                log.error('Unable to aquire the lock...')
+                return False
+            except Exception:
+                log.error('Exception running action sequence %s',
+                          func, exc_info=True)
+                return False
+
+        return True
+
     def run(self):
         self.chroot_lock.write_lock()
 
@@ -1373,26 +1389,15 @@ class StageBase(TargetBase, ClearBase, GenBase):
             log.info('StageBase: run() purge')
             self.purge()
 
-        failure = False
-        for x in self.prepare_sequence + self.build_sequence + self.finish_sequence:
-            log.notice('--- Running action sequence: %s', x)
-            sys.stdout.flush()
-            try:
-                getattr(self, x)()
-            except LockInUse:
-                log.error('Unable to aquire the lock...')
-                failure = True
-                break
-            except Exception:
-                log.error('Exception running action sequence %s',
-                          x, exc_info=True)
-                failure = True
-                break
+        if not self.run_sequence(self.prepare_sequence):
+            return False
 
-        if failure:
-            log.notice('Cleaning up... Running unbind()')
-            self.unbind()
+        if not self.run_sequence(self.build_sequence):
             return False
+
+        if not self.run_sequence(self.finish_sequence):
+            return False
+
         return True
 
     def unmerge(self):


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:master commit in: catalyst/base/
@ 2020-10-24 22:07 Matt Turner
  2020-10-23  4:36 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
  0 siblings, 1 reply; 31+ messages in thread
From: Matt Turner @ 2020-10-24 22:07 UTC (permalink / raw
  To: gentoo-commits

commit:     da56b3e0b3080dd592874e7076c69809b2657cfb
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Fri Oct 23 04:09:18 2020 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Fri Oct 23 04:09:18 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=da56b3e0

catalyst: Fix indentation

This code was initially committed with tabs and didn't work. I ran
autopep8 on it but did not realize that the indentation was still
incorrect.

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index be7b96c8..603e49d9 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -1132,16 +1132,16 @@ class StageBase(TargetBase, ClearBase, GenBase):
         if os.path.exists(hosts_file + '.catalyst'):
             os.rename(hosts_file + '.catalyst', hosts_file)
 
-            # optionally clean up binary interpreter
-            if "interpreter" in self.settings:
-                    if os.path.exists(self.settings['chroot_path'] + '/' + self.settings['interpreter'] + '.catalyst'):
-                        os.rename(
-                            self.settings['chroot_path'] + '/' +
-                            self.settings['interpreter'] + '.catalyst',
-                            self.settings['chroot_path'] + '/' + self.settings['interpreter'])
-                    else:
-                        os.remove(
-                            self.settings['chroot_path'] + '/' + self.settings['interpreter'])
+        # optionally clean up binary interpreter
+        if "interpreter" in self.settings:
+            if os.path.exists(self.settings['chroot_path'] + '/' + self.settings['interpreter'] + '.catalyst'):
+                os.rename(
+                    self.settings['chroot_path'] + '/' +
+                    self.settings['interpreter'] + '.catalyst',
+                    self.settings['chroot_path'] + '/' + self.settings['interpreter'])
+            else:
+                os.remove(
+                    self.settings['chroot_path'] + '/' + self.settings['interpreter'])
 
         # optionally clean up portage configs
         if ("portage_prefix" in self.settings and


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/base/
@ 2020-10-22 18:59 Matt Turner
  0 siblings, 0 replies; 31+ messages in thread
From: Matt Turner @ 2020-10-22 18:59 UTC (permalink / raw
  To: gentoo-commits

commit:     45a0e0b08affca6615ed16de29bf9a8454be414f
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: Thu Oct 22 18:57:43 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=45a0e0b0

catalyst: Use libmount for handling mounts

Handle the mounts/unmounts in all in process rather than shelling out
(pun intended!) to an external program.

While we're here, change some log.notice to log.debug since those cases
are normal and expected.

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 42 +++++++++++++++++++++++++++---------------
 1 file changed, 27 insertions(+), 15 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 06919fb5..95cb2912 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -6,6 +6,7 @@ import sys
 
 from pathlib import Path
 
+import libmount
 import toml
 
 from snakeoil import fileutils
@@ -842,7 +843,8 @@ class StageBase(TargetBase, ClearBase, GenBase):
 
             source = str(self.mount[x]['source'])
             target = self.settings['chroot_path'] + str(self.mount[x]['target'])
-            mount = ['mount']
+            fstype = ''
+            options = ''
 
             log.debug('bind %s: "%s" -> "%s"', x, source, target)
 
@@ -850,18 +852,20 @@ 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"]
+                fstype = 'tmpfs'
+                options = f"size={self.settings['var_tmpfs_portage']}G"
             elif source == 'tmpfs':
-                mount += ['-t', 'tmpfs']
+                fstype = 'tmpfs'
             elif source == 'shm':
-                mount += ['-t', 'tmpfs', '-o', 'noexec,nosuid,nodev']
+                fstype = 'tmpfs'
+                options = "noexec,nosuid,nodev"
             else:
                 source_path = Path(self.mount[x]['source'])
                 if source_path.suffix == '.sqfs':
-                    mount += ['-o', 'ro']
+                    fstype = "squashfs"
+                    options = "ro,loop"
                 else:
-                    mount.append('--bind')
+                    options = "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
@@ -870,25 +874,33 @@ 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:
+                cxt = libmount.Context(source=source, target=target,
+                                       fstype=fstype, options=options)
+                cxt.mount()
+            except OSError as e:
+                self.unbind()
+                raise CatalystError(f"Counldn't mount: {source}, {e.strerror}")
 
     def unbind(self):
-        mypath = self.settings["chroot_path"]
+        chroot_path = self.settings["chroot_path"]
         umount_failed = False
 
         # 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)
+        for target in [Path(chroot_path + self.mount[x]['target'])
+                       for x in reversed(self.mount)
+                       if self.mount[x]['enable']]:
+            if not target.exists():
+                log.debug('%s does not exist. Skipping', target)
                 continue
 
             if not ismount(target):
-                log.notice('%s is not a mount point. Skipping', target)
+                log.debug('%s is not a mount point. Skipping', target)
                 continue
 
             try:
-                cmd(['umount', target], env=self.env)
+                cxt = libmount.Context(target=str(target))
+                cxt.umount()
             except OSError as e:
                 log.warning("Couldn't umount: %s, %s", target,
                             e.strerror)


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:master commit in: catalyst/base/
@ 2020-05-21 20:25 Matt Turner
  2020-05-20  3:39 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
  0 siblings, 1 reply; 31+ messages in thread
From: Matt Turner @ 2020-05-21 20:25 UTC (permalink / raw
  To: gentoo-commits

commit:     d97ef9d0879cc935258f5d30b84dd31d464abc9f
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Wed May 20 02:55:15 2020 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Wed May 20 02:58:07 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=d97ef9d0

catalyst: Don't even try to make envars from dicts

With the removal of the arch modules (presumably), the two exceptions
(compress_definitions and decompress_definitions) are the only dicts in
self.settings.

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 22 ++--------------------
 1 file changed, 2 insertions(+), 20 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 9410f151..8e2b08da 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -1285,28 +1285,10 @@ class StageBase(TargetBase, ClearBase, GenBase):
                     self.env[varname] = "true"
                 else:
                     self.env[varname] = "false"
-            # This handles a dictionary of objects just one level deep and no deeper!
-            # Its currently used only for USE_EXPAND flags which are dictionaries of
-            # lists in arch/amd64.py and friends.  If we wanted self.settigs[var]
-            # of any depth, we should make this function recursive.
             elif isinstance(self.settings[x], dict):
-                if x in ["compress_definitions",
-                         "decompress_definitions"]:
+                if x in ['compress_definitions', 'decompress_definitions']:
                     continue
-                self.env[varname] = ' '.join(self.settings[x].keys())
-                for y in self.settings[x].keys():
-                    varname2 = "clst_" + y.replace("/", "_")
-                    varname2 = varname2.replace("-", "_")
-                    varname2 = varname2.replace(".", "_")
-                    if isinstance(self.settings[x][y], str):
-                        self.env[varname2] = self.settings[x][y]
-                    elif isinstance(self.settings[x][y], list):
-                        self.env[varname2] = ' '.join(self.settings[x][y])
-                    elif isinstance(self.settings[x][y], bool):
-                        if self.settings[x][y]:
-                            self.env[varname] = "true"
-                        else:
-                            self.env[varname] = "false"
+                log.warning("Not making envar for '%s', is a dict", x)
 
         if "makeopts" in self.settings:
             if isinstance(self.settings["makeopts"], str):


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:master commit in: catalyst/base/
@ 2020-05-21 20:25 Matt Turner
  2020-05-20  3:39 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
  0 siblings, 1 reply; 31+ messages in thread
From: Matt Turner @ 2020-05-21 20:25 UTC (permalink / raw
  To: gentoo-commits

commit:     6bacd678bab3be95318fe4dcd432ad627a3f2b3e
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Wed May 20 00:23:42 2020 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Wed May 20 01:49:37 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=6bacd678

catalyst: Add decompressor_search_order as valid spec option

The next commit is going to remove this from the list of valid config
file options, where it should not be, and that list currently is used to
populate the list of valid spec options.

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 0c311515..f39895fe 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -49,6 +49,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
             "common_flags",
             "compression_mode",
             "cxxflags",
+            "decompressor_search_order",
             "distcc_hosts",
             "fcflags",
             "fflags",


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:master commit in: catalyst/base/
@ 2020-05-21 20:25 Matt Turner
  2020-05-20  3:39 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
  0 siblings, 1 reply; 31+ messages in thread
From: Matt Turner @ 2020-05-21 20:25 UTC (permalink / raw
  To: gentoo-commits

commit:     3e1784975ab40fda968fe4f36a57e2cfb8edd695
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Wed May 20 00:11:36 2020 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Wed May 20 01:49:37 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=3e178497

catalyst: Remove unused decompression_mode spec option

Never used.

Fixes: 99e9ceabe053 (DeComp bug fixes)
Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 1 -
 1 file changed, 1 deletion(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 651bf4e4..0c311515 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -49,7 +49,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
             "common_flags",
             "compression_mode",
             "cxxflags",
-            "decompression_mode",
             "distcc_hosts",
             "fcflags",
             "fflags",


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:wip/mattst88 commit in: catalyst/base/
@ 2020-05-20  3:39 Matt Turner
  2020-05-20  3:39 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
  0 siblings, 1 reply; 31+ messages in thread
From: Matt Turner @ 2020-05-20  3:39 UTC (permalink / raw
  To: gentoo-commits

commit:     ff0b574a509e9b2796d25dabdcfb473ffa673fd1
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Wed May 20 02:26:52 2020 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Wed May 20 03:15:02 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=ff0b574a

catalyst: Support emitting int/float envars

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 645a9f61..5a8cd1df 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -1283,6 +1283,8 @@ class StageBase(TargetBase, ClearBase, GenBase):
             elif isinstance(self.settings[x], bool):
                 if self.settings[x]:
                     self.env[varname] = "true"
+            elif isinstance(self.settings[x], (int, float)):
+                self.env[varname] = str(self.settings[x])
             elif isinstance(self.settings[x], dict):
                 if x in ['compress_definitions', 'decompress_definitions']:
                     continue


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/base/
@ 2020-05-15  6:32 Matt Turner
  0 siblings, 0 replies; 31+ messages in thread
From: Matt Turner @ 2020-05-15  6:32 UTC (permalink / raw
  To: gentoo-commits

commit:     dc0abc9160b4f85659a1d5db39201febb184e8df
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Fri May 15 06:24:52 2020 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Fri May 15 06:31:34 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=dc0abc91

catalyst: Factor out mount/source/target in bind()

This simplifies things, and lets us only append to the end of the list.
It also enables us to simply add multiple args (in the next commit).

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 52f9cd5b..55d1032d 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -852,6 +852,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
 
             source = str(self.mount[x]['source'])
             target = self.settings['chroot_path'] + str(self.mount[x]['target'])
+            mount = ['mount']
 
             log.debug('bind %s: "%s" -> "%s"', x, source, target)
 
@@ -859,29 +860,25 @@ class StageBase(TargetBase, ClearBase, GenBase):
                 if 'var_tmpfs_portage' not in self.settings:
                     continue
 
-                _cmd = ['mount', '-t', 'tmpfs', '-o', 'size=' +
-                        self.settings['var_tmpfs_portage'] + 'G', source,
-                        target]
+                mount += ['-t', 'tmpfs', '-o', 'size=' +
+                          self.settings['var_tmpfs_portage'] + 'G']
             elif source == 'tmpfs':
-                _cmd = ['mount', '-t', 'tmpfs', source, target]
+                mount += ['-t', 'tmpfs']
             elif source == 'shm':
-                _cmd = ['mount', '-t', 'tmpfs', '-o', 'noexec,nosuid,nodev',
-                        source, target]
+                mount += ['-t', 'tmpfs', '-o', 'noexec,nosuid,nodev']
             else:
-                _cmd = ['mount', source, target]
-
-                source = Path(self.mount[x]['source'])
-                if source.suffix != '.sqfs':
-                    _cmd.insert(1, '--bind')
+                source_path = Path(self.mount[x]['source'])
+                if source_path.suffix != '.sqfs':
+                    mount.append('--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
                     # the binary packages will be stored into.
-                    source.mkdir(mode=0o755, exist_ok=True)
+                    source_path.mkdir(mode=0o755, exist_ok=True)
 
             Path(target).mkdir(mode=0o755, parents=True, exist_ok=True)
 
-            cmd(_cmd, env=self.env, fail_func=self.unbind)
+            cmd(mount + [source, target], env=self.env, fail_func=self.unbind)
 
     def unbind(self):
         ouch = 0


^ permalink raw reply related	[flat|nested] 31+ messages in thread
* [gentoo-commits] proj/catalyst:pending/mattst88 commit in: catalyst/base/
@ 2020-05-15  6:32 Matt Turner
  0 siblings, 0 replies; 31+ messages in thread
From: Matt Turner @ 2020-05-15  6:32 UTC (permalink / raw
  To: gentoo-commits

commit:     f7b7b9f3e0df2c62e4724a7f44ce8ddd9c3e1084
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Fri May 15 06:30:09 2020 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Fri May 15 06:31:34 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=f7b7b9f3

catalyst: Mount squashfs with -o ro

Even though squashfs is not writeable, it must be mounted with -o ro in
order to be mounted multiple times. This allows, for example, the same
snapshot to be mounted simultaneously in multiple catalyst chroots.

Signed-off-by: Matt Turner <mattst88 <AT> gentoo.org>

 catalyst/base/stagebase.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 55d1032d..651bf4e4 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -868,7 +868,9 @@ class StageBase(TargetBase, ClearBase, GenBase):
                 mount += ['-t', 'tmpfs', '-o', 'noexec,nosuid,nodev']
             else:
                 source_path = Path(self.mount[x]['source'])
-                if source_path.suffix != '.sqfs':
+                if source_path.suffix == '.sqfs':
+                    mount += ['-o', 'ro']
+                else:
                     mount.append('--bind')
 
                     # We may need to create the source of the bind mount. E.g., in the


^ permalink raw reply related	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2021-01-28  2:09 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-24 22:07 [gentoo-commits] proj/catalyst:master commit in: catalyst/base/ Matt Turner
2020-10-23  4:36 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
2020-10-29 21:00 ` [gentoo-commits] proj/catalyst:wip/mattst88 " Matt Turner
  -- strict thread matches above, loose matches on Subject: below --
2021-01-28  2:41 [gentoo-commits] proj/catalyst:master " Matt Turner
2021-01-28  2:09 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
2021-01-28  2:41 [gentoo-commits] proj/catalyst:master " Matt Turner
2021-01-28  2:09 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
2021-01-28  2:09 Matt Turner
2021-01-28  1:54 Matt Turner
2021-01-28  1:54 Matt Turner
2021-01-18 19:53 Matt Turner
2020-10-29 19:05 Matt Turner
2020-10-29 19:05 Matt Turner
2020-10-29 19:05 Matt Turner
2020-10-29 16:34 Matt Turner
2020-10-29 16:14 Matt Turner
2020-10-29 16:14 Matt Turner
2020-10-29 16:14 Matt Turner
2020-10-29 16:04 Matt Turner
2020-10-29 16:04 Matt Turner
2020-10-29 16:04 Matt Turner
2020-10-29 15:47 Matt Turner
2020-10-29 15:47 Matt Turner
2020-10-29 15:47 Matt Turner
2020-10-29 13:08 Matt Turner
2020-10-24 22:07 [gentoo-commits] proj/catalyst:master " Matt Turner
2020-10-23  4:36 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
2020-10-22 18:59 Matt Turner
2020-05-21 20:25 [gentoo-commits] proj/catalyst:master " Matt Turner
2020-05-20  3:39 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
2020-05-21 20:25 [gentoo-commits] proj/catalyst:master " Matt Turner
2020-05-20  3:39 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
2020-05-21 20:25 [gentoo-commits] proj/catalyst:master " Matt Turner
2020-05-20  3:39 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
2020-05-20  3:39 [gentoo-commits] proj/catalyst:wip/mattst88 " Matt Turner
2020-05-20  3:39 ` [gentoo-commits] proj/catalyst:pending/mattst88 " Matt Turner
2020-05-15  6:32 Matt Turner
2020-05-15  6:32 Matt Turner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox