[LTP] [PATCH] tst_virt: Add fallback KVM detection via virtio block devices
Darren Chang
chihsheng@google.com
Sat May 2 10:14:46 CEST 2026
Currently, is_kvm() relies on reading /proc/cpuinfo to find the
"QEMU Virtual CPU" string.
This patch introduces a fallback mechanism to detect KVM environments
by checking for the existence of standard virtio block devices when the
CPU info check fails. Specifically, it probes for:
- /sys/block/vda (Reliable sysfs kernel interface)
- /dev/vda (Standard Linux device node)
- /dev/block/vda (Android's ueventd device node)
Including "/dev/block/vda" ensures that the detection works seamlessly
within Android emulator environments (such as Cuttlefish),
which use ueventd and place block devices under /dev/block/ instead of
the standard Linux /dev/.
Signed-off-by: Darren Chang <chihsheng@google.com>
---
lib/tst_virt.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/lib/tst_virt.c b/lib/tst_virt.c
index 109d7a853..ac0aef665 100644
--- a/lib/tst_virt.c
+++ b/lib/tst_virt.c
@@ -44,6 +44,19 @@ static int is_kvm(void)
}
SAFE_FCLOSE(NULL, cpuinfo);
+
+ /* * Fallback check for KVM:
+ * Android's ueventd creates block devices in /dev/block/
+ * instead of the standard Linux /dev/, so we check both.
+ */
+ if (!found) {
+ if (access("/dev/vda", F_OK) == 0 ||
+ access("/sys/block/vda", F_OK) == 0 ||
+ access("/dev/block/vda", F_OK) == 0) {
+ found = 1;
+ }
+ }
+
return found;
}
--
2.54.0.545.g6539524ca2-goog
More information about the ltp
mailing list