udev-util: rename device_is_processing() -> device_is_processed()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 3 Apr 2024 20:39:25 +0000 (05:39 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 4 Apr 2024 16:48:59 +0000 (01:48 +0900)
And make it also check the existence of the udev database.

src/network/networkd-link.c
src/shared/udev-util.c
src/shared/udev-util.h

index 3e8aa9e37aaadedf31dd6799558a7b8bfd1cc513..192e9df979b66e35dde903207a990ee9bcc62b9f 100644 (file)
@@ -1630,9 +1630,9 @@ static int link_check_initialized(Link *link) {
                 return 0;
         }
 
-        r = sd_device_get_is_initialized(device);
+        r = device_is_processed(device);
         if (r < 0)
-                return log_link_warning_errno(link, r, "Could not determine whether the device is initialized: %m");
+                return log_link_warning_errno(link, r, "Could not determine whether the device is processed by udevd: %m");
         if (r == 0) {
                 /* not yet ready */
                 log_link_debug(link, "link pending udev initialization...");
@@ -1647,14 +1647,6 @@ static int link_check_initialized(Link *link) {
                 return 0;
         }
 
-        r = device_is_processing(device);
-        if (r < 0)
-                return log_link_warning_errno(link, r, "Failed to determine whether the device is being processed: %m");
-        if (r > 0) {
-                log_link_debug(link, "Interface is being processed by udevd, pending initialization.");
-                return 0;
-        }
-
         return link_initialized(link, device);
 }
 
index 0014b7236f5a566c9cfcf0cd9293c8923afc5f9c..19346940352d614bf1ba5617437f675eebe75501 100644 (file)
@@ -237,16 +237,27 @@ int device_is_renaming(sd_device *dev) {
         return r;
 }
 
-int device_is_processing(sd_device *dev) {
+int device_is_processed(sd_device *dev) {
         int r;
 
         assert(dev);
 
+        /* sd_device_get_is_initialized() only checks if the udev database file exists. However, even if the
+         * database file exist, systemd-udevd may be still processing the device, e.g. when the udev rules
+         * for the device have RUN tokens. See issue #30056. Hence, to check if the device is really
+         * processed by systemd-udevd, we also need to read ID_PROCESSING property. */
+
+        r = sd_device_get_is_initialized(dev);
+        if (r <= 0)
+                return r;
+
         r = device_get_property_bool(dev, "ID_PROCESSING");
         if (r == -ENOENT)
-                return false; /* defaults to false */
+                return true; /* If the property does not exist, then it means that the device is processed. */
+        if (r < 0)
+                return r;
 
-        return r;
+        return !r;
 }
 
 bool device_for_action(sd_device *dev, sd_device_action_t a) {
index 13710a3ec1f51e9ab8bac768ef49907c2d544c67..c21c4c158caa7c3d08dea13ce0bab0a1c1517a3a 100644 (file)
@@ -13,7 +13,7 @@ int udev_parse_config(void);
 int device_wait_for_initialization(sd_device *device, const char *subsystem, usec_t timeout_usec, sd_device **ret);
 int device_wait_for_devlink(const char *path, const char *subsystem, usec_t timeout_usec, sd_device **ret);
 int device_is_renaming(sd_device *dev);
-int device_is_processing(sd_device *dev);
+int device_is_processed(sd_device *dev);
 
 bool device_for_action(sd_device *dev, sd_device_action_t action);