daandemeyer / rpms / systemd

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