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