Blame SOURCES/0143-ARM-detect-virt-detect-QEMU-KVM.patch

17b0f1
From fa2237b9987c39147704274937895547c8c8d647 Mon Sep 17 00:00:00 2001
17b0f1
From: Andrew Jones <drjones@redhat.com>
17b0f1
Date: Tue, 31 Mar 2015 11:08:13 +0200
17b0f1
Subject: [PATCH] ARM: detect-virt: detect QEMU/KVM
17b0f1
17b0f1
QEMU/KVM guests do not have hypervisor nodes, but they do have
17b0f1
fw-cfg nodes (since qemu v2.3.0-rc0). fw-cfg nodes are documented,
17b0f1
see kernel doc Documentation/devicetree/bindings/arm/fw-cfg.txt,
17b0f1
and therefore we should be able to rely on it in this detection.
17b0f1
17b0f1
Unfortunately, we currently don't have enough information in the
17b0f1
DT, or elsewhere, to determine if we're using KVM acceleration
17b0f1
with QEMU or not, so we can only report 'qemu' at this time, even
17b0f1
if KVM is in use. This shouldn't really matter in practice though,
17b0f1
because if detect-virt is used interactively it will be clear to
17b0f1
the user whether or not KVM acceleration is present by the overall
17b0f1
speed of the guest. If used by a script, then the script's behavior
17b0f1
should not change whether it's 'qemu' or 'kvm'. QEMU emulated
17b0f1
guests and QEMU/KVM guests of the same type should behave
17b0f1
identically, only the speed at which they run should differ.
17b0f1
17b0f1
Cherry-picked from: ce09c71d56a11
17b0f1
Resolves: #1207773
17b0f1
---
17b0f1
 src/shared/virt.c | 17 +++++++++++++++++
17b0f1
 1 file changed, 17 insertions(+)
17b0f1
17b0f1
diff --git a/src/shared/virt.c b/src/shared/virt.c
17b0f1
index 712523210d..54c465520d 100644
17b0f1
--- a/src/shared/virt.c
17b0f1
+++ b/src/shared/virt.c
17b0f1
@@ -115,6 +115,23 @@ static int detect_vm_devicetree(const char **_id) {
17b0f1
                         *_id = "xen";
17b0f1
                         return 1;
17b0f1
                 }
17b0f1
+        } else if (r == -ENOENT) {
17b0f1
+                _cleanup_closedir_ DIR *dir = NULL;
17b0f1
+                struct dirent *dent;
17b0f1
+
17b0f1
+                dir = opendir("/proc/device-tree");
17b0f1
+                if (!dir) {
17b0f1
+                        if (errno == ENOENT)
17b0f1
+                                return 0;
17b0f1
+                        return -errno;
17b0f1
+                }
17b0f1
+
17b0f1
+                FOREACH_DIRENT(dent, dir, return -errno) {
17b0f1
+                        if (strstr(dent->d_name, "fw-cfg")) {
17b0f1
+                                *_id = "qemu";
17b0f1
+                                return 1;
17b0f1
+                        }
17b0f1
+                }
17b0f1
         }
17b0f1
 #endif
17b0f1
         return 0;