From 23301afb5f111be40ad5a8a97477f7d5700f8ee0 Mon Sep 17 00:00:00 2001 From: Jonathan Kliegman Date: Wed, 9 Nov 2011 18:30:06 -0500 Subject: [PATCH] Modify zero-free_space to sync the file and remove within it There appear to be race conditions in some environments around mounting and unmounting a file system quickly failing due to a device in use error. This change removes the extra umount/mount/rm/umount sequence around rootfs/filler which was done to ensure the file was being synced to disk. Instead the dd command has added conv=fdatasync which causes it to sync the file to disk on completion. This also fixes a possible loopback device leak where the unmount would fail and then build output directory deletion would fail because the rootfs was still mounted, leaking both disk space and loopback devices. BUG=chromium-os:22308 TEST=Ran filefrag on filler, validated that rootfs.image has blocks of 0 bytes in each position Compressed chromiumos_base_image.bin, compared size to previous build_image Booted image on tegra2 device, confirmed it still boots Change-Id: I097440b7abefd4a0d25f743e968f33a1531a7a21 Reviewed-on: https://gerrit.chromium.org/gerrit/11487 Reviewed-by: Thieu Le Tested-by: Jon Kliegman Reviewed-by: Paul Taysom Reviewed-by: David James Commit-Ready: Jon Kliegman Reviewed-by: Jon Kliegman --- build_library/base_image_util.sh | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/build_library/base_image_util.sh b/build_library/base_image_util.sh index fdb588cda5..ef16a3b86c 100755 --- a/build_library/base_image_util.sh +++ b/build_library/base_image_util.sh @@ -48,8 +48,9 @@ zero_free_space() { info "Zeroing freespace in ${fs_mount_point}" # dd is a silly thing and will produce a "No space left on device" message # that cannot be turned off and is confusing to unsuspecting victims. - ( sudo dd if=/dev/zero of="${fs_mount_point}/filler" bs=4096 \ + ( sudo dd if=/dev/zero of="${fs_mount_point}/filler" bs=4096 conv=fdatasync \ || true ) 2>&1 | grep -v "No space left on device" + sudo rm "${fs_mount_point}/filler" } # Takes as an arg the name of the image to be created. @@ -218,24 +219,14 @@ create_base_image() { # Zero rootfs free space to make it more compressible so auto-update # payloads become smaller zero_free_space "${ROOT_FS_DIR}" - loopback_cleanup trap delete_prompt EXIT - # Now that the filler file has been sync'd to disk and has filled - # up all free space with zeros, re-mount the rootfs to delete the - # filler file. - ROOT_LOOP_DEV=$(sudo losetup --show -f "${ROOT_FS_IMG}") - sudo mount -t ext2 "${ROOT_LOOP_DEV}" "${ROOT_FS_DIR}" - sudo rm -f "${ROOT_FS_DIR}/filler" - sudo umount -d "${ROOT_FS_DIR}" - # Create the GPT-formatted image. build_gpt "${BUILD_DIR}/${image_name}" \ "${ROOT_FS_IMG}" \ "${STATEFUL_FS_IMG}" \ "${ESP_FS_IMG}" - # Clean up temporary files. rm -f "${ROOT_FS_IMG}" "${STATEFUL_FS_IMG}" "${ESP_FS_IMG}"