valeriyvdovin / rpms / systemd

Forked from rpms/systemd 4 years ago
Clone

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

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