summaryrefslogtreecommitdiffstats
path: root/src/core/kmod-setup.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/kmod-setup.c')
-rw-r--r--src/core/kmod-setup.c36
1 files changed, 29 insertions, 7 deletions
diff --git a/src/core/kmod-setup.c b/src/core/kmod-setup.c
index 15337d0..ea01fd7 100644
--- a/src/core/kmod-setup.c
+++ b/src/core/kmod-setup.c
@@ -30,7 +30,7 @@ static void systemd_kmod_log(
REENABLE_WARNING;
}
-static int has_virtio_rng_recurse_dir_cb(
+static int match_modalias_recurse_dir_cb(
RecurseDirEvent event,
const char *path,
int dir_fd,
@@ -40,6 +40,7 @@ static int has_virtio_rng_recurse_dir_cb(
void *userdata) {
_cleanup_free_ char *alias = NULL;
+ char **modaliases = ASSERT_PTR(userdata);
int r;
if (event != RECURSE_DIR_ENTRY)
@@ -57,13 +58,13 @@ static int has_virtio_rng_recurse_dir_cb(
return RECURSE_DIR_LEAVE_DIRECTORY;
}
- if (STARTSWITH_SET(alias, "pci:v00001AF4d00001005", "pci:v00001AF4d00001044"))
+ if (startswith_strv(alias, modaliases))
return 1;
return RECURSE_DIR_LEAVE_DIRECTORY;
}
-static bool has_virtio_rng(void) {
+static bool has_virtio_feature(const char *name, char **modaliases) {
int r;
/* Directory traversal might be slow, hence let's do a cheap check first if it's even worth it */
@@ -74,16 +75,28 @@ static bool has_virtio_rng(void) {
AT_FDCWD,
"/sys/devices/pci0000:00",
/* statx_mask= */ 0,
- /* n_depth_max= */ 2,
+ /* n_depth_max= */ 3,
RECURSE_DIR_ENSURE_TYPE,
- has_virtio_rng_recurse_dir_cb,
- NULL);
+ match_modalias_recurse_dir_cb,
+ modaliases);
if (r < 0)
- log_debug_errno(r, "Failed to determine whether host has virtio-rng device, ignoring: %m");
+ log_debug_errno(r, "Failed to determine whether host has %s device, ignoring: %m", name);
return r > 0;
}
+static bool has_virtio_rng(void) {
+ return has_virtio_feature("virtio-rng", STRV_MAKE("pci:v00001AF4d00001005", "pci:v00001AF4d00001044"));
+}
+
+static bool has_virtiofs(void) {
+ return has_virtio_feature("virtiofs", STRV_MAKE("virtio:d0000001Av"));
+}
+
+static bool has_virtio_pci(void) {
+ return has_virtio_feature("virtio-pci", STRV_MAKE("pci:v00001AF4d"));
+}
+
static bool in_qemu(void) {
return IN_SET(detect_vm(), VIRTUALIZATION_KVM, VIRTUALIZATION_QEMU);
}
@@ -117,6 +130,15 @@ int kmod_setup(void) {
/* virtio_rng would be loaded by udev later, but real entropy might be needed very early */
{ "virtio_rng", NULL, false, false, has_virtio_rng },
+ /* We can't wait for specific virtiofs tags to show up as device nodes so we have to load the
+ * virtiofs and virtio_pci modules early to make sure the virtiofs tags are found when
+ * sysroot.mount is started.
+ *
+ * TODO: Remove these again once https://gitlab.com/virtio-fs/virtiofsd/-/issues/128 is
+ * resolved and the kernel fix is widely available. */
+ { "virtiofs", "/sys/module/virtiofs", false, false, has_virtiofs },
+ { "virtio_pci", "/sys/module/virtio_pci", false, false, has_virtio_pci },
+
/* qemu_fw_cfg would be loaded by udev later, but we want to import credentials from it super early */
{ "qemu_fw_cfg", "/sys/firmware/qemu_fw_cfg", false, false, in_qemu },