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 12/12] catalyst: Drop unbind()
Date: Thu, 29 Oct 2020 16:16:58
Message-Id: 20201029161632.146732-12-mattst88@gentoo.org
In Reply to: [gentoo-catalyst] [PATCH 01/12] catalyst: Replace pathcompare() by Matt Turner
1 mount_namespaces(7) says
2
3 A mount ceases to be a member of a peer group when either the
4 mount is explicitly unmounted, or when the mount is implicitly
5 unmounted because a mount namespace is removed (because it has
6 no more member processes).
7
8 As a result, we can rely on exiting the mount namespace to unmount the
9 bind mounts.
10
11 Signed-off-by: Matt Turner <mattst88@g.o>
12 ---
13 catalyst/base/stagebase.py | 45 +------------------------------
14 catalyst/targets/embedded.py | 1 -
15 catalyst/targets/livecd_stage1.py | 1 -
16 catalyst/targets/livecd_stage2.py | 2 --
17 catalyst/targets/netboot.py | 3 ---
18 catalyst/targets/stage4.py | 1 -
19 6 files changed, 1 insertion(+), 52 deletions(-)
20
21 diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
22 index d5454b77..a75dbdf9 100644
23 --- a/catalyst/base/stagebase.py
24 +++ b/catalyst/base/stagebase.py
25 @@ -498,7 +498,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
26 "setup_environment",
27 "run_local",
28 "preclean",
29 - "unbind",
30 ])
31 self.finish_sequence.extend([
32 "clean",
33 @@ -853,40 +852,8 @@ class StageBase(TargetBase, ClearBase, GenBase):
34 fstype=fstype, options=options)
35 cxt.mount()
36 except OSError as e:
37 - self.unbind()
38 raise CatalystError(f"Couldn't mount: {source}, {e.strerror}")
39
40 - def unbind(self):
41 - chroot_path = self.settings["chroot_path"]
42 - umount_failed = False
43 -
44 - # Unmount in reverse order
45 - for target in [Path(chroot_path + self.mount[x]['target'])
46 - for x in reversed(self.mount)
47 - if self.mount[x]['enable']]:
48 - if not target.exists():
49 - log.debug('%s does not exist. Skipping', target)
50 - continue
51 -
52 - if not ismount(target):
53 - log.debug('%s is not a mount point. Skipping', target)
54 - continue
55 -
56 - try:
57 - cxt = libmount.Context(target=str(target))
58 - cxt.umount()
59 - except OSError as e:
60 - log.warning("Couldn't umount: %s, %s", target,
61 - e.strerror)
62 - umount_failed = True
63 -
64 - if umount_failed:
65 - # if any bind mounts really failed, then we need to raise
66 - # this to potentially prevent an upcoming bash stage cleanup script
67 - # from wiping our bind mounts.
68 - raise CatalystError(
69 - "Couldn't umount one or more bind-mounts; aborting for safety.")
70 -
71 def chroot_setup(self):
72 self.makeconf = read_makeconf(normpath(self.settings["chroot_path"] +
73 self.settings["make_conf"]))
74 @@ -1190,7 +1157,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
75 env=self.env)
76 self.resume.enable("remove")
77 except:
78 - self.unbind()
79 raise
80
81 def preclean(self):
82 @@ -1206,7 +1172,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
83 self.resume.enable("preclean")
84
85 except:
86 - self.unbind()
87 raise CatalystError("Build failed, could not execute preclean")
88
89 def capture(self):
90 @@ -1269,7 +1234,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
91 self.settings['controller_file'])
92
93 except CatalystError:
94 - self.unbind()
95 raise CatalystError("Stage build aborting due to error.",
96 print_traceback=False)
97
98 @@ -1349,7 +1313,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
99
100 with namespace(mount=True):
101 if not self.run_sequence(self.build_sequence):
102 - self.unbind()
103 return False
104
105 if not self.run_sequence(self.finish_sequence):
106 @@ -1375,7 +1338,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
107 env=self.env)
108 log.info('unmerge shell script')
109 except CatalystError:
110 - self.unbind()
111 raise
112 self.resume.enable("unmerge")
113
114 @@ -1450,7 +1412,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
115 fileutils.touch(build_packages_resume)
116 self.resume.enable("build_packages")
117 except CatalystError:
118 - self.unbind()
119 raise CatalystError(
120 self.settings["spec_prefix"] +
121 "build aborting due to error.")
122 @@ -1474,7 +1435,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
123 self._build_kernel(kname=kname)
124 self.resume.enable("build_kernel")
125 except CatalystError:
126 - self.unbind()
127 raise CatalystError(
128 "build aborting due to kernel build error.",
129 print_traceback=True)
130 @@ -1518,7 +1478,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
131 key = 'boot/kernel/' + kname + '/config'
132 if key in self.settings:
133 if not os.path.exists(self.settings[key]):
134 - self.unbind()
135 raise CatalystError("Can't find kernel config: %s" %
136 self.settings[key])
137
138 @@ -1527,7 +1486,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
139 self.settings['chroot_path'] + '/var/tmp/' + kname + '.config')
140
141 except IOError:
142 - self.unbind()
143 + raise
144
145 def _copy_initramfs_overlay(self, kname):
146 key = 'boot/kernel/' + kname + '/initramfs_overlay'
147 @@ -1557,7 +1516,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
148 env=self.env)
149 self.resume.enable("bootloader")
150 except CatalystError:
151 - self.unbind()
152 raise CatalystError("Script aborting due to error.")
153
154 def livecd_update(self):
155 @@ -1573,7 +1531,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
156 self.resume.enable("livecd_update")
157
158 except CatalystError:
159 - self.unbind()
160 raise CatalystError(
161 "build aborting due to livecd_update error.")
162
163 diff --git a/catalyst/targets/embedded.py b/catalyst/targets/embedded.py
164 index 1314ce7c..e9138437 100644
165 --- a/catalyst/targets/embedded.py
166 +++ b/catalyst/targets/embedded.py
167 @@ -56,7 +56,6 @@ class embedded(StageBase):
168 "root_overlay",
169 "fsscript",
170 "unmerge",
171 - "unbind",
172 ])
173 self.finish_sequence.extend([
174 "remove",
175 diff --git a/catalyst/targets/livecd_stage1.py b/catalyst/targets/livecd_stage1.py
176 index 81367053..5c5e9f58 100644
177 --- a/catalyst/targets/livecd_stage1.py
178 +++ b/catalyst/targets/livecd_stage1.py
179 @@ -34,7 +34,6 @@ class livecd_stage1(StageBase):
180 "chroot_setup",
181 "setup_environment",
182 "build_packages",
183 - "unbind",
184 ])
185 self.finish_sequence.extend([
186 "clean",
187 diff --git a/catalyst/targets/livecd_stage2.py b/catalyst/targets/livecd_stage2.py
188 index f6c14919..3606047f 100644
189 --- a/catalyst/targets/livecd_stage2.py
190 +++ b/catalyst/targets/livecd_stage2.py
191 @@ -80,7 +80,6 @@ class livecd_stage2(StageBase):
192 for x in self.settings["livecd/modblacklist"]:
193 myf.write("\nblacklist "+x)
194 except:
195 - self.unbind()
196 raise CatalystError("Couldn't open " +
197 self.settings["chroot_path"] +
198 "/etc/modprobe.d/blacklist.conf.",
199 @@ -109,7 +108,6 @@ class livecd_stage2(StageBase):
200 "fsscript",
201 "rcupdate",
202 "unmerge",
203 - "unbind",
204 ])
205 self.finish_sequence.extend([
206 "remove",
207 diff --git a/catalyst/targets/netboot.py b/catalyst/targets/netboot.py
208 index 9a0a4156..55f4dff1 100644
209 --- a/catalyst/targets/netboot.py
210 +++ b/catalyst/targets/netboot.py
211 @@ -93,7 +93,6 @@ class netboot(StageBase):
212 cmd([self.settings['controller_file'], 'image'] +
213 myfiles, env=self.env)
214 except CatalystError:
215 - self.unbind()
216 raise CatalystError("Failed to copy files to image!",
217 print_traceback=True)
218
219 @@ -121,7 +120,6 @@ class netboot(StageBase):
220 cmd([self.settings['controller_file'], 'final'], env=self.env)
221 log.notice('Netboot Build Finished!')
222 except CatalystError:
223 - self.unbind()
224 raise CatalystError("Failed to move kernel images!",
225 print_traceback=True)
226
227 @@ -178,7 +176,6 @@ class netboot(StageBase):
228 "move_kernels",
229 "remove",
230 "empty",
231 - "unbind",
232 ])
233 self.finish_sequence.extend([
234 "clean",
235 diff --git a/catalyst/targets/stage4.py b/catalyst/targets/stage4.py
236 index 78a5c780..b7f74b01 100644
237 --- a/catalyst/targets/stage4.py
238 +++ b/catalyst/targets/stage4.py
239 @@ -57,7 +57,6 @@ class stage4(StageBase):
240 "preclean",
241 "rcupdate",
242 "unmerge",
243 - "unbind",
244 ])
245 self.finish_sequence.extend([
246 "remove",
247 --
248 2.26.2