Gentoo Archives: gentoo-catalyst

From: Matt Turner <mattst88@g.o>
To: gentoo-catalyst@l.g.o
Cc: Matt Turner <mattst88@g.o>
Subject: [gentoo-catalyst] [PATCH 11/12] catalyst: Remove mount_safety_check()
Date: Thu, 29 Oct 2020 16:16:56
Message-Id: 20201029161632.146732-11-mattst88@gentoo.org
In Reply to: [gentoo-catalyst] [PATCH 01/12] catalyst: Replace pathcompare() by Matt Turner
1 mount_safety_check() exists to prevent bad things from happening if a
2 previous catalyst invocation left bind mounts active in the chroot.
3 E.g., a previous catalyst invocation is interrupted without unmounting
4 the bind mounts. A new catalyst invocation runs and cleans the old
5 chroot, which inadvertently deletes files outside of the chroot via the
6 bind mounts.
7
8 With all the mounts now inside a namespace, it is no longer possible to
9 have mounts accessible outside the build sequence. In fact, I think this
10 code has been unnecessary since commit e5a53e42 ("catalyst: create
11 namespaces for building").
12
13 Signed-off-by: Matt Turner <mattst88@g.o>
14 ---
15 catalyst/base/stagebase.py | 37 -------------------------------------
16 1 file changed, 37 deletions(-)
17
18 diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
19 index 5fc11eae..d5454b77 100644
20 --- a/catalyst/base/stagebase.py
21 +++ b/catalyst/base/stagebase.py
22 @@ -638,39 +638,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
23 assert self.settings[verify] == "blake2"
24 self.settings.setdefault("gk_mainargs", []).append("--b2sum")
25
26 - def mount_safety_check(self):
27 - """
28 - Check and verify that none of our paths in mypath are mounted. We don't
29 - want to clean up with things still mounted, and this allows us to check.
30 - Returns 1 on ok, 0 on "something is still mounted" case.
31 - """
32 -
33 - if not os.path.exists(self.settings["chroot_path"]):
34 - return
35 -
36 - log.debug('self.mount = %s', self.mount)
37 - for x in [x for x in self.mount if self.mount[x]['enable']]:
38 - target = normpath(self.settings['chroot_path'] +
39 - self.mount[x]['target'])
40 - log.debug('mount_safety_check() x = %s %s', x, target)
41 - if not os.path.exists(target):
42 - continue
43 -
44 - if ismount(target):
45 - # Something is still mounted
46 - try:
47 - log.warning(
48 - '%s is still mounted; performing auto-bind-umount...', target)
49 - # Try to umount stuff ourselves
50 - self.unbind()
51 - if ismount(target):
52 - raise CatalystError("Auto-unbind failed for " + target)
53 - log.notice('Auto-unbind successful...')
54 - except CatalystError:
55 - raise CatalystError("Unable to auto-unbind " + target)
56 -
57 def unpack(self):
58 -
59 clst_unpack_hash = self.resume.get("unpack")
60
61 # Set up all unpack info settings
62 @@ -755,8 +723,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
63 % self.settings["source_path"])
64
65 if _unpack:
66 - self.mount_safety_check()
67 -
68 if invalid_chroot:
69 if "autoresume" in self.settings["options"]:
70 log.notice(
71 @@ -1363,9 +1329,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
72 def run(self):
73 self.chroot_lock.write_lock()
74
75 - # Check for mounts right away and abort if we cannot unmount them
76 - self.mount_safety_check()
77 -
78 if "clear-autoresume" in self.settings["options"]:
79 self.clear_autoresume()
80
81 --
82 2.26.2