Ryan Wilson 10c3e1
From ca0cef28691be7ea22274c2fa7d95a2725da1ba5 Mon Sep 17 00:00:00 2001
Ryan Wilson 10c3e1
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Ryan Wilson 10c3e1
Date: Sun, 24 Nov 2024 13:19:27 +0900
Ryan Wilson 10c3e1
Subject: [PATCH 1/2] core/device: ignore ID_PROCESSING udev property on
Ryan Wilson 10c3e1
 enumerate
Ryan Wilson 10c3e1
Ryan Wilson 10c3e1
This partially reverts the commit 405be62f05d76f1845f347737b5972158c79dd3e
Ryan Wilson 10c3e1
"tree-wide: refuse enumerated device with ID_PROCESSING=1".
Ryan Wilson 10c3e1
Ryan Wilson 10c3e1
Otherwise, when systemd-udev-trigger.service is started just before
Ryan Wilson 10c3e1
daemon-reexec, which can be easily happen on update, then udev database
Ryan Wilson 10c3e1
files for many devices may have ID_PROCESSING=1 property, thus devices may
Ryan Wilson 10c3e1
not enumerated on daemon-reexec. That causes many units especially mount
Ryan Wilson 10c3e1
units deactivated after daemon-reexec.
Ryan Wilson 10c3e1
Ryan Wilson 10c3e1
Fixes #35329.
Ryan Wilson 10c3e1
---
Ryan Wilson 10c3e1
 src/core/device.c | 3 ---
Ryan Wilson 10c3e1
 1 file changed, 3 deletions(-)
