From: Mateusz Moscicki Date: Tue, 19 Dec 2023 14:34:00 +0000 (+0100) Subject: Add check for dm-bow error during upgrade X-Git-Tag: accepted/tizen/unified/20240319.154803^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1aa13f82eed8be03f50d7e54e8782ad0403a15a2;p=platform%2Fcore%2Fsystem%2Fupgrade.git Add check for dm-bow error during upgrade If such an error occurs, the partition will be remounted as RO. Therefore, before commiting the data, a check is made to ensure that the partition is not in this mode. Change-Id: I43cb571b646f2e0403e2e1138f455c8afe571d59 --- diff --git a/scripts/rw-upgrade/rw-update-macro.inc b/scripts/rw-upgrade/rw-update-macro.inc index c431da1..70a5c2d 100644 --- a/scripts/rw-upgrade/rw-update-macro.inc +++ b/scripts/rw-upgrade/rw-update-macro.inc @@ -162,14 +162,36 @@ restore_backup_file() { fi } +IS_MOUNT_RO() +{ + PART_PATH="$1" + if ! grep "$PART_PATH" /proc/mounts | \ + awk '{print $4}' | \ + awk -F',' '{for(i=1; i<=NF; i++) {if ($i == "ro") {found=1; exit}}} END {exit found}'; then + + ERROR "Partition $PART_PATH is mounted as RO, probably due to an error" + return 1 + fi + return 0 +} + COMMIT_BOW_PARTITION() { LABEL=${1} BOWDEV_PATH=/dev/mapper/bowdev_${LABEL} + + if ! IS_MOUNT_RO "$BOWDEV_PATH"; then + # If the partition is in read-only mode, it is most likely that + # an dm-bow error occurred as a result of insufficient free + # space. Therefore, the upgrade must be considered unsuccessful. + return 1 + fi + DM_NUMBER=$(($("${STAT}" -c "0x%T" $(readlink -f ${BOWDEV_PATH})))) echo 2 > /sys/block/dm-${DM_NUMBER}/bow/state NOTIFY "Changes on partition ${LABEL} commited (dm-bow)" + return 0 } COMMIT_F2FS_PARTITION() @@ -177,8 +199,13 @@ COMMIT_F2FS_PARTITION() LABEL=${1} PART_DEVICE=${2} - mount -o remount,checkpoint=enable "${PART_DEVICE}" - NOTIFY "Changes on partition ${LABEL} commited (f2fs)" + if mount -o remount,checkpoint=enable "${PART_DEVICE}"; then + NOTIFY "Changes on partition ${LABEL} commited (f2fs)" + return 0 + else + ERROR "Error when commit changes on partition ${LABEL} (f2fs)" + return 1 + fi } DELETE_BTRFS_PARTITION() { @@ -186,7 +213,7 @@ DELETE_BTRFS_PARTITION() { MNT_POINT="$("$FINDMNT" "$PART" -o TARGET)" if [ "$MNT_POINT" = "" ]; then ERROR "Unable to find btrfs mountpoint for: $PART" - return + return 1 fi NOTIFY "Deleting btrfs snapshot" umount "${MNT_POINT}" @@ -195,6 +222,7 @@ DELETE_BTRFS_PARTITION() { rm -rf "$MNT_POINT/fota/RO_update" umount "${MOUNT_POINT}" mount -o rw "${PART}" "${MNT_POINT}" + return 0 } @@ -202,8 +230,12 @@ COMMIT_BTRFS_PARTITION() { LABEL=${1} PART_SYSTEM_DATA=$(blkid --match-token PARTLABEL="${LABEL}" -o device -l || blkid --match-token LABEL="${LABEL}" -o device -l) - DELETE_BTRFS_PARTITION "${PART_SYSTEM_DATA}" - NOTIFY "Changes on partition ${LABEL} commited (btrfs)" + if DELETE_BTRFS_PARTITION "${PART_SYSTEM_DATA}"; then + NOTIFY "Changes on partition ${LABEL} commited (btrfs)" + return 0 + fi + + return 1 } COMMIT_PARTITION() @@ -213,7 +245,7 @@ COMMIT_PARTITION() PART_DEVICE=$(blkid --match-token PARTLABEL="${LABEL}" -o device -l || blkid --match-token LABEL="${LABEL}" -o device -l) if [ -z "${PART_DEVICE}" ]; then NOTIFY "WARNING: Partition ${LABEL} not found" - return + return 0 fi TYPE=$(blkid ${PART_DEVICE} -o value -s TYPE | tail -n 1) @@ -226,10 +258,17 @@ COMMIT_PARTITION() else ERROR "ERROR: Cannot commit ${LABEL}: Unsupported filesystem ${TYPE}" fi + return $? } COMMIT_CHANGES() { - COMMIT_PARTITION system-data - COMMIT_PARTITION user + if ! COMMIT_PARTITION system-data; then + return 1 + fi + if ! COMMIT_PARTITION user; then + return 1 + fi + + return 0 } diff --git a/scripts/rw-upgrade/update-finalize.sh.in b/scripts/rw-upgrade/update-finalize.sh.in index 172de40..6d1a137 100644 --- a/scripts/rw-upgrade/update-finalize.sh.in +++ b/scripts/rw-upgrade/update-finalize.sh.in @@ -40,7 +40,11 @@ UPDATE_SUCCESS=1 if [ -z ${UPDATE_PREPARE_ERR+x} ] && [ "${UPDATE_SUCCESS}" == "1" ]; then /usr/bin/device_board_clear_boot_mode - COMMIT_CHANGES + if ! COMMIT_CHANGES; then + ERROR "FAIL: Commit changes error" + reboot -f fota + fi + /usr/bin/device_board_clear_partition_ab_cloned /usr/bin/device_board_set_boot_success SET_UPGRADE_STATUS 100