]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/device: Log if we fail to open a device
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 7 May 2022 13:18:32 +0000 (15:18 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 8 May 2022 11:25:42 +0000 (13:25 +0200)
We also shorten the logic by getting rid of the validate_node()
function. An extra check is added to verify we're dealing with
a device before calling sd_device_new_from_devname() since that
will return -EINVAL if anything other than a device is passed.

src/core/device.c

index 5bee0b5c1638f0a05d921c230241e2b00d54ed38..1c7dde2f2264032aa636d60a6409dd8b4622f02b 100644 (file)
@@ -948,29 +948,9 @@ static int device_dispatch_io(sd_device_monitor *monitor, sd_device *dev, void *
         return 0;
 }
 
-static int validate_node(const char *node, sd_device **ret) {
-        _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
+void device_found_node(Manager *m, const char *node, DeviceFound found, DeviceFound mask) {
         int r;
 
-        assert(node);
-        assert(ret);
-
-        /* Validates a device node that showed up in /proc/swaps or /proc/self/mountinfo if it makes sense for us to
-         * track. Note that this validator is fine within missing device nodes, but not with badly set up ones! */
-
-        r = sd_device_new_from_devname(&dev, node);
-        if (r == -ENODEV) {
-                *ret = NULL;
-                return 0; /* good! (though missing) */
-        }
-        if (r < 0)
-                return r; /* bad! */
-
-        *ret = TAKE_PTR(dev);
-        return 1; /* good! */
-}
-
-void device_found_node(Manager *m, const char *node, DeviceFound found, DeviceFound mask) {
         assert(m);
         assert(node);
         assert(!FLAGS_SET(mask, DEVICE_FOUND_UDEV));
@@ -994,10 +974,18 @@ void device_found_node(Manager *m, const char *node, DeviceFound found, DeviceFo
 
                 /* If the device is known in the kernel and newly appeared, then we'll create a device unit for it,
                  * under the name referenced in /proc/swaps or /proc/self/mountinfo. But first, let's validate if
-                 * everything is alright with the device node. */
-
-                if (validate_node(node, &dev) < 0)
-                        return; /* Don't create a device unit for this if the device node is borked. */
+                 * everything is alright with the device node. Note that we're fine with missing device nodes,
+                 * but not with badly set up ones. */
+
+                r = sd_device_new_from_devname(&dev, node);
+                if (r == -ENODEV)
+                        log_debug("Could not find device for %s, continuing without device node", node);
+                else if (r < 0) {
+                        /* Reduce log noise from nodes which are not device nodes by skipping EINVAL. */
+                        if (r != -EINVAL)
+                                log_error_errno(r, "Failed to open %s device, ignoring: %m", node);
+                        return;
+                }
 
                 (void) device_setup_unit(m, dev, node, false); /* 'dev' may be NULL. */
         }