summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2019-01-20 17:53:33 +0000
committerDaniil Baturin <daniil@baturin.org>2019-01-20 17:53:33 +0000
commit2f09010ac0f5c38ebc4ef351695fbcbd3599d14d (patch)
tree92fc9539e84d2a87b78677a5e34ac5cbe3ffa2ee
parent0801a54b6c5d95ce6e18d6bbd525c66b9d7a6bdf (diff)
downloadhvinfo-2f09010ac0f5c38ebc4ef351695fbcbd3599d14d.tar.gz
hvinfo-2f09010ac0f5c38ebc4ef351695fbcbd3599d14d.zip
Add a DMI-based check for QEMU vs KVM.
This enabled KVM detection on non-x86 machines.
-rw-r--r--src/hvinfo.adb6
-rw-r--r--src/hypervisor_check.adb18
-rw-r--r--src/hypervisor_check.ads4
3 files changed, 28 insertions, 0 deletions
diff --git a/src/hvinfo.adb b/src/hvinfo.adb
index ec4ddcf..8133c3e 100644
--- a/src/hvinfo.adb
+++ b/src/hvinfo.adb
@@ -120,6 +120,12 @@ begin
if SMBIOS_HV_Name /= Null_Unbounded_String then
Hypervisor_Name := SMBIOS_HV_Name;
Hypervisor_Detected := True;
+
+ -- Special case: QEMU sets different product name for
+ -- emulated and KVM-accelerated machines
+ if Get_DMI_Product_Name = KVM then
+ Hypervisor_Name := US.To_Unbounded_String (KVM);
+ end if;
else
if Debug then
UIO.Put_Line (IO.Standard_Error, "DMI vendor name is: """ & SMBIOS_Vendor & """");
diff --git a/src/hypervisor_check.adb b/src/hypervisor_check.adb
index e598169..23a418f 100644
--- a/src/hypervisor_check.adb
+++ b/src/hypervisor_check.adb
@@ -188,6 +188,24 @@ package body Hypervisor_Check is
return Name;
end Get_DMI_Vendor_String;
+ function Get_DMI_Product_Name return US.Unbounded_String is
+ Product_Name, Vendor_Name : US.Unbounded_String;
+ begin
+ if Config.Linux then
+ Product_Name := Head_Of_File (Linux_Sys_Product_File);
+ else
+ raise OS_Not_Supported;
+ end if;
+
+ if Contains (Product_Name, KVM_DMI_Pattern) then
+ Vendor_Name := US.To_Unbounded_String (KVM);
+ else
+ Vendor_Name := US.Null_Unbounded_String;
+ end if;
+
+ return Vendor_Name;
+ end Get_DMI_Product_Name;
+
function Get_DMI_Vendor_Name (Vendor_String : US.Unbounded_String) return US.Unbounded_String is
Vendor_Name : US.Unbounded_String;
begin
diff --git a/src/hypervisor_check.ads b/src/hypervisor_check.ads
index 3c62f5c..5c561a7 100644
--- a/src/hypervisor_check.ads
+++ b/src/hypervisor_check.ads
@@ -49,6 +49,8 @@ package Hypervisor_Check is
function Get_DMI_Vendor_String return US.Unbounded_String;
+ function Get_DMI_Product_Name return US.Unbounded_String;
+
function Command_Succeeds (Command : String) return Boolean;
function VirtualBox_PCI_Present return Boolean;
@@ -71,6 +73,7 @@ private
-- Linux-specific file names etc.
Linux_Sys_Vendor_File : constant String := "/sys/class/dmi/id/sys_vendor";
+ Linux_Sys_Product_File : constant String := "/sys/class/dmi/id/product_name";
Linux_Sys_HV_Type_File : constant String := "/sys/hypervisor/type";
-- FreeBSD-specific file names, commands etc.
@@ -85,6 +88,7 @@ private
VirtualBox_DMI_Pattern : constant String := "innotek GmbH";
Parallels_DMI_Pattern : constant String := "Parallels";
QEMU_DMI_Pattern : constant String := "QEMU";
+ KVM_DMI_Pattern : constant String := "KVM Virtual Machine";
function CPUID (Arg : Unsigned_32) return CPUID_Registers;