From 4dd4c54ccb1e41e37ef7708376ae1f2ca28712cf Mon Sep 17 00:00:00 2001 From: David James Date: Wed, 10 Aug 2011 10:19:47 -0700 Subject: [PATCH] Fix race condition by using different symlinks for factory images. Both the tests and archive_build read and write the latest symlink. This CL fixes a race condition in archive_build by moving away from using the latest symlink in archive_build. BUG=chromium-os:18967 TEST=Run release cbuildbot archive_build on x86-mario-release. Verify it completes successfully and that latest symlink is unchanged now. Change-Id: Ia32d20903f3ef74e360944fbabdd9834c0edb99a Reviewed-on: http://gerrit.chromium.org/gerrit/5746 Reviewed-by: David James Tested-by: David James --- archive_build.sh | 42 +++++++++++------------------------------- build_image | 9 ++++++--- make_netboot.sh | 12 +++++++++--- 3 files changed, 26 insertions(+), 37 deletions(-) diff --git a/archive_build.sh b/archive_build.sh index 9e1b0bec82..77b7be8199 100755 --- a/archive_build.sh +++ b/archive_build.sh @@ -154,10 +154,12 @@ echo "archive to file: $ZIPFILE" mkdir -p "$OUTDIR" # Modify image for test if flag set. +CHROOT_IMAGE_DIR=$(reinterpret_path_for_chroot "$FLAGS_from") if [ $FLAGS_test_mod -eq $FLAGS_TRUE ]; then echo "Modifying image for test" ./enter_chroot.sh $CHROOT_ENV -- ./mod_image_for_test.sh \ - --board $FLAGS_board --noinplace --yes + --board $FLAGS_board --noinplace --yes \ + --image $CHROOT_IMAGE_DIR/$CHROMEOS_IMAGE_NAME pushd "${FLAGS_chroot}/build/${FLAGS_board}/usr/local" echo "Archiving autotest build artifacts" @@ -172,8 +174,6 @@ fi # Modify for recovery if [ $FLAGS_official_build -eq $FLAGS_TRUE ]; then - BUILDVER="$(readlink ${IMAGES_DIR}/${FLAGS_board}/latest)" - CHROOT_IMAGE_DIR=/home/$USER/trunk/src/build/images/$FLAGS_board/$BUILDVER ./enter_chroot.sh $CHROOT_ENV -- ./mod_image_for_recovery.sh \ --board $FLAGS_board --image $CHROOT_IMAGE_DIR/chromiumos_base_image.bin fi @@ -194,17 +194,8 @@ if [ $FLAGS_factory_test_mod -eq $FLAGS_TRUE ]; then # fail. You must explictly call replace and specify a unique name numerically # using build_attempt. ./enter_chroot.sh $CHROOT_ENV -- ./build_image --board $FLAGS_board \ - --replace --noenable_rootfs_verification --build_attempt 4 - - ./enter_chroot.sh $CHROOT_ENV -- ./mod_image_for_test.sh \ - --board $FLAGS_board --yes --noinplace --factory - - # Get the factory test dir: It is the newest build. - # This is the output dir for the factory shim, the factory test and - # release images will remain in IMG_DIR, defined previously. - FACTORY_DIR="$(readlink ${IMAGES_DIR}/${FLAGS_board}/latest)" - - echo "Factory image dir: ${FACTORY_DIR}" + --replace --noenable_rootfs_verification --build_attempt 4 \ + --symlink factory_test --factory --test fi # Build differently sized shims. Currently only factory install shim is @@ -220,22 +211,20 @@ if [ $FLAGS_factory_install_mod -eq $FLAGS_TRUE ]; then # fail. You must explictly call replace and specify a unique name numerically # using build_attempt. ./enter_chroot.sh $CHROOT_ENV -- ./build_image --board $FLAGS_board \ - --factory_install --replace --build_attempt 7 + --factory_install --replace --build_attempt 7 --symlink factory_shim - # Get the install shim dir: It is the newest build. - # This is the output dir for the factory shim, the factory test and - # release images will remain in IMG_DIR, defined previously. - SHIM_DIR="$(readlink ${IMAGES_DIR}/${FLAGS_board}/latest)" + # Get the install shim dir: It is the newest factory_shim build. + SHIM_DIR="${IMAGES_DIR}/${FLAGS_board}/factory_shim" + CHROOT_SHIM_DIR=$(reinterpret_path_for_chroot "${SHIM_DIR}") # For ARM we should creat a netboot image. # Only ARM has "uimg" uboot format kernels. # TODO(anush): We should have build infrastructure that can directly # query architecture. if [ -f "${SYSROOT}/boot/vmlinux.uimg" ]; then - ./enter_chroot.sh $CHROOT_ENV -- ./make_netboot.sh --board $FLAGS_board + ./enter_chroot.sh $CHROOT_ENV -- ./make_netboot.sh --board $FLAGS_board \ + --image "$CHROOT_SHIM_DIR/factory_install_shim.bin" fi - - echo "Factory install shim dir: ${SHIM_DIR}" fi # Zip the build @@ -251,16 +240,7 @@ if [ $FLAGS_factory_test_mod -eq $FLAGS_TRUE ] || \ # signing and packaging utilities need unpack_partitions.sh. echo "Compressing factory software" pushd .. - [ -n "${SHIM_DIR}" ] && rm -f factory_shim && \ - ln -s "${SHIM_DIR}" factory_shim - [ -n "${FACTORY_DIR}" ] && rm -f factory_test && \ - ln -s "${FACTORY_DIR}" factory_test - # Restore "latest" status to the original image. - # The "latest" symlink and latest timestamp are used extensively - # throughout the build scripts rather than explicitly specifying an image. - touch "${IMG_DIR}" - [ -n "${IMG_DIR}" ] && rm -f latest && ln -s "${IMG_DIR}" latest FACTORY_MANIFEST=$(find factory_shim factory_test -follow -type f | grep -E "(factory_image|factory_install|partition|netboot|hwid)") rm -f "${FACTORY_ZIPFILE}" diff --git a/build_image b/build_image index 710a4fce08..5305f1434c 100755 --- a/build_image +++ b/build_image @@ -68,6 +68,8 @@ DEFINE_string verity_algorithm "sha1" \ "Cryptographic hash algorithm used for kernel vboot. Default : sha1" DEFINE_boolean standard_backdoor ${FLAGS_TRUE} \ "Install standard backdoor credentials for testing" +DEFINE_string symlink "latest" \ + "Symlink name to use for this image." # TODO(clchiou): Remove this flag after buildbot is fixed DEFINE_boolean crosbug12352_arm_kernel_signing ${FLAGS_TRUE} \ @@ -811,9 +813,10 @@ rmdir "${ROOT_FS_DIR}" "${STATEFUL_FS_DIR}" "${ESP_FS_DIR}" # Generating AU generator zip file to run outside chroot generate_au_zip || echo "Failed generating AU zip file - ignoring Error..." -# Create a 'latest' link -rm -f ${FLAGS_output_root}/${BOARD}/latest -ln -s $(basename ${OUTPUT_DIR}) ${FLAGS_output_root}/${BOARD}/latest + +# Create a named symlink. +LINK_NAME="${FLAGS_output_root}/${BOARD}/${FLAGS_symlink}" +ln -sfT $(basename ${OUTPUT_DIR}) ${LINK_NAME} echo "Done. Image created in ${OUTPUT_DIR}" echo "Chromium OS image created as ${PRISTINE_IMAGE_NAME}" diff --git a/make_netboot.sh b/make_netboot.sh index d795c42887..2d1eb1ac4b 100755 --- a/make_netboot.sh +++ b/make_netboot.sh @@ -42,6 +42,7 @@ get_default_board DEFINE_string board "${DEFAULT_BOARD}" \ "The board to build an image for." +DEFINE_string image "" "Path to the image to use" # Parse command line. FLAGS "$@" || exit 1 @@ -52,10 +53,15 @@ set -e SYSROOT="${GCLIENT_ROOT}/chroot/build/${FLAGS_board}" # build_image artifact output. IMAGES_DIR="${CHROOT_TRUNK_DIR}/src/build/images" -# Canonical install shim name. -INSTALL_SHIM="factory_install_shim.bin" -cd ${IMAGES_DIR}/${FLAGS_board}/latest +if [ -n "${FLAGS_image}" ]; then + cd $(dirname "${FLAGS_image}") + INSTALL_SHIM=$(basename "${FLAGS_image}") +else + cd ${IMAGES_DIR}/${FLAGS_board}/latest + # Canonical install shim name. + INSTALL_SHIM="factory_install_shim.bin" +fi if [ ! -f "${INSTALL_SHIM}" ]; then echo "Cannot locate ${INSTALL_SHIM}, nothing to netbootify!"