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 <thieule@chromium.org>
Tested-by: Jon Kliegman <kliegs@chromium.org>
Reviewed-by: Paul Taysom <taysom@google.com>
Reviewed-by: David James <davidjames@chromium.org>
Commit-Ready: Jon Kliegman <kliegs@chromium.org>
Reviewed-by: Jon Kliegman <kliegs@chromium.org>
This commit is contained in:
Jonathan Kliegman 2011-11-09 18:30:06 -05:00 committed by Gerrit
parent d8f9130863
commit 23301afb5f

View File

@ -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}"