From 987a832351358f797f183305df03ed8baeb56873 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Thu, 4 Jun 2015 10:46:18 +0200 Subject: [PATCH] Cleanup the build directories earlier Split the cleanup_dirs function in two, i.e. cleanup of the build dir and the image dir, and use the former to cleanup the temporary build subdirs after their unmount, before the conversion to other disk formats; they are not needed anyway at that point, and allows to save disk space during the conversion phase. Change-Id: Ie30d7e6033613d6979148423326ae7e17a7342e7 --- bin/disk-image-create | 8 +++++--- lib/common-functions | 13 ++++++++++--- lib/img-functions | 3 ++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/bin/disk-image-create b/bin/disk-image-create index 2778218b..4a95994b 100755 --- a/bin/disk-image-create +++ b/bin/disk-image-create @@ -274,7 +274,10 @@ for X in ${!IMAGE_TYPES[@]} ; do fi done +# Unmount and cleanup the /mnt and /build subdirectories, to save +# space before converting the image to some other format. unmount_image +cleanup_build_dir has_raw_type= if [ "$IS_RAMDISK" == "0" ]; then @@ -292,9 +295,8 @@ if [ -n "$has_raw_type" ]; then compress_and_save_image $IMAGE_NAME.$IMAGE_TYPE fi -# Always cleanup after ourselves -rm -f $TMP_IMAGE_PATH -cleanup_dirs +# Remove the leftovers, i.e. the temporary image directory. +cleanup_image_dir case "$IMAGE_ELEMENT" in *ironic-agent*) diff --git a/lib/common-functions b/lib/common-functions index 20768f30..64a1461c 100644 --- a/lib/common-functions +++ b/lib/common-functions @@ -142,13 +142,20 @@ function mount_qcow_image() { fi } -function cleanup_dirs () { +function cleanup_build_dir () { sudo rm -rf $TMP_BUILD_DIR/built sudo rm -rf $TMP_BUILD_DIR/mnt if tmpfs_check 0; then - sudo umount -f $TMP_BUILD_DIR $TMP_IMAGE_DIR || true + sudo umount -f $TMP_BUILD_DIR || true fi - rm -rf --one-file-system $TMP_BUILD_DIR $TMP_IMAGE_DIR + rm -rf --one-file-system $TMP_BUILD_DIR +} + +function cleanup_image_dir () { + if tmpfs_check 0; then + sudo umount -f $TMP_IMAGE_DIR || true + fi + rm -rf --one-file-system $TMP_IMAGE_DIR } # Run a directory of hooks outside the target (that is, no chrooting). diff --git a/lib/img-functions b/lib/img-functions index 4e3a694c..e9b2c229 100644 --- a/lib/img-functions +++ b/lib/img-functions @@ -36,7 +36,8 @@ function trap_cleanup() { function cleanup () { unmount_image - cleanup_dirs + cleanup_build_dir + cleanup_image_dir } function ensure_nbd () {