From d7f68814750b890265ae639022d3647e3f91b430 Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Tue, 24 May 2022 22:43:35 +0200 Subject: [PATCH] Add a lock to the upgrade script One of the steps in A/B upgrade is to clone a partitions from the current slot to the next slot. At the same time there is clone_partition.service that also clones partitions for recovery purposes. Adding a lock is to prevent both processes from cloning partitions at the same time. Change-Id: I6f831eebbd6de37617a0b09145dbd70f15d7d638 --- clone_partitions/clone_partitions.sh | 4 ++++ scripts/upgrade-full.sh | 5 +++++ scripts/upgrade-trigger.sh | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/clone_partitions/clone_partitions.sh b/clone_partitions/clone_partitions.sh index 9fb74ea..3b4490b 100644 --- a/clone_partitions/clone_partitions.sh +++ b/clone_partitions/clone_partitions.sh @@ -1,5 +1,6 @@ #!/bin/bash PATH=/bin:/usr/bin:/sbin:/usr/sbin +FLOCK_PATH="/var/lock/clone_partitions.lock" SCRIPT_NAME="clone_partitions.sh" @@ -62,6 +63,8 @@ if [ ! -z "${UPGRADE_DEBUG}" ]; then set -x fi +( +flock 9 case $1 in "recovery") /bin/device_board_clear_partition_ab_cloned @@ -72,3 +75,4 @@ case $1 in do_clone ;; esac +) 9> "$FLOCK_PATH \ No newline at end of file diff --git a/scripts/upgrade-full.sh b/scripts/upgrade-full.sh index ee9a383..bdf8e84 100755 --- a/scripts/upgrade-full.sh +++ b/scripts/upgrade-full.sh @@ -23,6 +23,7 @@ LOG_FILE="/tmp/upgrade-trigger.log" CONFIG_FILE="update.cfg" HAL_UPGRADE_CFG_DIR="/hal/etc/upgrade/" HAL_PART_LIST_FILE="background_copy.list" +FLOCK_PATH="/var/lock/clone_partitions.lock" if [ "$#" != "1" ] || [ ! -f "$1" ]; then log "[Error] Usage: $0 path_to_upgrade.tar[.gz]" "$LOG_FILE" @@ -59,6 +60,9 @@ reboot_to_fota() { fi } +( +flock 9 + check_ab_partition_scheme check_used_block_device unpack_file "$DELTA_TAR" "$CONFIG_FILE" @@ -69,3 +73,4 @@ upgrade_images "$DOWNLOAD_DELTA" set_upgrade_status 80 reboot_to_fota cleanup_files +) 9> "$FLOCK_PATH" diff --git a/scripts/upgrade-trigger.sh b/scripts/upgrade-trigger.sh index f094d2a..1df950e 100755 --- a/scripts/upgrade-trigger.sh +++ b/scripts/upgrade-trigger.sh @@ -19,6 +19,7 @@ SCRIPT_UPGRADE_FULL="upgrade-full.sh" SCRIPT_UPGRADE_PREPARE_PARTITIONS="upgrade-prepare-partitions.sh" SCRIPT_UPGRADE_PARTIAL="upgrade-partial.sh" SCRIPT_UPGRADE_FOTA="upgrade-fota.sh" +FLOCK_PATH="/var/lock/clone_partitions.lock" prepare_fota_dir() { if [ -d "$FOTA_DIR" ]; then @@ -101,6 +102,9 @@ do_update() { fi } +( +flock 9 + rm -f "$LOG_FILE" && touch "$LOG_FILE" if [ "$#" != "1" ] || [ ! -f "$1" ]; then @@ -118,3 +122,4 @@ tar xfp "$DOWNLOAD_DELTA" -C "$FOTA_DIR" upgrade-common.inc set_upgrade_status 1 verify_img "${DOWNLOAD_DELTA}" do_update +) 9> "$FLOCK_PATH" -- 2.7.4