]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
kmod-setup: bypass heavy virtio-rng check if we are not running in a VM anyway 27320/head
authorLennart Poettering <lennart@poettering.net>
Tue, 18 Apr 2023 08:48:54 +0000 (10:48 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 18 Apr 2023 08:52:04 +0000 (10:52 +0200)
detect_vm() is cheap, because cached, let's hence do that early before
we get out the big guns and sweep through sysfs.

src/core/kmod-setup.c

index 949b1a5854a041647880765b57f88b5b5df4c833..adf817800f449fd78176f2afa07093d2399d728b 100644 (file)
@@ -67,6 +67,10 @@ static int has_virtio_rng_recurse_dir_cb(
 static bool has_virtio_rng(void) {
         int r;
 
+        /* Directory traversal might be slow, hence let's do a cheap check first if it's even worth it */
+        if (detect_vm() == VIRTUALIZATION_NONE)
+                return false;
+
         r = recurse_dir_at(
                         AT_FDCWD,
                         "/sys/devices/pci0000:00",