commit:     4b5ff905a7ad2ffe1ed8c863b91e9d0ce6981f5f
Author:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 22 20:37:54 2020 +0000
Commit:     Matt Turner <mattst88 <AT> gentoo <DOT> org>
CommitDate: Fri Oct 30 22:40:52 2020 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=4b5ff905

catalyst: Drop unbind()

mount_namespaces(7) says

        A mount ceases to be a member of a peer group when either the
        mount is explicitly unmounted, or when the mount is implicitly
        unmounted because a mount namespace is removed (because it has
        no more member processes).

As a result, we can rely on exiting the mount namespace to unmount the
bind mounts.

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

 catalyst/base/stagebase.py        | 44 +--------------------------------------
 catalyst/targets/embedded.py      |  1 -
 catalyst/targets/livecd_stage1.py |  1 -
 catalyst/targets/livecd_stage2.py |  2 --
 catalyst/targets/netboot.py       |  3 ---
 catalyst/targets/stage4.py        |  1 -
 6 files changed, 1 insertion(+), 51 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index b9c220d0..a75dbdf9 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -498,7 +498,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
             "setup_environment",
             "run_local",
             "preclean",
-            "unbind",
         ])
         self.finish_sequence.extend([
             "clean",
@@ -853,40 +852,8 @@ class StageBase(TargetBase, ClearBase, GenBase):
                                        fstype=fstype, options=options)
                 cxt.mount()
             except OSError as e:
-                self.unbind()
                 raise CatalystError(f"Couldn't mount: {source}, {e.strerror}")
 
-    def unbind(self):
-        chroot_path = self.settings["chroot_path"]
-        umount_failed = False
-
-        # Unmount in reverse order
-        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.debug('%s is not a mount point. Skipping', target)
-                continue
-
-            try:
-                cxt = libmount.Context(target=str(target))
-                cxt.umount()
-            except OSError as e:
-                log.warning("Couldn't umount: %s, %s", target,
-                            e.strerror)
-                umount_failed = True
-
-        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.
-            raise CatalystError(
-                "Couldn't umount one or more bind-mounts; aborting for 
safety.")
-
     def chroot_setup(self):
         self.makeconf = read_makeconf(normpath(self.settings["chroot_path"] +
                                                self.settings["make_conf"]))
@@ -1190,7 +1157,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
                         env=self.env)
                     self.resume.enable("remove")
             except:
-                self.unbind()
                 raise
 
     def preclean(self):
@@ -1206,7 +1172,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
                 self.resume.enable("preclean")
 
         except:
-            self.unbind()
             raise CatalystError("Build failed, could not execute preclean")
 
     def capture(self):
@@ -1269,7 +1234,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
                          self.settings['controller_file'])
 
         except CatalystError:
-            self.unbind()
             raise CatalystError("Stage build aborting due to error.",
                                 print_traceback=False)
 
@@ -1374,7 +1338,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
                     env=self.env)
                 log.info('unmerge shell script')
             except CatalystError:
-                self.unbind()
                 raise
             self.resume.enable("unmerge")
 
@@ -1449,7 +1412,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
                     fileutils.touch(build_packages_resume)
                     self.resume.enable("build_packages")
                 except CatalystError:
-                    self.unbind()
                     raise CatalystError(
                         self.settings["spec_prefix"] +
                         "build aborting due to error.")
@@ -1473,7 +1435,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
                     self._build_kernel(kname=kname)
                 self.resume.enable("build_kernel")
             except CatalystError:
-                self.unbind()
                 raise CatalystError(
                     "build aborting due to kernel build error.",
                     print_traceback=True)
@@ -1517,7 +1478,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
         key = 'boot/kernel/' + kname + '/config'
         if key in self.settings:
             if not os.path.exists(self.settings[key]):
-                self.unbind()
                 raise CatalystError("Can't find kernel config: %s" %
                                     self.settings[key])
 
@@ -1526,7 +1486,7 @@ class StageBase(TargetBase, ClearBase, GenBase):
                             self.settings['chroot_path'] + '/var/tmp/' + kname 
