diff options
author | Andy Piper <andy.piper@arcticwolf.com> | 2022-01-17 20:51:41 -0500 |
---|---|---|
committer | Andy Piper <andy.piper@arcticwolf.com> | 2022-01-17 21:09:13 -0500 |
commit | ed37ddccb57e0a0298c51629adc63277f99cb311 (patch) | |
tree | 2306a6496eb27a22463a665257bb4bc9591aea09 | |
parent | f2c2863f09bbd6fe10f9f901ffefdc50de5b3598 (diff) | |
download | vmdb2-ed37ddccb57e0a0298c51629adc63277f99cb311.tar.gz |
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
-rw-r--r-- | vmdb/plugins/mount.mdwn | 4 | ||||
-rw-r--r-- | vmdb/plugins/mount_plugin.py | 11 |
2 files changed, 14 insertions, 1 deletions
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"] |