From 12cb94a75d0ff5859dc57fb2b42154b32075d1a9 Mon Sep 17 00:00:00 2001 From: James Arendt Date: Thu, 17 Dec 2015 20:16:17 -0800 Subject: [PATCH] Fix unmount/remove race in cleanup_build_dir With a slow file system, umount can return 0 and the immediately following remove can fail with a "Device or resource busy" error. This happened in DevStack in disk-image-create where unmount_image is followed by an immediate cleanup_build_dir. Solution is to apply same logic from bug 1332521 to allow the remove to retry on failure (up to 5s) in case the umount has not completed. Change-Id: I3337e2b4ad0111e77f79dc179439cdfea8ebdeda Closes-Bug: #1527721 --- lib/common-functions | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/common-functions b/lib/common-functions index fdfec48f..0f948260 100644 --- a/lib/common-functions +++ b/lib/common-functions @@ -173,7 +173,10 @@ function mount_qcow_image() { } function cleanup_build_dir () { - sudo rm -rf $TMP_BUILD_DIR/built + if ! timeout 5 sh -c " while ! sudo rm -rf $TMP_BUILD_DIR/built; do sleep 1; done"; then + echo "ERROR: unable to cleanly remove $TMP_BUILD_DIR/built" + exit 1 + fi sudo rm -rf $TMP_BUILD_DIR/mnt if tmpfs_check 0; then sudo umount -f $TMP_BUILD_DIR || true