From fa505db314ba74c71e5165c8857009ff9e7d4641 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 18 Apr 2023 10:48:50 +0200 Subject: [PATCH 1/2] kmod-setup: use STARTSWITH_SET() where appropriate --- src/core/kmod-setup.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/core/kmod-setup.c b/src/core/kmod-setup.c index e843743777..949b1a5854 100644 --- a/src/core/kmod-setup.c +++ b/src/core/kmod-setup.c @@ -11,6 +11,7 @@ #include "macro.h" #include "recurse-dir.h" #include "string-util.h" +#include "strv.h" #include "virt.h" #if HAVE_KMOD @@ -57,10 +58,7 @@ static int has_virtio_rng_recurse_dir_cb( return RECURSE_DIR_LEAVE_DIRECTORY; } - if (startswith(alias, "pci:v00001AF4d00001005")) - return 1; - - if (startswith(alias, "pci:v00001AF4d00001044")) + if (STARTSWITH_SET(alias, "pci:v00001AF4d00001005", "pci:v00001AF4d00001044")) return 1; return RECURSE_DIR_LEAVE_DIRECTORY; From 0a5d3c0b5bfee68102de6345a3cd5580fbd5da02 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 18 Apr 2023 10:48:54 +0200 Subject: [PATCH 2/2] 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 949b1a5854..adf817800f 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",