Error handling of checkpoint creation 75/275175/3
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Tue, 17 May 2022 08:50:45 +0000 (10:50 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 18 May 2022 12:17:41 +0000 (14:17 +0200)
Change-Id: Iabae1e33e69fc347335f9804b1fba8abacf80915

upgrade/update-checkpoint-create.sh

index cc276d1..4d4c1ed 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/bash 
+#!/bin/bash
 PATH="/usr/bin:/bin:/usr/sbin:/sbin"
 
 SYNC="/bin/sync"
@@ -15,6 +15,15 @@ USER_MNT="opt/usr"
 HAL_MNT="hal"
 BTRFS="/usr/sbin/btrfs"
 
+exit_handler() {
+        if [ $? -ne 0 ]; then
+                echo "[Error] Failure to create checkpoint. Reboot."
+                reboot -f
+                exit 1
+        fi
+        echo "[Debug] Checkpoint created"
+}
+
 get_partition_id() {
         PART_ROOTFS=$("$BLKID" --match-token PARTLABEL=rootfs -o device || "$BLKID" --match-token LABEL=rootfs -o device)
         PART_SYSTEM_DATA=$("$BLKID" --match-token PARTLABEL=system-data -o device || "$BLKID" --match-token LABEL=system-data -o device)
@@ -41,15 +50,26 @@ mount_bow_partition() {
 
         DM_NUMBER=$(($("${STAT}" -c "0x%T" $(readlink -f ${BOWDEV_PATH}))))
         echo 1 > /sys/block/dm-${DM_NUMBER}/bow/state
-        echo "[Debug] Mounted ${PARTITION} as DM-BOW"
+        if [ "$(</sys/block/dm-${DM_NUMBER}/bow/state)" = "1" ]; then
+                echo "[Debug] Mounted ${PARTITION} as DM-BOW"
+                return 0
+        else
+                echo "[Error] Failure to create checkpoint for ${PARTITION}"
+                return 1
+        fi
 }
 
 mount_f2fs_partition() {
         LABEL=${1}
         PARTITION=${2}
         DIRECTORY=${3}
-        "${MOUNT}" -o checkpoint=disable ${PARTITION} ${DIRECTORY}
-        echo "[Debug] Mounted ${PARTITION} as F2FS checkpoint=disable"
+        if "${MOUNT}" -o checkpoint=disable ${PARTITION} ${DIRECTORY}; then
+                echo "[Debug] Mounted ${PARTITION} as F2FS checkpoint=disable"
+                return 0
+        else
+                echo "[Error] Failure to mount partition ${PARTITION}"
+                return 1
+        fi
 }
 
 mount_btrfs_partition() {
@@ -62,6 +82,7 @@ mount_btrfs_partition() {
         "$UMOUNT" "${DIRECTORY}"
         "$MOUNT" -o rw "${PARTITION}" "${DIRECTORY}"
         echo "[Debug] Mounted ${PARTITION} as btrfs"
+        return 0
 }
 
 mount_checkpoint_partition() {
@@ -79,17 +100,22 @@ mount_checkpoint_partition() {
         else
                 mount ${PARTITION} ${DIRECTORY}
         fi
+        return $?
 }
 
+trap exit_handler EXIT
+
 get_partition_id
 
-mount_checkpoint_partition system-data ${PART_SYSTEM_DATA} /${SYSTEM_DATA_MNT}
+mount_checkpoint_partition system-data ${PART_SYSTEM_DATA} /${SYSTEM_DATA_MNT} || exit 1
 if [ ! -z "${PART_USER}" ]; then
-        mount_checkpoint_partition user ${PART_USER} /${USER_MNT}
+        mount_checkpoint_partition user ${PART_USER} /${USER_MNT} || exit 1
 fi
 
 if [ ! -z "${PART_HAL}" ] && [ ! -d "/${HAL_MNT}/lib" ]
 then
         # Workaround code to check whether /hal/lib directory is exist
-        mount_checkpoint_partition hal ${PART_HAL} /${HAL_MNT}
+        mount_checkpoint_partition hal ${PART_HAL} /${HAL_MNT} || exit 1
 fi
+
+exit 0