Ryan Wilson 10c3e1
Ryan Wilson 10c3e1
diff --git a/src/core/device.c b/src/core/device.c
Ryan Wilson 10c3e1
index 03a730f6240c1..a8921e91c344e 100644
Ryan Wilson 10c3e1
--- a/src/core/device.c
Ryan Wilson 10c3e1
+++ b/src/core/device.c
Ryan Wilson 10c3e1
@@ -1048,9 +1048,6 @@ static void device_enumerate(Manager *m) {
Ryan Wilson 10c3e1
                 _cleanup_set_free_ Set *ready_units = NULL, *not_ready_units = NULL;
Ryan Wilson 10c3e1
                 Device *d;
Ryan Wilson 10c3e1
 
Ryan Wilson 10c3e1
-                if (device_is_processed(dev) <= 0)
Ryan Wilson 10c3e1
-                        continue;
Ryan Wilson 10c3e1
-
Ryan Wilson 10c3e1
                 if (device_setup_units(m, dev, &ready_units, &not_ready_units) < 0)
Ryan Wilson 10c3e1
                         continue;
Ryan Wilson 10c3e1
 
Ryan Wilson 10c3e1
Ryan Wilson 10c3e1
From 388151b72103c10d63bac1e845d6a151619990ae Mon Sep 17 00:00:00 2001
Ryan Wilson 10c3e1
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Ryan Wilson 10c3e1
Date: Sun, 24 Nov 2024 13:57:37 +0900
Ryan Wilson 10c3e1
Subject: [PATCH 2/2] test: add reproducer for issue #35329
Ryan Wilson 10c3e1
Ryan Wilson 10c3e1
Without the previous commit, the test case will fail.
Ryan Wilson 10c3e1
---
Ryan Wilson 10c3e1
 .../TEST-17-UDEV.device_is_processing.sh      | 65 +++++++++++++++++++
Ryan Wilson 10c3e1
 1 file changed, 65 insertions(+)
Ryan Wilson 10c3e1
 create mode 100755 test/units/TEST-17-UDEV.device_is_processing.sh
Ryan Wilson 10c3e1
Ryan Wilson 10c3e1
diff --git a/test/units/TEST-17-UDEV.device_is_processing.sh b/test/units/TEST-17-UDEV.device_is_processing.sh
Ryan Wilson 10c3e1
new file mode 100755
Ryan Wilson 10c3e1
index 0000000000000..9b39b43238e44
Ryan Wilson 10c3e1
--- /dev/null
Ryan Wilson 10c3e1
+++ b/test/units/TEST-17-UDEV.device_is_processing.sh
Ryan Wilson 10c3e1
@@ -0,0 +1,65 @@
Ryan Wilson 10c3e1
+#!/usr/bin/env bash
Ryan Wilson 10c3e1
+# SPDX-License-Identifier: LGPL-2.1-or-later
Ryan Wilson 10c3e1
+set -ex
Ryan Wilson 10c3e1
+set -o pipefail
Ryan Wilson 10c3e1
+
Ryan Wilson 10c3e1
+# This is a reproducer of issue #35329,
Ryan Wilson 10c3e1
+# which is a regression caused by 405be62f05d76f1845f347737b5972158c79dd3e.
Ryan Wilson 10c3e1
+
Ryan Wilson 10c3e1
+IFNAME=udevtestnetif
Ryan Wilson 10c3e1
+
Ryan Wilson 10c3e1
+udevadm settle
Ryan Wilson 10c3e1
+
Ryan Wilson 10c3e1
+mkdir -p /run/udev/udev.conf.d/
Ryan Wilson 10c3e1
+cat >/run/udev/udev.conf.d/timeout.conf <
Ryan Wilson 10c3e1
+event_timeout=1h
Ryan Wilson 10c3e1
+EOF
Ryan Wilson 10c3e1
+
Ryan Wilson 10c3e1
+mkdir -p /run/udev/rules.d/
Ryan Wilson 10c3e1
+cat >/run/udev/rules.d/99-testsuite.rules <
Ryan Wilson 10c3e1
+SUBSYSTEM=="net", ACTION=="change", KERNEL=="${IFNAME}", OPTIONS="log_level=debug", RUN+="/usr/bin/sleep 1000"
Ryan Wilson 10c3e1
+EOF
Ryan Wilson 10c3e1
+
Ryan Wilson 10c3e1
+systemctl restart systemd-udevd.service
Ryan Wilson 10c3e1
+
Ryan Wilson 10c3e1
+ip link add "$IFNAME" type dummy
Ryan Wilson 10c3e1
+IFINDEX=$(ip -json link show "$IFNAME" | jq '.[].ifindex')
Ryan Wilson 10c3e1
+udevadm wait --timeout 10 "/sys/class/net/${IFNAME}"
Ryan Wilson 10c3e1
+# Check if the database file is created.
Ryan Wilson 10c3e1
+[[ -e "/run/udev/data/n${IFINDEX}" ]]
Ryan Wilson 10c3e1
+
Ryan Wilson 10c3e1
+systemd-run \
Ryan Wilson 10c3e1
+    -p After="sys-subsystem-net-devices-${IFNAME}.device" \
Ryan Wilson 10c3e1
+    -p BindsTo="sys-subsystem-net-devices-${IFNAME}.device" \
Ryan Wilson 10c3e1
+    -u testsleep.service \
Ryan Wilson 10c3e1
+    sleep 1h
Ryan Wilson 10c3e1
+
Ryan Wilson 10c3e1
+timeout 10 bash -c 'until systemctl is-active testsleep.service; do sleep .5; done'
Ryan Wilson 10c3e1
+
Ryan Wilson 10c3e1
+udevadm trigger "/sys/class/net/${IFNAME}"
Ryan Wilson 10c3e1
+timeout 30 bash -c "until grep -F 'ID_PROCESSING=1' /run/udev/data/n${IFINDEX}; do sleep .5; done"
Ryan Wilson 10c3e1
+
Ryan Wilson 10c3e1
+for _ in {1..3}; do
Ryan Wilson 10c3e1
+    systemctl daemon-reexec
Ryan Wilson 10c3e1
+    systemctl is-active testsleep.service
Ryan Wilson 10c3e1
+done
Ryan Wilson 10c3e1
+
Ryan Wilson 10c3e1
+for _ in {1..3}; do
Ryan Wilson 10c3e1
+    systemctl daemon-reload
Ryan Wilson 10c3e1
+    systemctl is-active testsleep.service
Ryan Wilson 10c3e1
+done
Ryan Wilson 10c3e1
+
Ryan Wilson 10c3e1
+# Check if the reexec and reload have finished during processing the event.
Ryan Wilson 10c3e1
+grep -F 'ID_PROCESSING=1' "/run/udev/data/n${IFINDEX}"
Ryan Wilson 10c3e1
+
Ryan Wilson 10c3e1
+# cleanup
Ryan Wilson 10c3e1
+systemctl stop testsleep.service
Ryan Wilson 10c3e1
+rm -f /run/udev/udev.conf.d/timeout.conf
Ryan Wilson 10c3e1
+rm -f /run/udev/rules.d/99-testsuite.rules
Ryan Wilson 10c3e1
+# Forcibly kills sleep command invoked by the udev rule before restarting,
Ryan Wilson 10c3e1
+# otherwise systemctl restart below will takes longer.
Ryan Wilson 10c3e1
+killall -KILL sleep
Ryan Wilson 10c3e1
+systemctl restart systemd-udevd.service
Ryan Wilson 10c3e1
+ip link del "$IFNAME"
Ryan Wilson 10c3e1
+
Ryan Wilson 10c3e1
+exit 0