ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
Ryan Wilson 14b620
From 3a1ea280dd3c8c70b616467f4fd375cf2e4d31fa Mon Sep 17 00:00:00 2001
Ryan Wilson 14b620
From: Ryan Wilson <ryantimwilson@meta4.com>
Ryan Wilson 14b620
Date: Sat, 23 Nov 2024 20:30:31 -0800
Ryan Wilson 14b620
Subject: [PATCH] pid1: Do not update state for device units being processed by
Ryan Wilson 14b620
 udev
Ryan Wilson 14b620
Ryan Wilson 14b620
---
Ryan Wilson 14b620
 src/core/device.c | 40 ++++++++++++++++++++++++++++++++++++----
Ryan Wilson 14b620
 src/core/device.h |  1 +
Ryan Wilson 14b620
 2 files changed, 37 insertions(+), 4 deletions(-)
Ryan Wilson 14b620
Ryan Wilson 14b620
diff --git a/src/core/device.c b/src/core/device.c
Ryan Wilson 14b620
index d8567676a7..d13140759d 100644
Ryan Wilson 14b620
--- a/src/core/device.c
Ryan Wilson 14b620
+++ b/src/core/device.c
Ryan Wilson 14b620
@@ -334,6 +334,11 @@ static int device_coldplug(Unit *u) {
Ryan Wilson 14b620
 static void device_catchup(Unit *u) {
Ryan Wilson 14b620
         Device *d = ASSERT_PTR(DEVICE(u));
Ryan Wilson 14b620
 
Ryan Wilson 14b620
+        if (d->enumerated_udev_processing) {
Ryan Wilson 14b620
+                log_unit_debug(u, "Device is being processed by systemd-udevd. Skipping updating state.");
Ryan Wilson 14b620
+                return;
Ryan Wilson 14b620
+        }
Ryan Wilson 14b620
+
Ryan Wilson 14b620
         /* Second, let's update the state with the enumerated state */
Ryan Wilson 14b620
         device_update_found_one(d, d->enumerated_found, DEVICE_FOUND_MASK);
Ryan Wilson 14b620
 }
Ryan Wilson 14b620
@@ -742,6 +747,14 @@ static bool device_is_ready(sd_device *dev) {
Ryan Wilson 14b620
 
Ryan Wilson 14b620
         assert(dev);
Ryan Wilson 14b620
 
Ryan Wilson 14b620
+        r = device_is_processed(dev);
Ryan Wilson 14b620
+        if (r < 0)
Ryan Wilson 14b620
+                log_device_warning_errno(dev, r, "Failed to check if device is processed, assuming device is processed: %m");
Ryan Wilson 14b620
+        if (r == 0) {
Ryan Wilson 14b620
+                log_device_debug(dev, "Device busy: device is currently being processed");
Ryan Wilson 14b620
+                return false;
Ryan Wilson 14b620
+        }
Ryan Wilson 14b620
+
Ryan Wilson 14b620
         if (device_for_action(dev, SD_DEVICE_REMOVE))
Ryan Wilson 14b620
                 return false;
Ryan Wilson 14b620
 
Ryan Wilson 14b620
@@ -1051,16 +1064,35 @@ static void device_enumerate(Manager *m) {
Ryan Wilson 14b620
                 _cleanup_set_free_ Set *ready_units = NULL, *not_ready_units = NULL;
Ryan Wilson 14b620
                 Device *d;
Ryan Wilson 14b620
 
Ryan Wilson 14b620
-                if (device_is_processed(dev) <= 0)
Ryan Wilson 14b620
+                r = device_setup_units(m, dev, &ready_units, &not_ready_units);
Ryan Wilson 14b620
+                if (r < 0) {
Ryan Wilson 14b620
+                        log_device_debug_errno(dev, r, "Failed to set up device units: %m");
Ryan Wilson 14b620
                         continue;
Ryan Wilson 14b620
+                }
Ryan Wilson 14b620
 
Ryan Wilson 14b620
-                if (device_setup_units(m, dev, &ready_units, &not_ready_units) < 0)
Ryan Wilson 14b620
+                r = device_is_processed(dev);
Ryan Wilson 14b620
+                if (r < 0)
Ryan Wilson 14b620
+                        log_device_warning_errno(dev, r, "Failed to determine if device is processed by systemd-udevd, assuming device is processed: %m");
Ryan Wilson 14b620
+                if (r == 0) {
Ryan Wilson 14b620
+                        SET_FOREACH(d, ready_units) {
Ryan Wilson 14b620
+                                log_unit_warning(UNIT(d), "Device unit is ready but currently processing in systemd-udevd.");
Ryan Wilson 14b620
+                                d->enumerated_udev_processing = true;
Ryan Wilson 14b620
+                        }
Ryan Wilson 14b620
+                        SET_FOREACH(d, not_ready_units) {
Ryan Wilson 14b620
+                                log_unit_debug(UNIT(d), "Device unit currently processing in systemd-udevd.");
Ryan Wilson 14b620
+                                d->enumerated_udev_processing = true;
Ryan Wilson 14b620
+                        }
Ryan Wilson 14b620
                         continue;
Ryan Wilson 14b620
+                }
Ryan Wilson 14b620
 
Ryan Wilson 14b620
-                SET_FOREACH(d, ready_units)
Ryan Wilson 14b620
+                SET_FOREACH(d, ready_units) {
Ryan Wilson 14b620
+                        log_unit_debug(UNIT(d), "Device unit found in systemd-udevd.");
Ryan Wilson 14b620
                         device_update_found_one(d, DEVICE_FOUND_UDEV, DEVICE_FOUND_UDEV);
Ryan Wilson 14b620
-                SET_FOREACH(d, not_ready_units)
Ryan Wilson 14b620
+                }
Ryan Wilson 14b620
+                SET_FOREACH(d, not_ready_units) {
Ryan Wilson 14b620
+                        log_unit_debug(UNIT(d), "Device unit not found in systemd-udevd.");
Ryan Wilson 14b620
                         device_update_found_one(d, DEVICE_NOT_FOUND, DEVICE_FOUND_UDEV);
Ryan Wilson 14b620
+                }
Ryan Wilson 14b620
         }
Ryan Wilson 14b620
 
Ryan Wilson 14b620
         return;
Ryan Wilson 14b620
diff --git a/src/core/device.h b/src/core/device.h
Ryan Wilson 14b620
index 9dd6fb57c2..14d5547c7a 100644
Ryan Wilson 14b620
--- a/src/core/device.h
Ryan Wilson 14b620
+++ b/src/core/device.h
Ryan Wilson 14b620
@@ -31,6 +31,7 @@ struct Device {
Ryan Wilson 14b620
         DeviceFound found, deserialized_found, enumerated_found;
Ryan Wilson 14b620
 
Ryan Wilson 14b620
         bool bind_mounts;
Ryan Wilson 14b620
+        bool enumerated_udev_processing;
Ryan Wilson 14b620
 
Ryan Wilson 14b620
         /* The SYSTEMD_WANTS udev property for this device the last time we saw it */
Ryan Wilson 14b620
         char **wants_property;
Ryan Wilson 14b620
-- 
Ryan Wilson 14b620
2.43.5
Ryan Wilson 14b620