Add ability to do checkpoint in init 16/310916/4
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 8 May 2024 16:18:46 +0000 (18:18 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Tue, 4 Jun 2024 13:00:23 +0000 (15:00 +0200)
The system-data partition should be mounted before system starts to
boot, due to the configuration files that may reside on it.
Therefore, the script that created checkpoints needed to be modified so
that it could be run from both - systemd service and init.

Change-Id: I6a46c420de1ddc6c7e3ece02f58e132b792a3e47

packaging/upgrade.spec
scripts/rw-upgrade/update-checkpoint-create.sh

index 2e38c36e9837f29170f4edf45018db62199227fc..9601b534611f802101f843ac5cafb3e0c012974e 100644 (file)
@@ -141,6 +141,8 @@ ln -s ../default.target %{buildroot}%{_unitdir}/online-update.target.requires
 ln -s ../online-update-pre.target %{buildroot}%{_unitdir}/online-update.target.requires
 ln -s ../online-update-pre.service %{buildroot}%{_unitdir}/online-update-pre.target.requires
 ln -s ../online-update.service %{buildroot}%{_unitdir}/online-update.target.requires
+ln -s ../udev-trigger-dmbow@.service %{buildroot}%{_unitdir}/online-update.target.requires/udev-trigger-dmbow@system-data.service
+ln -s ../udev-trigger-dmbow@.service %{buildroot}%{_unitdir}/online-update.target.requires/udev-trigger-dmbow@user.service
 ln -s ../online-update-verify.service %{buildroot}%{_unitdir}/online-update-success.service.requires
 ln -s ../online-update-success.service %{buildroot}%{_unitdir}/delayed.target.wants
 ln -s ../online-update-failure.service %{buildroot}%{_unitdir}/online-update-failure.target.requires
@@ -205,6 +207,8 @@ fi
 %{_unitdir}/online-update.target.requires/online-update.service
 %{_unitdir}/online-update.target.requires/online-update-pre.target
 %{_unitdir}/online-update.target.requires/default.target
+%{_unitdir}/online-update.target.requires/udev-trigger-dmbow@system-data.service
+%{_unitdir}/online-update.target.requires/udev-trigger-dmbow@user.service
 %{_unitdir}/online-update.service
 %{_unitdir}/online-update-failure.target
 %{_unitdir}/online-update-failure.target.requires/online-update-failure.service
index fb456fc3e5a1486fc0acd143eaed1b641bf111b3..7d246d0d1ab7b95fa147c6499c4bb4ccb4dc5b6b 100644 (file)
@@ -14,6 +14,8 @@ SYSTEM_DATA_MNT="opt"
 USER_MNT="opt/usr"
 HAL_MNT="hal"
 BTRFS="/usr/sbin/btrfs"
+BASEDIR="/"
+PART_TO_CHECKPOINT=""
 
 exit_handler() {
         if [ $? -ne 0 ]; then
@@ -45,6 +47,7 @@ mount_bow_partition() {
         SECTORS=$(</sys/class/block/$(lsblk -no NAME ${PARTITION})/size)
 
         "${DMSETUP}" create ${BOWDEV_NAME} --table "0 ${SECTORS} bow ${PARTITION}"
+        "${DMSETUP}" mknodes
         "${MOUNT}" ${BOWDEV_PATH} ${DIRECTORY}
         "${SYNC}"
         "${FSTRIM}" -v ${DIRECTORY}
@@ -92,6 +95,13 @@ mount_checkpoint_partition() {
         DIRECTORY=${3}
         FSTYPE=$(lsblk -o FSTYPE -n "${PARTITION}")
 
+        if findmnt "$DIRECTORY" > /dev/null; then
+                # Don't mount if there is something already installed here,
+                # probably init did it.
+                echo "[Info] Partition ${PARTITION} probably already mounted"
+                return 0
+        fi
+
         if [ "${FSTYPE}" = "ext4" ]; then
                 mount_bow_partition ${LABEL} ${PARTITION} ${DIRECTORY}
         elif [ "${FSTYPE}" = "f2fs" ]; then
@@ -104,19 +114,40 @@ mount_checkpoint_partition() {
         return $?
 }
 
+do_checkpoint() {
+        PART_NAME="$1"
+        if [ "${PART_NAME}" == "system-data" ]; then
+                mount_checkpoint_partition system-data "${PART_SYSTEM_DATA}" "${BASEDIR}/${SYSTEM_DATA_MNT}" || exit 1
+        elif [ "${PART_NAME}" == "user" ] && [ ! -z "${PART_USER}" ]; then
+                mount_checkpoint_partition user "${PART_USER}" "${BASEDIR}/${USER_MNT}" || exit 1
+        elif [ "${PART_HAL}" == "hal" ] && [ ! -z "${PART_HAL}" ] && [ ! -d "/${HAL_MNT}/lib" ]; then
+                mount_checkpoint_partition hal "${PART_HAL}" "${BASEDIR}/${HAL_MNT}" || exit 1
+        fi
+}
+
 trap exit_handler EXIT
 
-get_partition_id
 
-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} || exit 1
+if [ "$#" -gt 0 ]; then
+        BASEDIR="$1"
+        if [ "${BASEDIR:0:1}" != "/" ]; then
+                echo "BASEDIR must be a absolute path"
+                exit 1
+        fi
+fi
+
+if [ "$#" -gt 1 ]; then
+        PART_TO_CHECKPOINT="$2"
 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} || exit 1
+get_partition_id
+
+if [ -z "${PART_TO_CHECKPOINT}" ]; then
+        do_checkpoint system-data
+        do_checkpoint user
+        do_checkpoint hal
+else
+        do_checkpoint "${PART_TO_CHECKPOINT}"
 fi
 
 exit 0