From 6337e6fe170ed767f9007613e86673b723be2a19 Mon Sep 17 00:00:00 2001 From: Michael Kerrin <michael.kerrin@hp.com> Date: Tue, 27 Jan 2015 18:45:55 +0000 Subject: [PATCH] Fix issue with leaking /tmp/image.* directories When building the ramdisk we don't cleanup the temporary directories after ourselves. This leaves /tmp/image.* directories mounted and /tmp/image.* directories on the system. Also the ramdisk-functions duplicate, from what I can see, the cleanup function from common-functions. So when a job is killed off it ends up leaving /tmp/image.* directories on the system. Change-Id: I2d73aabd0eb176027b4e7368580db08902e2b6ab --- bin/disk-image-create | 10 ++++------ lib/common-functions | 2 +- lib/ramdisk-functions | 14 -------------- 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/bin/disk-image-create b/bin/disk-image-create index 5e82d9bca..d706d4dc3 100755 --- a/bin/disk-image-create +++ b/bin/disk-image-create @@ -251,14 +251,12 @@ if [ "$IS_RAMDISK" == "0" ]; then for IMAGE_TYPE in ${IMAGE_TYPES[@]} ; do compress_and_save_image $IMAGE_NAME.$IMAGE_TYPE done - rm $TMP_IMAGE_PATH - cleanup_dirs -else - # This is a ramdisk build, we have already extracted the kernel and ramdisk - # by this point. - rm $TMP_IMAGE_PATH fi +# Always cleanup after ourselves +rm $TMP_IMAGE_PATH +cleanup_dirs + case "$IMAGE_ELEMENT" in *ironic-agent*) rm $IMAGE_NAME.$IMAGE_TYPE diff --git a/lib/common-functions b/lib/common-functions index df3475cbe..c876b0960 100644 --- a/lib/common-functions +++ b/lib/common-functions @@ -173,7 +173,7 @@ function cleanup_dirs () { sudo rm -rf $TMP_BUILD_DIR/built sudo rm -rf $TMP_BUILD_DIR/mnt sudo umount -f $TMP_BUILD_DIR $TMP_IMAGE_DIR || true - rm -rf $TMP_BUILD_DIR $TMP_IMAGE_DIR + rm -rf --one-file-system $TMP_BUILD_DIR $TMP_IMAGE_DIR } # Run a directory of hooks outside the target (that is, no chrooting). diff --git a/lib/ramdisk-functions b/lib/ramdisk-functions index 62e27428e..7fa5834d6 100644 --- a/lib/ramdisk-functions +++ b/lib/ramdisk-functions @@ -24,20 +24,6 @@ function fullpath() { fi } -function cleanup () { - if [ "$RAMDISK_ELEMENT" != "dracut-ramdisk" ]; then - unmount_dir "$TMP_BUILD_DIR/mnt" - fi - if [ -f "$TMP_IMAGE_PATH" ]; then - loopdev=`sudo losetup -j "$TMP_IMAGE_PATH" | cut -d: -f1` - if [ -n "$loopdev" ]; then - detach_loopback "$loopdev" - fi - fi - unmount_dir "$TMP_BUILD_DIR" - rm -rf --one-file-system "$TMP_BUILD_DIR" -} - function create_ramdisk_base () { echo "Creating base system"