From 0a5d3c0b5bfee68102de6345a3cd5580fbd5da02 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 18 Apr 2023 10:48:54 +0200 Subject: [PATCH] kmod-setup: bypass heavy virtio-rng check if we are not running in a VM anyway 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 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/kmod-setup.c b/src/core/kmod-setup.c index 949b1a5854a..adf817800f4 100644 --- a/src/core/kmod-setup.c +++ b/src/core/kmod-setup.c @@ -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",