From c7d80ddeed80d9ae39a9f2bf2d8a1127cccf6522 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Fri, 9 Aug 2013 22:53:32 +1200 Subject: [PATCH] Cleanup mount points automatically. Manually listing the mount points that need cleanup is not maintainable and makes it hard to write elements that use bind mounting to inject resources into the build environment. Change-Id: I7c9ade444f4ebe42552f8e321f257a7ec0a674ef --- README.md | 5 +++++ elements/base/finalise.d/02-remove-ccache | 4 ++++ lib/img-functions | 14 +++++--------- 3 files changed, 14 insertions(+), 9 deletions(-) create mode 100755 elements/base/finalise.d/02-remove-ccache diff --git a/README.md b/README.md index 461c10c8..cba647e5 100644 --- a/README.md +++ b/README.md @@ -192,6 +192,11 @@ Conform to the following conventions: If they both use set -e and cp -n then the conflict will be caught and cause the build to fail. +* If your element mounts anything into the image build tree ($TMP\_BUILD\_DIR) + then it will be automatically unmounted when the build tree is unmounted - + and not remounted into the filesystem image - if the mount point is needed + again, your element will need to remount it at that point. + Make as many of the following subdirectories as you need, depending on what part of the process you need to customise: diff --git a/elements/base/finalise.d/02-remove-ccache b/elements/base/finalise.d/02-remove-ccache new file mode 100755 index 00000000..b550f726 --- /dev/null +++ b/elements/base/finalise.d/02-remove-ccache @@ -0,0 +1,4 @@ +#!/bin/bash +set -e + +rmdir /tmp/ccache || true diff --git a/lib/img-functions b/lib/img-functions index 40844d64..845e3261 100644 --- a/lib/img-functions +++ b/lib/img-functions @@ -16,16 +16,14 @@ function unmount_image () { # unmount from the chroot # Don't use TMP_MOUNT_PATH here, it might not have been set. - sudo umount -f $TMP_BUILD_DIR/mnt/sys || true - sudo umount -f $TMP_BUILD_DIR/mnt/proc || true - sudo umount -f $TMP_BUILD_DIR/mnt/dev || true - sudo umount -f $TMP_BUILD_DIR/mnt/tmp/in_target.d || true - sudo umount -f $TMP_BUILD_DIR/mnt/tmp/ccache || true + local MOUNTS + MOUNTS=$(grep < /proc/mounts " $TMP_BUILD_DIR/mnt" | awk '{ print $2 }' | sort -r) + for M in $MOUNTS; do + sudo umount -f $M || true + done # give it a second (ok really 5) to umount XXX - why? should instead track # the mount data / lsof etc. sleep 5 - # oh ya don't want to forget to unmount the image - sudo umount -f $TMP_BUILD_DIR/mnt || true # having disk corruption issues; one possibility is qemu-nbd not flushing # dirty pages on disconnect? sync @@ -84,8 +82,6 @@ function run_d_in_target () { check_break after-$1 run_in_target bash sudo umount -f $TMP_MOUNT_PATH/tmp/in_target.d sudo rmdir $TMP_MOUNT_PATH/tmp/in_target.d - sudo umount -f $TMP_MOUNT_PATH/tmp/ccache || true - sudo rmdir $TMP_MOUNT_PATH/tmp/ccache fi }