Dynamic Partitions - fix remove partitions after cloning
authorJacek Kryszyn <j.kryszyn@samsung.com>
Tue, 19 Mar 2024 11:27:06 +0000 (12:27 +0100)
committerChanwoo Choi <cw00.choi@samsung.com>
Wed, 24 Apr 2024 01:50:02 +0000 (10:50 +0900)
Dynamic partitions from the next slot are removed after
cloning using dmsetup remove. Sometimes this operation
fails due to devices being busy. This fix changes the
way that partitions are removed. dmsetup remove is
repeated five times and --retry flag is used which makes
dmsetup try to remove the device for a couple of seconds
until it will fail.

Change-Id: I2b13055981ed9d4ed5f6b69b516b932c96da020f

scripts/upgrade-support/upgrade-common.inc

index 34e5e0dee0067ee58d943c7b22f94d8e39125bcf..66ccd5eed13ff8827431947548a9664b8d91cd4e 100644 (file)
@@ -115,7 +115,7 @@ verify_img() {
 check_ab_partition_scheme() {
        CURRENT_AB="$(/bin/sed -E 's|.*(partition_ab=)([a-b]).*|\2|' /proc/cmdline)"
        if [ "$CURRENT_AB" != "a" ] && [ "$CURRENT_AB" != "b" ]; then
-               flog "[Info] There is no A/B partition scheme"
+               flog "[Error] There is no A/B partition scheme"
                exit_error
        fi
        NEXT_AB="b"
@@ -124,17 +124,30 @@ check_ab_partition_scheme() {
        fi
 }
 
+unmap_dp () {
+       local part=$1
+
+       for i in 1 .. 5; do
+               if dmsetup remove --retry "${part}"; then
+                       return 0
+               fi
+       done
+
+       flog "[Error] It was not possible to remove /dev/mapper/$part"
+       exit_error
+}
+
 unmap_next_dynamic_partitions () {
        if [ -n "$SUPERFS" ]; then
                local MAPPED_DEVICES=""
                MAPPED_DEVICES=$(dmsetup ls)
 
                if [[ $MAPPED_DEVICES = *"rootfs_${NEXT_AB}"* ]]; then
-                       dmsetup remove rootfs_"${NEXT_AB}"
+                       unmap_dp "rootfs_${NEXT_AB}"
                fi
 
                if [[ $MAPPED_DEVICES = *"hal_${NEXT_AB}"* ]]; then
-                       dmsetup remove hal_"${NEXT_AB}"
+                       unmap_dp "hal_${NEXT_AB}"
                fi
        fi
 }