Add checkpoint for user and system_data partitions. 53/260853/4
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Mon, 1 Mar 2021 14:09:28 +0000 (15:09 +0100)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Fri, 30 Jul 2021 12:25:12 +0000 (14:25 +0200)
Change-Id: Ibde9fb6e98d6128549d5a11e417a3d461dce293b

CMakeLists.txt
packaging/system-rw-update.spec
units/data-checkpoint.service.in [new file with mode: 0644]
units/data-checkpoint.target [new file with mode: 0644]
units/udev-trigger-dmbow@.service [new file with mode: 0644]
upgrade/update-checkpoint-create.sh [new file with mode: 0755]
upgrade/update.sh.in

index fdf84fd634eb76b9c22a7e13507e691eb8552277..5481ce413ac52ad946a2982cb8fe113889069d8b 100755 (executable)
@@ -7,3 +7,4 @@ CONFIGURE_FILE(upgrade/update.sh.in            upgrade/update.sh            @ONL
 CONFIGURE_FILE(upgrade/record-version.sh.in    upgrade/record-version.sh    @ONLY)
 CONFIGURE_FILE(units/udev-sdb-init.service.in  units/udev-sdb-init.service  @ONLY)
 CONFIGURE_FILE(units/offline-update.service.in units/offline-update.service @ONLY)
+CONFIGURE_FILE(units/data-checkpoint.service.in units/data-checkpoint.service @ONLY)
index a361b6e25b375c3814fb210cd7fc1cf9710893a6..aa184e26e7d80daaaab3e0a035c7efa325c64468 100644 (file)
@@ -1,6 +1,6 @@
 Name:       system-rw-update
 Summary:    System RW Update Manager
-Version:    1.2.4
+Version:    1.3.0
 Release:    0
 Group:      Base/Startup
 License:    Apache-2.0
@@ -43,6 +43,7 @@ cp upgrade/record-version.sh %{buildroot}%{upgrade_dir}
 cp upgrade/rw-update-macro.inc %{buildroot}%{upgrade_dir}
 cp upgrade/update-init.sh %{buildroot}%{upgrade_dir}
 cp upgrade/update.sh %{buildroot}%{upgrade_dir}
+cp upgrade/update-checkpoint-create.sh %{buildroot}%{upgrade_dir}
 mkdir -p %{buildroot}%{_unitdir}/system-update.target.wants
 install -m 644 units/offline-update.service %{buildroot}%{_unitdir}
 ln -s ../offline-update.service %{buildroot}%{_unitdir}/system-update.target.wants/
@@ -54,6 +55,17 @@ ln -s ../dbus.socket %{buildroot}%{_unitdir}/system-update.target.wants
 install -m 644 units/udev-sdb-init.service %{buildroot}%{_unitdir}
 ln -s ../udev-sdb-init.service %{buildroot}%{_unitdir}/system-update.target.wants
 
+# DM-BOW device prepare
+install -m 644 units/udev-trigger-dmbow@.service %{buildroot}%{_unitdir}
+ln -s ../udev-trigger-dmbow@.service %{buildroot}%{_unitdir}/system-update.target.wants/udev-trigger-dmbow@user.service
+
+# data checkpoint target
+install -m 644 units/data-checkpoint.target %{buildroot}%{_unitdir}
+install -m 644 units/data-checkpoint.service %{buildroot}%{_unitdir}
+ln -s ../data-checkpoint.target %{buildroot}%{_unitdir}/system-update.target.wants
+mkdir -p %{buildroot}%{_unitdir}/data-checkpoint.target.wants
+ln -s ../data-checkpoint.service %{buildroot}%{_unitdir}/data-checkpoint.target.wants/data-checkpoint.service
+
 %clean
 rm -rf %{buildroot}
 
@@ -72,3 +84,7 @@ fi
 %{_unitdir}/offline-update.service
 %{_unitdir}/system-update.target.wants
 %{_unitdir}/udev-sdb-init.service
+%{_unitdir}/udev-trigger-dmbow@.service
+%{_unitdir}/data-checkpoint.target
+%{_unitdir}/data-checkpoint.service
+%{_unitdir}/data-checkpoint.target.wants/data-checkpoint.service
diff --git a/units/data-checkpoint.service.in b/units/data-checkpoint.service.in
new file mode 100644 (file)
index 0000000..566d935
--- /dev/null
@@ -0,0 +1,17 @@
+[Unit]
+Description=Data checkpoint
+DefaultDependencies=no
+Before=systemd-journald.service opt.mount opt-usr.mount
+
+
+[Service]
+Type=oneshot
+ExecStart=@TZ_SYS_UPGRADE@/update-checkpoint-create.sh
+RemainAfterExit=yes
+StandardOutput=journal+console
+StandardError=journal+console
+SmackProcessLabel=System::Privileged
+
+[Install]
+WantedBy=data-checkpoint.target
+
diff --git a/units/data-checkpoint.target b/units/data-checkpoint.target
new file mode 100644 (file)
index 0000000..b4694c5
--- /dev/null
@@ -0,0 +1,7 @@
+[Unit]
+Description=Data checkpoint
+DefaultDependencies=no
+Conflicts=shutdown.target
+Before=local-fs-pre.target
+OnFailure=emergency.target
+OnFailureJobMode=replace-irreversibly
diff --git a/units/udev-trigger-dmbow@.service b/units/udev-trigger-dmbow@.service
new file mode 100644 (file)
index 0000000..294619f
--- /dev/null
@@ -0,0 +1,17 @@
+# If coldplug (systemd-udev-trigger.service) is called before the "local file
+# system" target is reached, it will not be possible to mount created bow
+# device because it will have the "SYSTEMD_READY=0" flag. This unit trigger the
+# change action on the bow device  to remove that flag, then systemd sees the
+# device as available.
+
+[Unit]
+Description=Trigger the change action on DM-BOW device if system update
+DefaultDependencies=no
+After=systemd-udev-trigger.service
+Before=opt.mount opt-usr.mount
+ConditionPathExists=/dev/mapper/bowdev_%i
+
+[Service]
+SmackProcessLabel=System
+Type=oneshot
+ExecStart=/usr/sbin/udevadm trigger -c change /dev/mapper/bowdev_%i
diff --git a/upgrade/update-checkpoint-create.sh b/upgrade/update-checkpoint-create.sh
new file mode 100755 (executable)
index 0000000..4f8ba2a
--- /dev/null
@@ -0,0 +1,69 @@
+#!/bin/bash 
+PATH="/usr/bin:/bin:/usr/sbin:/sbin"
+
+SYNC="/bin/sync"
+REBOOT="/sbin/reboot"
+MOUNT="/bin/mount"
+UMOUNT="/bin/umount"
+BLKID="/usr/sbin/blkid"
+DMSETUP="/usr/sbin/dmsetup"
+FSTRIM="/usr/sbin/fstrim"
+STAT="/usr/bin/stat"
+
+SYSTEM_DATA_MNT="opt"
+USER_MNT="opt/usr"
+
+
+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)
+        PART_USER=$("$BLKID" --match-token PARTLABEL=user -o device || "$BLKID" --match-token LABEL=user -o device)
+}
+
+mount_bow_partition() {
+        LABEL=${1}
+        PARTITION=${2}
+        DIRECTORY=${3}
+        BOWDEV_NAME=bowdev_${LABEL}
+        BOWDEV_PATH=/dev/mapper/${BOWDEV_NAME}
+        SECTORS=$(</sys/class/block/$(lsblk -no NAME ${PARTITION})/size)
+
+        "${DMSETUP}" create ${BOWDEV_NAME} --table "0 ${SECTORS} bow ${PARTITION}"
+        "${MOUNT}" ${BOWDEV_PATH} ${DIRECTORY}
+        "${SYNC}"
+        "${FSTRIM}" -v ${DIRECTORY}
+
+        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"
+}
+
+mount_f2fs_partition() {
+        LABEL=${1}
+        PARTITION=${2}
+        DIRECTORY=${3}
+        "${MOUNT}" -o checkpoint=disable ${PARTITION} ${DIRECTORY}
+        echo "[Debug] Mounted ${PARTITION} as F2FS checkpoint=disable"
+}
+
+mount_checkpoint_partition() {
+        LABEL=${1}
+        PARTITION=${2}
+        DIRECTORY=${3}
+        FSTYPE=$(lsblk -o FSTYPE -n "${PARTITION}")
+
+        if [ "${FSTYPE}" = "ext4" ]; then
+                mount_bow_partition ${LABEL} ${PARTITION} ${DIRECTORY}
+        elif [ "${FSTYPE}" = "f2fs" ]; then
+                mount_f2fs_partition ${LABEL} ${PARTITION} ${DIRECTORY}
+        else
+                mount ${PARTITION} ${DIRECTORY}
+        fi
+}
+
+get_partition_id
+
+mount_checkpoint_partition system-data ${PART_SYSTEM_DATA} /${SYSTEM_DATA_MNT}
+if [ ! -z "${PART_USER}" ]; then
+        mount_checkpoint_partition user ${PART_USER} /${USER_MNT}
+fi
index 3377c2cb51a7a83529ee21fe7c4fbef975059454..2d065ddfd43a6736f39af295d936ed604f322671 100755 (executable)
@@ -131,4 +131,4 @@ fi
 NOTIFY "----------------------------------------------------------------------"
 
 #Reboot
-/sbin/reboot -f
+reboot -f