Add a lock to the upgrade script 22/275422/6
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Tue, 24 May 2022 20:43:35 +0000 (22:43 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Fri, 27 May 2022 08:37:48 +0000 (10:37 +0200)
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
scripts/upgrade-full.sh
scripts/upgrade-trigger.sh

index 9fb74ea..3b4490b 100644 (file)
@@ -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
index ee9a383..bdf8e84 100755 (executable)
@@ -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"
index f094d2a..1df950e 100755 (executable)
@@ -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"