Add data restore for partitions checkpointed with BOW 89/274389/2
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Tue, 26 Apr 2022 14:08:06 +0000 (16:08 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 27 Apr 2022 14:37:42 +0000 (16:37 +0200)
If the data on the partition was checkpointed with BOW (e.g. during an
upgrade) and was not commited before the reboot, it should be restored
at this point, as this means that an unexpected reboot has occurred.

Change-Id: I09d116c233b26a81ff4517445decd18ad0eb5933

packaging/initrd-recovery.spec
src/initrd-recovery/00-initrd-recovery.list.in
src/initrd-recovery/init

index 3ddc7096cb10de648627cd54b9ca42ed6bae9f81..add54a8f0185c73b26af925ecf79cf640b02235e 100644 (file)
@@ -8,6 +8,7 @@ ExclusiveArch:  %{arm} aarch64
 
 Source0:        %{name}-%{version}.tar.gz
 Source1001:     initrd-recovery.manifest
+Requires:       bow-restore
 
 BuildRequires:  cmake
 
index 7ba7d2b9c8213827292cd729fbf4404c6c690404..fb73e5cd79130ec0dc195b8ded96eaf620b4e8ee 100644 (file)
@@ -14,6 +14,7 @@ WITHLIBS="
 /usr/bin/umount
 /usr/bin/dirname
 /usr/sbin/blkid
+/usr/sbin/bow-restore
 "
 
 # LinkFileName:Target
index fdccb71482a28e5650bd21bdc9205b990670bc37..21cc1bbe3a6649afd1d9e06e8f6acf22b2c11db1 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 export PATH=/usr/bin:/bin:/usr/sbin:/sbin
 
@@ -13,6 +13,7 @@ DIRNAME="/bin/dirname"
 REBOOT="/sbin/reboot"
 BLKID="/usr/sbin/blkid"
 CP="/bin/cp"
+BOW_RESTORE="/sbin/bow-restore"
 
 #------------------------------------------------
 #       mount_partitions
@@ -105,6 +106,45 @@ do_reboot() {
     done
 }
 
+#------------------------------------------------
+#       restore_checkpoint
+#------------------------------------------------
+restore_checkpoint() {
+    # Any existing checkpoint means that the RW update was unexpectedly
+    # aborded, so we must roll back the changes and update again.
+    echo "Checkpoint restore"
+    PART="${1}"
+    FS_TYPE="$(blkid -o value -s TYPE "${PART}")"
+    if [ "$FS_TYPE" = "ext4" ]; then
+        "$BOW_RESTORE" "${PART}"
+    else
+        echo "Checkpoint restore error: unknown filesystem ${FS_TYPE} on ${PART}"
+    fi
+}
+
+#------------------------------------------------
+#       restore_partitions
+#------------------------------------------------
+restore_partitions() {
+    echo "Restore partitions"
+    . /usr/libexec/upgrade-support/upgrade-common.inc
+    if [[ "${P_SLOT}" == "" ]]
+    then
+        # We have only one slot, so it is likely that rootfs also has
+        # a checkpoint
+        restore_checkpoint "${PART_ROOTFS}"
+        if [ ! "z${PART_HAL}" = "z" ]; then
+            restore_checkpoint "${PART_HAL}"
+        fi
+    fi
+    if [ ! "z${PART_USER}" = "z" ]; then
+        restore_checkpoint "${PART_USER}"
+    fi
+    if [ ! "z${PART_SYSTEM_DATA}" = "z" ]; then
+        restore_checkpoint "${PART_SYSTEM_DATA}"
+    fi
+}
+
 #------------------------------------------------
 #       Main Routine Start
 #------------------------------------------------
@@ -112,6 +152,8 @@ echo "You entered into /sbin/init on initrd"
 
 mount_partitions
 mount_inform
+get_partition_id
+restore_partitions
 copy_hal_data
 
 cd /