diff options
author | rtkapiper <andy.piper@arcticwolf.com> | 2023-07-11 17:53:08 +0000 |
---|---|---|
committer | rtkapiper <andy.piper@arcticwolf.com> | 2023-07-14 14:10:04 +0000 |
commit | a993ca34fe8a6e190b3216b34c2127f921315b1e (patch) | |
tree | a79350e723656c8e155caf4dbada282cb2b364de | |
parent | f0d9ccccaaabba9bf0f53fee4bfbbf1ebb21d4ef (diff) | |
download | vmdb2-a993ca34fe8a6e190b3216b34c2127f921315b1e.tar.gz |
grub_plugin virtualfs_plugin: only mount virtual filesystems once
The grub_plugin mounts a subset of the filesystems mounted by the
virtualfs_plugin. When `vmdb2` is run on Docker for Mac and
virtualfs_plugin and grub_plugin are both used, the rootfs cannot be
unmounted during teardown because some virtualfs mounts have been
mounted twice but only unmounted once. This results in leaked
device-mapper entries after each execution of `vmdb2`
To fix this issue, these plugins now only mount filesystems that
have not already been mounted.
-rw-r--r-- | vmdb/plugins/grub_plugin.py | 15 | ||||
-rw-r--r-- | vmdb/plugins/virtualfs_plugin.py | 3 |
2 files changed, 12 insertions, 6 deletions
diff --git a/vmdb/plugins/grub_plugin.py b/vmdb/plugins/grub_plugin.py index a0d8479..1bfdda8 100644 --- a/vmdb/plugins/grub_plugin.py +++ b/vmdb/plugins/grub_plugin.py @@ -341,14 +341,17 @@ class GrubStepRunner(vmdb.StepRunnerInterface): def mount(self, chroot, path, mount_point, state, mount_opts=None): chroot_path = self.chroot_path(chroot, mount_point) - if not os.path.exists(chroot_path): - os.makedirs(chroot_path) + if os.path.ismount(chroot_path): + logging.debug("already mounted: %s", chroot_path) + else: + if not os.path.exists(chroot_path): + os.makedirs(chroot_path) - if mount_opts is None: - mount_opts = [] + if mount_opts is None: + mount_opts = [] - vmdb.runcmd(["mount"] + mount_opts + [path, chroot_path]) - state.grub_mounts.append(chroot_path) + vmdb.runcmd(["mount"] + mount_opts + [path, chroot_path]) + state.grub_mounts.append(chroot_path) def chroot_path(self, chroot, path): return os.path.normpath(os.path.join(chroot, "." + path)) diff --git a/vmdb/plugins/virtualfs_plugin.py b/vmdb/plugins/virtualfs_plugin.py index cddb8e7..925e10b 100644 --- a/vmdb/plugins/virtualfs_plugin.py +++ b/vmdb/plugins/virtualfs_plugin.py @@ -56,6 +56,9 @@ class VirtualFilesystemMountStepRunner(vmdb.StepRunnerInterface): for device, mount_point, fstype in self.virtuals: path = os.path.normpath(os.path.join(rootfs, "./" + mount_point)) + if os.path.ismount(path): + logging.debug("already mounted: %s", path) + continue if not os.path.exists(path): os.mkdir(path) vmdb.runcmd(["mount", "-t", fstype, device, path]) |