Merge pull request #32085 from yuwata/udev-check-processing

udev: check ID_PROCESSING udev property more
This commit is contained in:
Luca Boccassi
2024-04-04 23:46:26 +01:00
committed by GitHub
9 changed files with 40 additions and 22 deletions

View File

@@ -1051,6 +1051,9 @@ static void device_enumerate(Manager *m) {
_cleanup_set_free_ Set *ready_units = NULL, *not_ready_units = NULL;
Device *d;
if (device_is_processed(dev) <= 0)
continue;
if (device_setup_units(m, dev, &ready_units, &not_ready_units) < 0)
continue;

View File

@@ -1365,8 +1365,11 @@ static int manager_enumerate_devices(Manager *m) {
if (r < 0)
return r;
FOREACH_DEVICE(e, d)
FOREACH_DEVICE(e, d) {
if (device_is_processed(d) <= 0)
continue;
(void) manager_add_device(m, d);
}
return 0;
}

View File

@@ -194,8 +194,11 @@ static int manager_enumerate_devices(Manager *m) {
r = 0;
FOREACH_DEVICE(e, d)
FOREACH_DEVICE(e, d) {
if (device_is_processed(d) <= 0)
continue;
RET_GATHER(r, manager_process_seat_device(m, d));
}
return r;
}
@@ -225,8 +228,11 @@ static int manager_enumerate_buttons(Manager *m) {
r = 0;
FOREACH_DEVICE(e, d)
FOREACH_DEVICE(e, d) {
if (device_is_processed(d) <= 0)
continue;
RET_GATHER(r, manager_process_button_device(m, d));
}
return r;
}

View 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);
}

View File

@@ -487,7 +487,7 @@ static int test_network_interface_initialized(const char *name) {
if (r < 0)
return log_error_errno(r, "Failed to get device %s: %m", name);
r = sd_device_get_is_initialized(d);
r = device_is_processed(d);
if (r < 0)
return log_error_errno(r, "Failed to determine whether interface %s is initialized: %m", name);
if (r == 0)

View File

@@ -139,7 +139,7 @@ static int device_wait_for_initialization_internal(
}
if (device) {
if (sd_device_get_is_initialized(device) > 0) {
if (device_is_processed(device) > 0) {
if (ret)
*ret = sd_device_ref(device);
return 0;
@@ -202,7 +202,7 @@ static int device_wait_for_initialization_internal(
if (r < 0 && !ERRNO_IS_DEVICE_ABSENT(r))
return log_error_errno(r, "Failed to create sd-device object from %s: %m", devlink);
}
if (device && sd_device_get_is_initialized(device) > 0) {
if (device && device_is_processed(device) > 0) {
if (ret)
*ret = sd_device_ref(device);
return 0;
@@ -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) {

View 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);

View File

@@ -1214,8 +1214,11 @@ static int run(int argc, char* argv[]) {
if (r < 0)
return log_error_errno(r, "Failed to exclude loop devices: %m");
FOREACH_DEVICE(enumerator, device)
FOREACH_DEVICE(enumerator, device) {
if (device_is_processed(device) <= 0)
continue;
device_added(&context, device);
}
}
_cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL;

View File

@@ -67,7 +67,7 @@ static int check_device(const char *path) {
return r;
if (arg_wait_until == WAIT_UNTIL_INITIALIZED)
return sd_device_get_is_initialized(dev);
return device_is_processed(dev);
return true;
}