From 4a9b57f91fdf3a2b35a5cf707970d05bf9cadba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 2 Mar 2018 02:26:26 +0100 Subject: [PATCH] qvm-template-postprocess: call fstrim after removing image file This is especially important on LVM thin pool, where space after removing the file needs to be given back to the pool, to be reused for other volumes (for example this template). --- qubesadmin/tools/qvm_template_postprocess.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qubesadmin/tools/qvm_template_postprocess.py b/qubesadmin/tools/qvm_template_postprocess.py index 9f6eb03..5fb4ae5 100644 --- a/qubesadmin/tools/qvm_template_postprocess.py +++ b/qubesadmin/tools/qvm_template_postprocess.py @@ -214,6 +214,11 @@ def post_install(args): if not args.keep_source: shutil.rmtree(args.dir) + # if running as root, tell underlying storage layer about just freed + # data blocks + if os.getuid() == 0: + subprocess.call(['sync', '-f', os.path.dirname(args.dir)]) + subprocess.call(['fstrim', os.path.dirname(args.dir)]) return 0