From ed37ddccb57e0a0298c51629adc63277f99cb311 Mon Sep 17 00:00:00 2001 From: Andy Piper Date: Mon, 17 Jan 2022 20:51:41 -0500 Subject: mount_plugin: run zerofree by default on unmount When unmounting `ext*` filesystems, run zerofree by default unless told not to via a `zerofree: false` key --- vmdb/plugins/mount.mdwn | 4 ++++ vmdb/plugins/mount_plugin.py | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/vmdb/plugins/mount.mdwn b/vmdb/plugins/mount.mdwn index 9c830ef..b646fb3 100644 --- a/vmdb/plugins/mount.mdwn +++ b/vmdb/plugins/mount.mdwn @@ -12,6 +12,10 @@ Step keys: * `mount-on` — OPTIONAL; tag of already mounted filesystem in image. (FIXME: this may be wrong?) +* `zerofree` — OPTIONAL; Boolean flag controlling whether or not to run + the `zerofree` utility on the filesystem after unmounting it at the end of + the build process. Defaults to `true` + Example (in the .vmdb file): - mount: root diff --git a/vmdb/plugins/mount_plugin.py b/vmdb/plugins/mount_plugin.py index b8102a6..b18c009 100644 --- a/vmdb/plugins/mount_plugin.py +++ b/vmdb/plugins/mount_plugin.py @@ -30,13 +30,22 @@ class MountPlugin(vmdb.Plugin): class MountStepRunner(vmdb.StepRunnerInterface): def get_key_spec(self): - return {"mount": str, "dirname": "", "mount-on": ""} + return {"mount": str, "dirname": "", "mount-on": "", "zerofree": True} def run(self, values, settings, state): self.mount_rootfs(values, settings, state) def teardown(self, values, settings, state): self.unmount_rootfs(values, settings, state) + tag = values["mount"] + run_zerofree = values.get("zerofree", True) + if run_zerofree: + fstype = state.tags.get_fstype(tag) + if fstype.startswith('ext'): + dev = state.tags.get_dev(tag) + vmdb.runcmd(["zerofree", "-v", dev]) + else: + logging.info(f"not running zerofree on {tag} with {fstype} filesystem") def mount_rootfs(self, values, settings, state): tag = values["mount"] -- cgit v1.2.1