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)
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
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/
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}
%{_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
--- /dev/null
+[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
+
--- /dev/null
+[Unit]
+Description=Data checkpoint
+DefaultDependencies=no
+Conflicts=shutdown.target
+Before=local-fs-pre.target
+OnFailure=emergency.target
+OnFailureJobMode=replace-irreversibly
--- /dev/null
+# 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
--- /dev/null
+#!/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
NOTIFY "----------------------------------------------------------------------"
#Reboot
-/sbin/reboot -f
+reboot -f