+ '.config')
 
             except IOError:
-                self.unbind()
+                raise
 
     def _copy_initramfs_overlay(self, kname):
         key = 'boot/kernel/' + kname + '/initramfs_overlay'
@@ -1556,7 +1516,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
                 env=self.env)
             self.resume.enable("bootloader")
         except CatalystError:
-            self.unbind()
             raise CatalystError("Script aborting due to error.")
 
     def livecd_update(self):
@@ -1572,7 +1531,6 @@ class StageBase(TargetBase, ClearBase, GenBase):
             self.resume.enable("livecd_update")
 
         except CatalystError:
-            self.unbind()
             raise CatalystError(
                 "build aborting due to livecd_update error.")
 

diff --git a/catalyst/targets/embedded.py b/catalyst/targets/embedded.py
index 1314ce7c..e9138437 100644
--- a/catalyst/targets/embedded.py
+++ b/catalyst/targets/embedded.py
@@ -56,7 +56,6 @@ class embedded(StageBase):
             "root_overlay",
             "fsscript",
             "unmerge",
-            "unbind",
         ])
         self.finish_sequence.extend([
             "remove",

diff --git a/catalyst/targets/livecd_stage1.py 
b/catalyst/targets/livecd_stage1.py
index 81367053..5c5e9f58 100644
--- a/catalyst/targets/livecd_stage1.py
+++ b/catalyst/targets/livecd_stage1.py
@@ -34,7 +34,6 @@ class livecd_stage1(StageBase):
             "chroot_setup",
             "setup_environment",
             "build_packages",
-            "unbind",
         ])
         self.finish_sequence.extend([
             "clean",

diff --git a/catalyst/targets/livecd_stage2.py 
b/catalyst/targets/livecd_stage2.py
index f6c14919..3606047f 100644
--- a/catalyst/targets/livecd_stage2.py
+++ b/catalyst/targets/livecd_stage2.py
@@ -80,7 +80,6 @@ class livecd_stage2(StageBase):
                     for x in self.settings["livecd/modblacklist"]:
                         myf.write("\nblacklist "+x)
             except:
-                self.unbind()
                 raise CatalystError("Couldn't open " +
                                     self.settings["chroot_path"] +
                                     "/etc/modprobe.d/blacklist.conf.",
@@ -109,7 +108,6 @@ class livecd_stage2(StageBase):
                 "fsscript",
                 "rcupdate",
                 "unmerge",
-                "unbind",
             ])
             self.finish_sequence.extend([
                 "remove",

diff --git a/catalyst/targets/netboot.py b/catalyst/targets/netboot.py
index 9a0a4156..55f4dff1 100644
--- a/catalyst/targets/netboot.py
+++ b/catalyst/targets/netboot.py
@@ -93,7 +93,6 @@ class netboot(StageBase):
                 cmd([self.settings['controller_file'], 'image'] +
                     myfiles, env=self.env)
             except CatalystError:
-                self.unbind()
                 raise CatalystError("Failed to copy files to image!",
                                     print_traceback=True)
 
@@ -121,7 +120,6 @@ class netboot(StageBase):
             cmd([self.settings['controller_file'], 'final'], env=self.env)
             log.notice('Netboot Build Finished!')
         except CatalystError:
-            self.unbind()
             raise CatalystError("Failed to move kernel images!",
                                 print_traceback=True)
 
@@ -178,7 +176,6 @@ class netboot(StageBase):
             "move_kernels",
             "remove",
             "empty",
-            "unbind",
         ])
         self.finish_sequence.extend([
             "clean",

diff --git a/catalyst/targets/stage4.py b/catalyst/targets/stage4.py
index 78a5c780..b7f74b01 100644
--- a/catalyst/targets/stage4.py
+++ b/catalyst/targets/stage4.py
@@ -57,7 +57,6 @@ class stage4(StageBase):
             "preclean",
             "rcupdate",
             "unmerge",
-            "unbind",
         ])
         self.finish_sequence.extend([
             "remove",

Reply via email to